WO2024109076A1 - 内存管理方法、计算机设备及存储介质 - Google Patents

内存管理方法、计算机设备及存储介质 Download PDF

Info

Publication number
WO2024109076A1
WO2024109076A1 PCT/CN2023/104847 CN2023104847W WO2024109076A1 WO 2024109076 A1 WO2024109076 A1 WO 2024109076A1 CN 2023104847 W CN2023104847 W CN 2023104847W WO 2024109076 A1 WO2024109076 A1 WO 2024109076A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
behavior information
compression
allocation request
parameter
Prior art date
Application number
PCT/CN2023/104847
Other languages
English (en)
French (fr)
Inventor
冉小凯
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2024109076A1 publication Critical patent/WO2024109076A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]

Definitions

  • the present disclosure relates to the technical field of computer memory, and in particular to a memory management method, a computer device, and a storage medium.
  • Memory is a component of a computer.
  • data related to the program can be temporarily stored in the memory, waiting for the processor to call it. If the memory resources are insufficient, the processor may need to wait for a while to obtain the data required for the program to run.
  • it is necessary to manage the usage of memory resources such as using a randomized method to tune the memory configuration parameters and test the system performance under different memory configuration parameters to determine the optimal solution.
  • this random testing method has technical problems such as taking a long time, difficulty in converging memory configuration parameters, and low adjustment efficiency.
  • Embodiments of the present disclosure provide a memory management method, a computer device, and a storage medium.
  • an embodiment of the present disclosure provides a memory management method, comprising: receiving a memory allocation request; after the memory allocation request fails to execute, recording behavior information of a memory operating system; based on the behavior information, determining adjustment parameters of memory configuration parameters to be adjusted, wherein there is a corresponding relationship between the memory configuration parameters to be adjusted and the behavior information; and adjusting the memory configuration parameters according to the adjustment parameters.
  • an embodiment of the present disclosure further provides a computer device, comprising a processor, a memory, a computer program stored in the memory and executable by the processor, and a data bus for realizing connection and communication between the processor and the memory, wherein when the computer program is executed by the processor, any memory management method provided in the embodiments of the present disclosure is implemented.
  • an embodiment of the present disclosure further provides a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement any memory management method provided in an embodiment of the present disclosure.
  • FIG1 is a schematic diagram of a step flow of a memory management method provided by an embodiment of the present disclosure
  • FIG2 is a schematic diagram of behavior information provided by an embodiment of the present disclosure.
  • FIG3 is a schematic diagram of memory configuration parameters provided by an embodiment of the present disclosure.
  • FIG4 is a schematic diagram of a step flow chart of another memory management method provided by an embodiment of the present disclosure.
  • FIG5 is a schematic block diagram of the structure of a computer device provided in an embodiment of the present disclosure.
  • the existing automatic tuning solutions for memory configuration parameters use a randomized approach to form a set of memory configuration parameters, test the system performance of each parameter combination, and finally select the optimal solution.
  • modern operating systems have a huge number of operating parameters, and performance testing takes a long time. Therefore, this random testing method is not easy to find a set of optimal parameter configuration combinations, which makes it difficult for memory configuration parameters to converge. It is not only time-consuming but also inefficient.
  • the random parameter tuning method is bound to specific business loads or scenarios. The tuned memory configuration parameters are difficult to dynamically adapt to different business loads or scenarios, and have poor flexibility.
  • the present disclosure provides a memory management method, a computer device and a storage medium. It can be applied to computer devices, including servers and terminal devices.
  • the server can be a single server or a server cluster composed of multiple servers
  • the terminal device can be an electronic device such as a mobile phone, tablet computer, laptop computer, desktop computer, personal digital assistant, and wearable device.
  • FIG. 1 is a schematic diagram of the steps of a memory management method provided by an embodiment of the present disclosure.
  • the memory management method includes steps S101 to S104 .
  • Step S101 receiving a memory allocation request.
  • the memory allocation request is used to request memory allocation.
  • Memory allocation refers to the memory that allocates or reclaims storage space during program execution, including static memory allocation and dynamic memory allocation.
  • data related to the program operation can be temporarily stored in the memory, waiting for the processor to call.
  • the computer device needs to manage the memory, for example, after receiving a memory allocation request, allocate memory to the process according to the memory allocation request.
  • the computer device may execute a memory allocation request through a memory operating system.
  • the memory operating system executes a memory allocation request, if the memory resources are insufficient, it may take a while to complete the memory allocation request.
  • the time interval from when the memory operating system receives the memory allocation request to when the memory allocation request is completed may be referred to as memory pressure. The larger the time interval, the greater the system memory pressure.
  • Step S102 After the memory allocation request fails to execute, the behavior information of the memory operating system is recorded.
  • the computer device can monitor the process of the memory operating system processing memory allocation, so as to determine whether the memory allocation request is executed successfully or failed. For the memory allocation request that failed to execute, the computer device can record the behavior information of the memory operating system, so as to facilitate the analysis of the reason why the memory operating system cannot satisfy the memory allocation request.
  • the behavior information includes memory reclamation, memory compression, and page cache thrashing limit.
  • memory reclamation refers to the behavior of reclaiming heap segments and file mapping segments in user space.
  • the types of memory that can be reclaimed include file pages (File-backed Page) and anonymous pages (Anonymous Page).
  • Memory compression refers to the behavior of compressing memory. When the memory operating system detects that the memory is insufficient, it will compress the useless memory and put it on the physical memory instead of writing it to the hard disk (virtual memory). For example, the memory operating system compresses the memory of infrequently used background applications to expand the available memory.
  • page cache thrashing limit refers to the behavior of limiting or even eliminating page cache thrashing.
  • the thrashing problem is also called the jitter problem.
  • page cache thrashing There are many reasons for page cache thrashing. For example, the physical memory pages allocated to a process If the number of pages is too small, the process will frequently have page fault interrupts during operation, resulting in thrashing. Therefore, when the memory operating system finds the page cache thrashing problem, it can eliminate the page cache thrashing according to the specific cause.
  • the behavior information includes at least one of background memory reclamation 11, background memory compression 12, foreground memory reclamation 13, foreground memory compression 14, container memory reclamation 15, and page cache bump limit 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.
  • the behavior information of the memory operating system may be one of the above items or multiple items, and this embodiment does not specifically limit this.
  • background memory recycling 11 means that when the physical memory is tight, the kernel thread will be awakened to reclaim the memory. This memory recycling process is asynchronous and will not block the execution of the process.
  • Foreground memory recycling 13 is also called direct memory recycling (direct reclaim). If the background asynchronous recycling cannot keep up with the speed of the process memory application, direct memory recycling will start. This memory recycling process is synchronous and will block the execution of the process.
  • Container memory recycling 15 can be called foreground container memory recycling. If the free physical memory still cannot meet the physical memory application after direct memory recycling, the kernel will trigger container memory recycling, for example, according to the algorithm, select a process that occupies a high amount of physical memory, and then stop it to release memory resources.
  • the difference between background memory compression 12 and foreground memory compression 14 is that the process of background memory compression 12 is asynchronous and will not block the execution of the process.
  • the process of foreground memory compression 14 is synchronous and will block the execution of the process.
  • a method for determining whether a memory allocation request fails to execute includes: monitoring the time for waiting for a memory response when executing a memory allocation request; and determining that the memory allocation request fails to execute when the memory response time is greater than or equal to a preset response time.
  • the time for waiting for a memory response may start after the memory operating system receives the memory allocation request, and the preset response time may be set according to actual conditions, for example, 5 seconds.
  • the time for waiting for a memory response may also be referred to as memory pressure, and the longer the time for waiting for a memory response, the greater the memory pressure of the memory operating system.
  • the computer device may analyze the reasons why the system cannot meet the memory allocation request and generate relevant data.
  • Step S103 Determine adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information.
  • the memory configuration parameters to be adjusted are determined based on the behavior information and the corresponding relationship.
  • the behavior information of the memory operating system is based on the inability to meet the memory allocation request, so the behavior information of the memory operating system can reflect the relevant issues of memory allocation.
  • the memory configuration parameters to be adjusted can be accurately determined, as well as how to accurately adjust the memory configuration parameters, to obtain the adjustment parameters of the memory configuration parameters, thereby reducing memory pressure.
  • determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information it also includes: obtaining the number of records of the behavior information of the memory operating system; when the number of records is greater than or equal to the preset number of records, executing the step of determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information.
  • the preset number of records can be set according to actual conditions, for example, 5. It should be noted that in order to ensure the accuracy of the memory pressure assessment of the memory operating system, when the number of records of the behavior information of the memory operating system is greater than or equal to the preset number of records, the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information and subsequent steps can be performed.
  • a computer device includes a system performance monitoring service platform MEMD.
  • a system performance monitoring service platform MEMD When the number of records of behavior information of a memory operating system is greater than or equal to a preset number of records, multiple behavior information of the memory operating system is sent to the system performance monitoring service platform MEMD, so that the system performance monitoring service platform MEMD can execute adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information and subsequent steps.
  • the memory configuration parameters include at least one of a memory watermark, an active memory compression instruction, a memory swap instruction, a memory fragmentation compression threshold, a container memory quota, and a page cache load ratio. It should be noted that there are three memory watermarks for each memory area of a computer device, including a high watermark (High Water Marker), a low watermark (Low Water Marker), and a minimum watermark (Min Water Marker).
  • the number of free cache pages in a memory area is greater than the high watermark, it indicates that the memory is sufficient; if the number of free cache pages in a memory area is less than the low watermark, it indicates that the memory is slightly insufficient; if the number of free cache pages in a memory area is less than the minimum watermark, it indicates that the memory is seriously insufficient.
  • the memory below the minimum watermark is "emergency reserved memory” and will only be allocated to specific processes when the memory is seriously insufficient. These processes must commit to "allocating a small amount of memory and releasing more memory.”
  • the active memory compression instruction is used to instruct the memory operating system to enable active memory compression, such as zSwap, zRAM, zCache, etc., so as to save memory.
  • the memory swap instruction is used to instruct the memory operating system to enable memory swap, such as saving some temporarily unused memory pages of certain processes to the disk, and then allocating physical memory pages to more urgent business use, and then reading them back from the disk to the memory when the process uses them.
  • the memory fragmentation compression threshold is used to adjust the execution frequency of the background compression task. When the memory fragmentation reaches the memory fragmentation compression threshold, the memory operating system can start the background compression task.
  • the container available memory includes two parts: physical memory and Swap swap partition.
  • the container memory quota is used to control the container's Swap size, available memory size and other memory controls.
  • the container memory quota includes memory swap (memory-swappiness) parameters, kernel memory (kernel-memory) parameters, memory (memory) parameters, memory reservation (memory-reservation) parameters, etc.
  • the memory swap parameter is used to control the process's tendency to swap physical memory to the Swap partition.
  • the default coefficient is 60. The smaller the coefficient, the more inclined to use physical memory.
  • the page cache load ratio is used to represent the quota ratio of the page cache. The larger the page cache load ratio is, the larger the quota ratio of the page cache is.
  • the correspondence between memory configuration parameters and behavior information includes: memory waterline corresponds to background memory reclamation, active memory compression instructions correspond to background memory compression; memory swap instructions correspond to foreground memory reclamation, memory fragmentation compression threshold corresponds to foreground memory compression; container memory quota corresponds to container memory reclamation, and page cache load ratio corresponds to page cache thrashing limit.
  • the behavior information includes at least one of background memory reclamation 11, background memory compression 12, foreground memory reclamation 13, foreground memory compression 14, container memory reclamation 15, and page cache bump limit 16, and the memory configuration parameters include at least one of memory waterline 21, active memory compression instruction 22, memory swap instruction 23, memory fragmentation compression threshold 24, container memory quota 25, and page cache load ratio 26.
  • the memory waterline 21 corresponds to the background memory reclamation 11
  • the active memory compression instruction 22 corresponds to the background memory compression 12
  • the memory swap instruction 23 corresponds to the foreground memory reclamation 13
  • the memory fragmentation compression threshold 24 corresponds to the foreground memory compression 14
  • the container memory quota 25 corresponds to the container memory reclamation 15
  • the page cache load ratio 26 corresponds to the page cache bump limit 16.
  • the behavior information of the memory operating system can reflect the relevant issues of memory allocation.
  • the adjustment parameters of the memory configuration parameters to be adjusted can be accurately determined.
  • the adjustment parameters can be updated memory configuration parameters or the adjustment changes of memory configuration parameters.
  • the adjustment parameter when the behavior 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 behavior information includes background memory compression, the adjustment parameter is used to generate an active memory compression instruction; when the behavior information includes foreground memory reclamation, the adjustment parameter is used to generate a memory swap 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 limit, the adjustment parameter is used to increase the page cache load ratio.
  • the corresponding memory configuration parameter is the memory waterline
  • the adjustment parameter of the memory configuration parameter is used to increase the difference between the low waterline and the lowest waterline in the memory waterline, so that the background recycling task can be woken up more frequently to reduce memory pressure.
  • the corresponding memory configuration parameter is the memory compression instruction
  • the adjustment parameter of the memory configuration parameter is used to generate active memory compression instructions to save memory space.
  • the corresponding memory configuration parameter is the memory swap instruction
  • the adjustment parameter of the memory configuration parameter is used to start the memory swap task, save some temporarily unused memory pages of certain processes to the disk, and then allocate physical memory pages to more urgent business use to reduce memory pressure.
  • the corresponding memory configuration parameters is the memory fragmentation compression threshold.
  • the adjustment parameters of the memory configuration parameters are used to lower the memory fragmentation compression threshold, thereby increasing the execution frequency of background compression tasks and reducing memory pressure.
  • the corresponding memory configuration parameter is the container memory quota.
  • the adjustment parameters of the memory configuration parameters are used to increase the container memory quota, thereby reducing container memory recycling and enabling more memory to be used.
  • the corresponding memory configuration parameter is the page cache load ratio.
  • the adjustment parameters of the memory configuration parameters are used to increase the page cache load ratio, increase the page cache quota ratio, and improve memory resource utilization.
  • Step S104 Adjust the memory configuration parameters according to the adjustment parameters.
  • the adjustment parameter can be an updated memory configuration parameter or an adjustment change of the memory configuration parameter. It should be noted that by adjusting the memory configuration parameter in a targeted manner according to the adjustment parameter, the rapid convergence of the memory configuration parameter can be achieved, and the adjustment efficiency of the memory configuration parameter can be improved, thereby reducing the memory pressure, which is conducive to optimizing the system memory management and allocation method to reduce the memory allocation delay.
  • the embodiment of the present disclosure can adjust the memory configuration parameters according to different system loads and scenarios, and has good flexibility.
  • the memory configuration parameter to be adjusted is determined; the behavior duration corresponding to the behavior information is obtained; based on the behavior duration, the adjustment change of the memory configuration parameter is determined as the adjustment parameter.
  • the adjustment parameter includes the adjustment change of the memory configuration parameter.
  • the behavior information of the memory operating system includes foreground memory compression, and the adjustment parameters of the memory configuration parameters are used to lower the memory fragmentation compression threshold.
  • the memory fragmentation compression threshold is a negative value
  • the behavior duration is inversely proportional to the adjustment change of the memory configuration parameters. That is, the longer the behavior duration corresponding to the foreground memory compression, the greater the reduction amount used to adjust the memory fragmentation compression threshold.
  • the behavior information of the memory operating system includes a page cache thrashing limit
  • the adjustment parameter of the memory configuration parameter is used to increase the page cache load ratio.
  • the behavior duration is directly proportional to the adjustment change of the memory configuration parameter, that is, the longer the behavior duration corresponding to the page cache thrashing limit, the larger the increment used to adjust the page cache load ratio.
  • after adjusting the memory configuration parameters according to the adjustment parameters it also includes: receiving a new memory allocation request and determining whether the new memory allocation request fails to execute; after the new memory allocation request fails to execute, determining a preset number of low-priority target businesses from multiple pending businesses in the memory; migrating or stopping the execution of the target business.
  • the priority of the pending business can be determined according to the actual situation, for example, the priority of the restartable business or the unimportant business can be determined as a low priority.
  • the new memory allocation request is likely to fail to execute, so the part can be closed or migrated.
  • Distributed services can ultimately reduce memory pressure to below the threshold, improve the reliability of memory management, reduce system delays caused by memory resource competition, and improve system throughput.
  • the memory management method provided in the above embodiment receives a memory allocation request, and after the memory allocation request fails to execute, records the behavior information of the memory operating system; based on the behavior information, determines the adjustment parameters of the memory configuration parameters to be adjusted, wherein there is a corresponding relationship between the memory configuration parameters to be adjusted and the behavior information; and adjusts the memory configuration parameters according to the adjustment parameters.
  • the disclosed embodiment can adjust the memory configuration parameters in a targeted manner according to the memory operating system behavior, can adapt to different business scenarios, and can improve the adjustment efficiency of the memory configuration parameters, realize the rapid convergence of the memory configuration parameters, thereby reducing the memory pressure and improving the memory resource utilization.
  • FIG. 4 is a schematic diagram of the steps of another memory management method provided by an embodiment of the present disclosure.
  • the memory management method includes steps S201 to S206 .
  • Step S201 Receive a memory allocation request.
  • a memory allocation request is used to request memory allocation.
  • a memory allocation request may be received through a memory operating system.
  • the time interval from when the memory operating system receives the memory allocation request to when the memory allocation request is completed may be referred to as memory pressure.
  • Step S202 After the memory allocation request fails to execute, the behavior information of the memory operating system is recorded.
  • the memory allocation request may be executed successfully or failed. For example, when the memory pressure of the memory operating system exceeds a preset pressure threshold (preset response time), the memory allocation request is determined to have failed. For failed memory allocation requests, the computer device may record the behavior information of the memory operating system, thereby facilitating analysis of the reasons why the memory operating system cannot satisfy the memory allocation request.
  • a preset pressure threshold preset response time
  • the system performance monitoring service MEMD when the pressure of allocation delay is greater than a preset pressure threshold, the system performance monitoring service MEMD is awakened, and the MEMD reads the system's memory status report to obtain the behavior information of the memory operating system, wherein the behavior information includes memory recycling, memory compression, and page cache thrashing limit.
  • Step S203 Determine the memory configuration parameters to be adjusted based on the behavior information.
  • the memory configuration parameters to be adjusted includes at least one of background memory recycling, background memory compression, foreground memory recycling, foreground memory compression, container memory recycling, and page cache thrashing limit.
  • the memory configuration parameters include at least one of memory waterline, active memory compression instruction, memory swap instruction, memory fragmentation compression threshold, container memory quota, and page cache load ratio.
  • the corresponding memory configuration parameter when the behavior information of the memory operating system includes background memory recycling, the corresponding memory configuration parameter is the memory waterline; when the behavior information of the memory operating system includes background memory compression, the corresponding memory configuration parameter is is a memory compression instruction; when the behavior information of the memory operating system includes foreground memory recycling, the corresponding memory configuration parameter is a memory swap instruction; when the behavior information of the memory operating system includes foreground memory compression, the corresponding memory configuration parameter is a memory fragmentation compression threshold; when the behavior information of the memory operating system includes container memory recycling, the corresponding memory configuration parameter is a container memory quota; when the behavior information of the memory operating system includes page cache thrashing limit, the corresponding memory configuration parameter is a page cache load ratio.
  • Step S204 Obtain the behavior duration corresponding to the behavior information.
  • the behavior information of the memory operating system can reflect the related problems of the memory allocation, and the behavior duration corresponding to the behavior information can reflect the severity of the related problems of the memory allocation.
  • the behavior duration may be recorded together with the behavior information of the memory operating system.
  • the behavior duration is recorded in the behavior information, for example, after a memory allocation request fails to execute, the completion time of one or more behaviors is recorded, and the behavior and duration are generated into a key-value corresponding entry to obtain the behavior duration corresponding to the behavior information.
  • Step S205 adjust the memory configuration parameters based on the behavior duration to obtain updated memory configuration parameters as adjustment parameters.
  • behavior duration corresponding to the behavior information may be directly proportional or inversely proportional to the updated memory configuration parameter, and the directly proportional or inversely proportional relationship needs to be determined according to the specific behavior information.
  • the behavior information of the memory operating system includes foreground memory compression, and the adjustment parameters of the memory configuration parameters are used to lower the memory fragmentation compression threshold.
  • the memory fragmentation compression threshold is a negative value, and the behavior duration is inversely proportional to the updated memory configuration parameters. That is, the longer the behavior duration corresponding to the foreground memory compression, the smaller the updated memory configuration parameters.
  • Step S206 Adjust the memory configuration parameters according to the adjustment parameters.
  • the adjustment parameter of the memory configuration parameter is an updated memory configuration parameter
  • the updated memory configuration parameter can be replaced with the current memory configuration parameter.
  • a memory allocation request that failed to execute is obtained; the memory allocation request is re-executed, and it is determined whether the new memory allocation request fails to execute; After the memory allocation request fails to execute, a preset number of low-priority target businesses are determined from multiple pending businesses in the memory; the target business is migrated or stopped.
  • the focus of the embodiment of the present disclosure is to record the behavior information of the memory operating system after the memory allocation request fails to execute, so as to facilitate the analysis of the memory configuration parameters that caused the memory allocation failure, find out the cause of the system memory pressure, and adjust the memory configuration parameters in a targeted manner to achieve the purpose of quickly converging to the optimal system parameters.
  • the memory management method provided in the above embodiment receives a memory allocation request, and after the memory allocation request fails to execute, records the behavior information of the memory operating system; based on the behavior information, 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; and adjusts the memory configuration parameters according to the adjustment parameters.
  • the disclosed embodiment can adjust the memory configuration parameters in a targeted manner according to the memory operating system behavior, can adapt to different business scenarios, and can improve the adjustment efficiency of the memory configuration parameters, realize the rapid convergence of the memory configuration parameters, thereby reducing memory pressure and improving memory resource utilization.
  • FIG. 5 is a schematic block diagram of the structure of a computer device provided in an embodiment of the present disclosure.
  • the computer device 300 includes a processor 301 and a memory 302, and the processor 301 and the memory 302 are connected via a bus 303, such as an I2C (Inter-integrated Circuit) bus.
  • the computer device 300 may be a server or a terminal device.
  • the processor 301 is used to provide computing and control capabilities to support the operation of the entire computer device.
  • the processor 301 can be a central processing unit (CPU), and the processor 301 can also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
  • the memory 302 can be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a mobile hard disk.
  • ROM read-only memory
  • the memory 302 can be a Flash chip, a read-only memory (ROM) disk, an optical disk, a USB flash drive, or a mobile hard disk.
  • FIG. 5 is merely a block diagram of a partial structure related to the embodiments of the present disclosure, and does not constitute a limitation on the computer device 300 to which the embodiments of the present disclosure 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 a different arrangement of components.
  • the processor is used to run a computer program stored in the memory, and implement any one of the memory management methods provided by the embodiments of the present disclosure when executing the computer program.
  • the processor is used to run a computer program stored in a memory, and implement the following steps when executing the computer program: receiving a memory allocation request; after the memory allocation request fails to execute, recording behavior information of the memory operating system; based on the behavior information, determining adjustment parameters of the memory configuration parameters to be adjusted, wherein there is a corresponding relationship between the memory configuration parameters to be adjusted and the behavior information; and adjusting the memory configuration parameters according to the adjustment parameters.
  • the processor when implementing the judgment of failure in executing a memory allocation request, is used to implement: monitoring the time waiting for a memory response when executing a memory allocation request; and when the memory response time is greater than or equal to a preset response time, judging that the memory allocation request has failed in execution.
  • the behavior 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 limit;
  • the memory configuration parameters include at least one of memory waterline, active memory compression instructions, memory swap instructions, memory fragmentation compression threshold, container memory quota, and page cache load ratio.
  • the correspondence between memory configuration parameters and behavior information includes: memory waterline corresponds to background memory reclamation, active memory compression instructions correspond to background memory compression; memory swap instructions correspond to foreground memory reclamation, memory fragmentation compression threshold corresponds to foreground memory compression; container memory quota corresponds to container memory reclamation, and page cache load ratio corresponds to page cache thrashing limit.
  • the adjustment parameter when the behavior 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 behavior information includes background memory compression, the adjustment parameter is used to generate active memory compression instructions; when the behavior information includes foreground memory reclamation, the adjustment parameter is used to generate memory swap instructions; 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 limit, the adjustment parameter is used to increase the page cache load ratio.
  • the processor before the processor implements the step of determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information, it is also used to implement: obtaining the number of records of the behavior information of the memory operating system; when the number of records is greater than or equal to a preset number of records, executing the step of determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information.
  • the processor when the processor implements determining the adjustment parameters of the memory configuration parameters to be adjusted based on the behavior information, it is used to implement: determining the memory configuration parameters to be adjusted based on the behavior information; obtaining the behavior duration corresponding to the behavior information; adjusting the memory configuration parameters based on the behavior duration, and obtaining updated memory configuration parameters as adjustment parameters.
  • the processor is also used to implement: receiving a new memory allocation request and determining whether the new memory allocation request fails to execute; after the new memory allocation request fails to execute, determining a preset number of low-priority target businesses from multiple businesses to be executed in the memory; and migrating or stopping execution of the target business.
  • the embodiments of the present disclosure also provide a storage medium for computer-readable storage, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement any memory management method provided in the embodiments of the present disclosure.
  • the storage medium may be an internal storage unit of the computer device described in the foregoing embodiment, such as a hard disk or memory of the computer device.
  • the storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc., provided on the computer device.
  • a plug-in hard disk such as a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc.
  • Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or temporary medium).
  • a computer storage medium 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 technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer.
  • communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
  • the present disclosure provides a memory management method, a computer device and a storage medium, aiming to improve memory configuration parameters.
  • the adjustment efficiency is improved to achieve rapid convergence of memory configuration parameters.
  • the disclosed embodiment provides a memory management method, a computer device, and a storage medium.
  • the disclosed embodiment receives a memory allocation request, and after the memory allocation request fails to execute, records the behavior information of the memory operating system; based on the behavior information, determines the adjustment parameters of the memory configuration parameters to be adjusted, wherein there is a corresponding relationship between the memory configuration parameters to be adjusted and the behavior information; and adjusts the memory configuration parameters according to the adjustment parameters.
  • the disclosed embodiment can adjust the memory configuration parameters in a targeted manner according to the memory operating system behavior, can adapt to different business scenarios, and can improve the adjustment efficiency of the memory configuration parameters, achieve rapid convergence of the memory configuration parameters, and thus can reduce memory pressure.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本公开实施例提供一种内存管理方法、计算机设备及存储介质,属于计算机领域,该方法包括:接收内存分配请求,并在内存分配请求执行失败后,记录内存操作系统的行为信息;基于行为信息,确定待调整的内存配置参数的调节参数,其中,待调整的内存配置参数与行为信息存在对应关系;根据调节参数,对内存配置参数进行调整。

