Memory recovery method and device, electronic equipment and storage medium

By dividing the target memory into regions and adjusting the ant colony algorithm, we can quickly identify and reclaim long-term unused memory of low-priority tasks, solving the performance jitter problem caused by memory over-allocation in cloud-native colocation scenarios, and improving memory resource utilization and the response speed of high-priority tasks.

CN120704856APending Publication Date: 2025-09-26CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510585354.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-07
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

In cloud-native colocation scenarios, how can we quickly identify and reclaim long-term unused memory of low-priority tasks to avoid performance jitter caused by memory over-allocation?

Method used

By dividing the target memory into regions, the access status of each memory region is obtained, and the reclaimable region is determined based on the access frequency and time. The ant colony algorithm is used to dynamically adjust the memory reclaim threshold, merge or divide the memory regions to improve recognition efficiency and control computing resource consumption.

Benefits of technology

Effectively identify and reclaim long-term unused memory, reduce memory usage, avoid performance jitter, improve memory resource utilization, and ensure that high-priority tasks quickly obtain resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120704856A_ABST
    Figure CN120704856A_ABST
Patent Text Reader

Abstract

The invention discloses a memory recovery method and device, electronic equipment and a storage medium, and relates to the technical field of computers.The method comprises the steps that when a preset obtaining condition is met, the first access situation of any sub-area of each memory area in a target memory is obtained; wherein the target memory is used for storing task data of a target task; the memory region comprises one or more sub-regions; determining a second access condition of each memory region based on the collected first access condition of each memory region; acquiring the usage amount of the target task for the target memory; and under the condition that the usage amount meets a preset recovery condition, determining a recoverable area in all the memory areas based on the second access condition, and recovering a target sub-area in the recoverable area. According to the method and the device, the long-term unused memory of the low-priority task can be quickly identified, so that the identification problem of the long-term unused memory is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a memory recovery method, device, electronic device, and storage medium. Background Art

[0002] In cloud-native colocation scenarios, tasks of different priorities are mixed together—for example, latency-sensitive, high-priority tasks, and latency-insensitive, resource-intensive, low-priority tasks—to maximize resource utilization, such as memory and the central processing unit (CPU). To ensure that high-priority tasks can immediately access resources when they need them, it's necessary to reclaim long-unused memory in advance to reduce memory usage by low-priority tasks. Therefore, quickly identifying long-unused memory for low-priority tasks is a pressing issue. Summary of the Invention

[0003] In view of this, the present disclosure provides a memory recycling method, apparatus, electronic device, and storage medium to solve the problem of identifying long-term unused memory of low-priority tasks.

[0004] In a first aspect, the present disclosure provides a memory recovery method, the method comprising:

[0005] Whenever a preset acquisition condition is met, a first access condition of any sub-region of each memory region in the target memory is acquired; wherein the target memory is used to store task data of the target task; and the memory region includes one or more sub-regions;

[0006] Determining a second access status of each of the memory areas based on the collected first access status of each of the memory areas;

[0007] Obtaining the target memory usage of the target task;

[0008] When the usage meets a preset recycling condition, a reclaimable area is determined in all the memory areas based on the second access situation, and a target sub-area in the reclaimable area is recycled.

[0009] In a second aspect, the present disclosure provides a memory recovery device, the device comprising:

[0010] A first acquisition module is configured to acquire a first access condition of any sub-region of each memory region in a target memory whenever a preset acquisition condition is met; wherein the target memory is used to store task data of a target task; and the memory region includes one or more sub-regions;

[0011] a first processing module, configured to determine a second access status of each of the memory areas based on the collected first access status of each of the memory areas;

[0012] A second acquisition module is used to obtain the usage of the target memory by the target task;

[0013] The second processing module is configured to determine a reclaimable area in all the memory areas based on the second access situation when the usage meets a preset reclaim condition, and reclaim a target sub-area in the reclaimable area.

[0014] In a third aspect, the present disclosure provides an electronic device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the memory recovery method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0015] In a fourth aspect, the present disclosure provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the memory recovery method of the first aspect or any corresponding embodiment thereof.

[0016] The memory recovery method provided by the embodiment of the present disclosure divides the target memory used by the target task into regions. Then, whenever the preset acquisition condition is met, the first access situation of any sub-region of each memory region in the target memory is obtained to determine the second access situation of each memory region. Since the memory access situations of adjacent regions in the memory used by the target task are relatively close, the memory access situations of sub-regions of the same memory region are usually relatively close. Therefore, when the target task's usage of the target memory meets the preset recovery condition, the memory region where long-term unused memory may exist, i.e., the reclaimable region, can be quickly identified based on the second access situation. Furthermore, the target sub-region that has not been used for a long time is quickly identified and recovered in the determined reclaimable region, thereby improving the recognition efficiency of long-term unused memory (i.e., target sub-region) to effectively reclaim long-term unused memory.

