Memory management method, computer device and storage medium
By recording the operating system's behavior information and optimizing memory configuration parameters, the problem of low efficiency in adjusting memory configuration parameters is solved, achieving rapid convergence and efficient memory resource management, adapting to different business scenarios, and reducing memory pressure and system latency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZTE CORP
- Filing Date
- 2022-11-22
- Publication Date
- 2026-07-10
AI Technical Summary
In existing technologies, adjusting memory configuration parameters is inefficient, difficult to converge quickly, and hard to adapt to different business scenarios, resulting in low memory resource utilization and increased system latency.
After a memory allocation request fails, the system records the operating system's behavior information, determines the memory configuration parameters to be adjusted based on this information, and then adjusts them accordingly. This includes optimizing parameters such as memory waterline, active memory compression instructions, memory swapping instructions, memory fragmentation compression threshold, container memory quota, and page cache load ratio.
It achieves rapid convergence of memory configuration parameters, improves the efficiency of adjusting memory configuration parameters, adapts to different business scenarios, reduces memory pressure, and improves memory resource utilization and system performance.
Smart Images

Figure CN118093150B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of computer memory, and more particularly to a memory management method, computer device, and storage medium. Background Technology
[0002] Memory is a component of a computer. When a computer runs a program, data related to the program's execution can be temporarily stored in memory, waiting for the processor to access it. If memory resources are insufficient, the processor may need to wait for a period of time to obtain the data required for program execution. To improve memory resource utilization, memory resource usage needs to be managed. For example, memory configuration parameters can be tuned using randomization methods, and system performance under different memory configuration parameters can be tested to determine the optimal solution. However, current random testing methods are time-consuming, and memory configuration parameters are difficult to converge, resulting in low tuning efficiency. Summary of the Invention
[0003] This application provides a memory management method, a computer device, and a storage medium, aiming to improve the efficiency of adjusting memory configuration parameters and achieve rapid convergence of memory configuration parameters.
[0004] In a first aspect, embodiments of this application provide a memory management method, comprising: receiving a memory allocation request; recording the behavior information of the memory operating system after the memory allocation request fails; determining an adjustment parameter for a memory configuration parameter to be adjusted based on the behavior information, wherein the memory configuration parameter to be adjusted corresponds to the behavior information; and adjusting the memory configuration parameter according to the adjustment parameter.
[0005] Secondly, embodiments of this application also provide a computer device, the computer device including a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for implementing connection communication between the processor and the memory, wherein when the computer program is executed by the processor, it implements the steps of any memory management method provided in embodiments of this application.
[0006] Thirdly, embodiments of this application also provide a storage medium for computer-readable storage, characterized in that the storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of any memory management method provided in embodiments of this application.
[0007] This application provides a memory management method, computer device, and storage medium. The method involves receiving a memory allocation request and, upon failure, recording the behavior information of the memory operating system. Based on this behavior information, adjustment parameters for memory configuration parameters to be adjusted are determined, wherein there is a correspondence between the memory configuration parameters to be adjusted and the behavior information. The memory configuration parameters are then adjusted according to these adjustment parameters. This method can specifically adjust memory configuration parameters based on the behavior of the memory operating system, adapting to different business scenarios and improving the efficiency of memory configuration parameter adjustment, achieving rapid convergence of memory configuration parameters, thereby reducing memory pressure. Attached Figure Description
[0008] Figure 1 This is a flowchart illustrating the steps of a memory management method provided in an embodiment of this application.
[0009] Figure 2 A schematic diagram illustrating behavioral information provided in an embodiment of this application;
[0010] Figure 3 A schematic diagram of memory configuration parameters provided in an embodiment of this application;
[0011] Figure 4 This is a flowchart illustrating the steps of another memory management method provided in an embodiment of this application.
[0012] Figure 5 This is a schematic block diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0013] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0014] The flowchart shown in the attached diagram is for illustrative purposes only and does not necessarily include all content and operations / steps, nor does it necessarily have to be performed in the order described. For example, some operations / steps can be broken down, combined, or partially merged, so the actual execution order may change depending on the actual situation.
[0015] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0016] To reduce memory pressure, existing automatic tuning solutions for memory configuration parameters use randomization to create a set of parameters, test the system performance of each parameter combination, and ultimately select the optimal solution. However, modern operating systems have a huge number of runtime parameters, and performance testing takes a long time. Therefore, this random testing method is unlikely to find an optimal parameter combination, leading to difficulties in converging memory configuration parameters, which is not only time-consuming but also inefficient. Furthermore, random parameter tuning is tied to specific business loads or scenarios, making it difficult for the tuned memory configuration parameters to dynamically adapt to different business loads or scenarios, resulting in poor flexibility.
[0017] This application provides a memory management method, a computer device, and a storage medium. The memory management method can be applied to a computer device, which includes a server and terminal devices. The server can be a single server or a server cluster consisting of multiple servers, and the terminal devices can be electronic devices such as mobile phones, tablets, laptops, desktop computers, personal digital assistants, and wearable devices.
[0018] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0019] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating the steps of a memory management method provided in an embodiment of this application.
[0020] like Figure 1 As shown, the memory management method includes steps S101 to S104.
[0021] Step S101: Receive memory allocation request.
[0022] Among them, the memory allocation request is used to request memory allocation. Memory allocation refers to the allocation or reclamation of memory storage space during program execution, including static memory allocation and dynamic memory allocation.
[0023] It should be noted that during the operation of a computer device, data related to program execution can be temporarily stored in memory, awaiting processor access. Computer devices need to manage memory; for example, after receiving a memory allocation request, they allocate memory to the process according to the request.
[0024] In one embodiment, the computer device can execute memory allocation requests through a memory operating system. If memory resources are insufficient when the memory operating system executes a memory allocation request, it may need to wait for a period of time to complete the request. The time interval between the memory operating system receiving the memory allocation request and completing it can be referred to as memory pressure. The longer the time interval, the greater the system memory pressure.
[0025] Step S102: After the memory allocation request fails, record the behavior information of the memory operating system.
[0026] It should be noted that computer devices can monitor the memory allocation process handled by the operating system to determine whether a memory allocation request succeeds or fails. For failed memory allocation requests, the computer device can record the operating system's behavior information, which facilitates analysis of why the operating system could not fulfill the memory allocation request.
[0027] The behavioral information includes memory reclamation, memory compaction, and page cache thrashing limits. It's important to note that memory reclamation refers to the process of reclaiming heap segments and file-mapped segments in user space. Reclaimable memory types include file-backed pages and anonymous pages. Memory compaction refers to the process of compressing memory. When the memory operating system detects insufficient memory, it compresses unused memory and places it on physical memory instead of writing it to disk (virtual memory). For example, the memory operating system can compress the memory of infrequently used background applications to increase available memory.
[0028] It's important to note that page cache thrashing refers to the actions taken to limit or even eliminate page cache thrashing. Thrashing, also known as page cache jittering, can be caused by various factors. For example, allocating too few physical pages of memory to a process can lead to frequent page faults and thrashing during execution. Therefore, when the memory operating system detects page cache thrashing, it can eliminate it based on its specific cause.
[0029] For example, such as Figure 2As shown, the behavioral information includes at least one of the following: background memory reclamation 11, background memory compression 12, foreground memory reclamation 13, foreground memory compression 14, container memory reclamation 15, and page cache thrashing limitation 16. It should be noted that memory reclamation includes background memory reclamation 11, foreground memory reclamation 13, and container memory reclamation 15, and memory compression includes background memory compression 12 and foreground memory compression 14. After a memory allocation request fails, the recorded behavioral information of the memory operating system can be one or more of the above; this embodiment does not specifically limit this.
[0030] It's important to note that background memory reclamation (kswapd) refers to waking up kernel threads to reclaim memory when physical memory is scarce. This reclamation process is asynchronous and does not block process execution. Foreground memory reclamation (kswapd), also known as direct reclaim, occurs when asynchronous background reclamation cannot keep up with the process's memory allocation. This reclamation process is synchronous and will block process execution. Container memory reclamation (kswapd) can be called foreground container memory reclamation. If direct memory reclamation still cannot satisfy the current physical memory allocation, the kernel will trigger container memory reclamation. For example, it might select a process with high physical memory usage based on an algorithm, stop it, and release its memory resources. The difference between background memory compression (kswapd) and foreground memory compression (kswapd) is that background memory compression (kswapd) is asynchronous and does not block process execution, while foreground memory compression (kswapd) is synchronous and will block process execution.
[0031] In one embodiment, the method for determining memory allocation request failure includes: monitoring the time spent waiting for a memory response when executing the memory allocation request; and determining that the memory allocation request has failed when the memory response time is greater than or equal to a preset response time. It should be noted that the waiting time for a memory response can begin counting after the memory operating system receives the memory allocation request, and the preset response time can be set according to actual conditions, for example, 5 seconds. This waiting time for a memory response can also be referred to as memory pressure; the longer the waiting time, the greater the memory pressure on the memory operating system. When the memory response time is greater than or equal to the preset response time, the memory allocation request is determined to have failed. For requests that fail to allocate memory and cause memory allocation delays, the computer device can analyze the reasons why the system cannot fulfill the memory allocation request and generate relevant data.
[0032] Step S103: Based on the behavioral information, determine the adjustment parameters of the memory configuration parameters to be adjusted.
[0033] The memory configuration parameters to be adjusted correspond to behavioral information. In other words, the memory configuration parameters to be adjusted are determined based on the behavioral information and this correspondence. It should be noted that the memory operating system's behavioral information is generated when memory allocation requests cannot be fulfilled; therefore, the memory operating system's behavioral information can reflect memory allocation-related issues. Based on the memory operating system's behavioral information, the memory configuration parameters to be adjusted can be accurately determined, and how to accurately adjust these parameters can be obtained, thereby reducing memory pressure.
[0034] In one embodiment, before determining the adjustment parameter of the memory configuration parameter to be adjusted based on the behavior information, the method further includes: obtaining the number of records of behavior information of the memory operating system; and when the number of records is greater than or equal to a preset number of records, performing the step of determining the adjustment parameter of the memory configuration parameter to be adjusted based on the behavior information.
[0035] The preset number of records can be set according to actual needs, for example, to 5. It should be noted that, to ensure the accuracy of the memory pressure assessment of the memory operating system, the adjustment parameters for determining the memory configuration parameters to be adjusted based on the behavior information, and subsequent steps, can be executed only when the number of records of the memory operating system's behavior information is greater than or equal to the preset number of records.
[0036] For example, the computer device includes a system performance monitoring service platform memd. When the number of records of the behavior information of the memory operating system is greater than or equal to a preset number of records, the system performance monitoring service platform memd sends multiple behavior information of the memory operating system to the system performance monitoring service platform memd so that the system performance monitoring service platform memd can perform adjustment parameters based on the behavior information to determine the memory configuration parameters to be adjusted and subsequent steps.
[0037] In one embodiment, memory configuration parameters include at least one of the following: memory waterline, active memory compression instructions, memory swapping instructions, memory fragmentation compression threshold, container memory quota, and page cache load ratio. It should be noted that each memory region of a computer device has three memory waterlines: a high waterline, a low waterline, and a minimum waterline. If the number of free cache pages in a memory region is greater than the high waterline, it indicates sufficient memory; if the number of free cache pages is less than the low waterline, it indicates slightly insufficient memory; if the number of free cache pages is less than the minimum waterline, it indicates severely insufficient memory. Memory below the minimum waterline is "urgently reserved memory," which is only allocated to specific processes in cases of severe memory shortage, and these processes must commit to "allocating a small amount of memory to free up more memory."
[0038] It's important to note that active memory compression instructions instruct the memory operating system to enable active memory compression, such as zSwap, zRAM, and zCache, thereby saving memory. Memory swapping instructions instruct the memory operating system to enable memory swapping, for example, saving temporarily unused memory pages from certain processes to disk, then allocating physical memory pages to more urgent business needs, and reading them back from disk into memory when needed. Memory fragmentation compression thresholds adjust the execution frequency of background compression tasks. When memory fragmentation reaches the memory fragmentation compression threshold, the memory operating system can initiate background compression tasks. Container available memory consists of two parts: physical memory and swap partition. Container memory quotas control various memory-related aspects such as swap size and available memory size. These include parameters like memory-swappiness, kernel-memory, memory, and memory-reservation. The memory-swappiness parameter controls the tendency for processes to swap physical memory to the swap partition; its default value is 60. A smaller value indicates a greater tendency to use physical memory. Page cache load ratio represents the proportion of page cache quota; a higher page cache load ratio indicates a larger page cache quota.
[0039] In one embodiment, the correspondence between memory configuration parameters and behavioral information includes: memory waterline corresponding to background memory reclamation, active memory compression command corresponding to background memory compression; memory swapping command corresponding to foreground memory reclamation, memory fragmentation compression threshold corresponding to foreground memory compression; container memory quota corresponding to container memory reclamation, and page cache load ratio corresponding to page cache thrashing limit.
[0040] For example, such as Figure 2 and Figure 3 As shown, the behavioral information includes at least one of the following: background memory reclamation 11, background memory compression 12, foreground memory reclamation 13, foreground memory compression 14, container memory reclamation 15, and page cache thrashing limit 16. The memory configuration parameters include at least one of the following: memory waterline 21, active memory compression instruction 22, memory swapping instruction 23, memory fragmentation compression threshold 24, container memory quota 25, and page cache load ratio 26. There is a correspondence between the memory configuration parameters and the behavioral information: for example, memory waterline 21 corresponds to background memory reclamation 11; active memory compression instruction 22 corresponds to background memory compression 12; memory swapping instruction 23 corresponds to foreground memory reclamation 13; memory fragmentation compression threshold 24 corresponds to foreground memory compression 14; container memory quota 25 corresponds to container memory reclamation 15; and page cache load ratio 26 corresponds to page cache thrashing limit 16.
[0041] It should be noted that the operating system's behavior information can reflect memory allocation issues. By understanding the correspondence between memory configuration parameters and behavior information, the adjustment parameters of the memory configuration parameters to be adjusted can be accurately determined. These adjustment parameters can be updated memory configuration parameters or changes in memory configuration parameters.
[0042] In one embodiment, when the behavioral information includes background memory reclamation, the adjustment parameter is used to increase the difference between the low watermark and the lowest watermark in the memory watermark; when the behavioral information includes background memory compression, the adjustment parameter is used to generate an active memory compression instruction; when the behavioral information includes foreground memory reclamation, the adjustment parameter is used to generate a memory swap instruction; when the behavioral information includes foreground memory compression, the adjustment parameter is used to lower the memory fragmentation compression threshold; when the behavioral information includes container memory reclamation, the adjustment parameter is used to increase the container memory quota; and when the behavioral information includes page cache thrashing limits, the adjustment parameter is used to increase the page cache load ratio.
[0043] It's important to note that when the memory operating system's behavior includes background memory reclamation, the corresponding memory configuration parameter is the memory waterline. Adjusting this parameter increases the difference between the low and minimum waterline, allowing for more frequent wake-up of background reclamation tasks and reducing memory pressure. When the memory operating system's behavior includes background memory compression, the corresponding memory configuration parameter is the memory compression instruction. Adjusting this parameter generates proactive memory compression instructions, saving memory space. When the memory operating system's behavior includes foreground memory reclamation, the corresponding memory configuration parameter is the memory swapping instruction. Adjusting this parameter initiates a memory swapping task, saving temporarily unused memory pages from certain processes to disk and allocating physical memory pages to more urgent business needs, thus reducing memory pressure.
[0044] It's important to note that when the memory operating system's behavior information includes foreground memory compression, the corresponding memory configuration parameter is the memory fragmentation compression threshold. Adjusting this parameter lowers the memory fragmentation compression threshold, thereby increasing the execution frequency of background compression tasks and reducing memory pressure. When the memory operating system's behavior information includes container memory reclamation, the corresponding memory configuration parameter is the container memory quota. Adjusting this parameter increases the container memory quota, thereby reducing container memory reclamation and allowing more memory to be used. When the memory operating system's behavior information includes page cache thrashing limits, the corresponding memory configuration parameter is the page cache load ratio. Adjusting this parameter increases the page cache load ratio and the page cache quota ratio, improving memory resource utilization.
[0045] Step S104: Adjust the memory configuration parameters according to the adjustment parameters.
[0046] The adjustment parameters can be updated memory configuration parameters or changes in memory configuration parameters. It should be noted that targeted adjustments to memory configuration parameters based on these adjustment parameters can achieve rapid convergence of memory configuration parameters, improve adjustment efficiency, thereby reducing memory pressure and facilitating optimization of system memory management and allocation methods to reduce memory allocation latency. Furthermore, the embodiments of this application can adjust memory configuration parameters for different system loads and scenarios, offering good flexibility.
[0047] In one embodiment, based on behavioral information, the memory configuration parameters to be adjusted are determined; the duration of the behavior corresponding to the behavioral information is obtained; and based on the duration of the behavior, the amount of adjustment change of the memory configuration parameters is determined as the adjustment parameter. The adjustment parameter includes the amount of adjustment change of the memory configuration parameters. It should be noted that the duration of the behavior corresponding to the behavioral information can be directly proportional or inversely proportional to the amount of adjustment change of the memory configuration parameters; the direct or inverse proportional relationship needs to be determined based on the specific behavioral information.
[0048] For example, the behavioral information of the memory operating system includes foreground memory compression. The adjustment parameters of the memory configuration parameters are used to lower the memory fragmentation compression threshold. Then the memory fragmentation compression threshold is a negative value. The duration of the behavior is inversely proportional to the amount of change in the adjustment of the memory configuration parameters. That is, the longer the duration of the behavior corresponding to foreground memory compression, the greater the reduction in the amount of memory fragmentation compression threshold used to adjust it.
[0049] For example, the behavioral information of the memory operating system includes page cache thrashing limits and memory configuration parameters that are used to increase the page cache load ratio. The duration of the behavior is directly proportional to the amount of change in the memory configuration parameters. That is, the longer the duration of the behavior corresponding to the page cache thrashing limit, the larger the increment used to adjust the page cache load ratio.
[0050] In one embodiment, after adjusting the memory configuration parameters according to the adjustment parameters, the process further includes: receiving a new memory allocation request and determining whether the new memory allocation request has failed; if the new memory allocation request fails, determining a preset number of low-priority target services from multiple pending services in memory; and migrating or stopping the execution of the target services. The priority of the pending services can be determined according to actual conditions, for example, setting restartable or non-critical services as low priority. It should be noted that after adjusting the memory configuration parameters according to the adjustment parameters, if the memory pressure cannot be reduced below a threshold, new memory allocation requests are prone to failure. Therefore, some services can be shut down or migrated to ultimately reduce the memory pressure below the threshold, improve the reliability of memory management, reduce system latency caused by memory resource contention, and improve system throughput.
[0051] The memory management method provided in the above embodiments receives memory allocation requests and records the behavior information of the memory operating system after the memory allocation request fails. Based on the behavior information, it determines the adjustment parameters of the memory configuration parameters to be adjusted, wherein there is a correspondence between the memory configuration parameters to be adjusted and the behavior information. The memory configuration parameters are then adjusted according to the adjustment parameters. This embodiment can adjust memory configuration parameters specifically according to the behavior of the memory operating system, adapting to different business scenarios and improving the efficiency of memory configuration parameter adjustment, achieving rapid convergence of memory configuration parameters, thereby reducing memory pressure and improving memory resource utilization.
[0052] Please refer to Figure 4 , Figure 4 This is a flowchart illustrating the steps of another memory management method provided in an embodiment of this application.
[0053] like Figure 4 As shown, the memory management method includes steps S201 to S206.
[0054] Step S201: Receive memory allocation request.
[0055] A memory allocation request is used to request memory allocation. During computer operation, the operating system receives memory allocation requests. The time interval between the operating system receiving a memory allocation request and completing the allocation is called memory pressure. The longer the time interval, the greater the system memory pressure.
[0056] Step S202: After the memory allocation request fails, record the behavior information of the memory operating system.
[0057] Memory allocation requests can be executed successfully or fail. For example, if the memory pressure on the operating system exceeds a preset pressure threshold (preset response time), the memory allocation request is considered to have failed. For failed memory allocation requests, the computer device can record the behavior information of the operating system, which facilitates analysis of why the operating system cannot fulfill the memory allocation request.
[0058] For example, when the pressure of allocation latency exceeds a preset pressure threshold, the system performance monitoring service memd is activated. memd reads the system's memory status report to obtain memory operating system behavior information. This behavior information includes memory reclamation, memory compaction, and page cache thrashing limits.
[0059] Step S203: Based on the behavioral information, determine the memory configuration parameters to be adjusted.
[0060] The memory configuration parameters to be adjusted correspond to behavioral information. For example, behavioral information includes at least one of background memory reclamation, background memory compaction, foreground memory reclamation, foreground memory compaction, container memory reclamation, and page cache thrashing limits. Memory configuration parameters include at least one of memory waterline, active memory compaction commands, memory swapping commands, memory fragmentation compaction threshold, container memory quota, and page cache load ratio.
[0061] For example, when the memory operating system's behavior information includes background memory reclamation, the corresponding memory configuration parameter is the memory waterline; when the memory operating system's behavior information includes background memory compaction, the corresponding memory configuration parameter is the memory compaction instruction; when the memory operating system's behavior information includes foreground memory reclamation, the corresponding memory configuration parameter is the memory swapping instruction; when the memory operating system's behavior information includes foreground memory compaction, the corresponding memory configuration parameter is the memory fragmentation compaction threshold; when the memory operating system's behavior information includes container memory reclamation, the corresponding memory configuration parameter is the container memory quota; and when the memory operating system's behavior information includes page cache thrashing limits, the corresponding memory configuration parameter is the page cache load ratio.
[0062] Step S204: Obtain the duration of the behavior corresponding to the behavior information.
[0063] When the memory operating system is unable to fulfill a memory allocation request, the operating system's behavior information can reflect the related problems in memory allocation, and the duration of the behavior information can reflect the severity of the related problems.
[0064] In one embodiment, the duration of the behavior can be recorded along with the behavior information of the memory operating system. Alternatively, the duration of the behavior can be recorded in the behavior information. For example, after a memory allocation request fails, the completion time of one or more behaviors can be recorded, and key-value pairs can be generated to obtain the behavior duration corresponding to the behavior information.
[0065] Step S205: Adjust the memory configuration parameters based on the duration of the behavior to obtain updated memory configuration parameters as adjustment parameters.
[0066] It should be noted that the duration of the behavior corresponding to the behavior information can be directly or inversely proportional to the updated memory configuration parameters. The direct or inverse relationship needs to be determined based on the specific behavior information.
[0067] For example, the behavioral information of the memory operating system includes foreground memory compression. The adjustment parameters of the memory configuration parameters are used to lower the memory fragmentation compression threshold. Then the memory fragmentation compression threshold is a negative value. The duration of the behavior is inversely proportional to the updated memory configuration parameters. That is, the longer the duration of the behavior corresponding to foreground memory compression, the smaller the updated memory configuration parameters.
[0068] For example, the behavior information of the memory operating system includes page cache thrashing limits and memory configuration parameters that are used to increase the page cache load ratio. The duration of the behavior is directly proportional to the updated memory configuration parameters. That is, the longer the duration of the behavior corresponding to the page cache thrashing limit, the larger the updated memory configuration parameters should be.
[0069] Step S206: Adjust the memory configuration parameters according to the adjustment parameters.
[0070] It should be noted that when adjusting memory configuration parameters, the updated parameters should be replaced with the updated ones. By selectively adjusting memory configuration parameters, different business scenarios can be adapted, improving the efficiency of parameter adjustments and enabling rapid convergence. This, in turn, reduces memory pressure and improves memory resource utilization.
[0071] In one embodiment, after adjusting the memory configuration parameters according to the adjustment parameters, a failed memory allocation request is obtained; the memory allocation request is re-executed, and it is determined whether the new memory allocation request fails; after the new memory allocation request fails, a preset number of low-priority target services are determined from multiple pending services in memory; the target services are migrated or stopped from execution. Through the above method, system latency caused by memory resource contention can be reduced, and system throughput can be improved.
[0072] The key point of this application embodiment is that after the memory allocation request fails, the behavior information of the memory operating system is recorded, which facilitates the analysis of the memory configuration parameters that caused the memory allocation failure, finds out the cause of the system memory pressure, and then adjusts the memory configuration parameters in a targeted manner to achieve the purpose of quickly converging to the optimal system parameters.
[0073] The memory management method provided in the above embodiments receives memory allocation requests and records the behavior information of the memory operating system after the memory allocation request fails. Based on the behavior information, it determines the memory configuration parameters to be adjusted, obtains the behavior duration corresponding to the behavior information, adjusts the memory configuration parameters based on the behavior duration, and obtains updated memory configuration parameters as adjustment parameters. The memory configuration parameters are then adjusted according to the adjustment parameters. This embodiment can adjust memory configuration parameters specifically according to the behavior of the memory operating system, adapting to different business scenarios and improving the efficiency of memory configuration parameter adjustment, achieving rapid convergence of memory configuration parameters, thereby reducing memory pressure and improving memory resource utilization.
[0074] Please see Figure 5 , Figure 5 This is a schematic block diagram of the structure of a computer device provided in an embodiment of this application.
[0075] like Figure 5 As shown, computer device 300 includes a processor 301 and a memory 302, which are connected via a bus 303, such as an I2C (Inter-integrated Circuit) bus. Computer device 300 can be a server or a terminal device.
[0076] Specifically, processor 301 provides computing and control capabilities to support the operation of the entire computer device. Processor 301 can be a Central Processing Unit (CPU), but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0077] Specifically, the memory 302 can be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a portable hard drive, etc.
[0078] Those skilled in the art will understand that Figure 5The structure shown in the figure is merely a block diagram of a portion of the structure related to the embodiments of this application, and does not constitute a limitation on the computer device 300 to which the embodiments of this application are applied. The specific computer device 300 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0079] The processor is used to run computer programs stored in memory and to implement any of the memory management methods provided in the embodiments of this application when executing the computer programs.
[0080] In one embodiment, the processor is configured to run a computer program stored in memory, and when executing the computer program, perform the following steps:
[0081] Receive memory allocation requests;
[0082] After the memory allocation request fails, record the behavior information of the memory operating system;
[0083] Based on the behavioral information, the adjustment parameters of the memory configuration parameters to be adjusted are determined, wherein the memory configuration parameters to be adjusted have a corresponding relationship with the behavioral information;
[0084] The memory configuration parameters are adjusted according to the adjustment parameters.
[0085] In one embodiment, when the processor determines whether the memory allocation request has failed, it is configured to:
[0086] Monitor the time spent waiting for a memory response when executing the memory allocation request;
[0087] If the memory response time is greater than or equal to the preset response time, the memory allocation request is deemed to have failed.
[0088] In one embodiment, the behavioral information includes at least one of background memory reclamation, background memory compression, foreground memory reclamation, foreground memory compression, container memory reclamation, and page cache thrashing limitation;
[0089] The memory configuration parameters include at least one of the following: memory waterline, active memory compression instruction, memory swapping instruction, memory fragmentation compression threshold, container memory quota, and page cache load ratio.
[0090] In one embodiment, the correspondence between the memory configuration parameters and the behavioral information includes:
[0091] The memory waterline corresponds to the background memory reclamation, and the active memory compression command corresponds to the background memory compression;
[0092] The memory swapping instruction corresponds to the foreground memory reclamation, and the memory fragmentation compression threshold corresponds to the foreground memory compression;
[0093] The container memory quota corresponds to the container memory reclamation, and the page cache load ratio corresponds to the page cache thrashing limit.
[0094] In one embodiment, when the behavior information includes background memory reclamation, the adjustment parameter is used to increase the difference between the low waterline and the lowest waterline in the memory waterline;
[0095] When the behavior information includes background memory compression, the adjustment parameters are used to generate the active memory compression instruction;
[0096] When the behavior information includes foreground memory reclamation, the adjustment parameters are used to generate the memory swapping instruction;
[0097] When the behavior information includes foreground memory compression, the adjustment parameter is used to lower the memory fragmentation compression threshold;
[0098] When the behavior information includes container memory reclamation, the adjustment parameter is used to increase the container memory quota;
[0099] When the behavior information includes page cache thrashing limits, the adjustment parameter is used to increase the page cache load ratio.
[0100] In one embodiment, before determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavioral information, the processor is further configured to:
[0101] The number of records containing behavioral information of the memory operating system obtained;
[0102] When the number of records is greater than or equal to the preset number of records, the step of determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information is executed.
[0103] In one embodiment, when the processor determines the adjustment parameters of the memory configuration parameters to be adjusted based on the behavioral information, it is configured to:
[0104] Based on the behavioral information, determine the memory configuration parameters to be adjusted;
[0105] Obtain the duration of the behavior corresponding to the behavior information;
[0106] The memory configuration parameters are adjusted based on the duration of the behavior to obtain updated memory configuration parameters, which are then used as the adjustment parameters.
[0107] In one embodiment, after adjusting the memory configuration parameters according to the adjustment parameters, the processor is further configured to:
[0108] Receive a new memory allocation request and determine whether the new memory allocation request has failed to be executed;
[0109] After a new memory allocation request fails, a preset number of low-priority target services are determined from multiple pending services in memory.
[0110] Migrate or stop the execution of the target service.
[0111] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the computer device described above can be referred to the corresponding process in the aforementioned memory management method embodiments, and will not be repeated here.
[0112] This application also provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs that can be executed by one or more processors to implement the steps of any memory management method provided in this application.
[0113] The storage medium can be an internal storage unit of the computer device described in the foregoing embodiments, such as the hard disk or memory of the computer device. The storage medium can also be an external storage device of the computer device, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card.
[0114] It will be understood by those skilled in the art that all or some of the steps, systems, or apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software may be distributed on a computer-readable medium, which may include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
[0115] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments. The above descriptions are merely specific implementations of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A memory management method, characterized in that, include: Receive memory allocation requests; After the memory allocation request fails, record the behavior information of the memory operating system; Based on the behavioral information, the adjustment parameters of the memory configuration parameters to be adjusted are determined, wherein the memory configuration parameters to be adjusted have a corresponding relationship with the behavioral information; The memory configuration parameters are adjusted according to the adjustment parameters.
2. The memory management method according to claim 1, characterized in that, The methods for determining if a memory allocation request fails include: Monitor the time spent waiting for a memory response when executing the memory allocation request; If the memory response time is greater than or equal to the preset response time, the memory allocation request is deemed to have failed.
3. The memory management method according to claim 1, characterized in that, The behavioral information includes at least one of the following: background memory reclamation, background memory compression, foreground memory reclamation, foreground memory compression, container memory reclamation, and page cache thrashing limitation. The memory configuration parameters include at least one of the following: memory waterline, active memory compression instruction, memory swapping instruction, memory fragmentation compression threshold, container memory quota, and page cache load ratio.
4. The memory management method according to claim 3, characterized in that, The correspondence between the memory configuration parameters and the behavioral information includes: The memory waterline corresponds to the background memory reclamation, and the active memory compression command corresponds to the background memory compression; The memory swapping instruction corresponds to the foreground memory reclamation, and the memory fragmentation compression threshold corresponds to the foreground memory compression; The container memory quota corresponds to the container memory reclamation, and the page cache load ratio corresponds to the page cache thrashing limit.
5. The memory management method according to claim 4, characterized in that, When the behavior information includes background memory reclamation, the adjustment parameter is used to increase the difference between the low waterline and the lowest waterline in the memory waterline; When the behavior information includes background memory compression, the adjustment parameters are used to generate the active memory compression instruction; When the behavior information includes foreground memory reclamation, the adjustment parameters are used to generate the memory swapping instruction; When the behavior information includes foreground memory compression, the adjustment parameter is used to lower the memory fragmentation compression threshold; When the behavior information includes container memory reclamation, the adjustment parameter is used to increase the container memory quota; When the behavior information includes page cache thrashing limits, the adjustment parameter is used to increase the page cache load ratio.
6. The memory management method according to claim 1, characterized in that, Before determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavioral information, the method further includes: The number of records containing behavioral information of the memory operating system obtained; When the number of records is greater than or equal to the preset number of records, the step of determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information is executed.
7. The memory management method according to any one of claims 1-6, characterized in that, The step of determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavioral information includes: Based on the behavioral information, determine the memory configuration parameters to be adjusted; Obtain the duration of the behavior corresponding to the behavior information; The memory configuration parameters are adjusted based on the duration of the behavior to obtain updated memory configuration parameters, which are then used as the adjustment parameters.
8. The memory management method according to any one of claims 1-6, characterized in that, After adjusting the memory configuration parameters according to the adjustment parameters, the process further includes: Receive a new memory allocation request and determine whether the new memory allocation request has failed to be executed; After a new memory allocation request fails, a preset number of low-priority target services are determined from multiple pending services in memory. Migrate or stop the execution of the target service.
9. A computer device, characterized in that, The computer device includes a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for enabling communication between the processor and the memory, wherein when the computer program is executed by the processor, it implements the steps of the memory management method as described in any one of claims 1 to 8.
10. A storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the memory management method according to any one of claims 1 to 8.