A method and related device for memory recycling

By calculating the performance stability coefficient of the process and selecting the target process for memory recovery, the problem of failure to consider the real-time status of the process in the existing technology is solved, and the balance between performance and normal operation of the process is improved.

CN114675959BActive Publication Date: 2025-04-29HUAWEI TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011549662.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-24
Publication Date
2025-04-29
Estimated Expiration
2040-12-24

AI Technical Summary

Technical Problem

The existing memory recovery method fails to effectively consider the real-time state of the process, resulting in serious performance losses of memory-sensitive processes, large performance gaps between processes, affecting normal operation.

Method used

By obtaining the performance parameters of the process, such as the number of page missing times, page swap out times and page swap in, calculate the performance stability coefficient of the process, select the target process with a higher performance stability coefficient for memory recycling, and avoid recycling of processes with poor performance.

Benefits of technology

Improves the balance between performance between processes, ensures the normal operation of processes, and avoids performance losses caused by improper memory recovery.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114675959B_ABST
    Figure CN114675959B_ABST
Patent Text Reader

Abstract

The present application discloses a memory recovery method, which can be applied to a terminal. The method includes calculating the performance stability coefficient of each process according to the performance parameters of each process, the performance stability coefficient is used to represent the stable state of the performance of the process, and then selecting a target process according to the stability coefficient, and recovering the page of the target process. By selecting a target process with a higher performance stability coefficient and performing memory recovery on the target process, the scheme can avoid memory recovery for processes with poor performance, improve the balance of performance between processes, and ensure the normal operation of the process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a memory recycling method and related devices. Background Art

[0002] In cloud computing, big data, and machine learning scenarios, computer workloads are often expressed as huge working sets. Huge working sets often require a large amount of memory in the computer. Since the computer's memory capacity is limited, during the operation of the computer, there is often a situation where the capacity of the free memory cannot meet the memory allocation request of the process. Therefore, the system in the computer will periodically recycle memory to meet the memory allocation request of the process.

[0003] At present, the existing memory recycling method only determines the access popularity of pages from the perspective of the system, and executes page recycling based on the access popularity of pages. This memory recycling method does not consider the real-time status of the running process, which can easily cause serious performance loss to memory-sensitive processes, resulting in a large performance gap between processes, affecting the normal operation of the process. Summary of the invention

[0004] The present application provides a memory recovery method and related devices for improving the balance of performance between processes and ensuring the normal operation of the processes.

[0005] The first aspect of the present application provides a memory recovery method, which can be applied to a terminal. The method includes: the terminal obtains the performance parameters of a process in a first process set, the first process set includes N processes currently running on the terminal, N is an integer greater than 1, and the performance parameters include the number of page misses, the number of page swap-outs and / or the number of page swap-ins. Among them, the number of page misses refers to the number of page misses that occur in the process. Specifically, when a process attempts to access a page that has been mapped in a virtual address space, it is found that the page is not loaded in the memory, which can be called a page miss. The number of page swap-outs refers to the number of times a page in the memory of a process is swapped out to a disk, and the number of page swap-outs may include the number of file page swap-outs and / or the number of anonymous page swap-outs. The number of page swap-ins refers to the number of times a page in the disk of a process is swapped into the memory, and the number of page swap-ins may include the number of file page swap-ins and / or the number of anonymous page swap-ins.

[0006] The terminal calculates the performance stability coefficient of the process based on the acquired performance parameters of the process, and the performance stability coefficient is used to indicate the stable state of the performance of the process. Since the performance parameter is a parameter used to indicate the performance information during the running of the process, the stable state of the current performance of the process can be determined based on the performance parameter. Specifically, if the number of page faults of the process increases relative to the previous cycle, the performance of the process is more unstable; if the number of page faults of the process decreases relative to the previous cycle, the performance of the process tends to be stable; if the number of page faults of the process remains unchanged relative to the previous cycle, the performance of the process does not fluctuate.

[0007] The terminal recycles the pages of the target process in the memory, and the target process is a process in the first process set whose performance stability coefficient meets the first preset condition. After the terminal determines the performance stability coefficient of the process based on the performance parameters of the process, the terminal can determine the target process in the first process set whose pages need to be reclaimed based on the performance stability coefficient of the process. Specifically, the terminal can select the process in the first process set whose performance stability coefficient meets the first preset condition as the target process. In simple terms, the terminal can select a process with a lower performance stability coefficient in the first process set as the target process, that is, select a process with relatively stable performance as the target process as much as possible, so as to recycle the pages of the process with relatively stable performance in the memory.

[0008] In this solution, the terminal calculates the performance stability coefficient of the process based on the performance parameters of the process, and selects the target process with a higher performance stability coefficient. By performing memory recycling on the target process with a higher performance stability coefficient, it is possible to avoid memory recycling on the process with poor performance, improve the balance of performance between processes, and ensure the normal operation of the process.

[0009] In a possible implementation, the method further includes: the terminal can select n processes as target processes in the first process set in the order of the performance stability coefficient from small to large. The n processes are the processes in the first process set whose performance stability coefficients meet the first preset condition, that is, the first preset condition is that the process is one of the n processes with the smallest performance stability coefficient. The value of n can be a preset value, for example, the value of n is 3 or 5; for another example, the value of n is 50% of N, that is, the value of n is 50% of the number of all processes in the first process set.

[0010] In this solution, the terminal selects n processes with the smallest performance stability coefficients as the target processes for page recovery, thereby realizing page recovery for the n processes with the most stable performance, avoiding memory recovery for processes with poor performance, improving the performance balance between processes, and ensuring the normal operation of the processes.

[0011] In a possible implementation, the method further includes: the terminal selects a process whose performance stability coefficient is less than a first threshold value from the first process set as a target process. The process whose performance stability coefficient is less than the first threshold value is a process whose performance stability coefficient in the first process set satisfies the first preset condition, that is, the first preset condition is that the performance stability coefficient of the process is less than the first threshold value. The first threshold value is a preset threshold value, and the first threshold value may be, for example, a value such as 0.8 or 1.

[0012] In this solution, the terminal selects the process whose performance stability coefficient is less than a specific threshold as the target process for page recovery. It can recycle pages for processes that meet the performance stability standards, avoid memory recovery for processes with poor performance, improve the performance balance between processes, and ensure the normal operation of the processes.

[0013] In a possible implementation, before the terminal obtains the performance parameters of the processes in the first process set, the method further includes: the terminal obtains the memory usage of the processes in the second process set, the second process set includes M processes, and M is an integer greater than N. The terminal selects N processes from the second process set in descending order of the memory usage to obtain the first process set. In short, the terminal can select multiple processes with larger memory usage from the running processes as the processes in the first process set to execute the subsequent memory recovery process.

[0014] In this solution, the terminal selects processes with large memory usage to perform page recycling, and can reclaim more space memory based on a small number of processes, avoiding page recycling for a large number of processes with small memory usage, thereby effectively improving memory recycling efficiency.

[0015] In a possible implementation, the terminal calculates the performance stability coefficient of the process according to the performance parameters of the process, including: the terminal calculates the first stability coefficient according to the number of page faults of the process in a first cycle and the number of page faults in a second cycle, the second cycle is a cycle previous to the first cycle, and the second cycle has the same cycle length as the first cycle. The terminal calculates the second stability coefficient according to the number of anonymous page swap-outs and anonymous page swap-in of the process. The terminal calculates the performance stability coefficient of the process according to the first stability coefficient and the second stability coefficient.

[0016] In this solution, the terminal evaluates the performance of the process in a certain stage based on the real-time indicators of the process operation, namely the number of page misses, the number of anonymous page swap-outs, and the number of anonymous page swap-in, so as to guide the memory recovery of the process, improve the balance of performance between processes, and ensure the normal operation of the process.

[0017] In a possible implementation, the method further includes: the terminal calculating a page recovery amount of the target process. The terminal recovering pages of the target process in the memory includes: the terminal recovering pages of the target process in the memory according to the page recovery amount.

[0018] In this solution, by precalculating the page recovery amount of the target process, targeted page recovery can be achieved based on the performance of the target process, avoiding excessive page recovery of the target process, which would cause serious performance degradation of the target process.

[0019] In a possible implementation, the terminal calculates the page recovery amount of the target process, including: the terminal obtains the total amount of inactive file pages and the total amount of inactive anonymous pages of the target process in the memory. The terminal calculates the file page recovery amount of the target process based on the total amount of inactive file pages, the recovery coefficient, the number of page faults of the process in the first cycle, and the number of page faults of the second cycle. The terminal calculates the anonymous page recovery amount of the target process based on the total amount of inactive anonymous pages, the recovery coefficient, the number of anonymous page swap-outs and the number of anonymous page swap-in of the process. The terminal recycles the file pages and anonymous pages of the target process in the memory based on the file page recovery amount and the anonymous page recovery amount.

[0020] In this scheme, the recovery weights of anonymous pages and file pages are determined by sensing the sensitivity of the anonymous pages and file pages of the process, and the anonymous pages and file pages of the target process are recovered differentially. This can solve the problem of system memory shortage caused by inaccurate recovery of anonymous pages and file pages, and ensure the rational recovery of file pages and anonymous pages.

[0021] In a possible implementation, after the terminal recycles the pages of the target process in the memory, the method further includes: the terminal recalculates the performance stability coefficient of the target process. If the performance stability coefficient of the target process meets the second preset condition, the terminal adjusts the recovery coefficient to adjust the page recovery amount of the target process. If the performance stability coefficient of the target process does not meet the second preset condition, the terminal stops recovering the pages of the target process in the memory.

[0022] In this solution, after executing page recycling for a process, the page recycling strategy for the process is adjusted based on the performance changes of the process to avoid excessive performance degradation of the process, improve the balance of performance between processes, and ensure the normal operation of the process.

[0023] In one possible implementation, the second preset condition includes that the performance stability coefficient of the target process still satisfies the first preset condition, the performance stability coefficient of the target process is less than a second threshold, the growth rate of the performance stability coefficient of the target process is less than a third threshold and / or the number of recycles of the target process is less than a fourth threshold.

[0024] In this solution, the performance change of the target process is determined through multiple dimensions, which can effectively evaluate the performance change of the target process after executing page recycling, thereby improving the flexibility of the solution.

[0025] In a possible implementation, the terminal adjusts the recovery coefficient, including: if the increase in the performance stability coefficient of the target process is less than a fifth threshold, the terminal reduces the recovery coefficient to increase the page recovery amount of the target process. If the increase in the performance stability coefficient of the target process is greater than or equal to the fifth threshold, the terminal increases the recovery coefficient to reduce the page recovery amount of the target process.

[0026] In this solution, the page recovery amount of the target process is adjusted based on the performance changes of the target process, so as to accurately recover the pages of the target process, avoid excessive performance degradation of the process, improve the balance of performance between processes, and ensure the normal operation of the process.

[0027] The second aspect of the present application provides a terminal, comprising: an acquisition unit and a processing unit. The acquisition unit is used to acquire the performance parameters of a process in a first process set, the first process set includes N processes, N is an integer greater than 1, and the performance parameters include the number of page misses, the number of page swaps out and / or the number of page swaps in. The processing unit is used to calculate the performance stability coefficient of the process based on the performance parameters of the process, and the performance stability coefficient is used to represent the stable state of the performance of the process. The processing unit is also used to recycle the pages of the target process in the memory, and the target process is a process in the first process set whose performance stability coefficient meets the first preset condition.

[0028] In a possible implementation, the processing unit is also used to select n processes as target processes from the first process set in order of the performance stability coefficient from small to large, where n is an integer less than N, and the n processes are processes in the first process set whose performance stability coefficients meet the first preset condition.

[0029] In a possible implementation, the processing unit is also used to select a process whose performance stability coefficient is less than a first threshold from the first process set as a target process, and the process whose performance stability coefficient is less than the first threshold is a process in the first process set whose performance stability coefficient meets the first preset condition.

[0030] In a possible implementation, the acquisition unit is also used to obtain the memory usage of processes in a second process set, where the second process set includes M processes, where M is an integer greater than N; the processing unit is also used to select N processes from the second process set in descending order of the memory usage to obtain the first process set.

[0031] In a possible implementation, the processing unit is further used to calculate a first stability coefficient based on the number of page faults of the process in a first cycle and the number of page faults in a second cycle, wherein the second cycle is the previous cycle of the first cycle and the second cycle has the same cycle length as the first cycle; the processing unit is further used to calculate a second stability coefficient based on the number of anonymous pages swapped out and the number of anonymous pages swapped in of the process; the processing unit is further used to calculate a performance stability coefficient of the process based on the first stability coefficient and the second stability coefficient.

[0032] In a possible implementation, the processing unit is further used to calculate the page recovery amount of the target process; the processing unit is further used to recycle the pages of the target process in the memory according to the page recovery amount.

[0033] In a possible implementation, the acquisition unit is further used to acquire the total amount of inactive file pages and the total amount of inactive anonymous pages of the target process in the memory; the processing unit is further used to calculate the file page recovery amount of the target process based on the total amount of inactive file pages, the recovery coefficient, the number of page faults of the process in the first cycle, and the number of page faults in the second cycle; the processing unit is further used to calculate the anonymous page recovery amount of the target process based on the total amount of inactive anonymous pages, the recovery coefficient, the number of anonymous page swap-outs and the number of anonymous page swap-in of the process; the processing unit is further used to recycle the file pages and anonymous pages of the target process in the memory based on the file page recovery amount and the anonymous page recovery amount.

[0034] In one possible implementation, the processing unit is further used to recalculate the performance stability coefficient of the target process; the processing unit is further used to adjust the recovery coefficient to adjust the page recovery amount of the target process if the performance stability coefficient of the target process meets a second preset condition; the processing unit is further used to stop recovering the pages of the target process in the memory if the performance stability coefficient of the target process does not meet the second preset condition.

[0035] In one possible implementation, the second preset condition includes that the performance stability coefficient of the target process still satisfies the first preset condition, the performance stability coefficient of the target process is less than a second threshold, the growth rate of the performance stability coefficient of the target process is less than a third threshold and / or the number of recycles of the target process is less than a fourth threshold.

[0036] In one possible implementation, the processing unit is further used to reduce the recovery coefficient to increase the page recovery amount of the target process if the increase in the performance stability coefficient of the target process is less than a fifth threshold value; the processing unit is further used to increase the recovery coefficient to reduce the page recovery amount of the target process if the increase in the performance stability coefficient of the target process is greater than or equal to the fifth threshold value.

[0037] The third aspect of the present application provides a terminal, which includes: a processor, a non-volatile memory and a volatile memory; wherein the non-volatile memory or the volatile memory stores computer-readable instructions; the processor reads the computer-readable instructions to enable the terminal to implement a method as in any one of the implementation methods of the first aspect.

[0038] A fourth aspect of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes a method as in any one of the implementation modes of the first aspect.

[0039] The fifth aspect of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute a method as in any one of the implementations of the first aspect.

[0040] In a sixth aspect, the present application provides a chip, comprising one or more processors, wherein some or all of the processors are used to read and execute a computer program stored in a memory to execute a method in any possible implementation of any of the above aspects.

[0041] Optionally, the chip includes a memory, and the memory is connected to the processor through a circuit or wire. Optionally, the chip also includes a communication interface, and the processor is connected to the communication interface. The communication interface is used to receive data and / or information to be processed, and the processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing results through the communication interface. The communication interface can be an input and output interface. The method provided in the present application can be implemented by one chip, or by multiple chips in collaboration. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A schematic diagram of the structure of a terminal 101 provided in an embodiment of the present application;

[0043] Figure 2 A flowchart of a memory recycling method 200 provided in an embodiment of the present application;

[0044] Figure 3 A schematic diagram of a process for reclaiming memory in a new cycle provided in an embodiment of the present application;

[0045] Figure 4 A schematic diagram of a system architecture provided for an embodiment of the present application;

[0046] Figure 5 A schematic diagram of an implementation process of a memory recycling method provided in an embodiment of the present application;

[0047] Figure 6 A flowchart of a memory recycling method 600 provided in an embodiment of the present application;

[0048] Figure 7 A schematic diagram of the performance parameter structure of four processes provided in an embodiment of the present application;

[0049] Figure 8 A schematic diagram of a performance stability coefficient of a process provided in an embodiment of the present application;

[0050] Fig. 9 A schematic diagram showing a comparison of system performances of memory recycling based on an LRU algorithm and a process-level recycling method provided in an embodiment of the present application;

[0051] Fig.10 A schematic diagram showing a comparison of used memory when memory is recycled based on an LRU algorithm and a process-level recycling method provided in an embodiment of the present application;

[0052] Fig.11 A schematic diagram of the operating performance of each process when memory is reclaimed based on the LRU algorithm and the process-level reclaiming method provided in an embodiment of the present application;

[0053] Fig.12 A schematic diagram of the used memory of each process when reclaiming memory based on the LRU algorithm and the process-level recycling method provided in an embodiment of the present application;

[0054] Fig.13 A schematic diagram showing a comparison of system performances of memory recycling based on an LRU algorithm and a process-level recycling method provided in an embodiment of the present application;

[0055] Fig.14 A schematic diagram showing a comparison of used memory when memory is recycled based on an LRU algorithm and a process-level recycling method provided in an embodiment of the present application;

[0056] Fig.15 A schematic diagram of the operating performance of each process when memory is reclaimed based on the LRU algorithm and the process-level reclaiming method provided in an embodiment of the present application;

[0057] Fig.16 A schematic diagram of the used memory of each process when reclaiming memory based on the LRU algorithm and the process-level recycling method provided in an embodiment of the present application;

[0058] Fig.17 A schematic diagram of the structure of a terminal 1700 provided in an embodiment of the present application;

[0059] Fig.18 A schematic diagram of the structure of a computer program product 1800 provided in an embodiment of the present application. DETAILED DESCRIPTION

[0060] The following describes the embodiments of the present application in conjunction with the accompanying drawings. Obviously, the described embodiments are only embodiments of a part of the present application, rather than all embodiments. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0061] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described here can be implemented in an order other than that illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The naming or numbering of steps in this application does not mean that the steps in the method flow must be executed in the time / logical sequence indicated by the naming or numbering. The process steps that have been named or numbered can change the execution order according to the technical purpose to be achieved, as long as the same or similar technical effects can be achieved.

[0062] In cloud computing, big data, and machine learning scenarios, the workload of computers is often expressed as a huge working set. A huge working set often requires a large amount of memory in the computer, resulting in excessive use of machine memory, making the free memory resources in the computer particularly tight. Simply put, due to the limited memory capacity of the computer, a large number of processes in the computer need to request memory allocation during operation, resulting in a situation where the capacity of the free memory in the computer cannot meet the memory allocation requests of the processes. Based on this, the system in the computer will periodically recycle memory to meet the memory allocation requests of the processes.

[0063] However, memory recycling in computer systems can easily cause some performance problems for processes, such as page thrashing. Page thrashing refers to frequent page scheduling, which is caused by the fact that pages that have just been discarded or swapped out need to be swapped into memory again, and pages that have just been swapped in need to be swapped out of memory soon. Therefore, effectively recycling inactive memory is an important means to improve memory utilization and maintain stable process performance.

[0064] In the related art, the Linux system uses a memory watermark mechanism to determine whether memory resources have become tight, thereby triggering page recycling. Specifically, each memory zone in the Linux system has three independent watermark values: minimum watermark value (watermark_min), low watermark value (watermark_low) and high watermark value (watermark_high). Among them, the minimum watermark indicates that the memory is obviously insufficient; the low watermark indicates that the memory has begun to be tight; the high watermark indicates that the memory is still sufficient.

[0065] Specifically, there are two ways for the Linux system to trigger page recycling.

[0066] The first method is to start the direct memory reclaim mode to reclaim memory when it is found that the free memory is lower than the minimum watermark value during the memory allocation phase. In this way, the memory allocation process will be blocked by the memory reclaim operation, increasing the waiting time for memory allocation. The main objects to be reclaimed during page reclaim are anonymous pages and file pages. During the anonymous page reclaim process, the anonymous page needs to be swapped out to the swap partition, resulting in slower input / output (I / O) operations. During the file page reclaim process, if the file page is dirty, the file page also needs to be written back to the disk, resulting in slower I / O operations. In other words, since slow I / O operations need to be performed during the anonymous page and file page reclaim processes, the waiting time for memory allocation is longer, affecting the normal operation of the process.

[0067] The second method is that the system periodically starts background reclaim to perform memory reclaim. Specifically, when the free memory is lower than the low watermark, the system wakes up the kernel thread kswapd to scan each zone to perform memory reclaim.

[0068] It can be seen that the triggering timing of the above two methods is determined by the water level value of the system memory. The memory recycling in these two methods depends on the same memory recycling strategy. Among them, the memory recycling strategy uses a least recently used (Least Recently Used, LRU) algorithm to execute the recycling of pages in the memory.

[0069] The principle of the LRU algorithm is to recycle the least used pages in the recent period, that is, to recycle the pages that are not frequently accessed. Among them, the infrequently accessed pages refer to judging whether the page has been accessed in the previous period from the perspective of the processor. If a page has not been accessed for a long time, it is considered that the access popularity of the page is low and the page is not frequently accessed; if the page has been accessed in a short period of time, it is considered that the access popularity of the page is high and the page is frequently accessed.

[0070] That is to say, the memory recycling strategy in the related art recycles pages based on the access popularity of the pages. The recycling process does not consider the real-time status of the process and recycles pages with low access popularity indiscriminately. The recycling method based on page access popularity cannot identify the degree of impact of recycled pages on performance, that is, it cannot identify which processes' cold pages have the least impact on process performance when recycled.

[0071] For example, the pages in memory of some processes are less frequently accessed, but these processes are more sensitive to page recycling. If the pages in memory of the process are recycled, the performance of the process may fluctuate greatly. For another example, the pages in memory of some processes are more frequently accessed, but these processes are less sensitive to page recycling. If the pages in memory of the process are recycled, the performance of the process may not be greatly affected.

[0072] Due to differences in memory usage and the different importance of memory to processes, reclaiming pages of a process in memory based on page access popularity can easily cause serious performance losses to memory-sensitive processes, resulting in a large performance gap between processes and affecting the normal operation of the processes.

[0073] In view of this, an embodiment of the present application provides a memory recovery method, which can be applied to a terminal. The performance stability coefficient of the process is calculated based on the performance parameters of the process, so as to select a target process with a higher performance stability coefficient. By performing memory recovery on the target process with a higher performance stability coefficient, it is possible to avoid performing memory recovery on the process with poor performance, improve the balance of performance between processes, and ensure the normal operation of the process.

[0074] The terminal involved in the embodiment of the present application can be a device with memory and the operation of the process in the terminal depends on the memory. Exemplarily, the terminal can be, for example, a personal computer (PC), a laptop, a server, a mobile phone, a tablet computer, a mobile internet device (MID), a wearable device, a virtual reality (VR) device, an augmented reality (AR) device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in smart grid, a wireless terminal in transportation safety, a wireless terminal in smart city, a wireless terminal in smart home, etc. The terminal can be a device running Android system, IOS system, Windows system and other systems.

[0075] See also Figure 1 , Figure 1 FIG. 1 is a schematic diagram of the structure of a terminal 101 provided in an embodiment of the present application. Figure 1 As shown, the terminal 101 includes a processor 103, which is coupled to a system bus 105. The processor 103 may be one or more processors, each of which may include one or more processor cores. A display adapter (video adapter) 107, which may drive a display 109, which is coupled to the system bus 105. The system bus 105 is coupled to an input / output (I / O) bus via a bus bridge 111. An I / O interface 115 is coupled to the I / O bus. The I / O interface 115 communicates with a variety of I / O devices, such as an input device 117 (e.g., a touch screen, etc.), a multimedia tray 121 (e.g., a compact disc read-only memory, CD-ROM), a multimedia interface, etc.). A transceiver 123 (which may send and / or receive radio communication signals), a camera 155 (which may capture static and dynamic digital video images), and an external USB port 125. Optionally, the interface connected to the I / O interface 115 may be a USB interface.

[0076] The processor 103 may be any conventional processor, including a reduced instruction set computing (RISC) processor, a complex instruction set computing (CISC) processor, or a combination thereof. Alternatively, the processor may be a dedicated device such as an ASIC.

[0077] The terminal 101 can communicate with the software deployment server 149 through the network interface 129. Exemplarily, the network interface 129 is a hardware network interface, such as a network card. The network 127 can be an external network, such as the Internet, or an internal network, such as Ethernet or a virtual private network (VPN). Optionally, the network 127 can also be a wireless network, such as a WiFi network, a cellular network, etc.

[0078] The hard disk drive interface 131 is coupled to the system bus 105. The hard disk drive interface is connected to the hard disk drive 133. The system memory 135 is coupled to the system bus 105. The data running in the system memory 135 may include the operating system (OS) 137 of the terminal 101, the application program 143 and the scheduler.

[0079] The operating system includes a shell 139 and a kernel 141. Shell 139 is an interface between the user and the kernel of the operating system. The shell is the outermost layer of the operating system. The shell manages the interaction between the user and the operating system: waiting for user input, interpreting user input to the operating system, and processing various operating system output results.

[0080] The kernel 141 consists of those parts of the operating system that manage memory, files, peripherals, and system resources. The kernel 141 interacts directly with the hardware. The operating system kernel usually runs processes and provides communication between processes, provides CPU time slice management, interrupts, memory management, IO management, etc.

[0081] Exemplarily, when the terminal 101 is a server, the application 143 includes cloud computing related programs. In one embodiment, when the application 143 needs to be executed, the terminal 101 can download the application 143 from the software deployment server 149. In one embodiment, when the terminal 101 downloads the application 143 from the software deployment server 149, the terminal 101 can also download the scheduling table corresponding to the application 143 from the software deployment server 149.

[0082] To facilitate understanding, some technical terms involved in the embodiments of the present application are introduced below.

[0083] Anonymous pages refer to pages without file backgrounds, such as heaps, stacks, and data segments. Anonymous pages do not exist in the form of files and cannot be exchanged with disk files. By dividing an additional swap partition on the disk, inactive anonymous pages can be swapped to the disk to alleviate memory tension. Among them, the swap partition is a storage space opened up by the system on the disk, which can be used as a memory cache.

[0084] File page refers to a page with a file background. File page is the cache generated in the memory after the program reads the file, which is generally called file cache.

[0085] Page fault, also known as page fault interrupt, page fault, etc., refers to an interrupt issued by the processor's memory management unit when the software attempts to access a page that has been mapped in the virtual address space but has not been loaded in the physical memory.

[0086] Memory recycling refers to the system recycling the pages of the process in memory while ensuring that the application data is not lost. There are usually three ways to recycle pages: page writeback, page swap, and page discard.

[0087] Page writeback means that if the recycled page is a file page, the file page is written back to the location corresponding to the file page in the disk.

[0088] Page swapping means that if the recycled page is an anonymous page, the anonymous page is swapped to the swap partition. When the anonymous page is accessed again, it is swapped back to the memory from the swap partition.

[0089] Page discard means that if the recycled page is a file page, but the file content corresponding to the file page cannot be modified in the memory, the file page can be discarded.

[0090] See also Figure 2 , Figure 2 A flowchart of a memory recycling method 200 provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method 200 includes the following steps 201-203.

[0091] Step 201, obtaining performance parameters of processes in a first process set, wherein the first process set includes N processes, where N is an integer greater than 1, and the performance parameters include the number of page misses, the number of page swap-outs, and / or the number of page swap-in.

[0092] In this embodiment, the first process set includes N processes, and the N processes are the processes currently running in the terminal. The performance parameter is a parameter used to indicate the performance information during the process operation, and the performance parameter includes the number of page faults, the number of page swap-outs and / or the number of page swap-ins of the process. Among them, the number of page faults refers to the number of page faults that occur in the process. Specifically, when a process attempts to access a page that has been mapped in the virtual address space, it is found that the page is not loaded in the memory, which can be called a page fault. The number of page swap-outs refers to the number of times the pages of the process in the memory are swapped out to the disk, and the number of page swap-outs can include the number of file page swap-outs and / or the number of anonymous page swap-outs. The number of page swap-ins refers to the number of times the pages of the process in the disk are swapped into the memory, and the number of page swap-ins can include the number of file page swap-ins and / or the number of anonymous page swap-ins.

[0093] Optionally, when the terminal periodically performs memory recycling, the terminal may obtain performance parameters of processes in the first process set within a cycle, that is, obtain the number of page misses, page swap-outs, and / or page swap-ins of processes in the first process set within a cycle. The time length of a cycle in which the terminal performs memory recycling may be, for example, 10 milliseconds, 20 milliseconds, or 50 milliseconds, that is, the terminal may obtain the performance parameters of processes in the first process set within these 50 milliseconds every 50 milliseconds. In actual applications, the time length of the cycle in which the terminal performs memory recycling may be adjusted according to the processing capability of the terminal and the memory size of the terminal, and this embodiment does not specifically limit the time length of the cycle in which the terminal performs memory recycling.

[0094] When the terminal has a strong processing capability, a large number of processes may be running in the terminal at the same time, and the memory sizes occupied by different processes are also different. For example, some processes may occupy most of the memory (such as 80% of the memory), while other processes may occupy only a small part of the memory (such as only 1% of the memory). In this case, for the processes that occupy most of the memory, you only need to recycle part of the memory occupied by these processes to obtain more free memory. For the processes that only occupy a small part of the memory, even if all the memory occupied by these processes is recycled, only less free memory can be obtained.

[0095] Therefore, in a possible embodiment, the terminal may select multiple processes with larger memory usage from the running processes as processes in the first process set to execute a subsequent memory recovery process.

[0096] Exemplarily, the terminal obtains the memory usage of processes in the second process set, where the second process set includes M processes, where M is an integer greater than N. For example, the M processes included in the second process set may be all processes currently running on the terminal. The terminal selects N processes from the second process set in descending order of memory usage to obtain the first process set.

[0097] For example, assuming that the second process set includes 10 processes and the value of N is 5, the terminal can obtain the memory usage of the 10 processes included in the second process set, and sort the 10 processes in descending order of memory usage, with the process with the larger memory usage being at the front. Based on the value of N being 5, the terminal selects the top 5 processes from the 10 sorted processes to obtain the first process set.

[0098] The value of N may be a preset value, such as 5, 10, or 15; or 20% of M, that is, 20% of the number of all currently running processes. In actual applications, the value of N may be adjusted according to the memory size in the terminal and the expected memory recovery rate, and this embodiment does not specifically limit the value of N.

[0099] Step 202: Calculate a performance stability coefficient of the process according to the performance parameters of the process, where the performance stability coefficient is used to represent a stable state of the performance of the process.

[0100] It is understandable that, since the performance parameter is a parameter used to indicate the performance information during the process running, the stable state of the current performance of the process can be determined based on the performance parameter. Specifically, if the number of page faults of the process increases relative to the previous cycle, the performance of the process is more unstable; if the number of page faults of the process decreases relative to the previous cycle, the performance of the process tends to be stable; if the number of page faults of the process remains unchanged relative to the previous cycle, the performance of the process has not fluctuated. In addition, if the number of page swaps out of the process is much larger than the number of page swaps in of the process, it means that the memory occupied by the process is insufficient and the performance of the process is not stable; if the number of page swaps out of the process is close to the number of page swaps in of the process, it means that the page of the process has experienced page thrashing and the performance of the process is extremely unstable; if the number of page swaps out of the process is close to 0, it means that the memory occupied by the process is relatively sufficient and the performance of the process is extremely stable.

[0101] In a possible embodiment, the terminal calculates the performance stability coefficient of the process according to the performance parameters of the process, specifically including: the terminal calculates the first stability coefficient according to the number of page faults of the process in the first cycle and the number of page faults in the second cycle, wherein the second cycle is the previous cycle of the first cycle, and the second cycle has the same cycle length as the first cycle. That is, the terminal determines the first stability coefficient based on the change in the number of page faults of the current cycle of the process relative to the number of page faults of the previous cycle. The terminal calculates the second stability coefficient according to the number of anonymous pages swapped out and the number of anonymous pages swapped in of the process. That is, the terminal determines the second stability coefficient based on the relative size relationship between the number of anonymous pages swapped out and the number of anonymous pages swapped in of the process. Finally, the terminal calculates the performance stability coefficient of the process according to the first stability coefficient and the second stability coefficient.

[0102] It is understandable that the number of page misses includes the total number of misses for file pages and anonymous pages, that is, it reflects the total page swap-in situation of file pages and anonymous pages. In addition, since the number of file page swap-outs does not have a significant impact on process performance, the performance stability coefficient of the process can be determined not based on the number of file page swap-outs, that is, the performance stability coefficient of the process is not reflected based on the number of file page swap-outs. Then, the performance stability coefficient of the process determined based on the number of anonymous page swap-ins, the number of anonymous page swap-outs, and the total number of file page and anonymous page misses can effectively represent the performance stability state of the process.

[0103] Exemplarily, the terminal may calculate the performance stability coefficient of the process by using Formula 1 according to the performance parameters of the process.

[0104] Specifically, Formula 1 is as follows.

[0105]

[0106] Among them, R i represents the performance stability coefficient of process i, R i The smaller it is, the more stable the performance of process i is. i The larger it is, the more unstable the performance of process i is. represents the first stability coefficient; Represents the second stability factor; RF i Indicates the number of page faults in the first cycle of the process; PREV_PE i Indicates the number of page misses of the process in the second cycle; the second cycle is the previous cycle of the first cycle, and the second cycle has the same cycle length as the first cycle; SI i Indicates the number of anonymous page swaps; SO irepresents the number of anonymous page swaps; a represents the first coefficient; and b represents the second coefficient. Specifically, the first coefficient a is used to ensure that the denominator in the first stability coefficient is not 0, and the second coefficient b is used to ensure that the denominator in the second stability coefficient is not 0. The value of the first coefficient a can be, for example, 1, and the value of the second coefficient b can also be, for example, 1. This embodiment does not specifically limit the values ​​of the first coefficient and the second coefficient.

[0107] It can be seen from formula 1 that if the number of page faults in the first cycle PF i Relative to the number of page faults in the second cycle PREV_PE i The larger the first stability factor is, the more unstable the process performance is. i Relative to the number of page faults in the second cycle PREV_PF i The smaller the first stability factor is, the smaller the first stability factor is, that is, the performance of the process tends to be stable. i Relative to the number of page faults in the second cycle PREV_PF i If it does not change, the first stability coefficient is a relatively fixed value, and the performance of the process does not fluctuate.

[0108] In addition, if the number of page swaps out of the process is SO i Much larger than the number of pages swapped into the process SI i , it means that the memory occupied by the process is insufficient, the second stability coefficient is large, and the performance of the process is not stable. i The number of pages swapped in by the process SI i If the number of page swaps is close to 1, it means that the page of the process has experienced page thrashing, the second stability coefficient is close to the maximum value, and the performance of the process is extremely unstable. i When it is close to 0, it means that the memory occupied by the process is relatively sufficient. The second stability coefficient is close to 0, and the performance of the process is extremely stable.

[0109] Step 203: reclaiming pages of the target process in the memory, wherein the target process is a process in the first process set whose performance stability coefficient meets a first preset condition.