[0017] The beneficial effects of the memory recycling device, electronic device, and storage medium correspond to the beneficial effects of the memory recycling method and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the specific embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0019] Figure 1 is a flowchart of a memory recycling method according to an embodiment of the present disclosure;

[0020] Figure 2 is a flowchart of another memory recycling method according to an embodiment of the present disclosure;

[0021] Figure 3 is a structural block diagram of a memory recycling device according to an embodiment of the present disclosure;

[0022] Figure 4 It is a structural block diagram of an electronic device according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0023] To make the purpose, technical solutions, and advantages of the embodiments of the present disclosure more clear, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of the present disclosure.

[0024] In cloud-native colocation scenarios, tasks of different priorities are mixed together—for example, latency-sensitive, high-priority tasks and latency-insensitive, resource-intensive, low-priority tasks—to maximize resource utilization, such as memory and central processing units (CPUs), thereby reducing costs. To ensure that high-priority tasks can immediately access the resources they need, it's necessary to monitor and limit the resources consumed by low-priority tasks.

[0025] In related technologies, cloud-native resource management technologies based on control groups (cgroups) are usually used to monitor and limit the resources of a single or multiple tasks in the operating system. However, in hybrid business scenarios, memory over-allocation is often accompanied. Therefore, when multiple low-priority tasks are working simultaneously, although the resources consumed by a single low-priority task are within the cgroup limit, the total resource consumption of the low-priority task may still exceed the overall resource threshold of the low-priority task, thereby triggering resource recovery and restriction operations for the low-priority task, thereby blocking the normal operation of some tasks.

[0026] To address this situation, memory resource management can mitigate this by reducing memory usage by preemptively reclaiming long-unused memory when the memory consumed by low-priority tasks approaches the maximum available memory. For example, the container's background asynchronous memory reclamation method allows the container to set a threshold. If this threshold is exceeded, background reclamation is triggered, using a least recently used (LRU) cache replacement strategy to reclaim recently unused memory. The purpose of LRU is to manage and optimize memory usage. The LRU strategy tracks the usage time of data in memory and determines which data should be eliminated. When memory space is insufficient, the LRU selects the least recently used data for reclamation, allowing new data to be loaded into memory. This effectively retains frequently accessed data and improves cache hit rates. However, the container's background asynchronous memory reclamation method does not consider the possibility that the memory exceeding the threshold may be accessed again in the future, which can cause performance jitter.

[0027] In view of this, according to an embodiment of the present disclosure, a memory recovery method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0028] In this embodiment, a memory recovery method is provided, which can be used in an operating system, such as a control group in an operating system. Figure 1 is a flow chart of a memory recycling method according to an embodiment of the present disclosure, such as Figure 1 As shown, the process includes the following steps:

[0029] Step S101, whenever a preset acquisition condition is met, obtain the first access status of any sub-area of ​​each memory area in the target memory; wherein the target memory is used to store task data of the target task; the memory area includes one or more sub-areas.

[0030] In practical applications, memory information used by the target task can be collected, such as the starting addresses of continuous memory areas such as the heap, stack, and code segments, and these continuous memory areas can be randomly divided into multiple new memory areas to obtain the various memory areas in the target memory. Alternatively, based on the access status of each memory area, these divided memory areas can be merged or further divided to obtain the various memory areas in the target memory, without limitation here.

[0031] Optionally, the preset acquisition condition is every first preset period, which can be adjusted according to actual conditions.

[0032] Optionally, the sub-region is a page.

[0033] Specifically, at intervals of a first preset period, a sub-region (such as a page) is randomly sampled in each memory region to determine whether the sub-region has been accessed, so as to obtain a first access status of the sub-region.

[0034] It can be understood that the first access condition is used to determine whether the sub-area has been visited.

[0035] Optionally, the target task is a low-priority task, i.e., a task with a priority lower than a preset priority threshold in a cloud-native colocation scenario. The target memory is the memory allocated to the target task.

[0036] Step S102: determining a second access status of each memory area based on the collected first access status of each memory area.

[0037] Specifically, at intervals of a second preset period, the second access status of each memory area is determined based on the first access status of each memory area collected within the second preset period.

[0038] Specifically, the accumulated result of the first access condition of the memory area within the second preset period is obtained to determine the second access condition of the memory area.

[0039] Optionally, the first access condition and the second access condition are access frequencies.

[0040] Step S103: Obtain the target memory usage of the target task.

[0041] It can be understood that the usage is the memory usage of the target memory used by the target task.

[0042] Step S104 : When the usage meets the preset recycling condition, a reclaimable area is determined in all memory areas based on the second access situation, and a target sub-area in the reclaimable area is recycled.

[0043] Optionally, initialize a memory reclaim watermark to obtain a low watermark and a high watermark. The low watermark is used as the preset minimum memory, and the high watermark is used as the preset maximum memory. The preset reclaim condition includes the usage reaching the preset maximum memory.

[0044] Specifically, when the usage reaches a preset maximum memory, a reclaimable area is determined from all memory areas based on the second access condition, and a target sub-area in the reclaimable area is reclaimed. As the target sub-area in the reclaimable area is reclaimed, i.e., memory is reclaimed, the target task's usage of the target memory decreases. When the usage is less than or equal to a preset minimum memory, the target sub-area in the reclaimable area is stopped from being reclaimed.

[0045] Furthermore, when the usage is less than or equal to the preset minimum memory, or the total amount of reclaimed memory reaches the target memory reclaim threshold, reclaiming the target sub-area in the reclaimable area is stopped.

[0046] The memory recovery method provided in this embodiment divides the target memory used by the target task into regions. Then, whenever the preset acquisition condition is met, the first access situation of any sub-region of each memory region in the target memory is obtained to determine the second access situation of each memory region. Since the memory access situations of adjacent regions in the memory used by the target task are relatively close, the memory access situations of sub-regions of the same memory region are usually relatively close. Therefore, when the target task's usage of the target memory meets the preset recovery condition, the memory region where long-term unused memory may exist, i.e., the recyclable region, can be quickly identified based on the second access situation. Furthermore, the target sub-region that has not been used for a long time is quickly identified and recovered in the determined recyclable region, thereby improving the recognition efficiency of long-term unused memory (i.e., target sub-region) to effectively recycle long-term unused memory.

[0047] In some optional implementations, the above step S104 includes:

[0048] Step a1: determining a reclaimable area in all memory areas based on the second access situation.

[0049] Optionally, the second access condition is an access frequency. Based on the second access condition, a memory area with the lowest access frequency is determined among all memory areas to serve as a reclaimable area.

[0050] Alternatively, based on the second access situation, a memory area having an access frequency less than a first preset low-frequency threshold is determined from all memory areas as a reclaimable area.

[0051] Step a2: Obtain the third access status of the sub-area in the reclaimable area.

[0052] Optionally, the third access condition is at least one of access frequency and access time.

[0053] Step a3: determining a target sub-area in the reclaimable area based on the third access situation, and reclaiming the target sub-area.

[0054] Optionally, if the third access condition indicates that a sub-region in the reclaimable region has not been used for a long period of time, then the sub-region is determined as a target sub-region. For example, if the access frequency of the sub-region is less than a first preset low-frequency threshold, or if the time between the last access and the current time reaches a preset maximum time, then the sub-region is determined as a target sub-region.

[0055] It can be understood that the target sub-area includes a sub-area in the reclaimable area that has not been used for a long time, that is, a cold page in the reclaimable area.

[0056] The memory reclamation method provided in this embodiment, after determining a reclaimable area based on the second access condition, determines a target sub-area within the reclaimable area based on the third access condition of a sub-area within the reclaimable area and reclaims it. Thus, it is possible to adaptively reclaim a target sub-area that has not been used for a long time.

[0057] In some optional embodiments, the memory recovery method disclosed herein further includes: when the second access conditions of adjacent memory areas all meet a preset low-frequency access condition, obtaining the difference in the second access conditions between adjacent memory areas; if the difference size meets a preset difference range, merging the adjacent memory areas to obtain a merged memory area.

[0058] Optionally, the second access condition is access frequency, and the preset low-frequency access condition includes that the access frequencies of adjacent memory regions are all less than a second preset low-frequency threshold. The second preset low-frequency threshold may be the same as or different from the first preset low-frequency threshold.

[0059] Furthermore, when the second access conditions of adjacent memory areas all meet the preset low-frequency access condition, if the difference in access frequency between adjacent memory areas meets the preset difference range, the adjacent memory areas are merged to obtain a merged memory area.

[0060] That is, adjacent memory areas with similar access frequencies and low access frequencies are merged to obtain a merged memory area.

[0061] The memory recycling method provided in this embodiment merges adjacent memory areas with similar access frequencies and low access frequencies. Therefore, it is convenient to quickly locate the memory area where the target sub-area that has not been used for a long time is located during memory recycling, so as to further improve the efficiency of identifying long-term unused memory.

[0062] In some optional implementations, the memory reclaiming method of the present disclosure further includes: dividing the memory area into a plurality of new memory areas when the second access condition of any memory area meets a preset high-frequency access condition.

[0063] Optionally, the second access condition is an access frequency, and the preset high-frequency access condition includes that the access frequency of the memory area is greater than a preset high-frequency threshold.

[0064] That is, the memory area with high access frequency is divided into smaller memory areas.

[0065] The memory recycling method provided in this embodiment divides a memory area with a high access frequency into smaller memory areas, thereby improving the recognition accuracy of memory that has not been used for a long time.

[0066] In some optional implementations, the memory reclaiming method of the present disclosure further includes:

[0067] Step b1: Obtain the target memory reclamation threshold and the total amount of reclaimed memory.

[0068] Specifically, obtaining the target memory reclamation threshold in step b1 includes:

[0069] Step b11: Obtain the computing resource consumption of the most recent preset number of historical memory recyclings.

[0070] Optionally, the computing resource consumption includes CPU consumption.

[0071] Optionally, the preset number of times is 10 times, and can be adjusted to 8 times, 11 times, etc. according to actual conditions, which is not limited here.

[0072] The most recent preset number of historical memory recyclings is the most recent preset number of historical memory recyclings from the current time.

[0073] Step b12: Based on the resource consumption level represented by the computing resource consumption, the initial memory reclamation threshold is adjusted to obtain a target memory reclamation threshold; wherein the resource consumption level is inversely proportional to the target memory reclamation threshold.

[0074] Optionally, an initial value of the memory reclaim threshold is preset to obtain an initial memory reclaim threshold MEMreclaim_max.

[0075] Specifically, the resource consumption is calculated as the CPU resource consumption, and based on the resource consumption level represented by the CPU resource consumption, the initial memory reclamation threshold is adjusted to obtain the target memory reclamation threshold, wherein the greater the resource consumption level, the smaller the target memory reclamation threshold.

[0076] Understandably, if CPU resource consumption was high over the past 10 times, future CPU resource consumption is also expected to be high. In this case, if excessive CPU resources are used for memory reclamation, process performance jitter is likely to occur. Therefore, it is necessary to lower the target memory reclamation threshold to reduce the CPU resources consumed by memory reclamation.

[0077] In this embodiment, the resource consumption level represented by the computing resource consumption can be used as ant pheromone, and the ant colony algorithm is used to adjust the initial memory recovery threshold to obtain the target memory recovery threshold, thereby dynamically adjusting the target memory recovery threshold MEMreclaim of memory recovery, thereby ensuring that the computing resources consumed in the entire recovery process are within a controllable range.

[0078] The memory reclamation method provided in this embodiment determines a target memory reclamation threshold based on the degree of resource consumption, as represented by the amount of computing resources consumed during historical memory reclamation. The degree of resource consumption is inversely proportional to the target memory reclamation threshold. This prevents excessive computing resource consumption during memory reclamation, thereby preventing performance jitter.

[0079] Furthermore, the above step b12 further includes:

[0080] Step b121: determining the resource consumption degree corresponding to the computing resource consumption based on the amount of computing resource consumption.

[0081] It should be noted that the amount of computing resource consumption is directly proportional to the degree of resource consumption, that is, the greater the amount of computing resource consumption, the greater the degree of resource consumption.

[0082] Specifically, an array corresponding to the most recent preset number of historical memory recyclings is set, and the array is used to record the computing resource consumption of the most recent preset number of historical memory recyclings.

[0083] Optionally, the computing resource consumption of the array in the initial state is a preset maximum computing resource consumption.

[0084] For example, if the preset number of times is 10 and the computing resource consumption is the CPU resource consumption, then set the array CPUusage

[10] and use CPUusage

[10] to record the computing resource consumption of the last 10 historical memory recyclings. Among them, CPUusage[0] is the CPU resource consumption of the most recent historical memory recycling, and CPUusage[9] is the CPU resource consumption of the historical memory recycling most distant from the current time, and so on. It should be noted that the initial value in CPUusage is the preset maximum CPU resource consumption CPUmax.

[0085] Specifically, if the computing resource consumption is less than or equal to a preset maximum computing resource consumption, the resource consumption level is determined to be a first preset value. If the computing resource consumption is greater than the preset maximum computing resource consumption, the resource consumption level is determined based on the difference between the preset maximum computing resource consumption and the computing resource consumption. Optionally, the first preset value is 0.

[0086] Furthermore, determining the resource consumption level based on the difference between the preset maximum computing resource consumption and the computing resource consumption includes: determining a first difference between the preset maximum computing resource consumption and a second preset value; and determining a second difference between the second difference and the computing resource consumption. Determining the resource consumption level corresponding to the computing resource consumption based on the sum of the second preset value and the reciprocal of the second difference. Optionally, the second preset value is 1.

[0087] Specifically, taking the ant colony algorithm to adjust the initial memory recycling threshold and calculating the resource consumption as CPU resource consumption as an example, the resource consumption degree corresponding to the CPU resource consumption at different memory recycling times is simulated as the ant pheromone. The latest pheromone has the largest weight, while the weight of the oldest pheromone is close to 0, indicating that the CPU resource consumption information has completely evaporated and has no impact on the actual behavior of the ants. This method can be used to predict the future CPU resource consumption and dynamically adjust the target memory recycling threshold.

[0088] Specifically, the resource consumption level IF corresponding to the resource consumption is calculated according to the following formula:

[0089]

[0090] Among them, IF[i] is the resource consumption degree of the computing resource consumption of the i-th historical memory recycling, CPUusage[i] is the computing resource consumption of the i-th historical memory recycling, and CPUmax is the preset maximum computing resource consumption.

[0091] It should be noted that the calculation formula for the above resource consumption degree IF is an inverse proportional formula. The larger the CPUusage[i], the greater its impact. The impact degree is normalized by the inverse proportional formula to ensure that the maximum impact degree is 1.

[0092] Step b122: determining the weight of the corresponding resource consumption degree based on the memory reclaim time corresponding to the calculated resource consumption; wherein, the closer the memory reclaim time is to the current time, the greater the weight.

[0093] It can be understood that the weight corresponding to the latest computing resource consumption is the largest, and the weight corresponding to the computing resource consumption that is the longest from the current time is the smallest, which is close to 0.

[0094] Step b123: performing weighted summation on the resource consumption levels based on the weights to obtain the historical resource consumption levels.

[0095] Optionally, historical resource consumption is calculated according to the following formula: Where N is the preset number of times, and (Ni)*0.01 is the weight corresponding to IF[i].

[0096] Taking the preset number of times as 10 as an example, the historical resource consumption is

[0097] Step b124: adjusting the initial memory reclamation threshold based on the historical resource consumption level to obtain a target memory reclamation threshold; wherein the historical resource consumption level is inversely proportional to the target memory reclamation threshold.

[0098] Specifically, a third difference between a third preset value and the historical resource consumption level is determined, and a target memory reclamation threshold is obtained based on a product of the initial memory reclamation threshold and the third difference.

[0099] Specifically, the target memory reclaim threshold MEMreclaim is obtained according to the following formula:

[0100]

[0101] MEMreclaim_max is the initial memory reclaim threshold.

[0102] Taking the preset number of times as 10 as an example, the target memory recycling threshold is:

[0103]

[0104] Understandably, when the resource consumption of computing resources in the past 10 times is large, the resource consumption of computing resources in the future is also expected to be large, and therefore, the target memory reclaim threshold needs to be lowered.

[0105] It should be noted that the range of the above IF[i] is 0-1. When IF[i] is all 1, the sum of IF[i]*(10-i) is 55. It is necessary to multiply it by 0.01 to ensure that the sum value is in the range of 0-1.

[0106] The memory reclamation method provided in this embodiment first determines the corresponding resource consumption level based on the amount of computing resource consumption, and then determines the weight of the resource consumption level based on the memory reclamation time. The closer the memory reclamation time, the greater the weight, reducing the impact of computing resource consumption over a longer period. Furthermore, the resource consumption levels are weighted and summed based on the weights to obtain the historical resource consumption level, which reflects the future resource consumption level. Thus, the target memory reclamation threshold is dynamically adjusted based on the historical resource consumption level, ensuring that computing resource consumption during the memory reclamation process is controllable.

[0107] Step b2: When the total amount of memory reaches the target memory reclamation threshold, stop reclaiming the target sub-area in the reclaimable area.

[0108] Furthermore, when the target task's target memory usage is less than or equal to a preset minimum memory, or the total amount of reclaimed memory reaches a target memory reclaim threshold, reclaiming the target sub-area in the reclaimable area is stopped.

