Memory recovery method and electronic device
In the memory recycling method of electronic devices, the target memory recycling amount is dynamically adjusted according to the urgency of the process and memory pressure, and the problem that memory recycling in the existing technology cannot meet business needs is solved, more efficient memory supply is achieved, and application lag is reduced.
Patent Information
- Application Number
- PCT/CN2023/115346
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-05-30
AI Technical Summary
In the prior art, electronic devices often fail to meet business needs when memory resources are insufficient, resulting in slow and stuttering application responses and impacting user experience.
In the memory recycling method, the target memory recycling amount is dynamically adjusted according to the urgency of the process and the memory pressure, reducing the blocking time of synchronous memory recycling, and improving memory supply efficiency.
It effectively reduces application lag caused by slow memory supply, improves user experience, and improves memory supply efficiency.
Smart Images

Figure CN2023115346_30052025_PF_FP_ABST
Abstract
Description
Memory recycling method and electronic device Technical Field
[0001] The present application relates to the field of storage technology, and in particular to a memory recycling method and electronic device. Background Art
[0002] As various applications continue to upgrade, their demand for memory is increasing. However, the memory capacity of electronic devices is limited and cannot meet the long-term needs of a large number of applications. Therefore, when memory resources are insufficient, the core of the electronic device will reclaim memory.
[0003] In existing technologies, the kernel performs asynchronous memory reclamation when remaining memory space is insufficient. However, when the system's current memory demand is high, asynchronous memory reclamation often fails to meet business needs, triggering the kernel to perform synchronous reclamation. However, synchronous reclamation blocks the process; the kernel cannot allocate memory space to the process until memory reclamation is complete. In this case, low memory supply efficiency directly affects application responsiveness, causing application lag and negative user experience.
[0004] Summary of the Invention
[0005] The embodiments of the present application provide a memory recycling method and an electronic device for improving memory supply efficiency, reducing the lag caused by long memory application time, and improving user experience.
[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0007] In a first aspect, the present application provides a memory recovery method, which is applied to an electronic device, and the method includes: in response to a first event that triggers a first process to apply for memory, reclaiming memory in a first memory recovery method based on a first memory recovery parameter; in response to a second event that triggers a second process to apply for memory, reclaiming memory in a second memory recovery method based on a second memory recovery parameter; wherein the first memory recovery parameter includes a first target memory recovery amount, and the second memory recovery parameter includes a second target memory recovery amount; when the urgency of the first process is the same as the urgency of the second process, and the memory pressure corresponding to the first memory recovery method is higher than the memory pressure corresponding to the second memory recovery method, the first target memory recovery amount is less than the second target memory recovery amount; when the urgency of the first process is higher than the urgency of the second process, and the first memory recovery method is the same as the second memory recovery method, the first target memory recovery amount is less than the second target memory recovery amount.
[0008] Among them, when the urgency of the first process is the same as that of the second process, and the memory pressure corresponding to the first memory recovery method is higher than the memory pressure corresponding to the second memory recovery method, the first target memory recovery amount is smaller than the second target memory recovery amount, which means that the higher the memory pressure corresponding to the target memory recovery method, the smaller the target memory recovery amount. In this way, for the synchronous memory method, it can have a smaller target memory recovery amount, so that the kernel can exit the memory recovery process more quickly and allocate memory space to the application process for application operation, thereby reducing the application jamming caused by slow memory supply. For the asynchronous memory recovery method, it can have a larger target memory recovery amount, so that it can reduce the situation of synchronous recovery by the kernel by providing sufficient memory, thereby reducing the application jamming caused by slow memory supply.
[0009] If the urgency of the first process is higher than that of the second process, and the first and second memory reclamation methods are the same, the first target memory reclamation amount is smaller than the second target memory reclamation amount, indicating that the higher the urgency of the process, the smaller the target memory reclamation amount. Therefore, after the kernel enters synchronous memory mode, the target memory reclamation amount for the high-urgency process can be reduced, allowing the kernel to exit the memory reclamation process more quickly and allocate memory space to the application process for use, thereby reducing application lag caused by slow memory supply.
[0010] In an implementation provided in the first aspect, the urgency of the first process is determined based on system status information and process status information, the system status information is used to indicate memory pressure, and the process status information is used to indicate the impact of the first process on the user experience; wherein the system status information includes at least one of information indicating whether the electronic device is performing garbage collection and information indicating whether there is a process competing with the first process for memory; the process status information includes the priority of the first process, whether the first process is a real-time process, and at least one of the types of the first process, the types of the first process including foreground processes, background processes, and foreground-related processes, and the foreground-related processes are processes that support the operation of the foreground process.
[0011] In an implementation method provided in the first aspect, when the system status information and the process status information meet a first condition, the target memory requirement is a first target memory requirement, which is less than or equal to the memory requirement of the first process; when the system status information and the process status information meet a second condition, the target memory requirement is a second target memory requirement, which is equal to the memory requirement of the first process; when the system status information and the process status information meet a third condition, the target memory requirement is a third target memory requirement, which is greater than or equal to the memory requirement of the first process; wherein, the urgency of the first process when the system status information and the process status information meet the first condition is higher than the urgency of the first process when the system status information and the process status information meet the second condition, and the urgency of the first process when the system status information and the process status information meet the second condition is higher than the urgency of the first process when the system status information and the process status information meet the third condition.
[0012] That is to say, when the urgency is high, the target memory requirement can be reduced based on the memory requirement of the process; when the urgency is low, the target memory requirement can be increased based on the memory requirement of the first process. This is conducive to setting different target memory requirements according to the urgency of the process, and meeting the memory supply efficiency requirements of processes with different urgency levels.
[0013] In an implementation provided in the first aspect, the first condition includes: there is a process that competes with the first process for memory; or, the electronic device is performing garbage collection, the priority of the first process is higher than the preset priority and the first process is a real-time process; or, the first process is a foreground process and the first process is a real-time process.
[0014] In an implementation provided in the first aspect, the second condition includes: the electronic device is performing garbage collection, the priority of the first process is higher than the preset priority and the first process is not a real-time process; or, the first process is a foreground process and the first process is not a real-time process.
[0015] In an implementation manner provided by the first aspect, the third condition includes: the first process is a foreground-related process or a background process.
[0016] In an implementation provided in the first aspect, the memory recovery parameters also include a dirty page write-back flag; when the system status information and the process status information meet the fourth condition, the dirty page write-back flag is a first value, and the dirty page write-back flag is the first value, indicating that the dirty page write-back operation is not performed during the memory recovery process; wherein the fourth condition includes: there is a process that competes with the first process for memory; or, the electronic device is performing garbage collection and the priority of the first process is higher than the preset priority; or, the first process is a foreground process.
[0017] Among them, when the fourth condition is met, it indicates that the urgency of the first process is high. In this case, by setting the dirty page write-back flag to the first value, the electronic device can not write back the dirty page during the memory recovery process, which is conducive to improving the memory recovery efficiency.
[0018] In an implementation provided in the first aspect, the memory recovery parameter also includes a recovery mode; when the system status information and the process status information meet the fifth condition, the recovery mode is the first mode; wherein, when the recovery mode is the first mode, the electronic device does not continue to recycle memory when the actual memory recovery amount is greater than or equal to the target memory recovery amount; wherein the fifth condition includes: there is a process that competes with the first process for memory; or, the electronic device is performing garbage collection and the priority of the first process is higher than the preset priority.
[0019] Among them, when the fifth condition is met, it indicates that the urgency of the first process is high. In this case, the recycling mode is set to the first mode, which can make it easier for the electronic device to exit the recycling process, thereby shortening the memory recycling time and improving the memory supply efficiency.
[0020] In an implementation provided in the first aspect, the system status information includes the number of file pages, and the memory recovery parameter also includes a file page flag; when the number of file pages is less than or equal to the first value, the file page flag is a second value, and the file page flag is the second value, indicating that anonymous pages are recycled first during the memory recovery process.
[0021] It can be understood that when the number of file pages is less than or equal to the first value, setting the file page flag to the second value can enable the electronic device to give priority to recycling anonymous pages during the memory recycling process, thereby achieving the effect of balancing the number of anonymous pages and file pages.
[0022] In an implementation provided by the first aspect, in response to a first event that triggers a first process to apply for memory, memory is reclaimed in a first memory reclaiming method based on a first memory reclaiming parameter, including: in response to the first event that triggers the first process to apply for memory, obtaining the memory requirement of the first process; determining a first memory reclaiming method from a plurality of memory reclaiming methods based on the memory requirement and the remaining memory space of the first process; wherein the plurality of memory reclaiming methods correspond to different memory pressures; and reclaiming memory in the first memory reclaiming method based on the first memory reclaiming parameter.
[0023] In a second aspect, the present application provides a memory recovery method, which is applied to an electronic device, and the method includes: obtaining the memory requirement of a first process; determining a target memory recovery method from a plurality of memory recovery methods based on the remaining memory space and the memory requirement of the first process; wherein the plurality of memory recovery methods correspond to different memory pressures; and recovering memory based on memory recovery parameters in the target memory recovery method; wherein the memory recovery parameters include a target memory recovery amount, and the higher the memory pressure corresponding to the target memory recovery method, the smaller the target memory recovery amount, and the higher the urgency of the first process, the smaller the target memory recovery amount.
[0024] In an implementation provided in the second aspect, the urgency of the first process is determined based on system status information and process status information, the system status information is used to indicate memory pressure, and the process status information is used to indicate the impact of the first process on the user experience; wherein the system status information includes at least one of information indicating whether the system is performing garbage collection and information indicating whether there is a process competing with the first process for memory; the process status information includes the priority of the first process, whether the first process is a real-time process, and at least one of the types of the first process, the types of the first process including foreground processes, background processes, and foreground-related processes, and the foreground-related processes are processes that support the operation of foreground processes.
[0025] In a third aspect, the present application provides an electronic device, comprising: a memory and a processor; the processor is coupled to the memory; wherein the memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device executes the method provided in the first aspect, the second aspect, and any one of their implementations.
[0026] In a fourth aspect, the present application provides a computer-readable storage medium comprising computer instructions; when the computer instructions are executed on an electronic device, the electronic device executes the method provided in the first aspect, the second aspect and any one of their implementations.
[0027] In a fifth aspect, the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the method provided in the first aspect, the second aspect, and any one of their implementations.
[0028] Among them, the technical effects brought about by any implementation method in the second to fifth aspects can refer to the technical effects brought about by different implementation methods in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] FIG1 is a memory recycling flow chart provided by the related art;
[0030] FIG2 is a hardware structure diagram of an electronic device provided in an embodiment of the present application;
[0031] FIG3 is a software structure block diagram of an electronic device provided in an embodiment of the present application;
[0032] FIG4 is a flowchart of a memory recycling method according to an embodiment of the present application;
[0033] FIG5 is a second flow chart of a memory recycling method provided in an embodiment of the present application;
[0034] FIG6 is a third flow chart of a memory recycling method provided in an embodiment of the present application;
[0035] FIG7 is a fourth flow chart of a memory recycling method provided in an embodiment of the present application;
[0036] FIG8 is a fifth flow chart of a memory recycling method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The technical solutions in the embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. Among them, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and claims of the present application, the singular expressions "a", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two). The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships can exist; for example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0038] References to "one embodiment" or "some embodiments" etc. described in this specification mean that the specific features, structures or characteristics described in conjunction with the embodiment are included in one or more embodiments of the present application. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. appearing in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in another way. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in another way. The term "connected" includes direct and indirect connections, unless otherwise stated. "First" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.
[0039] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0040] The memory recovery method provided in this application can be used in memory recovery scenarios of electronic devices. Among them, the electronic devices provided in the embodiments of this application can be mobile phones, tablet computers, desktop computers, laptop computers, handheld computers, notebook computers, ultra-mobile personal computers (UMPCs), netbooks, as well as cellular phones, personal digital assistants (PDAs), augmented reality (AR) devices, virtual reality (VR) devices, artificial intelligence (AI) devices, wearable devices, vehicle-mounted devices, smart home devices and / or smart city devices, etc. The embodiments of this application do not impose any special restrictions on the specific type of the electronic device.
[0041] In some related technologies, electronic devices can set a memory watermark. When the remaining memory space is monitored to be lower than the low water level in the memory watermark, asynchronous memory recycling is triggered, such as application killing, memory compression, file page cleaning, etc. However, in actual use, there are some scenarios, such as application startup scenarios, photo / video shooting scenarios, or game application battles and matches, which have high memory requirements. Often, the remaining memory space cannot meet the application requirements, and the kernel needs to perform synchronous memory recycling. Synchronous memory recycling will block the process, that is, the kernel needs to complete memory recycling before allocating memory to the application process, which will cause the application to freeze.
[0042] For example, let's take the scenario of launching a game application. As shown in Figure 1, an electronic device can receive an action in which a user clicks on the game application icon. In response to this action, the game application is launched. Specifically, after the electronic device's desktop detects the user clicking on the game application icon, it can launch the game application through the electronic device's operating system (which can be understood as launching the game application process). The game application can then send a memory request to the electronic device's kernel. This memory request includes the amount of memory space requested by the game application. After receiving the memory request, the kernel can determine whether the remaining memory space of the electronic device is less than the memory space requested by the game application. If the remaining memory space is less than the memory space requested by the game application, the kernel performs synchronous memory reclaim until the remaining memory space is greater than or equal to the memory space requested by the game application. If the remaining memory space is greater than or equal to the memory space requested by the game application, the kernel allocates memory space to the game application to provide memory space for the game application to start, allowing the game application to successfully start.
[0043] It can be seen that when the kernel performs synchronous memory recycling, the more time the kernel spends on memory recycling, the slower the kernel is in meeting the memory needs of the application, the more stuck the application becomes, and the user experience will be seriously affected.
[0044] In view of this, this application provides a memory reclamation method. For synchronous memory reclamation, the target memory reclamation amount is reduced, so that the kernel can exit the memory reclamation process more quickly and allocate memory space to the application process for application operation, thereby reducing application lag caused by slow memory supply. For asynchronous memory reclamation, the target memory reclamation amount is increased. By providing sufficient memory, the kernel can reduce the number of times it enters the synchronous reclamation process, thereby reducing application lag caused by slow memory supply.
[0045] FIG2 is a hardware structure diagram of an electronic device 100 provided in an embodiment of the present application. As shown in FIG2 , the electronic device 100 includes a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone jack 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195.
[0046] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices or integrated into one or more processors. The processor 110 can be the nerve center and command center of the electronic device 100. The processor 110 can generate operation control signals based on instruction opcodes and timing signals to complete the control of instruction fetching and execution.
[0047] In an embodiment of the present application, the processor 110 may perform memory recycling.
[0048] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0049] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0050] It is understood that the interface connection relationship between the modules illustrated in this embodiment is merely an illustrative illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments, the electronic device 100 may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0051] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.
[0052] The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 can execute instructions stored in the internal memory 121, and the internal memory 121 can include a program storage area and a data storage area.
[0053] Among them, the program storage area can store the operating system, at least one application required for a function (such as a recent task management function), etc. The data storage area can store data created during the use of the electronic device 100, for example, it can include the memory requirements of the application, the remaining memory space, etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. In the embodiment of the present application, the memory space to be reclaimed by the kernel is the memory space of the internal memory 121.
[0054] It should be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In other embodiments, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0055] In addition, an operating system runs on top of the above components. Open source operating systems, operating system, The operating system, etc., is not specifically limited here. Application programs can be installed and run on the operating system.
[0056] The operating system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. The software structure of electronic device 100 is illustrated using the system's layered architecture as an example. The layered architecture divides the software into several layers, each with distinct roles and responsibilities. Layers communicate with each other via software interfaces.
[0057] FIG3 is a block diagram of the software structure of a terminal device according to an embodiment of the present application. The software structure includes an application layer and a kernel layer (kernel) (hereinafter referred to as kernel).
[0058] The application layer can include a series of application packages. As shown in Figure 3, the application can include camera, game, social, call and other applications.
[0059] The kernel layer is a layer between hardware and software that provides interaction with the hardware. In an embodiment of the present application, as shown in FIG3 , the kernel layer includes a memory management module, a memory recycling module, a decision center, and a memory recycling optimization module.
[0060] The memory management module is used to determine the target memory recovery method. For a description of the memory recovery method, please refer to the relevant content in S402 and will not be described here for the time being.
[0061] The decision center is used to obtain system status information and process status information, and determine memory reclamation parameters based on the system status information and process status information. The detailed process of obtaining the system status information, process status information, and determining the memory reclamation parameters can be found in the relevant memory in S403 below and will not be described here.
[0062] The memory recycling module is used to recycle memory according to memory recycling parameters.
[0063] The memory recycling optimization module is used to transmit data to the decision center and the memory recycling module, and to determine whether to continue recycling memory.
[0064] It should be noted that the above-mentioned memory recycling optimization module and decision center can be a kernel object (kernel object), such as a dynamic link file used by the kernel. The suffix of the dynamic link file is ".ko", so it can also be called a ko file.
[0065] Among them, the dynamic link files of the memory recycling optimization module and the decision center can be isolated from the kernel native modules (such as the memory management module and the memory recycling module), and the kernel native modules and the dynamic link files (i.e., the memory recycling optimization module and the decision center) can be linked using a hook mechanism.
[0066] The hook mechanism is a technique that alters the program's execution flow. For example, if a normal program runs from A->B->C, a hook mechanism can change the flow to A->D->B->C, where D is the newly added program. During this process, D can access the data passed by A to B, modify or utilize it, and then pass it back to B, all without A or B being aware of the process. Therefore, using the hook mechanism can both minimize the impact on existing kernel programs and optimize the memory reclamation process.
[0067] It should also be noted that the software architecture shown in Figure 3 only shows part of the layers, and the operating system can also include more layers than those shown in Figure 3, such as an application framework layer (framework), a hardware abstraction layer (HAL), etc., and no specific restrictions are made here.
[0068] The memory recycling method provided in the embodiments of the present application will be described below with reference to the accompanying drawings.
[0069] FIG4 is a flow chart of a memory recycling method according to an embodiment of the present application. The memory recycling method can be executed by the electronic device 100 shown in FIG2. As shown in FIG4, the memory recycling method includes:
[0070] S401 : In response to a first event that triggers a first process to request memory, obtain a memory requirement of the first process.
[0071] The first event is any event that triggers the first process to request memory. Different first processes have different corresponding first events. For example, the first process can be the process of any application, and the first event can be the event of the application being started. For another example, if the first process is the process of a game application, the first event can be the event of the game application switching to an interface that requires a lot of rendering. For another example, if the first process is the process of a camera application, the first event can be the event of the camera application recording / shooting an image, etc.
[0072] The memory requirement refers to the amount of memory space required by the first process under the influence of the first event. In an optional embodiment, the electronic device 100 may obtain the memory requirement of the first process after the first process of the electronic device 100 is launched. For example, after the first process is launched, the first process may send a memory request to the kernel of the electronic device 100, and the memory request may include the memory requirement of the first process.
[0073] S402: Determine a target memory reclaiming method according to the remaining memory space and the memory requirement of the first process.
[0074] Memory reclaim methods include three types: memory reclaim using the kernel swap daemon process (kswapd) (referred to as kswapd memory reclaim in this embodiment), direct reclaim, and other memory reclaim methods. Other memory reclaim methods include, for example, OOM (out of memory) memory detection mechanisms.
[0075] All three memory reclamation methods can be used for memory reclamation. Different memory reclamation methods have different impacts on memory supply speed. The kswapd memory reclamation method is asynchronous and does not block processes, resulting in a minimal impact on memory supply speed and application responsiveness. Direct memory reclamation and other memory reclamation methods are synchronous and block processes, significantly impacting memory supply speed and significantly impacting application responsiveness.
[0076] In addition, the triggering timing of different memory reclamation methods varies. Specifically, the triggering timing of different memory reclamation methods is related to the current memory pressure of the system. When memory pressure is relatively low, electronic devices can use the kswapd memory reclamation method; when memory pressure is relatively high, electronic devices can use the direct memory reclamation method; if memory pressure remains high after using the direct memory reclamation method, electronic devices can use other memory reclamation methods.
[0077] In an embodiment of the present application, the electronic device may evaluate the current memory pressure of the system based on the remaining memory space and the memory requirement of the first process. If the remaining memory space is less than the memory requirement, it indicates that the remaining memory space cannot meet the application requirements and the current memory pressure of the system is relatively high. Therefore, the target memory reclamation method is determined to be direct memory reclamation.
[0078] If the remaining memory space is greater than or equal to the required memory space, the electronic device can further assess the system's current memory pressure based on the memory waterline interval in which the remaining memory space is located. The memory waterline interval is divided into a memory waterline low and a memory waterline min, with the memory waterline low being greater than the memory waterline min.
[0079] If the remaining memory space is greater than or equal to the memory waterline min and less than the memory waterline low (that is, memory waterline low ≥ remaining memory space ≥ memory waterline min), it indicates that the current memory pressure of the system is relatively small, so the target memory recovery method is determined to be the kswapd memory recovery method.
[0080] If the remaining memory space is less than the memory waterline min (ie, the remaining memory space < the memory waterline min), it indicates that the current memory pressure of the system is relatively large, and the target memory reclamation method is determined to be the direct memory reclamation method.
[0081] If the remaining memory space of the electronic device 100, such as the kernel of the electronic device 100, is still less than the memory waterline min after memory is reclaimed in a direct memory reclaiming manner, it indicates that the current memory pressure of the system is very high, and the target memory reclaiming manner is determined to be other memory reclaiming manners, such as the OOM memory reclaiming manner.
[0082] It should be noted that if the remaining memory space is greater than the memory waterline low, the kernel does not need to reclaim memory.
[0083] S403: Determine memory reclamation parameters according to the system status information, the process status information, and the target memory reclamation method.
[0084] In an embodiment of the present application, the system status information includes information reflecting the memory status, such as the number of file pages, electronic devices, such as whether the operating system of the electronic device is performing garbage collection (GC) operations, whether there are processes competing with the first process for memory, and other information.
[0085] The process status information may include information reflecting the impact of the first process on the user experience, such as the priority of the first process, whether the first process is a real-time process, and the type of the first process.
[0086] The higher the priority of the first process or the real-time process of the first process, the greater the impact of the response speed of the first process on the user experience.
[0087] The first process types include foreground processes, background processes, and foreground-related processes. Foreground processes are processes that users can interact with on the device; foreground-related processes are processes that support the foreground process; and background processes are processes that the user is unaware of, do not run in the foreground of the device, and do not require user interaction. This shows that the impact of foreground processes, foreground-related processes, and background processes on the user experience decreases in descending order.
[0088] Memory reclamation parameters include the target memory reclamation amount, file page flag, dirty page write-back flag, and reclamation mode.
[0089] Among them, the target memory recovery amount refers to the memory space that the kernel needs to reclaim. It can be understood that the smaller the target memory recovery amount, the shorter the memory recovery time, and thus the faster the memory is allocated to the process, that is, the higher the memory supply efficiency. Among them, the memory recovery time can refer to the electronic device 100, such as the time required for the kernel of the electronic device 100 to reclaim memory. For example, it is the time required from the kernel starting to execute S404 to the kernel determining not to continue to reclaim memory, and for example, it is the time required from the kernel receiving the memory application request of the first process to the kernel allocating memory to the first process.
[0090] The file page flag is used to indicate the number of file pages. In an embodiment of the present application, the number of file pages can be marked by the value of the file page flag. For example, the value of the file page flag can be tiny or empty. A file page flag of tiny indicates that the number of file pages is extremely small; a file page flag of empty indicates that the number of file pages is sufficient. It is understandable that when the number of file pages is extremely small, even if the kernel releases all file pages, it can only reclaim a small amount of memory space. Therefore, the kernel will give priority to reclaiming anonymous pages, which is conducive to improving memory recovery efficiency and reducing memory recovery time.
[0091] The dirty page write back flag is used to indicate whether dirty pages can be written back. In an embodiment of the present application, whether dirty pages can be written back can be marked by the value of the file page flag. For example, the value of the dirty page write back flag can be true or false. If the dirty page write back flag is true, it means that the kernel can write back dirty pages during the memory recovery process; if the dirty page write back flag is false, it means that the kernel cannot write back dirty pages during the memory recovery process. It can be understood that if the kernel cannot write back dirty pages during the memory recovery process, the I / O operations caused by writing back dirty pages can be reduced, which is conducive to improving memory recovery efficiency and reducing memory recovery time.
[0092] The recycling mode is one of the parameters used to determine whether the kernel continues to recycle memory after completing a round of memory recycling. In an embodiment of the present application, the recycling mode may include a first mode and a second mode. Specifically, when the other parameters used to determine whether the kernel continues to recycle memory after completing a round of memory recycling are the same, the first mode may be more likely to cause the kernel to stop reclaiming memory than the second mode, thereby reducing the memory recycling time. Regarding the process of the kernel determining whether to continue reclaiming memory based on the recycling mode and other parameters, see S405, which will not be described here for the time being.
[0093] In an embodiment of the present application, memory optimization strategies corresponding to three types of memory recovery methods are pre-stored in the electronic device. The electronic device 100, such as the kernel of the electronic device 100, can determine the target memory optimization strategy according to the target memory recovery method, and then obtain the memory recovery parameters based on the system status information, the process status information and the target memory optimization strategy.
[0094] Each memory optimization strategy includes a correspondence between system status information, process status information, and memory reclamation parameters. In an embodiment of the present application, the system status information and process status information can be used to assess the urgency of the first process obtaining memory, and the memory reclamation parameters can affect the memory reclamation time. Each memory optimization strategy satisfies the following conditions: the higher the urgency of the first process obtaining memory, the higher the memory reclamation efficiency and the shorter the memory reclamation time. Furthermore, each memory optimization strategy can be used to balance the number of anonymous pages, file pages, and slab caches.
[0095] The following uses the memory optimization policy corresponding to the direct memory reclamation method as an example to illustrate the correspondence between system status information, process status information, and memory reclamation parameters.
[0096] In an optional embodiment, the kernel may determine whether the number of file pages is less than a first value. If the number of file pages is less than or equal to the first value, the file page flag is set to "tiny" (also referred to as the second value); if the number of file pages is greater than the first value, the file page flag is set to "empty." If the file page flag is set to "tiny," the kernel will prioritize anonymous pages during memory reclamation, thereby balancing the number of anonymous pages and file pages.
[0097] The kernel may also determine other memory reclamation parameters based on system status information and / or process status information. Determining memory reclamation parameters based on system status information and process status information may include the following situations:
[0098] (1) If there is a process competing with the first process for memory, the recovery mode is the first mode, the dirty page write-back flag is false (also called the first value), and the target memory recovery amount is the smaller value between the memory demand amount and the preset first memory amount.
[0099] It is understandable that when there is a process competing with the first process for memory, it indicates that there are other processes currently waiting to apply for memory. In order for other processes to apply for memory as quickly as possible, the kernel needs to exit the memory recovery process as quickly as possible, thereby allocating memory to the first process as quickly as possible. Among them, setting the dirty page write-back flag to false can prevent the kernel from writing back dirty pages during the memory recovery process, thereby improving the kernel's memory recovery efficiency. In addition, the purpose of setting the target memory recovery amount to the smaller value of the memory demand amount and the first memory amount is to reduce the memory recovery amount to reduce the time required for memory recovery. That is to say, when there is a process competing with the first process for memory, setting the dirty page write-back flag to false and reducing the memory recovery amount can avoid excessive recovery and shorten the memory recovery time, so that the kernel can exit the memory recovery process as quickly as possible, so as to allocate memory to the first process more quickly, and reduce the problem of the first process and other processes being stuck due to slow memory supply.
[0100] (2) If the priority of the first process is higher than the preset priority, the system is performing a GC operation, and the first process is a real-time process, the recovery mode is the first mode, the dirty page write-back flag is false, and the target memory recovery amount is the smaller value of the memory demand amount and the second memory amount, and the second memory amount is greater than the first memory amount.
[0101] Understandably, the fact that the priority of the first process is higher than the preset priority indicates that the first process has a greater impact on the user experience; the fact that the system is performing a GC operation indicates that the system is under great memory pressure. Furthermore, the fact that the first process is a real-time process indicates that the process has a certain urgency and requires a very quick response to external events. Therefore, the dirty page write-back flag is set to false to improve memory recovery efficiency by reducing I / O operations. Setting the target memory recovery amount to the smaller of the memory demand and the second memory amount aims to reduce the memory recovery amount to shorten the time required for memory recovery. This allows the kernel to exit the memory recovery process as quickly as possible, allocating memory to the first process more quickly and reducing the problem of stalling the first process and other processes due to slow memory supply. At the same time, reducing the memory recovery amount can also avoid excessive memory recovery.
[0102] (3) If the priority of the first process is higher than the preset priority, the system is performing a GC operation, and the first process is not a real-time process, the recycling mode is the first mode, and the dirty page writeback flag is false. In this case, the target memory recycling amount is the memory demand of the first process.
[0103] (4) If the first process is a foreground process and the first process is a real-time process, the recovery mode is the second mode, the dirty page write-back flag is false, and the target memory recovery amount is the smaller value of the memory demand amount and the second memory amount, and the second memory amount is greater than the first memory amount.
[0104] Understandably, the fact that the first process is a foreground process indicates that it has a significant impact on the user experience; the fact that it is a real-time process indicates that it is urgent and requires a very fast response to external events. Therefore, the kernel sets the dirty page writeback flag to false and reduces the amount of memory to be reclaimed, effectively expediting the memory reclamation process.
[0105] (5) If the first process is a foreground process and is not a real-time process, the reclaim mode is set to the second mode, and the dirty page writeback flag is false. In this case, the target memory reclaim amount is not adjusted and is the memory requirement of the first process.
[0106] (6) If the first process is a foreground-related process, the recovery mode is set to the third mode, and the target memory recovery amount is the larger value of the memory demand amount and the third memory amount, and the third memory amount is greater than the second memory amount.
[0107] It can be understood that the first process is a foreground-related process, which indicates that the first process has little impact on the user experience. Therefore, the target memory recovery amount can be set to the larger value of the memory demand amount and the third memory amount, and the memory recovery amount can be appropriately increased to ensure that the kernel can reclaim sufficient memory space.
[0108] (7) If the first process is a background process, the recovery mode is set to the third mode, the file page flag is tiny, and the target memory recovery amount can be the larger value of the memory demand amount and the fourth memory amount, and the fourth memory amount is greater than the third memory amount.
[0109] Understandably, if the first process is a background process, its impact on the user experience is minimal. Therefore, the file page flag can be set to "tiny" to prioritize the kernel's reclaiming of anonymous pages, reducing I / O operations. Furthermore, the target memory reclaim amount can be set to the larger of the memory requirement and the fourth memory amount to increase the memory reclaim amount, allowing the kernel to reclaim sufficient memory space.
[0110] Among them, the above situation (1) corresponds to urgency level 1, the above situation (2) and situation (4) correspond to urgency level 2, the above situation (3) and situation (5) correspond to urgency level 3, the above situation (6) corresponds to urgency level 4, and the above situation (7) corresponds to urgency level 5. Among them, urgency level 1, urgency level 2, urgency level 3, urgency level 4 and urgency level 5 decrease in sequence.
[0111] The memory reclamation parameters corresponding to the above case (1) are substantially the same as those corresponding to the above case (2). The difference is that the target memory reclamation amount 1 corresponding to the above case (1) is the smaller value between the memory demand and the first memory amount, while the target memory reclamation amount 2 corresponding to the above case (2) is the smaller value between the memory demand and the second memory amount. Since the second memory amount is greater than the first memory amount, the memory reclamation amount 1 is less than or equal to the memory reclamation amount 2. Therefore, the memory reclamation time corresponding to the above case (1) is less than or equal to the memory reclamation time corresponding to the above case (2).
[0112] The memory reclamation parameters corresponding to case (2) are roughly the same as those corresponding to case (3). The difference is that the target memory reclamation amount 2 corresponding to case (2) is the smaller of the memory demand and the second memory amount, while the target memory reclamation amount 3 corresponding to case (3) is the memory demand. Therefore, target memory reclamation amount 2 is less than or equal to memory reclamation amount 3, and therefore the memory reclamation time corresponding to case (2) is less than or equal to the memory reclamation time corresponding to case (3).
[0113] The memory reclamation parameters corresponding to the above case (1) are substantially the same as those corresponding to the above case (4). The difference is that the target memory reclamation amount 1 corresponding to the above case (1) is the smaller value between the memory demand and the first memory amount, while the target memory reclamation amount 4 corresponding to the above case (4) is the smaller value between the memory demand and the second memory amount. Since the second memory amount is greater than the first memory amount, the memory reclamation amount 1 is less than or equal to the memory reclamation amount 4. Therefore, the memory reclamation time corresponding to the above case (1) is less than or equal to the memory reclamation time corresponding to the above case (4).
[0114] The memory reclamation parameters corresponding to case (4) are roughly the same as those corresponding to case (5). The difference is that the target memory reclamation amount 4 corresponding to case (4) is the smaller of the memory demand and the second memory amount, while the target memory reclamation amount 5 corresponding to case (5) is the memory demand. Therefore, the target memory reclamation amount 4 is less than or equal to the memory reclamation amount 5, and therefore the memory reclamation time corresponding to case (4) is less than or equal to the memory reclamation time corresponding to case (5).
[0115] The main difference between the memory reclamation parameters corresponding to the above case (5) and the memory reclamation parameters corresponding to the above case (6) is that the target memory reclamation amount 5 corresponding to the above case (5) is the memory demand amount, while the target memory reclamation amount 6 corresponding to the above case (6) is the larger value between the memory demand amount and the third memory amount; and the dirty page write-back flag in the above case (5) is false. Therefore, the memory reclamation amount 5 is less than or equal to the memory reclamation amount 6, and the memory reclamation efficiency is improved in the above case (5) because there is no need to write back dirty pages. Therefore, the memory reclamation time corresponding to the above case (5) is less than or equal to the memory reclamation time corresponding to the above case (6).
[0116] The main difference between the memory recovery parameters corresponding to the above case (6) and the memory recovery parameters corresponding to the above case (7) is that the target memory recovery amount 6 corresponding to the above case (6) is the larger value of the memory demand and the third memory amount, and the target memory recovery amount 7 corresponding to the above case (7) is the larger value of the memory demand and the fourth memory amount, wherein, since the fourth memory amount is greater than the third memory amount, the memory recovery amount 6 is less than or equal to the memory recovery amount 7; and considering that the file page flag in the above case (7) is tiny, which will cause the kernel to give priority to reclaiming anonymous pages and affect the memory recovery efficiency, the memory recovery time corresponding to the above case (6) is less than or equal to the memory recovery time corresponding to the above case (7).
[0117] It should be noted that, when the target memory recovery method is the kswapd memory recovery method or other memory recovery methods (such as OOM), the kernel determines the memory recovery parameters in a similar manner to the above process. The difference is that, when the system status information and process status information are the same, the target memory recovery amounts corresponding to the three memory recovery methods are different. Among them, the memory optimization strategies of the kswapd memory recovery method, the direct memory recovery method, and other memory recovery methods meet the following requirements: when the system status information and the process status information are the same, the target memory recovery amounts corresponding to the kswapd memory recovery method, the direct memory recovery method, and the OOM memory recovery method decrease in sequence, and the memory recovery times corresponding to the kswapd memory recovery method, the direct memory recovery method, and the OOM memory recovery method decrease in sequence.
[0118] For example, when the target memory recovery mode is the kswapd memory recovery mode, the memory optimization strategy may have the following corresponding relationship: when the system status information and the process status information meet the above situation (1), the recovery mode is the first mode, the dirty page write-back flag is set to false, and the target memory recovery amount is the smaller value between the memory demand amount and the fifth memory amount, and the fifth memory amount is greater than the first memory amount.
[0119] It can be understood that, since the fifth memory amount is greater than the first memory amount, when the system status information and process status information meet the above condition (1), the target memory recovery amount corresponding to the kswapd memory recovery method (greater than or equal to the fifth memory amount) is greater than or equal to the target memory recovery amount corresponding to the direct memory recovery method (greater than or equal to the first memory amount). And since other memory recovery parameters are consistent, the memory recovery time corresponding to the kswapd memory recovery method is greater than the memory recovery time corresponding to the direct memory recovery method.
[0120] For another example, when the system status information and the process status information meet the above situation (2), the recovery mode is the first mode, the dirty page write-back flag is set to false, and the target memory recovery amount is the smaller value between the memory demand amount and the sixth memory amount, and the sixth memory amount is greater than the second memory amount.
[0121] Among them, by increasing the target memory recovery amount of the kswapd memory recovery method, the kswapd memory recovery method can reclaim more memory space, thereby reducing the situation where the kernel enters the synchronous recovery process and alleviating the application lag caused by slow memory supply.
[0122] In other implementations, the kernel may also adjust other information in the memory recovery parameters, without specific limitation here, as long as the conditions that the memory recovery times corresponding to the kswapd memory recovery method, direct memory recovery method, and OOM memory recovery method are reduced in sequence are met.
[0123] S404: Perform memory reclamation according to the memory reclamation parameters to obtain an actual memory reclamation amount.
[0124] In an embodiment of the present application, the electronic device 100, such as the kernel of the electronic device 100, can be scanned in the order of zone, node, and memory control group (memcg), and during the scanning process, memory pages can be determined and released based on memory recovery parameters such as dirty page write-back flag and file page flag.
[0125] It is understandable that once the kernel has scanned all memcgs, a round of memory reclamation is complete. S404 can be understood as the process of a round of memory reclamation. During a memory reclamation process, the kernel can perform at least one round of memory reclamation. The actual memory reclaimed amount can refer to the total amount of memory reclaimed by the kernel in all memory reclamation rounds.
[0126] S405: Determine whether to continue memory recycling.
[0127] In an embodiment of the present application, the electronic device 100, such as the core of the electronic device 100, may determine whether to continue memory reclamation after completing a round of memory reclamation.
[0128] When the reclamation mode is the first mode, if the actual memory reclamation amount is greater than or equal to the target memory reclamation amount, the kernel does not continue to perform memory reclamation and executes S406.
[0129] If the reclamation mode is the second mode, or the actual memory reclamation amount is less than the target memory reclamation amount, the kernel may further determine whether to continue memory reclamation based on the first memory reclamation exit mechanism. The first memory reclamation exit mechanism is the kernel's native memory reclamation exit mechanism and is dependent on factors such as the actual memory reclamation amount, the target memory reclamation amount, whether dirty pages are written back during the reclamation process, and whether the dirty page writeback is complete. If the first memory reclamation exit mechanism is satisfied, the kernel does not continue memory reclamation and executes S406. If the first memory reclamation exit mechanism is not satisfied, the kernel continues memory reclamation and re-executes S404.
[0130] S406: Allocate memory to the first process according to the memory requirement.
[0131] After exiting the memory reclaiming process, the kernel may allocate memory to the first process according to the memory requirement applied for by the first process, so that the first process performs corresponding operations.
[0132] It can be seen that the present application can set different memory recovery amounts for different memory recovery methods, and the greater the memory pressure corresponding to the memory recovery method, the less memory recovery amount. This can not only enable the kswapd memory recovery method to reclaim more memory space and reduce the probability of triggering the kernel to perform synchronous memory recovery, but also enable the kernel to quickly exit the memory recovery process when performing synchronous memory recovery, quickly supply memory to the application process, reduce the application's lag, and improve the user experience.
[0133] In addition, this application combines system status information and process status information to set the memory recovery amount. The higher the urgency of the process indicated by the system status information and process status information, the less memory recovery amount. This allows the kernel to quickly exit the memory recovery process and provide memory to the application process as soon as possible, reducing the application's lag and improving the user experience.
[0134] The following will further illustrate the memory recovery method provided by this application based on the software architecture shown in Figure 3.
[0135] 5 , which is a second flow chart of the memory reclaiming method provided in an embodiment of the present application. As shown in FIG5 , the memory reclaiming method provided in an embodiment of the present application includes S501 to S521.
[0136] S501: A first process sends a memory application request to a memory management module.
[0137] After being started, the first process may send a memory application request to the kernel, wherein the memory application request carries the memory requirement of the first process.
[0138] S502: The memory management module obtains the memory requirement of the first process.
[0139] The memory management module may obtain the memory requirement of the first process from the memory application request.
[0140] S503: The memory management module determines a target memory reclaiming method according to the remaining memory space and the memory requirement of the first process.
[0141] The process of the memory management module determining the target memory reclaiming method may be referred to in S402 and will not be described in detail here.
[0142] S504: The memory management module sends a memory reclaiming notification to the memory reclaiming module.
[0143] The memory recycling notification may be used to indicate a target memory recycling method.
[0144] In an optional embodiment, the memory management module may send a memory reclamation notification to the memory reclamation module via a function call. Specifically, for different memory reclamation methods, the memory management module may call different functions to send the memory reclamation notification to the memory reclamation module. For example, the memory management module may call the try_to_free_pages function to trigger the direct memory reclamation method.
[0145] S505: The memory recycling module initializes memory recycling parameters.
[0146] Initializing the memory reclamation parameters can be understood as assigning initial values to various parameters in the memory reclamation parameters. For example, the initial value of the target memory reclamation amount is the memory demand of the first process.
[0147] In an optional implementation, the memory reclaim module may use the set_task_reclaim_state function to initialize the memory reclaim parameters.
[0148] S506: The memory recycling module sends a notification of setting a memory recycling method to the memory recycling optimization module.
[0149] The notification of setting the memory recycling method may be used to indicate a target memory recycling method.
[0150] S507: The memory recycling optimization module sets the memory recycling flag to a flag corresponding to the target memory recycling method.
[0151] In an embodiment of the present application, the memory recycling parameters may further include a memory recycling flag. The memory recycling optimization module may identify the memory recycling method through the memory recycling flag. The memory recycling flag may be kswapd, direct reclaim, or others. If the memory recycling flag is kswapd, it indicates that the memory recycling method is the kswapd memory recycling method; if the memory recycling flag is direct reclaim, it indicates that the memory recycling method is the direct memory recycling method; if the memory recycling flag is others, it indicates that the memory recycling method is other memory recycling methods.
[0152] Therefore, if the target memory reclamation method is kswapd, the memory reclamation module can set the memory reclamation flag to the flag corresponding to the kswapd memory reclamation method, that is, kswapd. If the target memory reclamation method is direct, the memory reclamation flag can be set to the flag corresponding to the direct memory reclamation method, that is, direct reclaim. If the target memory reclamation method is OOM, the memory reclamation optimization module can set the memory reclamation flag to the flag corresponding to the OOM memory reclamation method, that is, others.
[0153] S508: The memory recycling optimization module sends a setting completion notification to the memory recycling module.
[0154] The notification of setting completion can be understood as a reply operation after the memory recycling optimization module completes S507.
[0155] S509: The memory recycling module sends a notification of updating memory recycling parameters to the memory recycling optimization module.
[0156] S510: The memory recycling optimization module sends a notification of optimizing memory recycling parameters to the decision center.
[0157] The notification of optimizing the memory reclamation parameters may be used to indicate a target memory reclamation method (eg, a direct memory reclamation method).
[0158] S511, the decision center determines memory reclamation parameters according to the system status information, the process status information and the target memory reclamation method.
[0159] The process of the decision center determining the memory recycling parameters may be referred to in S403 and will not be described in detail here.
[0160] S512: The decision center sends the updated memory recycling parameters to the memory recycling optimization module.
[0161] S513: The memory recycling optimization module uses the updated memory recycling parameters to overwrite the original memory recycling parameters.
[0162] S514: The memory recycling optimization module sends an update notification to the memory recycling module.
[0163] This update notification indicates that there is an update to the memory reclamation parameters.
[0164] S515: The memory recycling module performs memory recycling according to the updated memory recycling parameters to obtain an actual memory recycling amount.
[0165] In an optional manner, the memory recovery module may call the do_try_to_free_pages, shrink_zones, shrink_nodes, and shrink_memcgs functions in sequence to scan in the order of zones, nodes, and memcgs, and determine and release memory pages based on memory recovery parameters such as the dirty page write-back flag and the file page flag during the scanning process.
[0166] It can be understood that once the kernel has scanned all memcgs, a round of memory reclamation is complete. S515 can be understood as the process of a round of memory reclamation. During a memory reclamation process, the kernel can perform at least one round of memory reclamation. The actual memory reclaimed amount can refer to the total amount of memory reclaimed by the kernel in all memory reclamation rounds.
[0167] S516: The memory recycling module sends a notification to the memory recycling optimization module to determine whether to continue to recycle memory.
[0168] In an embodiment of the present application, after completing each round of memory recycling, the memory recycling module may send a notification to the memory recycling optimization module to determine whether to continue recycling memory.
[0169] S517: The memory recycling optimization module obtains a first result according to the recycling mode, the actual memory recycling amount, and the target memory recycling amount.
[0170] The first result may indicate whether to continue or not to continue reclaiming memory. In an optional embodiment, the value of the first result may be true or false. If the value of the first result is true, it indicates that memory reclaiming is to continue; if the value of the first result is false, it indicates that memory reclaiming is not to continue.
[0171] If the recovery mode is the first mode and the actual memory recovery amount is greater than or equal to the target memory recovery amount, a first result indicating not to continue memory recovery is generated, for example, the value of the first result is set to false; if the recovery mode is the second mode, or the actual memory recovery amount is less than the target memory recovery amount, a first result indicating continuing memory recovery is generated, for example, the value of the first result is set to true.
[0172] S518: The memory recycling optimization module sends the first result to the memory recycling module.
[0173] S519: The memory recycling module determines whether to continue to recycle memory according to the first result and the first memory recycling exit mechanism.
[0174] If the first result indicates that memory recycling should not continue, the memory recycling module does not continue to recycle memory and executes S520. If the first result indicates that memory recycling should continue, the memory recycling module further determines whether to continue memory recycling based on the first memory recycling exit mechanism. If the first memory recycling exit mechanism is satisfied, the memory recycling module does not continue to recycle memory and executes S520. If the first memory recycling exit mechanism is not satisfied, the memory recycling module continues to recycle memory and executes S515 again.
[0175] In an optional implementation, the memory recovery module may implement the judgment described in S519 according to the continue_reclaim function.
[0176] S520: The memory recycling module sends a notification of memory recycling completion to the memory management module.
[0177] S521: The memory management module allocates memory to the first process according to the memory requirement.
[0178] In an optional embodiment, the above-mentioned S506 to S508, S509 to S514, and S516 to S518 can be implemented using a hook mechanism. For example, when the target recovery method is the direct recovery method, add hook point 1 between the set_task_reclaim_state function and the do_try_to_free_pages function to implement the above-mentioned S506 to S508. Add hook point 2 between the do_try_to_free_pages function and the shrink_nodes function to implement the above-mentioned S509 to S514. And add hook point 3 between the shrink_memcgs function and the continue_reclaim function to implement the above-mentioned S516 to S518. The use of the hook mechanism can greatly reduce the impact of the improvement on the original memory recovery process.
[0179] 6, which is a flowchart diagram of the memory recycling method provided in the embodiment of the present application. As shown in FIG6, the memory recycling method provided in the embodiment of the present application includes S601 to S621.
[0180] S601: Process 1 sends a memory request to the memory management module.
[0181] S602: The memory management module obtains the memory requirement 1 of process 1 (50 MB).
[0182] In the embodiment of the present application, the memory requirement of process 1 is memory requirement 1, for example, 50 MB.
[0183] S603: The memory management module determines that the target memory reclamation mode is the synchronous memory reclamation mode according to the remaining memory space (40 MB) and the memory requirement 1.
[0184] In the embodiment of the present application, the remaining memory space is 40 MB. Since the memory demand 1 (50 MB) is smaller than the remaining memory space (40 MB), the memory management module determines that the target memory recycling method is the synchronous memory recycling method.
[0185] S604: The memory management module sends a memory reclaiming notification to the memory reclaiming module.
[0186] S605: The memory recycling module initializes memory recycling parameters.
[0187] S606: The memory recycling module sends a notification of setting a memory recycling method to the memory recycling optimization module.
[0188] S607: The memory reclaim optimization module sets the memory reclaim flag to direct reclaim.
[0189] In the embodiment of the present application, the memory reclaim optimization module sets the memory reclaim flag to a flag corresponding to the synchronous memory reclaim mode, namely, direct reclaim.
[0190] S608: The memory recycling optimization module sends a setting completion notification to the memory recycling module.
[0191] S609: The memory recycling module sends a notification of updating memory recycling parameters to the memory recycling optimization module.
[0192] S610: The memory recycling optimization module sends a notification of optimizing memory recycling parameters to the decision center.
[0193] S611, the decision center determines that the target memory recovery amount in the memory recovery parameters is the target memory recovery amount 1 (30MB) based on the system status information (indicating that the system is performing GC operation and the number of file pages is less than the first value), the process status information (indicating that the priority of process 1 is higher than the preset priority and process 1 is a real-time process) and the synchronous memory recovery method, the recovery mode is the first mode, the dirty page write back flag is false, and the file page flag is tiny.
[0194] In this embodiment of the present application, the process status information indicates that the priority of process 1 is higher than the preset priority and that process 1 is a real-time process. The system status information indicates that the system is performing a garbage collection (GC) operation, the number of file pages is less than a first value, and that synchronous memory reclamation is being used. Furthermore, the second memory size is 30 MB.
[0195] Therefore, the decision center determines that the target memory recovery amount in the memory recovery parameters is the smaller value between the memory demand amount 1 (i.e. 50MB) and the second memory amount (i.e. 30MB), that is, 30MB (i.e., the target memory recovery amount 1 is 30MB), the recovery mode is the first mode, the dirty page write back flag is false, and the file page flag is tiny.
[0196] S612: The decision center sends the updated memory recycling parameters to the memory recycling optimization module.
[0197] S613: The memory reclamation optimization module uses the updated memory reclamation parameters to overwrite the original memory reclamation parameters.
[0198] S614: The memory recycling optimization module sends an update notification to the memory recycling module.
[0199] S615 , the memory recycling module performs memory recycling according to the updated memory recycling parameters, and obtains an actual memory recycling amount 1 (35 MB).
[0200] S616: The memory recycling module sends a notification to the memory recycling optimization module to determine whether to continue recycling memory.
[0201] S617 , the memory recycling optimization module obtains a first result indicating not to continue recycling memory according to the recycling mode, the actual memory recycling amount 1 , and the target memory recycling amount 1 .
[0202] In the embodiment of the present application, since the actual memory recovery amount 1 (ie, 35MB) is greater than the target memory recovery amount 1 (ie, 30MB), and the recovery mode is the first mode, the memory recovery optimization module obtains the first result indicating not to continue to recycle memory.
[0203] S618: The memory recycling optimization module sends a first result indicating not to continue to recycle memory to the memory recycling module.
[0204] S619: The memory recycling module determines whether to continue to recycle memory according to the first result and the first memory recycling exit mechanism.
[0205] Since the first result indicates not to continue reclaiming the memory, the memory reclaiming module does not continue to reclaim the memory and executes S620.
[0206] S620: The memory recycling module sends a notification of memory recycling completion to the memory management module.
[0207] S621: The memory management module allocates 50 MB of memory space to process 1.
[0208] 7, which is a fourth flow chart of the memory reclaiming method provided in an embodiment of the present application. As shown in FIG7, the memory reclaiming method provided in an embodiment of the present application includes S701 to S721.
[0209] S701: Process 2 sends a memory request to the memory management module.
[0210] S702: The memory management module obtains the memory requirement 2 (60 MB) of process 2.
[0211] In the embodiment of the present application, the memory requirement of process 2 is memory requirement 2, for example, 60 MB.
[0212] S703: The memory management module determines that the target memory recovery mode is the kswapd memory recovery mode according to the remaining memory space (70 MB) and the memory requirement 2.
[0213] In an embodiment of the present application, the remaining memory space is 70MB, the memory watermark min is 30MB and the memory watermark low is 100MB. Since the memory watermark low (i.e. 100MB) > the remaining memory space (i.e. 70MB) > the memory watermark min (i.e. 30MB), the memory management module determines that the target memory recovery method is the kswapd memory recovery method.
[0214] S704: The memory management module sends a memory reclaiming notification to the memory reclaiming module.
[0215] S705: The memory recycling module initializes memory recycling parameters.
[0216] S706: The memory recycling module sends a notification of setting a memory recycling method to the memory recycling optimization module.
[0217] S707: The memory recycling optimization module sets the memory recycling flag to kswapd.
[0218] In an embodiment of the present application, the memory recovery optimization module sets the memory recovery flag to the flag corresponding to the kswapd memory recovery method, namely kswapd.
[0219] S708: The memory recycling optimization module sends a setting completion notification to the memory recycling module.
[0220] S709: The memory recycling module sends a notification of updating memory recycling parameters to the memory recycling optimization module.
[0221] S710: The memory recycling optimization module sends a notification of optimizing memory recycling parameters to the decision center.
[0222] S711, the decision center determines that the target memory recovery amount in the memory recovery parameters is the target memory recovery amount 2 (50MB) based on the system status information (indicating that the system is performing GC operation and the number of file pages is less than the first value), the process status information (indicating that the priority of process 2 is higher than the preset priority and process 2 is a real-time process) and the synchronous memory recovery method, the recovery mode is the first mode, the dirty page write back flag is false, and the file page flag is tiny.
[0223] In this embodiment of the present application, the process status information indicates that the priority of process 2 is higher than the preset priority and that process 2 is a real-time process. The system status information indicates that the system is performing a garbage collection operation, the number of file pages is less than a first value, and memory reclamation is performed using synchronous memory reclamation. Furthermore, the sixth memory amount is 50 MB.
[0224] Therefore, the decision center determines that the target memory recovery amount in the memory recovery parameters is the smaller value between the memory demand amount 2 (60MB) and the sixth memory amount (50MB), that is, 50MB (that is, the target memory recovery amount 2 is 50MB), the recovery mode is the first mode, the dirty page write back flag is false, and the file page flag is tiny.
[0225] S712: The decision center sends the updated memory recycling parameters to the memory recycling optimization module.
[0226] S713: The memory reclamation optimization module uses the updated memory reclamation parameters to overwrite the original memory reclamation parameters.
[0227] S714: The memory recycling optimization module sends an update notification to the memory recycling module.
[0228] S715 , the memory recycling module performs memory recycling according to the updated memory recycling parameters, and obtains an actual memory recycling amount 2 (60 MB).
[0229] S716: The memory recycling module sends a notification to the memory recycling optimization module to determine whether to continue recycling memory.
[0230] S717 , the memory recycling optimization module obtains a first result indicating not to continue recycling memory according to the recycling mode, the actual memory recycling amount 2 , and the target memory recycling amount 2 .
[0231] In the embodiment of the present application, since the actual memory recovery amount 2 (ie, 60MB) is greater than the target memory recovery amount 2 (ie, 50MB), and the recovery mode is the first mode, the memory recovery optimization module obtains the first result indicating not to continue to recycle memory.
[0232] S718: The memory recycling optimization module sends a first result indicating not to continue to recycle memory to the memory recycling module.
[0233] S719: The memory recycling module determines whether to continue to recycle memory based on the first result and the first memory recycling exit mechanism.
[0234] Since the first result indicates not to continue reclaiming the memory, the memory reclaiming module does not continue to reclaim the memory and executes S720.
[0235] S720: The memory recycling module sends a notification of memory recycling completion to the memory management module.
[0236] S721: The memory management module allocates 60 MB of memory space to process 2.
[0237] Comparing Figures 6 and 7, we can see that for the memory demand of process 1, the kernel uses the synchronous memory reclamation method, with a target memory reclamation amount of 1 (30MB). For the memory demand of process 2, the kernel uses the kswapd memory reclamation method, with a target memory reclamation amount of 2 (50MB). Furthermore, the memory pressure corresponding to the memory reclamation method for process 1 is greater than the memory pressure corresponding to the memory reclamation method for process 2. This shows that when processes with the same urgency level use different memory reclamation methods, the greater the memory pressure corresponding to the memory reclamation method, the smaller the target memory reclamation amount.
[0238] 8, which is a flowchart diagram 5 of the memory recycling method provided in the embodiment of the present application. As shown in FIG8, the memory recycling method provided in the embodiment of the present application includes S801 to S821.
[0239] S801, process 3 sends a memory application request to the memory management module.
[0240] S802: The memory management module obtains the memory requirement 3 (50 MB) of process 3.
[0241] In the embodiment of the present application, the memory requirement of process 3 is memory requirement 3, for example, 50 MB.
[0242] S803: The memory management module determines that the target memory reclamation mode is the synchronous memory reclamation mode according to the remaining memory space (40 MB) and the memory requirement 3.
[0243] In the embodiment of the present application, the remaining memory space is 40 MB. Since the memory requirement 3 (50 MB) is smaller than the remaining memory space (40 MB), the memory management module determines that the target memory recycling method is the synchronous memory recycling method.
[0244] S804: The memory management module sends a memory reclaiming notification to the memory reclaiming module.
[0245] S805: The memory recycling module initializes memory recycling parameters.
[0246] S806: The memory recycling module sends a notification of setting a memory recycling method to the memory recycling optimization module.
[0247] S807: The memory reclaim optimization module sets the memory reclaim flag to direct reclaim.
[0248] In the embodiment of the present application, the memory reclaim optimization module sets the memory reclaim flag to a flag corresponding to the synchronous memory reclaim mode, namely, direct reclaim.
[0249] S808: The memory recycling optimization module sends a setting completion notification to the memory recycling module.
[0250] S809: The memory recycling module sends a notification of updating memory recycling parameters to the memory recycling optimization module.
[0251] S810: The memory recycling optimization module sends a notification of optimizing memory recycling parameters to the decision center.
[0252] S811, the decision center determines that the target memory recovery amount in the memory recovery parameters is the target memory recovery amount 3 (20MB) based on the system status information (indicating that there is a process competing with process 3 for memory and the number of file pages is less than the first value) and the synchronous memory recovery method, the recovery mode is the first mode, the dirty page write back flag is false, and the file page flag is tiny.
[0253] In this embodiment of the present application, the system status information indicates that there is a process competing with process 3 for memory, the number of file pages is less than a first value, and memory reclamation is performed using a synchronous memory reclamation method. Furthermore, the first memory amount is 20 MB.
[0254] Therefore, the decision center determines that the target memory recovery amount in the memory recovery parameters is the smaller value between the memory demand amount 3 (i.e. 50MB) and the first memory amount (i.e. 20MB), that is, 20MB (i.e., the target memory recovery amount 3 is 20MB), the recovery mode is the first mode, the dirty page write back flag is false, and the file page flag is tiny.
[0255] S812: The decision center sends the updated memory recycling parameters to the memory recycling optimization module.
[0256] S813: The memory reclamation optimization module uses the updated memory reclamation parameters to overwrite the original memory reclamation parameters.
[0257] S814: The memory recycling optimization module sends an update notification to the memory recycling module.
[0258] S815, the memory recycling module performs memory recycling according to the updated memory recycling parameters, and obtains an actual memory recycling amount 3 (35 MB).
[0259] S816: The memory recycling module sends a notification to the memory recycling optimization module to determine whether to continue recycling memory.
[0260] S817 , the memory reclamation optimization module obtains a first result indicating not to continue reclaiming memory according to the reclamation mode, the actual memory reclamation amount 3 , and the target memory reclamation amount 3 .
[0261] In the embodiment of the present application, since the actual memory recovery amount 3 (ie, 35MB) is greater than the target memory recovery amount 3 (ie, 20MB), and the recovery mode is the first mode, the memory recovery optimization module obtains the first result indicating not to continue to recycle memory.
[0262] S818: The memory recycling optimization module sends a first result indicating not to continue to recycle memory to the memory recycling module.
[0263] S819: The memory recycling module determines whether to continue to recycle memory based on the first result and the first memory recycling exit mechanism.
[0264] Since the first result indicates not to continue reclaiming the memory, the memory reclaiming module does not continue to reclaim the memory and executes S820.
[0265] S820: The memory recycling module sends a notification of memory recycling completion to the memory management module.
[0266] S821: The memory management module allocates 50MB of memory space to process 3.
[0267] Comparing Figures 6 and 8, we can see that for process 1's memory request, the kernel uses synchronous memory reclamation, with a target memory reclamation amount of 1 (30MB). For process 3's memory request, the kernel uses synchronous memory reclamation, with a target memory reclamation amount of 3 (20MB). Furthermore, the urgency of process 1 is lower than that of process 3. This shows that, given the same memory reclamation method and the same process urgency, the higher the process urgency, the smaller the target memory reclamation amount.
[0268] To sum up, this application adaptively sets different target memory recovery amounts for different types of memory recovery methods, corresponding to different memory recovery efficiencies, and reduces the memory supply time to achieve the effect of reducing application lag caused by slow memory supply.
[0269] An embodiment of the present application further provides a chip system, which includes at least one processor and at least one interface circuit. The processor and the interface circuit can be interconnected via lines. For example, the interface circuit can be used to receive signals from other devices (such as a memory of an electronic device). For another example, the interface circuit can be used to send signals to other devices (such as a processor). Exemplarily, the interface circuit can read instructions stored in the memory and send the instructions to the processor. When the instructions are executed by the processor, the electronic device or server can perform the various steps in the above embodiments. Of course, the chip system can also include other discrete devices, which is not specifically limited in the embodiment of the present application.
[0270] This embodiment further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes each function or step in the above method embodiment.
[0271] This embodiment further provides a computer program product. When the computer program product is run on an electronic device, the electronic device is enabled to perform each function or step in the above method embodiment.
[0272] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory to enable the chip to perform the various functions or steps performed by the mobile phone in the above method embodiment.
[0273] Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0274] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0275] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0276] The units described as separate components may or may not be physically separate, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0277] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0278] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0279] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and are not intended to limit the present application. Although the present application has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present application may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present application.
Claims
1. A memory recycling method, characterized in that, applied to an electronic device, the method includes: responding to a first event that triggers a first process to apply for memory, and recycling memory in a first memory recycling manner based on first memory recycling parameters; responding to a second event that triggers a second process to apply for memory, and recycling memory in a second memory recycling manner based on second memory recycling parameters; wherein, the first memory recycling parameters include a first target memory recycling amount, and the second memory recycling parameters include a second target memory recycling amount; in the case where the urgency of the first process is the same as the urgency of the second process, and the memory pressure corresponding to the first memory recycling manner is higher than the memory pressure corresponding to the second memory recycling manner, the first target memory recycling amount is less than the second target memory recycling amount; in the case where the urgency of the first process is higher than the urgency of the second process, and the first memory recycling manner is the same as the second memory recycling manner, the first target memory recycling amount is less than the second target memory recycling amount.
2. The method according to claim 1, characterized in that, the urgency of the first process is determined according to system status information and process status information, the system status information is used to indicate memory pressure, and the process status information is used to indicate the degree of influence of the first process on user experience; wherein, the system status information includes at least one of information indicating whether the electronic device is performing garbage collection and information indicating whether there is a process competing for memory with the first process; the process status information includes at least one of the priority of the first process, whether the first process is a real-time process, and the type of the first process, the type of the first process includes a foreground process, a background process, and a foreground-related process, and the foreground-related process is a process that supports the operation of the foreground process.
3. The method according to claim 2, characterized in that, in the case where the system status information and the process status information meet a first condition, the target memory demand is a first target memory demand, and the first target memory demand is less than or equal to the memory demand of the first process; in the case where the system status information and the process status information meet a second condition, the target memory demand is a second target memory demand, and the second target memory demand is equal to the memory demand of the first process; in the case where the system status information and the process status information meet a third condition, the target memory demand is a third target memory demand, and the third target memory demand is greater than or equal to the memory demand of the first process; Wherein, when the system status information and the process status information satisfy the first condition, the urgency level of the first process is higher than that when the system status information and the process status information satisfy the second condition, and when the system status information and the process status information satisfy the second condition, the urgency level of the first process is higher than that when the system status information and the process status information satisfy the third condition.
4. The method according to claim 3, wherein, the first condition includes: there is a process competing for memory with the first process; or, the electronic device is performing garbage collection, the priority of the first process is higher than a preset priority, and the first process is a real-time process; or, the first process is a foreground process and the first process is a real-time process.
5. The method according to claim 3, wherein, the second condition includes: the electronic device is performing garbage collection, the priority of the first process is higher than a preset priority, and the first process is not a real-time process; or, the first process is a foreground process and the first process is not a real-time process.
6. The method according to claim 3, wherein, the third condition includes: the first process is a foreground-related process or a background process.
7. The method according to any one of claims 2-6, wherein, the memory recovery parameter further includes a dirty page write-back flag bit; when the system status information and the process status information satisfy the fourth condition, the dirty page write-back flag bit is a first value, and the dirty page write-back flag bit being the first value indicates that no dirty page write-back operation is performed during the memory recovery process; wherein, the fourth condition includes: there is a process competing for memory with the first process; or, the electronic device is performing garbage collection and the priority of the first process is higher than a preset priority; or, the first process is a foreground process.
8. The method according to any one of claims 2-7, wherein, the memory recovery parameter further includes a recovery mode; when the system status information and the process status information satisfy the fifth condition, the recovery mode is a first mode; wherein, when the recovery mode is the first mode, the electronic device does not continue to recover memory when the actual memory recovery amount is greater than or equal to the target memory recovery amount; wherein, the fifth condition includes: there is a process competing for memory with the first process; or, the electronic device is performing garbage collection and the priority of the first process is higher than a preset priority.
9. The method according to any one of claims 1-8, wherein, the system status information includes the number of file pages, and the memory recovery parameter further includes a file page flag bit; when the number of file pages is less than or equal to a first value, the file page flag bit is a second value, and the file page flag bit being the second value indicates that anonymous pages are preferentially recovered during the memory recovery process.
10. The method according to any one of claims 1-9, wherein, In response to a first event that triggers a first process to apply for memory, memory is reclaimed in a first memory reclaiming manner based on first memory reclaiming parameters, including: In response to a first event that triggers a first process to apply for memory, obtain the memory requirement of the first process; Determine the first memory reclaiming manner from multiple memory reclaiming manners according to the memory requirement of the first process and the remaining memory space; wherein, the multiple memory reclaiming manners correspond to different memory pressures; Reclaim memory in the first memory reclaiming manner based on the first memory reclaiming parameters.
11. A memory reclaiming method, characterized in that, applied to an electronic device, the method includes: Obtain the memory requirement of a first process; Determine a target memory reclaiming manner from multiple memory reclaiming manners according to the remaining memory space and the memory requirement of the first process; wherein, the multiple memory reclaiming manners correspond to different memory pressures; Reclaim memory in the target memory reclaiming manner based on memory reclaiming parameters; wherein, the memory reclaiming parameters include a target memory reclaiming amount, the higher the memory pressure corresponding to the target memory reclaiming manner, the smaller the target memory reclaiming amount, and the higher the urgency of the first process, the smaller the target memory reclaiming amount.
12. The method according to claim 11, characterized in that, the urgency of the first process is determined according to system status information and process status information, the system status information is used to indicate the memory pressure, and the process status information is used to indicate the degree of influence of the first process on the user experience; wherein, the system status information includes at least one of information indicating whether the system is performing garbage collection and information indicating whether there is a process competing for memory with the first process; the process status information includes at least one of the priority of the first process, whether the first process is a real-time process, and the type of the first process, the type of the first process includes a foreground process, a background process, and a foreground-related process, and the foreground-related process is a process that supports the operation of the foreground process.
13. An electronic device, characterized in that, the electronic device includes: a memory and a processor; the processor is coupled to the memory; wherein, the memory is used to store computer program code, and the computer program code includes computer instructions; when the computer instructions are executed by the processor, the electronic device is caused to execute the method according to any one of claims 1-12.
14. A computer-readable storage medium, characterized in that, including computer instructions; when the computer instructions are run on an electronic device, the electronic device is caused to execute the method according to any one of claims 1-12.