Memory management method for dynamically recovering page cache

Through the method of dynamically recycling page cache, the cleaning strategy is adjusted according to memory usage and pressure indicators, which solves the memory process blocking caused by page cache cleaning in Linux systems, and improves the system's response speed and business continuity.

CN120407193AInactive Publication Date: 2025-08-01BEIJING LINX SOFTWARE CORP

Patent Information

Application Number
CN202510838085.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-08-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In Linux systems, when the system space is insufficient, directly cleaning the page cache will cause serious blocking of memory processes and affecting normal business execution.

Method used

By monitoring the system's memory usage, dynamically recycling page cache, first clean the page cache corresponding to the cold file, combine memory pressure indicators and memory saturation, and use different cleaning strategies to adjust the cleaning speed when different business needs to avoid one-time large-scale cleaning.

Benefits of technology

It reduces the impact on I/O operations, ensures the memory requirements of business processes, and improves the system's response speed and business continuity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407193A_ABST
    Figure CN120407193A_ABST
Patent Text Reader

Abstract

The invention discloses a memory management method for dynamically recovering page caches, which comprises the following steps of: monitoring the memory utilization rate of a system, when the memory utilization rate of the system is relatively high, firstly cleaning the page caches corresponding to cold files in a preset time period in the system, and not completely releasing the page caches at one time to influence certain I / O (Input / Output) performance. After the system cleans the page cache corresponding to the cold file and the memory pressure of the system is relieved, the page cache space of the system is dynamically cleaned according to the memory pressure index and the memory saturation of the system, so that the page cache is cleaned in advance before the idle memory is insufficient, and the page cache cleaning efficiency is improved. The page cache cleaning speed is dynamically adjusted, the page cache is slowly and mildly cleaned when the memory demand quantity in the business process is small, and the influence on I / O is reduced; on the contrary, when the business process needs a large amount of memory, the page cache is rapidly and intensely cleaned, and the demand of the business process for the memory is guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure generally relates to the field of memory adjustment, and particularly to a memory management method for dynamically reclaiming page cache. Background Art

[0002] In the Linux system, to avoid programs repeatedly reading or directly writing data from / to storage devices, data is usually saved in the page cache, which improves the efficiency of many I / O operations. When the system space is insufficient, the page cache will be reclaimed and cleared.

[0003] Currently, when the system space is insufficient, the page cache space of the system is directly cleared. However, since clearing the page cache takes a long time, there is a serious problem of blocking memory processes, thus affecting the execution of normal services. Summary of the Invention

[0004] In view of the above defects or deficiencies in the prior art, it is desirable to provide a memory management method for dynamically reclaiming page cache.

[0005] In a first aspect, a memory management method for dynamically reclaiming page cache is provided. The method includes: Obtaining the memory utilization rate of the system; If the memory utilization rate is greater than a first threshold, determining whether the aging record is empty, where the aging record is used to record cold files of the system in a preset time period; If it is not empty, performing a page cache clearing operation on the cold files in the aging record based on the status and cache clearing time of each file in the aging record; the status of the file is used to indicate whether the file is currently being accessed; Dynamically clearing the page cache space of the system based on the memory pressure index and memory saturation of the system.

[0006] The memory management method for dynamically reclaiming page cache provided by this application takes into account that when the current system space is insufficient, the page cache space of the system will be directly cleared. However, since clearing the page cache takes a long time, it will seriously block the memory process and affect the execution of normal services. This application provides a memory management method for dynamically reclaiming page cache. This method monitors the memory usage rate of the system. When the memory usage rate of the system is relatively high, it first clears the page cache corresponding to the cold files in the system within a preset time period, and does not release all the page cache at once, which will affect some I / O performance. After the system clears the page cache corresponding to the cold files, when the memory pressure of the system is relieved, this application will continue to dynamically clear the page cache space of the system according to the memory pressure index and memory saturation of the system, so as to achieve page cache clearing in advance before the free memory is insufficient, and dynamically adjust the speed of page cache clearing. When the memory demand of the business process is small, the page cache is cleared slowly and gently to reduce the impact on I / O; on the contrary, when the memory demand of the business process is large, the page cache is cleared quickly and intensively to ensure the memory demand of the business process.

[0007] In a second aspect, a memory management device for dynamically reclaiming page cache is provided. The device includes: An acquisition module, configured to acquire the memory usage rate of the system; A determination module, configured to determine whether the aging record is empty when the memory usage rate is greater than a first threshold, where the aging record is used to record the cold files of the system within a preset time period; A first cleaning module, configured to perform a page cache cleaning operation on the cold files in the aging record based on the status of each file in the aging record and the cache cleaning time; the status of the file is used to indicate whether the file is currently being accessed; A second cleaning module, configured to dynamically clean the page cache space of the system based on the memory pressure index and memory saturation of the system.

[0008] [[ID=]14]In a third aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method of the first aspect is implemented. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] By reading the detailed description of the non-restrictive embodiments with reference to the following drawings, other features, objectives, and advantages of this application will become more apparent: Figure 1 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache of a process provided by this application; Figure 2 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache of a process provided by this application; Figure 3 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache provided by this application; Figure 4 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache provided by this application; Figure 5 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache in the process memory provided by this application; Figure 6 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache in the process memory provided by this application; Figure 7 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache in the process memory provided by this application; Figure 8 It is a block diagram of the structure of a memory management device for dynamically reclaiming page cache in the process memory provided by this application. Detailed implementation manners

[0010] The following further elaborates on this application in conjunction with the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are merely used to explain the related invention and are not intended to limit the invention. Additionally, it should be noted that for ease of description, only the parts related to the invention are shown in the drawings.

[0011] It should be noted that, without conflict, the embodiments in this application and the features in the embodiments can be combined with each other. The following will elaborate on this application in detail with reference to the drawings and embodiments.

[0012] In the Linux system, the part that occupies the most memory is usually the page cache. By storing data in the page cache, programs do not need to repeatedly read or directly write data from storage devices, accelerating many I / O operations.

[0013] When the available memory is insufficient, the page cache will be the first data to be cleared. At this time, the CPU must spend a lot of time on clearing the page cache, especially directly clearing the page cache, and direct clearing will also block the processes that are applying for memory, seriously affecting the execution of normal services.

[0014] To solve this problem, this application provides a memory management method for dynamically reclaiming page cache. The following combines Figure 1 Exemplarily illustrates the memory management method for dynamically reclaiming page cache provided by this application. Figure 1 It is a flowchart of the steps of a memory management method for dynamically reclaiming page cache provided by this application. The method includes the following steps: Step S20, obtain the memory usage rate of the system; Among them, the system is any Linux system. In this application, the memory usage rate of the system can be obtained through the following method: Read the / proc / meminfo file, obtain the values of the MemTotal and MemFree fields, and calculate the memory usage rate according to the following formula:

[0015] Step S30, if the memory usage rate is greater than the first threshold, determine whether the aging record is empty. The aging record is used to record the cold files of the system in a preset time period; Among them, after calculating the current memory usage rate of the system according to the above method, the first threshold can be retrieved from the memory address, and the memory usage rate is compared with the first threshold. The first threshold can be a value determined according to multiple factors such as the historical operation of the system, the relationship between the historical memory usage rate of the system and the operation of the system, and the impact of the historical memory usage rate of the system on processes at different times. The first threshold is used to limit whether the system performs cleaning of the aging record. The first threshold is, for example, 80%.

[0016] The aging record is a record table determined by the user according to their own access situation. In this record table, information such as the file name, storage address, and access times of some files that the user does not often access (i.e., cold files) is recorded.

[0017] In an optional embodiment, the aging record can be obtained according to the following operations, as Figure 2 shown: Step S201, the user determines the cold files according to the historical file access records. The cold files are files whose access times are less than the number threshold within a preset time period; Among them, during the process of the user operating the system, it is inevitable to generate some files with fewer access times (such as query operations on some computing platforms). After these files are accessed, the data remaining in the page cache will lose its utilization value, and sometimes the data volume of these files is large. Therefore, preferentially cleaning the page cache corresponding to this part of the files can effectively relieve the memory pressure of the system. Then the user can find out these files according to the historical file access records and determine them as cold files. The determination method can be, for example, to count the access times of each file within a preset time period, compare the access times with the preset number threshold, and determine whether the file is a cold file according to the comparison result. The number threshold can be a value determined according to historical experience, such as 1 time, 2 times, etc.

[0018] Step S202: Add the cold files to the list and add the corresponding cache cleaning time for the cold files to form an aging record.

[0019] Among them, after the user filters out the cold files according to the above filtering process, in order to facilitate faster cleaning of the page cache to be cleaned subsequently, these cold files can be grouped together to form a record table, and the corresponding cache cleaning time is configured for each cold file, so as to provide a judgment basis for determining whether the page cache corresponding to the cold file needs to be cleaned subsequently.

[0020] Exemplarily, the aging record of the present application can be obtained through the following method: # echo $dir [$age_time]>> / proc / sys / vm / age_pagecache_dirlist (where age_pagecache_dirlist is the aging record, $dir is the cold file to be cleaned, and $age_time is an optional parameter indicating the aging time of the files in this directory, such as 100ms).

[0021] It should be noted here that the aging record is set by the user according to needs. Of course, the user can also not set the aging record. Therefore, it is necessary to confirm whether the aging record is empty before cleaning the page cache. It can be understood that only when the aging record is not empty, the page cache cleaning operation is performed on the cold files in the aging record. If the aging record is empty, step S40 below is not required, and directly go to step S50.

[0022] In addition, as long as the content of the aging record is read, the result of whether the aging record is empty can be obtained, which will not be elaborated here.

[0023] Step S40: If it is not empty, perform a page cache cleaning operation on the cold files in the aging record based on the status and cache cleaning time of each cold file in the aging record; the status of the cold file is used to indicate whether the cold file is currently being accessed. Among them, since cold files are not frequently accessed, closing their corresponding page caches does not affect I / O operations. Then, when the present application determines that the aging record is not empty according to the above process, in order to prevent the page caches corresponding to these cold files from occupying the system memory, it will first consider cleaning the page caches corresponding to the cold files to relieve the system memory pressure in a timely manner.

[0024] Exemplarily, the present application can traverse each cold file in the aging record and immediately clean its corresponding page cache when the cold file has a corresponding page cache. Of course, in order to ensure more accurate cleaning of the page cache corresponding to the cold file, the present application can perform a page cache cleaning operation on the cold files in the aging record based on the status of each cold file in the aging record and the cache cleaning time.

[0025] Here, it should be noted that the status of the cold file is used to indicate whether the cold file is being accessed at the current moment. It can be understood that the status of the cold file includes being accessed and not being accessed. When the cold file is being accessed, if its page cache is cleaned, it will affect the normal access to the cold file. The following will be combined with Figure 3 , and an optional embodiment of cleaning the page cache of the cold file in the present application will be described. As Figure 3 shown, the method includes the following steps: Step S301, if the status of the cold file is being accessed, then traverse the next cold file in the aging record to perform the page cache cleaning operation; Among them, the present application can traverse and process the cold files in the aging record according to the arrangement order of the cold files. Exemplarily, when traversing the first cold file in the aging record, its status can be determined in the following way: #fuser $file; that is, if there is a process that is currently opening $file for the cold file, it means its status is being accessed. In order to avoid the impact of closing its corresponding page cache on accessing the cold file, the present application can continue to determine the next cold file in the aging record according to the above method to perform the corresponding page cache cleaning operation, that is, judge the status of the next cold file. Similarly, if the status of the next cold file is also being accessed, continue to traverse the next cold file after the next cold file until the status of the cold file is not being accessed, and then perform the following operation.

[0026] Step S302, if the status of the cold file is not being accessed, then obtain the current first timestamp and the second timestamp when the cold file was last accessed; Among them, as described above, if it is determined that there is no process currently opening the $file for the cold file, this application will further decide whether to clean the cold file based on whether the cold file has reached the preset cache cleaning time. This can avoid immediately cleaning data that may still have associated background processing, thereby reducing the risk of incorrect cleaning. Additionally, by controlling the cleaning rhythm through the time threshold, it is possible to avoid performance fluctuations caused by a large number of fragmented I / O operations in a short period of time. Combining with the disk sleep state characteristics (such as the D state in Linux), this strategy can reduce resource preemption for high-priority tasks. Immediately cleaning cold files that have not reached the time threshold may result in the need to reload data during subsequent access, causing obvious delays. Delayed cleaning can maintain the cache hit rate for some predictable access scenarios, such as the file access continuity in the periodic log analysis scenario, thereby achieving the technical effect of enhancing the user's perceived experience. Compared with the immediate cleaning strategy, this dual judgment mechanism (process status + time threshold) is more in line with the hierarchical management principle of the storage system, achieving a balance between releasing resources and maintaining business continuity.

[0027] Therefore, it is necessary to obtain the current first timestamp and the second timestamp when the cold file was last accessed. Decide whether to clean the cold file based on the two timestamps and the preset cache cleaning time of the cold file.

[0028] Step S303, if the difference between the first timestamp and the second timestamp is greater than or equal to the cache cleaning time of the cold file, then clean the page cache corresponding to the cold file; Among them, exemplarily, the first timestamp and the second timestamp can be obtained in the following manner: Obtain the current first timestamp now_time in the following way: # date “+%s” Obtain the second timestamp access_time in the following way: # ls -l --time=”atime” --time-style=”+%s” $file (where $file is the cold file to be processed, and the 6th line in the output result is the second timestamp when the file was last accessed; ) Calculate whether the cold file has exceeded the cache cleaning time according to the following formula:

[0029] If has_aged is true, then the page cache corresponding to the cold file needs to be cleaned. Use the following method to clean the cold file from the page cache: # vmtouch -e $file (where $file is the cold file to be cleaned; ) Step S304, if the difference between the first timestamp and the second timestamp is less than the cache cleaning time of the file, then traverse the next cold file in the aging record to perform the page cache cleaning operation.

[0030] As described above, if has_aged is false, it means that the page cache corresponding to this cold file does not need to be cleaned. Continue to traverse the next cold file in the aging record and repeat the judgment on the cold file status and whether the cache cleaning time is reached. For details, see the above process and will not be elaborated here.

[0031] Step S50, dynamically clean the page cache space of the system based on the memory pressure index and memory saturation of the system.

[0032] It can be understood that after the present application cleans each cold file in the aging record when the aging record is not empty according to the above steps, the memory pressure of the system is alleviated to a certain extent. However, other processes of the system are still running, and page caches of other files will still be generated. The accumulation of page caches of these files, including the page caches of the cold files that are being accessed and not cleaned above, will still put pressure on the system memory. Therefore, the present application needs to dynamically clean these page caches, that is, execute different cleaning strategies according to different situations, so as to slowly and gently clean the page cache when the memory demand of the business process is small, reduce the impact on I / O, and quickly and intensively clean the page cache when the memory demand of the business process is large, giving priority to ensuring the memory demand of the business process.

[0033] It can be understood that the basis for the present application to dynamically clean the system memory is the memory pressure index and memory saturation of the system. Memory pressure index: It refers to the quantitative data of the proportion of the time when the allocation task is delayed in the real-time monitoring of the memory allocation process, which reflects the tightness of the system's inability to allocate memory in time. Memory saturation: It means that during the memory usage process, the real-time monitoring of the memory triggers the swap-out process, and the infrequently used memory data is swapped out to the physical swap space to free up idle memory, which is defined as saturated, reflecting the situation where the physical memory cannot meet the memory allocation; otherwise, it is defined as unsaturated.

[0034] Exemplarily, the present application can perform dynamic cleaning through the following method: 1. When the memory pressure index reaches the predetermined index value and the memory saturation is saturated, the system enables the page cache cleaning function and performs page cache cleaning in a cleaning method of cleaning once every 5 seconds and releasing 180 page caches for each node; 2. When the memory pressure index reaches the predetermined index value or the memory saturation is saturated, the system enables the function of clearing the page cache and clears the page cache in the way of clearing once every 10 seconds and releasing 60 page caches for each node. 3. As long as the memory saturation is saturated, the system enables the function of clearing the page cache and clears the page cache in the way of clearing once every 3 seconds and releasing 360 page caches for each node. 4. When the memory saturation is unsaturated, continue to determine whether the memory pressure index reaches the predetermined index value. If it reaches, clear the page cache in the way of clearing once every 3 seconds and releasing 360 page caches for each node. If it does not reach, clear the page cache in the way of clearing once every 20 seconds and releasing 20 page caches for each node.

[0035] …… There may be other ways to dynamically clear the page cache space of the system based on the memory pressure index and memory saturation of the system, which are not listed one by one in this application.

[0036] In an alternative embodiment, as Figure 4 shown Figure 4 This is a method embodiment for dynamically clearing the page cache space of the system based on the memory pressure index and memory saturation of the system provided by an exemplary embodiment of this application. The method embodiment includes the following steps: Step S401: Obtain the index value of the memory pressure index, compare the index value with the preset index range, and obtain the comparison result. Among them, this application can obtain the index value of the memory pressure index through the following method: Read the / proc / pressure / memory file, obtain the value of the avg10 field in some lines, which represents the percentage of tasks being delayed within an average of 10 seconds when tasks allocate memory. The value of the avg10 field in some lines represents the index value of the memory pressure index. When this value is greater than 0, it means that within a short period (such as within 10 seconds), the memory allocation of a certain or certain processes is delayed. If this value is 10, it means that the task is delayed by 1 second.

[0037] The preset index range can be determined according to historical data, such as greater than 0 and less than 10, greater than 10 and less than 30, greater than 30, etc. Comparing the index value with the preset index range is used to determine which index range the index value satisfies, and different cleaning strategies are executed according to different index ranges. This avoids the waste of resources caused by a one-size-fits-all cleaning mode.

[0038] Step S402: Determine whether to enable the periodic page cache cleaning function and the cleaning policy based on the comparison result and the judgment result of memory saturation, and dynamically clean the page cache space of the system according to the cleaning policy.

[0039] Among them, based on the above comparison result combined with the evaluation result of memory saturation, make a dynamic decision: For example, only when both the memory pressure and saturation exceed the standard, start periodic cleaning (to avoid frequent operations affecting performance); select aggressive / conservative cleaning according to the degree of exceeding the standard (such as cleaning 500MB each time when severely insufficient, and cleaning 100MB when slightly insufficient), etc.

[0040] This technical solution realizes precise response when memory is tight, and at the same time reduces false triggers through dual judgments (pressure + saturation).

[0041] The process of the judgment result of memory saturation includes: continuously read the / proc / meminfo file twice within a period of time to obtain the values of the swap-related fields. If the available swap space in the first time is greater than that in the second time, indicating memory swap-out, it means that the memory saturation is in a saturated state, and a memory swap-out behavior to the swap device has occurred; otherwise, it means that the memory saturation is in an unsaturated state.

[0042] In the system of this application, corresponding cleaning policies can be set for different situations. As long as the comparison result and the judgment result of memory saturation are determined, the corresponding cleaning policy can be obtained by matching.

[0043] Exemplarily, when the comparison result is that the index value is in the index range greater than 0 and less than 10, and the memory saturation is in an unsaturated state, the first cleaning policy is matched; When the comparison result is that the index value is in the index range greater than 10 and less than 30, and the memory saturation is in an unsaturated state, the second cleaning policy is matched; When the comparison result is that the index value is in the index range greater than 30, and the memory saturation is in an unsaturated state, the third cleaning policy is matched.

[0044] Each cleaning policy can set different parameters such as cleaning speed and cleaning intensity for the cleaning of the page cache, so as to realize the dynamic cleaning of the page cache in the system.

[0045] In a specific embodiment, as shown in Figure 5, Figure 5 This is a method embodiment for determining whether to enable the periodic page cache cleaning function and the cleaning policy according to the comparison result and the judgment result of memory saturation provided by an exemplary embodiment of this application. This method embodiment includes the following steps: Step S501, if the comparison result shows that the index value is within the preset first range and the memory saturation judgment result is unsaturated, then the periodic page cache cleaning function is enabled and a first cleaning policy is generated. The first cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at the first cleaning speed and the first intensity; Step S502, if the comparison result shows that the index value is within the preset second range and the memory saturation judgment result is unsaturated, then the periodic page cache cleaning function is enabled and a second cleaning policy is generated. The second cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at the second cleaning speed and the second intensity. The second cleaning speed is faster than the first cleaning speed, and the second intensity is greater than the first intensity; Step S503, if the comparison result shows that the index value is within the preset third range and the memory saturation judgment result is unsaturated, then the periodic page cache cleaning function is enabled and a third cleaning policy is generated. The third cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at the third cleaning speed and the third intensity and turn off the memory fragmentation sorting function of the transparent huge pages. The third cleaning speed is faster than the second cleaning speed, and the third intensity is greater than the second intensity; Step S504, if the memory saturation judgment result is saturated, then the periodic page cache cleaning function is enabled and a fourth cleaning policy is generated. The fourth cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at the fourth cleaning speed and the fourth intensity and turn off the memory fragmentation sorting function of the transparent huge pages. The fourth cleaning speed is faster than the third cleaning speed, and the fourth intensity is greater than the third intensity.

[0046] Among them, the preset first range is, for example, greater than 0 and less than 10, the preset second range is, for example, greater than 10 and less than 30, and the preset third range is, for example, greater than 30; The first cleaning speed is, for example, to clean once every 20 seconds, and the first intensity is, for example, to release 20 page caches for each node; The second cleaning speed is, for example, to clean once every 10 seconds, and the second intensity is, for example, to release 60 page caches for each node; The third cleaning speed is, for example, to clean once every 5 seconds, and the third intensity is, for example, to release 180 page caches for each node; The fourth cleaning speed is, for example, to clean once every 3 seconds, and the fourth intensity is, for example, to release 360 page caches for each node; As can be seen from the above, the greater the memory pressure, the faster the cleaning speed and the greater the cleaning intensity.

[0047] The process of enabling the periodic page cache cleaning function and generating the first cleaning policy in this application can be achieved through the following methods: # echo 1> / proc / sys / vm / cache_reclaim_enable to enable periodic page cache cleaning # echo 20> / proc / sys / vm / cache_reclaim_s Clean every 20 seconds # echo 20> / proc / sys / vm / cache_reclaim_weight Release 20 page caches per node; This application can implement the process of enabling the periodic page cache cleaning function and generating the second cleaning policy in the following way: # echo 1> / proc / sys / vm / cache_reclaim_enable to enable periodic page cache cleaning # echo 10> / proc / sys / vm / cache_reclaim_s Clean every 10 seconds # echo 60> / proc / sys / vm / cache_reclaim_weight Release 60 page caches per node; This application can implement the process of enabling the periodic page cache cleaning function and generating the third cleaning policy in the following way: # echo 1> / proc / sys / vm / cache_reclaim_enable to enable periodic page cache cleaning # echo 5> / proc / sys / vm / cache_reclaim_s Clean every 5 seconds # echo 180> / proc / sys / vm / cache_reclaim_weight Release 180 page caches per node # echo never> / sys / kernel / mm / transparent_hugepage / defrag Turn off memory fragmentation sorting of transparent huge pages; This application can implement the process of enabling the periodic page cache cleaning function and generating the fourth cleaning policy in the following way: [[ID=e6]]# echo 1> / proc / sys / vm / cache_reclaim_enable to enable periodic page cache cleaning # echo 3> / proc / sys / vm / cache_reclaim_s Clean every 3 seconds # echo 360> / proc / sys / vm / cache_reclaim_weight Release 360 page caches per node # echo never > / sys / kernel / mm / transparent_hugepage / defrag Turn off memory fragmentation sorting of transparent huge pages.

[0048] In an optional embodiment, the metric value of the memory pressure metric may also be zero, and the judgment result of the memory saturation is unsaturated. In this case, there is no need to clean the page cache of the system, so there is no need to turn on the periodic page cache cleaning function and turn off the memory fragmentation sorting function of transparent huge pages. This application can be implemented in the following ways: # echo 0 > / proc / sys / vm / cache_reclaim_enable Turn off periodic cache page recycling # echo always > / sys / kernel / mm / transparent_hugepage / defrag Turn on memory fragmentation sorting of transparent huge pages.

[0049] In an optional embodiment, as Figure 6 shown, it includes the following steps: Step S601, after cleaning the page cache corresponding to the file, obtain the current memory usage rate of the system; Among them, this application avoids excessive cleaning through a real-time feedback mechanism. After each cold file's page cache is cleaned, the memory usage rate is immediately detected to form a closed-loop control.

[0050] Step S602, if the current memory usage rate of the system is less than the second threshold, stop the page cache cleaning operation for the aging record; Among them, the second threshold is a safety water level set according to the system's historical usage data, etc. (such as a memory usage rate of 60%). Once it is lower than this value, it stops immediately to prevent invalid operations. For example: after cleaning 3 files, the memory usage rate drops from 95% to 58%, then for the page cache cleaning operation of the aging record, retain the remaining page cache that may be reused.

[0051] Step S603, if the current memory usage rate of the system is greater than or equal to the second threshold, traverse the next file in the aging record to perform the page cache cleaning operation until the current memory usage rate of the system is less than the second threshold.

[0052] Among them, it can be understood that if after cleaning the page cache corresponding to the cold file, the current memory usage rate of the system is still greater than or equal to the second threshold, then it is necessary to continue cleaning the page cache corresponding to the cold file, and traverse the next file in the aging record to perform the page cache cleaning operation until the current memory usage rate of the system is less than the second threshold and stops immediately.

[0053] This application realizes precise page cache cleaning through a "clean - detect - decision" loop. It traverses files one by one instead of cleaning in batches, and combines aging records to ensure that the least active cold file page caches are released first, minimizing interference to business processes and being compatible with scenarios of sudden memory requirements.

[0054] In another optional embodiment, after this application traverses all cold files in the aging record and cleans the page caches to be cleaned, if the memory utilization rate is still less than the second threshold at this time, it stops the loop cleaning of the aging record and executes step S50 above, dynamically cleaning the page cache space of the system through the system's memory pressure metrics and memory saturation.

[0055] In yet another embodiment, if the system receives a stop instruction during the process of dynamically cleaning the page cache space of the system according to the cleaning policy, it closes the periodic page cache cleaning function. This mechanism achieves a balance between automated operation and maintenance and manual intervention, ensuring both the system's autonomous management ability and retaining human control in key scenarios. Exemplarily, this application uses the following method to close the dynamic cache recycling function: # echo 0> / proc / sys / vm / dynamic_pagecache_clean Next, Figure 7 a holistic exemplary description of the technical solution of this application is given: 1. Obtain the memory utilization rate of the system; 2. If the memory utilization rate of the system is greater than or equal to the first threshold, determine whether the aging record is empty; if the memory utilization rate of the system is less than the first threshold, no page cache cleaning operation for the system is performed; 3. If the aging record is empty, obtain the metric value of the memory pressure metric. If the metric value of the memory pressure metric is within a preset first range and the judgment result of memory saturation is unsaturated, then enable the periodic page cache cleaning function and generate a first cleaning policy; If the metric value of the memory pressure metric is within a preset second range and the judgment result of memory saturation is unsaturated, then enable the periodic page cache cleaning function and generate a second cleaning policy; If the metric value of the memory pressure metric is within a preset third range and the judgment result of memory saturation is unsaturated, then enable the periodic page cache cleaning function and generate a third cleaning policy; If the judgment result of memory saturation is saturated, then enable the periodic page cache cleaning function and generate a fourth cleaning policy; If the metric value of the memory pressure metric is zero and the judgment result of memory saturation is unsaturated, then close the periodic page cache cleaning function and enable the memory fragmentation sorting function of transparent huge pages; 4. If the aging record is not empty, traverse the aging record to determine the status of the first cold file. If the status is being accessed, traverse the next cold file in the aging record to perform the page cache cleaning operation; If the status of the cold file is not being accessed, obtain the current first timestamp and the second timestamp when the cold file was last accessed; If the difference between the first timestamp and the second timestamp is greater than or equal to the cache cleaning time of the cold file, clean the page cache corresponding to the cold file; If the difference between the first timestamp and the second timestamp is less than the cache cleaning time of the cold file, traverse the next cold file in the aging record to perform the page cache cleaning operation; After cleaning the page cache corresponding to the file, obtain the current memory usage rate of the system; if the current memory usage rate of the system is less than the second threshold, stop the page cache cleaning operation for the aging record; 5. After performing the page cache cleaning operation on the aging record, obtain the metric value of the memory pressure metric. If the metric value of the memory pressure metric is within the preset first range and the judgment result of the memory saturation is unsaturated, enable the periodic page cache cleaning function and generate the first cleaning policy; If the metric value of the memory pressure metric is within the preset second range and the judgment result of the memory saturation is unsaturated, enable the periodic page cache cleaning function and generate the second cleaning policy; If the metric value of the memory pressure metric is within the preset third range and the judgment result of the memory saturation is unsaturated, enable the periodic page cache cleaning function and generate the third cleaning policy; If the judgment result of the memory saturation is saturated, enable the periodic page cache cleaning function and generate the fourth cleaning policy; If the metric value of the memory pressure metric is zero and the judgment result of the memory saturation is unsaturated, disable the periodic page cache cleaning function and enable the memory fragmentation sorting function of the transparent huge pages.

[0056] 6. If a stop instruction from the user is received during the dynamic cleaning of the page cache space of the system according to the cleaning policy, disable the periodic page cache cleaning function.

[0057] It should be noted that although the operations of the method of the present invention are described in a specific order in the drawings, this does not require or imply that these operations must be performed in that specific order, or that all the operations shown must be performed to achieve the desired result. On the contrary, the steps depicted in the flowchart can be changed in the order of execution.

[0058] Further reference Figure 8, which shows an exemplary structural block diagram of a memory management device 800 for dynamically reclaiming page caches according to an embodiment of the present application. The memory management device 800 of this process includes an acquisition module 801, a determination module 802, a first cleaning module 803, and a second cleaning module 804.

[0059] The acquisition module 801 is used to acquire the memory utilization rate of the system; The determination module 802 is used to determine whether the aging record is empty when the memory utilization rate is greater than or equal to a first threshold. The aging record is used to record cold files of the system in a preset time period; The first cleaning module 803 is used to perform a page cache cleaning operation on the cold files in the aging record based on the status of each file in the aging record and the cache cleaning time when the aging record is not empty; the status of the file is used to indicate whether the file is currently being accessed; The second cleaning module 804 is used to dynamically clean the page cache space of the system based on the memory pressure index and memory saturation of the system.

[0060] In an optional embodiment, the first cleaning module 803 is specifically configured to, if the status of the cold file is being accessed, traverse the next cold file in the aging record to perform the page cache cleaning operation; If the status of the cold file is not being accessed, obtain the current first timestamp and the second timestamp when the cold file was last accessed; If the difference between the first timestamp and the second timestamp is greater than or equal to the cache cleaning time of the cold file, clean the page cache corresponding to the cold file; If the difference between the first timestamp and the second timestamp is less than the cache cleaning time of the cold file, traverse the next cold file in the aging record to perform the page cache cleaning operation.

[0061] In an optional embodiment, it further includes an acquisition and judgment module, which is used to acquire the current memory utilization rate of the system after cleaning the page cache corresponding to the file; If the current memory utilization rate of the system is less than a second threshold, stop the page cache cleaning operation for the aging record; If the current memory utilization rate of the system is greater than or equal to the second threshold, traverse the next file in the aging record to perform the page cache cleaning operation until the current memory utilization rate of the system is less than the second threshold.

[0062] In an optional embodiment, the second cleaning module 804 is specifically configured to obtain the index value of the memory pressure index, compare the index value with a preset index range, and obtain a comparison result; Determine whether to enable the periodic page cache cleaning function and the cleaning policy according to the comparison result and the determination result of the memory saturation degree, and dynamically clean the page cache space of the system according to the cleaning policy.

[0063] In an optional embodiment, the second cleaning module 804 is specifically configured to, if the comparison result is that the index value is within a preset first range and the determination result of the memory saturation degree is unsaturated, enable the periodic page cache cleaning function and generate a first cleaning policy, where the first cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at a first cleaning speed and a first intensity; If the comparison result is that the index value is within a preset second range and the determination result of the memory saturation degree is unsaturated, enable the periodic page cache cleaning function and generate a second cleaning policy, where the second cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at a second cleaning speed and a second intensity, the second cleaning speed is faster than the first cleaning speed, and the second intensity is greater than the first intensity; If the comparison result is that the index value is within a preset third range and the determination result of the memory saturation degree is unsaturated, enable the periodic page cache cleaning function and generate a third cleaning policy, where the third cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at a third cleaning speed and a third intensity and turn off the memory fragmentation sorting function of the transparent huge page, the third cleaning speed is faster than the second cleaning speed, and the third intensity is greater than the second intensity; If the determination result of the memory saturation degree is saturated, enable the periodic page cache cleaning function and generate a fourth cleaning policy, where the fourth cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at a fourth cleaning speed and a fourth intensity and turn off the memory fragmentation sorting function of the transparent huge page, the fourth cleaning speed is faster than the third cleaning speed, and the fourth intensity is greater than the third intensity.

[0064] In an optional embodiment, the second cleaning module 804 is further specifically configured to, if the index value of the memory pressure index is zero and the determination result of the memory saturation degree is unsaturated, turn off the periodic page cache cleaning function and turn on the memory fragmentation sorting function of the transparent huge page.

[0065] In an optional embodiment, it further includes a closing module, configured to turn off the periodic page cache cleaning function if a stop instruction from the user is received during the process of dynamically cleaning the page cache space of the system according to the cleaning policy.

[0066] In an optional embodiment, a determination and formation module is further included, which is used for a user to determine cold files according to historical file access records, where the cold files are files with the number of accesses less than a threshold within a preset time period; Add the cold files to a list, and add corresponding cache cleaning times to the cold files to form the aging records.

[0067] It should be understood that the various units or modules described in the memory management device 800 correspond to the respective steps in the method described with reference to Figure 1 Therefore, the operations and features described above for the method also apply to the memory management device 800 and the units included therein, which will not be elaborated herein. The memory management device 800 can be pre-implemented in the browser or other security applications of an electronic device, or can be loaded into the browser or its security application of the electronic device by means of downloading, etc. The corresponding units in the memory management device 800 can cooperate with the units in the electronic device to implement the solutions of the embodiments of the present application.

[0068] On the other hand, the present application also provides a computer-readable storage medium, which can be the computer-readable storage medium included in the device in the above embodiments; or can exist alone and be a computer-readable storage medium not assembled into the device. The computer-readable storage medium stores one or more programs, and the one or more programs are used by one or more processors to execute the memory management method for dynamically reclaiming page caches described in the present application.

[0069] The above description is only a preferred embodiment of the present application and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solutions formed by the specific combination of the above technical features, and should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the technical solutions formed by mutually replacing the above features with the (but not limited to) technical features with similar functions disclosed in the present application.

Claims

1. A memory management method for dynamically reclaiming page caches, characterized in that The method includes: Obtain the memory utilization rate of the system; If the memory utilization rate is greater than or equal to a first threshold, determine whether the aging record is empty, where the aging record is used to record cold files of the system in a preset time period; If it is not empty, perform a page cache cleaning operation on the cold files in the aging record based on the status and cache cleaning time of each cold file in the aging record; the status of the cold file is used to indicate whether the cold file is currently being accessed; Dynamically clean the page cache space of the system based on the memory pressure index and memory saturation of the system.

2. The method according to claim 1, wherein The performing a page cache cleaning operation on the cold files in the aging record based on the status and cache cleaning time of each cold file in the aging record includes: If the status of the cold file is being accessed, traverse the next cold file in the aging record to perform the page cache cleaning operation; If the status of the cold file is not being accessed, obtain the current first timestamp and the second timestamp when the cold file was last accessed; If the difference between the first timestamp and the second timestamp is greater than or equal to the cache cleaning time of the cold file, clean the page cache corresponding to the cold file; If the difference between the first timestamp and the second timestamp is less than the cache cleaning time of the cold file, traverse the next cold file in the aging record to perform the page cache cleaning operation.

3. The method according to claim 2, wherein The method further includes: After cleaning the page cache corresponding to the file, obtain the current memory utilization rate of the system; If the current memory utilization rate of the system is less than a second threshold, stop the page cache cleaning operation for the aging record; If the current memory utilization rate of the system is greater than or equal to the second threshold, traverse the next file in the aging record to perform the page cache cleaning operation until the current memory utilization rate of the system is less than the second threshold.

4. The method according to claim 1, wherein The dynamically cleaning the page cache space of the system based on the memory pressure index and memory saturation of the system includes: Obtain the index value of the memory pressure index, compare the index value with a preset index range to obtain a comparison result; Determine whether to enable the periodic page cache cleaning function and the cleaning policy according to the comparison result and the judgment result of the memory saturation, and dynamically clean the page cache space of the system according to the cleaning policy.

5. The method according to claim 4, wherein Determining whether to enable the periodic page cache cleaning function and the cleaning policy according to the comparison result and the judgment result of the memory saturation includes: If the comparison result is that the index value is within a preset first range and the judgment result of the memory saturation is unsaturated, enable the periodic page cache cleaning function and generate a first cleaning policy, where the first cleaning policy is to perform a page cache cleaning operation on the page cache space of the system at a first cleaning speed and a first intensity; If the comparison result is that the index value is within a preset second range and the judgment result of the memory saturation is unsaturated, then the periodic page cache cleaning function is enabled and a second cleaning policy is generated. The second cleaning policy is to perform a page cache cleaning operation on the page cache space of the system according to a second cleaning speed and a second intensity. The second cleaning speed is faster than the first cleaning speed, and the second intensity is greater than the first intensity; If the comparison result is that the index value is within a preset third range and the judgment result of the memory saturation is unsaturated, then the periodic page cache cleaning function is enabled and a third cleaning policy is generated. The third cleaning policy is to perform a page cache cleaning operation on the page cache space of the system according to a third cleaning speed and a third intensity and turn off the memory fragmentation sorting function of the transparent huge pages. The third cleaning speed is faster than the second cleaning speed, and the third intensity is greater than the second intensity; If the judgment result of the memory saturation is saturated, then the periodic page cache cleaning function is enabled and a fourth cleaning policy is generated. The fourth cleaning policy is to perform a page cache cleaning operation on the page cache space of the system according to a fourth cleaning speed and a fourth intensity and turn off the memory fragmentation sorting function of the transparent huge pages. The fourth cleaning speed is faster than the third cleaning speed, and the fourth intensity is greater than the third intensity.

6. The method according to claim 5, characterized in that The method further includes: If the index value of the memory pressure index is zero and the judgment result of the memory saturation is unsaturated, then the periodic page cache cleaning function is turned off and the memory fragmentation sorting function of the transparent huge pages is enabled.

7. The method according to claim 4, wherein The method further includes: During the process of dynamically cleaning the page cache space of the system according to the cleaning policy, if a stop instruction from the user is received, then the periodic page cache cleaning function is turned off.

8. The method according to claim 1, characterized in that The method further includes: The user determines cold files according to the historical file access records. The cold files are files with the number of accesses less than a number threshold within a preset time period; Add the cold files to a list and add corresponding cache cleaning times to the cold files to form the aging record.

9. A memory management device for dynamically reclaiming page caches, characterized in that, The device includes: An acquisition module, configured to acquire the memory usage rate of the system; A determination module, configured to determine whether the aging record is empty when the memory usage rate is greater than or equal to a first threshold. The aging record is used to record the cold files of the system within a preset time period; A first cleaning module, configured to perform a page cache cleaning operation on the cold files in the aging record based on the status and cache cleaning times of the files in the aging record when the aging record is not empty; the status of the file is used to indicate whether the file is currently being accessed; A second cleaning module, configured to dynamically clean the page cache space of the system based on the memory pressure index and memory saturation of the system.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Cache recovery method and device

    CN105446814A

  • Method and device for regularly recycling linux cache

    CN113986540A

  • Memory recovery method and device, equipment, medium and product

    CN118363879A

  • Method and device for recycling cold memory page of operating system

    CN118672768A

  • Automated TTL adjustment using cache performance and purge data

    US20190281129A1

Cited By

  • Memory resident data management method based on big data architecture

    CN121166574A

  • Transparent large page fault processing method

    CN121880084A