[0110] In this embodiment, after the terminal determines the performance stability coefficient of the process based on the performance parameters of the process, the terminal can determine the target process whose page needs to be reclaimed in the first process set based on the performance stability coefficient of the process. Specifically, the terminal can select the process whose performance stability coefficient meets the first preset condition in the first process set as the target process. In simple terms, the terminal can select the process with a lower performance stability coefficient in the first process set as the target process, that is, select the process with more stable performance as the target process as much as possible, so as to reclaim the page in the memory of the process with more stable performance.

[0111] In a possible embodiment, the terminal may select n processes as target processes in the first process set in the order of the performance stability coefficient from small to large. The n processes are the processes in the first process set whose performance stability coefficients satisfy the first preset condition, that is, the first preset condition is that the process is one of the n processes with the smallest performance stability coefficient. The value of n may be a preset value, such as a value of 3 or 5; for another example, the value of n is 50% of N, that is, the value of n is 50% of the number of all processes in the first process set. In actual applications, the value of n can also be adjusted according to the memory size in the terminal and the expected memory recovery rate, and this embodiment does not specifically limit the value of n.

[0112] In simple terms, the number of target processes is fixed. The terminal sorts the N processes in the first process set based on their performance stability coefficients, and the processes with smaller performance stability coefficients are ranked higher. Then, the terminal selects the top n processes in the N processes as the target processes.

[0113] For example, assuming that N is 5 and n is 3, the first process set includes the five processes {A1, A2, A3, A4, A5}. The terminal calculates the performance stability coefficients of the five processes {A1, A2, A3, A4, A5} to be {0.92, 0.84, 0.71, 0.76, 0.85} respectively. Then, the terminal sorts the performance stability coefficients of the five processes in the order of arrival from the smallest to the smallest, and obtains: 0.71<0.76<0.84<0.85<0.92. Based on this, the terminal selects the top three processes as the target processes, namely, process A3 with a performance stability coefficient of 0.11, process A4 with a performance stability coefficient of 0.16, and process A2 with a performance stability coefficient of 0.24.

[0114] In another possible embodiment, the terminal selects a process whose performance stability coefficient is less than a first threshold value from the first process set as the target process. The process whose performance stability coefficient is less than the first threshold value is a process whose performance stability coefficient satisfies the first preset condition in the first process set, that is, the first preset condition is that the performance stability coefficient of the process is less than the first threshold value. The first threshold value is a pre-set threshold value, and the first threshold value can be, for example, a value such as 0.8 or 1. In actual applications, the size of the first threshold value can be adjusted according to the memory size in the terminal and the expected memory recovery rate, and this embodiment does not specifically limit the value of n.

[0115] In short, the number of target processes is not fixed. For the N processes in the first process set, as long as the performance stability coefficient of the process is less than the first threshold, the terminal can determine the process as the target process.

[0116] For example, assuming that N is 5, n is 3, and the first threshold is 0.8, that is, the first process set includes 5 processes {A1, A2, A3, A4, A5}. The terminal calculates that the performance stability coefficients of the 5 processes {A1, A2, A3, A4, A5} are {0.92, 0.84, 0.71, 0.76, 0.85} respectively. Based on the condition that the performance stability coefficient is less than 0.8, the terminal can determine that process A3 with a performance stability coefficient of 0.71 and process A4 with a performance stability coefficient of 0.76 are the target processes.

[0117] In this embodiment, the terminal calculates the performance stability coefficient of the process based on the performance parameters of the process, thereby selecting a target process with a higher performance stability coefficient. By performing memory recycling on the target process with a higher performance stability coefficient, it is possible to avoid memory recycling on processes with poor performance, improve the balance of performance between processes, and ensure the normal operation of the process.

[0118] In a possible embodiment, the terminal may periodically execute the above-mentioned memory recovery method 200, that is, the terminal repeats the above-mentioned steps 201-203 in each cycle. That is, in each cycle, the terminal obtains the performance parameters of the processes in the first process set in the current cycle, and calculates the performance stability coefficient of the processes based on the performance parameters of the processes, thereby recovering the pages of the processes whose performance stability coefficients meet the first preset conditions. By periodically executing the above-mentioned memory recovery method 200, the terminal can continuously recover the pages of one or more processes with the most stable performance in each cycle, avoiding the serious performance degradation of a process due to continuous recovery of the pages of the process, thereby ensuring the performance balance of the global process.

[0119] In a possible embodiment, before the terminal recycles the pages of the target process in the memory, the terminal may also calculate the page recycle amount of the target process. After obtaining the page recycle amount of the target process, the terminal recycles the pages of the target process in the memory according to the page recycle amount.

[0120] It is understandable that, since the performance stability states and the number of inactive pages of the multiple target processes determined by the terminal are not the same, the terminal can recycle the pages of the multiple target processes differently. For example, for a target process with more stable performance, the terminal recycles more pages of the target process; for a target process with more inactive pages in the memory, the terminal recycles more pages of the target process.

[0121] Optionally, the terminal calculates the page recovery amount of the target process, which may specifically include the following steps S1-S3.

[0122] Step S1, the terminal obtains the total amount of inactive file pages and the total amount of inactive anonymous pages of the target process in the memory.

[0123] Specifically, a kernel preclaim (kpreclaimed) thread may be run in the terminal, and the kpreclaimed thread scans the pages in the memory to obtain the inactive file pages and inactive anonymous pages of each thread in the memory. Generally speaking, for the pages in the memory, the system may establish a queue or linked list corresponding to the page.

[0124] Taking a queue as an example, by establishing a queue corresponding to a page, the page can be sorted according to the page access time to obtain a queue composed of all pages in the memory. In the queue, if the page access time is closer to the current moment, that is, the closer the time to access the page, the higher the order of the page in the queue; if the page access time is farther from the current moment, that is, the longer the time to access the page, the lower the order of the page in the queue. Then, for pages that are ranked later in the queue (for example, 10% or 20% of the pages ranked later in the queue), these pages can be considered as inactive pages, thereby obtaining inactive file pages and inactive anonymous pages. Optionally, the file page and the anonymous page can be in the same queue, or the file page and the anonymous page can be in different queues. For example, assuming that the 20% of pages ranked last in the queue are inactive pages, and there are 1000 pages in the current queue, the terminal can determine that the 100 pages ranked last in the queue are inactive pages.

[0125] Taking the linked list as an example, the system can determine the activity of the page by establishing an LRU linked list. Among them, the LRU linked list is arranged according to the recent usage of the page. The most recently used page exists at the head of the linked list, and the least recently used page exists at the end of the linked list. Specifically, the LRU linked list can include four linked lists: INACTIVE_ANON, ACTIVE_ANON, INACTIVE_FILE, and ACTIVE_FILE, and the physical pages in these four linked lists can be recycled. Among them, ANON represents anonymous pages, FILE represents file pages, INACTIVE represents inactive, and ACTIVE represents active. The activity of physical pages in the ACTIVE linked list is higher than that of physical pages in the INACTIVE linked list. In other words, the activity of physical pages in the active state is higher than that of physical pages in the inactive state. Generally speaking, when the memory is insufficient, the system will give priority to recycling the physical pages in the INACTIVE_ANON and INACTIVE_FILE linked lists in the LRU linked list. When the process needs to use the content on the recycled physical page, it needs to load the corresponding physical page from the disk.

[0126] In addition, when the terminal periodically executes the above method 200 to recycle memory, if the terminal has already recycled the pages of the target process, the terminal can calculate the total amount of inactive file pages corresponding to the target process based on the total amount of inactive file pages of the target process in the previous cycle and the number of file pages recycled in the previous cycle (i.e., the total amount of inactive file pages in the previous cycle minus the number of file pages recycled in the previous cycle). Similarly, if the terminal has already recycled the pages of the target process, the terminal can calculate the total amount of inactive anonymous pages corresponding to the target process based on the total amount of inactive anonymous pages of the target process in the previous cycle and the number of anonymous pages recycled in the previous cycle.

[0127] Step S2, the terminal calculates the file page recovery amount of the target process according to the total amount of the inactive file pages, the recovery coefficient, the number of page faults of the process in the first cycle, and the number of page faults of the second cycle.

[0128] Exemplarily, the terminal may calculate the file page recovery amount of the target process by using Formula 2. Specifically, Formula 2 is as follows.

[0129]

[0130] Among them, IAF i Indicates the amount of file page recycling; INFC i Indicates the total amount of inactive file pages; SI i Indicates the number of anonymous page swaps; SO i Indicates the number of anonymous pages swapped out; α i represents the recovery factor, α i The value of can be 5, for example. It can be seen from formula 2 that the recovery coefficient α i The larger the value, the larger the file page recovery amount. i The smaller the recovery coefficient α i The smaller the file page recovery amount is, the smaller the file page recovery amount is. i The bigger.

[0131] Step S3, the terminal calculates the anonymous page recovery amount of the target process according to the total amount of inactive anonymous pages, the recovery coefficient, the number of anonymous page swap-outs and the number of anonymous page swap-in of the process.

[0132] Exemplarily, the terminal may calculate the anonymous page recovery amount of the target process by using Formula 3. Specifically, Formula 3 is as follows.

[0133]

[0134] Among them, IAN i Indicates the amount of anonymous page recovery; INAC iIndicates the total number of inactive anonymous pages; PF i Indicates the number of page faults in the first cycle of the process; PREV_PF i Indicates the number of page misses of the process in the second cycle; α i represents the recovery factor, α i The value of can be 5, for example. It can be seen from formula 3 that the recovery coefficient α i The larger the anonymous page recovery amount IAN i The smaller the recovery coefficient α i The smaller the anonymous page recovery amount IAN i The bigger.

[0135] In this way, when reclaiming pages of the target process, the terminal can reclaim the file pages and anonymous pages of the target process in the memory according to the calculated file page reclaim amount and the anonymous page reclaim amount.

[0136] In a possible embodiment, when the terminal periodically recycles memory, after reclaiming the pages of the target process in the memory, the terminal can continue to calculate the performance stability coefficient of the target process in the previous cycle. If the performance stability coefficient of the target process does not change much, that is, the performance of the target process has not been greatly lost, the strength of page recovery can be increased, and the pages of the target process can be recovered again. If the performance stability coefficient of the target process changes greatly, that is, the performance loss of the target process is too great, the strength of page recovery can be reduced or the recovery of the pages of the target process can be stopped.

[0137] Specifically, after the terminal recycles the pages of the target process in the memory, in the new cycle, the terminal can re-execute the above steps 201-202 to determine the target process in the new cycle. For the target process in the new cycle, if the target process was also determined as the target process in the previous cycle and the page recycling was performed, the terminal can determine whether the target process meets the second preset condition, thereby adjusting the recycling coefficient and continuing to recycle the pages of the target process or stopping recycling the pages of the target process. If the target process in the new cycle was not determined as the target process in the previous cycle, the terminal can recycle the pages of the target process in the memory by executing the above step 203.

[0138] For example, see Figure 3 , Figure 3 A schematic diagram of a process for reclaiming memory in a new cycle provided in an embodiment of the present application.

[0139] Step 301: The terminal determines a target process in a new cycle.

[0140] In the new cycle, the terminal can reacquire the first process set and obtain the performance parameters of the processes in the first process set. Then, the terminal calculates the performance stability parameters of the processes in the first process set in the new cycle based on the performance parameters of the processes in the first process set in the new cycle, and determines the target process in the new cycle based on the performance stability coefficients of the processes. Specifically, the way in which the terminal acquires the performance parameters of the processes in the first process set in the new cycle is similar to step 201, and the details can be referred to the above-mentioned step 201, which will not be repeated here. The way in which the terminal determines the target process in the new cycle based on the performance parameters of the processes in the first process set in the new cycle is similar to step 202, and the details can be referred to the above-mentioned step 202, which will not be repeated here.

[0141] Step 302: The terminal determines whether the target process determined in the new cycle was also determined as a target process in the previous cycle.

