Memory recovery method and device, electronic equipment and storage medium
By calculating memory reclamation efficiency and system resource consumption, a memory reclamation pressure index is generated, which solves the problems of inaccurate virtual machine memory status judgment and untimely reclamation, and improves the operational stability of virtual machines.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-22
- Publication Date
- 2026-03-27
AI Technical Summary
In existing technologies, the determination of virtual machine memory status is inaccurate and memory reclamation is not timely, which affects the stability of virtual machine operation.
By determining memory reclamation efficiency, calculating the ratio of pages successfully reclaimed by the kernel to the number of pages scanned, generating memory reclamation pressure indicators, and combining this with the amount of available system resources, memory reclamation can be controlled, enabling accurate judgment of the virtual machine's memory status.
This improves the stability of virtual machine operation, avoids the problem of untimely memory reclamation, and ensures the reasonable allocation and effective utilization of system resources.
Smart Images

Figure CN121742971A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a memory reclamation method, apparatus, electronic device, and storage medium. Background Technology
[0002] Currently, in public cloud environments, cloud service providers use virtualization technology to abstract a large number of physical server resources into elastically schedulable virtual machine instances to support the operation of various critical businesses. During this process, when a virtual machine experiences insufficient memory due to process memory leaks or sudden surges in business traffic, the system reclaims some memory by shutting down the program process.
[0003] For the aforementioned virtual machine memory reclamation management scenarios, existing solutions suffer from inaccurate virtual machine memory status assessment and untimely memory reclamation, which affect the effectiveness of memory reclamation and consequently impact the operational stability of the virtual machine. Summary of the Invention
[0004] This disclosure provides a memory reclamation method to overcome the problems of inaccurate virtual machine memory status judgment and untimely memory reclamation.
[0005] In a first aspect, embodiments of this disclosure provide a memory reclamation method, including:
[0006] Determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel; based on the memory reclamation efficiency, determine memory reclamation pressure, which represents the execution load of the kernel in reclaiming memory; control memory reclamation based on the memory reclamation pressure and the amount of available system resources.
[0007] Secondly, embodiments of this disclosure provide a memory reclamation device, comprising:
[0008] The acquisition module is used to determine the memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0009] The judgment module is used to determine the memory reclamation pressure based on the memory reclamation efficiency, wherein the memory reclamation pressure represents the execution load of the kernel reclamation of memory;
[0010] The execution module is used to control memory reclamation based on the memory reclamation pressure and the amount of available system resources.
[0011] Thirdly, embodiments of this disclosure provide an electronic device, including: a processor and a memory;
[0012] The memory stores computer-executed instructions;
[0013] The processor executes computer execution instructions stored in the memory, causing the at least one processor to perform the memory reclamation method as described in the first aspect and various possible designs of the first aspect.
[0014] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the memory reclamation method described in the first aspect and various possible designs of the first aspect.
[0015] Fifthly, embodiments of this disclosure provide a computer program product, including a computer program that, when executed by a processor, implements the memory reclamation method described in the first aspect and various possible designs of the first aspect.
[0016] The memory reclamation method, apparatus, electronic device, and storage medium provided in this embodiment determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel; based on the memory reclamation efficiency, determine memory reclamation pressure, which represents the execution load of the kernel in reclaiming memory; and control memory reclamation based on the memory reclamation pressure and the amount of available system resources. By obtaining memory reclamation efficiency and the amount of available system resources to control memory reclamation, accurate judgment of the virtual machine memory status can be achieved, avoiding problems such as untimely memory reclamation and improving the operational stability of the virtual machine. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 This is an application scenario diagram of the memory reclamation method provided in the embodiments of this disclosure;
[0019] Figure 2 Flowchart of the memory reclamation method provided in the embodiments of this disclosure Figure 1 ;
[0020] Figure 3 A flowchart for performing memory reclamation is provided as an embodiment of this disclosure;
[0021] Figure 4 Flowchart of the memory reclamation method provided in the embodiments of this disclosure Figure 2 ;
[0022] Figure 5 for Figure 4 A flowchart illustrating the specific implementation of step S205 in the illustrated embodiment;
[0023] Figure 6 This is a schematic diagram illustrating another memory reclamation process provided in an embodiment of the present disclosure;
[0024] Figure 7 This is a structural block diagram of the memory reclamation device provided in the embodiments of this disclosure;
[0025] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure;
[0026] Figure 9 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0028] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0029] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0030] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.
[0031] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0032] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0033] The application scenarios of the embodiments of this disclosure are explained below:
[0034] The memory reclamation method provided in this disclosure can be applied to cloud service and cloud computing application scenarios. The executing entity in this embodiment can be a virtual machine, a server (physical machine) deploying the virtual machine, or other electronic devices that perform similar functions. The virtual machine executes the method provided in this embodiment by running the target application or target service in user mode. The target application or target server can run partially or entirely on the server. Based on the virtual machine's running state, the operating system's running state information is automatically detected, and memory reclamation is automatically triggered when the memory reclamation triggering conditions are met. Alternatively, a memory reclamation prompt message can be displayed on the virtual machine side, and memory reclamation operations can be performed in response to user commands.
[0035] In some embodiments, the virtual machine or server can implement the memory reclamation method provided in this disclosure by running various computer-executable instructions or computer programs. For example, computer-executable instructions can be program-level commands, machine instructions, or software instructions. Computer programs can be native programs or software modules in an operating system; they can be local applications, i.e., programs that need to be installed in the operating system to run; or they can be subroutines or applets embedded in any other application, such as programs running in a browser environment. In summary, the aforementioned computer-executable instructions can be any form of instruction, and the aforementioned computer programs can be any form of application, module, or plugin; the specific implementation can be configured as needed. Furthermore, in implementing the memory reclamation method provided in this disclosure, the server can execute the method by running computer-executable instructions or computer programs set locally, or by calling computer-executable instructions or computer programs set in an external server. In some embodiments, the server may be an independent physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud storage, cloud communication, cloud database, cloud computing, cloud functions, network services, middleware services, domain name services, security services, content delivery network (CDN), and big data and artificial intelligence platforms.
[0036] Figure 1 This is an application scenario diagram of the memory reclamation method provided in the embodiments of this disclosure, with reference to... Figure 1 As shown, taking a virtual machine as an example, a virtual machine operating system runs inside the virtual machine, and various user-mode applications run based on the operating system. On the other hand, the virtual machine's computing resources are allocated and scheduled by the controller within the server. When the virtual machine's memory usage becomes too high and memory is exhausted, the server will be triggered to execute a memory exception handling task to reclaim the virtual machine's memory, thereby preventing the virtual machine from stopping due to memory exhaustion.
[0037] In existing technologies, traditional solutions to the aforementioned virtual machine memory exhaustion problem rely on the system kernel's Out of Memory (OOM) mechanism for handling. However, this has significant limitations in public cloud scenarios: to avoid OOM triggering, a relatively aggressive memory reclamation strategy is usually adopted. However, when this strategy is combined with cloud disks, due to the order-of-magnitude difference in throughput between cloud disks and local disks, it is easy to fall into an infinite loop of "constant swapping in and out of memory pages and code segments" in memory-insufficient scenarios. This causes system resources to be completely consumed in the memory swapping process, ultimately leading to a system freeze. Afterwards, the service can only be restored by manual restart, which is time-consuming and has a significant impact on business operations. Therefore, there is an urgent need for a technology that can identify memory pressure in advance, accurately sense memory pressure, and automatically trigger the shutdown of abnormal processes to ensure that virtual machines do not freeze due to memory exhaustion, thereby meeting the requirements for stable virtual machine operation and rapid business recovery.
[0038] This disclosure provides a memory reclamation method to solve the above-mentioned problems.
[0039] refer to Figure 2 , Figure 2 Flowchart of the memory reclamation method provided in the embodiments of this disclosure Figure 1 The method of this embodiment can be applied to servers with virtual machines deployed. In one possible implementation where the server executes the method provided in this embodiment, the server can implement the memory reclamation method provided in this embodiment by executing program code deployed locally and / or externally. The server can also implement the memory reclamation method provided in this embodiment by calling functional services running on other electronic devices. For example, the memory reclamation method provided in this embodiment includes:
[0040] Step S101: Determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0041] Step S102: Determine the memory reclamation pressure based on the memory reclamation efficiency. The memory reclamation pressure represents the execution load of the kernel reclaiming memory.
[0042] Step S103: Control memory reclamation based on memory reclamation pressure and available system resources.
[0043] refer to Figure 1The illustrated application scenario diagram illustrates the memory reclamation method provided in this embodiment, which uses a server as the execution entity. For example, a target virtual machine is deployed within the server. By running a user-mode application within the target virtual machine, a memory reclamation service is initiated. This memory reclamation service can determine the memory reclamation efficiency by obtaining relevant information about the current operating system of the target virtual machine. The memory reclamation efficiency represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel, which is obtained by calculating the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0044] Regarding the specific implementation process of step S101, firstly, the memory statistics of the current target virtual machine are obtained. Virtual memory statistics are generated during memory reclamation and are data used to describe relevant records of the memory reclamation process. Specifically, virtual memory statistics are, for example, the ` / proc / vmstat` file in a Linux system. ` / proc / vmstat` is a pseudo-file in Linux that exposes the running status of virtual memory (VM), and its core function is to provide detailed real-time statistics related to virtual memory for monitoring or troubleshooting. By reading this file, the number of memory pages scanned by the kernel during memory reclamation (the number of pages scanned by the kernel) and the number of pages successfully reclaimed (the number of pages successfully reclaimed by the kernel) are parsed. These kernel-scanned and kernel-successfully reclaimed pages are related information generated during kernel memory reclamation and stored in the ` / proc / vmstat` file, which can be directly read. It is understood that virtual memory statistics can be implemented in other forms under other operating systems; examples will not be given here. Then, the memory reclamation efficiency is obtained based on the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0045] Next, based on the memory reclamation efficiency, the memory reclamation pressure is determined. Memory reclamation efficiency and memory reclamation pressure are inversely proportional; that is, the lower the memory reclamation efficiency, the greater the memory reclamation pressure. For example, by performing an inverse conversion on the memory reclamation efficiency (memory reclamation efficiency is inversely proportional to memory reclamation pressure), a percentage value is generated, which is the memory reclamation pressure. Specifically, the specific implementation of this memory reclamation pressure is shown in equation (1):
[0046] (1)
[0047] Here, VMpre represents memory reclamation pressure, reclaimed is the number of pages successfully reclaimed by the kernel, and scanned is the number of pages scanned by the kernel. The ratio of the number of pages successfully reclaimed to the number of pages scanned by the kernel (i.e., reclaimed / scanned) is the memory reclamation efficiency. The memory reclamation pressure obtained through this method accurately reflects the execution load of the kernel in reclaiming memory and the true level of memory stress in the system. This metric directly reflects the difficulty the kernel faces in reclaiming memory. When reclamation efficiency decreases, memory reclamation pressure increases, meaning increased memory reclamation pressure and execution load, indicating overall system memory stress. Using this as a criterion to trigger memory reclamation can improve the rationality of memory management in cloud computing scenarios. Based on the specific value of VMpre, it can be mapped to several pressure levels. For example, when VMpre is greater than or equal to 70%, it is a high pressure level; when VMpre is greater than or equal to 25% but less than 70%, it is a medium pressure level; and when VMpre is less than 25%, it is a low pressure level.
[0048] Next, by obtaining the amount of available system resources, memory reclamation is controlled based on the memory reclamation pressure and the amount of available system resources. The amount of available system resources represents the memory resources currently usable by the operating system. Based on the memory reclamation pressure, and further considering the currently available memory resources, the timing for triggering memory reclamation is determined. When the memory reclamation pressure and the amount of available system resources meet the memory reclamation triggering conditions, a memory reclamation task is triggered. These triggering conditions can be threshold ranges for both memory reclamation pressure and available system resources. When both the memory reclamation pressure and available system resources fall within the threshold ranges described by the memory reclamation triggering conditions, the memory reclamation triggering conditions are considered met.
[0049] The available system resources include available memory and page cache. Based on the memory reclamation pressure, this embodiment further combines the size of available memory and page cache to jointly determine when to execute a process kill operation. For example, when the memory reclamation pressure is greater than the memory pressure threshold, and the available memory is less than the available memory threshold, and the page cache is less than the page cache threshold, it is determined that memory reclamation is imminent, and memory reclamation is controlled. For example, in one possible implementation, when the available memory is less than 2% of the total memory (available_threshold), and the page cache is less than a safe threshold (e.g., 512MB), the memory reclamation service determines that memory is under pressure. Based on this, if the memory reclamation pressure is at a medium or high pressure level (or the memory reclamation pressure is greater than the memory pressure threshold), it determines that the status information meets the memory reclamation triggering conditions, and then obtains the target program process running in the operating system and closes the target program process to release its memory resources.
[0050] Furthermore, in one possible implementation, the memory pressure threshold includes a first pressure threshold, for example, 70%; and at least one of a second pressure threshold and a third pressure threshold. The second pressure threshold is, for example, 35%, and the third pressure threshold is, for example, 8%. When the memory reclamation pressure falls within the range defined by the above pressure thresholds, it represents the corresponding pressure level. For example, when the memory reclamation pressure is greater than or equal to the first pressure threshold, it is a high pressure level; when the memory reclamation pressure is less than the first pressure threshold but greater than or equal to the second pressure threshold, it is a medium pressure level; when the memory reclamation pressure is less than the second pressure threshold but greater than or equal to the third pressure threshold, it is a low pressure level; and when the memory reclamation pressure is less than the third pressure threshold, it is a no-pressure level. Based on this, one possible memory reclamation triggering condition is that the memory reclamation pressure is greater than the second pressure threshold and less than the first pressure threshold, and the available memory is less than the available memory threshold, and the page cache is less than the page cache threshold; while another memory reclamation triggering condition is that the memory reclamation pressure is greater than the first pressure threshold, and the available memory is less than the available memory threshold, and the page cache is greater than the page cache threshold.
[0051] Figure 3 This disclosure provides a flowchart for performing memory reclamation, which is described below in conjunction with... Figure 3 The process of the above embodiments will be further described, such as... Figure 3As shown, firstly, the system obtains the operating system's running status information, including memory reclamation pressure Info_1 (shown as Info_1 in the figure), available memory Info_2 (shown as Info_2 in the figure), and page cache Info_3 (shown as Info_3 in the figure). First, the memory reclamation pressure Info_1 is assessed. If the memory reclamation pressure Info_1 is less than the second pressure threshold (i.e., the memory pressure is below the medium pressure level), no action is taken, and new running status information is obtained again after a preset time. If the memory reclamation pressure Info_1 is greater than or equal to the second pressure threshold (i.e., the memory pressure is above the medium pressure level), then the system continues to obtain available memory Info_2 and compares it with the available memory threshold ava_threshold (shown as ava_threshold in the figure). If available memory Info_2 is greater than the available memory threshold ava_threshold, no action is taken, and new status information is obtained again after a preset time. If available memory Info_2 is less than or equal to the available memory threshold ava_threshold, then the system continues to obtain page cache Info_3 and compares it with... The relationship between the page cache threshold cac_threshold (shown as cac_threshold in the diagram) is as follows: if the page cache Info_3 is less than the page cache threshold cac_threshold, then the memory reclamation trigger condition is met, and memory reclamation is performed; if the page cache Info_3 is greater than or equal to the page cache threshold cac_threshold, then it is further determined whether the memory reclamation pressure Info_1 is greater than or equal to the first pressure threshold. If the memory reclamation pressure Info_1 is greater than or equal to the first pressure threshold, then the memory reclamation trigger condition is met, and memory reclamation is performed; otherwise, no action is taken, and new status information is obtained again after a preset time.
[0052] In this embodiment, memory reclamation efficiency is determined, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel. Based on the memory reclamation efficiency, memory reclamation pressure is determined, which represents the execution load of the kernel in reclaiming memory. Memory reclamation is controlled based on the memory reclamation pressure and the amount of available system resources. By obtaining memory reclamation efficiency and the amount of available system resources to control memory reclamation, accurate judgment of the virtual machine's memory status can be achieved, avoiding problems such as untimely memory reclamation and improving the operational stability of the virtual machine.
[0053] refer to Figure 4 , Figure 4 Flowchart of the memory reclamation method provided in the embodiments of this disclosure Figure 2 This embodiment is in Figure 2 Based on the illustrated embodiment, step S103 is further refined, and the memory reclamation method includes:
[0054] Step S201: Determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0055] Step S202: Determine the memory reclamation pressure based on the memory reclamation efficiency. The memory reclamation pressure represents the execution load of the kernel reclaiming memory.
[0056] Step S203: Obtain the dynamic baseline corresponding to the processor utilization rate. The dynamic baseline is used to characterize the benchmark value of the processor utilization rate at different times.
[0057] Step S204: In response to the memory reclamation pressure being greater than the memory pressure threshold, the available memory being less than the available memory threshold, the page cache being less than the page cache threshold, and the processor utilization exceeding the dynamic baseline target multiple, the memory reclamation triggering conditions are determined to be met.
[0058] Step S205: If the memory reclamation triggering conditions are met, identify the target program process and close the target program process to release the memory resources of the target program process.
[0059] For example, in this embodiment, the memory reclamation service running within the virtual machine periodically obtains the operating system's running status information, including the number of pages successfully reclaimed by the kernel, the number of pages scanned by the kernel, available memory, page cache, and processor utilization. The memory reclamation pressure can be determined based on the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel. Memory reclamation pressure can be represented by a specific value or identifier. Available memory and page cache represent the amount of available system resources. The specific methods for obtaining and implementing the aforementioned memory reclamation pressure, available memory, and page cache have been described in detail in previous embodiments and will not be repeated here. Furthermore, in this embodiment, in addition to obtaining the above running status information, the virtual machine's processor utilization, i.e., the Central Processing Unit (CPU) utilization, is additionally obtained. By combining the processor utilization with the determination of memory reclamation trigger conditions, accuracy is further improved, avoiding triggering memory reclamation in certain input / output (I / O) intensive but memory pressure-controlled scenarios, which could lead to process false kills.
[0060] Furthermore, this embodiment introduces Exponentially Weighted Moving Average (EWMA) optimization of the CPU metric, with the specific steps as follows:
[0061] First, a dynamic baseline corresponding to the processor utilization rate is obtained. The dynamic baseline represents the benchmark value of the processor utilization rate at different times. The benchmark value is the utilization rate when the processor is in a normal state with low power consumption and low pressure. This benchmark value changes over time. For example, during the early morning hours, the CPU utilization rate of the target virtual machine decreases due to reduced workload, resulting in a lower benchmark value of processor utilization, such as 10%. During the daytime hours, the CPU utilization rate increases due to increased workload, resulting in a higher benchmark value of processor utilization, such as 30%. Based on these benchmark values, a curve describing the processor utilization rate throughout the day is formed; this is the dynamic baseline.
[0062] Furthermore, in one possible implementation, the processor utilization rate includes a first utilization rate and a second utilization rate. The first utilization rate represents the proportion of time the processor spends executing kernel-mode code, and the second utilization rate represents the proportion of time the processor spends waiting for input / output (I / O) operations to complete. The memory pressure threshold includes a first pressure threshold and a third pressure threshold. The memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the third pressure threshold.
[0063] Optionally, before step S203, the method further includes:
[0064] Step S2001: When the memory reclamation pressure is less than the third pressure threshold, collect the first occupancy rate and the second occupancy rate for a preset time, and construct the first baseline data corresponding to the first occupancy rate and the second baseline data corresponding to the second occupancy rate.
[0065] Step S2002: Based on the first and second benchmark data, use the dynamic smoothing index algorithm to generate dynamic baselines corresponding to the first and second occupancy rates respectively.
[0066] For example, when the memory reclamation pressure is less than the third pressure threshold, the memory pressure is at a stress-free level, meaning the virtual machine memory is in a "normal" state. At this time, the memory reclamation service calculates the processor's system% and iowait% by sampling the / proc / stat file in parallel. The first utilization rate represents the percentage of time the processor spends executing kernel-mode code, while the second utilization rate represents the percentage of time the processor spends waiting for I / O operations to complete. More specifically, system% refers to the percentage of time the CPU spends executing kernel-mode code, including kernel operations such as system calls, memory management, device drivers, and process scheduling. A high system% value usually indicates high kernel processing overhead, which may be due to driver anomalies or improper system configuration. iowait% refers to the percentage of time the CPU is idle but needs to wait for I / O (disk, network, peripherals, etc.) operations to complete. A high iowait% value does not necessarily mean the CPU is busy; rather, it indicates an I / O performance bottleneck causing CPU waiting, commonly seen in scenarios such as slow disk read / write operations or network congestion.
[0067] Subsequently, by continuously and periodically collecting the aforementioned first and second occupancy rates, corresponding first and second baseline data can be generated. Then, the dynamic baselines of these two indicators are constructed and maintained using the Exponentially Weighted Moving-Average (EWMA) algorithm, where the formula for the EWMA algorithm is shown in equation (2):
[0068] (2)
[0069] Among them, ewma new For the current point of the curve, ewma prev A point before the curve, This is a smoothing factor, with an empirical value (e.g., 0.2). Using the dynamic smoothing index algorithm described above, the dynamic baselines corresponding to the first and second occupancy rates can be obtained, namely the system% curve and the iowait% curve.
[0070] In this embodiment, dynamic baselines corresponding to the first and second utilization rates are constructed in the above manner. Then, based on the processor utilization rate exceeding the target multiple of the dynamic baseline, it is determined whether there is a system abnormality (for example, if it exceeds 2 times, it is determined that the system is abnormal), and then the process is closed. This can reduce the probability of accidental process closure and improve system stability.
[0071] Furthermore, the specific implementation method for determining the target program process in step S205 includes:
[0072] Step S205A: Obtain the termination priority score of the program process in the operating system.
[0073] Step S205B: Determine the target program process based on the termination priority score.
[0074] For example, when the memory reclamation trigger conditions are met and process shutdown begins, the memory reclamation service obtains the termination priority score corresponding to each program process and identifies one or more processes with the highest termination priority scores as target program processes. The termination priority score, such as the OOM score in Linux systems, refers to the process with the highest kernel OOM score, which is the process that the kernel determines should be terminated with the highest priority when the system experiences an OutOfMemoryError (OOM). The higher the termination priority score, the greater the probability that the program process will be selected and terminated by the OOM killer, with the aim of quickly releasing memory and preventing overall system crashes. The termination priority score is mainly affected by factors such as process memory usage, runtime, and whether it is a critical system process. Higher memory usage and non-core business processes tend to have higher scores. The specific method for generating this termination priority score is related to the operating system's memory reclamation mechanism, which will not be elaborated here. Then, the program process with the highest termination priority score is identified as the target program process.
[0075] Furthermore, in one possible implementation, step S205A is specifically implemented as follows:
[0076] Step S205A-1: Obtain the preset first program process list;
[0077] Step S205A-2: Obtain the termination priority score corresponding to each program process in the first program process list, and determine the target program process based on the termination priority score.
[0078] For example, in this embodiment, the memory reclamation service first obtains a first program process list preset by the virtual machine. This first program process list contains several preset program processes that can be shut down. Then, it obtains the termination priority score corresponding to each program process in the first program process list, and determines one or more of the processes with the highest termination priority scores as target program processes. Through the above steps, the pre-configuration of program processes that can be shut down is achieved, thereby avoiding the shutdown of critical program processes and improving system stability.
[0079] In another possible implementation, before step S205A, the method further includes: periodically traversing the pseudo file system through an independent thread to cache the N candidate program processes with the highest termination priority scores.
[0080] Accordingly, the specific implementation of step S205 includes:
[0081] S205C: Obtain the target program process from at least one alternative program process.
[0082] For example, in one possible implementation, to improve the speed of identifying and closing the target program process, the memory reclamation service pre-confirms and caches the target program process before determining it. Specifically, the memory reclamation service uses a separate thread to periodically traverse the pseudo-file system, such as traversing the / proc directory, to find the N candidate program processes with the highest termination priority scores. For example, the top three program processes with the highest termination priority scores are identified as candidate program processes. Then, before the memory reclamation trigger condition is met and the target program process needs to be identified and closed, the target program process is identified and closed from at least one of the above candidate program processes. Specifically, when there is only one candidate program process, it is directly closed as the target program process; when there are multiple candidate program processes, the one with the highest memory consumption or the one with the highest termination priority score can be closed, which can be configured as needed. Through the above embodiment steps, the most time-consuming step of traversing the pseudo-file system is assigned to a separate thread for pre-execution, so that after the memory reclamation trigger condition is met, the target program process that needs to be closed can be quickly identified, thereby achieving rapid closure of the target program process and memory release, improving the real-time performance of memory release.
[0083] Furthermore, by combining the two implementation methods above, in a more specific implementation method, such as... Figure 5 As shown, the specific implementation of step S205 includes:
[0084] Step S2051: Periodically traverse the pseudo file system using an independent thread to cache the N candidate program processes with the highest termination priority scores.
[0085] Step S2052: Obtain candidate program processes from the preset first program process list;
[0086] Step S2053: Update the termination priority score of the candidate process in the first process process list;
[0087] Step S2054: Sort the candidate program processes in the first program process list according to the updated termination priority score to obtain the target program process.
[0088] For example, in this embodiment, firstly, the pseudo-file system is periodically traversed by an independent thread to cache the N candidate program processes with the highest termination priority scores. For instance, the 10 program processes with the highest termination priority scores are cached to generate 10 cached candidate program processes. Next, a preset first program process list is obtained, which records non-critical program processes that are allowed to be closed. Then, by comparing the non-critical program processes in the first program process list with the cached candidate program processes, program processes that simultaneously satisfy both criteria are obtained; these are the candidate program processes located in the preset first program process list. Subsequently, the termination priority scores of the candidate process in the first process list are updated. Since obtaining the termination priority scores of all process in the pseudo file system and then obtaining the candidate process is time-consuming, even if a separate processing thread is used for periodic acquisition, there will still be a certain delay, resulting in poor real-time performance of the termination priority scores. In this embodiment, after obtaining the candidate process in the first process list, the termination priority scores of the candidate process in the first process list are sorted again to obtain one or more candidate process with the highest termination priority scores, and these are identified as target process. This improves the real-time performance and accuracy of the priority score sorting, and enables the identified and closed target process to maximize the memory reclamation effect.
[0089] Finally, after identifying the target program process, the target program process is closed to release memory resources.
[0090] Figure 6 This is a schematic diagram of another memory reclamation process provided in an embodiment of this disclosure, which is described below in conjunction with... Figure 6 The process of the above embodiments will be further described, such as... Figure 6As shown, exemplarily, firstly, the operating system's status information is obtained, including memory reclamation pressure Info_1, available memory Info_2, page cache Info_3, and processor utilization Info_4. First, the memory reclamation pressure Info_1 is assessed. If the memory reclamation pressure Info_1 is less than a third pressure threshold, meaning the memory pressure is at a stress-free level, then a dynamic baseline corresponding to the processor utilization is generated or updated based on the current processor utilization Info_4. If the memory reclamation pressure Info_1 is less than a second pressure threshold but greater than or equal to the third pressure threshold, meaning the memory pressure is at a low pressure level, no action is taken, and new status information is obtained again after a preset time. If the memory reclamation pressure Info_1 is greater than or equal to the second pressure threshold, i.e., the memory pressure is at or above the medium pressure level, then continue to obtain the available memory Info_2 and compare whether the available memory Info_2 is less than the available memory threshold ava_threshold. If the available memory Info_2 is greater than the available memory threshold ava_threshold, no action is taken, and new status information is obtained again after a preset time. If the available memory Info_2 is less than or equal to the available memory threshold ava_threshold, then continue to obtain the page cache Info_3 and determine the relationship between the page cache Info_3 and the page cache threshold cac_threshold. If the page cache Info_3 is less than the page cache threshold cac_threshold, then further compare the relationship between the processor utilization Info_4 and the dynamic baseline. If the processor utilization Info_4 is greater than the target multiple of the baseline value at the current moment in the dynamic baseline (shown in the figure as Info_4>n×base), where n is the multiple and base is the baseline value at the current moment. For example, if the value is greater than twice the baseline value in the dynamic baseline at the current moment, the memory reclamation trigger condition is met, and memory reclamation is performed; otherwise, no action is taken, and new status information is obtained again after a preset time. If the page cache Info_3 is greater than or equal to the page cache threshold cac_threshold, the memory reclamation pressure Info_1 is further checked to see if it is greater than or equal to the first pressure threshold. If the memory reclamation pressure Info_1 is greater than or equal to the first pressure threshold, the relationship between the processor utilization rate Info_4 and the dynamic baseline is further compared. If the processor utilization rate Info_4 is greater than the target multiple of the baseline value in the dynamic baseline at the current moment, for example, greater than twice the baseline value in the dynamic baseline at the current moment, the memory reclamation trigger condition is met, and memory reclamation is performed; otherwise, no action is taken, and new status information is obtained again after a preset time. On the other hand, if the page cache Info_3 is less than the page cache threshold cac_threshold, no action is taken, and new status information is obtained again after a preset time.
[0091] In this embodiment, the implementation of step S204 is the same as that in this disclosure. Figure 2 The implementation of step S103 in the illustrated embodiment is the same, and will not be described in detail here.
[0092] Corresponding to the memory reclamation method in the above embodiments, Figure 7 This is a structural block diagram of a memory reclamation device provided in an embodiment of this disclosure. The method described in the above embodiments can be executed by this memory reclamation device, which can be implemented by software and / or hardware, and can be integrated into an electronic device with certain data processing capabilities. The electronic device may include, but is not limited to, mobile terminals with big data processing capabilities, as well as fixed terminals with big data processing capabilities such as desktop computers and supercomputers.
[0093] For ease of explanation, only the parts relevant to embodiments of this disclosure are shown. (Refer to...) Figure 7 The memory reclamation device 3 includes:
[0094] The acquisition module 31 is used to determine the memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0095] The judgment module 32 is used to determine the memory reclamation pressure based on the memory reclamation efficiency. The memory reclamation pressure represents the execution load of the kernel reclamation of memory.
[0096] Execution module 33 is used to control memory reclamation based on memory reclamation pressure and the amount of available system resources.
[0097] According to one or more embodiments of this disclosure, the available resources of the system include available memory and page cache. Execution module 33 is specifically used to: control memory reclamation in response to memory reclamation pressure being greater than a memory pressure threshold, and available memory being less than an available memory threshold, and page cache being less than a page cache threshold.
[0098] According to one or more embodiments of this disclosure, the execution module 33 is further configured to: obtain a dynamic baseline corresponding to the processor utilization rate, wherein the dynamic baseline is used to characterize the benchmark value of the processor utilization rate at different times; when the execution module 33 controls memory reclamation in response to memory reclamation pressure being greater than the memory pressure threshold, and available memory being less than the available memory threshold, and page cache being less than the page cache threshold, the specific configuration is to: control memory reclamation in response to memory reclamation pressure being greater than the memory pressure threshold, and available memory being less than the available memory threshold, and page cache being less than the page cache threshold, and processor utilization rate exceeding the target multiple of the dynamic baseline.
[0099] According to one or more embodiments of this disclosure, the processor utilization rate includes a first utilization rate and a second utilization rate. The first utilization rate represents the proportion of time the processor spends executing kernel-mode code, and the second utilization rate represents the proportion of time the processor spends waiting for input / output operations to complete. The memory pressure threshold includes a first pressure threshold and a third pressure threshold. The memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the third pressure threshold. The execution module 33 is further configured to: when the memory reclamation pressure is less than the third pressure threshold, collect the first utilization rate and the second utilization rate for a preset duration, and construct first benchmark data corresponding to the first utilization rate and second benchmark data corresponding to the second utilization rate; based on the first benchmark data and the second benchmark data, use a dynamic smoothing index algorithm to generate dynamic baselines corresponding to the first utilization rate and the second utilization rate, respectively.
[0100] According to one or more embodiments of this disclosure, the memory pressure threshold includes a first pressure threshold and a second pressure threshold, wherein the memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the second pressure threshold; when the execution module 33 controls memory reclamation in response to the memory reclamation pressure being greater than the memory pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold, it is specifically used to: control memory reclamation in response to the memory reclamation pressure being greater than the second pressure threshold and less than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold; or, control memory reclamation in response to the memory reclamation pressure being greater than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being greater than the page cache threshold.
[0101] According to one or more embodiments of this disclosure, when controlling memory reclamation, the execution module 33 is specifically used to: obtain the termination priority score of the program process in the operating system; determine the target program process according to the termination priority score, and close the target program process to release the memory resources of the target program process.
[0102] According to one or more embodiments of this disclosure, before obtaining the termination priority score of the program process in the operating system, the execution module 33 is further configured to: periodically traverse the pseudo file system through an independent thread to cache the N candidate program processes with the highest termination priority scores; when obtaining the termination priority score of the program process in the operating system, the execution module 33 is specifically configured to: obtain the target program process from the N candidate program processes.
[0103] The acquisition module 31, the judgment module 32, and the execution module 33 are connected sequentially. The memory reclamation device 3 provided in this embodiment can execute the technical solution of the above method embodiment, and its implementation principle and technical effect are similar, so it will not be described again here.
[0104] Figure 8This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure, such as... Figure 8 As shown, the electronic device 4 includes:
[0105] Processor 41, and memory 42 communicatively connected to processor 41;
[0106] Memory 42 stores instructions executed by the computer;
[0107] The processor 41 executes computer execution instructions stored in the memory 42 to achieve, for example, Figures 2-6 The memory reclamation method in the illustrated embodiment.
[0108] Optionally, the processor 41 and the memory 42 are connected via a bus 43.
[0109] For relevant instructions, please refer to the corresponding text. Figures 2-6 The relevant descriptions and effects of the steps in the corresponding embodiments are understood, and will not be elaborated on here.
[0110] This disclosure provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement this disclosure. Figures 2-6 The memory reclamation method provided in any of the corresponding embodiments.
[0111] This disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements this disclosure. Figures 2-6 The memory reclamation method provided in any of the corresponding embodiments.
[0112] To implement the above embodiments, this disclosure also provides an electronic device.
[0113] refer to Figure 9 The diagram illustrates a structural schematic of an electronic device 900 suitable for implementing embodiments of the present disclosure. The electronic device 900 can be a terminal device or a server. The terminal device can include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, personal digital assistants (PDAs), tablet computers, portable media players (PMPs), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 9 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0114] like Figure 9 As shown, the electronic device 900 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 into a random access memory (RAM) 903. The RAM 903 also stores various programs and data required for the operation of the electronic device 900. The processing unit 901, ROM 902, and RAM 903 are interconnected via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0115] Typically, the following devices can be connected to I / O interface 905: input devices 906 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 907 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 908 including, for example, magnetic tapes, hard disks, etc.; and communication devices 909. Communication device 909 allows electronic device 900 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 9 An electronic device 900 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0116] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 909, or installed from a storage device 908, or installed from a ROM 902. When the computer program is executed by a processing device 901, it performs the functions defined in the methods of embodiments of this disclosure.
[0117] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0118] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0119] The aforementioned computer-readable medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the methods shown in the above embodiments.
[0120] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0121] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0122] The units or modules described in the embodiments of this disclosure can be implemented in software or hardware. The names of the units or modules do not necessarily limit the specific unit itself.
[0123] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.
[0124] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0125] In a first aspect, according to one or more embodiments of this disclosure, a memory reclamation method is provided, comprising:
[0126] Determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel; based on memory reclamation efficiency, determine memory reclamation pressure, which represents the execution load of the kernel in reclaiming memory; based on memory reclamation pressure and the amount of available system resources, control memory reclamation.
[0127] According to one or more embodiments of this disclosure, the available resources of the system include available memory and page cache. Memory reclamation is controlled based on memory reclamation pressure and the available resources of the system, including: controlling memory reclamation in response to memory reclamation pressure being greater than a memory pressure threshold, available memory being less than an available memory threshold, and page cache being less than a page cache threshold.
[0128] According to one or more embodiments of this disclosure, the method further includes: obtaining a dynamic baseline corresponding to the processor utilization rate, the dynamic baseline being used to characterize a benchmark value of the processor utilization rate at different times; and controlling memory reclamation in response to memory reclamation pressure being greater than a memory pressure threshold, and available memory being less than an available memory threshold, and page cache being less than a page cache threshold, including: controlling memory reclamation in response to memory reclamation pressure being greater than a memory pressure threshold, and available memory being less than an available memory threshold, and page cache being less than a page cache threshold, and processor utilization rate exceeding a target multiple of the dynamic baseline.
[0129] According to one or more embodiments of this disclosure, the processor utilization rate includes a first utilization rate and a second utilization rate. The first utilization rate represents the proportion of time the processor spends executing kernel-mode code, and the second utilization rate represents the proportion of time the processor spends waiting for input / output operations to complete. The memory pressure threshold includes a first pressure threshold and a third pressure threshold, wherein the memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the third pressure threshold. The method further includes: when the memory reclamation pressure is less than the third pressure threshold, collecting the first utilization rate and the second utilization rate for a preset duration, and constructing first baseline data corresponding to the first utilization rate and second baseline data corresponding to the second utilization rate; based on the first baseline data and the second baseline data, using a dynamic smoothing index algorithm, generating dynamic baselines corresponding to the first utilization rate and the second utilization rate, respectively.
[0130] According to one or more embodiments of this disclosure, the memory pressure threshold includes a first pressure threshold and a second pressure threshold, wherein the memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the second pressure threshold; in response to the memory reclamation pressure being greater than the memory pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold, memory reclamation is controlled, including: in response to the memory reclamation pressure being greater than the second pressure threshold and less than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold, memory reclamation is controlled; or, in response to the memory reclamation pressure being greater than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being greater than the page cache threshold, memory reclamation is controlled.
[0131] According to one or more embodiments of this disclosure, controlling memory reclamation includes: obtaining a termination priority score of a program process in an operating system; determining a target program process based on the termination priority score; and closing the target program process to release the memory resources of the target program process.
[0132] According to one or more embodiments of this disclosure, before obtaining the termination priority score of a program process in the operating system, the method further includes: periodically traversing the pseudo file system through an independent thread to cache N candidate program processes with the highest termination priority scores; obtaining the termination priority score of a program process in the operating system includes: obtaining the target program process from the N candidate program processes.
[0133] Secondly, according to one or more embodiments of this disclosure, a memory reclamation apparatus is provided, comprising:
[0134] The acquisition module is used to determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel.
[0135] The judgment module is used to determine the memory reclamation pressure based on the memory reclamation efficiency. The memory reclamation pressure represents the execution load of the kernel in reclaiming memory.
[0136] The execution module is used to control memory reclamation based on memory reclamation pressure and the amount of available system resources.
[0137] According to one or more embodiments of this disclosure, the available resources of the system include available memory and page cache. The execution module is specifically used to: control memory reclamation in response to memory reclamation pressure being greater than a memory pressure threshold, and available memory being less than an available memory threshold, and page cache being less than a page cache threshold.
[0138] According to one or more embodiments of this disclosure, the execution module is further configured to: obtain a dynamic baseline corresponding to the processor utilization rate, the dynamic baseline being used to characterize the benchmark value of the processor utilization rate at different times; when the execution module controls memory reclamation in response to memory reclamation pressure being greater than the memory pressure threshold, and available memory being less than the available memory threshold, and page cache being less than the page cache threshold, specifically configured to: control memory reclamation in response to memory reclamation pressure being greater than the memory pressure threshold, and available memory being less than the available memory threshold, and page cache being less than the page cache threshold, and processor utilization rate exceeding the target multiple of the dynamic baseline.
[0139] According to one or more embodiments of this disclosure, the processor utilization rate includes a first utilization rate and a second utilization rate. The first utilization rate represents the proportion of time the processor spends executing kernel-mode code, and the second utilization rate represents the proportion of time the processor spends waiting for input / output operations to complete. The memory pressure threshold includes a first pressure threshold and a third pressure threshold. The memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the third pressure threshold. The execution module is further configured to: when the memory reclamation pressure is less than the third pressure threshold, collect the first utilization rate and the second utilization rate for a preset duration, and construct first benchmark data corresponding to the first utilization rate and second benchmark data corresponding to the second utilization rate; based on the first benchmark data and the second benchmark data, generate dynamic baselines corresponding to the first utilization rate and the second utilization rate respectively using a dynamic smoothing index algorithm.
[0140] According to one or more embodiments of this disclosure, the memory pressure threshold includes a first pressure threshold and a second pressure threshold, wherein the memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the second pressure threshold; when the execution module controls memory reclamation in response to the memory reclamation pressure being greater than the memory pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold, it is specifically used to: control memory reclamation in response to the memory reclamation pressure being greater than the second pressure threshold and less than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold; or, control memory reclamation in response to the memory reclamation pressure being greater than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being greater than the page cache threshold.
[0141] According to one or more embodiments of this disclosure, when controlling memory reclamation, the execution module is specifically used to: obtain the termination priority score of a program process in the operating system; determine the target program process based on the termination priority score; and close the target program process to release the memory resources of the target program process.
[0142] According to one or more embodiments of this disclosure, before obtaining the termination priority score of a program process in the operating system, the execution module is further configured to: periodically traverse the pseudo file system through an independent thread to cache the N candidate program processes with the highest termination priority scores; when obtaining the termination priority score of a program process in the operating system, the execution module is specifically configured to: obtain the target program process from the N candidate program processes.
[0143] Thirdly, according to one or more embodiments of the present disclosure, an electronic device is provided, comprising: at least one processor and a memory;
[0144] The memory stores the instructions that the computer executes;
[0145] At least one processor executes computer execution instructions stored in memory, causing at least one processor to perform the memory reclamation method as described in the first aspect above and various possible designs of the first aspect.
[0146] Fourthly, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, which stores computer-executable instructions that, when executed by a processor, implement the memory reclamation method described in the first aspect and various possible designs of the first aspect.
[0147] Fifthly, according to one or more embodiments of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the memory reclamation method as described in the first aspect above and various possible designs of the first aspect.
[0148] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0149] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0150] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A memory reclamation method, characterized in that, include: Determine memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel; Based on the memory reclamation efficiency, the memory reclamation pressure is determined, which characterizes the execution load of the kernel reclamation of memory; Memory reclamation is controlled based on the memory reclamation pressure and the amount of available system resources.
2. The method according to claim 1, characterized in that, The available system resources include available memory and page cache. Controlling memory reclamation based on the memory reclamation pressure and the available system resources includes: In response to the memory reclamation pressure being greater than the memory pressure threshold, the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold, memory reclamation is controlled.
3. The method according to claim 2, characterized in that, The method further includes: Obtain the dynamic baseline corresponding to the processor utilization rate, which is used to characterize the benchmark value of the processor utilization rate at different times; The step of controlling memory reclamation in response to the memory reclamation pressure being greater than a memory pressure threshold, the available memory being less than an available memory threshold, and the page cache being less than a page cache threshold includes: In response to the memory reclamation pressure being greater than the memory pressure threshold, the available memory being less than the available memory threshold, the page cache being less than the page cache threshold, and the processor utilization exceeding the dynamic baseline target multiple, memory reclamation is controlled.
4. The method according to claim 3, characterized in that, The processor utilization rate includes a first utilization rate and a second utilization rate. The first utilization rate represents the proportion of time the processor spends executing kernel-mode code, and the second utilization rate represents the proportion of time the processor spends waiting for input / output operations to complete. The memory pressure threshold includes a first pressure threshold and a third pressure threshold. The memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the third pressure threshold. The method further includes: When the memory reclamation pressure is less than the third pressure threshold, the first occupancy rate and the second occupancy rate are collected for a preset time, and the first baseline data corresponding to the first occupancy rate and the second baseline data corresponding to the second occupancy rate are constructed. Based on the first and second benchmark data, a dynamic baseline is generated corresponding to the first and second occupancy rates using a dynamic smoothing index algorithm.
5. The method according to claim 2, characterized in that, The memory pressure threshold includes a first pressure threshold and a second pressure threshold, wherein the memory reclamation pressure corresponding to the first pressure threshold is greater than the memory reclamation pressure corresponding to the second pressure threshold; the step of controlling memory reclamation in response to the memory reclamation pressure being greater than the memory pressure threshold, the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold includes: In response to the memory reclamation pressure being greater than the second pressure threshold and less than the first pressure threshold, and the available memory being less than the available memory threshold, and the page cache being less than the page cache threshold, memory reclamation is controlled; or, In response to the memory reclamation pressure being greater than the first pressure threshold, the available memory being less than the available memory threshold, and the page cache being greater than the page cache threshold, memory reclamation is controlled.
6. The method according to claim 1, characterized in that, The control of memory reclamation includes: Obtain the termination priority score of a program process in the operating system; Based on the termination priority score, the target program process is determined and closed to release its memory resources.
7. The method according to claim 6, characterized in that, Before obtaining the termination priority score of the program process in the operating system, the method further includes: The pseudo file system is periodically traversed by an independent thread to cache the N candidate program processes with the highest termination priority scores. The process of obtaining the termination priority score of a program process in the operating system includes: Obtain the target program process from the N alternative program processes.
8. A memory reclamation device, characterized in that, include: The acquisition module is used to determine the memory reclamation efficiency, which represents the ratio of the number of pages successfully reclaimed by the kernel to the number of pages scanned by the kernel. The judgment module is used to determine the memory reclamation pressure based on the memory reclamation efficiency, wherein the memory reclamation pressure represents the execution load of the kernel reclamation of memory; The execution module is used to control memory reclamation based on the memory reclamation pressure and the amount of available system resources.
9. An electronic device, characterized in that, include: Processor and memory; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the memory reclamation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, implement the memory reclamation method as described in any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the memory reclamation method as described in any one of claims 1 to 7.