Memory recycling method and device

By receiving PSI events to obtain memory idle status information, multiple processes are selected for memory recycling based on the oom_adj value, which solves the problem of passive memory recycling in the existing technology and achieves effective memory management and improved user experience.

CN114218126BActive Publication Date: 2025-09-09BEIJING SPREADTRUM HI TECH COMM TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111299272.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-04
Publication Date
2025-09-09
Estimated Expiration
2041-11-04

AI Technical Summary

Technical Problem

In the prior art, when executing memory reclamation, the type of free memory is not considered or only one process is reclaimed, resulting in the problem of inactive reclamation.

Method used

By receiving memory pressure and blocking information (PSI) events, the system obtains memory idle state information, determines the number of processes that need to be reclaimed based on the idle state information, and selects multiple processes from the running processes for memory reclamation based on the process oom_adj value. This includes considering factors such as the proportion of high atomic type memory, upper-layer application memory requirements, the proportion of idle swap space, and the time that processes wait for hardware resources.

Benefits of technology

This solves the problem of inactive recycling caused by not considering the type of free memory or recycling only one process, ensuring the effectiveness of memory recycling while retaining important processes, avoiding incorrect recycling, and improving the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114218126B_ABST
    Figure CN114218126B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of electronic equipment, and in particular to a memory recovery method and device. A memory recovery method, comprising: triggering a memory recovery process upon receiving a memory pressure blocking information PSI event; obtaining memory idle state information in the memory recovery process; if it is determined according to the memory idle state information that the memory pressure requirement is greater than a set value, determining that there are multiple processes to be recovered; and selecting multiple processes from the running processes for memory recovery according to the process oom_adj value. When recycling the internal processes of the device, the memory pressure requirement of the device is judged according to the memory idle state information to determine the optimal number of recycling processes, thereby avoiding the situation where the recycling is not active due to not considering the type of idle memory or only recycling one process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical field

[0001] The present application relates to the technical field of electronic equipment, and in particular to a memory recycling method and device. [Background Technology]

[0002] When users operate terminal devices, they often encounter a situation where the terminal system has insufficient free memory. At this time, the terminal will reclaim the memory of applications or services running in the background according to the LMK (Low Memory Killer) mechanism to ensure the operation of foreground applications. Since kernel4.12, electronic devices have abandoned the LMK mechanism in the kernel and replaced it with the LMKD (Low Memory Killer Daemon) mechanism in user space. After kernel4.14, electronic devices report memory pressure events through PSI (Pressure stall information) and select a process for recycling to ensure that there is enough free memory. However, process recycling using this method will result in inactive recycling because the type of free memory is not taken into account or only one process is recycled. [Summary of the invention]

[0003] In view of this, an embodiment of the present invention provides a memory recycling method and apparatus to solve the problem in the prior art of not considering the type of free memory when executing memory recycling, or recycling only one process, resulting in inactive recycling.

[0004] In a first aspect, an embodiment of the present invention provides a memory reclaiming method, comprising:

[0005] When receiving the memory pressure blocking information PSI event, the memory recycling process is triggered;

[0006] In the memory recycling process, obtaining memory idle state information;

[0007] If it is determined according to the memory idle state information that the memory pressure requirement is greater than a set value, determining that the number of processes that need to be recycled is multiple;

[0008] Based on the oom_adj value of the process, multiple processes are selected from the running processes for memory recycling.

[0009] Optionally, the memory idle state information includes: the total remaining free memory value, the percentage of free memory of the highatomic type, memory requirement information of upper-layer applications, the percentage of free swap space, the time the process waits for hardware resources, and the oom_adj value of the process; if the memory idle state information satisfies a combination of one or more of the following, it is determined that the memory pressure demand is greater than the set value, including:

[0010] The total value of the remaining free memory is less than the memory watermark;

[0011] The percentage of free memory of the highatomic type is greater than the first threshold;

[0012] Specify an application to send memory requirement information;

[0013] The percentage of free swap space is less than the specified value;

[0014] The time the process waits for hardware resources is greater than a second threshold;

[0015] The number of processes whose oom_adj value is greater than a preset value is greater than a third threshold.

[0016] Optionally, if the memory idle state information satisfies the following combination, determining that the memory pressure requirement is greater than a set value includes:

[0017] The percentage of free swap space is less than the first specified value and the time the process waits for hardware resources is greater than the second threshold; or

[0018] The number of processes whose swap space free ratio is less than the second specified value and whose oom_adj value is greater than the preset value is greater than the third threshold.

[0019] Optionally, based on the oom_adj value of each process, multiple processes are selected from the running processes for memory reclamation, including:

[0020] Memory is reclaimed by selecting processes from the running processes in descending order of oom_adj values ​​until the total free memory value is greater than or equal to the memory watermark after the selected processes release memory.

[0021] Optionally, the memory idle state information includes: the idle swap space ratio; and selecting multiple processes from the running processes for memory reclamation based on the process oom_adj value, including:

[0022] If the swap space idle ratio is less than the third specified value and the number of processes whose oom_adj values ​​are greater than the preset value is greater than a fourth threshold, a recycling process is determined from the processes whose oom_adj values ​​are greater than the preset value, and memory recycling is performed on the recycling process.

[0023] Optionally, the memory idle state information further includes a page jitter value; and according to the process oom_adj value, multiple processes are selected from the running processes for memory reclamation, including:

[0024] Determining an oom_adj retention threshold according to the page jitter value, wherein the page jitter value and the oom_adj retention threshold are negatively correlated, and the larger the page jitter value, the smaller the oom_adj retention threshold; and

[0025] Determine a process whose oom_adj value is less than the oom_adj retention threshold as a reserved process, and the reserved process does not perform memory reclamation;

[0026] A recycling process is determined from processes whose oom_adj values ​​are greater than or equal to the oom_adj retention threshold, and memory recycling is performed on the recycling process.

[0027] Optionally, the memory idle state information further includes a total value of remaining idle memory; and according to the process oom_adj value, multiple processes are selected from the running processes for memory reclamation, including:

[0028] If the total remaining free memory value is greater than the memory watermark, the process with an oom_adj value of 0 is determined as a reserved process, and the reserved process does not perform memory reclamation;

[0029] A recycling process is determined from processes whose oom_adj values ​​are not 0, and memory recycling is performed on the recycling process.

[0030] In a second aspect, an embodiment of the present invention provides a memory recycling device, comprising:

[0031] The trigger module triggers the memory recycling process when receiving the memory pressure blocking information PSI event;

[0032] An acquisition module, which acquires memory idle state information during the memory recycling process;

[0033] a determination module, which determines that the number of processes to be recycled is multiple if it is determined that the memory pressure requirement is greater than a set value according to the memory idle state information;

[0034] The recycling module selects multiple processes from the running processes for memory recycling based on the process oom_adj value.

[0035] In a third aspect, an embodiment of the present invention provides a memory recycling device, comprising:

[0036] at least one processor; and

[0037] at least one memory in communication with the processor, wherein:

[0038] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method as described in any one of the first aspects above.

[0039] Optionally, the computer-readable storage medium includes a stored program, wherein when the program is running, the device where the computer-readable storage medium is located is controlled to execute any of the methods described in the first aspect above.

[0040] The above technical solution allows the device to select multiple processes for recycling by evaluating memory idle status information while recycling processes. This solves the problem of inactive recycling caused by not considering the type of idle memory or recycling only a single process. Furthermore, while recycling processes, some important processes are retained to avoid incorrect recycling.

Brief Description of the Drawings

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

[0042] Figure 1 A schematic structural diagram of an electronic device provided by an embodiment of the present invention;

[0043] Figure 2 A flowchart of a memory recovery method provided by an embodiment of the present invention;

[0044] Figure 3 A schematic structural diagram of a memory recycling device provided by an embodiment of the present invention;

[0045] Figure 4 A schematic structural diagram of another electronic device provided by an embodiment of the present invention. [Specific implementation method]

[0046] In order to better understand the technical solution of the present invention, the embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0047] It should be understood that the embodiments described are only a portion of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative work are within the scope of protection of the present invention.

[0048] When an electronic device encounters a situation where there is insufficient free memory, it generally reclaims memory through the LMKD mechanism triggered by a PSI event. In order to achieve memory recycling, an embodiment of the present invention provides a structural diagram of an electronic device. Figure 1 As shown, the electronic device is provided with a processing unit, which is used to confirm memory idle state information and recycle selected processes according to the memory idle state information to ensure that the electronic device has enough memory to keep running.

[0049] Specifically, when the processing unit receives a PSI event, it triggers the memory to start executing a reclaim process. During the execution of the memory reclaim process, the processing unit obtains memory idle state information and determines the number of processes that need to be reclaimed based on the memory idle state information.

[0050] Specifically, the memory status information can specifically indicate the current memory pressure demand. The memory idle status information specifically includes: the total remaining free memory value, the free memory percentage of the highatomic type, the memory demand information of the upper-layer application, the free swap space percentage, the process waiting time for hardware resources, and the process oom_adj value.

[0051] The total remaining free memory value is used to indicate the total remaining memory in the electronic device. The watermark is generally used to measure the remaining free memory pressure of the current system. The watermark is further divided into three levels: high, low, and min. When the remaining memory is above high, the system believes that the current memory usage pressure is not great; when the remaining memory drops to low, the system believes that the current memory is insufficient and starts to recycle processes; when the remaining memory is below min, the system memory pressure is very high. The watermark described in the embodiment of the present invention is generally a low-level watermark. Therefore, the watermark is used to indicate the pressure status of the total remaining free memory value in the device, and further indicates the real-time memory pressure status inside the device.

[0052] The percentage of free highatomic memory refers to the percentage of free highatomic memory within the total memory. Terminal internal memory is typically divided into four types: movable, unmovable, reclaimable, and highatomic. Device processes are run using movable memory. When the percentage of free highatomic memory is too high, it takes up some of the available movable memory, causing device performance to lag. Therefore, the percentage of free highatomic memory indicates the real-time memory pressure within the device.

[0053] The memory requirement information of the upper-layer application. The upper-layer application often requires a large amount of memory space when it is started. At this time, the upper-layer application will send the memory requirement information to the processing unit to reclaim some processes in the memory to flow out enough remaining memory space for the upper-layer application to start.

[0054] The percentage of free swap space. Swap space is a virtualized logical memory created from disk space to address insufficient physical memory. It temporarily stores infrequently used data in memory in this virtual space, moving it out of physical memory. When this data is needed, it is read back into physical memory. Swap space can also be used to indicate current memory pressure.

[0055] The time a process waits for hardware resources is known as a PSI event. PSI events specifically quantify task execution interruptions caused by hardware resource constraints and measure the time tasks in the system spend waiting for hardware resources. Therefore, PSI can be used as an indicator to measure hardware resource pressure. The longer a process waits for hardware resources, the greater the pressure on resources and, consequently, memory pressure. When a process waits for hardware resources for 700ms, the PSI reports a critical event.

[0056] The oom_adj value of a process is used to determine its importance. The higher the oom_adj value, the less important the process. When the LMKD mechanism is triggered, the processing unit will prioritize reclaiming processes with higher oom_adj values.

[0057] The processing unit determines whether the current terminal memory pressure is greater than the set value based on the above-mentioned memory idle state information. Specifically, when the memory idle state information satisfies one or more of the following combinations: the total value of the remaining idle memory is less than the memory watermark; the proportion of idle memory of the highatomic type is greater than the first threshold; the specified application sends memory demand information; the idle proportion of the swap space is less than the specified value; the process waits for hardware resources for a time greater than the second threshold; the number of processes with an oom_adj value greater than a preset value is greater than a third threshold, it is determined that the memory pressure demand is greater than the set value. At this time, processes are selected from the running processes in descending order of oom_adj values ​​for memory recovery, until the selected processes release the memory so that the total value of the idle memory is greater than or equal to the memory watermark, so as to meet the current memory demand space.

[0058] Among them, when determining whether the current terminal memory pressure is greater than the set value based on the memory idle state information combination, if the idle ratio of the swap space is less than the third specified value and the number of processes with an oom_adj value greater than the preset value is greater than the fourth threshold, then the recovery process is determined from the processes with an oom_adj value greater than the preset value, and memory recovery is performed on the recovery process. Generally, the preset value is set to 800, and the fourth threshold is set to 0, that is, when the idle ratio of the swap space is less than the third specified value and contains processes with an oom_adj value greater than 800, all processes with an oom_adj value greater than 800 are recovered to free up memory space. If the number of processes greater than the preset value in the current terminal is not greater than the fourth threshold, that is, the current terminal does not contain processes greater than 800, no process is recovered.