[0109] At the same time, the computing resource consumption of this memory reclamation (i.e., the target sub-region reclamation) is recorded and recorded in the array element corresponding to the latest historical memory reclamation, for example, CPUusage[0]. Other array elements are updated, for example, the value of CPUusage[8] is used to overwrite the value of CPUusage[9].

[0110] The memory recycling method provided in this embodiment stops recycling the target sub-area in the reclaimable area when the total amount of memory reaches the target memory recycling threshold. Therefore, it is possible to control the computing resources consumed by this memory recycling and avoid large fluctuations in the processing performance of the target task (such as a low-priority task).

[0111] As an optional embodiment, step b2 further includes obtaining a recent preset number of historical memory reclamation page fault interruptions. Based on the number of page fault interruptions and the degree of resource consumption represented by the computing resource consumption, an initial memory reclamation threshold is adjusted to obtain a target memory reclamation threshold; wherein the degree of resource consumption is inversely proportional to the target memory reclamation threshold, and the number of page fault interruptions is inversely proportional to the target memory reclamation threshold.

[0112] Furthermore, the number of page faults is the number of major page faults.

[0113] It should be noted that a major fault is a memory management event that occurs when a process accesses a page that is not in physical memory. At this point, the operating system needs to load the page from disk or other storage media into memory. This operation, which involves disk I / O, is time-consuming and may affect system performance. Therefore, by calculating the resource consumption level as represented by the resource consumption amount and combining it with the number of page faults, we determine the target memory reclamation threshold. This ensures effective memory reclamation while keeping the number of page faults for the target task within a controllable range, further reducing performance jitter for the target task.

[0114] As a specific application example, take the preset number of times as 10 times and the computing resource consumption as CPU resource consumption as an example, Figure 2 As shown, the main steps of the memory recovery method disclosed in the present invention include:

[0115] Step S201 , preparing a preset maximum memory, a preset minimum memory, and a CPU usage array for memory recycling.

[0116] In step S202 , it is determined whether the target task's usage of the target memory reaches a preset maximum memory. If so, step S203 is executed. If not, the memory recycling process ends.

[0117] Step S203: Use the CPUusage array to record the CPU resource consumption of the most recent 10 memory recycling events, and determine the target memory recycling threshold using an ant colony algorithm.

[0118] That is, based on the resource consumption levels represented by the CPU resource consumption of the most recent 10 historical memory reclamation operations, the initial memory reclamation threshold is adjusted to obtain the target memory reclamation threshold.

[0119] Step S204: collecting memory information used by the target task, and randomly dividing the used continuous memory area into a plurality of new memory areas.

[0120] Step S205 : At intervals of a first preset period, randomly collect information on whether a sub-region (such as a page) in the memory region has been accessed to obtain a first access status.

[0121] Step S206 , at intervals of a second preset period, based on the first access conditions of the memory areas collected within the second preset period, determining the memory area with the lowest access frequency, and reclaiming a sub-area in the memory area that has not been used for a long time.

[0122] Step S207 , merging adjacent memory regions with similar access frequencies and low access frequencies, and dividing the memory region with high access frequencies into smaller memory regions.

[0123] Step S208 , determining whether the target task's corresponding target memory usage is less than or equal to a preset minimum memory usage; if so, the memory recycling process ends; otherwise, executing step S209 .

[0124] Step S209 , determining whether the total amount of reclaimed memory is greater than the target memory reclaim threshold, if so, the local memory reclaim process ends, if not, returns to step S205 .

[0125] It is worth noting that this embodiment is based on the ant colony algorithm for adaptive memory recovery. Therefore, in the cloud-native hybrid deployment scenario, it can adaptively reclaim memory that has not been used for a long time in low-priority tasks while ensuring that the server CPU resource consumption is controllable. This ensures that in the case of memory over-allocation, high-priority tasks can quickly allocate memory, and at the same time, the performance of low-priority tasks will not have much jitter.

[0126] It can be understood that the memory recovery method disclosed in the present invention does not take into account the fact that the recovered memory may be accessed in the future, so it is easy to cause performance jitter problems. It adopts an adaptive memory recovery method based on the ant colony algorithm. In the memory recovery method disclosed in the present invention, since the data access conditions (such as access frequency, etc.) of adjacent memory areas in the target memory are relatively close, in order to improve monitoring efficiency, the continuous target memory can be divided into multiple data objects according to the data access conditions, and each data object is a memory area with the same access frequency. That is, if a sub-area (such as a page, etc.) in the memory area is accessed, there is a high probability that other sub-areas in the memory area will also be accessed. Therefore, the memory recovery method disclosed in the present invention adaptively divides and / or merges the memory areas used by low-priority tasks based on the memory access frequency, so that it can quickly and accurately identify long-term unused memory areas while controlling the consumption of computing resources (such as CPU resources) to effectively reclaim the target sub-areas in the long-term used memory areas. At the same time, by using the target memory reclamation threshold determined by the ant colony algorithm and dynamically adjusting the amount of reclaimed memory, the memory resources used by low-priority tasks can be greatly controlled and the process performance jitter caused by memory reclamation can be reduced. This ensures that the CPU resources consumed by memory reclamation are within a controllable range, thereby increasing the practicality of cloud-native colocation scenarios.

