CN116841723A - Memory management method, device, equipment and computer readable storage medium - Google Patents

Memory management method, device, equipment and computer readable storage medium Download PDF

Info

Publication number
CN116841723A
CN116841723A CN202210306918.3A CN202210306918A CN116841723A CN 116841723 A CN116841723 A CN 116841723A CN 202210306918 A CN202210306918 A CN 202210306918A CN 116841723 A CN116841723 A CN 116841723A
Authority
CN
China
Prior art keywords
memory
service process
step length
consumption
target
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202210306918.3A
Other languages
Chinese (zh)
Inventor
廖阿敏
王�义
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202210306918.3A priority Critical patent/CN116841723A/en
Publication of CN116841723A publication Critical patent/CN116841723A/en
Pending legal-status Critical Current

Links

Classifications

    • 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]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • 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]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application provides a memory management method, a device, equipment and a computer readable storage medium; the method comprises the following steps: determining at least one service process which is running by the target equipment, and determining a memory recovery step length corresponding to each service process, wherein the memory recovery step length is used for representing the size of a released memory space when memory recovery operation is executed on the service process; acquiring a value of a resource parameter of the target device, wherein the resource parameter comprises at least one of a calculation resource parameter and a storage resource parameter; when the step length adjustment condition is determined to be satisfied based on the value of the resource parameter, the memory recovery step length of each service process is adjusted to obtain a target memory recovery step length corresponding to each service process; and executing memory reclamation operation based on the target memory reclamation step length aiming at each service process so as to release the memory space with the size corresponding to the target memory reclamation step length. The application can improve the release speed of the memory space and ensure the timeliness of releasing the memory space.

Description

Memory management method, device, equipment and computer readable storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, a computer readable storage medium, and a computer program product for managing a memory.
Background
Memory reclamation is a more common mechanism for computer devices because the size of the memory itself is limited. Memory reclamation is performed for two main reasons: the system needs to provide enough memory for a sudden incoming memory application at any time so that the use of cache and other related memory will not leave the rest of the system memory in a very small state for a long period of time. In addition, when an application larger than the idle memory arrives, the memory reclamation is triggered.
In the related art, the memory space is mostly recovered based on a fixed memory recovery step, so that the condition that the memory is not recovered timely often occurs, and the memory recovery efficiency is low.
Disclosure of Invention
The embodiment of the application provides a memory management method, a device, equipment, a computer readable storage medium and a computer program product, which can improve the release speed of a memory space and ensure the timeliness of releasing the memory space.
The technical scheme of the embodiment of the application is realized as follows:
the embodiment of the application provides a memory management method, which comprises the following steps:
determining at least one service process which is running by the target equipment, and determining a memory recovery step length corresponding to each service process, wherein the memory recovery step length is used for representing the size of a released memory space when memory recovery operation is executed on the service process;
acquiring a value of a resource parameter of the target device, wherein the resource parameter comprises at least one of a calculation resource parameter and a storage resource parameter;
when the step length adjustment condition is determined to be satisfied based on the value of the resource parameter, the memory recovery step length of each service process is adjusted, and a target memory recovery step length corresponding to each service process is obtained;
and executing the memory reclamation operation based on the target memory reclamation step length for each service process so as to release the memory space with the size corresponding to the target memory reclamation step length.
The embodiment of the application provides a memory management device, which comprises:
the system comprises a determining module, a memory recovery step length determining module and a memory recovery module, wherein the determining module is used for determining at least one service process of which the target device is running, determining the memory recovery step length corresponding to each service process, and representing the size of a released memory space when memory recovery operation is executed on the service process;
An acquisition module, configured to acquire a value of a resource parameter of the target device, where the resource parameter includes at least one of a computing resource parameter and a storage resource parameter;
the adjustment module is used for adjusting the memory recovery step length of each service process when the step length adjustment condition is met based on the value of the resource parameter, so as to obtain a target memory recovery step length corresponding to each service process;
and the reclaiming module is used for executing the memory reclaiming operation based on the target memory reclaiming step length aiming at each service process so as to release the memory space with the size corresponding to the target memory reclaiming step length.
In the above scheme, the determining module is further configured to obtain an increment of consumption of the memory space compared with the consumption of the memory space when the last memory recovery operation is completed;
and when the consumption increment reaches an increment threshold, determining the memory reclamation step length corresponding to each service process.
In the above scheme, the determining module is further configured to determine an acquisition period of the consumption increment;
and taking the time when the latest memory recycling operation is completed as a target time point, and acquiring the consumption increment of the memory space when the acquisition time point of the consumption increment is determined to be reached based on the acquisition period and the target time point.
In the above scheme, the determining module is further configured to obtain a trigger period of the memory reclamation operation;
and taking the time when the latest memory reclamation operation is completed as a target time point, and determining the memory reclamation step length corresponding to each service process when the trigger time point of the memory reclamation operation is determined to be reached based on the trigger period of the memory reclamation operation and the target time point.
In the above scheme, the determining module is further configured to determine service contents corresponding to the service processes respectively;
and determining the memory recovery step length corresponding to the corresponding service process based on the service content corresponding to each service process.
In the above solution, the adjusting module is further configured to obtain a usage threshold of the computing resource of the target device when the resource parameter includes the computing resource parameter and a value of the computing resource parameter is used to indicate the usage of the computing resource of the target device;
and when the value of the computing resource parameter indicates that the utilization rate of the computing resource of the target device does not reach the utilization rate threshold value, determining that the step length adjustment condition is satisfied.
In the above solution, the adjusting module is further configured to obtain a parameter threshold corresponding to the storage resource parameter when the resource parameter includes the storage resource parameter;
When the value of the storage resource parameter reaches the parameter threshold value, determining that a step length adjustment condition is satisfied;
wherein the storage resource parameter comprises at least one of: the increment of the consumption of the memory space, and the consumption of the memory space are compared with the consumption of the memory space when the last memory reclamation operation is completed.
In the above scheme, the adjusting module is further configured to obtain a value of an adjustment coefficient for adjusting a memory reclamation step length of each service process;
and adjusting the memory recovery step length of each service process based on the value of the adjustment coefficient to obtain a target memory recovery step length corresponding to each service process.
In the above scheme, the adjusting module is further configured to obtain an increment of consumption of the memory space compared with the consumption of the memory space when the last memory recycling operation is completed;
acquiring the basic consumption corresponding to each service process;
and determining the ratio between the consumption increment and each basic consumption, and taking the ratio as the value of an adjustment coefficient for adjusting the memory reclamation step length of the corresponding service process.
In the above scheme, the adjusting module is further configured to obtain an increment of consumption of the memory space compared with the consumption of the memory space when the last memory recycling operation is completed;
Acquiring the priority of each service process;
and determining the value of an adjustment coefficient for adjusting the memory reclamation step length of each service process based on the consumption increment and each priority.
In the above scheme, when the adjustment coefficients and the service processes are in a one-to-one correspondence, the adjustment module is further configured to perform product processing on the values of the adjustment coefficients and the memory recovery step sizes of the corresponding service processes, so as to obtain product results corresponding to the service processes; or alternatively, the process may be performed,
when the number of the adjustment coefficients is one, carrying out product-seeking processing on the values of the adjustment coefficients and the memory recovery step length of each service process respectively to obtain product-seeking results corresponding to each service process;
and taking the product result as a target memory recovery step length corresponding to the service process.
In the above scheme, the reclamation module is further configured to execute the memory reclamation operation on the corresponding service process based on the memory reclamation step corresponding to each service process when the step adjustment condition is determined not to be satisfied based on the value of the resource parameter, so as to release the memory space with the size corresponding to the memory reclamation step.
An embodiment of the present application provides an electronic device, including:
a memory for storing executable instructions;
and the processor is used for realizing the memory management method provided by the embodiment of the application when executing the executable instructions stored in the memory.
The embodiment of the application provides a computer readable storage medium which stores executable instructions for realizing the memory management method provided by the embodiment of the application when being executed by a processor.
The embodiment of the application provides a computer program product, which comprises a computer program or instructions for causing a processor to execute the method for classifying objects based on a classification model.
The embodiment of the application has the following beneficial effects:
by applying the embodiment of the application, when the step length adjustment condition for each service process is determined to be satisfied based on the calculation resource parameter and the storage resource parameter of the target equipment, the memory recovery step length of each service process is dynamically adjusted, and the memory recovery operation is executed based on the adjusted target memory recovery step length, so that the memory space with the size corresponding to the target memory recovery step length is released. Therefore, the release speed of the memory space can be improved, and the timeliness of releasing the memory space is ensured.
Drawings
FIG. 1 is a schematic diagram of a memory management system according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of an electronic device implementing a memory management method according to an embodiment of the present application;
FIG. 3 is a flowchart illustrating a method for managing a memory according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a determining step adjustment condition provided by an embodiment of the present application;
FIG. 5 is a schematic diagram of a memory reclamation step size adjustment method according to an embodiment of the present application;
FIG. 6 is a schematic diagram of a mode of determining an adjustment coefficient according to an embodiment of the present application;
FIG. 7 is another schematic diagram of an adjustment coefficient determination method according to an embodiment of the present application;
FIG. 8 is a flowchart of a memory management method based on a fixed memory reclamation step size according to an embodiment of the present application;
FIG. 9 is a flowchart of a memory management method based on a dynamic memory reclamation step size according to an embodiment of the present application;
fig. 10A to 10D are schematic diagrams illustrating effect analysis of a memory management method in different scenarios according to an embodiment of the present application.
Detailed Description
The present application will be further described in detail with reference to the accompanying drawings, for the purpose of making the objects, technical solutions and advantages of the present application more apparent, and the described embodiments should not be construed as limiting the present application, and all other embodiments obtained by those skilled in the art without making any inventive effort are within the scope of the present application.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is to be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments and can be combined with one another without conflict.
If a similar description of "first/second" appears in the application document, the following description is added, in which the terms "first/second/third" are merely distinguishing between similar objects and not representing a particular ordering of the objects, it being understood that the "first/second/third" may be interchanged with a particular order or precedence, if allowed, so that embodiments of the application described herein may be practiced otherwise than as illustrated or described herein.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of the application only and is not intended to be limiting of the application.
Before describing embodiments of the present application in further detail, the terms and terminology involved in the embodiments of the present application will be described, and the terms and terminology involved in the embodiments of the present application will be used in the following explanation.
1) Memory (Memory): is an important component of electronic equipment, also called an internal memory and a main memory, and can be used for storing operation data in a central processing unit (CPU, central Processing Unit) and also can be used for storing data exchanged with an external memory such as a hard disk. All processes of the electronic equipment run in the memory, and the strength of the memory performance influences the overall running efficiency of the electronic equipment, so that the running efficiency of the processes and the electronic equipment can be improved by effectively managing the memory. In the embodiment of the present application, occupied memory refers to occupied memory space, and the occupied memory units include, but are not limited to, bytes (KB), megabytes (MB), gigabytes (GB), and Terabytes (TB).
2) Process (Process): the program in the electronic equipment refers to one running activity on a certain data set, is a basic unit for the operating system to allocate and schedule resources, and is also the basis of the operating system structure. In a sense, a process can be considered an instance of a running program. In the embodiment of the application, memory management can be performed on any process operated by the electronic device, and the functions of the process are not limited, for example, the process can be used for screen display, network connection, maintenance of software/hardware, maintenance of a firewall or operation of a virtual scene (such as a game virtual scene) and the like.
3) Garbage collection (GC, garbageCollection): garbage collection is an automatic storage management mechanism. When some occupied memory space is no longer needed, it should be freed to make room, and this storage resource management is called garbage collection (Garbage Collection), which may also be referred to as memory reclamation.
Based on the above explanation of terms and expressions involved in the embodiments of the present application, the memory management system provided by the embodiments of the present application is described below. Referring to fig. 1, fig. 1 is a schematic architecture diagram of a memory management system according to an embodiment of the present application, in order to implement a memory management application, in the memory management system 100, terminals (a terminal 400-1 and a terminal 400-2 are shown in an exemplary manner) are connected to a server 200 through a network 300, where the network 300 may be a wide area network or a local area network, or a combination of the two. Wherein the server 200 may belong to a target server cluster, and the target server cluster includes at least one of a server, a plurality of servers, a cloud computing platform, and a virtualization center. The server cluster may be used to provide background services for applications that support a three-dimensional virtual environment.
And the terminal is used for installing and running the client side with the target application, and responding to the starting operation of the user for the target application and sending a starting request for the target application to the server.
The server 200 is configured to start the target application after receiving a start request for the target application sent by the terminal, and determine at least one service process that the target device is running and a memory recovery step size corresponding to each service process, where the memory recovery step size is used to characterize a size of a memory space released when performing a memory recovery operation on the service process; acquiring a value of a resource parameter of the target device, wherein the resource parameter comprises at least one of a calculation resource parameter and a storage resource parameter; when the step length adjustment condition is determined to be satisfied based on the value of the resource parameter, the memory recovery step length of each service process is adjusted to obtain a target memory recovery step length corresponding to each service process; and executing memory reclamation operation based on the target memory reclamation step length aiming at each service process so as to release the memory space with the size corresponding to the target memory reclamation step length.
The server 200 is further configured to, when it is determined that the step adjustment condition is not satisfied based on the value of the resource parameter, perform a memory reclamation operation on the corresponding service process based on the memory reclamation step corresponding to each service process, so as to release the memory space with the size corresponding to the memory reclamation step.
In practical applications, the server 200 may be an independent physical server, or may be a server cluster or a distributed system formed by a plurality of physical servers, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs, content Delivery Network), and basic cloud computing services such as big data and artificial intelligence platforms. Terminals (e.g., terminal 400-1 and terminal 400-2) may be, but are not limited to, smart phones, tablet computers, notebook computers, desktop computers, smart speakers, smart televisions, smart watches, etc. Terminals, such as terminal 400-1 and terminal 400-2, and server 200 may be directly or indirectly connected through wired or wireless communication, and the present application is not limited thereto.
The embodiment of the application can also be realized by means of Cloud Technology (Cloud Technology), wherein the Cloud Technology refers to a hosting Technology for integrating serial resources such as hardware, software, network and the like in a wide area network or a local area network to realize calculation, storage, processing and sharing of data.
The cloud technology is a generic term of network technology, information technology, integration technology, management platform technology, application technology and the like based on cloud computing business model application, can form a resource pool, and is flexible and convenient as required. Cloud computing technology will become an important support. Background services of technical network systems require a large amount of computing and storage resources.
Referring to fig. 2, fig. 2 is a schematic structural diagram of an electronic device implementing a memory management method according to an embodiment of the present application, and in practical application, an electronic device 500 may be implemented as a server or a terminal in fig. 1, and an electronic device implementing a memory management method according to an embodiment of the present application is described. The electronic device 500 shown in fig. 2 includes: at least one processor 510, a memory 550, at least one network interface 520, and a user interface 530. The various components in electronic device 500 are coupled together by bus system 540. It is appreciated that bus system 540 is used to facilitate connected communications between these components. The bus system 540 includes a power bus, a control bus, and a status signal bus in addition to the data bus. The various buses are labeled as bus system 540 in fig. 2 for clarity of illustration.
The processor 510 may be an integrated circuit chip with signal processing capabilities such as a general purpose processor, such as a microprocessor or any conventional processor, or the like, a digital signal processor (DSP, digital Signal Processor), or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or the like.
The user interface 530 includes one or more output devices 531 that enable presentation of media content, including one or more speakers and/or one or more visual displays. The user interface 530 also includes one or more input devices 532, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
The memory 550 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid state memory, hard drives, optical drives, and the like. Memory 550 may optionally include one or more storage devices physically located remote from processor 510.
Memory 550 includes volatile memory or nonvolatile memory, and may also include both volatile and nonvolatile memory. The nonvolatile Memory may be a Read Only Memory (ROM), and the volatile Memory may be a random access Memory (RAM, random Access Memory). The memory 550 described in embodiments of the present application is intended to comprise any suitable type of memory.
In some embodiments, memory 550 is capable of storing data to support various operations, examples of which include programs, modules and data structures, or subsets or supersets thereof, as exemplified below.
An operating system 551 including system programs for handling various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and handling hardware-based tasks;
network communication module 552 is used to reach other computing devices via one or more (wired or wireless) network interfaces 520, exemplary network interfaces 520 include: bluetooth, wireless compatibility authentication (WiFi), and universal serial bus (USB, universal Serial Bus), etc.;
a presentation module 553 for enabling presentation of information (e.g., a user interface for operating a peripheral device and displaying content and information) via one or more output devices 531 (e.g., a display screen, speakers, etc.) associated with the user interface 530;
the input processing module 554 is configured to detect one or more user inputs or interactions from one of the one or more input devices 532 and translate the detected inputs or interactions.
In some embodiments, the memory management device provided in the embodiments of the present application may be implemented in a software manner, fig. 2 shows a schematic structural diagram of a server for providing management of memory by an electronic device provided in the embodiments of the present application, and the memory management device 555 stored in the memory 550 may be software in the form of a program, a plug-in, or the like, including the following software modules: the determining module 5551, the acquiring module 5552, the adjusting module 5553 and the recycling module 5554 are logical, so that any combination or further splitting may be performed according to the implemented functions. The functions of the respective modules will be described hereinafter.
In other embodiments, the memory management device provided in the embodiments of the present application may be implemented in hardware, and by way of example, the memory management device provided in the embodiments of the present application may be a processor in the form of a hardware decoding processor that is programmed to perform the memory management method provided in the embodiments of the present application, for example, the processor in the form of a hardware decoding processor may employ one or more application specific integrated circuits (ASIC, application Specific Integrated Circuit), DSP, programmable logic device (PLD, programmable Logic Device), complex programmable logic device (CPLD, complex Programmable Logic Device), field programmable gate array (FPGA, field-Programmable Gate Array), or other electronic components.
Based on the above description of the memory management system and the electronic device provided by the embodiments of the present application, the following describes a memory management method provided by the embodiments of the present application. In some embodiments, the memory management method provided by the embodiments of the present application may be implemented by a server or a terminal alone or cooperatively. In some embodiments, the terminal or the server may implement the memory management method provided by the embodiments of the present application by running a computer program. For example, the computer program may be a native program or a software module in an operating system; a Native Application (APP), i.e. a program that needs to be installed in an operating system to run, such as a client that supports virtual scenarios, such as a game APP; the method can also be an applet, namely a program which can be run only by being downloaded into a browser environment; but also an applet that can be embedded in any APP. In general, the computer programs described above may be any form of application, module or plug-in.
The following describes a memory management method provided by the embodiment of the present application by taking a server embodiment as an example. Referring to fig. 3, fig. 3 is a flowchart of a memory management method according to an embodiment of the present application, and will be described with reference to the steps shown in fig. 3.
In step 101, the server determines at least one service process that the target device is running, and determines a memory reclamation step size corresponding to each service process.
It should be noted that, the memory reclamation step length is used for characterizing the size of the released memory space when the memory reclamation operation is executed on the service process.
In practical implementation, the memory reclaiming operation may be a reclaiming module running a memory reclaiming program in the server. At least one target application may be run on the target device, and the server may detect at least one service process in an operational state in response to a start-up operation of each target application. Wherein the target application can be considered as a run (including background run) from start-up to exit. The target application may need to perform multiple rounds of memory reclamation operations during a run. The current time is the time for starting the memory reclamation of the current round, and can be denoted as Ti, where i is the round of memory reclamation performed during the current running period of the target application. For example, T1 represents the first round of memory reclamation during the current running of the target application.
When executing the memory reclamation operation for each service process, the memory reclamation step length corresponding to each service process is obtained in advance. In practical application, the memory reclamation step size is the reference size of the memory space that can be reclaimed for the corresponding service process when GC operation is executed each time, and different memory reclamation step sizes can be configured for different service processes.
Illustratively, with the target application as the game application, during running of the game application, a game background lobby service process lobby (which is used to manage each service process in the game application), a team forming process teamsvr for controlling team formation of players, and the like may be started, where during the memory reclamation process, a memory reclamation step size (which may be represented by step_size) for teamsvr is 200KB, that is, during each memory reclamation period, 200K of memory space is released for teamsvr.
In some embodiments, the server may determine the memory reclamation step size corresponding to each service process by: the server obtains the increment of the consumption of the memory space compared with the consumption of the memory space when the last memory recycling operation is completed; and when the consumption increment reaches an increment threshold, determining the memory reclamation step length corresponding to each service process.
In practical implementation, when the memory recovery step length corresponding to each running service process is obtained, the current target device is often in a memory recovery scene, that is, the memory recovery condition for executing the memory recovery operation for each service process is satisfied. The memory recovery condition refers to a trigger condition for starting the GC operation. The target application running on the target device has a corresponding at least one service process and a GC algorithm for performing GC operations. The GC algorithm is used for recycling the memory garbage generated by the operation of each target application. The memory reclamation condition may specifically be that a preset memory reclamation period arrives or that an increment of the consumption of the memory space reaches an increment threshold, etc. The memory recovery period refers to a time period for performing memory recovery, such as 30 seconds or 1 minute, i.e. performing memory recovery every half minute or 1 minute. The memory recovery period needs to be reasonably set according to the complexity of the data resources loaded by the target application, the target application is frequently interrupted due to the fact that the memory recovery period is too short, a large amount of memory is continuously occupied due to the fact that the memory recovery period is too long, and the target application is blocked or even dead. The increment threshold of the consumption increment of the memory space is a preset consumption increment maximum value, such as 60%.
In practical applications, it may be determined whether the memory reclamation condition is satisfied by the memory consumption increment. Here, the memory consumption increment (add_memory) refers to a consumption (current_memory) of the memory space at the current time, which is increased compared to a consumption (last_memory) of the memory space when the last memory reclamation operation was completed, i.e., add_memory=current_memory-last_memory. When the obtained consumption increment reaches an increment threshold, determining that a condition for executing a new round of GC is met, wherein the server can acquire a memory recovery step length corresponding to each service process and is used for releasing the consumption of the useless object for the memory space in the running process of each service process.
Taking a game application as an example, when a condition for starting a round of GC is set for the running game application, starting a round of GC when the consumption increment of the memory space by each running service process in the game application reaches 100MB, continuously acquiring the consumption of the memory space by each service process in the game application by a server, starting a round of GC operation when the consumption increment reaches 100MB, and acquiring a memory recovery step size set by each service process. For example, step_size=100 MB may be set for loginsvr (the service process responsible for the player logging in the game), step_size=200 MB may be set for teamsvr (the service process responsible for the player performing team formation), and so on.
In some embodiments, the server may obtain the consumption increment of the memory space by: determining an acquisition period of the consumption increment; and taking the time when the latest memory recycling operation is completed as a target time point, and acquiring the consumption increment of the memory space when the acquisition time point of the consumption increment is determined to be reached based on the acquisition period and the target time point.
In actual implementation, the server may periodically count the consumption increment of the memory space by setting an acquisition period T for the consumption increment, the consumption increment of the memory space. The time when the last GC operation is completed may be taken as a target time point (i.e., a start statistics time point, denoted as t_start), and then the acquisition time point (end statistics time point, denoted as t_end) for the consumption increment may be determined in combination with the acquisition period T and the target time point t_start, i.e., t_end-t_start=t, i.e., the interval duration of t_end and t_start is the same as the acquisition period T.
In some embodiments, the server may determine the memory reclamation step size corresponding to each service process by: acquiring a trigger period of the memory recycling operation; and taking the time when the latest memory reclamation operation is completed as a target time point, and determining the memory reclamation step length corresponding to each service process when the trigger time point of the memory reclamation operation is determined to be reached based on the trigger period of the memory reclamation operation and the target time point.
In practical implementation, the server may further determine a starting time point of a new GC based on a trigger period of GC operation, and at this time, in response to the memory recovery condition being satisfied, enter a preparation state for executing the GC, and obtain a memory recovery step size corresponding to each service process.
In some embodiments, the server may determine the memory reclamation step size corresponding to each service process by: respectively determining service contents corresponding to the service processes; and determining the memory recovery step length corresponding to the corresponding service process based on the service content corresponding to each service process.
In actual implementation, the functions of the service process, the service content associations or can indicate the size, number, etc. of object instances created by the service process. In each service process in the target application, the object is an instantiation of a class. A class is an abstraction of an entity with the same characteristics, and does not need to occupy memory, while an object is a concrete entity, and needs to occupy memory space. In the target application, a New object may be created by the keyword New. For example, in a game scene, the objects involved may include buildings, flowers and plants, etc. in a virtual scene, virtual objects, and tornadoes, pistols, etc. used for the virtual objects. Objects can be referenced against each other. If the object is not used for a long time after being created, the object can be regarded as garbage to be deleted so as to release the memory space occupied by the garbage object.
In some embodiments, the server may determine the memory reclamation step size corresponding to each service process by: and acquiring configuration parameters of each service process, and determining the memory recovery step length corresponding to each service process based on the configuration parameters.
In practical implementation, the target should be a developer, and the configuration parameters of the service processes can be configured, where the configuration parameters include a memory reclamation step length corresponding to the service process, an increment threshold of consumption of the target application for the memory space, and the like.
Taking a target application as an example of a game application, a game developer sets a memory reclamation step length for each background service in a configuration file of the game application, for example, sets a memory reclamation step length step_size=100 MB for a teamsvr service, runs a process corresponding to the teamsvr after the game application is started, and obtains a memory reclamation step length 100MB of the teamsvr after a memory reclamation condition is met, namely, releases a memory consumption amount of 100MB for the teamsvr in one reclamation period.
In step 102, a value of a resource parameter of the target device is obtained, the resource parameter comprising at least one of a computing resource parameter and a storage resource parameter.
In actual implementation, the server obtains values of resource parameters of the target device, where the resource parameters may include computing resource parameters and storage resource parameters. The computing resource may be a CPU resource required in the running process of each service process, and the storage resource may be a memory resource required in the running process of each service process.
In step 103, when the step adjustment condition is satisfied based on the value of the resource parameter, the memory reclamation step of each service process is adjusted to obtain the target memory reclamation step corresponding to each service process.
In practical implementation, the server may determine whether the step size adjustment condition is satisfied, that is, whether to trigger an adjustment operation of the memory reclamation step size for each service process, according to at least one of the above-mentioned value of the computing resource parameter (i.e., the usage rate of the CPU) and the value of the storage resource parameter (i.e., the consumption amount of the memory space). And when the step length adjusting conditions are met, the memory recovery step length of each service process is adjusted to obtain a corresponding target memory recovery step length.
In some embodiments, the server may determine that the step size adjustment condition is satisfied by: when the resource parameters comprise computing resource parameters and values of the computing resource parameters are used for indicating the utilization rate of computing resources of the target equipment, acquiring a utilization rate threshold value of the computing resources of the target equipment; when the value of the computing resource parameter indicates that the utilization rate of the computing resource of the target device does not reach the utilization rate threshold value, determining that a step size adjustment condition is satisfied.
In practical implementation, when the memory space is less and the CPU performance is at a higher level, whether the step length adjustment condition is satisfied can be directly determined according to the utilization rate of the CPU without considering the related response of the memory space.
For example, the server reads the usage rate threshold (e.g. 80%) set for the CPU, that is, when the usage rate of the CPU does not reach 80%, the memory reclamation step size of each service process may be enlarged, so as to accelerate the memory reclamation operation for each service process.
The method for determining the step length adjustment condition based on the CPU utilization rate can fully utilize CPU resources and reduce the waste of the CPU resources.
In some embodiments, the server may determine that the step size adjustment condition is satisfied by: when the resource parameters comprise storage resource parameters, acquiring parameter thresholds corresponding to the storage resource parameters; when the value of the storage resource parameter reaches a parameter threshold value, determining that a step length adjustment condition is satisfied; wherein the storage resource parameter comprises at least one of: the increment of the consumption of the memory space, and the consumption of the memory space are compared with the consumption of the memory space when the last memory reclamation operation is completed.
In actual implementation, the server may determine whether to adjust the memory reclamation step length corresponding to the service process according to the storage resource parameter and the corresponding parameter threshold, that is, determine whether the step length adjustment condition is satisfied. The storage resource parameter may refer to a consumption of the memory space, an increment of the consumption of the memory space, a consumption of the memory space, and the like, compared with a last time the memory reclamation operation is completed.
The server reads configuration information of the target application, determines storage resource parameters corresponding to each service process in the target application, assumes the storage resource parameters to be consumption increment of the memory space (i.e., consumption of the memory space at the current moment compared with the consumption of the memory space when the last memory reclamation operation is completed), sets a corresponding increment threshold to 30%, and determines that the step adjustment condition is satisfied when the consumption increment reaches the increment threshold.
The method for determining whether the step length adjustment condition is met according to the storage resource parameters can ensure that the utilization rate of the storage resource is maximized and the timeliness of releasing the memory space.
In some embodiments, when the resource parameters include the computing resource parameters and the storage resource parameters, the service may determine whether the step size adjustment condition is satisfied according to the steps shown in fig. 4, and fig. 4 is a schematic diagram of the step size adjustment condition determination provided in the embodiment of the present application, and is described in connection with the steps shown in fig. 4.
Step 1031a obtains a usage threshold of the computing resource of the target device and a parameter threshold corresponding to the storage resource parameter.
Wherein the value of the computing resource parameter is used to indicate the usage of the computing resource of the target device (i.e., the usage of the CPU). The storage resource parameters include at least one of: the increment of the consumption of the memory space, and the consumption of the memory space are compared with the consumption of the memory space when the last memory reclamation operation is completed.
In actual implementation, the utilization rate threshold of the computing resource and the parameter threshold corresponding to the storage resource parameter can be preset according to the actual resource utilization condition of the target device, the number of the target applications running on the target device and other information. The server combines the configuration information of each target application in the target equipment and the configuration information of each service process in each target application to determine the utilization rate threshold of the computing resource of the target equipment and the parameter threshold corresponding to the storage resource parameter.
In step 1032a, when the value of the computing resource parameter indicates that the usage of the computing resource of the target device does not reach the usage threshold and the value of the storage resource parameter reaches the parameter threshold, it is determined that the step size adjustment condition is satisfied.
In practical implementation, the server determines whether the step adjustment condition is satisfied or not in combination with the relation between the usage rate of the computing resource of the target device and the usage rate threshold value and the relation between the value of the storage resource parameter and the parameter threshold value.
By way of example, taking a game application as an example, setting the CPU usage threshold to 90% and the parameter threshold for the memory space consumption increment to 50MB (i.e., the storage resource parameter is the memory space consumption increment), it may be determined that when the CPU usage does not reach 90% and the memory space consumption increment reaches 50MB, the server determines that the step adjustment condition is satisfied and the server is ready to perform the step adjustment-related operation.
In some embodiments, referring to fig. 5, fig. 5 is a schematic diagram of a memory reclamation step size adjustment method according to an embodiment of the present application, and the steps shown in fig. 5 are described.
In step 1031b, the server obtains a value of an adjustment coefficient for adjusting the memory reclamation step size of each service process.
In practical implementation, the server may adjust the memory reclamation step length corresponding to each service process according to the adjustment coefficient. It should be noted that, the server may set an adjustment coefficient for each service process in the target application, or may set the same adjustment coefficient for the target application, that is, each service process in the target application uses the same adjustment coefficient. When the value of the adjustment coefficient is greater than 1, the memory recovery step length used for representing the expansion service process is used; when the value of the adjustment coefficient is smaller than 1, the memory recovery step length used for representing the reduced service process is used; when the value of the adjustment coefficient is equal to 1, the memory reclamation step length used for representing the service process is not adjusted.
In some embodiments, referring to fig. 6, fig. 6 is a schematic diagram illustrating a manner of determining an adjustment coefficient according to an embodiment of the present application, and based on fig. 6, step 1031b may be implemented by steps 201a-203 a.
In step 201a, the server obtains the increment of the consumption of the memory space, compared to the consumption of the memory space when the last memory reclamation operation is completed.
In practical implementation, the server may determine the adjustment coefficient according to the consumption of the memory space when the GC operation is completed compared with the last GC operation, and the base consumption corresponding to each service process. And determining the increment of the consumption of the memory space corresponding to the current time point based on the consumption of the memory space when the last GC operation is completed. The consumption increment can be characterized by an add_memory, and is used for judging the increasing speed of the memory consumption.
Step 202a, obtaining the basic consumption corresponding to each service process.
In actual implementation, the base consumption amount corresponding to each service process may be preconfigured, and different base consumption amounts may be set for each service process. When the step size adjustment condition is satisfied, the server reads the base consumption amount for each service process. The base consumption may be characterized using memory_default, among other things.
Illustratively, memory_default=50mb may be set for a service process written in the LUA scripting language.
In step 203a, a ratio between the consumption increment and each basic consumption is determined, and the ratio is used as a value of an adjustment coefficient for adjusting the memory reclamation step size of the corresponding service process.
In actual implementation, the server calculates the ratio between the consumption increment add_memory obtained in step 201a and the base consumption memory_default corresponding to each service process, and uses the ratio as the value of the adjustment coefficient for adjusting the memory reclamation step size of the corresponding service process, which may be referred to as gc_rate. I.e., gc_rate=add_memory/memory_default.
For example, for the service process P, the memory reclamation step size is set to 40MB, the add_memory from the last GC operation to the current time point is 80MB, and the memory_default corresponding to the service process P is 50MB, and then the gc_rate=80 MB/50 mb=1.6. I.e. in response to the step adjustment condition being met, the server adjusts the memory reclamation step size 40MB based on the adjustment coefficient 1.6, i.e. 1.6x40mb=64 MB, i.e. the determined target memory reclamation step size for the service process P is 64MB.
In some embodiments, referring to fig. 7, fig. 7 is another schematic diagram illustrating a manner of determining an adjustment coefficient according to an embodiment of the present application, and based on fig. 7, step 103 may be further implemented by steps 201b-203 b.
In step 201b, the server obtains the increment of the consumption of the memory space, compared to the consumption of the memory space when the last memory reclamation operation was completed.
In actual implementation, the server determines an increment add_memory of the consumption of the memory space corresponding to the current time point based on the consumption of the memory space when the last GC operation is completed.
Step 202b, obtaining the priority of each service process.
In practical implementation, each service process in the target application has different priorities, for example, in a game application of a group class, the priority of the service process teamsvr in charge of team formation is higher, and the priority of the process logo utsvr in charge of player exit game is lower.
In step 203b, a value of an adjustment coefficient for adjusting the memory reclamation step size of each service process is determined based on the consumption increment and each priority.
In actual implementation, the server may determine the value gc_rate of the adjustment coefficient according to the consumption increment and the priority. According to the different priorities of the service processes, setting the memory recovery rate corresponding to each service process, wherein the memory recovery rate can be understood as the recovery ratio of the consumption increment of the service process, for example, the consumption increment is 500MB, the consumption increment of the corresponding service process P is 200MB (200 MB in 500MB is the corresponding service process P), the memory recovery rate of the service process P is set to be 80%, namely, the GC of the round releases 200MB by 80% of memory space of the service process P. For service processes with high priority, a higher memory recovery rate, such as 100%, 90%, etc., and for service processes with low priority, a lower memory recovery rate, such as 10%, 20%, etc., may be set. Then, based on the memory recovery rate, an adjustment coefficient of each service process for the memory recovery step length is set. It should be noted that, when setting the memory recovery rate, the setting may also be combined with the computing resource case for the device.
For example, there are 5 running service processes P1, P2, P3, P4, P5, the corresponding priority order is P3 > P2 > P5 > P1 > P4, the consumption increment of the memory space is 500MB when triggering the GC operation of the current round, in order to accelerate the memory reclamation, the contribution value of the consumption increment of the highest priority P3 at 500MB (i.e. the consumption increment of the memory space by the P3 service process) is determined, and the contribution value is taken as the target adjustment step size corresponding to P3, i.e. the GC at this time, 100% of the consumption increment of the memory space corresponding to P3 is reclaimed (the memory reclamation rate=100% for P3 can be set), and the corresponding adjustment coefficient is the ratio of the contribution value to the initial memory reclamation step size. If the contribution value of P3 to 500MB is 150MB and the initial memory reclamation step size set for P3 is 100MB, the corresponding adjustment coefficient is 150MB/100 mb=1.5. Since the priority of P2 is lower than P3, the memory recovery rate=80% for P2 may be set, that is, the GC may recover 80% of the consumption increment of the memory space for P2, so as to determine the memory recovery rate of each service process based on the priority of the service process and the consumption increment, and further determine the corresponding adjustment coefficient.
Step 1032b, based on the value of the adjustment coefficient, the memory reclamation step length of each service process is adjusted, so as to obtain the target memory reclamation step length corresponding to each service process.
In actual implementation, the server adjusts the memory reclamation step size of each service process according to the adjustment coefficient gc_rate to obtain a target memory reclamation step size corresponding to each service process, which can be denoted as new_step_size. I.e. new_step_size=gc_rate.
For example, a memory reclamation step size=40mb is set for the service process P, and from the last GC operation, add_memory=80mb to the current time point, and memory_default=50mb corresponding to the service process P, gc_rate=80mb/50mb=1.6 corresponding to the service process P. The server adjusts the step_size based on the adjustment coefficient 1.6, to obtain new_step_size=1.6x40mb=64mb, i.e. the determined target memory reclamation step size for the service process P is 64MB. When the GC operation of the current round is performed, the memory reclamation step length for the service process P is 64MB, that is, the memory space of 64MB is released at a time.
In some embodiments, the server may adjust the memory reclamation step size by: when the adjustment coefficients and the service processes are in one-to-one correspondence, carrying out product finding processing on the values of the adjustment coefficients and the memory recovery step length of the corresponding service processes to obtain product finding results corresponding to the service processes; or when the number of the adjustment coefficients is one, carrying out product-seeking processing on the values of the adjustment coefficients and the memory recovery step length of each service process respectively to obtain product-seeking results corresponding to each service process; and taking the product result as a target memory recovery step length of the corresponding service process.
In practical implementation, the adjustment coefficients and the service processes may be in a one-to-one correspondence, that is, each service process corresponds to one adjustment coefficient, and the memory recovery step length corresponding to each service process performs product calculation with the corresponding adjustment coefficient, where the obtained product calculation result is used as the target memory recovery step length of the corresponding service process. In addition, the adjustment coefficient and the service process may be in one-to-many relationship, that is, the value of the same adjustment coefficient is respectively integrated with the memory recovery step length of each service process, and the obtained integration result is used as the target memory recovery step length of the corresponding service process. The server can determine the target memory recovery step length corresponding to each service process according to the corresponding relation between the pre-configured adjustment coefficient and the service process.
In step 104, for each service process, a memory reclamation operation is performed based on the target memory reclamation step size to free up memory space of a size corresponding to the target memory reclamation step size.
In practical implementation, after determining the target memory recovery step length for each service process, the server performs GC operation for each service process by adopting a corresponding target memory recovery step length in a GC period, so as to release a memory space with a size corresponding to the target memory recovery step length.
Taking an example of a running game application, the memory reclamation step size=100 MB set by the service process loginsvr in charge of the player logging in the game in advance, but a large number of players log in a set time period (such as holidays), at this time, in order to timely release the corresponding memory space, the server may set the target memory reclamation step size=200 MB of the loginsvr according to the obtained adjustment coefficient. Thus, when a large number of players log in together, the original step_size is enlarged 2 times, that is, 100MB is adjusted to 200MB in order to ensure normal execution of the loginsvr service process.
In some embodiments, the server may also perform the memory reclamation operation by: when the step length adjustment condition is not met based on the value of the resource parameter, based on the memory recycling step length corresponding to each service process, executing the memory recycling operation on the corresponding service process so as to release the memory space with the size corresponding to the memory recycling step length.
In actual implementation, if the step size adjustment condition is not satisfied, for example, the CPU resource occupation amount has reached a preset threshold, no more CPU resources are available in the target device for executing the step size adjustment operation, and at this time, the server may continue to execute the corresponding GC operation by using the memory reclamation step size (i.e., the preset fixed step size) of each running service process.
In the above example, the player logs in to the stationary phase and can readjust the memory reclamation step to 100MB.
By applying the embodiment of the application, when the step length adjustment condition for each service process is determined to be satisfied based on the calculation resource parameter and the storage resource parameter of the target equipment, the memory reclamation step length of each service process is dynamically adjusted, and the target memory reclamation step length for executing the memory reclamation operation is determined. Thus, when the increment of the consumption of the memory space is faster, the speed of releasing the memory space can be increased by expanding the memory recovery step length, and the balance between the computing resource and the memory resource of the target device can be achieved.
In the following, an exemplary application of the embodiment of the present application in a practical application scenario will be described.
Taking an example of implementing a game application based on the LUA5.3 version, the game application comprises at least one service process written by using LUA script language, the GC algorithm of each service process in the LUA5.3 version adopts a mark-and-clear method, and supports incremental GC, and a background service process controls GC recycling of the whole process by calling GC (manual step GC) regularly, instead of adopting an automatic GC mode of the LUA virtual machine. Because the garbage rate of different background service processes (game background hall service lobby, teamsvr, friendsvr) is different, when manual GC is performed, different memory recovery step sizes are respectively set according to different service processes, and then the memory recovery step sizes are fixed step sizes, and then the memory garbage rate of each service process is different, so that the fixed memory recovery step sizes cannot adapt to dynamically-changed scenes. When a certain version of background service (e.g. the background service teamsvr2.0 responsible for player team formation is greater than teamsvr 1.0) increases much business processing logic, the consumption of memory space increases greatly (or the speed of generating memory garbage increases greatly), which may result in that the fixed memory recovery step of the original configuration is too small to release the memory space in time. Meanwhile, if some sudden increase of the external network burst activity request amount occurs, the memory space consumption is too fast, so that the memory space is not recovered timely, and the system OOM (Out of Memory) is triggered, namely, when the memory of the computer equipment is used up, the forced triggering OOM is triggered, and the operating system can randomly kill the business process, so that the memory is recovered forcibly, the target application is interrupted, and the man-machine interaction experience is affected.
Based on this, the embodiment of the application provides a memory management method, which can dynamically adjust the memory recovery step according to the increase speed of the consumption of the CPU resource and the memory space of the server, i.e. adjust the fixed memory recovery step into the dynamic memory recovery step. Thus, the faster the consumption of the memory space increases (i.e. the faster the garbage is generated), the memory recovery step length of the GC is enlarged, so that the memory space is released more quickly and timely. Thus, the memory space which is consumed rapidly when different versions are different and the request bursts can be released in time.
In some embodiments, referring to fig. 8, fig. 8 is a flowchart of a memory management method based on a fixed memory reclamation step size according to an embodiment of the present application. A method of managing memory based on a fixed memory reclamation stride will be described with reference to the steps shown in fig. 8.
Step 301, the server obtains the running target service process. When the server runs the Lua script file, the manual GC operation gc_step is triggered through the tick and the update. the tick is a timing call, frequency 10 times/s; the update is invoked when the packet is received, and if there is no message in this round, it will go on_idle sleep 5ms. Through the two calls, the GC fractional recovery can be triggered in time. Step 302, the server acquires a memory reclamation step size for each service process, and the memory reclamation step size is denoted as step_size, wherein the step_size configures different fixed values for different service processes. Step 303, determining whether the memory recovery condition is satisfied, and in actual implementation, maintaining a gc_running global variable (used for indicating whether the memory recovery condition is satisfied, that is, whether to execute GC operation) by the server, and determining whether a GC round is started. If the GC is completed for one round, the server records the current Last_lua_mem of the Lua virtual machine. Only when the increment of the consumption of the memory space of the Lua virtual machine exceeds the consumption increment threshold, gc_running=true is set to trigger the next GC, so that the CPU resource can be prevented from being consumed by the GC in an ineffective idle mode when the consumption of the Lua memory is low. In step 304, the server calls a memory reclamation interface collectable ("step" step_size) provided by the Lua virtual machine to trigger the GC to reclaim the memory space step by step. Step 305, the memory reclamation operation for the service process is ended.
The GC operation performed with a fixed memory reclamation step size described above can be adapted to conventional non-dynamically changing application scenarios. For the memory management method of the dynamically changing application scenario, refer to fig. 9, and fig. 9 is a flowchart of the memory management method based on the dynamic memory recovery step length according to the embodiment of the present application. The core principle of the method comprises the following two points: first, the original fixed memory reclamation step size is corrected by adjusting the coefficient gc_rate, and gc_rate=1 can be regarded as the memory management method based on the fixed memory reclamation step size shown in fig. 8. gc_rate may be dynamically adjusted based on the amount of memory space consumed. Second, since dynamically expanding gc_rate eventually expands step_size, more CPU computing resources are consumed, and that is, dynamically adjusting memory reclamation steps is essentially a CPU memory replacement process. Therefore, it is necessary to expand gc_rate in conjunction with the CPU usage of the current service process. Next, the steps shown in fig. 9 will be described below:
in step 401, the server obtains a running target service process. The server triggers a manual GC operation gc_step through the tick and update while looping run. the tick is a timing call, frequency 10 times/s; the update is invoked when the packet is received, and if there is no message in this round, it will go on_idle sleep 5ms. Through the two calls, the GC can be triggered to recycle step by step in time.
Step 403, the server obtains the memory reclamation step length for each service process.
In step 403, it is determined whether the memory reclamation condition is satisfied, and in actual implementation, the system maintains the gc_running variable to determine whether a GC round is started. If one round of GC is completed, the system records the current Last_lua_mem of the Lua virtual machine. When the consumption increment of the consumption of the memory space of the Lua virtual machine exceeds a preset increment threshold, gc_running=true is set, and the next round of GC is triggered, so that the idle running consumption of CPU resources by the GC can be avoided when the consumption of the Lua memory is low.
Step 404, determining whether the usage of the computing resource exceeds a usage threshold.
In actual implementation, the server determines whether the usage of the process CPU exceeds a usage threshold (e.g., 90%). If the usage rate of the process CPU exceeds 90%, gc_rate=1 is directly used without enlarging step_size additionally. When the utilization rate of the process CPU does not reach the utilization rate threshold, and the consumption increment of the consumption of the Lua memory space after the start of the GC cycle of the present round exceeds a preset increment threshold (e.g. 50 MB), that is, cur_lua_mem-last_lua_mem >50MB, dynamic adjustment for the memory reclamation step size is started, where the increment threshold is configurable according to practical situations.
Step 405, the memory reclamation step length is adjusted to obtain the target memory reclamation step length. In practical implementation, the server obtains an adjustment coefficient for dynamically adjusting the memory reclamation step size, where the adjustment coefficient may be represented by gc_rate, i.e. the rate of dynamic acceleration for the memory reclamation step size may be controlled by gc_rate. Where gc_rate=add_mem/mem_default. In this case, if the consumption of Lua memory space increases faster, add_mem increases, the corresponding gc_rate increases, and the target step_size=step_size increases, so that GC speed increases.
In step 406, through the foregoing steps 1 to 5, a target memory reclamation step size may be calculated, and a C interface collectable ("step", step_size) provided by the Lua virtual machine is called to trigger GC fractional reclamation.
Step 407, when the usage rate of the process CPU reaches the usage rate threshold, the memory reclamation step size is not adjusted. In practical implementation, when gc_rate=1, the effect of GC operation remains the same as that of fig. 8, which shows a memory management method based on a fixed memory reclamation step size.
In practical application, referring to fig. 10A to 10D, fig. 10A to 10D are schematic effect analysis diagrams of a memory management method in different scenarios according to an embodiment of the present application. Step_normal in the figure represents a memory management method based on a fixed memory reclamation step size, and step_adapt represents a memory management method based on a dynamic memory reclamation step size. An index for effect analysis, comprising at least one of: CPU mean, CPU maximum amplitude, memory mean, memory maximum amplitude, step mean (step mean) for performing GC operation, gc_rate mean, GC recovery average duration.
The LUA script language is adopted for the small table, and the structural code fragments are created as follows:
the method is characterized by comprising the following steps of aiming at a large table, having certain randomness, 1-5 tabs at each time, layering 1-5 layers, and creating structural code fragments by adopting the LUA script language, wherein the structural code fragments are as follows:
based on the created large table and small table, referring to fig. 10A, an effect analysis diagram for the high-frequency small table is shown in fig. 10A, and the high-frequency small table created in the scene can support 2000 people online, qps per second is 5, and scattered small tables of 5-10 are created each time; when the two memory management methods are applied to the high-frequency small table, the analysis results of the analysis indexes are shown in table 1:
TABLE 1
Referring to fig. 10B, an effect analysis graph for a low frequency small table is shown in fig. 10B, and the low frequency small table created in the scene can support 2000 people online, qps per second, and each time, a scattered small table of 5-10 is created; when the two memory management methods are applied to the low-frequency small table, the analysis results of the analysis indexes are shown in table 2:
TABLE 2
Referring to fig. 10C, an effect analysis graph for a high frequency large table is shown in fig. 10C, 3000 people online, qps a second at a time, creating a large and deep table. When the two memory management methods are applied to a high-frequency large table, the analysis results for the analysis indexes are shown in table 3:
TABLE 3 Table 3
Referring to fig. 10D, fig. 10D shows 2500 people online, one large and deep table at a time, per second qps1, for a low frequency large table. When the two memory management methods are applied to the low-frequency large table, the analysis results for the analysis indexes are shown in table 4:
TABLE 4 Table 4
Based on the effect comparison information shown in the above fig. 10A to 10D and tables 1 to 4, it can be analytically found that: step-normal, in the case of high CPU pressure (high CPU usage), causes the system OOM when the memory space recovery rate does not keep up with the memory allocation rate (the rate of increase in the consumption of the memory space), and step-adpat can expand the memory recovery step size according to the increase in the consumption of the memory space, so that the memory of the computer device is at a relatively stable level. In terms of CPU utilization, the difference between the two data models (step-normal and step-adpat) is not large, and in the high-frequency data model, the step-adpat consumes higher CPU because of faster recovery speed for memory space.
By applying the embodiment of the application, when the increasing speed of the memory consumption is low (the memory garbage is generated slowly), the memory recovery step length can be fixed, and when the increasing speed of the memory consumption is high, the memory space can be recovered in time by dynamically adjusting the memory recovery step length, so that the system OOM is effectively prevented from being triggered due to untimely memory recovery caused by a burst state. And during memory recovery, comprehensively considering the balance between the CPU computing resources of the target device and the memory. Meanwhile, the dynamic adjustment of the memory reclamation step length can adapt to the difference between different versions of the service process and the scene of suddenly and greatly increasing the request quantity of the service process.
It will be appreciated that in the embodiments of the present application, related data such as user information is involved, and when the embodiments of the present application are applied to specific products or technologies, user permissions or agreements need to be obtained, and the collection, use and processing of related data need to comply with relevant laws and regulations and standards of relevant countries and regions.
Continuing with the description below of an exemplary structure of the memory management device 555 implemented as a software module provided in an embodiment of the present application, in some embodiments, as shown in fig. 2, the software module stored in the memory management device 555 of the memory 550 may include:
a determining module 5551, configured to determine at least one service process that is running on a target device, and determine a memory reclamation step size corresponding to each service process, where the memory reclamation step size is used to characterize a size of a memory space that is released when a memory reclamation operation is performed on the service process;
an acquisition module 5552, configured to acquire a value of a resource parameter of the target device, where the resource parameter includes at least one of a computing resource parameter and a storage resource parameter;
the adjustment module 5553 is configured to adjust a memory reclamation step size of each service process when determining that a step size adjustment condition is satisfied based on the value of the resource parameter, so as to obtain a target memory reclamation step size corresponding to each service process;
And a reclamation module 5554, configured to execute, for each service process, the memory reclamation operation based on the target memory reclamation step size, so as to release a memory space with a size corresponding to the target memory reclamation step size.
In some embodiments, the determining module is further configured to obtain an increment of consumption of the memory space compared to the consumption of the memory space when the last memory reclamation operation was completed; and when the consumption increment reaches an increment threshold, determining the memory reclamation step length corresponding to each service process.
In some embodiments, the determining module is further configured to determine an acquisition period of the consumption increment; and taking the time when the latest memory recycling operation is completed as a target time point, and acquiring the consumption increment of the memory space when the acquisition time point of the consumption increment is determined to be reached based on the acquisition period and the target time point.
In some embodiments, the determining module is further configured to obtain a trigger period of the memory reclamation operation; and taking the time when the latest memory reclamation operation is completed as a target time point, and determining the memory reclamation step length corresponding to each service process when the trigger time point of the memory reclamation operation is determined to be reached based on the trigger period of the memory reclamation operation and the target time point.
In some embodiments, the determining module is further configured to determine service content corresponding to each service process respectively; and determining the memory recovery step length corresponding to the corresponding service process based on the service content corresponding to each service process.
In some embodiments, the adjusting module is further configured to obtain a usage threshold of a computing resource of the target device when the resource parameter includes the computing resource parameter, the value of the computing resource parameter being used to indicate the usage of the computing resource of the target device; and when the value of the computing resource parameter indicates that the utilization rate of the computing resource of the target device does not reach the utilization rate threshold value, determining that the step length adjustment condition is satisfied.
In some embodiments, the adjusting module is further configured to obtain a parameter threshold corresponding to the storage resource parameter when the resource parameter includes the storage resource parameter; when the value of the storage resource parameter reaches the parameter threshold value, determining that a step length adjustment condition is satisfied; wherein the storage resource parameter comprises at least one of: the increment of the consumption of the memory space, and the consumption of the memory space are compared with the consumption of the memory space when the last memory reclamation operation is completed.
In some embodiments, the adjusting module is further configured to obtain a value of an adjustment coefficient for adjusting a memory reclamation step size of each service process; and adjusting the memory recovery step length of each service process based on the value of the adjustment coefficient to obtain a target memory recovery step length corresponding to each service process.
In some embodiments, the adjustment module is further configured to obtain an increment of consumption of the memory space compared to the consumption of the memory space when the last memory reclamation operation is completed; acquiring the basic consumption corresponding to each service process; and determining the ratio between the consumption increment and each basic consumption, and taking the ratio as the value of an adjustment coefficient for adjusting the memory reclamation step length of the corresponding service process.
In some embodiments, the adjustment module is further configured to obtain an increment of consumption of the memory space compared to the consumption of the memory space when the last memory reclamation operation is completed; acquiring the priority of each service process; and determining the value of an adjustment coefficient for adjusting the memory reclamation step length of each service process based on the consumption increment and each priority.
In some embodiments, the adjusting module is further configured to perform product processing on a value of each adjusting coefficient and a memory recovery step size of the corresponding service process when the adjusting coefficient has a one-to-one correspondence with the service process, so as to obtain a product result corresponding to each service process; or when the number of the adjustment coefficients is one, carrying out product-seeking processing on the values of the adjustment coefficients and the memory recovery step length of each service process respectively to obtain a product-seeking result corresponding to each service process; and taking the product result as a target memory recovery step length corresponding to the service process.
In some embodiments, the reclamation module is further configured to execute, when it is determined based on the value of the resource parameter that the stride length adjustment condition is not satisfied, the memory reclamation operation on the corresponding service process based on the memory reclamation stride length corresponding to each service process, so as to release the memory space with the size corresponding to the memory reclamation stride length.
Embodiments of the present application provide a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the memory management method according to the embodiment of the present application.
An embodiment of the present application provides a computer readable storage medium storing executable instructions, where the executable instructions are stored, which when executed by a processor, cause the processor to perform a memory management method provided by the embodiment of the present application, for example, a memory management method as shown in fig. 3.
In some embodiments, the computer readable storage medium may be FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; but may be a variety of devices including one or any combination of the above memories.
In some embodiments, the executable instructions may be in the form of programs, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and they may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
As an example, the executable instructions may, but need not, correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a hypertext markup language (HTML, hyper Text Markup Language) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files that store one or more modules, sub-programs, or portions of code).
As an example, executable instructions may be deployed to be executed on one computing device or on multiple computing devices located at one site or, alternatively, distributed across multiple sites and interconnected by a communication network.
In summary, when the increasing speed of the memory consumption is slow (the memory garbage is generated slowly), the memory recovery step length can be fixed, and when the increasing speed of the memory consumption is high, the memory space can be recovered in time by dynamically adjusting the memory recovery step length, so that the system OOM is effectively prevented from being triggered due to untimely memory recovery caused by the burst state. And during memory recovery, comprehensively considering the balance between the CPU computing resources of the target device and the memory. Meanwhile, the dynamic adjustment of the memory reclamation step length can adapt to the difference between different versions of the service process and the scene of suddenly and greatly increasing the request quantity of the service process.
The foregoing is merely exemplary embodiments of the present application and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and scope of the present application are included in the protection scope of the present application.

Claims (16)

1. The memory management method is characterized by comprising the following steps:
determining at least one service process which is running by the target equipment, and determining a memory recovery step length corresponding to each service process, wherein the memory recovery step length is used for representing the size of a released memory space when memory recovery operation is executed on the service process;
acquiring a value of a resource parameter of the target device, wherein the resource parameter comprises at least one of a calculation resource parameter and a storage resource parameter;
when the step length adjustment condition is determined to be satisfied based on the value of the resource parameter, the memory recovery step length of each service process is adjusted, and a target memory recovery step length corresponding to each service process is obtained;
and executing the memory reclamation operation based on the target memory reclamation step length for each service process so as to release the memory space with the size corresponding to the target memory reclamation step length.
2. The method of claim 1, wherein determining a memory reclamation step size corresponding to each service process comprises:
obtaining the increment of the consumption of the memory space compared with the consumption of the memory space when the last memory recycling operation is completed;
And when the consumption increment reaches an increment threshold, determining the memory reclamation step length corresponding to each service process.
3. The method of claim 2, wherein the obtaining the increment of consumption of the memory space comprises:
determining an acquisition period of the consumption increment;
and taking the time when the latest memory recycling operation is completed as a target time point, and acquiring the consumption increment of the memory space when the acquisition time point of the consumption increment is determined to be reached based on the acquisition period and the target time point.
4. The method of claim 1, wherein determining a memory reclamation step size corresponding to each service process comprises:
acquiring a trigger period of the memory recycling operation;
and taking the time when the latest memory reclamation operation is completed as a target time point, and determining the memory reclamation step length corresponding to each service process when the trigger time point of the memory reclamation operation is determined to be reached based on the trigger period of the memory reclamation operation and the target time point.
5. The method of claim 1, wherein determining a memory reclamation step size corresponding to each service process comprises:
Respectively determining service contents corresponding to the service processes;
and determining the memory recovery step length corresponding to the corresponding service process based on the service content corresponding to each service process.
6. The method of claim 1, wherein the determining that a step size adjustment condition is satisfied based on the value of the resource parameter comprises:
acquiring a utilization rate threshold of the computing resource of the target device when the resource parameter comprises the computing resource parameter and the value of the computing resource parameter is used for indicating the utilization rate of the computing resource of the target device;
and when the value of the computing resource parameter indicates that the utilization rate of the computing resource of the target device does not reach the utilization rate threshold value, determining that the step length adjustment condition is satisfied.
7. The method of claim 1, wherein the determining that a step size adjustment condition is satisfied based on the value of the resource parameter comprises:
when the resource parameters comprise the storage resource parameters, acquiring parameter thresholds corresponding to the storage resource parameters;
when the value of the storage resource parameter reaches the parameter threshold value, determining that a step length adjustment condition is satisfied;
Wherein the storage resource parameter comprises at least one of: the increment of the consumption of the memory space, and the consumption of the memory space are compared with the consumption of the memory space when the last memory reclamation operation is completed.
8. The method of claim 1, wherein the adjusting the memory reclamation step size for each of the service processes comprises:
acquiring the value of an adjustment coefficient for adjusting the memory reclamation step length of each service process;
and adjusting the memory recovery step length of each service process based on the value of the adjustment coefficient to obtain a target memory recovery step length corresponding to each service process.
9. The method of claim 8, wherein obtaining the value of the adjustment factor for adjusting the memory reclamation step size for each of the service processes comprises:
obtaining the increment of the consumption of the memory space compared with the consumption of the memory space when the last memory recycling operation is completed;
acquiring the basic consumption corresponding to each service process;
and determining the ratio between the consumption increment and each basic consumption, and taking the ratio as the value of an adjustment coefficient for adjusting the memory reclamation step length of the corresponding service process.
10. The method of claim 8, wherein obtaining the value of the adjustment factor for adjusting the memory reclamation step size for each of the service processes comprises:
obtaining the increment of the consumption of the memory space compared with the consumption of the memory space when the last memory recycling operation is completed;
acquiring the priority of each service process;
and determining the value of an adjustment coefficient for adjusting the memory reclamation step length of each service process based on the consumption increment and each priority.
11. The method of claim 8, wherein adjusting the memory reclamation step size of each service process based on the value of the adjustment coefficient to obtain the target memory reclamation step size corresponding to each service process comprises:
when the adjustment coefficients and the service processes are in one-to-one correspondence, carrying out product finding processing on the values of the adjustment coefficients and the memory recovery step length of the corresponding service process to obtain product finding results corresponding to the service processes; or alternatively, the process may be performed,
when the number of the adjustment coefficients is one, carrying out product-seeking processing on the values of the adjustment coefficients and the memory recovery step length of each service process respectively to obtain product-seeking results corresponding to each service process;
And taking the product result as a target memory recovery step length corresponding to the service process.
12. The method of claim 1, wherein the method further comprises:
and when the step length adjustment condition is not met based on the value of the resource parameter, executing the memory recycling operation on the corresponding service process based on the memory recycling step length corresponding to each service process so as to release the memory space with the size corresponding to the memory recycling step length.
13. A memory management apparatus, the apparatus comprising:
the system comprises a determining module, a memory recovery step length determining module and a memory recovery module, wherein the determining module is used for determining at least one service process of which the target device is running, determining the memory recovery step length corresponding to each service process, and representing the size of a released memory space when memory recovery operation is executed on the service process;
an acquisition module, configured to acquire a value of a resource parameter of the target device, where the resource parameter includes at least one of a computing resource parameter and a storage resource parameter;
the adjustment module is used for adjusting the memory recovery step length of each service process when the step length adjustment condition is met based on the value of the resource parameter, so as to obtain a target memory recovery step length corresponding to each service process;
And the reclaiming module is used for executing the memory reclaiming operation based on the target memory reclaiming step length aiming at each service process so as to release the memory space with the size corresponding to the target memory reclaiming step length.
14. An electronic device, the electronic device comprising:
a memory for storing executable instructions;
a processor configured to implement the memory management method according to any one of claims 1 to 12 when executing the executable instructions stored in the memory.
15. A computer readable storage medium storing executable instructions which when executed by a processor implement the memory management method of any one of claims 1 to 12.
16. A computer readable storage medium storing executable instructions which when executed by a processor implement the memory management method of any one of claims 1 to 12.
CN202210306918.3A 2022-03-25 2022-03-25 Memory management method, device, equipment and computer readable storage medium Pending CN116841723A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210306918.3A CN116841723A (en) 2022-03-25 2022-03-25 Memory management method, device, equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210306918.3A CN116841723A (en) 2022-03-25 2022-03-25 Memory management method, device, equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN116841723A true CN116841723A (en) 2023-10-03

Family

ID=88162186

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210306918.3A Pending CN116841723A (en) 2022-03-25 2022-03-25 Memory management method, device, equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN116841723A (en)

Similar Documents

Publication Publication Date Title
US10725826B1 (en) Serializing duration-limited task executions in an on demand code execution system
CN107832100B (en) APK plug-in loading method and terminal thereof
US8191068B2 (en) Resource management system, resource information providing method and program
US10871985B2 (en) Displaying media files between changes in states of an application client
CN104503887A (en) Method and device for showing state of computing equipment
CN113037794B (en) Method, device and system for computing resource allocation scheduling
CN110895524B (en) Composite overdue method, device, server and storage medium of full-load redis time key
JP7100154B2 (en) Processor core scheduling method, equipment, terminals and storage media
CN106569917B (en) Data backup method and mobile terminal
US10776081B2 (en) Systems and methods for utilizing webhooks integrated in platform-as-a-service supported application development and deployment
US20170033980A1 (en) Agent manager for distributed transaction monitoring system
CN112799925A (en) Data acquisition method and device, electronic equipment and readable storage medium
CN114706690B (en) Method and system for sharing GPU (graphics processing Unit) by Kubernetes container
CN108933947B (en) Bullet screen display method and device
CN109697112B (en) Distributed intensive one-stop operating system and implementation method
CN112783642A (en) In-container logic configuration method, device and computer readable medium
US20240129251A1 (en) Data processing method and apparatus, computer device, and readable storage medium
US20170171307A1 (en) Method and electronic apparatus for processing picture
CN112988062B (en) Metadata reading limiting method and device, electronic equipment and medium
CN112398752B (en) Message push control method and device, equipment and medium thereof
CN111294377A (en) Network request sending method of dependency relationship, terminal device and storage medium
CN116841723A (en) Memory management method, device, equipment and computer readable storage medium
CN110311935B (en) Sharing method, sharing deployment system and client
US10341451B2 (en) Cloud oriented stream scheduling method based on android platform
CN114816713A (en) Function calling method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination