Memory reclaiming method and apparatus, electronic device, storage medium, and program product

By setting multi-level memory watermark thresholds in kernel mode, determining memory reclamation strategies, and performing memory reclamation, we resolve system instability issues caused by memory overflows and improve system performance and online business responsiveness.

WO2025202758A1PCT designated stage Publication Date: 2025-10-02CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD

Patent Information

Application Number
PCT/IB2025/051859
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-03-29
Filing Date
2025-02-21
Publication Date
2025-10-02

AI Technical Summary

Technical Problem

In operating systems, memory overflows can cause program crashes or performance degradation, especially machine OOM and container OOM, which can have a significant impact on online services and affect system stability and performance.

Method used

By setting the global watermark threshold, offline business memory watermark threshold, and online business memory watermark threshold in kernel state, memory reclamation strategy is determined and free memory is reclaimed, including asynchronous memory reclamation, direct memory reclamation, and process termination operations, to avoid memory overflow.

Benefits of technology

It effectively avoids memory overflow, ensures stable system operation, improves system performance and resource utilization, and especially the rapid response capability of online services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IB2025051859_02102025_PF_FP_ABST
    Figure IB2025051859_02102025_PF_FP_ABST
Patent Text Reader

Abstract

The present disclosure relates to the technical field of cloud computing, and provides a memory reclaiming method and apparatus, an electronic device, a storage medium, and a program product. According to embodiments of the present disclosure, a global water level line threshold, a memory water level line threshold of an offline service, and a memory water level line threshold of an online service are set, a memory water level line is separately compared with the global water level line threshold, the memory water level line threshold of the offline service, and the memory water level line threshold of the online service, a memory reclaiming strategy is determined, and idle memory reclaiming is carried out, so that out of memory can be avoided to a certain extent, and stable operation of a system is ensured. Moreover, the method is applied to a kernel mode, does not depend on user state monitoring, and does not cause out of memory due to statistical lag.
Need to check novelty before this filing date? Find Prior Art

Description