[0127] This embodiment also provides a memory recycling device for implementing the above-mentioned embodiments and preferred embodiments. Details already described will not be repeated. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0128] This embodiment provides a memory recovery device, such as Figure 3 As shown, including:

[0129] A first acquisition module 301 is configured to acquire a first access condition of any sub-region of each memory region in a target memory whenever a preset acquisition condition is satisfied; wherein the target memory is used to store task data of a target task; and the memory region includes one or more sub-regions;

[0130] A first processing module 302 is configured to determine a second access status of each memory area based on the collected first access status of each memory area;

[0131] The second acquisition module 303 is used to obtain the target memory usage of the target task;

[0132] The second processing module 304 is configured to determine a reclaimable area in all memory areas based on the second access condition when the usage meets a preset reclaim condition, and reclaim a target sub-area in the reclaimable area.

[0133] In some optional implementations, the second processing module 304 includes:

[0134] an area determination unit, configured to determine a reclaimable area in all memory areas based on the second access condition;

[0135] an information acquisition unit, configured to acquire a third access condition of a sub-area in the reclaimable area;

[0136] The area recycling unit is configured to determine a target sub-area in the reclaimable area based on the third access situation, and reclaim the target sub-area.

[0137] In some optional implementations, the memory recycling device of the present disclosure further includes:

[0138] a third processing module, configured to determine a difference in the second access conditions between adjacent memory regions when the second access conditions of the adjacent memory regions all meet a preset low-frequency access condition;

[0139] The fourth processing module is configured to merge adjacent memory areas to obtain a merged memory area if the difference size satisfies a preset difference range.

[0140] In some optional implementations, the memory recycling device of the present disclosure further includes:

[0141] The fifth processing module is configured to divide the memory area into a plurality of new memory areas when the second access condition of any memory area meets a preset high-frequency access condition.

[0142] In some optional implementations, the memory recycling device of the present disclosure further includes:

[0143] The third acquisition module is used to obtain the target memory recycling threshold and the total amount of recycled memory;

[0144] The sixth processing module is configured to stop reclaiming a target sub-area in the reclaimable area when the total amount of memory reaches a target memory reclaim threshold.

[0145] In some optional implementations, the third acquisition module includes:

[0146] A historical data acquisition unit, used to obtain the computing resource consumption of the most recent preset number of historical memory recycling;

[0147] The threshold determination unit is used to adjust the initial memory reclamation threshold based on the resource consumption level represented by the computing resource consumption to obtain a target memory reclamation threshold; wherein the resource consumption level is inversely proportional to the target memory reclamation threshold.

[0148] In some optional implementations, the threshold determination unit includes:

[0149] The first processing subunit is configured to determine a resource consumption degree corresponding to the computing resource consumption based on the amount of computing resource consumption;

[0150] The second processing sub-unit is configured to determine a weight of a corresponding resource consumption degree based on a memory reclaim time corresponding to the calculated resource consumption amount; wherein the closer the memory reclaim time is to the current time, the greater the weight;

[0151] a third processing sub-unit, configured to perform weighted summation on the resource consumption levels based on the weights to obtain a historical resource consumption level;

[0152] The fourth processing sub-unit is configured to adjust the initial memory reclamation threshold based on the historical resource consumption level to obtain a target memory reclamation threshold; wherein the historical resource consumption level is inversely proportional to the target memory reclamation threshold.

[0153] The memory recovery device provided in the embodiments of the present disclosure can execute the memory recovery method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.

[0154] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0155] Figure 4 This is a structural block diagram of an electronic device provided in an embodiment of the present disclosure.

[0156] The following specific reference Figure 4, which shows a block diagram of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device may include a processor (e.g., a computing device, a graphics processor, etc.) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a memory 408 into a random access memory (RAM) 403. Various programs and data required for the operation of the electronic device are also stored in the RAM 403. The processor 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.

[0157] Typically, the following devices may be connected to the I / O interface 405: an input device 406 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a memory 408 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 409. The communication device 409 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all of the devices shown, and more or fewer devices may be implemented or possessed instead.

[0158] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 409, or installed from the memory 408, or installed from the ROM 402. When the computer program is executed by the processor 401, the above-mentioned functions defined in the memory recovery method of the embodiment of the present disclosure are performed.

[0159] Figure 4 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0160] The embodiments of the present disclosure also provide a computer-readable storage medium. The above-mentioned method according to the embodiments of the present disclosure can be implemented in hardware, firmware, or implemented as a computer code that can be recorded in a storage medium, or implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and downloaded through a network and will be stored in a local storage medium, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state drive, etc.; further, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that a computer, a processor, a microprocessor controller or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor or hardware, the memory recovery method shown in the above embodiment is implemented.

[0161] A portion of the present disclosure may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present disclosure through the operation of the computer. Those skilled in the art should understand that the form in which the computer program instruction exists in a computer-readable medium includes but is not limited to a source file, an executable file, an installation package file, etc. Accordingly, the way in which the computer program instruction is executed by the computer includes but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium that can be accessed by the computer.

[0162] Although the embodiments of the present disclosure have been described with reference to the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present disclosure, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A memory recovery method, characterized in that: The method comprises: Whenever a preset acquisition condition is met, a first access condition of any sub-region of each memory region in the target memory is acquired; wherein the target memory is used to store task data of the target task; and the memory region includes one or more sub-regions; Determining a second access status of each of the memory areas based on the collected first access status of each of the memory areas; Obtaining the target memory usage of the target task; When the usage meets a preset recycling condition, a reclaimable area is determined in all the memory areas based on the second access situation, and a target sub-area in the reclaimable area is recycled.

2. The method according to claim 1, characterized in that The determining of a reclaimable area in all the memory areas based on the second access situation and reclaiming a target sub-area in the reclaimable area includes: Determine the reclaimable area in all the memory areas based on the second access situation; Obtaining a third access condition of a sub-area in the reclaimable area; The target sub-area is determined in the reclaimable area based on the third access situation, and the target sub-area is reclaimed.

3. The method according to claim 1, characterized in that The method further comprises: When the second access conditions of the adjacent memory areas all meet the preset low-frequency access condition, determining the difference between the second access conditions of the adjacent memory areas; If the difference size satisfies a preset difference range, the adjacent memory areas are merged to obtain a merged memory area.

4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: When the second access condition of any of the memory areas meets a preset high-frequency access condition, the memory area is divided into a plurality of new memory areas.

5. The method according to claim 1, wherein The method further comprises: Get the target memory reclamation threshold and the total amount of reclaimed memory; When the total amount of memory reaches the target memory reclamation threshold, reclaiming the target sub-area in the reclaimable area is stopped.

6. The method according to claim 5, characterized in that Obtaining the target memory reclaim threshold includes: Get the computing resource consumption of the most recent preset number of historical memory recycling; Based on the resource consumption level represented by the computing resource consumption, the initial memory reclamation threshold is adjusted to obtain the target memory reclamation threshold; wherein the resource consumption level is inversely proportional to the target memory reclamation threshold.

7. The method according to claim 6, characterized in that The adjusting the initial memory reclaim threshold based on the resource consumption level represented by the computing resource consumption to obtain the target memory reclaim threshold includes: Determining a resource consumption level corresponding to the computing resource consumption based on the amount of computing resource consumption; Determining a weight of the corresponding resource consumption degree based on a memory reclaim time corresponding to the computing resource consumption; wherein the closer the memory reclaim time is to the current time, the greater the weight; Performing weighted summation on the resource consumption levels based on the weights to obtain a historical resource consumption level; The initial memory reclamation threshold is adjusted based on the historical resource consumption level to obtain the target memory reclamation threshold; wherein the historical resource consumption level is inversely proportional to the target memory reclamation threshold.

8. A memory recovery device, characterized in that: The device comprises: A first acquisition module is configured to acquire a first access condition of any sub-region of each memory region in a target memory whenever a preset acquisition condition is met; wherein the target memory is used to store task data of a target task; and the memory region includes one or more sub-regions; a first processing module, configured to determine a second access status of each of the memory areas based on the collected first access status of each of the memory areas; A second acquisition module is used to obtain the usage of the target memory by the target task; The second processing module is configured to determine a reclaimable area in all the memory areas based on the second access situation when the usage meets a preset reclaim condition, and reclaim a target sub-area in the reclaimable area.

9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, computer instructions are stored in the memory, and the processor executes the memory recovery method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the memory recycling method according to any one of claims 1 to 7.