Memory recovery method and device
By scanning and referring counting slab memory objects in the system, determining memory objects below the preset threshold and recycling, the system stability problems caused by slab memory accumulation are solved, and system performance and stability are improved.
Patent Information
- Application Number
- CN202210429570.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-22
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2042-04-22
AI Technical Summary
In the prior art, with the recycling of user-mode cold memory, the amount of slab memory in the system continues to increase, resulting in the impact of system stability, and the existing recycling methods will lead to a degradation of system performance.
By scanning the target memory object, obtaining its reference count information, determining the memory object whose reference count is lower than the preset threshold, and recycling it according to the preset recycling conditions.
Reduces system performance losses and improves system stability. By selecting less-used memory objects for recycling, the system performance is avoided.
Smart Images

Figure CN114995993B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present specification relate to the field of computer technology, and in particular to a memory recycling method. Background Art
[0002] Currently, cold memory recycling based on user-state pages (pagecache, anon) has been implemented. Its oversold memory resources can be rescheduled to new instances. At the same time, the increase in free memory has also greatly improved system stability. However, with the continuous recycling of user-state cold memory, the amount of slab memory in the system has been increasing, and it has to wait until the memory is insufficient to be recycled. In an online cluster, after a period of cold memory deployment, a large amount of slab memory may exist, and most of them are inactive. If slab memory accumulates for a long time, it will also have a great impact on system stability.
[0003] The current method for reclaiming slab memory objects is to reclaim all slab memories through the slab memory reclaiming interface provided by the operating system. This will cause the kernel to reallocate slab memory again, resulting in reduced system performance and affecting system stability. Summary of the invention
[0004] In view of this, an embodiment of this specification provides a memory recovery method. One or more embodiments of this specification also relate to a memory recovery device, a computing device, a computer-readable storage medium and a computer program to solve the technical defects existing in the prior art.
[0005] According to a first aspect of an embodiment of this specification, a memory recovery method is provided, including:
[0006] Scanning a target memory object to obtain reference count information of the target memory object, wherein a memory size of the target memory object satisfies a preset memory size;
[0007] A first memory object is determined from the target memory object according to the reference count information, and the first memory object that meets a preset recycling condition is recycled, wherein the first memory object is a memory object whose reference count is lower than a preset threshold.
[0008] According to a second aspect of an embodiment of this specification, a memory recycling device is provided, including:
[0009] A data acquisition module is configured to scan a target memory object to obtain reference count information of the target memory object, wherein a memory size of the target memory object satisfies a preset memory size;
[0010] The memory recycling module is configured to determine a first memory object from the target memory object according to the reference count information, and recycle the first memory object that meets the preset recycling conditions, wherein the first memory object is a memory object whose reference count is lower than a preset threshold.
[0011] According to a third aspect of an embodiment of this specification, a computing device is provided, including:
[0012] Memory and processor;
[0013] The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the above-mentioned memory recycling method are implemented.
[0014] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer-executable instructions, and when the instructions are executed by a processor, the steps of the above-mentioned memory recovery method are implemented.
[0015] According to a fifth aspect of the embodiments of this specification, a computer program is provided, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned memory recovery method.
[0016] The embodiments of the present specification provide a memory recycling method and device, wherein the memory recycling method comprises: scanning a target memory object to obtain reference count information of the target memory object, wherein the memory size of the target memory object satisfies a preset memory size, determining a first memory object from the target memory object according to the reference count information, and recycling the first memory object that satisfies a preset recycling condition, wherein the first memory object is a memory object whose reference count is lower than a preset threshold. By selecting a target memory object that satisfies a preset memory size, determining a first memory object from the target memory object according to the reference count, and determining whether the target memory object needs to be recycled according to the preset recycling condition, so as to recycle a part of the target memory objects, the performance loss of the system is reduced, and the stability of the system is improved because less used target memory objects are selected for recycling. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 is a flow chart of a memory recycling method provided by an embodiment of this specification;
[0018] Figure 2 is a schematic diagram of a memory recycling method provided by an embodiment of this specification;
[0019] Figure 3 is another schematic diagram of a memory recycling method provided by an embodiment of this specification;
[0020] Figure 4 is a process flow chart of a memory recycling method provided by an embodiment of this specification;
[0021] Figure 5 It is a structural schematic diagram of a memory recycling device provided by an embodiment of this specification;
[0022] Figure 6 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0023] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0024] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0025] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0026] First, the terms involved in one or more embodiments of this specification are explained.
[0027] Slab: is a memory allocation mechanism in the operating system, which is used to allocate and release objects smaller than 4k in size, such as process descriptors, dentry, inode, etc.
[0028] kidled: is a kernel-mode background cold memory identification thread.
[0029] Cold memory: refers to objects or pages that have not been accessed for a continuous period of time;
[0030] Kernel-mode pages: refers to memory allocated in the kernel, which is different from user-mode pages, such as slab memory objects and vmalloc pages.
[0031] User-mode pages: refers to pages allocated by user processes, which are usually released when the process exits, such as file pages and anonymous pages.
[0032] Thread: It is the smallest unit that the operating system can schedule operations. It is contained in the process and is the actual operation unit in the process. A thread refers to a single sequential control flow in the process. Multiple threads can run concurrently in a process, and each thread executes different tasks in parallel.
[0033] Reference counting: It is a memory management technology in computer programming languages. It refers to the process of saving the number of times a resource (which can be an object, memory, disk space, etc.) is referenced and releasing it when the number of references becomes zero.
[0034] Object: A memory address that has a value. This address may have an identifier pointing to it.
[0035] In this specification, a memory recovery method is provided. This specification also relates to a memory recovery device, a computing device, and a computer-readable storage medium, which are described in detail one by one in the following embodiments.
[0036] See also Figure 1 , Figure 1 A flowchart of a memory recycling method provided according to an embodiment of the present specification is shown, which specifically includes the following steps.
[0037] Step 102: Scan the target memory object to obtain reference count information of the target memory object, wherein the memory size of the target memory object meets the preset memory size.
[0038] Among them, the target memory object can be understood as the slab memory object in the above definition, for example, variable b can be called a slab memory object; the reference count information can be the number of times the target memory object is referenced, for example, the reference count information of variable b is 5, which means that variable b is referenced 5 times; the memory size of the target memory object meets the preset memory size and can be understood as a memory object with a memory size less than 4kb (kilobytes).
[0039] In practical applications, see Figure 2 , Figure 2A schematic diagram of a memory recovery method provided according to an embodiment of the present specification is shown, wherein the services in the user state include databases and remote dictionary parsing services, and in the kernel state, cold memory identification and cold memory recovery based on user state pages (file pages, anonymous pages) are currently implemented, and its oversold memory resources can be rescheduled to new instances, and the increase in free memory also greatly improves system stability. However, with the continuous recovery of cold memory in the user state, the number of slab pages (slab memory) in the system has been increasing, and it has to wait until insufficient memory is recovered. Now, the hot and cold identification of slab memory is increased to recover the cold slab memory.
[0040] Specifically, see Figure 3 , Figure 3 Another schematic diagram of a memory recovery method provided according to an embodiment of the present specification is shown. The original user-state services include databases and remote dictionary parsing services, and cold memory background services are added. In the kernel state, lightweight cold slab memory identification can be implemented according to the existing kidled framework. The kidled thread (memory identification thread) can scan and identify specific slab caches, such as inode caches, dentry caches, bufferhead caches, and radixtree caches. The reference count (age) of the memory objects in each cache is recorded. Then, the cold memory objects are recovered based on the memory recovery thread.
[0041] For example, the memory objects in the node cache (inodecaches) are target memory objects, including target memory object b and target memory object a. The reference count information of the target memory object b can be obtained as 9, and the reference count information of the target memory object a can be obtained as 5.
[0042] The embodiments of this specification use kidded threads to scan memory objects, thereby reducing system resource consumption and improving system performance.
[0043] In an achievable manner, the memory object may be scanned at a set time node, and whether the target memory object needs to be recycled is determined based on the obtained multiple reference count information for the target memory object. The specific implementation is as follows.
[0044] The scanning of the target memory object to obtain reference count information of the target memory object includes:
[0045] A scanning task for the target memory object is triggered at a set time node, and reference count information of the target memory object at the set time node is obtained.
[0046] The set time node may be a time node of a time period or a time node that is not a time period. For example, the time node may be set as a periodic time node every 5 seconds, or a time node may be set at the 3rd second and the 5th second.
[0047] For example, the time node is set to a periodic time node every 5 seconds, and the time nodes are set to 0 seconds, 5 seconds, 10 seconds... and other time nodes to trigger the target memory object scanning task. For example, at the 5th second, the memory objects in the node cache (inodecaches) are triggered to scan, including the target memory object b and the target memory object a, and the reference count information of the target memory object b is 9, and the reference count information of the target memory object a is 5.
[0048] For another example, the time nodes are set to trigger the target memory object scanning task from the starting time nodes of 0 seconds, 6 seconds, 10 seconds... For example, at the 5th second, the memory objects in the node cache (inodecaches) are triggered to be scanned, including the target memory object b and the target memory object a, and the reference count information of the target memory object b is 9, and the reference count information of the target memory object a is 5.
[0049] The embodiments of this specification scan memory objects and obtain reference counts of memory objects, so that the hot and cold memory properties of the memory objects can be determined later.
[0050] Step 104: Determine a first memory object from the target memory object according to the reference count information, and recycle the first memory object that meets a preset recycling condition, wherein the first memory object is a memory object whose reference count is lower than a preset threshold.
[0051] Among them, the first memory object can be a cold slab memory object, that is, a slab memory object whose access times are less than a set number. For example, the reference access times of the target memory object b is 0, then the target memory object b is determined to be the first memory object; the preset recycling condition can be understood as the condition for recycling the memory object, for example, recycling the cold memory every ten minutes; the preset threshold value can be a value such as 10, 5, 0, etc., and the embodiments of this specification do not limit the preset threshold value.
[0052] In practical applications, whether a memory object is a cold memory object can be determined based on the reference count information, so that the cold memory object can be reclaimed.
[0053] For example, the preset threshold is 0, including target memory object b, target memory object a and target memory object c. By scanning target memory object b, target memory object a and target memory object c, it can be obtained that the reference count information of target memory object b is 9, the reference count information of target memory object a is 5, and the reference count information of target memory object c is 0, then the target memory object c is determined to be the first memory object, that is, a cold memory object, and the cold memory object is reclaimed according to the preset recycling conditions.
[0054] In an implementable manner, determining the first memory object from the target memory object according to the reference count information includes:
[0055] A scanning task is executed at a currently set time node to obtain current reference count information, and when the current reference count information is less than or equal to a preset value, it is determined that a target memory object corresponding to the current reference count information is the first memory object.
[0056] In practical applications, when scanning memory objects multiple times, it is necessary to determine the cold memory objects each time so as to recycle them according to preset recycling conditions in subsequent steps.
[0057] For example, the preset threshold is 0, including target memory object b, target memory object a and target memory object c. By scanning target memory object b, target memory object a and target memory object c, it can be obtained that the reference count information of target memory object b is 9, the reference count information of target memory object a is 5, and the reference count information of target memory object c is 0, then the target memory object c is determined to be the first memory object, that is, a cold memory object.
[0058] In an achievable manner, the reclaiming of the first memory object that meets the preset reclaiming condition includes:
[0059] Updating the count of the target memory object being determined as the first memory object;
[0060] Obtaining a recycling threshold according to the preset recycling condition, and determining whether the count satisfies the recycling threshold when scanning the memory object is completed;
[0061] When the count satisfies the first memory threshold, the target memory object corresponding to the count is recycled.
[0062] Among them, the count of the target memory object being determined as the first memory object can be understood as the number of times the memory object is determined as a cold memory object. The first memory threshold is used to determine whether to recycle the memory object. For example, if the count of memory object a being determined as a cold memory object is 5 times and the first memory threshold is 6 times, it will not be recycled.
[0063] In actual applications, after each scan of memory objects is completed, a judgment is made whether to recycle cold memory objects.
[0064] For example, the preset threshold is 0, the first memory threshold is 5, including target memory object b, target memory object a and target memory object c. After the fourth scan is completed, the reference count of target memory object a is 6, the reference count of target memory object b is 1, and the reference count of target memory object c is 0. Then the target memory object c is determined to be a cold memory object. The number of times the target memory object c is determined to be a cold memory object is increased by 1, and the number of times the target memory object c is determined to be a cold memory object is 4 times in total. If the first memory threshold is not met, the target memory object c is not cleared. After the fifth scan is completed, the reference count of target memory object a is 6, the reference count of target memory object b is 1, and the reference count of target memory object c is 0. Then the target memory object c is determined to be a cold memory object. The number of times the target memory object c is determined to be a cold memory object is increased by 1, and the number of times the target memory object c is determined to be a cold memory object is 5 times in total. If the first memory threshold is met, the target memory object c is cleared.
[0065] When reclaiming memory objects, the embodiments of this specification take into account the number of times the memory objects are used, so as to reclaim cold memory objects and reduce the impact on system stability.
[0066] In another achievable manner, it is also possible to determine whether to reclaim the memory object according to the size of the cold memory object. The specific implementation manner is as follows.
[0067] The step of recycling the first memory object that meets the preset recycling condition includes:
[0068] A memory size threshold is obtained according to the preset recycling condition, and the first memory object is recycled when the memory size of the first memory object meets the memory size threshold.
[0069] The memory size threshold is used to determine whether to recycle the cold memory object. For example, if the memory size threshold is 15G (gigabytes), the cold memory object is recycled when the size of the cold memory object is 15G.
[0070] In practical applications, cold memory objects can be recycled according to their size, which makes it convenient to recycle slab memory according to memory resources.
[0071] For example, the memory size threshold is 15G, including target memory object b, target memory object a and target memory object c. After the fifth scan, the reference count of target memory object a is 6, the reference count of target memory object b is 1, and the reference count of target memory object c is 0. Then target memory object c is determined to be a cold memory object, and the size of the memory space occupied by target memory object c is 14G, so target memory object c is not cleared. After the sixth scan, the reference count of target memory object a is 6, the reference count of target memory object b is 1, and the reference count of target memory object c is 0. Then target memory object c is determined to be a cold memory object, and the size of the memory space occupied by target memory object c is 16G, which meets the memory size threshold, and target memory object c is cleared.
[0072] In one achievable manner, the processing resources of the system are monitored, and the set time node is adjusted according to the processing resources.
[0073] Among them, the system processing resources can be understood as the resources of the system's processor, for example, the system's processor usage rate is 50% at this time; monitoring the system's processing resources can be understood as obtaining the system's processor usage rate at regular intervals, for example, obtaining the processor usage rate every 0.5 seconds.
[0074] In actual applications, the scanning time interval of the memory object is adjusted according to the system processing resources. When the system processing resources are sufficient, the scanning times of the memory object are increased, and when the system processing resources are insufficient, the scanning times of the memory object are reduced. The specific implementation is as follows.
[0075] In an achievable manner, adjusting the set time node according to the system processing resources includes:
[0076] When the processing resource is greater than a preset resource threshold, reducing the adjacent scanning interval;
[0077] Alternatively, when the processing resource is less than a preset resource threshold, the adjacent scanning interval is increased.
[0078] The adjacent scanning interval can be understood as the time interval between two scans of the memory object. For example, if the first scan of the memory object and the second scan of the memory object are separated by 4 seconds, the adjacent scanning interval is 4 seconds.
[0079] For example, the preset resource threshold is 70%. When the system processor usage is 50%, the adjacent scanning interval is reduced from 5 seconds to 4 seconds. When the system processor usage is 80%, the adjacent scanning interval is increased from 4 seconds to 5 seconds.
[0080] It should be noted that preset resource thresholds can be set for the case of reducing the adjacent scan interval and the case of increasing the adjacent scan interval, respectively. A first preset resource threshold is set for the case of reducing the adjacent scan interval, and a second preset resource threshold is set for the case of increasing the adjacent scan interval, that is, under normal circumstances, the adjacent scan interval will not be increased or reduced. When it is less than the first preset threshold, the adjacent scan interval can be reduced to increase the number of scans of the memory object and make full use of the system's processing resources. When it is greater than the second preset threshold, the adjacent scan interval can be increased to reduce the number of scans of the memory object and alleviate the system's processing resources.
[0081] For example, a first preset resource threshold is set for the case of reducing the adjacent scanning interval, and a second preset resource threshold is set for the case of increasing the adjacent scanning interval, wherein the first preset resource threshold is 50%, and the second preset resource threshold is 80%, and the system processor usage is obtained every 0.5 seconds. When the system processor usage exceeds 80%, the original adjacent scanning interval is increased to 8 seconds. When the system processor usage is less than 50%, the adjacent scanning interval is reduced to 4 seconds. When the system processor usage is between 80% and 50%, the adjacent scanning interval is adjusted to 6 seconds.
[0082] In one achievable manner, in response to a memory reclaiming instruction, the first memory object is reclaimed.
[0083] Among them, the memory recycling instruction is an instruction for recycling memory objects.
[0084] In actual applications, memory objects can be recycled not only automatically but also manually.
[0085] For example, the preset threshold is 0, the first memory threshold is 5, including target memory object b, target memory object a and target memory object c. After the fourth scan is completed, the reference count of target memory object a is 6, the reference count of target memory object b is 1, and the reference count of target memory object c is 0. Then target memory object c is determined to be a cold memory object. The number of times target memory object c is determined to be a cold memory object is added by 1, and the number of times target memory object c is determined to be a cold memory object is 4 times in total. If the first memory threshold is not met, target memory object c is not cleared. However, when a memory recycling instruction is received, all cold memory objects are recycled, that is, target memory object c is recycled.
[0086] Furthermore, not only can cold memory objects be recycled, but also memory objects in a specified cache can be recycled. The specific implementation is as follows.
[0087] The recycling of the first memory object comprises:
[0088] Determining a memory object to be reclaimed from the first memory object according to the memory object identifier carried in the memory reclaim instruction;
[0089] Reclaim the memory object to be reclaimed.
[0090] The memory object identifier may be a cache name or an identifier of a memory object, for example, a node cache (inodecaches) or a memory object b.
[0091] For example, when a memory reclaiming instruction is received, a memory object identifier is obtained from the memory reclaiming instruction, and the memory object identifier is a node cache, that is, the memory object in the node cache is reclaimed.
[0092] It should be noted that when recycling memory objects in a node cache, cold memory objects therein may be recycled, or all memory objects therein may be recycled. This specification does not limit this. When the memory object identifier is an identifier of a memory object, the memory object may be recycled in all caches, or the memory object may be recycled in a certain cache.
[0093] The embodiments of the present specification provide a memory recycling method and device, wherein the memory recycling method comprises: scanning a target memory object to obtain reference count information of the target memory object, wherein the memory size of the target memory object satisfies a preset memory size, determining a first memory object from the target memory object according to the reference count information, and recycling the first memory object that satisfies a preset recycling condition, wherein the first memory object is a memory object whose reference count is lower than a preset threshold. By selecting a target memory object that satisfies a preset memory size, determining a first memory object from the target memory object according to the reference count, and determining whether the target memory object needs to be recycled according to the preset recycling condition, so as to recycle a part of the target memory objects, the performance loss of the system is reduced, and the stability of the system is improved because less used target memory objects are selected for recycling.
[0094] The following combination Figure 4 , taking the application of the memory recovery method provided in this specification in a server as an example, the memory recovery method is further described. Figure 4 A processing flow chart of a memory recycling method provided by an embodiment of the present specification is shown, which specifically includes the following steps.
[0095] Step 402: The server triggers a scanning task for the target memory object at a set time node, and obtains reference count information of the target memory object at the set time node.
[0096] Among them, the set time node can be a time node of a time period or a time node that is not a time period. For example, the time node can be set as a periodic time node every 5 seconds, or the time node can be set at the 3rd second and the time node can be set at the 5th second. The target memory object can be understood as the slab memory object in the above-mentioned definition. For example, variable b can be called a slab memory object. The reference count information can be the number of times the target memory object is referenced. For example, the reference count information of variable b is 5, which means that variable b is referenced 5 times. The memory size of the target memory object meets the preset memory size, which can be understood as a memory object with a memory size less than 4kb (kilobytes).
[0097] For example, the time node is set to a periodic time node every 5 seconds, and the time nodes are set to 0 seconds, 5 seconds, 10 seconds... and other time nodes to trigger the target memory object scanning task. For example, at the 5th second, the memory objects in the node cache (inodecaches) are triggered to scan, including the target memory object b and the target memory object a, and the reference count information of the target memory object b is 9, and the reference count information of the target memory object a is 5.
[0098] Step 404: the server executes a scanning task at a currently set time node to obtain current reference count information, and when the current reference count information is less than or equal to a preset value, determines that the target memory object corresponding to the current reference count information is the first memory object.
[0099] Among them, the first memory object can be a cold slab memory object, that is, a slab memory object whose access times are less than a set number. For example, the reference access times of the target memory object b is 0, then the target memory object b is determined to be the first memory object; the preset recycling condition can be understood as the condition for recycling the memory object, for example, recycling the cold memory every ten minutes; the preset threshold value can be a value such as 10, 5, 0, etc., and the embodiments of this specification do not limit the preset threshold value.
[0100] In practical applications, when scanning memory objects multiple times, it is necessary to determine the cold memory objects each time so as to recycle them according to preset recycling conditions in subsequent steps.
[0101] Continuing with the above example, the preset threshold is 0, including the target memory object b, the target memory object a and the target memory object c. After scanning the target memory object b, the target memory object a and the target memory object c, it can be obtained that the reference count information of the target memory object b is 9, the reference count information of the target memory object a is 5, and the reference count information of the target memory object c is 0, then the target memory object c is determined to be the first memory object, that is, the cold memory object.
[0102] Step 406: The server updates the count of the target memory object being determined as the first memory object.
[0103] Continuing with the above example, after the fourth scan is completed, the reference count of the target memory object a is 6, the reference count of the target memory object b is 1, and the reference count of the target memory object c is 0, then the target memory object c is determined to be a cold memory object, and the number of times the target memory object c is determined to be a cold memory object is increased by 1.
[0104] Step 408: The server obtains a recycling threshold according to the preset recycling condition, and determines whether the count satisfies the recycling threshold when the scanning of the memory object is completed.
[0105] Using the above example, the target memory object c is determined to be a cold memory object a total of 4 times, which does not meet the first memory threshold, and the target memory object c is not cleared. After the fifth scan is completed, the reference count of the target memory object a is 6, the reference count of the target memory object b is 1, and the reference count of the target memory object c is 0, so the target memory object c is determined to be a cold memory object. The number of times the target memory object c is determined to be a cold memory object is increased by 1, and the number of times the target memory object c is determined to be a cold memory object is determined to be 5 times, which meets the first memory threshold.
[0106] Step 410: When the count meets the first memory threshold, the server recycles the target memory object corresponding to the count.
[0107] Using the above example, the target memory object c is determined to be a cold memory object a total of 5 times, which meets the first memory threshold, and the target memory object c is cleared.
[0108] The embodiments of the present specification select a target memory object that meets a preset memory size, determine a first memory object from the target memory objects according to a reference count, and determine whether the target memory object needs to be recycled according to a preset recycling condition, so as to recycle a portion of the target memory objects, thereby reducing the performance loss of the system and improving the stability of the system by selecting less used target memory objects for recycling.
[0109] Corresponding to the above method embodiment, this specification also provides a memory recovery device embodiment, Figure 3 FIG. 2 shows a schematic diagram of a memory recycling device provided by an embodiment of the present specification. Figure 3 As shown, the device comprises:
[0110] The data acquisition module 502 is configured to scan the target memory object to obtain reference count information of the target memory object, wherein the memory size of the target memory object meets the preset memory size;
[0111] The memory recycling module 504 is configured to determine a first memory object from the target memory object according to the reference count information, and recycle the first memory object that meets the preset recycling condition, wherein the first memory object is a memory object whose reference count is lower than a preset threshold.
[0112] Furthermore, the data acquisition module 502 is further configured to:
[0113] A scanning task for the target memory object is triggered at a set time node, and reference count information of the target memory object at the set time node is obtained.
[0114] Furthermore, the memory recovery module 504 is further configured to:
[0115] A scanning task is executed at a currently set time node to obtain current reference count information, and when the current reference count information is less than or equal to a preset value, it is determined that a target memory object corresponding to the current reference count information is the first memory object.
[0116] Furthermore, the memory recovery module 504 is further configured to:
[0117] Updating the count of the target memory object being determined as the first memory object;
[0118] Obtaining a recycling threshold according to the preset recycling condition, and determining whether the count satisfies the recycling threshold when scanning the memory object is completed;
[0119] When the count satisfies the first memory threshold, the target memory object corresponding to the count is recycled.
[0120] Furthermore, the memory recovery module 504 is further configured to:
[0121] A memory size threshold is obtained according to the preset recycling condition, and the first memory object is recycled when the memory size of the first memory object meets the memory size threshold.
[0122] Furthermore, the memory recovery module 504 is further configured to:
[0123] The processing resources of the system are monitored, and the set time node is adjusted according to the processing resources.
[0124] Furthermore, the memory recovery module 504 is further configured to:
[0125] When the processing resource is greater than a preset resource threshold, reducing the adjacent scanning interval;
[0126] Alternatively, when the processing resource is less than a preset resource threshold, the adjacent scanning interval is increased.
[0127] Furthermore, the memory recovery module 504 is further configured to:
[0128] In response to the memory reclaim instruction, the first memory object is reclaimed.
[0129] Furthermore, the memory recovery module 504 is further configured to:
[0130] Determining a memory object to be reclaimed from the first memory object according to the memory object identifier carried in the memory reclaim instruction;
[0131] Reclaim the memory object to be reclaimed.
[0132] The embodiment of the present specification provides a memory recovery device, wherein the memory recovery device scans a target memory object to obtain reference count information of the target memory object, wherein the memory size of the target memory object satisfies a preset memory size, determines a first memory object from the target memory object according to the reference count information, and recovers the first memory object that meets a preset recovery condition, wherein the first memory object is a memory object whose reference count is lower than a preset threshold. By selecting a target memory object that meets a preset memory size, determining a first memory object from the target memory object according to the reference count, and determining whether the target memory object needs to be recovered according to the preset recovery condition, a part of the target memory objects is recovered, thereby reducing the performance loss of the system, and improving the stability of the system by selecting less used target memory objects for recovery.
[0133] The above is a schematic scheme of a memory recovery device of this embodiment. It should be noted that the technical scheme of the memory recovery device and the technical scheme of the above-mentioned memory recovery method belong to the same concept, and the details not described in detail in the technical scheme of the memory recovery device can be found in the description of the technical scheme of the above-mentioned memory recovery method.
[0134] Figure 6The block diagram of a computing device 600 according to an embodiment of the present specification is shown. The components of the computing device 600 include but are not limited to a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and the database 650 is used to store data.
[0135] The computing device 600 also includes an access device 640 that enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 640 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0136] In one embodiment of the present specification, the above components of the computing device 600 and Figure 6 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 6 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0137] The computing device 600 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 600 may also be a mobile or stationary server.
[0138] The processor 620 is used to execute the following computer executable instructions, which, when executed by the processor, implement the steps of the above-mentioned memory recovery method.
[0139] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the above-mentioned memory recovery method belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the above-mentioned memory recovery method.
[0140] An embodiment of the present specification further provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the above-mentioned memory recycling method.
[0141] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the above-mentioned memory recovery method belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the above-mentioned memory recovery method.
[0142] An embodiment of the present specification further provides a computer program, wherein when the computer program is executed in a computer, the computer is caused to execute the steps of the above-mentioned memory recycling method.
[0143] The above is a schematic scheme of a computer program of this embodiment. It should be noted that the technical scheme of the computer program and the technical scheme of the above-mentioned memory recovery method belong to the same concept, and the details not described in detail in the technical scheme of the computer program can be referred to the description of the technical scheme of the above-mentioned memory recovery method.
[0144] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0145] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0146] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.
[0147] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0148] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is only limited by the claims and their full scope and equivalents.
Claims
1. A memory recovery method, comprising: Scanning the target memory object to obtain reference count information of the target memory object, wherein the memory size of the target memory object satisfies a preset memory size, and the reference count information is the number of times the target memory object is referenced; A first memory object is determined from the target memory object according to the reference count information, and the first memory object that meets a preset recycling condition is recycled, wherein the first memory object is a memory object whose reference count is lower than a preset threshold.
2. According to the method of claim 1, scanning the target memory object to obtain the reference count information of the target memory object comprises: A scanning task for the target memory object is triggered at a set time node, and reference count information of the target memory object at the set time node is obtained.
3. The method according to claim 2, wherein determining the first memory object from the target memory object according to the reference count information comprises: A scanning task is executed at a currently set time node to obtain current reference count information, and when the current reference count information is less than or equal to a preset value, it is determined that a target memory object corresponding to the current reference count information is the first memory object.
4. According to the method of claim 3, the step of reclaiming the first memory object that meets the preset reclaiming condition comprises: Updating the count of the target memory object being determined as the first memory object; Obtaining a recycling threshold according to the preset recycling condition, and determining whether the count satisfies the recycling threshold when scanning the memory object is completed; When the count satisfies the recycling threshold, the target memory object corresponding to the count is recycled.
5. According to the method of claim 1, the step of reclaiming the first memory object that meets the preset reclaiming condition comprises: A memory size threshold is obtained according to the preset recycling condition, and the first memory object is recycled when the memory size of the first memory object meets the memory size threshold.
6. The method according to claim 2, further comprising: The processing resources of the system are monitored, and the set time node is adjusted according to the processing resources.
7. The method according to claim 6, wherein adjusting the set time node according to the processing resource comprises: When the processing resource is greater than a preset resource threshold, reducing the adjacent scanning interval; Alternatively, when the processing resource is less than a preset resource threshold, the adjacent scanning interval is increased.
8. The method according to claim 1, further comprising: In response to the memory reclaim instruction, the first memory object is reclaimed.
9. The method according to claim 8, wherein the reclaiming the first memory object comprises: Determining a memory object to be reclaimed from the first memory object according to the memory object identifier carried in the memory reclaim instruction; Reclaim the memory object to be reclaimed.
10. A memory recovery device, comprising: A data acquisition module is configured to scan a target memory object to obtain reference count information of the target memory object, wherein a memory size of the target memory object satisfies a preset memory size, and the reference count information is the number of times the target memory object is referenced; The memory recycling module is configured to determine a first memory object from the target memory object according to the reference count information, and recycle the first memory object that meets the preset recycling conditions, wherein the first memory object is a memory object whose reference count is lower than a preset threshold.
11. A computing device comprising: Memory and processor; The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the steps of the memory recovery method described in any one of claims 1 to 9 are implemented.
12. A computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the steps of the memory recycling method described in any one of claims 1 to 9.
13. A computer program product, characterized in that It includes computer instructions, which, when executed by a processor, implement the steps of the memory recycling method described in any one of claims 1 to 9.
Citation Information
Patent Citations
Method and device for recovering memories in Android
CN108052388A
Work set division method and system
CN110928635A
Heat-based storage management method and system
CN110968266A