[0001]Memory Reclaiming Method, Apparatus, Electronic Device, Storage Medium, and Program Product. This disclosure claims priority to Chinese patent application number 202410388455.9, filed with the China Patent Office on March 29, 2024, entitled "Memory Reclaiming Method, Apparatus, Electronic Device, Storage Medium, and Program Product," the entire contents of which are incorporated herein by reference. Technical Field: This disclosure relates to the field of cloud computing technology, and more particularly to a memory reclamation method, apparatus, electronic device, storage medium, and program product. Background: During the lifecycle of an operating system, when a program runs, it requests memory from the operating system to store data and instructions. If the memory required by the program exceeds the system's available memory limit and the required memory space cannot be allocated, an Out of Memory (OOM) error occurs, causing the program to crash or be terminated by the operating system. There are two main types of OOM errors: One is a system-wide OOM error. When the entire system's memory resources are exhausted, the entire system crashes. In this case, the system cannot continue to operate normally, and recovery may take several minutes to more than ten minutes, or even longer. A full-machine 00M will cause the system to be unable to respond to any requests, seriously impacting business stability. Another type of situation is a container 00M. When the memory resources within the container are exhausted, all processes within the container will be killed, and the central processing unit (CPU) utilization of the system on the same machine will surge. In this case, other services within the container will also be affected. Container 00M has a significant impact on online services, not only causing processes within the container to malfunction, but also potentially causing overall system performance degradation. Therefore, how to reclaim memory and avoid memory overflow has become a problem that needs to be solved. SUMMARY OF THE INVENTION Embodiments of the present disclosure provide a memory reclamation method, apparatus, electronic device, storage medium, and program product to achieve a certain degree of avoidance of memory overflow. In a first aspect, embodiments of the present disclosure provide a memory reclamation method, which is applied in kernel state and includes: obtaining a current memory watermark; comparing the memory watermark with a global watermark threshold, a memory watermark threshold for offline services, and a memory watermark threshold for online services, respectively, and determining a memory reclamation policy based on the comparison results; and reclaiming free memory space according to the memory reclamation policy; wherein the global watermark threshold is greater than the memory watermark threshold for offline services; and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services.In a second aspect, embodiments of the present disclosure provide a memory reclamation device, which is applied in kernel mode and includes: an acquisition module for acquiring a current memory watermark; a determination module for comparing the memory watermark with a global watermark threshold, a memory watermark threshold for offline services, and a memory watermark threshold for online services, and determining a memory reclamation policy based on the comparison results; and a reclamation module for reclaiming free memory space according to the memory reclamation policy. The global watermark threshold is greater than the memory watermark threshold for offline services; and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services. In a third aspect, embodiments of the present disclosure provide an electronic device, including a memory, a processor, and a computer program stored in the memory. The processor implements any of the aforementioned methods when executing the computer program. In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium, the computer-readable storage medium storing the computer program. When the processor executes the computer program, the processor implements any of the aforementioned methods. In a fifth aspect, embodiments of the present disclosure provide a computer program product, including the computer program. When the processor executes the computer program, the processor implements any of the aforementioned methods. Compared with the prior art, the present disclosure has the following advantages: The present disclosure provides a memory reclamation method, apparatus, electronic device, storage medium, and program product. First, the current memory watermark is obtained. Then, the memory watermark is compared with the global watermark threshold, the memory watermark threshold for offline services, and the memory watermark threshold for online services. A memory reclamation policy is determined based on the comparison results. Finally, free memory space is reclaimed based on the memory reclamation policy. The global watermark threshold is greater than the memory watermark threshold for offline services, and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services. In embodiments of the present disclosure, by setting the global watermark threshold, the memory watermark threshold for offline services, and the memory watermark threshold for online services, and then comparing the memory watermark with the global watermark threshold, the memory watermark threshold for offline services, and the memory watermark threshold for online services, a memory reclamation policy is determined, and free memory is reclaimed. This can avoid memory overflows to a certain extent and ensure stable system operation. Furthermore, the method is applied in kernel mode, does not rely on user-mode monitoring, and does not cause memory overflows due to statistical lag. The above description is merely an overview of the technical solution of the present disclosure. To better understand the technical approach of the present disclosure, implementation should be based on the contents of this specification. To further enhance the understanding of the above and other objectives, features, and advantages of the present disclosure, the following describes specific implementations of the present disclosure.BRIEF DESCRIPTION OF THE DRAWINGS In the accompanying drawings, unless otherwise specified, identical reference numerals throughout the various figures denote identical or similar components or elements. The figures are not necessarily drawn to scale. It should be understood that these figures depict only some embodiments according to the present disclosure and should not be construed as limiting the scope of the present disclosure. Figure 1 is a schematic diagram of an application scenario of the memory reclamation method provided by the present disclosure; Figure 2 is a schematic diagram of the memory reclamation method according to one embodiment of the present disclosure; Figure 3 is a flow chart of the memory reclamation method according to one embodiment of the present disclosure; Figure 4 is a block diagram of a memory reclamation apparatus according to one embodiment of the present disclosure; and Figure 5 is a block diagram of an electronic device for implementing the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS In the following, only certain exemplary embodiments are briefly described. As those skilled in the art will appreciate, the described embodiments may be modified in various ways without departing from the spirit or scope of the present disclosure. Therefore, the drawings and description are to be regarded as illustrative in nature and not restrictive. To facilitate understanding of the technical solutions of the embodiments of the present disclosure, the following describes related technologies of the embodiments of the present disclosure. The following related technologies are optional solutions that can be combined with the technical solutions of the embodiments of the present disclosure in any manner and fall within the scope of protection of the embodiments of the present disclosure. It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, storage, and display) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. The collection, use, and processing of relevant data must comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or reject. Figure 1 is a schematic diagram of an application scenario of the memory reclamation method provided in this disclosure. User mode and kernel mode are two different execution modes in an operating system. They define the instruction sets that a central processing unit (CPU) can execute and the permission levels of the hardware resources it can access. The user mode scheduler shown in Figure 1 is used to schedule processes in user mode, including processes for online services and offline services. The method in this embodiment can be applied in the kernel mode of an operating system. The specific processing process includes three parts: memory allocation, memory reclamation, and process termination. The online memory allocation interface module is used to allocate memory for online services. When offline services and online services coexist, it prevents online services from falling into direct memory reclaim and can quickly and efficiently execute memory page allocation functions (for example, a II oc_pages_may_oom function) to allocate memory pages.The online memory allocation interface module provides a reliable way to allocate memory resources for online services, effectively avoiding online service interruptions or performance degradation caused by direct memory reclamation for online services. The watermark classification module is used to set global watermark thresholds, offline service memory watermark thresholds, and online service memory watermark thresholds. First, set global watermark thresholds, such as the global minimum watermark. Specifically, use the memory.wmark_min_adj interface to set the global minimum watermark. For example, if the value of memory.wmark_min_adj is set to a positive number, the global minimum watermark will be raised by a corresponding percentage, indicating that the system will initiate memory reclamation operations earlier to avoid excessive memory resource usage. Conversely, if the value of the memory.wmark_min_adj interface is set to a negative number, the global minimum watermark will be lowered by a corresponding percentage. This helps the system use memory resources more tolerantly, but may also increase the risk of memory shortages. By adjusting the value of the memory.wmark_min_adj interface, the global minimum watermark can be flexibly controlled to meet different memory management requirements. This ensures that the system can promptly perform memory reclamation operations when memory resources are limited, avoiding excessive memory usage and improving system performance and stability. Then, based on the global watermark threshold, the memory watermark threshold for offline services and the memory watermark threshold for online services are set. The global watermark threshold is greater than the memory watermark threshold for offline services, and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services. The memory watermark thresholds for offline services and online services can be set based on specific needs and are not limited in this embodiment. The reclamation process control module is used to perform asynchronous memory reclamation if the memory watermark is equal to or less than the global watermark threshold and greater than the memory watermark threshold for offline services. Asynchronous memory reclamation can include various processing methods. Optionally, the operating system will launch dedicated kernel threads (such as kswapd in the Linux operating system) to monitor memory usage and reclaim memory in the background. These threads regularly check memory usage and, when insufficient memory is detected, release reclaimable memory pages, such as unused page caches and buffers. Asynchronous memory reclamation does not directly block running user-mode processes, reducing the impact of memory reclamation on system performance. Asynchronous memory reclamation can help maintain low latency and high throughput, especially for online businesses that require fast response times.If the memory watermark is equal to or less than the offline service memory watermark threshold and greater than the online service memory watermark threshold, direct memory reclamation will be performed on the offline service. Direct memory reclamation occurs when a memory allocation request cannot be immediately satisfied. When a process requests more memory and the system currently lacks sufficient free memory, the kernel may synchronously reclaim memory. In this case, the requesting process is suspended until sufficient memory is reclaimed to satisfy the request. Direct memory reclamation includes, but is not limited to, clearing the file system cache in the page cache; reclaiming temporary data in the buffer; and clearing and reclaiming other reclaimable memory. Furthermore, the reclamation process control module controls the number of offline service processes that undergo direct memory reclamation to prevent multiple resources from simultaneously entering the direct memory reclamation path, which could cause scheduling blockages or lock contention. This optimizes system performance and resource utilization, ensuring efficient memory reclamation. Specifically, based on the psi_memstart_enter / leave function, the number of processes entering the direct memory reclamation path is counted. The more processes entering the direct memory reclamation path, the slower the direct memory reclamation rate, and the more likely it is to trigger process termination. The process termination module is used to: If the memory watermark is equal to or less than the memory watermark threshold for online services, and offline services have already performed direct memory reclamation or are in sleep mode, determine the memory reclamation strategy to terminate the currently executing process. A process quantity threshold is set. If the number of stopped processes is less than the process quantity threshold and the memory released by stopped processes is insufficient to meet demand, all offline service processes are terminated. If all currently executing processes are online service processes, the number of online service processes to terminate is determined based on specific needs. The priority setting module is used to set the priorities of multiple processes. Lower priorities are assigned to unimportant or replaceable tasks or processes. When memory is insufficient, a lower-priority process is selected from multiple running processes as the target process to terminate. Setting priorities can reduce the impact on critical tasks or processes, improving overall system stability and performance. The reserved memory module is used to: Upon receiving a memory allocation request from an online service and pending memory release for terminated processes, it enters the reserved memory allocation path, obtains reserved memory space, and allocates it to the online service requester. If the allocation is successful, the system returns; if it fails, it waits for a retry. This module strives to meet online service memory requests to ensure service quality and timely response and fulfillment of requests for additional memory resources.Figure 2 is a schematic diagram of a memory reclamation method according to an embodiment of the present disclosure. A global high watermark, a global low watermark, a memory watermark threshold for offline services, and a memory watermark threshold for online services are set. A memory reclamation policy is determined by comparing the current memory watermark with the global high watermark, global low watermark, the memory watermark threshold for offline services, and the memory watermark threshold for online services. Memory reclamation is performed based on the memory reclamation policy. In this embodiment, a memory resource controller (memcg) is used for memory allocation and reclamation. The online memcg handles online services, while the offline memcg handles offline services. The specific process is as follows: If the current memory watermark is lower than the global high watermark but higher than the global low watermark, memory is sufficient and no memory reclamation is required. If the memory watermark is equal to or lower than the global low watermark (i.e., the global watermark threshold) and higher than the memory watermark threshold for offline services, the daemon process kswapd is awakened to perform asynchronous memory reclamation. If the memory watermark is equal to or less than the offline service's memory watermark threshold and greater than the online service's memory watermark threshold, the online service performs normal memory allocation, and direct memory reclaim is performed on the offline service. The number of offline processes undergoing direct memory reclaim is controlled by a counter. The kernel tracks which offline processes are reclaiming memory to ensure that excessive memory is not reclaimed. If the memory watermark is equal to or less than the online service's memory watermark threshold, and the offline service has already performed direct memory reclaim or is in sleep mode, the currently executing process is terminated. In one example, the online memcg carries the "~_GFP_DIRECT_RECLAIM | _GFP_NORETRY" flag when requesting memory. The "~_GFP_DIRECT_RECLAIM | _GFP_NORETRY" flag indicates that the online service will not perform direct memory reclaim and will not retry allocations if they fail. If no free memory pages can be obtained, the process is quickly terminated. If there are multiple currently executing processes, the priorities of the multiple currently executing processes are obtained, at least one target process is determined based on the priorities of the multiple processes, and the at least one target process is terminated. If the memory watermark is equal to or less than the memory watermark threshold for online services and there are no offline services, the memory reclamation policy is determined to be direct memory reclamation for online services if the following three conditions are met: the remaining area of ​​the page cache is greater than a preset cache threshold; the number of processes undergoing direct memory reclamation is less than a preset number threshold; and the delay for direct memory reclamation is less than a preset time threshold.If the remaining area of ​​the page cache is greater than a preset cache threshold, it indicates that a large amount of page cache space remains. If the number of processes undergoing direct memory reclamation is less than a preset threshold, this indicates that the system can accept this number. If the latency of direct memory reclamation is less than a preset time threshold, this indicates that the system can tolerate this latency. If these three conditions are met, direct memory reclamation is performed for the online service. If a memory allocation request is received from an online service and the memory release of the terminated process is not complete, reserved memory allocation is performed. This involves obtaining reserved memory space and allocating it to the memory requester of the online service. For example, multiple target processes are selected based on priority and a SIGKILL signal is sent. The SIGKILL signal is used to terminate the processes. After sending the SIGKILL signal, the online Memcg does not wait for memory release to complete. Instead, it uses reserved memory for allocation. If the reserved memory is insufficient, it will retry and wait for memory to be quickly released by the terminated process. When an offline process receives a SIGKILL signal, it may be in one of three situations: 1) running in user mode without any memory allocation requests; 2) falling into the direct memory reclamation path in kernel mode; or 3) sleeping in kernel mode, awaiting wakeup. In the first case, the offline process running in user mode can be quickly terminated, and the memory occupied by the process can be directly reclaimed. In the latter two cases, the SIGKILL signal can only be processed after the kernel mode direct reclamation path completes a reclaim and returns to user mode. To reduce waiting time, the kernel code may check the "fatal_signal_pending()" function to detect whether a SIGKILL signal is pending. If a SIGKILL is detected, the kernel can terminate the current operation as soon as possible and return control to user mode, allowing the process to be terminated immediately. In this disclosed embodiment, memory reclamation can be quickly triggered, preventing damage to online services due to prolonged unresponsiveness, maintaining stable online service performance under high watermarks, and avoiding performance jitter and latency issues caused by memory shortages. Furthermore, this solution is applied in kernel mode and does not rely on user-mode monitoring, preventing incorrect triggering of memory reclamation due to statistical lag. Furthermore, it can improve memory deployment density, i.e., more efficiently utilize memory with the same hardware resources, thereby improving overall system performance. This embodiment of the present disclosure provides a memory reclamation method that can be applied to computing devices, such as servers and user terminals. FIG3 shows a flowchart of the memory reclamation method according to one embodiment of the present disclosure, comprising: Step S301: Obtaining the current memory watermark.In step S302, the memory watermark is compared with the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold, and a memory reclamation policy is determined based on the comparison results. In step S303, free memory space is reclaimed according to the memory reclamation policy. The current memory watermark indicates current memory usage, for example, the percentage of total memory used. Optionally, the memory watermark during system operation can be monitored at preset time intervals. The global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold can be preconfigured based on specific needs. The offline service memory watermark threshold and the online service memory watermark threshold can be configured based on the global watermark threshold. The global watermark threshold is greater than the offline service memory watermark threshold, and the offline service memory watermark threshold is greater than the online service memory watermark threshold. The memory reclamation method provided in the embodiments of the present disclosure first obtains the current memory watermark. Then, the memory watermark is compared with the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold. A memory reclamation policy is determined based on the comparison results. Finally, free memory space is reclaimed according to the memory reclamation policy. The global watermark threshold is greater than the offline service memory watermark threshold, and the offline service memory watermark threshold is greater than the online service memory watermark threshold. In the embodiments of the present disclosure, by setting the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold, and then comparing the memory watermark with the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold, a memory reclamation policy is determined, and free memory is reclaimed. This method can, to a certain extent, avoid memory overflows and ensure stable system operation. Furthermore, the method is applied in kernel mode and does not rely on user-mode monitoring, thus preventing memory overflows due to statistical lags. The following describes the implementation process of each of the above steps in detail using various implementations. In one implementation, a memory reclamation policy is determined based on the comparison results, including: if the memory watermark is equal to or less than the global watermark threshold and greater than the offline service memory watermark threshold, then asynchronous memory reclamation is used as the memory reclamation policy. Asynchronous memory reclamation can include various processing methods. Optionally, the operating system will launch a dedicated kernel thread (such as kswapd in the Linux operating system) to monitor memory usage and reclaim memory in the background.These threads regularly check memory usage and, when insufficient memory is detected, release reclaimable memory pages, such as unused page caches and buffers. Asynchronous memory reclamation does not directly block running user-mode processes, reducing the impact of memory reclamation on system performance. This is particularly helpful for maintaining low latency and high throughput for online services that require fast responses. In one implementation, a memory reclamation strategy is determined based on the comparison results, including: if the memory watermark is equal to or less than the offline service memory watermark threshold and greater than the online service memory watermark threshold, direct memory reclamation is used for offline services. Direct memory reclamation is performed when a memory allocation request cannot be immediately satisfied. When a process requests more memory and the system currently does not have sufficient free memory, the kernel may synchronously reclaim memory. In this case, the requesting process is paused until sufficient memory is reclaimed to satisfy the request. Direct memory reclamation methods include, but are not limited to, clearing file system cache in the page cache; reclaiming temporary data in the buffer; and clearing and reclaiming other reclaimable memory. In one implementation, a memory reclamation strategy is determined based on the comparison results, including: if the memory watermark is equal to or less than the online service's memory watermark threshold, and the offline service has already undergone direct memory reclamation or is in sleep mode, then the memory reclamation strategy is determined to terminate the currently executing process. In actual applications, the currently executing processes terminated can include both online and offline processes. A process number threshold is set. If the number of terminated processes is less than the process number threshold, and the memory released by the terminated offline processes is insufficient to meet demand, all offline service processes are terminated. If all currently executing processes are online service processes, the number of online service processes to terminate is determined based on specific needs. In one implementation, there are multiple currently executing processes, and terminating the currently executing processes includes: obtaining priorities corresponding to the multiple currently executing processes, determining at least one target process based on the priorities corresponding to the multiple processes, and terminating the at least one target process. In practical applications, priorities can be set for the multiple processes. Lower priorities can be assigned to unimportant or replaceable tasks or processes. When memory is insufficient, a lower-priority process can be selected from the multiple running processes as the target process and terminated. Setting priorities can reduce the impact on critical tasks or processes, thereby improving overall system stability and performance.In one implementation, the memory reclamation method further includes: if a memory allocation request is received from an online service and memory release for a terminated process is not complete, obtaining reserved memory space and allocating it to the memory requester of the online service. In actual applications, if a memory allocation request is received from an online service and memory release for a terminated process is not complete, the reserved memory allocation path is entered, reserved memory space is obtained, and allocated to the memory requester of the online service. If the allocation is successful, a return is made; if the allocation fails, a retry is performed. Memory requests from online services are met as much as possible to ensure service quality and timely response and satisfaction when they require more memory resources. In one implementation, a memory reclamation strategy is determined based on the comparison result, including: if the memory watermark is equal to or less than the memory watermark threshold for online services and there are no offline services, determining the memory reclamation strategy as direct memory reclamation for the online service if at least one of the following conditions is met: the size of the remaining area of ​​the page cache area is greater than a preset cache threshold; the number of processes undergoing direct memory reclamation is less than a preset number threshold; and the delay of direct memory reclamation is less than a preset time threshold. In actual applications, if the memory watermark is equal to or less than the memory watermark threshold for online services and there are no offline services, a determination is made as to whether the conditions for memory reclamation for online services are met. If so, direct memory reclamation is performed for the online services to prevent memory overflow and system crashes. The conditions for memory reclamation for online services can be configured according to specific needs. Optionally, the determination includes determining whether the remaining area of ​​the page cache is greater than a preset cache threshold; determining whether the number of processes undergoing direct memory reclamation is less than a preset number threshold; and determining whether the delay for direct memory reclamation is less than a preset time threshold. Corresponding to the application scenarios and methods of the methods provided in the embodiments of the present disclosure, the embodiments of the present disclosure also provide a memory reclamation device. FIG4 shows a block diagram of the memory reclamation device according to one embodiment of the present disclosure. The device includes: an acquisition module 401 for acquiring the current memory watermark; a determination module 402 for comparing the memory watermark with the global watermark threshold, the memory watermark threshold for offline services, and the memory watermark threshold for online services, and determining a memory reclamation strategy based on the comparison results. The recycling module 403 is configured to reclaim free memory space according to a memory recycling policy. The global watermark threshold is greater than the memory watermark threshold for offline services, and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services.The memory reclamation device provided in the embodiments of the present disclosure first obtains the current memory watermark; then compares the memory watermark with the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold, and determines a memory reclamation policy based on the comparison results; finally, reclaims free memory space according to the memory reclamation policy. The global watermark threshold is greater than the offline service memory watermark threshold, and the offline service memory watermark threshold is greater than the online service memory watermark threshold. In the embodiments of the present disclosure, by setting the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold, and then comparing the memory watermark with the global watermark threshold, the offline service memory watermark threshold, and the online service memory watermark threshold, determining the memory reclamation policy, and reclaiming free memory, the device can avoid memory overflows to a certain extent and ensure stable system operation. Furthermore, the method is applied in kernel mode and does not rely on user mode monitoring, thus preventing memory overflows due to statistical lags. In one implementation, when determining the memory reclamation policy based on the comparison result, the determination module 402 is configured to: if the memory watermark is equal to or less than the global watermark threshold and greater than the offline service memory watermark threshold, determine the memory reclamation policy as asynchronous memory reclamation. In one implementation, when determining the memory reclamation policy based on the comparison result, the determination module 402 is configured to: if the memory watermark is equal to or less than the offline service memory watermark threshold and greater than the online service memory watermark threshold, determine the memory reclamation policy as direct memory reclamation for the offline service. In one implementation, when determining the memory reclamation policy based on the comparison result, the determination module 402 is configured to: if the memory watermark is equal to or less than the online service memory watermark threshold and the offline service has already performed direct memory reclamation or is in sleep mode, determine the memory reclamation policy as terminating the currently executing process. In one implementation, there are multiple currently executing processes. When terminating a currently executing process, the determination module 402 is configured to: obtain the priorities corresponding to the multiple currently executing processes, determine at least one target process based on the priorities corresponding to the multiple processes, and terminate the at least one target process. In one implementation, the device is further configured to: if a memory allocation request from an online service is received and memory release for the terminated process is not complete, obtain reserved memory space and allocate it to the memory requester of the online service.In one implementation, when determining a memory reclamation strategy based on the comparison results, determination module 402 is configured to: if the memory watermark is equal to or less than the memory watermark threshold for online services and there are no offline services, determine the memory reclamation strategy as direct memory reclamation for online services if at least one of the following conditions is met: the remaining area of ​​the page cache area is greater than a preset cache threshold; the number of processes undergoing direct memory reclamation is less than a preset number threshold; and the delay for direct memory reclamation is less than a preset time threshold. The functions of each module in the embodiments of the present disclosure can be found in the corresponding descriptions of the above-mentioned methods, and they provide corresponding beneficial effects, and are not further described here. Figure 5 is a block diagram of an electronic device for implementing the embodiments of the present disclosure. As shown in Figure 5, the electronic device includes a memory 510 and a processor 520. The memory 510 stores a computer program executable on the processor 520. When the processor 520 executes the computer program, the method in the above-mentioned embodiment is implemented. The number of memory 510 and processor 520 can be one or more. The electronic device also includes a communication interface 530 for communicating with external devices and exchanging data. If the memory 510, processor 520, and communication interface 530 are implemented independently, the memory 510, processor 520, and communication interface 530 may be interconnected via a bus and communicate with each other. This bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. This bus may be classified as an address bus, a data bus, a control bus, etc. For ease of illustration, FIG5 shows only one thick line, but this does not mean that there is only one bus or only one type of bus. Optionally, in a specific implementation, if the memory 510, processor 520, and communication interface 530 are integrated on a single chip, the memory 510, processor 520, and communication interface 530 may communicate with each other via an internal interface. Embodiments of the present disclosure provide a computer-readable storage medium storing a computer program. When executed by a processor, the program implements the methods provided in the embodiments of the present disclosure. Embodiments of the present disclosure also provide a computer program product. The computer program product includes the computer program. When executed by a processor, the computer program implements the methods provided in the embodiments of the present disclosure.The present disclosure also provides a chip including a processor configured to retrieve and execute instructions stored in a memory, thereby enabling a communication device equipped with the chip to perform the methods provided in the present disclosure. The present disclosure also provides a chip including an input interface, an output interface, a processor, and a memory. The input interface, the output interface, the processor, and the memory are connected via an internal connection path. The processor is configured to execute code in the memory. When the code is executed, the processor performs the methods provided in the present disclosure. It should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field programmable gate arrays (FPGAs), other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor. It is worth noting that the processor may be a processor supporting the Advanced Reduced Instruction Set Machine (ARM) architecture. Furthermore, optionally, the aforementioned memory may include read-only memory and random access memory. The memory may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Among them, the non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory may include random access memory (RAM), which serves as an external cache. By way of example and not limitation, many forms of RAM are available.For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM RAM (DR RAM). In the above embodiments, all or part of them can be implemented through software, hardware, firmware, or any combination thereof. When implemented using software, they can be implemented in whole or in part in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the present disclosure is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another. Throughout this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples" indicate that the specific features, structures, materials, or characteristics described in conjunction with that embodiment or example are included in at least one embodiment or example of the present disclosure. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate the different embodiments or examples described in this specification, as well as features from different embodiments or examples, unless otherwise specified. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed to indicate or imply relative importance or implicitly specify the number of technical features indicated. Therefore, features specified as "first" or "second" may explicitly or implicitly include at least one of those features. Throughout this disclosure, "plurality" means two or more, unless otherwise specifically defined.Any process or method described in a flowchart or otherwise herein can be understood to represent a module, segment, or portion of code comprising one or more executable instructions for implementing a specific logical function or process step. Furthermore, the scope of the preferred embodiments of the present disclosure includes alternative implementations in which functions may be performed out of the order shown or discussed, including performing functions substantially simultaneously or in reverse order depending on the functions involved. The logic and / or steps described in a flowchart or otherwise herein can, for example, be considered a sequenced list of executable instructions for implementing the logical function and can be embodied in any computer-readable medium for use by an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device), or in conjunction with such an instruction execution system, apparatus, or device. It should be understood that various aspects of the present disclosure can be implemented using hardware, software, firmware, or a combination thereof. In the aforementioned embodiments, various steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. All or part of the steps of the method embodiments described above can be completed by instructing the relevant hardware through a program. This program can be stored in a computer-readable storage medium. When executed, the program includes one or a combination of the steps of the method embodiments. Furthermore, the functional units in the various embodiments of the present disclosure can be integrated into a single processing module, each unit can exist physically separately, or two or more units can be integrated into a single module. These integrated modules can be implemented in either hardware or software functional modules. If these integrated modules are implemented as software functional modules and sold or used as standalone products, they can also be stored in a computer-readable storage medium. This storage medium can be a read-only memory, a magnetic disk, or an optical disk. The above is merely an exemplary embodiment of the present disclosure, but the scope of protection of the present disclosure is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope of this disclosure, and such variations or substitutions are intended to be encompassed by the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure shall be subject to the scope of protection of the claims.

