CN108804339B - A kind of memory rubbish recovering method and device - Google Patents

A kind of memory rubbish recovering method and device Download PDF

Info

Publication number
CN108804339B
CN108804339B CN201810272739.6A CN201810272739A CN108804339B CN 108804339 B CN108804339 B CN 108804339B CN 201810272739 A CN201810272739 A CN 201810272739A CN 108804339 B CN108804339 B CN 108804339B
Authority
CN
China
Prior art keywords
state
queue
garbage
stage
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810272739.6A
Other languages
Chinese (zh)
Other versions
CN108804339A (en
Inventor
陈闯
张炎泼
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Bai Yun Technology Co Ltd
Original Assignee
Beijing Bai Yun Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Bai Yun Technology Co Ltd filed Critical Beijing Bai Yun Technology Co Ltd
Priority to CN201810272739.6A priority Critical patent/CN108804339B/en
Publication of CN108804339A publication Critical patent/CN108804339A/en
Application granted granted Critical
Publication of CN108804339B publication Critical patent/CN108804339B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Processing Of Solid Wastes (AREA)

Abstract

Disclosed herein is a kind of memory rubbish recovering method and devices, comprising: the progress of work and collection process are alternately performed: when deleting object in the progress of work, this object being placed in and is removed in queue;After constructing adduction relationship in the progress of work, the object being cited is placed in mark queue;Collection process circulation executes garbage collection algorithms, and the garbage collection algorithms include that initial phase, identification phase, item undetermined determine stage, removing stage.Item undetermined determines the stage: executing following processing until item queue undetermined is sky: taking out an object from the item queue undetermined, judge the state of the object, when the state of the object is unknown state, determine that the object is rubbish, by by the object reference and be placed in the item queue undetermined for all objects of unknown state.Memory garbage reclamation treatment effeciency can be improved herein.

Description

Memory garbage recycling method and device
Technical Field
The present application relates to, but not limited to, the field of internet technologies, and in particular, to a method and an apparatus for recovering memory garbage.
Background
A garbage collection mechanism is built in various programming languages, and a Garbage Collection (GC) algorithm is used in the garbage collection mechanism to implement allocation and release of a memory, wherein a mark sweep (mark sweep) algorithm is commonly used. The method mainly comprises two stages, namely a marking stage and a clearing stage. In the marking phase, the garbage collector traverses from the root, and adds an identifier to each scanned object which can be accessed from the root, so as to indicate that the object is reachable (reachable). In the clearing stage, the garbage collector performs linear traversal on the memory from beginning to end, if an object is found not to be identified as reachable, the memory occupied by the object is recycled, and the reachable identification of the object identified as reachable is eliminated, so that the next mark clearing algorithm is performed.
In one existing mark removal algorithm, each object in the system has two states, which can be represented by white and black. Each newly created object is white. And in the initialization stage, traversing the objects in the root and adding the objects into an object linked list. In the marking stage, when an object which is not scanned exists in the object linked list, the object is taken out from the object linked list and marked as black, and other objects which are referred by the object are traversed and also marked as black. In the recycling stage, all the objects are traversed, the white objects are recycled as garbage, and the black objects are added into the object list again to wait for the next round of algorithm processing. The use of such a mark removal algorithm ensures that scanning of all objects is not interrupted, and if scanning of all objects is interrupted, the newly added object cannot determine its status. The processing performance of such algorithms is severely limited.
In another existing mark removal algorithm, each object in the system has three states, which can be represented by white, gray, and black. Each newly created object is white. And in the initialization stage, traversing the objects in the root, setting the traversed objects to be gray, and adding the gray objects to a gray node linked list. And in the marking stage, when an object which is not scanned exists in the object linked list, taking out the object from the object linked list, marking the object to be black, traversing other objects referenced by the object, setting the object to be gray if the object is white, and adding the gray linked list. In the recycling stage, all the objects are traversed, the white objects are recycled as garbage, and the gray objects are added into the object list again to wait for the next round of algorithm processing. Using such a mark removal algorithm can be interrupted in the process of scanning all objects, but this method has the following disadvantages:
when a new reference object is added to an already marked object, the object needs to be marked in gray, all objects in the object need to be marked again, and when the operation of adding the reference object is frequently performed on the object, the operation of repeatedly marking the table affects the performance of the algorithm.
Secondly, in the clearing stage, all the objects need to be scanned once to find out the garbage objects for releasing.
In summary, the algorithm in the prior art wastes too much processing power in the marking process and the scanning process, and the processing efficiency is low when the application scale is large and the number of objects is large.
Disclosure of Invention
In order to solve the above technical problems, the present invention provides a method and an apparatus for recovering memory garbage.
The memory garbage recovery method provided by the invention comprises the following steps:
the work process and the recovery process are executed alternately:
when an object is deleted in a work process, the object is placed in a clearing queue; after a reference relation is constructed in a work process, placing a referenced object in an identification queue;
the recovery process circularly executes a garbage recovery algorithm, wherein the garbage recovery algorithm comprises an initialization stage, an identification stage, a pending item determination stage and a clearing stage;
an initialization stage: setting a root node in an identification queue;
an identification stage: performing the following until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determination stage: executing the following processing until the pending item queue is empty: taking out an object from the pending queue, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the pending queue;
and (3) clearing stage: the following is performed until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
The memory garbage recycling method also comprises the following characteristics:
in the undetermined item determining stage and the clearing stage, the object is directly released after the object is determined to be garbage; or in the undetermined item determining stage and the clearing stage, after the object is determined to be garbage, the object is arranged in a garbage queue; a release phase is also included after the purge phase, including: and releasing the objects in the garbage queue.
The memory garbage recycling method also comprises the following characteristics:
the initialization phase of the first round garbage collection algorithm further comprises the following steps: setting an initial value of a value M of a global variable for representing a state parameter, wherein the initialization stage of each round of garbage collection algorithm after the first round further comprises the following steps: increasing the value of a global variable used to represent the state parameter by T, the value of T being greater than or equal to 3; the state that the object is identified as reachable is as follows: setting the state value of the object to be M + A; the determination that the object is garbage is: setting the state value of the object to be M + B; wherein A and B are both less than T, and A and B are not the same; determining the state of the object includes: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
The invention provides a memory garbage recycling device, which comprises:
the system comprises a work process processing module and a recovery process processing module;
the working process processing module is used for executing a working process and placing an object into a clearing queue when the object is deleted in the working process; after a reference relation is constructed in a work process, placing a referenced object in an identification queue;
the recovery process processing module is used for executing a recovery process and circularly executing a garbage recovery algorithm; the method comprises an initialization stage processing unit, an identification stage processing unit, an undetermined item determination stage processing unit and a clearing stage processing unit;
the initialization stage processing unit is used for setting the root node in the identification queue;
an identification phase processing unit configured to perform the following processing until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determining stage processing unit, configured to execute the following processing until the pending item queue is empty: taking out an object from the pending queue, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the pending queue;
a flush phase processing unit to perform the following until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
The memory garbage recycling device further comprises the following characteristics:
the processing unit of the stage determined by the undetermined item is also used for directly releasing the object after determining that the object is garbage; the clearing stage processing unit is also used for directly releasing the object after determining that the object is garbage;
or,
the processing unit of the undetermined item determining stage is further used for setting the object in a garbage queue after determining that the object is garbage; the clearing stage processing unit is further configured to set the object in a garbage queue after determining that the object is garbage; the device also comprises a release stage processing unit used for releasing the objects in the garbage queue.
The memory garbage recycling device further comprises the following characteristics:
the initialization stage processing unit is used for setting an initial value of a value M of a global variable used for representing the state parameter in a first-round garbage collection algorithm, and is also used for increasing the value of the global variable used for representing the state parameter by T in each-round garbage collection algorithm after the first round, wherein the value of T is more than or equal to 3; further for identifying the object as reachable using: setting the state value of the object to be M + A; further for determining that the object is spam using: setting the state value of the object to be M + B; wherein A and B are both less than T, and A and B are not the same; and for determining the state of the object using: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
The invention provides another memory garbage recycling method, which comprises the following steps:
the method comprises the steps of circularly executing a garbage recovery algorithm, wherein the garbage recovery algorithm comprises an initialization stage, an identification stage, a pending item determination stage and a clearing stage;
an initialization stage: setting a root node in an identification queue;
an identification stage: performing the following until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determination stage: executing the following processing until the pending item queue is empty: taking out an object from the queue to be determined, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the queue to be determined;
and (3) clearing stage: the following is performed until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
The memory garbage recycling method also comprises the following characteristics:
in the undetermined item determining stage and the clearing stage, the object is directly released after the object is determined to be garbage; or in the undetermined item determining stage and the clearing stage, after the object is determined to be garbage, the object is arranged in a garbage queue; a release phase is also included after the purge phase, including: and releasing the objects in the garbage queue.
The memory garbage recycling method also comprises the following characteristics:
the objects in the identification queue comprise reference objects in the reference relation when the reference relation is established by the work process; the objects in the cleanup queue include reference objects in reference relationships when the worker process removes the reference relationships.
The memory garbage recycling method also comprises the following characteristics:
the initialization phase of the first round garbage collection algorithm further comprises the following steps: setting an initial value of a value M of a global variable for representing a state parameter, wherein the initialization stage of each round of garbage collection algorithm after the first round further comprises the following steps: increasing the value of a global variable used to represent the state parameter by T, the value of T being greater than or equal to 3; the state that the object is identified as reachable is as follows: setting the state value of the object to be M + A; the determination that the object is garbage is: setting the state value of the object to be M + B; wherein A and B are both less than T, and A and B are not the same; determining the state of the object includes: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
The invention provides another memory garbage recycling device, which comprises:
the memory garbage collection processing module is used for circularly executing a garbage collection algorithm and comprises an initialization stage processing unit, an identification stage processing unit, an undetermined item determination stage processing unit and a clearing stage processing unit;
the initialization stage processing unit is used for setting the root node in the identification queue;
an identification phase processing unit configured to perform the following processing until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determining stage processing unit, configured to execute the following processing until the pending item queue is empty: taking out an object from the pending queue, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the pending queue;
a flush phase processing unit to perform the following until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
The memory garbage recycling device further comprises the following characteristics:
the processing unit of the stage determined by the undetermined item is also used for directly releasing the object after determining that the object is garbage; the clearing stage processing unit is also used for directly releasing the object after determining that the object is garbage;
or,
the processing unit of the undetermined item determining stage is further used for setting the object in a garbage queue after determining that the object is garbage; the clearing stage processing unit is further configured to set the object in a garbage queue after determining that the object is garbage; the device also comprises a release stage processing unit used for releasing the objects in the garbage queue.
The memory garbage recycling device further comprises the following characteristics:
the objects in the identification queue comprise reference objects in the reference relation when the reference relation is established by the work process; the objects in the cleanup queue include reference objects in reference relationships when the worker process removes the reference relationships.
The memory garbage recycling device further comprises the following characteristics:
the initialization stage processing unit is used for setting an initial value of a value M of a global variable used for representing the state parameter in a first-round garbage collection algorithm, and is also used for increasing the value of the global variable used for representing the state parameter by T in each-round garbage collection algorithm after the first round, wherein the value of T is more than or equal to 3; further for identifying the object as reachable using: setting the state value of the object to be M + A; further for determining that the object is spam using: setting the state value of the object to be M + B; wherein A and B are both less than T, and A and B are not the same; and for determining the state of the object using: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
When the method of the embodiment of the invention is initialized, objects to be scanned are all added into the identification queue and are sequentially marked, and if a newly added object exists in the process, the newly added object can be directly added into the identification queue without scanning all the objects, so that the processing efficiency is improved; and the reference objects in the released reference relation are uniformly placed in the clearing queue, and which object is garbage is judged in the clearing queue without scanning all the objects, so that the processing efficiency is improved.
The embodiment of the invention also provides the pending queue for storing the object which can not be clearly determined to be garbage in the Nth GC algorithm, and the object which can not be clearly determined to be garbage is determined to be garbage again in the (N + 1) th GC algorithm, so that the condition of garbage misjudgment can be effectively prevented.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate an embodiment of the invention and, together with the description, serve to explain the invention and not to limit the invention. In the drawings:
fig. 1 is a flowchart of a memory garbage collection method according to an embodiment.
Fig. 2 is a structural diagram of a memory garbage collection apparatus according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
Example one
In this embodiment, a method for recovering memory garbage relates to a work process and a recovery process, and as shown in fig. 1, the method includes:
the work process and the recovery process are executed alternately:
when an object is deleted in a work process, the object is placed in a clearing queue; after a reference relation is constructed in a work process, placing a referenced object in an identification queue;
the recovery process circularly executes a garbage recovery algorithm, wherein the garbage recovery algorithm comprises an initialization stage, an identification stage, a to-be-determined stage and a clearing stage;
an initialization stage: setting a root node in an identification queue;
an identification stage: the following is performed until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referred by the object and are in an unknown state into the identification queue;
a pending item determination stage: executing the following processing until the pending item queue is empty: taking out an object from the queue to be determined, judging the state of the object, determining that the object is garbage when the state of the object is unknown, and placing all objects which are referred by the object and are in unknown states into the queue to be determined;
and (3) clearing stage: the following is performed until the flush queue is empty: taking an object out of the clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
The initialization phase of the first round garbage collection algorithm further comprises the following steps: setting an initial value of a value M of a global variable for representing a state parameter, wherein the initialization stage of each round of garbage collection algorithm after the first round further comprises the following steps: increasing the value of a global variable used to represent the state parameter by T, the value of T being greater than or equal to 3;
identifying the object as reachable: setting the state value of the object to be M + A;
determining that the object is garbage: setting the state value of the object to be M + B;
wherein A and B are both less than T, and A and B are not the same;
determining the state of the object includes: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
In a more preferred application, the 1 st round sets M to have an initial value of 0, T to have a value of 3, A to have a value of 1, and B to have a value of 2.
In the method, the removal stage of the previous round of GC algorithm cannot be determined as the release of the garbage object in the undetermined item determination stage of the next round of GC algorithm.
The memory release may be performed in one of the following ways:
a first, time release, comprising: in the undetermined item determining stage and the removing stage, directly releasing an object after determining that the object is garbage;
second, a unified release approach, comprising: in the undetermined item determining stage and the removing stage, after the object is determined to be garbage, the object is arranged in a garbage queue; a release phase is also included after the purge phase, the release phase including: and releasing the objects in the garbage queue.
As shown in fig. 2, the memory garbage collection apparatus according to the first embodiment includes:
the system comprises a work process processing module and a recovery process processing module;
the work process processing module is used for executing a work process and placing an object into a clearing queue when the object is deleted in the work process; after a reference relation is constructed in a work process, placing a referenced object in an identification queue;
the recovery process processing module is used for executing a recovery process and circularly executing a garbage recovery algorithm; the method comprises an initialization stage processing unit, an identification stage processing unit, an undetermined item determination stage processing unit and a clearing stage processing unit;
the initialization stage processing unit is used for setting the root node in the identification queue;
an identification phase processing unit for performing the following processing until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referred by the object and are in an unknown state into the identification queue;
a pending item determining stage processing unit, configured to execute the following processing until the pending item queue is empty: taking an object out of the queue to be determined, judging the state of the object, determining that the object is garbage when the state of the object is unknown, and placing all objects which are referred by the object and are in unknown states into the queue to be determined;
a flush phase processing unit to perform the following until the flush queue is empty: taking an object out of the clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
Wherein,
the processing unit is used for determining the phase of the object to be determined and directly releasing the object after determining that the object is garbage;
the clearing stage processing unit is also used for directly releasing the object after determining that the object is garbage;
or,
the processing unit of the undetermined item determining stage is also used for setting the object in a garbage queue after determining that the object is garbage;
the clearing stage processing unit is also used for setting the object in a garbage queue after determining that the object is garbage;
the apparatus also includes a release stage processing unit to release the object in the garbage queue.
The initialization stage processing unit is used for setting an initial value of a value M of a global variable used for representing the state parameter in the first-round garbage collection algorithm and increasing the value of the global variable used for representing the state parameter by T in each round of garbage collection algorithm after the first round, wherein the value of T is more than or equal to 3; also for identifying the object as reachable using: setting the state value of the object to be M + A; also for determining that the object is spam using: setting the state value of the object to be M + B; wherein A and B are both less than T, and A and B are not the same; it is also used to determine the status of the object using the following method: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
In a more preferred application, the 1 st round sets M to have an initial value of 0, T to have a value of 3, A to have a value of 1, and B to have a value of 2.
Example two
The method for recovering the memory garbage only relates to a recovery process, and comprises the steps of circularly executing a garbage recovery algorithm, wherein the garbage recovery algorithm comprises an initialization stage, an identification stage, a to-be-determined stage and a clearing stage;
an initialization stage: identifying all objects as unknown states, and setting a root node in an identification queue;
an identification stage: the following is performed until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referred by the object and are in an unknown state into the identification queue;
a pending item determination stage: executing the following processing until the pending item queue is empty: taking out an object from the queue to be determined, judging the state of the object, determining that the object is garbage when the state of the object is unknown, and placing all objects which are referred by the object and are in unknown states into the queue to be determined;
and (3) clearing stage: the following is performed until the flush queue is empty: taking an object out of the clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
Wherein,
identifying the objects in the queue comprises referencing objects in the referencing relationship when the work process establishes the referencing relationship; clearing objects in the queue includes referencing objects in the referencing relationship when the worker process removes the referencing relationship.
In the method, the removal stage of the previous round of GC algorithm cannot be determined as the release of the garbage object in the undetermined item determination stage of the next round of GC algorithm.
The initialization phase of the first round garbage collection algorithm further comprises the following steps: setting an initial value of a value M of a global variable for representing a state parameter, wherein the initialization stage of each round of garbage collection algorithm after the first round further comprises the following steps: increasing the value of a global variable used to represent the state parameter by T, the value of T being greater than or equal to 3;
identifying the object as reachable: setting the state value of the object to be M + A;
determining that the object is garbage: setting the state value of the object to be M + B;
wherein A and B are both less than T, and A and B are not the same;
determining the state of the object includes: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
In a more preferred application, the 1 st round sets M to have an initial value of 0, T to have a value of 3, A to have a value of 1, and B to have a value of 2.
In the method, the removal stage of the previous round of GC algorithm cannot be determined as the release of the garbage object in the undetermined item determination stage of the next round of GC algorithm.
The memory release may be performed in one of the following ways:
a first, time release, comprising: in the undetermined item determining stage and the removing stage, directly releasing an object after determining that the object is garbage;
second, a unified release approach, comprising: in the undetermined item determining stage and the removing stage, after the object is determined to be garbage, the object is arranged in a garbage queue; a release phase is also included after the purge phase, the release phase including: and releasing the objects in the garbage queue.
The memory garbage collection device in the second embodiment includes:
the memory garbage collection processing module is used for circularly executing a garbage collection algorithm and comprises an initialization stage processing unit, an identification stage processing unit, a to-be-determined stage processing unit and a clearing stage processing unit;
the initialization stage processing unit is used for setting the root node in the identification queue;
an identification phase processing unit for performing the following processing until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referred by the object and are in an unknown state into the identification queue;
a pending item determining stage processing unit, configured to execute the following processing until the pending item queue is empty: taking an object out of the queue to be determined, judging the state of the object, determining that the object is garbage when the state of the object is unknown, and placing all objects which are referred by the object and are in unknown states into the queue to be determined;
a flush phase processing unit to perform the following until the flush queue is empty: taking an object out of the clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
Wherein,
the processing unit of the undetermined item determining stage is also used for directly releasing the object after determining that the object is garbage;
the clearing stage processing unit is also used for directly releasing the object after determining that the object is garbage;
or,
the processing unit of the undetermined item determining stage is also used for setting the object in a garbage queue after determining that the object is garbage;
the clearing stage processing unit is also used for setting the object in a garbage queue after determining that the object is garbage;
the device also comprises a release stage processing unit used for releasing the objects in the garbage queue.
Identifying the objects in the queue comprises referencing objects in the referencing relationship when the work process establishes the referencing relationship; clearing objects in the queue includes referencing objects in the referencing relationship when the worker process removes the referencing relationship.
The initialization stage processing unit is used for setting an initial value of a value M of a global variable used for representing the state parameter in a first-round garbage collection algorithm and increasing the value of the global variable used for representing the state parameter by T in each round of garbage collection algorithm after the first round, wherein the value of T is more than or equal to 3; also for identifying the object as reachable using: setting the state value of the object to be M + A; also for determining that the object is spam using: setting the state value of the object to be M + B; wherein A and B are both less than T, and A and B are not the same; it is also used to determine the status of the object using the following method: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
In a more preferred application, the 1 st round sets M to have an initial value of 0, T to have a value of 3, A to have a value of 1, and B to have a value of 2.
Examples are as follows:
the method relates to identifying queues, clearing queues and pending queues, and all queues are empty when an algorithm is not started. The work process and the GC process are executed alternately. R is a root node, in this example a root table, and R includes C, D, E three objects. R { } in each step schematic described below denotes a set of objects visible from the root node R.
Step 1: and executing a GC algorithm, identifying all objects as unknown states in an initialization stage, and setting a root table in an identification queue.
The content of the step is as follows:
R{C、D、E}
identifying a queue: [ R ]
Clearing the queue: []
Pending queue: []
And 2, deleting the object C from the root node R by the work process, wherein only D, E objects remain in the root node R, and placing the deleted object C in a clearing queue in response to the deletion operation of the work module on the object C.
The content of the step is as follows:
R{D、E}
identifying a queue: [ R ]
Clearing the queue: [C]
pending queue: []
And 3, the GC process executes an identification phase, an object, namely the object D, is taken out from the identification queue and is identified as accessible, and the accessible identification (R) is carried in the object D seen from the R, so that only the object E is remained in the identification queue.
The content of the step is as follows:
R{D(r)、E}
identifying a queue: [E]
clearing the queue: [C]
pending queue: []
And 4, setting the object D to reference the object E (namely adding the object E into the object D) by the work process, and then immediately deleting the reference of the object D to the object E. In the method, the referenced objects are added into the identification queue as long as the work process establishes the reference relationship between the two objects, and the referenced objects are added into the clearing queue as long as the work process removes the reference relationship between the two objects. In this step, object E is added to the identify queue and clear queue in response to the work process setting object D referencing object E and then immediately deleting object D's reference to object E.
The content of the step is as follows:
R{D(r)、E}
identifying a queue: [E]
clearing the queue: [ C, E ]
Pending queue: []
And step 5, the GC process continuously executes the identification phase, an object, namely the object E, is taken out from the identification queue and is identified as accessible, the accessible identification (R) is carried in the object E seen from the R, the identification queue is empty, and the identification phase of the GC process is ended.
The content of the step is as follows:
R{D(r)、E(r)}
identifying a queue: []
Clearing the queue: [ C, E (r) ]
Pending queue: []
And 6, deleting the object E by the work process.
The content of the step is as follows:
R{E(r)}
identifying a queue: []
Clearing the queue: [ C, D (r), E (r) ]
Pending queue: []
And 7, the queue of the pending item is empty, and the GC process skips the stage of determining the pending item. The GC process executes a clearing stage, takes out the object C from the clearing queue, judges the state of the object as an unknown state, marks the object as garbage, and places the object in a garbage queue; taking out an object D from the clearing queue, judging that the state of the object is a reachable state, and placing the object in a pending queue; and taking out the object E from the clearing queue, judging that the state of the object is a reachable state, and placing the object in a pending queue. The GC process executes a release phase to release the object C in the garbage queue.
The content of the step is as follows:
R{E(r)}
identifying a queue: []
Clearing the queue: []
Pending queue: [ D (r), E (r) ]
And 8, executing a second GC algorithm by the GC process, identifying all objects as unknown states in an initialization stage, and setting the root nodes in the identification queue.
The content of the step is as follows:
R{E}
identifying a queue: [ R ]
Clearing the queue: []
Pending queue: [ D, E ]
Step 8, the GC process executes the identification phase, takes out an object from the identification queue, namely the object E, and identifies the object as accessible, only the object E exists in the R, and the identification phase is completed.
The content of the step is as follows:
R{E(r)}
identifying a queue: []
Clearing the queue: []
Pending queue: [ D, E (r) ]
Step 8, the GC process executes the undetermined item determining stage, takes out an object D from the undetermined item queue, judges the state of the object D to be an unknown state, marks the object to be garbage, and places the object in a garbage queue; and taking out an object E from the pending item queue, judging the state of the object E to be a reachable state, and reserving the object E. The purge queue is empty and the GC process skips the purge phase. And the GC process executes a release phase to release the object D in the garbage queue.
The content of the step is as follows:
R{E(r)}
identifying a queue: []
Clearing the queue: []
Pending queue: []
The above-described aspects may be implemented individually or in various combinations, and such variations are within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein.
It will be understood by those skilled in the art that all or part of the steps of the above methods may be implemented by instructing the relevant hardware through a program, and the program may be stored in a computer-readable storage medium, such as a read-only memory, a magnetic or optical disk, and the like. Alternatively, all or part of the steps of the foregoing embodiments may also be implemented by using one or more integrated circuits, and accordingly, each module/unit in the foregoing embodiments may be implemented in the form of hardware, and may also be implemented in the form of a software functional module. The present invention is not limited to any specific form of combination of hardware and software.
It is to be noted that, in this document, the terms "comprises", "comprising" or any other variation thereof are intended to cover a non-exclusive inclusion, so that an article or apparatus including a series of elements includes not only those elements but also other elements not explicitly listed or inherent to such article or apparatus. Without further limitation, an element defined by the phrase "comprising … …" does not exclude the presence of additional like elements in the article or device comprising the element.
The above embodiments are merely to illustrate the technical solutions of the present invention and not to limit the present invention, and the present invention has been described in detail with reference to the preferred embodiments. It will be understood by those skilled in the art that various modifications and equivalent arrangements may be made without departing from the spirit and scope of the present invention and it should be understood that the present invention is to be covered by the appended claims.

Claims (14)

1. A method for reclaiming memory garbage is characterized by comprising the following steps:
the work process and the recovery process are executed alternately:
when an object is deleted in a work process, the object is placed in a clearing queue; after a reference relation is constructed in a work process, placing a referenced object in an identification queue;
the recovery process circularly executes a garbage recovery algorithm, wherein the garbage recovery algorithm comprises an initialization stage, an identification stage, a pending item determination stage and a clearing stage;
an initialization stage: setting a root node in an identification queue;
an identification stage: performing the following until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determination stage: executing the following processing until the pending item queue is empty: taking out an object from the pending queue, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the pending queue;
and (3) clearing stage: the following is performed until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
2. The memory garbage collection method of claim 1,
in the undetermined item determining stage and the clearing stage, the object is directly released after the object is determined to be garbage;
or,
in the undetermined item determining stage and the clearing stage, after the object is determined to be garbage, the object is arranged in a garbage queue; a release phase is also included after the purge phase, including: and releasing the objects in the garbage queue.
3. The memory garbage collection method of claim 1,
the initialization phase of the first round garbage collection algorithm further comprises the following steps: setting an initial value of a value M of a global variable for representing a state parameter, wherein the initialization stage of each round of garbage collection algorithm after the first round further comprises the following steps: increasing the value of a global variable used to represent the state parameter by T, the value of T being greater than or equal to 3;
the state that the object is identified as reachable is as follows: setting the state value of the object to be M + A;
the determination that the object is garbage is: setting the state value of the object to be M + B;
wherein A and B are both less than T, and A and B are not the same;
determining the state of the object includes: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
4. A memory garbage collection device, comprising:
the system comprises a work process processing module and a recovery process processing module;
the working process processing module is used for executing a working process and placing an object into a clearing queue when the object is deleted in the working process; after a reference relation is constructed in a work process, placing a referenced object in an identification queue;
the recovery process processing module is used for executing a recovery process and circularly executing a garbage recovery algorithm; the method comprises an initialization stage processing unit, an identification stage processing unit, an undetermined item determination stage processing unit and a clearing stage processing unit;
the initialization stage processing unit is used for setting the root node in the identification queue;
an identification phase processing unit configured to perform the following processing until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determining stage processing unit, configured to execute the following processing until the pending item queue is empty: taking out an object from the pending queue, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the pending queue;
a flush phase processing unit to perform the following until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
5. The memory garbage collection apparatus according to claim 4,
the processing unit of the stage determined by the undetermined item is also used for directly releasing the object after determining that the object is garbage;
the clearing stage processing unit is also used for directly releasing the object after determining that the object is garbage;
or,
the processing unit of the undetermined item determining stage is further used for setting the object in a garbage queue after determining that the object is garbage;
the clearing stage processing unit is further configured to set the object in a garbage queue after determining that the object is garbage;
the device also comprises a release stage processing unit used for releasing the objects in the garbage queue.
6. The memory garbage collection apparatus according to claim 4,
the initialization stage processing unit is used for setting an initial value of a value M of a global variable used for representing the state parameter in a first-round garbage collection algorithm, and is also used for increasing the value of the global variable used for representing the state parameter by T in each-round garbage collection algorithm after the first round, wherein the value of T is more than or equal to 3;
further for identifying the object as reachable using: setting the state value of the object to be M + A;
further for determining that the object is spam using: setting the state value of the object to be M + B;
wherein A and B are both less than T, and A and B are not the same;
and for determining the state of the object using: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
7. A method for reclaiming memory garbage is characterized by comprising the following steps:
the method comprises the steps of circularly executing a garbage recovery algorithm, wherein the garbage recovery algorithm comprises an initialization stage, an identification stage, a pending item determination stage and a clearing stage;
an initialization stage: setting a root node in an identification queue;
an identification stage: performing the following until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determination stage: executing the following processing until the pending item queue is empty: taking out an object from the queue to be determined, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the queue to be determined;
and (3) clearing stage: the following is performed until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
8. The method of memory garbage collection of claim 7,
in the undetermined item determining stage and the clearing stage, the object is directly released after the object is determined to be garbage;
or,
in the undetermined item determining stage and the clearing stage, after the object is determined to be garbage, the object is arranged in a garbage queue; a release phase is also included after the purge phase, including: and releasing the objects in the garbage queue.
9. The method of memory garbage collection of claim 7,
the objects in the identification queue comprise reference objects in the reference relation when the reference relation is established by the work process;
the objects in the cleanup queue include reference objects in reference relationships when the worker process removes the reference relationships.
10. The method of memory garbage collection of claim 7,
the initialization phase of the first round garbage collection algorithm further comprises the following steps: setting an initial value of a value M of a global variable for representing a state parameter, wherein the initialization stage of each round of garbage collection algorithm after the first round further comprises the following steps: increasing the value of a global variable used to represent the state parameter by T, the value of T being greater than or equal to 3;
the state that the object is identified as reachable is as follows: setting the state value of the object to be M + A;
the determination that the object is garbage is: setting the state value of the object to be M + B;
wherein A and B are both less than T, and A and B are not the same;
determining the state of the object includes: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
11. A memory garbage collection device, comprising:
the memory garbage collection processing module is used for circularly executing a garbage collection algorithm and comprises an initialization stage processing unit, an identification stage processing unit, an undetermined item determination stage processing unit and a clearing stage processing unit;
the initialization stage processing unit is used for setting the root node in the identification queue;
an identification phase processing unit configured to perform the following processing until the identification queue is empty: taking an object out of the identification queue, identifying the object as a reachable state, and placing all objects which are referenced by the object and are in an unknown state into the identification queue;
a pending item determining stage processing unit, configured to execute the following processing until the pending item queue is empty: taking out an object from the pending queue, judging the state of the object, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in the unknown state into the pending queue;
a flush phase processing unit to perform the following until the flush queue is empty: taking an object out of a clearing queue, judging the state of the object, placing the object in a pending queue when the state of the object is a reachable state, determining that the object is garbage when the state of the object is an unknown state, and placing all objects which are referred by the object and are in unknown states in the clearing queue.
12. The memory garbage collection apparatus according to claim 11,
the processing unit of the stage determined by the undetermined item is also used for directly releasing the object after determining that the object is garbage;
the clearing stage processing unit is also used for directly releasing the object after determining that the object is garbage;
or,
the processing unit of the undetermined item determining stage is further used for setting the object in a garbage queue after determining that the object is garbage;
the clearing stage processing unit is further configured to set the object in a garbage queue after determining that the object is garbage;
the device also comprises a release stage processing unit used for releasing the objects in the garbage queue.
13. The memory garbage collection apparatus according to claim 11,
the objects in the identification queue comprise reference objects in the reference relation when the reference relation is established by the work process;
the objects in the cleanup queue include reference objects in reference relationships when the worker process removes the reference relationships.
14. The memory garbage collection apparatus according to claim 11,
the initialization stage processing unit is used for setting an initial value of a value M of a global variable used for representing the state parameter in a first-round garbage collection algorithm, and is also used for increasing the value of the global variable used for representing the state parameter by T in each-round garbage collection algorithm after the first round, wherein the value of T is more than or equal to 3;
further for identifying the object as reachable using: setting the state value of the object to be M + A;
further for determining that the object is spam using: setting the state value of the object to be M + B;
wherein A and B are both less than T, and A and B are not the same;
and for determining the state of the object using: when the state value of the object is smaller than the current M value, the state of the object is determined to be an unknown state, when the state value of the object is M + A, the state of the object is determined to be a reachable state, and when the state value of the object is M + B, the state of the object is determined to be garbage.
CN201810272739.6A 2018-03-29 2018-03-29 A kind of memory rubbish recovering method and device Active CN108804339B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810272739.6A CN108804339B (en) 2018-03-29 2018-03-29 A kind of memory rubbish recovering method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810272739.6A CN108804339B (en) 2018-03-29 2018-03-29 A kind of memory rubbish recovering method and device

Publications (2)

Publication Number Publication Date
CN108804339A CN108804339A (en) 2018-11-13
CN108804339B true CN108804339B (en) 2019-07-16

Family

ID=64095462

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810272739.6A Active CN108804339B (en) 2018-03-29 2018-03-29 A kind of memory rubbish recovering method and device

Country Status (1)

Country Link
CN (1) CN108804339B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110659217B (en) * 2019-08-30 2021-10-15 苏州浪潮智能科技有限公司 Garbage recycling method, device and equipment for solid state disk and storage medium

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB9813264D0 (en) * 1998-06-20 1998-08-19 Koninkl Philips Electronics Nv Finalisation in incremental garbage collection
US7069279B1 (en) * 2002-11-04 2006-06-27 Savaje Technologies, Inc. Timely finalization of system resources
CN1321377C (en) * 2005-06-16 2007-06-13 北京航空航天大学 Method for controlling smart card storage environment
US7631024B2 (en) * 2006-01-03 2009-12-08 Sun Microsystems, Inc. Method and apparatus for facilitating mark-sweep garbage collection with reference counting
US7840612B2 (en) * 2006-10-23 2010-11-23 Research In Motion Limited Methods and apparatus for concurrently executing a garbage collection process during execution of a primary application program
CN101727355B (en) * 2008-10-31 2013-02-20 国际商业机器公司 Handling method and system for memory access events
CN102262591B (en) * 2010-05-31 2014-03-19 国际商业机器公司 Garbage collection method and system for memory copy system
US8412751B2 (en) * 2010-12-15 2013-04-02 International Business Machines Corporation Determining whether a Java object has been scan-missed by a garbage collector scan
CN102411513B (en) * 2011-08-10 2013-10-16 复旦大学 Garbage collection method for mixed mode execution engine
US10534716B2 (en) * 2016-07-13 2020-01-14 Seagate Technology Llc Limiting access operations in a data storage device
US9842060B1 (en) * 2016-07-13 2017-12-12 Seagate Technology Llc Cache over-provisioning in a data storage device

Also Published As

Publication number Publication date
CN108804339A (en) 2018-11-13

Similar Documents

Publication Publication Date Title
KR100715638B1 (en) Memory reclamation method
US6393439B1 (en) Stored data object marking for garbage collectors
US10372601B2 (en) Managing memory in a computer system
CN106302632A (en) The method for down loading of a kind of foundation image and management node
CN108804339B (en) A kind of memory rubbish recovering method and device
CN111037554A (en) Garbage cleaning method, device, equipment and medium based on machine learning
CN115827162A (en) Method, device, medium and equipment for intelligently processing mirror image warehouse data
US6338073B1 (en) Finalization in incremental garbage collectors
CN110059214A (en) A kind of image resource processing method and processing device
CN113568604A (en) Method and device for updating wind control strategy and computer readable storage medium
CN108897569A (en) The method for cleaning and computer readable storage medium of iOS engineering discarded record
CN105868057B (en) A kind of method, apparatus and mobile terminal of data processing
CN106802860B (en) Useless class detection method and device
CN113377724A (en) Cache space management method, device and storage medium
US6324550B1 (en) Data object identification and removal system
US7120750B1 (en) Method and system for handling queue overflow during in-cache garbage collection
CN108536537B (en) A kind of process resource recovery method and device
CN110807092A (en) Data processing method and device
CN113467940B (en) Resource management method, device, equipment and computer readable storage medium
CN111105868B (en) Data management method, in-vitro diagnosis device and storage medium
US8473529B2 (en) Single pass marking of finalizable objects
CN111857809B (en) Front-end development file updating method and device and electronic equipment
CN114791934A (en) Block chain upgrading method, device, equipment and storage medium
CN116339747A (en) JS file generation method, device, equipment and storage medium
CN116244262A (en) File processing method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant