Operating system-oriented memory recovery method, device and equipment and storage medium
By monitoring the system memory pressure indicator and dynamically adjusting the memory recycling strategy, the problem of reduced responsiveness of the Linux kernel under high memory pressure is solved, and the system stability and efficiency are improved.
Patent Information
- Application Number
- CN202510839092.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-20
- Publication Date
- 2025-10-03
AI Technical Summary
The existing Linux kernel is unable to effectively reclaim memory in a timely manner under high memory pressure scenarios, resulting in decreased system responsiveness and process blocking, which is particularly evident in cloud computing, databases, and real-time systems.
By monitoring the system memory pressure indicators, you can flexibly select targeted memory recovery strategies, including adjusting the watermark, asynchronous memory recovery mechanism, and process control, and dynamically adjust memory utilization to avoid resource waste and lag.
It improves the stability and efficiency of the system, avoids resource waste, ensures the system runs smoothly under high memory pressure, and enhances the user experience.
Smart Images

Figure CN120743798A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing, specifically to operating system technical fields such as memory management and memory recycling, and more particularly to a memory recycling method, device, electronic device, computer-readable storage medium, and computer program product for an operating system. Background Art
[0002] Existing Linux kernel memory reclamation and tuning methods mainly rely on two methods: the kernel swap daemon (Kswapd) and direct memory reclamation (Direct Reclaim) executed in the process context.
[0003] Kswapd reclaims memory by periodically checking the free memory in each memory zone in the current system. Direct memory reclamation is a synchronous memory reclamation process performed by a process when it cannot obtain memory through the lightweight fast path.
[0004] In latency-sensitive application scenarios such as cloud computing, databases, and real-time systems, when encountering intermittent, short-lived high memory pressure, existing memory reclamation methods are unable to effectively reclaim memory in a timely manner. At the same time, a large number of processes will be blocked from performing synchronous reclamation, resulting in a sharp decline in the overall responsiveness of the system.
[0005] How to avoid and alleviate the system performance degradation and lag caused by a large number of processes being blocked from executing memory synchronous recycling in high memory pressure scenarios is an urgent problem that technicians in this field need to solve. Summary of the Invention
[0006] The embodiments of the present disclosure propose a memory recovery method, device, electronic device, computer-readable storage medium and computer program product for an operating system, which flexibly selects targeted recovery strategies to reclaim memory by monitoring various pressure indicators of system memory.
[0007] In the first aspect, an embodiment of the present disclosure proposes a memory recovery method for an operating system, comprising: obtaining actual operating parameters of the memory during the operation of the target Linux operating system; wherein the actual operating parameters include at least: actual available cache; determining memory abnormality items based on the actual operating parameters and preset parameter thresholds; executing a recovery processing strategy that matches the memory abnormality items to obtain a memory recovery result.
[0008] In the second aspect, an embodiment of the present disclosure proposes a memory recovery device for an operating system, including: a parameter acquisition module, configured to obtain the actual operating parameters of the memory during the operation of the target Linux operating system; wherein the actual operating parameters include at least: the actual available cache; an abnormality determination module, configured to determine the memory abnormality item based on the actual operating parameters and a preset parameter threshold; a memory recovery module, configured to execute a recovery processing strategy that matches the memory abnormality item to obtain a memory recovery result.
[0009] In a third aspect, an embodiment of the present disclosure provides an electronic device comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can implement the operating system-oriented memory recovery method described in the first aspect when executing the instructions.
[0010] In a fourth aspect, an embodiment of the present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, which are used to enable a computer to implement the operating system-oriented memory recovery method described in the first aspect when executed.
[0011] In a fifth aspect, an embodiment of the present disclosure provides a computer program product comprising a computer program, which, when executed by a processor, can implement the various steps of the memory recovery method for an operating system as described in the first aspect.
[0012] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Other features, objects and advantages of the present disclosure will become more apparent from a reading of the detailed description of non-limiting embodiments made with reference to the following drawings: Figure 1 is an exemplary system architecture in which the present disclosure may be applied; Figure 2 A flowchart of a memory recovery method for an operating system provided in an embodiment of the present disclosure; Figure 3 A flowchart of another memory recovery method for an operating system provided in an embodiment of the present disclosure; Figure 4a 、 Figure 4b 、 Figure 4c and Figure 4d These are schematic diagrams related to a memory recycling optimization method specifically for a Linux operating system in an application scenario provided by an embodiment of the present disclosure; Figure 5 A structural block diagram of a memory recycling device for an operating system provided in an embodiment of the present disclosure; Figure 6 A schematic structural diagram of an electronic device suitable for executing an operating system-oriented memory recycling method provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0014] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those skilled in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description. It should be noted that the embodiments in the present disclosure and the features in the embodiments can be combined with each other unless there is a conflict.
[0015] In the technical solutions disclosed herein, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0016] Figure 1 An exemplary system architecture 100 is shown to which embodiments of the operating system-oriented memory reclamation method, apparatus, electronic device, and computer-readable storage medium disclosed herein can be applied.
[0017] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. Network 104 is a medium for providing communication links between terminal devices 101, 102, 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0018] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various applications for enabling information communication between the terminal devices 101, 102, and 103 and server 105 can be installed, such as memory management applications, search applications, and instant messaging applications.
[0019] Terminal devices 101, 102, 103 and server 105 can be either hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices with display screens, including but not limited to smartphones, tablet computers, laptop computers, and desktop computers. When terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above. They can be implemented as multiple software or software modules, or as a single software or software module, and are not specifically limited here. When server 105 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the server is software, it can be implemented as multiple software or software modules, or as a single software or software module, and are not specifically limited here.
[0020] A memory management application may be installed in the operating systems running on the terminal devices 101 , 102 , 103 and the server 105 , and the memory management application may be used to recycle memory data in the operating systems running on the devices.
[0021] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0022] Please refer to Figure 2 , Figure 2 This is a flowchart of a memory recovery method for an operating system provided by an embodiment of the present disclosure, wherein process 200 includes the following steps: Step 201: Acquire actual operating parameters of the memory during the operation of the target Linux operating system.
[0023] In this embodiment, the execution subject (eg Figure 1 The terminal devices 101, 102, 103 or the server 105 shown can use a command line tool to obtain actual operating parameters of the memory during the operation of the target Linux operating system. The actual operating parameters of the memory include at least one of the actual available cache, the actual available swap space, and the actual available memory.
[0024] Step 202: Determine memory abnormality items based on actual operating parameters and preset parameter thresholds.
[0025] In this embodiment, the execution entity determines a memory anomaly based on the actual operating parameters obtained in step 202 and a preset parameter threshold. The memory anomaly includes low actual available cache, low actual available swap space, and low actual available memory, and the preset parameter thresholds include an available cache threshold, an available swap space threshold, and an available memory threshold. For example, when the actual available cache is less than the preset available cache threshold, the memory anomaly is low actual available cache.
[0026] Step 203: Execute the recycling processing strategy that matches the memory exception item to obtain a memory recycling result.
[0027] In this embodiment, after determining the memory anomaly, the execution subject executes the recycling policy that matches the memory anomaly to obtain a memory recycling result. The correspondence between the memory anomaly and the recycling policy is preset in advance, and the memory recycling result is the operating state of the target Linux operating system memory after executing the recycling policy.
[0028] In this embodiment, the execution subject may determine the recycling processing strategy according to the preset correspondence between the memory abnormality item and the recycling processing strategy, and execute the recycling processing strategy to obtain the memory recycling result.
[0029] The memory recovery method for an operating system provided by the embodiment of the present disclosure determines memory anomalies based on the actual operating parameters of the memory and preset parameter thresholds, and then executes a recovery processing strategy that matches the memory anomalies to obtain a memory recovery result. This method monitors various pressure indicators of the system memory and flexibly selects a targeted recovery strategy to recycle the memory, thereby avoiding resource waste and improving system stability and efficiency.
[0030] The above embodiment describes the memory recovery solution provided by the Linux operating system as an example. When the actual conditions of other operating systems do not differ significantly or substantially from the Linux operating system, the memory recovery solution provided by the above embodiment can also be applied to other operating systems after adaptive modification.
[0031] Please refer to Figure 3 , Figure 3 This is a flowchart of another memory recovery method for an operating system provided by an embodiment of the present disclosure, wherein process 300 includes the following steps: Step 301: Acquire actual operating parameters of the memory during the operation of the target Linux operating system.
[0032] Step 301 is similar to Figure 2 The step 201 shown is the same, and for the same content, please refer to the corresponding part of the previous embodiment, which will not be repeated here.
[0033] Step 302: Compare the actual available buffer with a preset available buffer threshold.
[0034] In this embodiment, the execution entity compares the actual available cache with a preset available cache threshold, where the preset available cache threshold refers to a preset available cache standard.
[0035] Step 303: In response to the actual available buffer being less than the available buffer threshold, determining the low actual available buffer as a memory abnormality item.
[0036] In this embodiment, when the actual available cache is less than the available cache threshold, the execution entity determines the low actual available cache as a memory abnormality item.
[0037] Step 304: Determine a first target recycling size based on the actual available cache and the available cache threshold.
[0038] In this embodiment, the execution entity determines a first target reclaim size based on the actual available cache and the available cache threshold. Specifically, the execution entity subtracts the actual available cache from the available cache threshold and determines the resulting difference as the first target reclaim size. The first target reclaim size refers to the amount of memory capacity planned to be reclaimed in this memory reclamation.
[0039] Step 305: The process whose actual memory usage exceeds a preset memory usage or whose actual memory usage ratio exceeds a preset ratio threshold is stored as a first target process in a preset first control group.
[0040] In this embodiment, the execution entity stores processes whose actual memory usage exceeds a preset amount or whose actual memory usage ratio exceeds a preset ratio threshold as first target processes in a preset first control group. The first target processes are processes requiring memory reclamation, and the preset first control group groups processes requiring memory reclamation for centralized management.
[0041] In this embodiment, the execution entity may store a process whose actual memory usage exceeds a preset memory usage as a first target process in a preset first control group. For example, if the preset memory usage of process A is 100MB and the actual memory usage is 110MB, process A will be stored as the first target process in the preset first control group.
[0042] In this embodiment, the execution entity may also store processes whose actual memory usage exceeds a preset threshold as first target processes in a preset first control group. For example, if the preset threshold for memory usage of process B is 5% and the actual usage is 6%, process B will be stored as the first target process in the preset first control group.
[0043] Step 306 : reclaiming memory for each first target process in the first control group according to a preset ratio or a preset size, and removing each first target process from the first control group when the reclaimed memory size is not less than the first target reclaim size.
[0044] In this embodiment, the execution entity reclaims memory for each first target process in the first control group at a preset ratio or size, and removes each first target process from the first control group when the reclaimed memory size is not less than the first target reclaim size. The memory reclaim operations performed at the preset ratio or size do not affect the normal operation of the first target process. The preset ratio or size is calculated based on the actual memory usage of each first target process and the first target reclaim size.
[0045] In this embodiment, the execution entity can reclaim memory for each first target process in the first control group at a preset ratio. For example, if the first control group includes first target processes A, B, and C, and a total of 100MB of memory is reclaimed, and the preset reclaim ratio for process A is 20%, the preset reclaim ratio for process B is 30%, and the preset reclaim ratio for process C is 50%, then process A needs to reclaim 20MB of memory, process B needs to reclaim 30MB of memory, and process C needs to reclaim 50MB of memory.
[0046] In this embodiment, the execution subject may also reclaim memory of each first target process in the first control group according to a preset size. For example, if the preset memory reclaim size is 50M, then 50M of memory is reclaimed for each of the first target processes A, B, and C in the first control group.
[0047] Step 307: In response to the kernel swap daemon process triggered after obtaining the memory reclamation result actually occupying the CPU exceeding a preset occupancy threshold, an asynchronous kernel object cache reclamation mechanism and an asynchronous least recently used page reclamation mechanism are started.
[0048] In this embodiment, when the actual CPU usage of the kernel swap daemon process triggered after obtaining the memory reclamation result exceeds a preset usage threshold, an asynchronous kernel object cache reclamation mechanism and an asynchronous least recently used page reclamation mechanism are activated. The asynchronous kernel object cache reclamation mechanism improves the memory utilization efficiency and performance of the operating system by asynchronously reclaiming no longer needed memory, and the asynchronous least recently used page reclamation mechanism releases memory resources by asynchronously clearing inactive processes, thereby performing memory reclamation without affecting other tasks to optimize the memory utilization and performance of the system.
[0049] The actual operating parameters of the memory during the operation of the target Linux operating system may include the actual available swap space. At this time, the specific implementation method for determining the memory abnormality item based on the actual operating parameters and the preset parameter threshold is as follows: compare the actual available swap space with the preset available swap space threshold; when the actual available swap space is less than the available swap space threshold, determine the low actual available swap space as a memory abnormality item; determine the second target recovery size based on the actual available swap space and the available swap space threshold; store the processes in the memory with an actual priority lower than the preset priority as the second target process in the preset second control group; swap out the memory data in the inactive memory pages of each second target process in the second control group from the swap space of the memory to the swap space of the disk, and remove each second target process from the second control group when the size of the swapped memory data is not less than the second target recovery size. This method effectively recycles memory by dynamically adjusting the process priority and memory swap strategy, avoiding system crashes or performance degradation due to insufficient memory, and ensuring that the system can run smoothly when the memory pressure is too high.
[0050] The actual operating parameters of the memory during the operation of the target Linux operating system may include actual available memory. At this time, the specific implementation method of determining the memory abnormality item based on the actual operating parameters and the preset parameter threshold is as follows: compare the actual available memory with the preset available memory threshold; when the actual available memory is less than the available memory threshold, determine the low actual available memory as a memory abnormality item; determine the third target recovery size based on the actual available memory and the available memory threshold; based on the original water level line of each area in the memory, raise the water level line according to the third target recovery size, so that the kernel swap daemon performs corresponding memory recovery operations on each area in the memory according to the raised water level line to obtain the memory recovery result, that is, by adjusting the water level line and performing the memory recovery operation, the memory is recovered in time to avoid the system from falling into deep lag.
[0051] After executing the recycling processing strategies corresponding to low actual available cache, low actual available swap space and low actual available memory respectively according to the above embodiments and obtaining the memory recycling results, the effectiveness of eliminating the memory exception item can also be determined according to the memory recycling results, that is, whether the memory exception item has been successfully eliminated according to the memory recycling results; when it is determined according to the elimination effectiveness that the memory exception item has not been successfully eliminated, the backup recycling processing strategy that matches the memory exception item is executed, that is, when the memory exception item is not successfully eliminated, the backup recycling processing strategy is executed; when the memory exception item is successfully eliminated by executing the backup recycling processing strategy that matches the memory exception item, the matching priority between the backup recycling processing strategy and the memory exception item is increased, that is, after the recycling strategy successfully eliminates the memory exception item, the priority of the strategy is increased to enhance the effectiveness of future processing, improve the efficiency of memory recycling, and enhance the user experience.
[0052] In this embodiment, different from Figure 2 In the illustrated embodiment, step 301 corresponds to step 201. Steps 302-303 provide a specific implementation method for determining memory anomalies, and steps 304-306 provide a specific implementation method for executing a recycling strategy. There is no causal or dependency relationship between the two implementation methods, and they do not necessarily need to be applied simultaneously in the same embodiment. They can be applied separately in different embodiments to determine memory anomalies or to execute a recycling strategy as needed. This embodiment exists only as a preferred embodiment that simultaneously includes both specific implementation methods.
[0053] The memory recovery method for the operating system provided in this embodiment determines memory anomalies by comparing actual operating parameters with preset parameter thresholds, and executes a recovery processing strategy that matches the memory anomalies to obtain memory recovery results. By monitoring various pressure indicators of the system memory, a targeted recovery strategy is flexibly selected to recycle the memory, thereby avoiding resource waste and improving the stability and efficiency of the system. When the available memory is small, the water level lines of various areas in the memory are adjusted to recycle the memory in a timely manner to avoid the system from falling into deep freeze. In addition, the recovery strategy that has the least impact on the user's current experience and the operation of system applications can be given priority to improve the user experience.
[0054] To deepen understanding, this disclosure also combines a specific application scenario and provides a memory recovery optimization method specifically for the Liunx operating system. This optimization method mainly consists of two components: a memory monitoring daemon (Mem-Monitor-Daemon) that monitors the overall memory status of the system and a memory diagnostic daemon (Mem-Tune-Daemon).
[0055] The overall technical implementation plan of this function is as follows Figure 4a and Figure 4b As shown, the overall working process is as follows: 1. Monitor system memory pressure-related indicators. After the memory monitoring daemon is started, it actively monitors the system memory pressure. At this time, it determines whether it is in a new information collection cycle. If not, it updates the information collection time and waits for the next wake-up. If it is in a new information collection cycle, it collects and calculates the system's memory data through the interface, such as memory usage, available memory, cache (cache or available cache, equivalent to the actual available cache mentioned in the above embodiment) memory, swap (using hard disk space to simulate extended memory when physical memory is insufficient) memory, PSI (provides monitoring information on system resource pressure), number of dentry (currently active file directory entries in memory), Kswapd (memory recovery process in the Linux kernel), etc., and sends this memory data to the memory monitoring daemon for analysis and diagnosis.
[0056] 2. Receive memory metrics and evaluate memory status. The memory diagnostic daemon receives memory metrics from the memory monitoring daemon through the listening channel, compares and analyzes these memory data with the user-set memory thresholds, and diagnoses the current system's memory status and memory pressure.
[0057] 3. Calculate memory targets and execute recycling strategies. Based on the current system memory status diagnosed, the memory diagnostic daemon will take memory recycling actions before memory pressure reaches a critical point. Based on predefined memory recycling methods and tuning strategies, it performs targeted memory recycling actions, such as Watermark Adjuse (adjusting memory watermarks), MemcgReclaim (memory control group recycling), Kill Adj>900Task (reclaiming unimportant processes), asynchronous Shrink Slab (the kernel object cache recycling mechanism mentioned in the above embodiment), and asynchronous Shrink LRU (the least recently used page recycling mechanism mentioned in the above embodiment). By bringing recycling actions forward, it alleviates the problem of delayed memory recycling that may occur with Kswapd and direct memory recycling, and avoids system performance regression, freezing, or triggering of the kernel OOM Killer (Out-Of-Memory Killer, an automatic mechanism in the Linux kernel that frees up memory by ending processes that occupy too much memory to ensure continued system operation) due to memory exhaustion or memory shortage.
[0058] 4. Notification system. After the memory diagnostic daemon completes memory reclamation, it updates the information collection time, waits for the next wake-up, and integrates the relevant results (execution strategy, reclaimed memory amount, current memory status) into the customer's IT operations and maintenance system via Grafana (a data visualization and monitoring tool). This helps customers analyze system operating status and make targeted adjustments during subsequent system operations.
[0059] Further references Figure 4c The following describes how to determine the memory recycling strategy based on the current system memory information: Step 1: The memory monitoring daemon process collects statistics on the current system memory information.
[0060] Step 2: The memory diagnostic daemon receives current memory information.
[0061] Step 3: Determine whether the memory usage in the current system memory information is higher than the threshold. If yes, jump to step 4; otherwise, jump to step 9.
[0062] Step 4: Determine whether the available memory is lower than the threshold. If so, calculate the amount of missing memory and increase the watermark based on the amount of missing memory. Then jump to step 8; otherwise, jump to step 5.
[0063] Step 5: Determine whether the cache memory is lower than the threshold. If so, filter users with high memory usage and add them to a Cgroup (a control group is a mechanism in the Linux kernel that manages and limits process resource usage to ensure that system resources are properly allocated). Execute the Memcg Reclaim command for the processes in the Cgroup and then jump to Step 8. If not, jump to Step 6.
[0064] Step 6: Determine whether Swap Used (the size of the swap space currently used by the system, which reflects whether the system memory is facing pressure) is lower than the threshold. If so, select the user with the highest priority and add them to the Cgroup. Then swap out the Inactive Anon Pages (inactive anonymous memory pages) of the processes in the Cgroup to the swap space, and then jump to Step 8; otherwise, jump to Step 7.
[0065] Step 7: Determine whether Kswapd occupies too much CPU. If so, determine that the overall system load is too high. If the load is too high, enable asynchronous Shrink Slab and asynchronous Shrink LRU. If the load is not too high, jump to step 9.
[0066] Step 8: Determine whether the memory status is restored. If yes, jump to step 9; if not, jump to step 1.
[0067] Step 9: Memory recycling is completed successfully and the system waits for the next diagnostic signal.
[0068] Further references Figure 4dThis paper discloses a memory reclamation method for when cache memory falls below a threshold. Specifically, it determines whether cache memory is below the threshold. If so, it calculates the cache memory to be reclaimed. It then adds processes with Adj > 800 to a Cgroup. The amount of memory to be reclaimed for each process is calculated based on the memory usage ratio. It then executes Memcg Reclaim to calculate the memory reclaimed. The process is then removed from the Cgroup. Finally, the reclamation result is returned and the memory status is updated.
[0069] This implementation provides a specific memory recycling optimization method for the Linux operating system. It determines memory anomalies by comparing actual operating parameters with preset parameter thresholds, and executes recycling processing strategies that match the memory anomalies to obtain memory recycling results. By monitoring various pressure indicators of the system memory, it flexibly selects targeted recycling strategies to recycle memory, thus avoiding resource waste and improving system stability and efficiency. When the available memory is small, the water level lines of various areas in the memory are adjusted to recycle the memory in a timely manner to avoid the system from falling into deep lag. In addition, it can also give priority to the recycling strategy that has the least impact on the user's current experience and the operation of system applications to improve the user experience.
[0070] Further references Figure 5 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a memory recovery device for an operating system. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0071] like Figure 5 As shown, the operating system-oriented memory recovery device 500 of this embodiment may include: a parameter acquisition module 501, an anomaly determination module 502, and a memory recovery module 503. The parameter acquisition module 501 is configured to obtain actual operating parameters of the memory during the operation of the target Linux operating system; the actual operating parameters include at least actual available cache; the anomaly determination module 502 is configured to determine memory anomalies based on the actual operating parameters and preset parameter thresholds; and the memory recovery module 503 is configured to execute a recovery processing strategy that matches the memory anomaly to obtain a memory recovery result.
[0072] The specific processing of the parameter acquisition module 501, the abnormality determination module 502 and the memory recovery module 503 mentioned above and the technical effects thereof can be referred to in the respective Figure 2 The relevant descriptions of steps 201-203 in the corresponding embodiment are not repeated here.
[0073] In some optional implementations of this embodiment, the anomaly determination module 502 includes: a first threshold comparison unit configured to compare the actual available cache with a preset available cache threshold; the first anomaly determination unit configured to, in response to the actual available cache being less than the available cache threshold, determine the low actual available cache as a memory anomaly. The memory reclaim module 503 includes: a first reclaim size determination unit configured to determine a first target reclaim size based on the actual available cache and the available cache threshold; a first control unit configured to store processes whose actual memory usage exceeds a preset usage or whose actual usage ratio exceeds a preset ratio threshold as first target processes in a preset first control group; the first memory reclaim unit configured to reclaim memory for each first target process in the first control group according to a preset ratio or preset size, and remove each first target process from the first control group when the reclaimed memory size is not less than the first target reclaim size; wherein the memory reclaim operations performed according to the preset ratio or preset size do not affect the normal operation of the first target process, and the preset ratio or preset size is calculated based on the actual memory usage ratio of each first target process and the first target reclaim size.
[0074] In some optional implementations of this embodiment, the abnormality determination module 502 includes: a second threshold comparison unit, configured to compare the actual available swap space with a preset available swap space threshold, and the actual operating parameters also include the actual available swap space; the second abnormality determination unit, configured to, in response to the actual available swap space being less than the available swap space threshold, determine the low actual available swap space as a memory abnormality item. The memory recovery module 503 includes: a second recovery size determination unit, configured to determine a second target recovery size based on the actual available swap space and the available swap space threshold; a second control unit, configured to store processes in the memory whose actual priority is lower than the preset priority as second target processes in a preset second control group; a second memory recovery unit, configured to swap out memory data in inactive memory pages of each second target process in the second control group from the swap space of the memory to the swap space of the disk, and remove each second target process from the second control group when the size of the swapped memory data is not less than the second target recovery size.
[0075] In some optional implementations of this embodiment, the abnormality determination module 502 includes: a third threshold comparison unit, configured to compare the actual available memory with a preset available memory threshold, and the actual operating parameters also include the actual available memory; the third abnormality determination unit, configured to, in response to the actual available memory being less than the available memory threshold, determine the low actual available memory as a memory abnormality item. The memory recovery module 503 includes: a third recovery size determination unit, configured to determine a third target recovery size based on the actual available memory and the available memory threshold; the third memory recovery unit, configured to raise the watermark of each area in the memory based on the original watermark according to the third target recovery size, so that the kernel swap daemon performs corresponding memory recovery operations on each area in the memory according to the raised watermark to obtain a memory recovery result.
[0076] In some optional implementations of this embodiment, the memory recovery device 500 for the operating system also includes: an effect determination unit, configured to determine the effectiveness of eliminating the memory exception item based on the memory recovery result; a backup recovery unit, configured to execute a backup recovery processing strategy that matches the memory exception item in response to determining that the memory exception item has not been successfully eliminated based on the elimination effectiveness; and a priority adjustment unit, configured to increase the matching priority between the backup recovery processing strategy and the memory exception item in response to successfully eliminating the memory exception item by executing the backup recovery processing strategy that matches the memory exception item.
[0077] In some optional implementations of this embodiment, the memory recovery device 500 for the operating system also includes: an asynchronous recovery unit, which is configured to start an asynchronous kernel object cache recovery mechanism and an asynchronous least recently used page recovery mechanism in response to the actual CPU occupancy of the kernel swap daemon process triggered after obtaining the memory recovery result exceeding a preset occupancy threshold.
[0078] This embodiment exists as a device embodiment corresponding to the above-mentioned method embodiment. The memory recovery device for the operating system provided by this embodiment determines the memory abnormality item by comparing the actual operating parameters with the preset parameter threshold, and executes the recovery processing strategy that matches the memory abnormality item to obtain the memory recovery result. By monitoring the various pressure indicators of the system memory, it flexibly selects a targeted recovery strategy to recycle the memory, thereby avoiding resource waste and improving the stability and efficiency of the system. When the available memory is small, the water level lines of each area in the memory are adjusted, so as to recycle the memory in time and avoid the system from falling into deep freeze. In addition, it can also give priority to the recovery strategy that has the least impact on the user's current experience and the operation of system applications to improve the user experience.
[0079] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can implement the memory recovery method for the operating system described in any of the above embodiments when executing.
[0080] According to an embodiment of the present disclosure, the present disclosure further provides a readable storage medium storing computer instructions, which are used to enable a computer to implement the memory recovery method for an operating system described in any of the above embodiments when executed.
[0081] According to an embodiment of the present disclosure, the present disclosure further provides a computer program product, which, when executed by a processor, can implement the memory recycling method for an operating system described in any of the above embodiments.
[0082] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are provided as examples only and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0083] like Figure 6 As shown, device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 into a random access memory (RAM) 603. RAM 603 may also store various programs and data required for the operation of device 600. Computing unit 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to bus 604.
[0084] Multiple components in device 600 are connected to I / O interface 605, including: input unit 606, such as a keyboard, mouse, etc.; output unit 607, such as various types of displays, speakers, etc.; storage unit 608, such as a magnetic disk, optical disk, etc.; and communication unit 609, such as a network card, modem, wireless communication transceiver, etc. Communication unit 609 allows device 600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0085] The computing unit 601 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 601 performs the various methods and processes described above, such as the memory reclamation method for the operating system. For example, in some embodiments, the memory reclamation method for the operating system can be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 608. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the memory reclamation method for the operating system described above can be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to execute the steps of the memory reclamation method for the operating system in any other appropriate manner (eg, by means of firmware).
[0086] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0087] The program code for implementing the method of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0088] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fibers, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0089] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0090] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0091] A computer system may include a client and a server. The client and server are generally remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers and establishing a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host. This is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and virtual private server (VPS) services.
[0092] According to the technical solution of the embodiment of the present disclosure, memory anomalies are determined by comparing actual operating parameters with preset parameter thresholds, and a recycling processing strategy that matches the memory anomaly is executed to obtain a memory recycling result. By monitoring various pressure indicators of the system memory, a targeted recycling strategy is flexibly selected to recycle the memory, thereby avoiding resource waste and improving the stability and efficiency of the system. When the available memory is small, the water level lines of various areas in the memory are adjusted to recycle the memory in a timely manner to avoid the system from falling into a deep freeze. In addition, the recycling strategy that has the least impact on the user's current experience and the operation of system applications can be given priority to improve the user experience.
[0093] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not a limitation herein.
[0094] The above specific embodiments do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the scope of protection of this disclosure.
Claims
1. A memory recovery method for an operating system, comprising: Acquire actual operating parameters of the memory during the operation of the target Linux operating system; wherein the actual operating parameters at least include: actual available cache; Determining memory abnormality items based on the actual operating parameters and preset parameter thresholds; Execute a recycling processing strategy that matches the memory exception item to obtain a memory recycling result.
2. The method according to claim 1, wherein The determining of the memory abnormality item according to the actual operating parameter and the preset parameter threshold includes: Comparing the actual available cache with a preset available cache threshold; In response to the actual available buffer being less than the available buffer threshold, determining low actual available buffer as a memory abnormality item; The executing a recycling processing strategy matching the memory exception item to obtain a memory recycling result includes: determining a first target reclaim size according to the actual available cache and the available cache threshold; storing the process whose actual memory usage exceeds a preset memory usage or whose actual memory usage ratio exceeds a preset ratio threshold as a first target process in a preset first control group; Memory is reclaimed for each first target process in the first control group according to a preset ratio or preset size, and each first target process is removed from the first control group when the reclaimed memory size is not less than the first target reclaim size; wherein, the memory reclaiming operations performed according to the preset ratio or the preset size do not affect the normal operation of the first target process.
3. The method according to claim 2, wherein: The preset ratio or the preset size is calculated based on the actual memory occupation ratio of each first target process and the first target recovery size.
4. The method according to claim 1, wherein The actual operating parameters also include the actual available swap space, The determining of the memory abnormality item according to the actual operating parameter and the preset parameter threshold includes: Comparing the actual available swap space with a preset available swap space threshold; In response to the actual available swap space being less than the available swap space threshold, determining low actual available swap space as a memory exception item; The executing a recycling processing strategy matching the memory exception item to obtain a memory recycling result includes: determining a second target reclaim size according to the actual available swap space and the available swap space threshold; storing the processes in the memory whose actual priority is lower than the preset priority as second target processes in a preset second control group; Swap out memory data in the inactive memory pages of each second target process in the second control group from the swap space of the memory to the swap space of the disk, and move each second target process out of the second control group when the size of the swapped memory data is not less than the second target recycle size.
5. The method according to claim 1, wherein The actual operating parameters also include actual available memory, The determining of the memory abnormality item according to the actual operating parameter and the preset parameter threshold includes: Comparing the actual available memory with a preset available memory threshold; In response to the actual available memory being less than the available memory threshold, determining low actual available memory as a memory abnormality item; The executing a recycling processing strategy matching the memory exception item to obtain a memory recycling result includes: determining a third target reclaim size according to the actual available memory and the available memory threshold; Based on the original watermarks of each area in the memory, the watermarks are raised according to the third target recovery size, so that the kernel swap daemon process performs corresponding memory recovery operations on each area in the memory according to the raised watermarks to obtain the memory recovery result.
6. The method according to claim 1, further comprising: Determining the effectiveness of eliminating the memory abnormality item according to the memory recovery result; In response to determining, based on the elimination effectiveness, that the memory exception item is not successfully eliminated, executing a backup recycling processing strategy that matches the memory exception item.
7. The method according to claim 6, further comprising: In response to successfully eliminating the memory exception item by executing the backup reclaim processing policy that matches the memory exception item, the matching priority between the backup reclaim processing policy and the memory exception item is increased.
8. The method according to any one of claims 1 to 7, wherein: After executing the recycling processing strategy matching the memory exception item, the method further includes: In response to the actual CPU occupancy of the kernel swap daemon process triggered after obtaining the memory reclamation result exceeding a preset occupancy threshold, an asynchronous kernel object cache reclamation mechanism and an asynchronous least recently used page reclamation mechanism are started.
9. A memory recovery device for an operating system, comprising: The parameter acquisition module is configured to obtain actual operating parameters of the memory during the operation of the target Linux operating system; wherein the actual operating parameters at least include: actual available cache; an abnormality determination module, configured to determine a memory abnormality item based on the actual operating parameters and a preset parameter threshold; The memory recovery module is configured to execute a recovery processing strategy that matches the memory exception item to obtain a memory recovery result.
10. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the memory recycling method for an operating system according to any one of claims 1 to 8.
11. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute the memory reclamation method for an operating system according to any one of claims 1 to 8.
12. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the steps of the memory reclamation method for an operating system according to any one of claims 1 to 8.
Citation Information
Patent Citations
Memory recycle method and device
CN107220076A
Memory recovery method and device, computer device and computer readable storage medium
CN110018901A
Method and device for regularly recycling linux cache
CN113986540A
Memory recovery method and device, electronic equipment and storage medium
CN115421907A
Cache recovery method and device, electronic equipment and storage medium
CN115437788A