[0059] In some embodiments, excessive process recycling can cause some normally executing processes to be recycled, resulting in a poor user experience. Therefore, while recycling processes using the LMKD mechanism, it is also necessary to retain some important processes based on the memory free state information. For example, some processes can be retained based on the page jitter value and the total remaining free memory value.

[0060] Specifically, the oom_adj retention threshold is determined according to the page jitter value, wherein the page jitter value is negatively correlated with the oom_adj retention threshold, and the larger the page jitter value, the smaller the oom_adj retention threshold, and the smaller the page jitter value, the larger the oom_adj retention threshold.

[0061] A process whose oom_adj value is less than the oom_adj retention threshold is determined as a reserved process, and memory reclamation is not performed on the reserved process; a reclaimed process is determined from processes whose oom_adj value is greater than or equal to the oom_adj retention threshold, and memory reclamation is performed on the reclaimed process.

[0062] Typically, the oom_adj value retention thresholds are set to 900, 701, 201, and 100. The oom_adj value retention threshold range can be further divided based on user needs. The process retention range is determined based on the specific page jitter value.

[0063] At the same time, some processes are retained based on the total remaining free memory value. If the total remaining free memory value is greater than the memory watermark, processes with an oom_adj value of 0 are identified as retained processes, and memory reclamation is not performed on these retained processes. Reclaimed processes are then determined from processes with non-zero oom_adj values, and memory reclamation is performed on these reclaimed processes. Processes with an oom_adj value of 0 are currently running in the foreground of the terminal, and these foreground processes are retained to prevent crashes and other issues during user operations.

[0064] based on Figure 1 The electronic device structure shown in FIG, an embodiment of the present invention provides a memory recovery method. Figure 2 , which is a flow chart of a memory recovery method provided by an embodiment of the present invention. The execution subject of the method is the processing unit 101, and the execution steps of the method include:

[0065] 201. When a memory pressure blocking information PSI event is received, a memory recycling process is triggered.

[0066] 202. In the memory recycling process, obtain memory idle state information.

[0067] Specifically, the memory idle state information is used to indicate the current memory pressure requirement of the electronic device, including: the total remaining free memory value, the free memory ratio of highatomic type, the memory requirement information of the upper-layer application, the free ratio of swap space, the process waiting time for hardware resources, and the process oom_adj value.

[0068] 203 : Determine whether the memory pressure requirement is greater than a set value according to the memory idle state information.

[0069] Specifically, if the memory idle state information satisfies a combination of one or more of the following, it is determined that the memory pressure requirement is greater than a set value, including:

[0070] The total remaining free memory value is less than the memory watermark; the proportion of free memory of the highatomic type is greater than the first threshold; the designated application sends memory demand information; the proportion of free swap space is less than the specified value; the time a process waits for hardware resources is greater than the second threshold; and the number of processes with an oom_adj value greater than a preset value is greater than a third threshold. If the following conditions are met: the proportion of free swap space is less than the first specified value and the time a process waits for hardware resources is greater than the second threshold; or the proportion of free swap space is less than the second specified value and the number of processes with an oom_adj value greater than a preset value is greater than the third threshold, then it is determined that the current terminal memory pressure demand is greater than the set value; otherwise, it is determined that the current terminal memory pressure is less than the set value.

[0071] In some specific embodiments, one of the memory free state information may be satisfied, for example, the memory free state information may show that the proportion of free memory of the highatomic type is greater than 75%, which compresses the movable type memory used to run the process. Execute step 206.

[0072] In some specific embodiments, when one of the memory idle status information is satisfied, for example, when a specific application such as a camera, WeChat, or other common electronic device applications sends memory requirement information in the memory idle status information, the set value of the memory requirement is determined and step 204 is executed.

[0073] In some specific embodiments, a combination of multiple memory idle status information conditions may occur. For example, if the swap space idle percentage is less than a first specified value and the process wait time for hardware resources is greater than 700ms, a critical event is reported; or if the swap space idle percentage is less than a second specified value and the number of processes with an oom_adj value greater than 800 is greater than 0, the memory pressure requirement is determined to be greater than the set value. Execute step 204.