Claims

Claims 1. A memory recycling method, wherein: The method, applied in kernel mode, includes: obtaining a current memory watermark; comparing the memory watermark with a global watermark threshold, a memory watermark threshold for offline services, and a memory watermark threshold for online services, respectively, and determining a memory reclamation strategy based on the comparison results; and reclaiming free memory space according to the memory reclamation strategy; wherein the global watermark threshold is greater than the memory watermark threshold for offline services; and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services.

2. The method according to claim 1, wherein: The determining of the memory reclamation strategy according to the comparison result includes: if the memory watermark is equal to or less than the global watermark threshold and greater than the memory watermark threshold of the offline service, determining the memory reclamation strategy as asynchronous memory reclamation.

3. The method according to claim 1 or 2, wherein: The determining of the memory reclamation strategy according to the comparison result includes: if the memory watermark is equal to or less than the memory watermark threshold of the offline service and greater than the memory watermark threshold of the online service, determining the memory reclamation strategy as directly reclaiming memory for the offline service.

4. The method according to any one of claims 1 to 3, wherein: The determining of the memory reclaiming strategy according to the comparison result includes: if the memory watermark is equal to or less than the memory watermark threshold of the online service, and the offline service has performed direct memory reclaiming or sleep waiting, determining the memory reclaiming strategy to terminate the currently executing process.

5. The method according to claim 4, wherein: There are multiple currently executing processes, and ending the currently executing process includes: obtaining priorities corresponding to the multiple currently executing processes, determining at least one target process according to the priorities corresponding to the multiple processes, and ending the at least one target process.

6. The method according to claim 4 or 5, wherein: The method further includes: if a memory allocation request of an online service is received and the memory release of the end process is not completed, obtaining reserved memory space and allocating it to the memory requester of the online service.

7. The method according to any one of claims 1 to 6, wherein: The determining of the memory reclamation strategy based on the comparison result includes: if the memory watermark is equal to or less than the memory watermark threshold of the online service and there is no offline service, determining the memory reclamation strategy to be direct memory reclamation for the online service when at least one of the following conditions is met: the size of the remaining area of ​​the page cache area is greater than a preset cache threshold; the number of processes performing direct memory reclamation is less than a preset number threshold; and the delay of performing direct memory reclamation is less than a preset time threshold.

8. A memory recycling device, wherein: The device is applied in kernel mode and includes: an acquisition module, configured to acquire a current memory watermark; a determination module, configured to compare the memory watermark with a global watermark threshold, a memory watermark threshold for offline services, and a memory watermark threshold for online services, respectively, and determine a memory reclamation strategy based on the comparison results; and a reclamation module, configured to reclaim free memory space based on the memory reclamation strategy; wherein the global watermark threshold is greater than the memory watermark threshold for offline services; and the memory watermark threshold for offline services is greater than the memory watermark threshold for online services.

9. An electronic device, wherein: The electronic device includes a memory, a processor, and a computer program stored in the memory, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, wherein: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

11. A computer program product, wherein: The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Memory recovery method and device, storage medium and electronic equipment

    CN111831444A

  • Memory environment real-time optimization method and system for Android system

    CN113626203A

  • Memory management method and device and electronic equipment

    CN117493063A

Cited By

  • Memory recovery method, electronic equipment, storage medium and computer program product

    CN122044885A