[0142] Since the terminal has recovered the pages of the target processes determined in the previous cycle in the previous cycle, the performance stability coefficients of these target processes may change in the new cycle. When the performance of the target processes determined in the previous cycle decreases more in the new cycle, these target processes may no longer meet the first preset condition in the new cycle, and thus are no longer determined as target processes in the new cycle; when the performance of the target processes determined in the previous cycle decreases less in the new cycle, these target processes may still meet the first preset condition in the new cycle, and thus continue to be determined as target processes in the new cycle. For processes that are still determined as target processes in the new cycle, the terminal can adjust the page recovery strength of the process based on the changes in the performance stability coefficient of the process, so as to achieve dynamic adjustment of the page recovery amount of the process based on feedback of the performance stability coefficient.

[0143] Based on this, the terminal can determine whether the target process determined in the new cycle was also determined as the target process in the previous cycle, that is, determine whether the target process determined in the new cycle has been determined as the target process for two consecutive cycles.

[0144] Step 303: If the target process determined in the new cycle has not been determined as the target process in the previous cycle, the terminal calculates the page recovery amount of the target process determined in the new cycle and recovers the pages of the target process in the memory.

[0145] In this embodiment, if the target process determined in the new cycle has not been determined as the target process in the previous cycle, the target process can be considered to be the newly determined target process in the new cycle, and there is no need to adjust the page recovery strength of the target process. Therefore, the terminal can calculate the page recovery amount of the target process determined in the new cycle and recover the pages of the target process in the memory according to the pre-set recovery coefficient. Among them, the process of the terminal calculating the page recovery amount of the target process determined in the new cycle and recovering the pages of the target process in the memory is similar to the above-mentioned step 203, and the details can be referred to the above-mentioned step 203, which will not be repeated here.

[0146] Step 304: If the target process determined in the new cycle has been determined as the target process in the previous cycle, the terminal determines whether the performance stability coefficient of the target process determined in the new cycle meets the second preset condition.

[0147] Exemplarily, the second preset condition includes that the performance stability coefficient of the target process still satisfies the first preset condition, the performance stability coefficient of the target process is less than the second threshold, the growth rate of the performance stability coefficient of the target process is less than the third threshold, and / or the number of recycling times of the target process is less than the fourth threshold. Among them, the second threshold can be 1.5, the third threshold can be 1.6, and the fourth threshold can be 4. In actual applications, the second threshold, the third threshold and the fourth threshold can be adjusted according to the memory size of the terminal and the expected memory recycling rate. This embodiment does not specifically limit the values ​​of the second threshold, the third threshold and the fourth threshold.

[0148] Step 305: If the performance stability coefficient of the target process determined in the new cycle meets the second preset condition, the terminal determines whether the increase in the performance stability coefficient of the target process is less than the fifth threshold.

[0149] If the performance stability coefficient of the target process determined in the new cycle meets the second preset condition, it can be considered that the performance of the target process has not decreased much, and the target process is still in a relatively stable performance state. Therefore, the terminal can further determine the performance change of the target process to determine how to adjust the page recovery amount of the target process.

[0150] Specifically, the terminal can adjust the recovery coefficient corresponding to the target process by determining whether the increase in the performance stability coefficient of the target process is less than the fifth threshold value, so as to adjust the page recovery amount of the target process. The value of the fifth threshold value can be, for example, 0.5. In actual applications, the fifth threshold value can be adjusted according to the memory size of the terminal and the expected memory recovery rate. This embodiment does not specifically limit the value of the fifth threshold value.

[0151] In addition, in addition to determining the performance change of the target process by determining whether the increase in the performance stability coefficient of the target process is less than the fifth threshold, the terminal can also determine the performance change of the target process by determining the change in the ranking number of the performance stability coefficient of the target process in the previous cycle in the first process set and the ranking number of the performance stability coefficient of the target process in the new cycle in the first process set. If the difference between the ranking numbers of the performance stability coefficients corresponding to the two cycles is less than a preset value, that is, the ranking number has no obvious change, it can be considered that the performance change of the target process is not obvious.

[0152] Step 306: If the increase in the performance stability coefficient of the target process is less than the fifth threshold, the terminal reduces the recovery coefficient to increase the page recovery amount of the target process.

[0153] In simple terms, if the terminal determines that the increase in the performance stability coefficient of the target process is less than the fifth threshold, it can be considered that the performance change of the target process is not obvious, that is, the impact of recycling the pages of the target process in the memory on the performance of the target process is relatively small, so the page recycling amount of the target process can be increased. Specifically, the terminal can reduce the recycling coefficient, for example, subtract 1 from the value of the recycling coefficient, and then calculate the file page recycling amount of the target process based on the following formula 4, and calculate the anonymous page recycling amount of the target process based on formula 5, and recycle the file pages and anonymous pages of the target process according to the calculated file page recycling amount and anonymous page recycling amount.

[0154] Specifically, Formula 4 is as follows.

[0155]

[0156] Among them, IAF i Indicates the amount of file page recycling; INFC i Indicates the total amount of inactive file pages; prev_IAF i Indicates the amount of file pages recovered in the previous cycle of the target process; SI i Indicates the number of anonymous page swaps; SO i Indicates the number of anonymous pages swapped out; α i represents the recovery factor, α i The value of can be 4, for example.

[0157] Specifically, Formula 5 is as follows.

[0158]

[0159] Among them, IAN i Indicates the amount of anonymous page recovery; INAC i Indicates the total number of inactive anonymous pages; prev_IANi Indicates the amount of anonymous pages recovered by the target process in the previous cycle; PF i Indicates the number of page faults in the first cycle of the process; PREV_PF i Indicates the number of page misses of the process in the second cycle; α i represents the recovery factor, α i The value of can be 4, for example.

[0160] Step 307: If the increase in the performance stability coefficient of the target process is greater than or equal to the fifth threshold, the terminal increases the recovery coefficient to reduce the page recovery amount of the target process.

[0161] In simple terms, if the terminal determines that the increase in the performance stability coefficient of the target process is greater than or equal to the fifth threshold, it can be considered that the performance change of the target process is more obvious, that is, the recovery of the pages of the target process in the memory has a greater impact on the performance of the target process, so the page recovery amount of the target process can be reduced. Specifically, the terminal can increase the recovery coefficient, for example, add 1 to the value of the recovery coefficient, and then calculate the file page recovery amount of the target process based on the above formula 4, and calculate the anonymous page recovery amount of the target process based on the above formula 5, and recover the file pages and anonymous pages of the target process according to the calculated file page recovery amount and anonymous page recovery amount.

[0162] Step 308: If the performance stability coefficient of the target process determined in the new cycle does not satisfy the second preset condition, the terminal stops recycling the pages of the target process in the memory.

[0163] If the performance stability coefficient of the target process determined in the new cycle does not meet the second preset condition, it can be considered that the performance of the target process has declined significantly and the target process is in an unstable performance state. Therefore, the terminal can start recycling protection for the target process and stop recycling the pages of the target process in the memory to avoid excessive performance loss of the target process.

[0164] The above introduces the execution process of the memory recovery method provided in the embodiment of the present application. The following will introduce the implementation process of the memory recovery method in combination with the system architecture used to implement the memory recovery method.

[0165] See also Figure 4 , Figure 4 A schematic diagram of a system architecture provided in an embodiment of the present application. Figure 4 As shown, the system architecture includes: an active trigger module, a passive trigger module, a kpreclaimed thread and a process pool module.

[0166] The active trigger module is used to trigger the direct memory recycling process when it is found that the regional memory is lower than the low water mark value during the memory allocation process.

[0167] The passive trigger module is used to wake up the kernel thread kswapd process when the system memory is lower than the lowest water mark value of the area to reclaim memory in the area.

[0168] The system also establishes an active linked list and an inactive linked list based on the pages in the memory. The active linked list indicates the active pages in the memory, and the inactive linked list indicates the inactive pages in the memory. When the active trigger module and the passive trigger module trigger memory recycling, they recycle the inactive pages indicated in the inactive linked list.

[0169] The process pool module is used to manage the N processes in the first process set. Specifically, the process pool module includes N process nodes, which are organized in a K-heap tree structure in the order of the memory usage of the process from large to small. Among them, the process pool module can be divided into three modules: a physical page table pool module, an inactive memory pool module, and a state parameter pool module.

[0170] The physical page table pool module is used to maintain the mapping relationship between the virtual addresses and physical addresses of N processes in the K heap tree.

[0171] The inactive memory pool module is used to manage the inactive physical pages of each process, including reclaimable inactive anonymous pages and inactive file pages, which can be obtained by the kpreclaimed scanning module by scanning N processes in the K heap tree.

[0172] The state parameter pool module is used to maintain the performance parameters and stable state coefficients of the process. Among them, the performance parameters mainly include real-time parameters such as the number of page misses, the number of page swap-ins and the number of page swap-outs; the stable state coefficient includes the performance stability coefficient of the process (calculated by the monitoring module) and the recovery coefficient of the process.

[0173] The kpreclaimed thread can be divided into four modules, including: scanning module, monitoring module, feedback module and recycling module.

[0174] The monitoring module is used to pass the performance parameters, performance stability coefficient and recovery coefficient of the process to the feedback module, then calculate the total amount of inactive pages in this cycle, and instruct the recovery module to recycle pages according to the performance stability coefficient and recovery coefficient.

[0175] The scanning module is used to scan the page tables of the N processes with the largest memory usage in the process pool, and move the inactive pages of these N processes from the inactive linked list of the system zone area to the process inactive linked list pool. During the two scans of the scanning module, if the page is accessed, the page is moved to the active linked list of the system zone area.

[0176] The monitoring module is used to monitor the performance parameters of N processes in the K heap tree and modify the performance parameters of the node to which the process belongs in the process pool module, that is, the data in the status parameter pool, mainly including real-time parameters such as the number of page misses, the number of page swaps in and the number of page swaps out.

[0177] The feedback module is used to calculate the performance stability coefficient of the process and determine the total amount of inactive anonymous pages and inactive file pages that need to be reclaimed for each process based on the performance parameters transmitted by the monitoring module, so as to fine-grainedly adjust the page recovery process of the process.

[0178] The recycling module is used to determine the stable state of the process based on the performance stability coefficient calculated by the feedback module, select the processes with the top n performance stability coefficients among N processes (the smaller the performance stability coefficient, the higher the ranking), and recycle anonymous pages and file pages in the inactive memory pool in a feedback manner.

[0179] For example, see Figure 5 , Figure 5 A schematic diagram of the implementation process of a memory recycling method provided in an embodiment of the present application. Figure 5 As shown, in the process pool module, multiple process nodes are organized according to the structure of the K heap tree. The physical page pool included in the process pool module includes physical pages corresponding to each process node. The scanning module in the kpreclaimed thread adds inactive pages to the inactive linked list pool of the process by scanning the physical pages of each process in the physical page pool. The monitoring module in the kpreclaimed thread obtains the performance parameters of N processes by monitoring the performance of the processes in the K heap tree. The feedback module in the kpreclaimed thread calculates the performance stability coefficient of the process based on the performance parameters transmitted by the monitoring module and determines the total amount of inactive anonymous pages and the total amount of inactive file pages that each process needs to recycle. The recycling module in the kpreclaimed thread determines the stable state of the process based on the performance stability coefficient calculated by the feedback module, and recycles the anonymous pages and file pages in the inactive memory pool in a feedback manner.

[0180] See also Figure 6 , Figure 6 A flowchart of a memory recycling method 600 provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the memory reclaiming method 600 includes the following steps 601-617.

[0181] Step 601, determine the N processes with the largest memory usage.

[0182] First, the terminal determines the memory occupied by all running processes, and based on the memory occupied by the processes, determines N processes with the largest memory usage.

[0183] Step 602, determining the performance stability coefficients of N processes.

[0184] The process of the terminal determining the performance stability coefficients of N processes is similar to the above steps 201-202. For details, please refer to the above steps 201-202, which will not be repeated here.

[0185] Step 603, selecting n processes with the smallest performance stability coefficients.

[0186] After determining the performance stability coefficients of the N processes, the terminal selects n processes with the smallest performance stability coefficients from the N processes.

[0187] Step 604, obtaining the total amount of inactive pages of n processes.

[0188] The terminal can scan the pages of n processes in memory through the kpreclaimed thread to obtain the total amount of inactive pages of n processes.

[0189] Step 605, calculate the page recovery amount of n processes.

[0190] The process of the terminal calculating the page recovery amounts of n processes is similar to the above steps S1-S3, and the details may refer to the above steps S1-S3, which will not be described again.

[0191] Step 606: reclaim the inactive pages of n processes.

[0192] After determining the page recovery amounts of the n processes, the terminal recycles the inactive file pages and inactive anonymous pages of the n processes respectively based on the page recovery amounts corresponding to the n processes.

[0193] Step 607, determine whether the number of recycling times of the process is less than 4 times.

[0194] After the terminal completes executing the inactive page recycling of the process, the terminal determines the number of page recycling times corresponding to the process, and determines whether the number of recycling times of the process is less than 4 times.

[0195] Step 608: If the number of recycling times of the process is less than 4 times, determine whether the performance loss of the process is serious.

[0196] The terminal may determine whether the performance loss of the process is serious by: determining whether the increase in the performance stability coefficient of the process is greater than or equal to a fifth threshold after executing page recovery. If the increase in the performance stability coefficient of the process is greater than or equal to the fifth threshold, it is determined that the performance loss of the process is serious; if the increase in the performance stability coefficient of the process is less than the fifth threshold, it is determined that the performance loss of the process is not serious.

[0197] Step 609: If the performance loss of the process is serious or the number of recycling times of the process is not less than 4 times, the process is protected for S cycles.

[0198] Among them, protecting the process for S cycles means that the pages of the process in the memory are no longer recycled within S cycles. The value of S can be 3 or 4, for example. In actual applications, the value of S can be adjusted according to the memory size of the terminal and the expected memory recycling rate. This embodiment does not specifically limit the value of S.

[0199] Step 610, determining whether the performance of the process is stable within the protection period.

[0200] During the period when the process is in the protection period, the terminal can continuously obtain the performance parameters of the process and calculate the performance stability coefficient of the process to determine whether the performance of the process is stable during the protection period. The method of determining whether the performance of the process is stable during the protection period is to determine whether the performance stability coefficient of the process becomes low during the protection period, and whether the performance stability coefficient of the process meets the first preset condition after the protection period ends.

[0201] If the performance stability coefficient of the process becomes lower during the protection period, and the performance stability coefficient of the process meets the first preset condition mentioned above after the protection period ends, it can be determined that the performance of the process is stable during the protection period; if the performance stability coefficient of the process does not become lower during the protection period, or the performance stability coefficient of the process does not meet the first preset condition mentioned above after the protection period ends, it can be determined that the performance of the process is unstable during the protection period.

[0202] Step 611: If the performance of the process is stable within the protection period, the recovery factor is increased to continue to recover the pages of the process.

[0203] If the performance of the process is stable within the protection period, the pages of the process in the memory can continue to be recycled. Since the process has already executed page recycling and entered the protection period due to severe performance degradation, the recycling factor of the process is increased, for example, the recycling factor of the process is increased to the maximum value to minimize the recycling of pages of the process.

[0204] Step 612: If the performance loss of the process is not serious, determine whether the performance stability coefficient of the process is still ranked in the top n.

[0205] If the number of recycling times of the process is less than 4 times and the performance loss of the process is not serious, it can be determined whether the performance stability coefficient of the process is still ranked in the top n, that is, whether the performance stability coefficient of the process is still one of the smallest n among N processes.

[0206] Step 613: If the performance stability coefficient of the process is still ranked in the top n, the recovery coefficient is increased to continue to recover the pages of the process.

[0207] If the performance stability coefficient of the process is still ranked in the top n, it means that the performance of the process is still more stable than the other Nn processes, and the pages of the process can continue to be recycled. Specifically, since the process has already executed page recycling, the recycling coefficient of the process is increased, for example, the recycling coefficient of the process is increased by 1, so as to reduce the pages of the process to be recycled as much as possible.

[0208] Step 614: If the performance stability coefficient of the process is no longer ranked in the top n, the process is protected for S cycles.

[0209] If the performance stability coefficient of the process is still ranked in the top n, it means that the performance of the process has deteriorated due to the recycling of pages, and there are already processes with more stable performance than the current process among the other Nn processes. Therefore, the terminal can protect the process for S cycles and no longer recycle the pages of the process.

[0210] Step 615, determining whether the performance of the process is stable within the protection period.

[0211] Among them, step 615 is similar to step 610, and the details can be referred to the above step 610, which will not be repeated here.

[0212] Step 616: If the performance of the process is stable within the protection period, the recovery coefficient is kept unchanged and the pages of the process are continuously recovered.

[0213] If the performance of the process is stable during the protection period, the pages of the process in memory can be further recycled. Since the process has already executed page recycling but has not entered the protection period due to severe performance degradation, the recycling coefficient of the process can be kept unchanged and the pages of the process can be further recycled.

[0214] Step 617: If the performance of the process is unstable during the protection period, the recovery factor is increased to continue to recover the pages of the process.

[0215] If the performance of a process is unstable during the protection period, the recovery factor of the process may be increased and the pages of the process may be further recovered. For example, the recovery factor of the process may be increased to a maximum value to minimize the number of pages of the process to be recovered.

[0216] In this embodiment, when reclaiming the pages of a process, the process whose pages need to be reclaimed is determined according to the stable performance state of the process when it is running, and the sensitivity of anonymous pages and file pages is sensed in a fine-grained manner to reclaim anonymous pages and file pages. Therefore, this embodiment can not only make the performance between processes more balanced, but also ensure the optimal memory utilization of a single process.

[0217] In addition, by sensing the performance changes of the process and adjusting the recovery strategy in time, it is ensured that the performance of the process will not drop significantly, serious performance loss of the process can be avoided, and the memory recovery method provided in this embodiment is suitable for scenarios where the process memory requirements vary.

[0218] To facilitate understanding, the memory recycling method provided in the embodiment of the present application will be introduced below with reference to specific examples.

[0219] In this embodiment, four processes PRO1, PRO2, PRO3, and PRO4 are simultaneously run on a server. The memory of the server is 24 Gigabytes (GB), and the memory occupied by processes PRO1, PRO2, PRO3, and PRO4 are 4GB, 3GB, 4GB, and 3GB, respectively. In addition, processes PRO1, PRO2, PRO3, and PRO4 are the top four processes in the system in terms of memory occupied, and are maintained by a K-heap tree. At this time, there are inactive pages in all four processes, and the system does not start memory recycling, resulting in the inactive pages of the processes not being recycled, which reduces the memory utilization rate.

[0220] First, the server sorts the processes according to their memory usage, and establishes a process K-heap tree based on processes whose memory usage is greater than a certain threshold. For example, this embodiment establishes a process K-heap tree based on processes whose memory usage is greater than 500 megabytes (MB).

[0221] The data of each node in the K-heap tree is used to maintain the performance parameters of the process, the inactive linked list of the file pages of the process, and the inactive linked list of the anonymous pages of the process. Among them, the performance parameters include the number of page faults of the process in the current cycle, the number of page faults in the previous cycle, the number of page swaps out, and the number of page swaps in. The inactive linked list of the file pages of the process maintains the inactive file pages to be recycled of the process; the inactive linked list of the anonymous pages of the process maintains the inactive anonymous pages to be recycled of the process. In this embodiment, the server establishes a K-heap tree based on the above-mentioned four processes PRO1, PRO2, PRO3, and PRO4.

[0222] In the process of executing memory recovery for the process in the K-heap tree, the monitoring module in the kpreclaimed kernel thread first monitors and records the performance index parameters of the process in the K-heap tree. The obtained performance parameter structure is as follows: Figure 7 shown. Figure 7 This is a schematic diagram of the performance parameter structure of four processes provided in the embodiment of the present application. Figure 7As shown in the figure, the Resident Set Size (RSS) indicates the memory usage of the process; PF indicates the number of page faults of the process in the current cycle; prev_PF indicates the number of page faults of the process in the previous cycle; SO indicates the number of page swaps out of the process; SI indicates the number of page swaps in of the process.

[0223] Depend on Figure 7 It can be seen that the number of page faults PF1, PF2, PF3, and PF4 in the current cycle of processes PRO1, PRO2, PRO3, and PRO4 are 10, 10, 20, and 20 respectively. The number of page faults in the previous cycle of processes PRO1, PRO2, PRO3, and PRO4 is are 5, 5, 15, and 30 respectively. The page swap-out times SO1, SO2, SO3, and SO4 of processes PRO1, PRO2, PRO3, and PRO4 are 10, 0, 5, and 5 respectively. The page swap-in times SI1, SI2, SI3, and SI4 of processes PRO1, PRO2, PRO3, and PRO4 are 10, 0, 10, and 0 respectively. In addition, the recovery coefficient k of the process in the K heap is set to the highest value (set to 4 in this embodiment). When the recovery coefficient is the largest, it means that the process performance state is unstable and the page recovery strength is low.

[0224] Based on the performance parameters of the processes obtained in the previous step, the performance stability coefficients of processes PRO1, PRO2, PRO3, and PRO4 are calculated based on the above formula 1. The calculation results are as follows: Figure 8 As shown, Figure 8 A schematic diagram of the performance stability coefficient of a process provided in an embodiment of the present application. Figure 8 As shown in Figure 2, the performance stability coefficients R1, R2, R3, and R4 of processes PRO1, PRO2, PRO3, and PRO4 are 1.1, 0.63, 0.87, and 1.23, respectively. The monitoring module in the kpreclaimed kernel thread is responsible for periodically updating the performance stability coefficient R of the process. i Then, the feedback module in the kpreclaimed kernel thread sorts the processes according to their performance stability coefficients, and selects the first n (n is set to 4 in this embodiment) processes as target processes for reclaiming pages.

[0225] If the process R i Greater than threshold 1 (in this embodiment, threshold 1 is set to 1.5) or the R iIf the growth rate is greater than threshold 2 (this embodiment sets threshold 2 to 1.5), the process enters the unstable state processing flow. After entering the unstable state processing flow, on the one hand, the number of inactive file pages and the number of inactive anonymous pages that the process should recycle are set to 0 to mark the protection of the process for several cycles (this embodiment sets the protection cycle to 3); on the other hand, the value of the recovery coefficient k is set to the maximum (the maximum value of k is set to 4 in this embodiment). If the R of the process i is less than or equal to the threshold 1 and the process's R i If the growth rate is less than or equal to the threshold 2, the process enters the steady state processing flow.

[0226] For a process that enters a stable state for the first time, the server uses the kpreclaimed process scanning module to scan the physical page table of the process, remove the inactive pages of the process from the inactive list of the system, add them to the inactive list of the process, and update the total amount of inactive anonymous pages INAC corresponding to the process. i and the total number of inactive file pages INFC i Then, the pages to be recycled for the four processes in this embodiment are calculated according to the above formulas 2 and 3, including the anonymous page recycling amount IAN i IAF and file page recovery i .

[0227] For the processes PRO1, PRO2, PRO3, and PRO4 provided in this embodiment, the server calculates the anonymous page recovery amount IAN of these four processes. i They are 0, 64MB, 2MB, and 17MB respectively; the file page recovery amount IAF of these four processes i They are 20MB, 20MB, 60MB, and 158MB respectively. Moreover, the recycling coefficient k of these four processes is the maximum value of 4. Then, the server uses the recycling module in the kpreclaimed kernel thread to recycle the inactive anonymous pages and inactive file pages in these four processes. Among them, during the interval between two scans of the scanning module in the kpreclaimed process, if the anonymous page or file page becomes active due to access, the recycling module in the kpreclaimed process puts the page back into the system inactive list and hands it over to the system memory management module for management, otherwise it remains in the process's inactive list waiting for recycling.