Description

内存管理方法、计算机设备及存储介质
相关申请的交叉引用
本公开要求享有2022年11月22日提交的名称为“内存管理方法、计算机设备及存储介质”的中国专利申请CN202211467176.9的优先权,其全部内容通过引用并入本公开中。
技术领域
本公开涉及计算机内存的技术领域,尤其涉及一种内存管理方法、计算机设备及存储介质。
背景技术
内存(memory)是计算机的组成部分,当计算机运行程序时,与程序运行相关的数据可以暂时存放在内存中,等待处理器调用。若内存资源不足,则处理器可能需要等待一段时间才能获取程序运行所需的数据。为了提高内存资源利用率,需要对内存资源的使用情况进行管理,例如使用随机化的方式对内存配置参数进行调优,并测试不同内存配置参数下的系统性能来确定最优解。然而,这种随机测试的方法存在例如需花费较长时间、内存配置参数难以收敛、调整效率较低等技术问题。
发明内容
本公开实施例提供一种内存管理方法、计算机设备及存储介质。
第一方面,本公开实施例提供一种内存管理方法,包括:接收内存分配请求;在内存分配请求执行失败后,记录内存操作系统的行为信息;基于行为信息,确定待调整的内存配置参数的调节参数,其中,待调整的内存配置参数与行为信息存在对应关系;根据调节参数,对内存配置参数进行调整。
第二方面,本公开实施例还提供一种计算机设备,计算机设备包括处理器、存储器、存储在存储器上并可被处理器执行的计算机程序以及用于实现处理器和存储器之间的连接通信的数据总线,其中所述计算机程序被处理器执行时,实现如本公开实施例提供的任一项内存管理方法。
第三方面,本公开实施例还提供一种存储介质,用于计算机可读存储,存储介质存储有一个或者多个程序,一个或者多个程序可被一个或者多个处理器执行,以实现如本公开实施例提供的任一项内存管理方法。
附图说明
图1为本公开实施例提供的一种内存管理方法的步骤流程示意图;
图2为本公开实施例提供的行为信息的一示意图;
图3为本公开实施例提供的内存配置参数的一示意图;
图4为本公开实施例提供的另一种内存管理方法的步骤流程示意图;以及
图5为本公开实施例提供的一种计算机设备的结构示意框图。
具体实施方式
下面将结合本公开实施例中的附图,对本公开实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。
附图中所示的流程图仅是示例说明,不是必须包括所有的内容和操作/步骤,也不是必须按所描述的顺序执行。例如,有的操作/步骤还可以分解、组合或部分合并,因此实际执行的顺序有可能根据实际情况改变。
应当理解,在此本公开说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本公开。如在本公开说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。
为了降低内存压力,目前已经存在的内存配置参数的自动调优方案中,使用随机化的方式组成内存配置参数集合,测试每组参数组合的系统性能并最终选取最优解。但现代操作系统的运行参数数量巨大,性能测试需较长时间,所以这种随机测试的方法不容易找到一组最优参数配置组合,会导致内存配置参数难以收敛,不仅耗费时间长且效率较低。同时,随机参数调优法与具体业务负载或场景绑定,调优的内存配置参数难以动态适应不同的业务负载或场景,灵活性较差。
本公开实施例提供一种内存管理方法、计算机设备及存储介质。其中,该内存管理方法 可应用于计算机设备中,计算机设备包括服务器和终端设备。其中,服务器可以为单台的服务器或者多台服务器组成的服务器集群,该终端设备可以为手机、平板电脑、笔记本电脑、台式电脑、个人数字助理和穿戴式设备等电子设备。
下面结合附图,对本公开的一些实施方式作详细说明。在不冲突的情况下,下述的实施例及实施例中的特征可以相互组合。
请参照图1,图1为本公开实施例提供的一种内存管理方法的步骤流程示意图。
如图1所示,该内存管理方法包括步骤S101至步骤S104。
步骤S101、接收内存分配请求。
其中,内存分配请求用于请求进行内存分配,内存分配是指在程序执行的过程中分配或者回收存储空间的内存,包括静态内存分配和动态内存分配。
需要说明的是,计算机设备运行过程中,与程序运行相关的数据可以暂时存放在内存中,等待处理器调用。计算机设备需要对内存进行管理,例如在接收内存分配请求之后,根据内存分配请求为进程分配内存。
在一示例性实施例中,计算机设备可以通过内存操作系统执行内存分配请求。内存操作系统在执行内存分配请求时,若内存资源不足,则可能需要等待一段时间才能完成内存分配请求。内存操作系统收到内存分配请求之后到完成内存分配请求的时间间隔,可以称为内存压力。时间间隔越大,表明系统内存压力越大。
步骤S102、在内存分配请求执行失败后,记录内存操作系统的行为信息。
需要说明的是,计算机设备可以监控内存操作系统处理内存分配的流程,从而确定内存分配请求执行成功或者执行失败。对于执行失败的内存分配请求,计算机设备可以记录内存操作系统的行为信息,从而便于分析内存操作系统无法满足内存分配请求的原因。
其中,行为信息包括内存回收、内存压缩和页缓存颠簸限制。需要说明的是,内存回收指的是对用户空间中的堆段和文件映射段进行回收的行为,可被回收的内存类型包括文件页(File-backed Page)和匿名页(Anonymous Page)。内存压缩是指对内存进行压缩的行为,当内存操作系统觉察到内存不够用时,它会将无用的内存进行压缩,并放在物理内存上,而不再是将它们写入硬盘(虚拟内存)。例如,内存操作系统对不常用的后台应用程序的内存进行压缩,能够扩大可用内存。
需要说明的是,页缓存颠簸限制是指对页缓存颠簸进行限制甚至消除的行为,颠簸问题又称抖动问题,页缓存颠簸的产生的原因有多种因素。例如,分配给一个进程的内存物理页 面数太少,会造成进程在运行过程中频繁地发生缺页中断而产生颠簸。因此,当内存操作系统发现页缓存颠簸问题时,可以根据其出现具体原因对页缓存颠簸进行消除。
在一示例性实施例中,如图2所示,行为信息包括后台内存回收11、后台内存压缩12、前台内存回收13、前台内存压缩14、容器内存回收15、页缓存颠簸限制16中的至少一种。需要说明的是,内存回收包括后台内存回收11、前台内存回收13和容器内存回收15,内存压缩包括后台内存压缩12和前台内存压缩14。在内存分配请求执行失败后,记录内存操作系统的行为信息可以是上述的其中一项,也可以是其中多项,本实施例对此不做具体限定。
需要说明的是,后台内存回收11(kswapd)是指在物理内存紧张的时候,会唤醒内核线程来回收内存,这个回收内存的过程是异步的,不会阻塞进程的执行。前台内存回收13又称直接内存回收(direct reclaim),如果后台异步回收跟不上进程内存申请的速度,就会开始直接内存回收,这个回收内存的过程是同步的,会阻塞进程的执行。容器内存回收15可以称为前台容器内存回收,如果直接内存回收后,空闲的物理内存仍然无法满足此次物理内存的申请,那么内核就会触发容器内存回收,例如根据算法选择一个占用物理内存较高的进程,然后将其停止,释放内存资源。后台内存压缩12和前台内存压缩14的区别在于,后台内存压缩12的过程是异步的,不会阻塞进程的执行。前台内存压缩14的过程是同步的,会阻塞进程的执行。
在一示例性实施例中,内存分配请求执行失败的判断方式,包括:监测执行内存分配请求时等待内存响应的时间;在内存响应时间大于或等于预设响应时间时,判断内存分配请求执行失败。需要说明的是,等待内存响应的时间可以为内存操作系统收到内存分配请求之后开始计时,预设响应时间可以根据实际情况进行设置,例如为5秒。该等待内存响应的时间也可以称为内存压力,等待内存响应的时间越长则表明内存操作系统的内存压力越大。在内存响应时间大于或等于预设响应时间时,确定内存分配请求执行失败。对于内存分配失败并产生内存分配延迟的请求,计算机设备可以分析系统无法满足内存分配请求的原因,并生成相关数据。
步骤S103、基于行为信息,确定待调整的内存配置参数的调节参数。
其中,待调整的内存配置参数与行为信息存在对应关系。也就是说,待调整的内存配置参数根据行为信息和该对应关系确定的。需要说明的是,内存操作系统的行为信息是在无法满足内存分配请求的基础上进行的,因此内存操作系统的行为信息能够反映内存分配的相关问题。基于内存操作系统的行为信息能够准确的确定待调整的内存配置参数,以及如何准确的调节内存配置参数,得到内存配置参数的调节参数,从而降低内存压力。
在一示例性实施例中,基于行为信息,确定待调整的内存配置参数的调节参数之前,还包括:获取内存操作系统的行为信息的记录数量;在记录数量大于或等于预设记录数量时,执行基于行为信息确定待调整的内存配置参数的调节参数的步骤。
其中,预设记录数量间可以根据实际情况进行设置,例如为5个。需要说明的是,为了保证内存操作系统的内存压力的评估准确性,可以在内存操作系统的行为信息的记录数量大于或等于预设记录数量时,再执行基于行为信息确定待调整的内存配置参数的调节参数以及之后的步骤。
在一示例性实施例中,计算机设备包括系统性能监控服务平台MEMD,在内存操作系统的行为信息的记录数量大于或等于预设记录数量时,将内存操作系统的多个行为信息发送至系统性能监控服务平台MEMD,以供系统性能监控服务平台MEMD执行基于行为信息确定待调整的内存配置参数的调节参数以及之后的步骤。
在一示例性实施例中,内存配置参数包括内存水线、主动内存压缩指令、内存交换指令、内存碎片压缩门限、容器内存配额、页缓存负载比例中的至少一种。需要说明的是,计算机设备的每个内存区域存在三条内存水线,包括高水线(High Water Marker)、低水线(Low Water Marker)和最低水线(Min Water Marker)。若内存区域的空闲缓存页数大于高水线,表示内存充足;若内存区域的空闲缓存页数小于低水线,表示内存轻微不足;若内存区域的空闲缓存页数小于最低水线,表示内存严重不足。最低水线以下的内存是“紧急保留内存”,只有在内存严重不足的情况下,才会分配给特定进程,这些进程的必须承诺“分配少量内存,释放更多内存”。
需要说明的是,主动内存压缩指令用于指示内存操作系统开启主动内存压缩,例如zSwap、zRAM、zCache等,从而节省内存。内存交换指令用于指示内存操作系统开启内存交换,例如把某些进程的一些暂时用不到的内存页保存到磁盘中,然后把物理内存页分配给更紧急的业务使用,当进程用到时再从磁盘读回到内存中即可。内存碎片压缩门限用于调节后台压缩任务的执行频率,当内存碎片达到内存碎片压缩门限时,内存操作系统可以启动后台压缩任务。容器可用内存包括两个部分:物理内存和Swap交换分区,容器内存配额用于控制容器的Swap大小、可用内存大小等各种内存方面的控制,例如容器内存配额包括内存互换(memory-swappiness)参数、内核内存(kernel-memory)参数、内存(memory)参数、内存预留(memory-reservation)参数等,其中内存互换参数用于控制进程将物理内存交换到Swap分区的倾向,默认系数为60,系数越小,就越倾向于使用物理内存。页缓存负载比例用于表征页缓存的配额比例,页缓存负载比例越大则页缓存的配额比例越大。
在一示例性实施例中,内存配置参数与行为信息之间的对应关系,包括:内存水线与后台内存回收相对应,主动内存压缩指令与后台内存压缩相对应;内存交换指令与前台内存回收相对应,内存碎片压缩门限与前台内存压缩相对应;容器内存配额与容器内存回收相对应,页缓存负载比例与页缓存颠簸限制相对应。
在一示例性实施例中,如图2和图3所示,行为信息包括后台内存回收11、后台内存压缩12、前台内存回收13、前台内存压缩14、容器内存回收15、页缓存颠簸限制16中的至少一种,内存配置参数包括内存水线21、主动内存压缩指令22、内存交换指令23、内存碎片压缩门限24、容器内存配额25、页缓存负载比例26中的至少一种。内存配置参数与行为信息存在对应关系:如,内存水线21与后台内存回收11相对应,主动内存压缩指令22与后台内存压缩12相对应;内存交换指令23与前台内存回收13相对应,内存碎片压缩门限24与前台内存压缩14相对应;容器内存配额25与容器内存回收15相对应,页缓存负载比例26与页缓存颠簸限制16相对应。
需要说明的是,内存操作系统的行为信息能够反映内存分配的相关问题,通过内存配置参数与行为信息之间的对应关系,能够准确的确定待调整的内存配置参数的调节参数,该调节参数可以为更新的内存配置参数或者内存配置参数的调节变化量。
在一示例性实施例中,在行为信息包括后台内存回收时,调节参数用于增加内存水线中低水线与最低水线之间的差值;在行为信息包括后台内存压缩时,调节参数用于生成主动内存压缩指令;在行为信息包括前台内存回收时,调节参数用于生成内存交换指令;在行为信息包括前台内存压缩时,调节参数用于降低内存碎片压缩门限;在行为信息包括容器内存回收时,调节参数用于增加容器内存配额;在行为信息包括页缓存颠簸限制时,调节参数用于增加页缓存负载比例。
需要说明的是,在内存操作系统的行为信息包括后台内存回收时,对应的内存配置参数为内存水线,内存配置参数的调节参数用于增加内存水线中低水线与最低水线之间的差值,从而能够更频繁的唤醒后台回收任务,降低内存压力。在内存操作系统的行为信息包括后台内存压缩时,对应的内存配置参数为内存压缩指令,内存配置参数的调节参数用于生成主动内存压缩指令,从而节省内存空间。在内存操作系统的行为信息包括前台内存回收时,对应的内存配置参数为内存交换指令,内存配置参数的调节参数用于启动内存交换任务,把某些进程的一些暂时用不到的内存页保存到磁盘中,然后把物理内存页分配给更紧急的业务使用,降低内存压力。
需要说明的是,在内存操作系统的行为信息包括前台内存压缩时,对应的内存配置参数 为内存碎片压缩门限,内存配置参数的调节参数用于降低内存碎片压缩门限,从而增加后台压缩任务的执行频率,降低内存压力。在内存操作系统的行为信息包括容器内存回收时,对应的内存配置参数为容器内存配额,内存配置参数的调节参数用于增加容器内存配额,从而减少容器内存回收,能够使用更多内存。在内存操作系统的行为信息包括页缓存颠簸限制时,对应的内存配置参数为页缓存负载比例,内存配置参数的调节参数用于增加页缓存负载比例,增加页缓存的配额比例,提高内存资源利用率。
步骤S104、根据调节参数,对内存配置参数进行调整。
其中,调节参数可以为更新的内存配置参数或者内存配置参数的调节变化量。需要说明的是,根据调节参数针对性的对内存配置参数进行调整,能够实现内存配置参数的快速收敛,提高内存配置参数的调整效率,从而能够降低内存压力,有利于优化系统内存管理、分配方式,以降低内存分配延迟。并且,本公开实施例可以针对不同的系统负载和场景进行内存配置参数的调整,灵活性较好。
在一示例性实施例中,基于行为信息,确定待调整的内存配置参数;获取行为信息对应的行为持续时间;基于行为持续时间,确定内存配置参数的调节变化量作为调节参数。其中,调节参数包括内存配置参数的调节变化量。需要说明的是,行为信息对应的行为持续时间可以是与内存配置参数的调节变化量呈正比或者反比的,正比或者反比的关系需要根据具体行为信息确定。
例如,内存操作系统的行为信息包括前台内存压缩,内存配置参数的调节参数用于降低内存碎片压缩门限,则内存碎片压缩门限为负值,行为持续时间与内存配置参数的调节变化量呈反比关系,即前台内存压缩对应的行为持续时间越长,则用于调节内存碎片压缩门限的降低量越大。
又例如,内存操作系统的行为信息包括页缓存颠簸限制,内存配置参数的调节参数用于增加页缓存负载比例,则行为持续时间与内存配置参数的调节变化量呈正比关系,即页缓存颠簸限制对应的行为持续时间越长,则用于调节页缓存负载比例的增量越大。
在一示例性实施例中,根据调节参数,对内存配置参数进行调整之后,还包括:接收新的内存分配请求,并确定新的内存分配请求是否执行失败;在新的内存分配请求执行失败后,从内存的多个待执行业务中确定预设数量个低优先级的目标业务;迁移或停止执行目标业务。其中,待执行业务的优先级可以根据实际情况确定,例如将可重启业务或者不紧要业务的优先级确定为低优先级。需要说明的是,根据调节参数对内存配置参数进行调整之后,如果无法使内存压力降低到阈值以下,新的内存分配请求容易执行失败,因此可以关闭或者迁移部 分服务,最终使内存压力降低到阈值以下,提高内存管理的可靠性,减少由于内存资源竞争而导致的系统延迟,能够提升系统吞吐量。
上述实施例提供的内存管理方法,通过接收内存分配请求,并在内存分配请求执行失败后,记录内存操作系统的行为信息;基于行为信息,确定待调整的内存配置参数的调节参数,其中,待调整的内存配置参数与行为信息存在对应关系;根据调节参数,对内存配置参数进行调整。本公开实施例能够根据内存操作系统行为,针对性的调整内存配置参数,能够适应不同的业务场景,并能提高内存配置参数的调整效率,实现内存配置参数的快速收敛,从而能够降低内存压力,提高内存资源利用率。
请参照图4,图4为本公开实施例提供的另一种内存管理方法的步骤流程示意图。
如图4所示,该内存管理方法包括步骤S201至S206。
步骤S201、接收内存分配请求。
内存分配请求用于请求进行内存分配,计算机设备运行过程中,可以通过内存操作系统接收内存分配请求。内存操作系统收到内存分配请求之后到完成内存分配请求的时间间隔,可以称为内存压力。时间间隔越大,表明系统内存压力越大。
步骤S202、在内存分配请求执行失败后,记录内存操作系统的行为信息。
其中,内存分配请求可以执行成功或者执行失败,例如当内存操作系统的内存压力超过预设压力阈值(预设响应时间)时,判定内存分配请求执行失败。对于执行失败的内存分配请求,计算机设备可以记录内存操作系统的行为信息,从而便于分析内存操作系统无法满足内存分配请求的原因。
在一示例性实施例中,当分配延迟的压力大于预设压力阈值时,唤醒系统性能监控服务MEMD,MEMD读取系统的内存状态报告,得到内存操作系统的行为信息。其中,行为信息包括内存回收、内存压缩和页缓存颠簸限制。
步骤S203、基于行为信息,确定待调整的内存配置参数。
其中,待调整的内存配置参数与行为信息存在对应关系。例如,行为信息包括后台内存回收、后台内存压缩、前台内存回收、前台内存压缩、容器内存回收、页缓存颠簸限制中的至少一种。内存配置参数包括内存水线、主动内存压缩指令、内存交换指令、内存碎片压缩门限、容器内存配额、页缓存负载比例中的至少一种。
在一示例性实施例中,在内存操作系统的行为信息包括后台内存回收时,对应的内存配置参数为内存水线;在内存操作系统的行为信息包括后台内存压缩时,对应的内存配置参数 为内存压缩指令;在内存操作系统的行为信息包括前台内存回收时,对应的内存配置参数为内存交换指令;在内存操作系统的行为信息包括前台内存压缩时,对应的内存配置参数为内存碎片压缩门限;在内存操作系统的行为信息包括容器内存回收时,对应的内存配置参数为容器内存配额;在内存操作系统的行为信息包括页缓存颠簸限制时,对应的内存配置参数为页缓存负载比例。
步骤S204、获取行为信息对应的行为持续时间。
在内存操作系统无法满足内存分配请求时,内存操作系统的行为信息能够反映内存分配的相关问题,行为信息对应的行为持续时间能够反映内存分配的相关问题的严重程度。
在一实施例中,行为持续时间可以是在记录内存操作系统的行为信息时一同记录的。或者,行为持续时间记录于行为信息中,例如在内存分配请求执行失败后,记录某项或者多项行为的完成时间,将行为和持续时间生成key-value对应条目,得到行为信息对应的行为持续时间。
步骤S205、基于行为持续时间对内存配置参数进行调节,得到更新的内存配置参数作为调节参数。
需要说明的是,行为信息对应的行为持续时间可以是与更新的内存配置参数呈正比或者反比的,正比或者反比的关系需要根据具体行为信息确定。
例如,内存操作系统的行为信息包括前台内存压缩,内存配置参数的调节参数用于降低内存碎片压缩门限,则内存碎片压缩门限为负值,行为持续时间与更新的内存配置参数呈反比关系,即前台内存压缩对应的行为持续时间越长,则更新的内存配置参数越小。
又例如,内存操作系统的行为信息包括页缓存颠簸限制,内存配置参数的调节参数用于增加页缓存负载比例,则行为持续时间与更新的内存配置参数呈正比关系,即页缓存颠簸限制对应的行为持续时间越长,则更新的内存配置参数越大。
步骤S206、根据调节参数,对内存配置参数进行调整。
需要说明的是,当内存配置参数的调节参数为更新的内存配置参数,在对内存配置参数进行调整时,将更新的内存配置参数替换当前的内存配置参数即可。通过针对性的调整内存配置参数,能够适应不同的业务场景,并能提高内存配置参数的调整效率,实现内存配置参数的快速收敛,从而能够降低内存压力,提高内存资源利用率。
在一示例性实施例中,根据调节参数,对内存配置参数进行调整之后,获取执行失败的内存分配请求;重新执行该内存分配请求,并确定新的内存分配请求是否执行失败;在新的 内存分配请求执行失败后,从内存的多个待执行业务中确定预设数量个低优先级的目标业务;迁移或停止执行目标业务。通过上述方式,能够减少由于内存资源竞争而导致的系统延迟,能够提升系统吞吐量。
本公开实施例的重点在于,在内存分配请求执行失败后,记录内存操作系统的行为信息,从而便于对造成内存分配失败的内存配置参数进行分析,找出系统内存压力产生的原因,从而针对性的调整内存配置参数,达到快速收敛出最佳系统参数的目的。
上述实施例提供的内存管理方法,通过接收内存分配请求,并在内存分配请求执行失败后,记录内存操作系统的行为信息;基于行为信息,确定待调整的内存配置参数,获取行为信息对应的行为持续时间,基于行为持续时间对内存配置参数进行调节,得到更新的内存配置参数作为调节参数;根据调节参数,对内存配置参数进行调整。本公开实施例能够根据内存操作系统行为,针对性的调整内存配置参数,能够适应不同的业务场景,并能提高内存配置参数的调整效率,实现内存配置参数的快速收敛,从而能够降低内存压力,提高内存资源利用率。
请参阅图5,图5为本公开实施例提供的一种计算机设备的结构示意性框图。
如图5所示,计算机设备300包括处理器301和存储器302,处理器301和存储器302通过总线303连接,该总线比如为I2C(Inter-integrated Circuit)总线。计算机设备300可以为服务器或终端设备。
在一示例性实施例中,处理器301用于提供计算和控制能力,支撑整个计算机设备的运行。处理器301可以是中央处理单元(Central Processing Unit,CPU),该处理器301还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
在一示例性实施例中,存储器302可以是Flash芯片、只读存储器(ROM,Read-Only Memory)磁盘、光盘、U盘或移动硬盘等。
本领域技术人员可以理解,图5中示出的结构,仅仅是与本公开实施例相关的部分结构的框图,并不构成对本公开实施例所应用于其上的计算机设备300的限定,具体的计算机设备300可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
其中,处理器用于运行存储在存储器中的计算机程序,并在执行计算机程序时实现本公开实施例提供的任意一种的内存管理方法。
在一示例性实施例中,处理器用于运行存储在存储器中的计算机程序,并在执行计算机程序时实现如下步骤:接收内存分配请求;在内存分配请求执行失败后,记录内存操作系统的行为信息;基于行为信息,确定待调整的内存配置参数的调节参数,其中,待调整的内存配置参数与行为信息存在对应关系;根据调节参数,对内存配置参数进行调整。
在一示例性实施例中,处理器在实现内存分配请求执行失败的判断时,用于实现:监测执行内存分配请求时等待内存响应的时间;在内存响应时间大于或等于预设响应时间时,判断内存分配请求执行失败。
在一示例性实施例中,行为信息包括后台内存回收、后台内存压缩、前台内存回收、前台内存压缩、容器内存回收、页缓存颠簸限制中的至少一种;内存配置参数包括内存水线、主动内存压缩指令、内存交换指令、内存碎片压缩门限、容器内存配额、页缓存负载比例中的至少一种。
在一示例性实施例中,内存配置参数与行为信息之间的对应关系,包括:内存水线与后台内存回收相对应,主动内存压缩指令与后台内存压缩相对应;内存交换指令与前台内存回收相对应,内存碎片压缩门限与前台内存压缩相对应;容器内存配额与容器内存回收相对应,页缓存负载比例与页缓存颠簸限制相对应。
在一示例性实施例中,在行为信息包括后台内存回收时,调节参数用于增加内存水线中低水线与最低水线之间的差值;在行为信息包括后台内存压缩时,调节参数用于生成主动内存压缩指令;在行为信息包括前台内存回收时,调节参数用于生成内存交换指令;在行为信息包括前台内存压缩时,调节参数用于降低内存碎片压缩门限;在行为信息包括容器内存回收时,调节参数用于增加容器内存配额;在行为信息包括页缓存颠簸限制时,调节参数用于增加页缓存负载比例。
在一示例性实施例中,处理器在实现基于行为信息,确定待调整的内存配置参数的调节参数之前,还用于实现:获取内存操作系统的行为信息的记录数量;在记录数量大于或等于预设记录数量时,执行基于行为信息确定待调整的内存配置参数的调节参数的步骤。
在一示例性实施例中,处理器在实现基于行为信息,确定待调整的内存配置参数的调节参数时,用于实现:基于行为信息,确定待调整的内存配置参数;获取行为信息对应的行为持续时间;基于行为持续时间对内存配置参数进行调节,得到更新的内存配置参数作为调节参数。
在一示例性实施例中,处理器在实现根据调节参数,对内存配置参数进行调整之后,还用于实现:接收新的内存分配请求,并确定新的内存分配请求是否执行失败;在新的内存分配请求执行失败后,从内存的多个待执行业务中确定预设数量个低优先级的目标业务;迁移或停止执行目标业务。
需要说明的是,所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的计算机设备的具体工作过程,可以参考前述内存管理方法实施例中的对应过程,在此不再赘述。
本公开实施例还提供一种存储介质,用于计算机可读存储,存储介质存储有一个或者多个程序,一个或者多个程序可被一个或者多个处理器执行,以实现如本公开实施例提供的任一项内存管理方法。
其中,所述存储介质可以是前述实施例所述的计算机设备的内部存储单元,例如所述计算机设备的硬盘或内存。所述存储介质也可以是所述计算机设备的外部存储设备,例如所述计算机设备上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。
本领域普通技术人员可以理解,上文中所公开方法中的全部或某些步骤、系统、装置中的功能模块/单元可以被实施为软件、固件、硬件及其适当的组合。在硬件实施方式中,在以上描述中提及的功能模块/单元之间的划分不一定对应于物理组件的划分;例如,一个物理组件可以具有多个功能,或者一个功能或步骤可以由若干物理组件合作执行。某些物理组件或所有物理组件可以被实施为由处理器,如中央处理器、数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质(或非暂时性介质)和通信介质(或暂时性介质)。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息(诸如计算机可读指令、数据结构、程序模块或其他数据)的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘(DVD)或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。
本公开实施例提供一种内存管理方法、计算机设备及存储介质,旨在提高内存配置参数 的调整效率,实现内存配置参数的快速收敛。本公开实施例提供一种内存管理方法、计算机设备及存储介质,本公开实施例通过接收内存分配请求,并在内存分配请求执行失败后,记录内存操作系统的行为信息;基于行为信息,确定待调整的内存配置参数的调节参数,其中,待调整的内存配置参数与行为信息存在对应关系;根据调节参数,对内存配置参数进行调整。本公开实施例能够根据内存操作系统行为,针对性的调整内存配置参数,能够适应不同的业务场景,并能提高内存配置参数的调整效率,实现内存配置参数的快速收敛,从而能够降低内存压力。
上述本公开实施例序号仅仅为了描述,不代表实施例的优劣。以上所述,仅为本公开的具体实施方式,但本公开的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本公开揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本公开的保护范围之内。因此,本公开的保护范围应以权利要求的保护范围为准。

Claims (10)

  1. 一种内存管理方法,包括:
    接收内存分配请求;
    在所述内存分配请求执行失败后,记录内存操作系统的行为信息;
    基于所述行为信息,确定待调整的内存配置参数的调节参数,其中,待调整的内存配置参数与所述行为信息存在对应关系;
    根据所述调节参数,对所述内存配置参数进行调整。
  2. 根据权利要求1所述的内存管理方法,其中,所述内存分配请求执行失败的判断方式,包括:
    监测执行所述内存分配请求时等待内存响应的时间;
    在内存响应时间大于或等于预设响应时间时,判断所述内存分配请求执行失败。
  3. 根据权利要求1所述的内存管理方法,其中,所述行为信息包括后台内存回收、后台内存压缩、前台内存回收、前台内存压缩、容器内存回收、页缓存颠簸限制中的至少一种;
    所述内存配置参数包括内存水线、主动内存压缩指令、内存交换指令、内存碎片压缩门限、容器内存配额、页缓存负载比例中的至少一种。
  4. 根据权利要求3所述的内存管理方法,其中,所述内存配置参数与所述行为信息之间的对应关系,包括:
    所述内存水线与所述后台内存回收相对应,所述主动内存压缩指令与所述后台内存压缩相对应;
    所述内存交换指令与所述前台内存回收相对应,所述内存碎片压缩门限与所述前台内存压缩相对应;
    所述容器内存配额与所述容器内存回收相对应,所述页缓存负载比例与所述页缓存颠簸限制相对应。
  5. 根据权利要求4所述的内存管理方法,其中,
    在所述行为信息包括后台内存回收时,所述调节参数用于增加所述内存水线中低水线与最低水线之间的差值;
    在所述行为信息包括后台内存压缩时,所述调节参数用于生成所述主动内存压缩指令;
    在所述行为信息包括前台内存回收时,所述调节参数用于生成所述内存交换指令;
    在所述行为信息包括前台内存压缩时,所述调节参数用于降低所述内存碎片压缩门限;
    在所述行为信息包括容器内存回收时,所述调节参数用于增加所述容器内存配额;
    在所述行为信息包括页缓存颠簸限制时,所述调节参数用于增加所述页缓存负载比例。
  6. 根据权利要求1所述的内存管理方法,其中,所述基于所述行为信息,确定待调整的内存配置参数的调节参数之前,还包括:
    获取所述内存操作系统的行为信息的记录数量;
    在所述记录数量大于或等于预设记录数量时,执行所述基于所述行为信息确定待调整的内存配置参数的调节参数的步骤。
  7. 根据权利要求1-6中任一项所述的内存管理方法,其中,所述基于所述行为信息,确定待调整的内存配置参数的调节参数,包括:
    基于所述行为信息,确定待调整的内存配置参数;
    获取所述行为信息对应的行为持续时间;
    基于所述行为持续时间对所述内存配置参数进行调节,得到更新的内存配置参数作为所述调节参数。
  8. 根据权利要求1-6中任一项所述的内存管理方法,其中,所述根据所述调节参数,对所述内存配置参数进行调整之后,还包括:
    接收新的内存分配请求,并确定新的所述内存分配请求是否执行失败;
    在新的所述内存分配请求执行失败后,从内存的多个待执行业务中确定预设数量个低优先级的目标业务;
    迁移或停止执行所述目标业务。
  9. 一种计算机设备,包括处理器、存储器、存储在所述存储器上并可被所述处理器执行的计算机程序以及用于实现所述处理器和所述存储器之间的连接通信的数据总线,其中所述计算机程序被所述处理器执行时,实现如权利要求1至8中任一项所述的内存管理方法的步骤。
  10. 一种存储介质,用于计算机可读存储,所述存储介质存储有一个或者多个程序,所述一个或者多个程序可被一个或者多个处理器执行,以实现权利要求1至8中任一项所述的内存管理方法的步骤。
PCT/CN2023/104847 2022-11-22 2023-06-30 内存管理方法、计算机设备及存储介质 WO2024109076A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211467176.9A CN118093150A (zh) 2022-11-22 2022-11-22 内存管理方法、计算机设备及存储介质
CN202211467176.9 2022-11-22

Publications (1)

Publication Number Publication Date
WO2024109076A1 true WO2024109076A1 (zh) 2024-05-30

Family

ID=91144614

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/104847 WO2024109076A1 (zh) 2022-11-22 2023-06-30 内存管理方法、计算机设备及存储介质

Country Status (2)

Country Link
CN (1) CN118093150A (zh)
WO (1) WO2024109076A1 (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130326166A1 (en) * 2012-05-31 2013-12-05 Apple Inc. Adaptive resource management of a data processing system
CN110532197A (zh) * 2019-08-30 2019-12-03 Oppo(重庆)智能科技有限公司 内存回收方法及装置、电子设备、存储介质
CN110764906A (zh) * 2019-09-27 2020-02-07 Oppo(重庆)智能科技有限公司 内存回收处理方法、装置、电子设备以及存储介质
CN114168065A (zh) * 2020-09-10 2022-03-11 荣耀终端有限公司 调整内存配置参数的方法和装置

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130326166A1 (en) * 2012-05-31 2013-12-05 Apple Inc. Adaptive resource management of a data processing system
CN110532197A (zh) * 2019-08-30 2019-12-03 Oppo(重庆)智能科技有限公司 内存回收方法及装置、电子设备、存储介质
CN110764906A (zh) * 2019-09-27 2020-02-07 Oppo(重庆)智能科技有限公司 内存回收处理方法、装置、电子设备以及存储介质
CN114168065A (zh) * 2020-09-10 2022-03-11 荣耀终端有限公司 调整内存配置参数的方法和装置

Also Published As

Publication number Publication date
CN118093150A (zh) 2024-05-28

Similar Documents

Publication Publication Date Title
US11531625B2 (en) Memory management method and apparatus
US10901802B2 (en) Method and apparatus for implementing virtual GPU and system
US11106579B2 (en) System and method to manage and share managed runtime memory for java virtual machine
US11340803B2 (en) Method for configuring resources, electronic device and computer program product
US20150161056A1 (en) Tracking guest memory characteristics for memory scheduling
US20090043873A1 (en) Methods and Apparatus for Restoring a Node State
CN111782148B (zh) 数据存储控制方法和装置、以及电子设备和存储介质
CN110196770B (zh) 云系统内存数据处理方法、装置、设备及存储介质
WO2011097884A1 (zh) 内存分配方法及装置
US11360884B2 (en) Reserved memory in memory management system
WO2016127291A1 (zh) 内存管理装置和方法
CN105574141B (zh) 一种对数据库进行数据迁移的方法和装置
US11886743B2 (en) Method for enhancing quality of service of solid-state drive and solid-state drive
WO2022001136A1 (zh) 分布式存储系统Inode号分配管理方法及相关组件
US10877790B2 (en) Information processing apparatus, control method and storage medium
US20220253252A1 (en) Data processing method and apparatus
WO2024109076A1 (zh) 内存管理方法、计算机设备及存储介质
EP2757481B1 (en) Caching method and caching system using dual disks
US20230100110A1 (en) Computing resource management method, electronic equipment and program product
US20240086086A1 (en) Ssd performance per power state improvement by deterministic utilization control
CN111090627B (zh) 基于池化的日志存储方法、装置、计算机设备及存储介质
CN109753363B (zh) 一种嵌入式系统内存管理方法及装置
US10324752B2 (en) Response times based on application states
CN111752851B (zh) 一种内存回收方法及装置
US9940053B2 (en) Information processing device, information processing system, memory management method, and program recording medium