[0074] In some specific embodiments, only some of the conditions in the combination of multiple memory idle state information items may be met. For example, if only the swap space idle ratio is less than a first specified value, the memory pressure requirement is determined to be less than the set value. Execute step 206.

[0075] 204. Determine whether there are multiple processes that need to be recycled.

[0076] Specifically, when the memory idle state information satisfies one or more combinations, it is determined that the memory pressure requirement is greater than a set value, and in this case, it is determined that the number of processes that need to be recycled is multiple.

[0077] 205. Select multiple processes from the running processes for memory recovery based on the process oom_adj value.

[0078] Specifically, processes are selected from the running processes in descending order of oom_adj values ​​for memory reclamation until the total free memory value exceeds the set value of memory demand after the selected processes release memory; or until all processes above the selected oom_adj threshold are reclaimed.

[0079] In some embodiments, when a combination of multiple memory idle status information conditions is satisfied: the number of processes with a swap space idle percentage less than a second specified value and an oom_adj value greater than a preset value is greater than a third threshold; or the number of processes with a swap space idle percentage less than the third specified value and an oom_adj value greater than a preset value is greater than a fourth threshold, a reclaimed process is identified from among the processes with an oom_adj value greater than the preset value, and memory reclaim is performed on the reclaimed process. The preset value is typically set to 800, and the third and fourth thresholds are set to 0. That is, when these conditions are met, all processes within the device with an oom_adj value greater than 800 are reclaimed; otherwise, no action is taken.

[0080] 206. Determine that the number of processes that need to be recycled is one.

[0081] Specifically, when the memory idle state information only satisfies some conditions in the combination of multiple memory idle state information items, it is determined that the memory pressure requirement is less than the set value, and the number of processes to be recycled is determined to be one.

[0082] 207. Based on the oom_adj value of the process, the process with the largest current oom_adj value is selected for recycling.

[0083] In the above technical solution, while the device is recycling processes, multiple processes can be selected for recycling by judging the memory idle status information, which solves the problem of unactive recycling due to not considering the idle memory type or recycling only one process.

[0084] In some embodiments, the LMKD mechanism's overly aggressive process recycling may result in the incorrect recycling of some normally running applications. To avoid this, an embodiment of the present invention also provides a process retention method to protect some important processes during process recycling.

[0085] In some embodiments, the memory idle state information may be related to the page jitter value. In this case, some processes need to be retained based on the specific page jitter value and the oom_adj value of the terminal internal process.

[0086] Specifically, the oom_adj retention threshold is determined according to the page jitter value, wherein the page jitter value is negatively correlated with the oom_adj retention threshold, and the larger the page jitter value, the smaller the oom_adj retention threshold, and the smaller the page jitter value, the larger the oom_adj retention threshold.

[0087] A process whose oom_adj value is less than the oom_adj retention threshold is determined as a reserved process, and memory reclamation is not performed on the reserved process; a reclaimed process is determined from processes whose oom_adj value is greater than or equal to the oom_adj retention threshold, and memory reclamation is performed on the reclaimed process.

[0088] Typically, the oom_adj value retention thresholds are set to 900, 701, 201, and 100. The oom_adj value retention threshold range can be further divided based on user needs. The process retention range is determined based on the specific page jitter value.

[0089] In some embodiments, the memory idle status information may show that the total remaining free memory value is greater than the memory watermark. At this time, the process with an oom_adj value of 0 is determined as a reserved process, and the reserved process does not perform memory reclamation; and the reclamation process is determined from the processes with an oom_adj value not being 0, and memory reclamation is performed on the reclamation process.

[0090] Through the above method, when the terminal recycles the internal process, some important processes will be retained to prevent them from being erroneously recycled by the processing unit, thereby avoiding the process flashback when the user is using the terminal.

[0091] Corresponding to the above memory recovery method, an embodiment of the present invention further provides a memory recovery device. Figure 3 The memory recycling device may include: a trigger module 301, an acquisition module 302, a determination module 303, and a recycling module 304.

[0092] The trigger module 301 triggers the memory recycling process upon receiving the memory pressure blocking information PSI event;

[0093] An acquisition module 302 acquires memory idle state information during the memory recycling process;

[0094] Determining module 303, if it is determined according to the memory idle state information that the memory pressure requirement is greater than a set value, then determining that there are multiple processes that need to be recycled;

[0095] The recycling module 304 selects multiple processes from the running processes for memory recycling according to the process oom_adj value.

[0096] Figure 3 The memory recycling device provided in the illustrated embodiment can be used to execute the technical solution of the method embodiment shown in this specification. Its implementation principle and technical effects can be further referred to the relevant description in the method embodiment.

[0097] Figure 4 This is a schematic diagram of the structure of an embodiment of an electronic device in this specification, such as Figure 4 As shown, the electronic device may include at least one processor; and at least one memory communicatively connected to the processing unit, wherein: the memory stores program instructions that can be executed by the processing unit, and the processor calls the program instructions to execute the memory recovery method provided in this embodiment.

[0098] The electronic device can be a device capable of intelligently communicating with a user, such as a cloud server. The specific form of the electronic device is not limited in this specification. It is understood that the electronic device here is the machine mentioned in the method embodiment.

[0099] Figure 4 A block diagram is shown of an exemplary electronic device suitable for implementing embodiments of the present description. Figure 4 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of this specification.

[0100] like Figure 4 As shown, the electronic device is implemented as a general-purpose computing device. Components of the electronic device may include, but are not limited to, one or more processors 410, a communication interface 420, and a memory 430, and a communication bus 440 connecting different system components (including the memory 430, the communication interface 420, and the processor 410).

[0101] Communication bus 440 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of such architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnection (PCI) bus.

[0102] Electronic devices typically include a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device, including volatile and non-volatile media, removable and non-removable media.

[0103] Memory 430 may include computer-readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The electronic device may further include other removable / non-removable, volatile / non-volatile computer system storage media. Memory 430 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of this specification.

[0104] A program / utility having a set (at least one) of program modules may be stored in memory 430. Such program modules include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. The program modules generally perform the functions and / or methods of the embodiments described herein.

[0105] The processor 410 executes various functional applications and data processing by running the programs stored in the memory 430, such as implementing the memory recycling method provided in the embodiments shown in this specification.

[0106] An embodiment of this specification provides a non-transitory computer-readable storage medium, which stores computer instructions. The computer instructions enable the computer to execute the memory recycling method provided by the embodiment shown in this specification.

[0107] The above-mentioned non-transitory computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (Read Only Memory; hereinafter referred to as: ROM), an erasable programmable read-only memory (Erasable Programmable Read Only Memory; hereinafter referred to as: EPROM) or flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by an instruction execution system, device or device or used in combination with it.

[0108] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0109] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0110] Computer program code for performing the operations of this specification can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

[0111] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0112] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature specified as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout this specification, "plurality" means at least two, such as two or three, unless otherwise specifically defined.

[0113] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code comprising one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of this specification includes alternative implementations in which functions may be performed out of the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by those skilled in the art to which the embodiments of this specification belong.

[0114] The word "if," as used herein, may be interpreted as "at the time of" or "when" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if (stated condition or event) is detected" may be interpreted as "when it is determined" or "in response to the determination" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)," depending on the context.

[0115] It should be noted that the terminals involved in the embodiments of this specification may include but are not limited to personal computers (Personal Computer; hereinafter referred to as: PC), personal digital assistants (Personal Digital Assistant; hereinafter referred to as: PDA), wireless handheld devices, tablet computers (Tablet Computer), mobile phones, MP3 players, MP4 players, etc.

[0116] In the embodiments provided in this specification, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some interface, indirect coupling or communication connection of the device or unit, which may be electrical, mechanical or other forms.

[0117] In addition, the functional units in the various embodiments of this specification may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or hardware plus software functional units.

[0118] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit stored in a storage medium includes a number of instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) or a processor to perform some steps of the method described in various embodiments of this specification.

[0119] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.

Claims

1. A memory recovery method, characterized in that: include: When receiving the memory pressure blocking information PSI event, the memory recycling process is triggered; In the memory recycling process, obtaining memory idle state information; If it is determined according to the memory idle state information that the memory pressure requirement is greater than a set value, determining that the number of processes that need to be recycled is multiple; According to the process oom_adj value, multiple processes are selected from the running processes for memory recycling; The memory idle state information also includes a page jitter value; Based on the oom_adj value of the process, multiple processes are selected from the running processes for memory recycling, including: Determining an oom_adj retention threshold according to the page jitter value, wherein the page jitter value and the oom_adj retention threshold are negatively correlated, and the larger the page jitter value, the smaller the oom_adj retention threshold; and Determine a process whose oom_adj value is less than the oom_adj retention threshold as a reserved process, and the reserved process does not perform memory reclamation; A recycling process is determined from processes whose oom_adj values ​​are greater than or equal to the oom_adj retention threshold, and memory recycling is performed on the recycling process.

2. The method according to claim 1, characterized in that The memory idle state information includes: the total remaining free memory value, the percentage of free memory of the highatomic type, the memory requirement information of the upper-layer application, the percentage of free swap space, the time the process waits for hardware resources, and the oom_adj value of the process; if the memory idle state information satisfies one or more of the following combinations, it is determined that the memory pressure requirement is greater than the set value, including: The total value of the remaining free memory is less than the memory watermark; The percentage of free memory of the highatomic type is greater than the first threshold; Specify an application to send memory requirement information; The percentage of free swap space is less than the specified value; The time the process waits for hardware resources is greater than a second threshold; The number of processes whose oom_adj value is greater than a preset value is greater than a third threshold.

3. The method according to claim 2, characterized in that If the memory idle state information satisfies the following combination, it is determined that the memory pressure requirement is greater than a set value, including: The percentage of free swap space is less than the first specified value and the time the process waits for hardware resources is greater than the second threshold; or The number of processes whose swap space free ratio is less than the second specified value and whose oom_adj value is greater than the preset value is greater than the third threshold.

4. The method according to claim 1, wherein Based on the oom_adj value of the process, multiple processes are selected from the running processes for memory recycling, including: Memory is reclaimed by selecting processes from the running processes in descending order of oom_adj values ​​until the total free memory value is greater than or equal to the memory watermark after the selected processes release memory.

5. The method according to any one of claims 1 to 4, characterized in that The memory idle state information includes: the idle swap space ratio; and selecting multiple processes from the running processes for memory reclamation based on the process oom_adj value, including: If the swap space idle ratio is less than the third specified value and the number of processes whose oom_adj values ​​are greater than the preset value is greater than a fourth threshold, a recycling process is determined from the processes whose oom_adj values ​​are greater than the preset value, and memory recycling is performed on the recycling process.

6. The method according to claim 1, characterized in that The memory idle state information also includes the total value of remaining idle memory; according to the process oom_adj value, multiple processes are selected from the running processes for memory recycling, including: If the total remaining free memory value is greater than the memory watermark, the process with an oom_adj value of 0 is determined as a reserved process, and the reserved process does not perform memory reclamation; A recycling process is determined from processes whose oom_adj values ​​are not 0, and memory recycling is performed on the recycling process.

7. A memory recovery device, characterized in that: include: The trigger module triggers the memory recycling process when receiving the memory pressure blocking information PSI event; An acquisition module, which acquires memory idle state information during the memory recycling process; a determination module, which determines that the number of processes to be recycled is multiple if it is determined that the memory pressure requirement is greater than a set value according to the memory idle state information; The recycling module selects multiple processes from the running processes for memory recycling based on the process oom_adj value; The memory idle state information also includes a page jitter value; Based on the oom_adj value of the process, multiple processes are selected from the running processes for memory recycling, including: Determining an oom_adj retention threshold according to the page jitter value, wherein the page jitter value and the oom_adj retention threshold are negatively correlated, and the larger the page jitter value, the smaller the oom_adj retention threshold; and Determine a process whose oom_adj value is less than the oom_adj retention threshold as a reserved process, and the reserved process does not perform memory reclamation; A recycling process is determined from processes whose oom_adj values ​​are greater than or equal to the oom_adj retention threshold, and memory recycling is performed on the recycling process.

8. A memory recycling device, characterized in that: include: at least one processor; as well as at least one memory in communication with the processor, wherein: The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Targeted Memory Pressure Event Notifications

    US20130332942A1

  • Method for terminal acceleration, terminal and storage medium

    US20140208328A1