[0228] For the processes that were stable in the previous cycle and have recycled pages, the monitoring module collects the performance parameters of the processes after recycling pages. The feedback module calculates the performance stability coefficient of the process in the next recycling cycle to determine the performance changes of the process. If the performance of the process has not been greatly lost, the recycling intensity is increased, that is, the recycling coefficient k is reduced, and the anonymous page recycling amount IAN is updated. iIAF and file page recovery i . If the process performance loss is serious, it means that the process's page recycling is excessive, resulting in insufficient memory for the process and performance fluctuations. At this time, the k value can be increased to reduce the enthusiasm for page recycling. If the process performance continues to decline in the next cycle, the process is protected for several cycles, and page recycling is avoided as much as possible to avoid excessive performance loss of the page. After the protection cycle ends, the physical page table of the process is scanned by the scanning module in the kpreclaimed process, and the inactive linked list of the process is updated.

[0229] In the process of adjusting the process page recovery degree based on the process performance feedback, the feedback module mainly collects the performance parameters of a process after executing the recovery, and calculates the stable state R of the process in the current cycle. i If the process R i R is greater than the threshold 1 or the process i If the growth rate is greater than the threshold 2, the process enters the unstable state processing flow. After the process enters the unstable state processing flow, the number of pages to be recycled and the recycling coefficient k of the process are updated, and the process is protected for several cycles. i is less than or equal to the threshold 1 and the process's R i If the growth rate is less than or equal to the threshold 2, the recovery state is maintained, the recovery coefficient k is reduced, and the anonymous page recovery amount and file page recovery amount of the process are updated according to the above formulas 4 and 5. Then, the stable state of the process is calculated in the next cycle. If the performance stability coefficient of the process still meets the above requirements, the recovery coefficient k is reduced, and the anonymous pages and file pages of the process are continued to be recovered.

[0230] In order to prevent subsequent sudden excessive page recycling, the page recycling of the process will last for a maximum of S cycles in a stable state, and then the process will be protected for several cycles. After the protection cycle, the change in the performance stability coefficient of the process during the protection cycle is determined. If the performance of the process remains stable, the inactive memory pool of the process is rebuilt and the number of pages to be recycled of the process is updated, the recycling coefficient k is increased to the maximum value, and the page recycling process is entered. If the performance of the process fluctuates during the protection cycle, the protection cycle of the process is extended.

[0231] Illustratively, in this embodiment, in the initial recycling cycle, the memory recycling amount of the process is as shown in Table 1.

[0232] Table 1 Memory recovery amount of the process

[0233] <![CDATA[PRO1]]> <![CDATA[PRO2]]> <![CDATA[PRO3]]> <![CDATA[PRO4]]> Inactive anonymous page OMB 64MB 2MB 17MB Inactive file pages 20MB 20MB 60MB 158MB Total recycling amount 20MB 84MB 62MB 175MB

[0234] Table 1 shows the amount of physical memory that has been reclaimed by the four processes in the initial reclaim cycle. At the same time, it can be seen from Table 1 that the server differentially reclaims anonymous pages and file pages of different processes, which improves memory utilization while ensuring that the performance of the process is not greatly affected.

[0235] Based on the above memory recycling method, a preliminary simulation experiment was conducted in this embodiment, and the simulation results were analyzed. The analysis results are as follows.

[0236] First, the system settings of the simulation experiment are introduced.

[0237] In the simulation experiment, the page recovery situation of a zone in the memory is simulated. For this zone, the distribution of pages in the zone can be indicated by 4 linked lists, which are: active anonymous page list, active file page list, inactive anonymous page list and inactive file page list. The simulation experiment preliminarily implemented the LRU algorithm. There are two goals for this simulation experiment, which are verified in two different scenarios. One scenario is that when the system has sufficient free memory, compared with the original mechanism based on the global LRU algorithm to implement memory recovery, the memory recovery method provided in this embodiment can effectively recycle inactive pages in the system and will not seriously affect the system performance. Another scenario is that when the original system is short of free memory, the process-level memory recovery method provided by this embodiment can effectively alleviate the system from entering a state of memory tension.

[0238] In the simulation experiment, there are three processes in the system. These three processes have different memory access modes, namely uniform access mode, non-uniform access mode and periodic access mode.

[0239] The uniform access mode refers to simulating access to the file area and the anonymous area. The virtual page address accessed each time is completely randomly generated, and the access probability of the file area is greater than that of the anonymous area. In each cycle, the number of pages accessed by the process is randomly generated, and its value is between 4000-6000.

[0240] The non-uniform access mode refers to simulating access to the file area and the anonymous area. The virtual page addresses accessed each time are localized and concentrated within 30% of the above two areas. The virtual addresses within the area are completely randomly generated, and the access probability of the file area is greater than that of the anonymous area. In each time period, the number of pages accessed by the process is randomly generated, and its value is between 4000-6000.

[0241] The periodic access mode refers to simulating access to the file area and the anonymous area. The virtual page address accessed each time is periodic. The interval between two virtual addresses accessed is randomly generated. The interval can be set to 1-6. The access probability of the file area is greater than that of the anonymous area. In each time period, the number of pages accessed by the process is randomly generated, and its value is between 4000-6000.

[0242] Specifically, the simulation settings of the process in the simulation experiment can be found in Table 2.

[0243] Table 2

[0244] Process Name Access Mode Total visits Process area information Pid 0 Uniform access pattern 100 0,130000,130001,280000 Pid 1 Non-uniform access pattern 100 0,130000,130001,280000 Pid 2 Periodic access pattern 100 0,130000,130001,280000

[0245] The objectives of the simulation experiment are as follows.

[0246] (1) When the system has sufficient memory, process-level recycling can effectively recycle inactive memory in the system without affecting system performance.

[0247] (2) When the system memory is gradually insufficient, process-level recycling can effectively alleviate the system from entering a state of memory shortage.

[0248] The results of the simulation experiment are analyzed as follows.

[0249] Among them, the total memory capacity of the system is 777760MB.

[0250] 1. The goal of the simulation experiment is to measure the system performance by the total number of page faults in the system when the system memory is sufficient, and to prove that process-level memory recycling can effectively recycle inactive pages in the system without seriously affecting the system performance. For ease of description, the memory recycling method provided in this embodiment is referred to as a process-level recycling method.

[0251] See also Fig. 9 , Fig. 9 A schematic diagram showing the performance comparison of the system based on the LRU algorithm and the process-level recycling method for recycling memory provided in the embodiment of the present application. Fig. 9 In the system, the number of page visits each time reaches more than 10,000 times. Fig. 9 It can be seen that when evaluating system performance based on the total number of system page faults, compared with the original LRU algorithm method of reclaiming memory, although the process-level recycling method to recycle memory causes the total number of system page faults to increase in the later period, the increase is small, averaging about 300 pages.

[0252] See also Fig.10 , Fig.10A schematic diagram showing the comparison of used memory when reclaiming memory based on the LRU algorithm and the process-level reclaiming method provided in the embodiment of the present application. Fig.10 It can be seen that in the early stage, due to the low memory usage, the amount of inactive memory that can be reclaimed is small, and the recycling process is not obvious. Later, as the process runs, the inactive pages in the system gradually increase, and the amount of memory reclaimed by the process-level recycling method gradually increases compared to the LRU algorithm. It can be seen that although the memory recycling based on the process-level recycling method causes a slight decrease in system performance, it can effectively save memory.

[0253] Secondly, we evaluate the impact of memory recycling on the performance of each process under the LRU algorithm and process-level recycling method. The performance of the process is still measured by the number of page faults, and then we check the changes in the actual memory usage of each process.

[0254] See also Fig.11 , Fig.11 A schematic diagram of the operating performance of each process when reclaiming memory based on the LRU algorithm and process-level recycling method provided in an embodiment of the present application. Fig.11 (a) in the figure is a process that uses a uniform access pattern. Fig.11 (b) in the figure is a process that uses a non-uniform access pattern. Fig.11 (c) in the figure is a process that uses a periodic access pattern. Fig.11 It can be seen that reclaiming free memory does not significantly affect the performance of the process. In addition, memory reclamation has a greater impact on processes with uniform access patterns and the least impact on processes with periodic access patterns.

[0255] See also Fig.12 , Fig.12 A schematic diagram of the used memory of each process when reclaiming memory based on the LRU algorithm and the process-level recycling method provided in an embodiment of the present application. Fig.12 (a) in the figure is a process that uses a uniform access pattern. Fig.12 (b) in the figure is a process that uses a non-uniform access pattern. Fig.12 (c) in the figure is a process that uses a periodic access pattern. Fig.12 It can be seen that the amount of free memory reclaimed by different processes is different. From the perspective of the amount of reclaimed memory, the process using the periodic access mode reclaims relatively more memory, and the numerical difference reaches 400,000 pages.

[0256] 2. The goal of the simulation experiment is to measure the system performance by the total number of page faults in the system when the system memory is insufficient in the later stage, and to prove that the process-level recycling method can effectively alleviate the system from entering a state of memory shortage.

[0257] See also Fig.13 , Fig.13A schematic diagram showing the performance comparison of the system based on the LRU algorithm and the process-level recycling method for recycling memory provided in the embodiment of the present application. Fig.13 In the system, the number of page visits each time reaches more than 10,000 times. Fig. 9 It can be seen that when evaluating system performance based on the total number of system page faults, compared with the original LRU algorithm method of reclaiming memory, although the process-level recycling method to recycle memory causes the total number of system page faults to increase in the later period, the increase is small, averaging about 300 pages.

[0258] See also Fig.14 , Fig.14 A schematic diagram showing the comparison of used memory when reclaiming memory based on the LRU algorithm and the process-level reclaiming method provided in the embodiment of the present application. Fig.14 It can be seen that in the early stage, due to the low memory usage, the amount of inactive memory that can be reclaimed is small, and the recycling process is not obvious. Later, as the process runs, the inactive pages in the system gradually increase, and the amount of memory reclaimed by the process-level recycling method gradually increases compared to the LRU algorithm. It can be seen that although the memory recycling based on the process-level recycling method causes a slight decrease in system performance, it can effectively save memory.

[0259] Secondly, we evaluate the impact of memory recycling on the performance of each process under the LRU algorithm and process-level recycling method. The performance of the process is still measured by the number of page faults, and then we check the changes in the actual memory usage of each process.

[0260] See also Fig.15 , Fig.15 A schematic diagram of the operating performance of each process when reclaiming memory based on the LRU algorithm and process-level recycling method provided in an embodiment of the present application. Fig.15 (a) in the figure is a process with uniform access mode. Fig.15 (b) in the figure is a process that uses a non-uniform access pattern. Fig.15 (c) in the figure is a process that uses a periodic access pattern. Fig.15 It can be seen that the recycling method based on the LRU algorithm causes the performance of the three processes to decline, among which the process using the uniform access mode has the greatest impact, followed by the process using the non-uniform access mode.

[0261] See also Fig.16 , Fig.16 A schematic diagram of the used memory of each process when reclaiming memory based on the LRU algorithm and the process-level recycling method provided in an embodiment of the present application. Fig.16 (a) in the figure is a process that uses a uniform access pattern. Fig.16 (b) in the figure is a process that uses a non-uniform access pattern. Fig.16(c) in the figure is a process that uses a periodic access pattern. Fig.16 It can be seen that the amount of free memory reclaimed by different processes is different. From the perspective of the amount of reclaimed memory, the process using the periodic access mode reclaims relatively more memory, and the numerical difference reaches 400,000 pages.

[0262] exist Figures 1 to 16 On the basis of the corresponding embodiments, in order to better implement the above-mentioned solutions of the embodiments of the present application, related devices for implementing the above-mentioned solutions are also provided below.

[0263] For details, please refer to Fig.17 , Fig.17 A structural schematic diagram of a terminal 1700 provided for an embodiment of the present application, the terminal 1700 includes: an acquisition unit 1701 and a processing unit 1702. The acquisition unit 1701 is used to acquire performance parameters of a process in a first process set, the first process set includes N processes, N is an integer greater than 1, and the performance parameters include the number of page misses, the number of page swaps out and / or the number of page swaps in. The processing unit 1702 is used to calculate a performance stability coefficient of the process based on the performance parameters of the process, and the performance stability coefficient is used to represent the stable state of the performance of the process. The processing unit 1702 is also used to recycle the pages of the target process in the memory, and the target process is a process in the first process set whose performance stability coefficient meets a first preset condition.

[0264] In a possible implementation, the processing unit 1702 is also used to select n processes as target processes in the first process set in order of the performance stability coefficient from small to large, where n is an integer less than N, and the n processes are processes in the first process set whose performance stability coefficients meet the first preset condition.

[0265] In a possible implementation, the processing unit 1702 is also used to select a process whose performance stability coefficient is less than a first threshold from the first process set as a target process, and the process whose performance stability coefficient is less than the first threshold is a process in the first process set whose performance stability coefficient meets the first preset condition.

[0266] In a possible implementation, the acquisition unit 1701 is also used to obtain the memory usage of processes in a second process set, where the second process set includes M processes, where M is an integer greater than N; the processing unit 1702 is also used to select N processes from the second process set in descending order of the memory usage to obtain the first process set.

[0267] In a possible implementation, the processing unit 1702 is further used to calculate a first stability coefficient based on the number of page faults of the process in a first cycle and the number of page faults in a second cycle, wherein the second cycle is the previous cycle of the first cycle and the second cycle has the same cycle length as the first cycle; the processing unit 1702 is further used to calculate a second stability coefficient based on the number of anonymous pages swapped out and the number of anonymous pages swapped in of the process; the processing unit 1702 is further used to calculate a performance stability coefficient of the process based on the first stability coefficient and the second stability coefficient.

[0268] In a possible implementation, the processing unit 1702 is further configured to calculate a page recovery amount of the target process; the processing unit 1702 is further configured to recover pages of the target process in the memory according to the page recovery amount.

[0269] In a possible implementation, the acquisition unit 1701 is also used to acquire the total amount of inactive file pages and the total amount of inactive anonymous pages of the target process in the memory; the processing unit 1702 is also used to calculate the file page recovery amount of the target process based on the total amount of inactive file pages, the recovery coefficient, the number of page faults of the process in the first cycle, and the number of page faults in the second cycle; the processing unit 1702 is also used to calculate the anonymous page recovery amount of the target process based on the total amount of inactive anonymous pages, the recovery coefficient, the number of anonymous page swap-outs and the number of anonymous page swap-in of the process; the processing unit 1702 is also used to recycle the file pages and anonymous pages of the target process in the memory based on the file page recovery amount and the anonymous page recovery amount.

[0270] In one possible implementation, the processing unit 1702 is also used to recalculate the performance stability coefficient of the target process; the processing unit 1702 is also used to adjust the recovery coefficient to adjust the page recovery amount of the target process if the performance stability coefficient of the target process meets the second preset condition; the processing unit 1702 is also used to stop recovering the pages of the target process in the memory if the performance stability coefficient of the target process does not meet the second preset condition.

[0271] In one possible implementation, the second preset condition includes that the performance stability coefficient of the target process still satisfies the first preset condition, the performance stability coefficient of the target process is less than a second threshold, the growth rate of the performance stability coefficient of the target process is less than a third threshold and / or the number of recycles of the target process is less than a fourth threshold.

[0272] In one possible implementation, the processing unit 1702 is also used to reduce the recovery coefficient to increase the page recovery amount of the target process if the increase in the performance stability coefficient of the target process is less than a fifth threshold value; the processing unit 1702 is also used to increase the recovery coefficient to reduce the page recovery amount of the target process if the increase in the performance stability coefficient of the target process is greater than or equal to the fifth threshold value.

[0273] The memory recovery method provided in the embodiment of the present application can be specifically executed by a chip in the terminal, and the chip includes: a processing unit and a communication unit. The processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, a pin or a circuit. The processing unit can execute the computer execution instructions stored in the storage unit to enable the chip in the server to execute the above Figures 1 to 16 The memory recycling method described in the illustrated embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit can also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.

[0274] Reference Fig.18 The present application also provides a computer program product. In some embodiments, the above Figure 2 The disclosed methods may be implemented as computer program instructions encoded in a machine-readable format on a computer-readable storage medium or on other non-transitory media or articles of manufacture.

[0275] Fig.18 Schematically illustrates a conceptual partial view of an example computer program product, arranged in accordance with at least some embodiments presented herein, the example computer program product comprising a computer program for executing a computer process on a computing device.

[0276] In one embodiment, the computer program product 1800 is provided using a signal bearing medium 1801. The signal bearing medium 1801 may include one or more program instructions 1802, which when executed by one or more processors may provide the above-described Figure 2 Thus, for example, reference to Figure 2 In the embodiment shown in , one or more features of steps 201-203 may be undertaken by one or more instructions associated with the signal bearing medium 1801. In addition, Fig.18 Program instructions 1802 in also describe example instructions.

[0277] In some examples, the signal bearing medium 1801 may include a computer readable medium 1803 such as, but not limited to, a hard drive, a compact disk (CD), a digital video disk (DVD), a digital tape, a memory, a ROM or RAM, and the like.

[0278] In some embodiments, the signal bearing medium 1801 may include a computer recordable medium 1804, such as, but not limited to, a memory, a read / write (R / W) CD, a R / W DVD, etc. In some embodiments, the signal bearing medium 1801 may include a communication medium 1805, such as, but not limited to, a digital and / or analog communication medium (e.g., a fiber optic cable, a waveguide, a wired communication link, a wireless communication link, etc.). Thus, for example, the signal bearing medium 1801 may be communicated by a wireless form of the communication medium 1805 (e.g., a wireless communication medium that complies with the IEEE 802.11 standard or other transmission protocol).

[0279] The one or more program instructions 1802 may be, for example, computer executable instructions or logic implementation instructions. In some examples, the computing device of the computing device may be configured to provide various operations, functions, or actions in response to the program instructions 1802 communicated to the computing device via one or more of the computer readable medium 1803, the computer recordable medium 1804, and / or the communication medium 1805.

[0280] It should be understood that the arrangement described here is only for illustrative purposes. Thus, it will be appreciated by those skilled in the art that other arrangements and other elements (e.g., machines, interfaces, functions, sequences, and functional groups, etc.) can be used instead, and some elements can be omitted together according to the desired result. In addition, many of the described elements can be implemented as discrete or distributed components, or in any appropriate combination and position to combine other components to implement functional entities.

[0281] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0282] In the several embodiments provided in the present application, 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 only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0283] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0284] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0285] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.

Claims

1. A memory recovery method, characterized in that: include: Acquire performance parameters of processes in a first process set, where the first process set includes N processes, where N is an integer greater than 1, and the performance parameters include a number of page misses, a number of page swap-outs, and / or a number of page swap-ins; Calculating a performance stability coefficient of the process according to the performance parameters of the process, wherein the performance stability coefficient is used to represent a stable state of the performance of the process; Calculating the performance stability coefficient of the process according to the performance parameter of the process includes: Among them, R i represents the performance stability coefficient of process i, represents the first stability coefficient; Indicates the second stability factor; PF i Indicates the number of page faults of the process in the first cycle; PREV_PF i Indicates the number of page misses of the process in the second cycle; the second cycle is the previous cycle of the first cycle, and the second cycle has the same cycle length as the first cycle; SI i Indicates the number of anonymous page swaps; SO i represents the number of anonymous page swaps; a represents the first coefficient; b represents the second coefficient; Reclaim pages of a target process in the memory, where the target process is a process in the first process set whose performance stability coefficient meets a first preset condition.

2. The method according to claim 1, characterized in that The method further comprises: In order of the performance stability coefficient from small to large, n processes are selected from the first process set as target processes, where n is an integer less than N, and the n processes are processes in the first process set whose performance stability coefficients meet the first preset condition.

3. The method according to claim 1, characterized in that The method further comprises: A process whose performance stability coefficient is less than a first threshold is selected from the first process set as a target process, and the process whose performance stability coefficient is less than the first threshold is a process in the first process set whose performance stability coefficient meets the first preset condition.

4. The method according to any one of claims 1 to 3, characterized in that: Before obtaining the performance parameters of the processes in the first process set, the method further includes: Obtaining memory usage of processes in a second process set, where the second process set includes M processes, where M is an integer greater than N; Select N processes from the second process set in descending order of the memory usage to obtain the first process set.

5. The method according to any one of claims 1 to 3, characterized in that: The calculating the performance stability coefficient of the process according to the performance parameter of the process includes: Calculating a first stability coefficient according to the number of page misses of the process in a first cycle and the number of page misses in a second cycle, where the second cycle is a cycle previous to the first cycle and the second cycle has the same cycle length as the first cycle; Calculating a second stability coefficient according to the number of anonymous page swap-outs and the number of anonymous page swap-in of the process; A performance stability coefficient of the process is calculated based on the first stability coefficient and the second stability coefficient.

6. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Calculate the page reclaim amount of the target process; The reclaiming the pages of the target process in the memory includes: According to the page recovery amount, the pages of the target process in the memory are recovered.

7. The method according to claim 6, characterized in that The calculating of the page recovery amount of the target process includes: Obtain the total amount of inactive file pages and the total amount of inactive anonymous pages of the target process in the memory; Calculate the file page recovery amount of the target process according to the total amount of the inactive file pages, the recovery coefficient, the number of page faults of the process in the first cycle and the number of page faults in the second cycle; Calculate the anonymous page recovery amount of the target process according to the total amount of inactive anonymous pages, the recovery coefficient, the number of anonymous page swap-outs and the number of anonymous page swap-in of the process; Reclaiming pages of the target process in the memory according to the page reclaim amount includes: The file pages and anonymous pages of the target process in the memory are reclaimed according to the file page reclaim amount and the anonymous page reclaim amount.

8. The method according to any one of claims 1 to 3, characterized in that: After reclaiming the pages of the target process in the memory, the method further includes: Recalculating the performance stability coefficient of the target process; If the performance stability coefficient of the target process meets the second preset condition, adjusting the recovery coefficient to adjust the page recovery amount of the target process; If the performance stability coefficient of the target process does not meet the second preset condition, then the page recovery of the target process in the memory is stopped.

9. The method according to claim 8, characterized in that The second preset condition includes that the performance stability coefficient of the target process still satisfies the first preset condition, the performance stability coefficient of the target process is less than a second threshold, the growth rate of the performance stability coefficient of the target process is less than a third threshold and / or the number of recycles of the target process is less than a fourth threshold.

10. The method according to claim 8, characterized in that The adjustment recovery factor comprises: If the increase in the performance stability coefficient of the target process is less than a fifth threshold, reducing the recovery coefficient to increase the page recovery amount of the target process; If the increase in the performance stability coefficient of the target process is greater than or equal to the fifth threshold, the recovery coefficient is increased to reduce the page recovery amount of the target process.

11. A terminal, characterized in that: The terminal comprises a memory and a processor; the memory stores codes, the processor is configured to execute the codes, and when the codes are executed, the terminal executes the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, characterized in that: The method comprises computer-readable instructions, which, when executed on a computer, cause the computer to perform the method according to any one of claims 1 to 10.

13. A computer program product, characterized in that The method comprises computer-readable instructions, and when the computer-readable instructions are executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Linux kernel page table replacement-based method for tracking memory access model

    CN101604283A

  • Memory scheduling processing method and device

    CN111124678A