Memory recovery method and electronic device

By configuring the recycling level for each application's memory management group and giving priority to recycling memory in efficient groups, the problem of low memory recycling efficiency and poor user experience in Linux systems is solved, achieving more efficient memory management and improving user experience.

WO2024221903A1PCT designated stage expired Publication Date: 2024-10-31HONOR DEVICE CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2023/134800
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-23
Filing Date
2023-11-28
Publication Date
2024-10-31

AI Technical Summary

Technical Problem

When the Linux system recycles memory, each memcg has different recycling rates, resulting in low memory recycling efficiency and a lack of priority recycling strategy, which affects the user experience, especially improper memory recycling for foreground applications.

Method used

Configure the recycling level based on the memory recycling efficiency of each application's memory management group, give priority to recycling memory in efficient groups, calculate the memory recycling efficiency based on historical data, set the recycling level, traverse and scan memory management groups appropriately, and avoid excessive memory recycling.

Benefits of technology

It improves the overall memory recycling efficiency of the system, reduces the impact of memory recycling on common and foreground applications, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023134800_31102024_PF_FP_ABST
    Figure CN2023134800_31102024_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are a memory recovery method and an electronic device. The method comprises: if a memory recovery process trigger condition is met, according to historical data of memory recovery, acquiring a memory recovery efficiency of a memory Cgroup corresponding to each application in the current electronic device; according to the acquired memory recovery efficiency, setting a recovery level of the memory Cgroup corresponding to each application; and on the basis of a recovery priority and the recovery level of each memory Cgroup, determining a target memory Cgroup which requires to be traversed, scanning the target memory Cgroup, and recovering a recoverable memory which is obtained by means of scanning. In this way, a memory recovery level of each application is configured on the basis of a memory recovery efficiency of a memory Cgroup corresponding to each application, and the memory of an application which is ranked at the top in terms of recovery level is preferentially recovered, such that the memory Cgroup, which can be easily recovered, is preferentially recovered, and thus the situation of excessive memory recovery can be effectively avoided, and the overall memory recovery efficiency of a system is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Memory recycling method and electronic device

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 23, 2023, with application number 202310442272.6 and application name “Memory Recovery Method and Electronic Device”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of terminal devices, and in particular to a memory recovery method and electronic device. Background Art

[0003] Linux is an operating system. Memory reclamation in Linux memory management refers to the process of reclaiming the releasable portion of allocated memory (including file pages, anonymous pages, and SLAB cache) and returning it to the buddy system.

[0004] memcg (Memory Cgroup) is a memory management technology used in the Linux open source community. Currently, some manufacturers assign each application's memory to a memcg to facilitate memory management.

[0005] In the related art, when Linux reclaims memory, the system will traverse each memcg and reclaim reclaimable memory. However, the memory reclamation of some memcgs takes a long time, but the amount of memory reclaimed is small, resulting in low overall memory reclamation efficiency of the system.

[0006] Summary of the Invention

[0007] In order to solve the above technical problems, the present application provides a memory recovery method and electronic device, which configures the memory recovery level of each application based on the memory recovery efficiency of the memory management group corresponding to each application, and gives priority to the memory of the application with a higher recovery level, so that the memory management group that is easy to recycle is recycled first, avoiding excessive memory recovery and improving memory recovery efficiency.

[0008] In the first aspect, the present application provides a memory recovery method, which is applied to electronic devices, and the method includes: if the memory recovery process triggering condition is met, based on the historical data of memory recovery, obtaining the memory recovery efficiency of the memory management group corresponding to each application in the current electronic device; according to the obtained memory recovery efficiency, setting the recovery level of the memory management group corresponding to each application; based on the recovery priority and the recovery level of each memory management group, determining the target memory management group that needs to be traversed, scanning the target memory management group, and reclaiming the scanned recyclable memory. In this way, the memory recovery level of each application is configured based on the memory recovery efficiency of the memory management group corresponding to each application, and the memory of the application with the higher recovery level is prioritized, so that the memory management group that is easy to recycle is recycled first, which can effectively avoid the situation of excessive memory recovery and improve memory recovery efficiency.

[0009] According to a first aspect, based on the acquired memory recycling efficiency, the recycling level of the memory management group corresponding to each application is set, including: for each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; searching for the first recycling level corresponding to the first recycling efficiency range in the configured correspondence between recycling efficiency ranges and recycling levels; and setting the recycling level of the memory management group to the first recycling level. Thus, by setting the recycling level for the memory management group according to the memory recycling efficiency, a basis is provided for selecting the memory management group to be scanned based on the recycling level, so that memory management groups with high memory recycling efficiency are given priority in recycling scanning opportunities.

[0010] According to a first aspect, the memory recycling level of a memory management group corresponding to each application is set based on the acquired memory recycling efficiency, including: acquiring an application whitelist, wherein the application whitelist records at least one first application; and setting the recycling level of the memory management group corresponding to each application based on the acquired memory recycling efficiency and the application whitelist. Thus, by using the application whitelist as one of the factors determining the recycling level of the memory management group, a specific recycling level can be set for the memory management group of a specific application as needed, reducing the probability of memory recycling for the memory management group corresponding to the applications in the application whitelist, thereby reducing the impact of memory recycling on the applications in the whitelist and improving the user experience.

[0011] According to the first aspect, obtaining an application whitelist includes: reading a first whitelist from an existing configuration file; setting the recycling level of the memory management group corresponding to each application based on the acquired memory recycling efficiency and the application whitelist, including: for each memory management group, determining the first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; searching for the first recycling level corresponding to the first recycling efficiency range in the correspondence between the configured recycling efficiency range and the recycling level; setting the recycling level of the memory management group to the first recycling level; and adjusting the recycling level of the memory management group corresponding to the first application in the first whitelist to the second recycling level. In this way, commonly used applications can be added to the configuration file so that the commonly used applications become applications in the whitelist, so that a special recycling level can be set for the memory management group of the commonly used applications, thereby reducing the probability of memory management groups corresponding to commonly used applications being subjected to memory recycling, thereby reducing the impact of memory recycling on the use of commonly used applications and improving the user experience.

[0012] According to the first aspect, obtaining an application whitelist includes: identifying foreground applications; generating a second whitelist based on the identified foreground applications, wherein the applications in the second whitelist are foreground applications; setting the recycling level of the memory management group corresponding to each application based on the acquired memory recycling efficiency and the application whitelist, including: for each memory management group, determining the first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; searching for the first recycling level corresponding to the first recycling efficiency range in the correspondence between the configured recycling efficiency range and the recycling level; setting the recycling level of the memory management group to the first recycling level; and adjusting the recycling level of the memory management group corresponding to the foreground application to the second recycling level. In this way, by adding the foreground application to the application whitelist and setting a special recycling level for the memory management group of the foreground application, the probability of the memory management group corresponding to the foreground application being subjected to memory recycling can be reduced, thereby reducing the impact of memory recycling on the use of the foreground application and improving the user experience.

[0013] According to the first aspect, obtaining an application whitelist includes: reading a first whitelist from an existing configuration file; identifying foreground applications; adding foreground applications to the first whitelist to obtain a third whitelist; setting the recycling level of the memory management group corresponding to each application based on the acquired memory recycling efficiency and the application whitelist, including: for each memory management group, determining the first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; searching for the first recycling level corresponding to the first recycling efficiency range in the correspondence between the configured recycling efficiency range and recycling level; setting the recycling level of the memory management group to the first recycling level; and adjusting the recycling level of the memory management group corresponding to each application in the third whitelist to the second recycling level. In this way, by adding both commonly used applications and foreground applications to the application whitelist, a special recycling level setting can be made for the memory management groups of commonly used applications and foreground applications, thereby reducing the probability of memory management groups corresponding to commonly used applications and foreground applications being subjected to memory recycling, thereby reducing the impact of memory recycling on the use of commonly used applications and foreground applications, and improving the user experience.

[0014] According to the first aspect, the second recycling level is the lowest recycling level. In this way, the probability of memory recycling for commonly used applications and / or memory management groups corresponding to foreground applications can be minimized.

[0015] According to the first aspect, in the correspondence between the recycling efficiency range and the recycling level, the higher the recycling efficiency value corresponding to the recycling efficiency range, the higher the recycling level corresponding to the recycling efficiency range. This allows memory management groups with high recycling efficiency to be given priority for memory recycling opportunities, avoiding excessive memory recycling, reducing memory recycling time, and improving the overall memory recycling efficiency of the system.

[0016] According to a first aspect, based on historical memory recycling data, the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device is obtained, including: for each application, obtaining the memory scan amount and memory recycling amount of the memory management group corresponding to the application in the previous recycling process; and determining the memory recycling efficiency of the memory management group corresponding to the application based on the memory scan amount and memory recycling amount. In this way, the memory recycling efficiency of the memory management group corresponding to each application can be obtained, providing a basis for sorting the recycling opportunities of each memory management group in the current memory recycling process.

[0017] According to the first aspect, the memory recovery efficiency of the memory management group corresponding to the application is determined based on the memory scan amount and the memory recovery amount, including: determining the first memory recovery efficiency of the file page of the memory management group corresponding to the application based on the first memory scan amount and the first memory recovery amount of the file page of the memory management group corresponding to the application in the last recovery; determining the second memory recovery efficiency of the anonymous page of the memory management group corresponding to the application based on the second memory scan amount and the second memory recovery amount of the anonymous page of the memory management group corresponding to the application in the last recovery; and determining the memory recovery efficiency of the memory management group corresponding to the application based on the first memory recovery efficiency and the second memory recovery efficiency. In this way, the memory recovery efficiency of each memory management group can be accurately obtained.

[0018] According to the first aspect, the memory reclamation efficiency of the memory management group corresponding to the application is equal to the product of the first memory reclamation efficiency and the first coefficient, plus the second memory reclamation efficiency. Thus, by taking a weighted sum of the memory reclamation efficiencies of file pages and anonymous pages within a memory management group, the memory reclamation efficiency of each memory management group can be accurately obtained.

[0019] According to the first aspect, the first coefficient is determined based on the ratio of the file page recovery rate to the anonymous page recovery rate. Thus, by determining the first coefficient based on the ratio of the file page recovery rate to the anonymous page recovery rate, the proportion of the file page and anonymous page recovery efficiencies in the memory management group to the memory management group recovery efficiency can be more reasonably determined, thereby accurately obtaining the memory recovery efficiency of the memory management group.

[0020] According to the first aspect, based on the recycling priority and the recycling level of each memory management group, the target memory management group that needs to be traversed is determined, the target memory management group is scanned, and the recyclable memory scanned is recycled, including: according to the corresponding relationship between the recycling priority and the recycling level, the first target recycling level corresponding to the initial recycling priority is determined; the memory management group whose corresponding recycling level is equal to or higher than the first target recycling level is determined as the first target memory management group; the first target memory management group is scanned, and the first recyclable memory scanned is recycled. In this way, by only recycling memory for memory management groups that are equal to or higher than the first target recycling level, while meeting the memory recycling amount requirements, it is possible to effectively avoid excessive memory recycling, reduce the number of memory recycling times, and thus improve the memory recycling efficiency of the entire system.

[0021] According to the first aspect, before determining the first target recycling level corresponding to the initial recycling priority based on the correspondence between recycling priorities and recycling levels, the method further includes: determining the initial recycling priority based on a preset recycling volume for this recycling, wherein the larger the preset recycling volume, the lower the determined initial recycling priority. In this way, by determining the initial recycling priority based on the preset recycling volume, the scope of memory recycling can be reasonably determined, the number of recycling times can be reduced, and the memory recycling efficiency of the entire system can be improved.

[0022] According to the first aspect, it also includes: if the first reclaimable memory is less than the preset reclaim amount, determining the first target reclaim priority according to the initial reclaim priority and the adjustment step, the first target reclaim priority is lower than the initial reclaim priority; determining the second target reclaim level corresponding to the first target reclaim priority according to the correspondence between the reclaim priority and the reclaim level, the second target reclaim level is equal to or lower than the first target reclaim level; determining the memory management group whose corresponding reclaim level is equal to or higher than the second target reclaim level as the second target memory management group; scanning the second target memory management group, and reclaiming the scanned second reclaimable memory. In this way, when the memory reclaimed once does not meet the required reclaim amount, a reasonable memory range can be determined to reclaim the memory again, which can effectively avoid excessive memory reclaim and improve the memory reclaim efficiency of the entire system.

[0023] According to the first aspect, it also includes: if the sum of the first recyclable memory and the second recyclable memory is less than the preset recycling amount, determining the second target recycling priority according to the first target recycling priority and the adjustment step, the second target recycling priority is lower than the first target recycling priority; determining the third target recycling level corresponding to the second target recycling priority according to the corresponding relationship between the recycling priority and the recycling level, the third target recycling level is equal to or lower than the second target recycling level; determining the memory management group whose corresponding recycling level is equal to or higher than the third target recycling level as the third target memory management group; scanning the third target memory management group, and recycling the scanned third recyclable memory. In this way, when the total amount of memory recycled for the second time does not meet the required recycling amount, a reasonable memory range can be determined to recycle the memory again, which can effectively avoid excessive memory recycling and improve the memory recycling efficiency of the entire system.

[0024] According to the first aspect, the adjustment step size is a fixed value; alternatively, the adjustment step size is determined as follows: the adjustment step size is determined based on the difference between the total memory recovered in the current round and a preset recovery amount, where the larger the difference, the larger the adjustment step size; alternatively, the adjustment step size is determined based on the ratio of the difference between the total memory recovered in the current round and the preset recovery amount to the preset recovery amount, where the larger the ratio, the larger the adjustment step size. In this way, different adjustment step size determination methods can be adopted according to usage requirements to meet the needs of different scenarios.

[0025] According to the first aspect, if a memory reclamation process triggering condition is met, before obtaining the memory reclamation efficiency of the memory management group corresponding to each application in the current electronic device based on historical memory reclamation data, the method further includes: triggering the memory reclamation process when the free memory of the current electronic device is detected to be lower than a first value. In this way, the memory reclamation process can be triggered in a timely manner.

[0026] According to the first aspect, applications with higher memory reclamation efficiency have corresponding memory management groups with higher reclamation levels. The higher the reclamation level, the greater the reclamation probability. Thus, by setting the reclamation level, the reclamation probabilities of different memory management groups are controlled, changing the situation where all memory management groups have the same reclamation probability. This increases the reclamation probability of easily reclaimable memory management groups and reduces the reclamation probability of difficult-to-reclaim memory management groups, thereby improving the overall memory reclamation efficiency of the system.

[0027] According to the first aspect, a higher reclaim priority requires traversing higher reclaim levels of target memory management groups. Given that the number of memory management groups and corresponding reclaim levels remain unchanged, the number of target memory management groups decreases. This allows the reclaim levels to control the scope of memory reclaim, avoiding excessive memory reclaim and improving the overall memory reclaim efficiency of the system.

[0028] According to the first aspect, the electronic device may be a mobile phone, a tablet or a television. Of course, it is not limited thereto and may also be other electronic devices that require memory recycling.

[0029] In a second aspect, the present application provides an electronic device comprising: a memory and a processor, the memory being coupled to the processor; the memory storing program instructions, which, when executed by the processor, enables the electronic device to execute any one of the memory recovery methods of the first aspect.

[0030] In a third aspect, the present application provides a computer-readable storage medium comprising a computer program. When the computer program is run on an electronic device, the electronic device executes any one of the memory recovery methods of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] FIG1 is a schematic structural diagram of an exemplary electronic device 100;

[0032] FIG2 is a block diagram illustrating a software structure of the electronic device 100 according to an embodiment of the present application;

[0033] FIG3 is a flowchart illustrating a memory recycling method according to an embodiment of the present invention;

[0034] FIG4 is a schematic diagram illustrating memory management of a memory management group memcg of each application in a mobile phone;

[0035] FIG5 is a schematic diagram showing an exemplary management of a linked list in each memory management group memcg;

[0036] FIG6 is another flowchart illustrating the memory recycling method according to the present embodiment;

[0037] FIG7 is a schematic diagram showing the relationship between the update of the application whitelist and the setting of the memory management group recycling level in this embodiment;

[0038] FIG8 is a flowchart illustrating another example of a memory recycling method in this embodiment. DETAILED DESCRIPTION

[0039] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0040] The term "and / or" in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0041] In the description and claims of the embodiments of this application, the terms "first" and "second" are used to distinguish different objects, rather than to describe a specific order of objects. For example, the terms "first target object" and "second target object" are used to distinguish different objects, rather than to describe a specific order of objects.

[0042] 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.

[0043] In the description of the embodiments of this application, unless otherwise specified, "multiple" means two or more. For example, "multiple processing units" means two or more processing units; "multiple systems" means two or more systems.

[0044] In related technologies, Linux traverses each memcg during memory recycling to reclaim reclaimable memory. This approach has the following problems:

[0045] First, the memory recovery rate of different memcgs is different. For example, some memcgs can reclaim 100MB (megabits) of memory within 1ms (milliseconds), while some memcgs can only reclaim 5MB of memory within 1ms. This results in excessive time consumption in a memcg that is difficult to reclaim memory, resulting in low overall memory recovery efficiency of the system.

[0046] Second, memory recycling in related technologies requires traversing all memcgs, without a prioritized recycling strategy. However, during normal user usage, each app's usage varies. For example, App 1 may be used approximately 70% of the time, while App 2 may only be used 5%. Applying the same recycling strategy to both App 1 and App 2 would compromise the user experience of App 1.

[0047] Third, the relevant technology makes no difference in memory recycling between foreground apps and background apps, and memory recycling for foreground apps will lead to a poor user experience for the foreground apps.

[0048] This embodiment provides a memory recovery method and electronic device, which configures the order of memory recovery for each application based on the memory recovery efficiency of the memory management group corresponding to each application, prioritizes memory recovery for applications with higher rankings, and improves memory recovery efficiency.

[0049] This embodiment can be applied to electronic devices such as mobile phones, tablets, and televisions, but is certainly not limited thereto. The structure of the electronic device can be as shown in FIG1 .

[0050] FIG1 is a schematic diagram illustrating the structure of an exemplary electronic device 100. It should be understood that the electronic device 100 shown in FIG1 is merely an example of an electronic device, and that the electronic device 100 may have more or fewer components than shown, may combine two or more components, or may have a different component configuration. The various components shown in FIG1 may be implemented in hardware, including one or more signal processing and / or application-specific integrated circuits, software, or a combination of hardware and software.

[0051] 1 , the electronic device 100 may include: a processor 110, 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 interface 170D, a sensor module 180, an indicator 192, a camera 193, etc.

[0052] 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). The different processing units may be independent devices or integrated into one or more processors.

[0053] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0054] The processor 110 may further include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory.

[0055] The internal memory 121 can be used to store computer executable program codes, which include 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. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), 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.

[0056] FIG2 is a block diagram illustrating a software structure of the electronic device 100 according to an embodiment of the present application.

[0057] The layered architecture of electronic device 100 divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer, an application framework layer, a system library, and a kernel layer.

[0058] The application layer can include a series of application packages.

[0059] As shown in FIG2 , the application package may include applications such as camera, calendar, map, WLAN, music, short message, gallery, call, navigation, Bluetooth, video, etc. Of course, these applications are only exemplary, and in other embodiments, the application layer may include applications not shown in FIG2 , or may not include one or more applications shown in FIG2 .

[0060] As shown in FIG2 , the application framework layer may include a monitoring module, a whitelist management module, a whitelist configuration module, and the like.

[0061] The monitoring module is used to identify the foreground application and send the identification result to the whitelist management module.

[0062] The whitelist configuration module is used to initialize the configuration based on the application configuration information input by the user and generate a configuration file, wherein the configuration file may include one or more applications.

[0063] The whitelist management module is used to update the application whitelist according to the configuration file read from the whitelist configuration module and / or the foreground application identification result sent by the monitoring module.

[0064] The Android Runtime consists of the core library and the virtual machine. The Android runtime is responsible for scheduling and management of the Android system.

[0065] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.

[0066] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.

[0067] The system library may include multiple functional modules. As shown in FIG2 , for example, the system library may include a surface manager and the like.

[0068] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.

[0069] The kernel layer is the layer between hardware and software.

[0070] As shown in Figure 2, the kernel layer may include modules such as audio driver, display driver, Bluetooth driver, memory recycling module, and sensor driver.

[0071] The memory recycling module is used to execute the memory recycling method of this embodiment. The memory recycling module can obtain a whitelist from the aforementioned whitelist management module and set the recycling level of applications in the whitelist to a preset level, such as the lowest recycling level.

[0072] It is understood that the layers in the software structure shown in FIG2 and the components contained in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer layers than shown, and each layer may include more or fewer components, and this application does not limit this.

[0073] The memory recovery method of this embodiment is described below using a mobile phone as an example. Of course, the following embodiment is also applicable to other electronic devices besides mobile phones, such as tablets, televisions, etc.

[0074] In the following embodiments, it is assumed that there are 8 applications in the mobile phone, namely: application 1 (i.e., APP1) to application 8 (i.e., APP1). The memory management groups corresponding to applications 1 to 8 are: memory management group 1 (i.e., memcg1) to memory management group 8 (i.e., memcg8).

[0075] FIG3 is a flowchart illustrating a memory recycling method according to an embodiment of the present invention. Referring to FIG3 , in this embodiment, the memory recycling method may include the following steps:

[0076] S301, if the memory recycling process triggering condition is met, calculate the memory recycling efficiency of the memory management groups memcg1 to memcg8 corresponding to applications 1 to 8 based on the memory scan amount and memory recycling amount of the memory management groups of applications 1 to 8 in the last recycling.

[0077] In one example, the triggering condition for the memory recycling process may be: the current free memory capacity in the electronic device is lower than a first value. For example, assume that three watermark values ​​are set: a first watermark value, a second watermark value, and a third watermark value, and the first watermark value is greater than the second watermark value, and the second watermark value is greater than the third watermark value. Assume that it is stipulated that the triggering condition for the memory recycling process may be: the current free memory capacity in the electronic device is lower than the second watermark value. Then, the second watermark value is the first value. In addition, it can also be stipulated that the preset recycling amount in this case is equal to the first watermark value.

[0078] Of course, the memory reclamation process triggering conditions listed above are only examples, and in other embodiments, other memory reclamation process triggering conditions may be set, for example, triggering the memory reclamation process based on system pressure or a specified event.

[0079] When the memory reclamation process triggering conditions are met, a memory reclamation process is triggered. In a memory reclamation process, one or more rounds of memory reclamation can be performed.

[0080] Here, a method for obtaining the memory reclamation efficiency of the memory management group memcg is described.

[0081] Figure 4 is a schematic diagram illustrating memory management of the memory management group memcg for each application in a mobile phone. Referring to Figure 4, the memory of each application (i.e., APP) is set as a memory management group memcg, and the memory in each memcg is divided into two categories: file pages and anonymous pages.

[0082] Figure 5 illustrates the management of linked lists within each memcg (memcg). As shown in Figure 5, each memcg manages four linked lists: an active and inactive list for file pages, and an active and inactive list for anonymous pages. When reclaiming memory within a memcg, the Linux kernel traverses these four linked lists, reclaiming reclaimable memory to the buddy system and rotating unreclaimable memory back to the head of the linked list.

[0083] In this article, the variables are defined as follows:

[0084] Scanned amount (nr_scaned): The amount of memory scanned in one memory recycling.

[0085] Reclaimed amount (nr_reclaimed): The amount of memory reclaimed to the buddy system in one memory reclamation.

[0086] Return amount (nr_rotated): The memory capacity returned to the head of the linked list in a memory recycling.

[0087] Memory recycling efficiency.

[0088] In this embodiment, the scan amount, reclaim amount, and return amount of the file page and the anonymous page can be recorded separately, and the memory reclaim efficiency of the file page and the memory reclaim efficiency of the anonymous page are also calculated separately.

[0089] In this embodiment, the memory recycling efficiency can be calculated according to the following formula (1).

[0090] File pages and anonymous pages are recycled independently. Using formula (1), we can calculate the memory recycling efficiency of file pages (file_efficiency) and the memory recycling efficiency of anonymous pages (anon_efficiency). That is, the memory recycling efficiency of file pages is equal to the quotient of the file page recycling amount divided by the file page scan amount, and the memory recycling efficiency of anonymous pages is equal to the quotient of the anonymous page recycling amount divided by the anonymous page scan amount.

[0091] For an effective memory recovery, when the scan volume is constant, the more the recovery volume is, the higher the recovery efficiency is. On the contrary, the higher the return volume is, the more difficult it is to recover the memory of the memcg during this period.

[0092] The recycling rate of file pages is different from the recycling rate of anonymous pages, and the recycling rate of file pages is usually much higher than that of anonymous pages. Therefore, when calculating the overall memory recycling efficiency of memcg, this embodiment does not simply add file_efficiency and anon_efficiency, but rather assigns a certain weight. For example, the overall memory recycling efficiency of a memcg can be calculated according to the following formula (2): memcgeefficiency = file_efficiency * scale + anon_efficiency (2)

[0093] In formula (2), the parameter scale can be configured. For example, the parameter scale can be determined based on the ratio of the file page recycling rate to the anonymous page recycling rate in actual use.

[0094] Assuming that the aforementioned formulas (1) and (2) are used, the memory recycling efficiencies of the memory management groups memcg1 to memcg8 corresponding to applications 1 to 8 are calculated as shown in Table 1.

[0095] Table 1

[0096] S302 : Setting the recycling level of memory management groups memcg1 to memcg8 according to the memory recycling efficiency of the memory management groups memcg1 to memcg8 .

[0097] In one example, the recycling level of a memory management group is set according to the memory recycling efficiency of the memory management group, which can be performed as follows:

[0098] For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs;

[0099] In the configured correspondence between recycling efficiency ranges and recycling levels, searching for a first recycling level corresponding to a first recycling efficiency range;

[0100] Sets the reclaim level of the memory management group to the first reclaim level.

[0101] That is, the memory recycling efficiency of memcg is determined according to its recycling efficiency range, and then the recycling level of memcg is determined according to the recycling efficiency range.

[0102] For example, assume that the corresponding relationship between the recycling efficiency range and the recycling level is as shown in Table 2.

[0103] Table 2

[0104] Among them, level 0 is the lowest recycling level, level 4 is the highest recycling level, and the recycling levels from level 0 to level 4 increase gradually.

[0105] In this way, according to Table 1 and Table 2, the memcg corresponding to each recycling level can be determined, as shown in Table 3.

[0106] Table 3

[0107] It should be noted that while the above example includes five recycling levels, in other embodiments, more or fewer recycling levels may be provided, and this embodiment does not limit the number of recycling levels. Furthermore, the correspondence between the recycling efficiency range and the recycling level may also be adjusted and is not limited to the correspondence shown in Table 2.

[0108] S303 , reading the initial recycling priority 12, and determining that the recycling level corresponding to the initial recycling priority 12 is level 4 according to the corresponding relationship between the recycling priority and the recycling level.

[0109] In this embodiment, it is assumed that the recycling priority range is 0-12. The higher the recycling priority value, the lower the recycling intensity. The lower the recycling granularity, the smaller the recycling scan range. Of course, in other embodiments, a larger or smaller recycling priority range can be set, and is not limited to 0-12.

[0110] It should be noted that one or more rounds of memory reclamation can be performed during a memory reclamation process, depending on the total memory capacity to be reclaimed (i.e., the preset reclamation amount). In this embodiment, the initial reclamation priority is 12. Each time a reclamation is performed, if the reclaimed memory capacity does not meet the requirement, the reclamation priority value is reduced by 1, and the next round of reclamation continues until the reclaimed memory capacity meets the requirement.

[0111] It is assumed that the corresponding relationship between recycling priority and recycling level is shown in Table 4.

[0112] Table 4

[0113] According to Table 4, we can find that recycling priority 12 corresponds to recycling level 4.

[0114] In one example, the initial priority may be fixed, for example, the initial priority may be set equal to the highest recycling priority value within the recycling priority range.

[0115] In another example, the initial priority can be variable. For example, the initial priority can be determined based on the preset amount of memory to be reclaimed during each memory reclamation process. The larger the preset amount of memory to be reclaimed, the lower the initial priority. This flexible setting of the initial reclamation priority based on the amount of memory to be reclaimed helps reduce memory reclamation time and improve memory reclamation efficiency.

[0116] S304: Determine memcg1 and memcg2 with recycling level 4 as memory management groups for this round of scanning.

[0117] In this example, since level 4 is the highest recycling level, the only recycling level higher than or equal to level 4 is level 4. Therefore, memcg with a recycling level of level 4 is determined as the memory management group for this scan. As shown in Table 3, the corresponding memory management groups with recycling levels higher than or equal to level 4 are memcg1 and memcg2. Therefore, memcg1 and memcg2 are determined as the memory management groups for this scan.

[0118] S305 , memcg1 and memcg2 are scanned, and a1 megabyte of memory is available for recycling. The a1 megabyte of memory is recycled to the partner system.

[0119] A1 megabyte of memory was successfully recovered in this round.

[0120] S306, determining whether the memory capacity a1 recovered this time reaches the preset recovery amount b, if not, executing step S307, otherwise ending this memory recovery process.

[0121] S307 , subtract 1 from the initial recycling priority 12 to obtain a first target recycling priority 11.

[0122] In this embodiment, the step size for reducing the recycling priority is 1. In other embodiments, other step sizes may be set. For example, the step size for reducing the recycling priority can be determined based on the difference between the total memory recycled in this round and the preset recycling amount. The larger the difference, the larger the step size. Alternatively, the step size can be determined based on the ratio of the difference between the total memory recycled in this round and the preset recycling amount to the preset recycling amount. The larger the ratio, the larger the step size. In this way, the recycling scan range can be expanded more quickly, improving recycling efficiency.

[0123] S308 : According to the correspondence between recycling priorities and recycling levels, determine that the recycling level corresponding to the first target recycling priority 11 is level 4 .

[0124] Refer to Table 4. The recycling level corresponding to recycling priority 11 is also level 4.

[0125] S309 , determining that memcg1 and memcg2 with recycling level 4 are memory management groups for this round of scanning.

[0126] S310 , memcg1 and memcg2 are scanned, and a2 megabytes of memory can be reclaimed. The a2 megabytes of memory are reclaimed to the partner system.

[0127] S311, determine whether the memory capacity (a1+a2) recovered this time reaches the preset recovery amount b. If not, execute step S312, otherwise end the memory recovery process.

[0128] S312 , subtract 1 from the first target recycling priority 11 to obtain a second target recycling priority 10 .

[0129] S313: Based on the correspondence between recycling priorities and recycling levels, it is determined that the recycling level corresponding to the second target recycling priority 10 is level 4. Memcg1 and memcg2 with recycling level 4 are determined to be the memory management groups for this round of scanning. Memcg1 and memcg2 are scanned to reclaim the recyclable a3 megabytes of memory to the partner system.

[0130] S314, determine whether the memory capacity (a1+a2+a3) recovered this time reaches the preset recovery amount b. If not, execute step S315, otherwise end the memory recovery process.

[0131] S315 , subtract 1 from the second target recycling priority 10 to obtain a third target recycling priority 9.

[0132] S316: Based on the correspondence between recycling priorities and recycling levels, it is determined that the recycling level corresponding to the third target recycling priority 9 is level 3. MEMCG1, MEMCG2, and MEMCG3, whose recycling levels are equal to or higher than level 3, are determined as memory management groups for this round of scanning. MEMCG1, MEMCG2, and MEMCG3 are scanned to reclaim the recyclable 4 megabits of memory to the partner system.

[0133] Refer to Table 4. Recycling priority 9 corresponds to recycling level 3.

[0134] In this example, there are two recycling levels higher than or equal to level 3: level 3 and level 4. Therefore, memcg with recycling level 3 and memcg with recycling level 4 are determined as memory management groups for this scan round. Refer to Table 3. The corresponding memory management groups with recycling levels higher than or equal to level 3 are memcg1, memcg2, and memcg3. Therefore, memcg1, memcg2, and memcg3 are determined as memory management groups for this scan round.

[0135] S317: It is determined that the memory capacity (a1+a2+a3+a4) recovered this time is greater than or equal to the preset recovery amount b, and the memory recovery process ends.

[0136] It should be noted that if the memory capacity (a1+a2+a3+a4) that has been reclaimed this time is still less than the preset recovery amount b, it is necessary to continue to reduce the recovery priority, and determine the scanned memory management group memcg again according to the reduced recovery priority, and continue memory recovery until the reclaimed memory capacity is greater than or equal to the preset recovery amount b.

[0137] In this memory recovery process, the recovery amount and scanning amount of each memory management group can be recorded and saved, and the recovery amount and scanning amount of file pages and anonymous pages in the same memory management group can be recorded and saved separately, so as to calculate the memory recovery efficiency of each memory management group in the next memory recovery process.

[0138] It can be seen from the above embodiments that the memory recovery method of this embodiment configures the memory recovery level of each application based on the memory recovery efficiency of the memory management group corresponding to each application, controls the recovery probability of different memory management groups, and changes the situation where the recovery probability of all memory management groups is the same, so that the memory management groups that are easy to recycle are sorted first, and the memory management groups that are easy to recycle are prioritized for recovery. When the memory recovery amount of the memory management groups that are easy to recycle meets the requirements, other difficult-to-recycle memories will no longer be recycled, which can effectively avoid the situation of excessive memory recovery, thereby reducing the time consumed in memory recovery processing and improving the overall memory recovery efficiency of the system.

[0139] FIG6 is another example flow chart of the memory recycling method in this embodiment. Referring to FIG6 , in this embodiment, the memory recycling method may include the following steps:

[0140] S601: If the memory recycling process triggering condition is met, the memory recycling efficiency of the memory management groups memcg1 to memcg8 corresponding to applications 1 to 8 is calculated based on the memory scan amount and memory recycling amount of the memory management groups of applications 1 to 8 in the last recycling.

[0141] Assume that the calculated memory recycling efficiencies of the memory management groups memcg1 to memcg8 are still as shown in Table 1.

[0142] S602: Obtain an application whitelist.

[0143] Assume that the application whitelist includes application 1, application 5, and application 7.

[0144] It should be noted that the application whitelist may record at least one application. In this embodiment, a lower recycling level is set for the memory management groups corresponding to the applications in the application whitelist to reduce the probability of memory recycling for the memory management groups corresponding to the applications in the application whitelist.

[0145] In one example, obtaining the application whitelist may include: reading a first whitelist from an existing configuration file, wherein the configuration file is generated by the whitelist configuration module in FIG.

[0146] In this embodiment, the applications in the first whitelist are the applications in the configuration file, which may be pre-configured.

[0147] In one example, obtaining an application whitelist may include:

[0148] Identify the foreground application;

[0149] A second whitelist is generated based on the identified foreground applications, where the applications in the second whitelist are foreground applications.

[0150] In this embodiment, the applications in the second whitelist are the current foreground applications. When there is no floating window on the mobile phone interface, the application on the current main interface of the mobile phone is the foreground application. When there is a floating window on the mobile phone interface, the application on the current main interface of the mobile phone and the application in the floating window are both foreground applications.

[0151] In one example, obtaining the application whitelist may include: reading a first whitelist from an existing configuration file;

[0152] Identify the foreground application;

[0153] The foreground application is added to the first whitelist to obtain a third whitelist.

[0154] In this embodiment, the applications in the third whitelist include the applications in the configuration file and the current foreground application. That is, the applications in the third whitelist include the applications in the first whitelist and the applications in the second whitelist.

[0155] S603 : Set the recycling level of the memory management groups memcg1 to memcg8 according to the memory recycling efficiency of the memory management groups memcg1 to memcg8 and the application whitelist.

[0156] In this embodiment, the recycling level is set based on the memory recycling efficiency of the memory management group and the application whitelist. The following example illustrates how to set the recycling level based on the memory recycling efficiency of the memory management group and the application whitelist.

[0157] FIG7 is a schematic diagram showing the relationship between the update of the application whitelist and the setting of the memory management group recycling level in this embodiment. Referring to FIG7, in this embodiment, the recycling level setting process may include:

[0158] 1. The whitelist configuration module performs initialization configuration based on the application configuration information entered by the user and generates a configuration file.

[0159] The configuration file includes application names, such as Application 1 and Application 5.

[0160] It should be noted that the configuration file can be configured once and then no longer changed. In this way, the applications in the configuration file are fixed. Developers can write one or more of the most commonly used applications into the configuration file based on the statistical data of the usage of each application, so that the recycling level of the memory management group of these most commonly used applications can be set to a lower level in the future, such as the lowest level 0, thereby reducing the chance of memory management groups of these most commonly used applications being recycled. In this way, the number of times the memory management groups of these most commonly used applications are recycled is reduced, which in turn can reduce the impact of memory recycling on the use of these most commonly used applications, such as reducing the freeze caused by memory recycling and improving the user experience.

[0161] 2. The whitelist management module reads the configuration file from the whitelist configuration module.

[0162] 3. The whitelist management module updates the application whitelist according to the configuration file. The updated application whitelist is the first whitelist.

[0163] Assume that the updated application whitelist includes two applications, namely, application 1 and application 5.

[0164] 4. The monitoring module identifies the foreground application.

[0165] Assume that the foreground application is application 7.

[0166] 5. The monitoring module sends the identified foreground application to the whitelist management module.

[0167] 6. The whitelist management module updates the application whitelist according to the foreground application. The application whitelist obtained after this update is the third whitelist.

[0168] In this step, the whitelist management module adds the foreground application to the first whitelist obtained after the update in the aforementioned step 3, that is, a third whitelist is obtained.

[0169] The updated application whitelist includes three applications, namely application 1, application 5 and application 7.

[0170] By adding foreground apps to the application whitelist, you can subsequently set the memory management group reclaim level for these foreground apps to a lower level, such as level 0, thereby reducing the chances of their memory management groups being reclaimed. This reduces the number of times their memory management groups are reclaimed, thereby reducing the impact of memory reclaim on the foreground app's usage, such as reducing lag in the foreground app caused by memory reclaim, and improving the user experience.

[0171] 7. The memory recovery module reads the application whitelist from the whitelist management module.

[0172] Before this step, the memory recycling module has set the recycling level according to the memory recycling efficiency of memcg, as shown in the aforementioned Table 3. The detailed setting process of the recycling level in Table 3 can be found in the description of the aforementioned step S302 and will not be repeated here.

[0173] 8. Adjust the recycling level based on the application whitelist.

[0174] For example, assuming that the adjustment policy is to adjust the recycling level of the memcg corresponding to the application in the application whitelist to the lowest level level 0, then after the adjustment, the memcg corresponding to each recycling level is as shown in Table 5.

[0175] Table 5

[0176] It should be noted that the above example generates an application whitelist based on both the configuration file and the foreground application. In other embodiments, the application whitelist may be generated based only on the configuration file, or based only on the foreground application.

[0177] When the application whitelist is generated only based on the configuration file, the application whitelist is the aforementioned first whitelist (the first whitelist includes application 1 and application 5). At this time, the recycling level setting process may not include steps 4 to 6 in Figure 7. In this case, the adjusted recycling level is shown in Table 6.

[0178] Table 6

[0179] When the application whitelist is generated only based on the foreground application, the application whitelist is the aforementioned second whitelist (the second whitelist includes the foreground application 7). At this time, the recycling level setting process may not include steps 1 to 3 in Figure 7. In this case, the adjusted recycling level is shown in Table 7.

[0180] Table 7

[0181] S604 , reading the initial recycling priority 12 , and determining that the recycling level corresponding to the initial recycling priority 12 is level 4 according to the corresponding relationship between the recycling priority and the recycling level.

[0182] According to Table 4, we can find that recycling priority 12 corresponds to recycling level 4.

[0183] S605 , determining that memcg2 with a recycling level of level 4 is the memory management group for this round of scanning.

[0184] In this example, since level 4 is the highest recycling level, the only recycling level higher than or equal to level 4 is level 4. Therefore, memcg with a recycling level of level 4 is determined as the memory management group for this scan. As shown in Table 5, memcg2 is the only memory management group with a recycling level higher than or equal to level 4. Therefore, memcg2 is determined as the memory management group for this scan.

[0185] S606 , memcg2 is scanned, and c1 megabytes of memory can be reclaimed. The c1 megabytes of memory are reclaimed to the partner system.

[0186] c1 megabytes of memory were successfully recovered in this round.

[0187] S607, determining whether the memory capacity c1 reclaimed this time reaches the preset reclaimed capacity b, if not, executing step S608, otherwise ending the memory reclaiming process.

[0188] S608 , subtract 1 from the initial recycling priority 12 to obtain a first target recycling priority 11.

[0189] In this embodiment, it is still assumed that the step size of the recycling priority reduction is 1. In other embodiments, other step sizes may be set, or the step size of the recycling priority reduction may be determined based on the difference between the total amount of recycled memory and the preset recycling amount.

[0190] S609 : According to the correspondence between recycling priorities and recycling levels, determine that the recycling level corresponding to the first target recycling priority 11 is level 4 .

[0191] Refer to Table 4. The recycling level corresponding to recycling priority 11 is also level 4.

[0192] S610: Determine that memcg2 with a recycling level of level 4 is the memory management group for this round of scanning.

[0193] S611, scan memcg2, there is c2 megabytes of memory that can be reclaimed, and the c2 megabytes of memory are reclaimed to the partner system.

[0194] S612, determine whether the memory capacity (c1+c2) recovered this time reaches the preset recovery amount b. If not, execute step S613, otherwise end the memory recovery process.

[0195] S613 , subtract 1 from the first target recycling priority 11 to obtain a second target recycling priority 10 .

[0196] S614: Based on the correspondence between recycling priorities and recycling levels, it is determined that the recycling level corresponding to the second target recycling priority 10 is level 4. Memcg2 with recycling level 4 is determined to be the memory management group to be scanned in this round. Memcg2 is scanned to reclaim c3 megabytes of reclaimable memory to the partner system.

[0197] S615, determine whether the memory capacity (c1+c2+c3) recovered this time reaches the preset recovery amount b. If not, execute step S616, otherwise end the memory recovery process.

[0198] S616 , subtract 1 from the second target recycling priority 10 to obtain a third target recycling priority 9.

[0199] S617: Based on the correspondence between recycling priorities and recycling levels, determine that the recycling level corresponding to the third target recycling priority 9 is level 3. Determine memcg2 and memcg3, whose recycling levels are equal to or higher than level 3, as the memory management groups to be scanned in this round. Scan memcg2 and memcg3 to reclaim the recyclable 4 megabits of memory to the partner system.

[0200] Refer to Table 4. Recycling priority 9 corresponds to recycling level 3.

[0201] In this example, there are two recycling levels higher than or equal to level 3: level 3 and level 4. Therefore, memcg with recycling level 3 and memcg with recycling level 4 are determined as memory management groups for this scan round. Refer to Table 5. The corresponding memory management groups with recycling levels higher than or equal to level 3 are memcg2 and memcg3. Therefore, memcg2 and memcg3 are determined as memory management groups for this scan round.

[0202] S618: It is determined that the memory capacity (c1+c2+c3+c4) recovered this time is greater than or equal to the preset recovery amount b, and the memory recovery process ends.

[0203] It should be noted that if the memory capacity (c1+c2+c3+c4) that has been reclaimed this time is still less than the preset recovery amount b, it is necessary to continue to reduce the recovery priority, and determine the scanned memory management group memcg again according to the reduced recovery priority, and continue memory recovery until the reclaimed memory capacity is greater than or equal to the preset recovery amount b.

[0204] In this memory recovery process, the recovery amount and scanning amount of each memory management group can be recorded and saved, and the recovery amount and scanning amount of file pages and anonymous pages in the same memory management group can be recorded and saved separately, so as to calculate the memory recovery efficiency of each memory management group in the next memory recovery process.

[0205] As can be seen from the above embodiments, the memory recovery method of this embodiment configures the memory recovery level of each application based on the memory recovery efficiency of the memory management group corresponding to each application and the application usage, controls the recovery probability of different memory management groups, and changes the situation where the recovery probability of all memory management groups is the same, so that the memory management groups that are easy to recover are ranked higher and are recycled first, and the commonly used applications and / or foreground applications are ranked lower. In this way, the memory management groups that are easy to recover can be recycled first, which can effectively avoid the situation of excessive memory recovery, thereby reducing the time consumption of memory recovery processing and improving the overall memory recovery efficiency of the system. In addition, the memory recovery method of this embodiment realizes more memory recovery for infrequently used APPs and less recovery for frequently used and important APPs, reducing the probability of memory recovery for memory management groups of commonly used applications and / or foreground applications, thereby reducing the impact of memory recovery on the use of commonly used applications and / or foreground applications, and improving the user experience.

[0206] FIG8 is another example flow chart of the memory recycling method in this embodiment. Referring to FIG8 , in this embodiment, the memory recycling method may include the following steps:

[0207] S801: If a memory recycling process triggering condition is met, the memory recycling efficiency of the memory management group corresponding to each application in the electronic device is obtained according to historical memory recycling data.

[0208] S802: Setting a recycling level of the memory management group corresponding to each application according to the acquired memory recycling efficiency.

[0209] S803: Based on the recycling priority and the recycling level of each memory management group, determine the target memory management group to be traversed, scan the target memory management group, and reclaim the scanned reclaimable memory.

[0210] An embodiment of the present application also provides an electronic device, which includes a memory and a processor. The memory is coupled to the processor, and the memory stores program instructions. When the program instructions are executed by the processor, the electronic device implements the memory recovery method executed by the aforementioned electronic device.

[0211] It is understandable that, in order to implement the above functions, the electronic device includes hardware and / or software modules that perform the corresponding functions. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of this application.

[0212] This embodiment also provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the memory recycling method in the above-mentioned embodiment.

[0213] This embodiment further provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the above-mentioned related steps to implement the memory recycling method in the above-mentioned embodiment.

[0214] 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 execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory to enable the chip to execute the memory recovery method in the above-mentioned method embodiments.

[0215] Among them, the electronic device, computer storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.

[0216] Through the description of the above implementation methods, technical personnel in the relevant field can 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 distributed and completed by 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.

[0217] 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 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.

[0218] Units described as separate components may or may not be physically separate, and 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.

[0219] 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.

[0220] Any content of each embodiment of this application, as well as any content of the same embodiment, can be freely combined. Any combination of the above content is within the scope of this application.

[0221] 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.

[0222] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

[0223] The steps of the method or algorithm described in conjunction with the disclosure of the embodiments of the present application can be implemented in a hardware manner, or can be implemented by a processor executing a software instruction. The software instruction can be composed of corresponding software modules, and the software module can be stored in a random access memory (Random Access Memory, RAM), a flash memory, a read-only memory (Read Only Memory, ROM), an erasable programmable read-only memory (Erasable Programmable ROM, EPROM), an electrically erasable programmable read-only memory (Electrically EPROM, EEPROM), a register, a hard disk, a mobile hard disk, a read-only compact disc (CD-ROM) or any other form of storage medium well known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and can write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.

[0224] Those skilled in the art will appreciate that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any media that facilitates the transmission of computer programs from one place to another. The storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.

[0225] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

Claims

1. A memory recovery method, characterized in that: Applied to electronic equipment, the method comprises: If the memory recycling process triggering condition is met, the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device is obtained according to the historical data of memory recycling; According to the acquired memory recycling efficiency, setting the recycling level of the memory management group corresponding to each application; Based on the recycling priority and the recycling level of each memory management group, the target memory management group that needs to be traversed is determined, the target memory management group is scanned, and the scanned recyclable memory is recycled.

2. The method according to claim 1, characterized in that According to the acquired memory recycling efficiency, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; The reclaim level of the memory management group is set to the first reclaim level.

3. The method according to claim 1, characterized in that According to the acquired memory recycling efficiency, the recycling level of the memory management group corresponding to each application is set, including: Obtaining an application whitelist, wherein the application whitelist records at least one first application; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set.

4. The method according to claim 3, characterized in that Get the application whitelist, including: Read the first whitelist from the existing configuration file; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; Setting the recycling level of the memory management group to the first recycling level; The recycling level of the memory management group corresponding to the first application in the first whitelist is adjusted to the second recycling level.

5. The method according to claim 3, characterized in that: Get the application whitelist, including: Identify the foreground application; Generate a second whitelist according to the identified foreground application, where the applications in the second whitelist are the foreground applications; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; Setting the recycling level of the memory management group to the first recycling level; The recycling level of the memory management group corresponding to the foreground application is adjusted to the second recycling level.

6. The method according to claim 3, characterized in that Get the application whitelist, including: Read the first whitelist from the existing configuration file; Identify the foreground application; Adding the foreground application to the first whitelist to obtain a third whitelist; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; Setting the recycling level of the memory management group to the first recycling level; The recycling level of the memory management group corresponding to each application in the third whitelist is adjusted to the second recycling level.

7. The method according to any one of claims 3 to 6, characterized in that: The second recycling level is the lowest recycling level.

8. The method according to any one of claims 2, 4 to 6, characterized in that: In the correspondence between the recovery efficiency range and the recovery level, the higher the recovery efficiency value corresponding to the recovery efficiency range is, the higher the recovery level corresponding to the recovery efficiency range is.

9. The method according to claim 1, characterized in that: According to the historical data of memory recycling, the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device is obtained, including: For each application, obtain the memory scan amount and memory recovery amount of the memory management group corresponding to the application in the last recovery; A memory recovery efficiency of a memory management group corresponding to the application is determined according to the memory scan amount and the memory recovery amount.

10. The method according to claim 9, characterized in that Determining the memory recovery efficiency of the memory management group corresponding to the application according to the memory scan amount and the memory recovery amount includes: Determining a first memory recovery efficiency of the file page of the memory management group corresponding to the application according to a first memory scan amount and a first memory recovery amount of the file page of the memory management group corresponding to the application in the last recovery; Determining a second memory recycling efficiency of the anonymous pages of the memory management group corresponding to the application according to a second memory scan amount and a second memory recycling amount in a previous recycling; The memory reclaim efficiency of the memory management group corresponding to the application is determined according to the first memory reclaim efficiency and the second memory reclaim efficiency.

11. The method according to claim 10, characterized in that The memory recovery efficiency of the memory management group corresponding to the application is equal to the product of the first memory recovery efficiency and the first coefficient and the sum of the second memory recovery efficiency.

12. The method according to claim 11, characterized in that The first coefficient is determined according to the ratio of the recycling rate of the file pages to the recycling rate of the anonymous pages.

13. The method according to claim 1, characterized in that Based on the recycling priority and the recycling level of each memory management group, determine the target memory management group that needs to be traversed, scan the target memory management group, and recycle the scanned recyclable memory, including: Determine a first target recycling level corresponding to the initial recycling priority according to the corresponding relationship between the recycling priority and the recycling level; Determine a memory management group corresponding to a recycling level equal to or higher than the first target recycling level as a first target memory management group; The first target memory management group is scanned, and the scanned first reclaimable memory is reclaimed.

14. The method according to claim 13, characterized in that Before determining the first target recycling level corresponding to the initial recycling priority according to the correspondence between the recycling priority and the recycling level, the method further includes: The initial recycling priority is determined according to the preset recycling volume of this recycling. The larger the preset recycling volume is, the lower the determined initial recycling priority is.

15. The method according to claim 13, characterized in that Also includes: If the first reclaimable memory is less than a preset reclaim amount, determining a first target reclaim priority according to the initial reclaim priority and the adjustment step size, the first target reclaim priority being lower than the initial reclaim priority; Determine, according to the correspondence between recycling priorities and recycling levels, a second target recycling level corresponding to the first target recycling priority, wherein the second target recycling level is equal to or lower than the first target recycling level; Determine a memory management group corresponding to a recycling level equal to or higher than the second target recycling level as a second target memory management group; The second target memory management group is scanned, and the scanned second reclaimable memory is reclaimed.

16. The method according to claim 15, characterized in that Also includes: If the sum of the first reclaimable memory and the second reclaimable memory is less than the preset reclaim amount, determining a second target reclaim priority according to the first target reclaim priority and the adjustment step, the second target reclaim priority being lower than the first target reclaim priority; Determine, according to the correspondence between the recycling priority and the recycling level, a third target recycling level corresponding to the second target recycling priority, wherein the third target recycling level is equal to or lower than the second target recycling level; Determine a memory management group corresponding to a recycling level equal to or higher than the third target recycling level as a third target memory management group; The third target memory management group is scanned, and the scanned third reclaimable memory is reclaimed.

17. The method according to claim 15 or 16, characterized in that The adjustment step size is a fixed value; or, the adjustment step size is determined as follows: Determine the adjustment step size according to the difference between the total memory recovery amount currently recovered in this round and the preset recovery amount, the larger the difference is, the larger the value of the determined adjustment step size is; Alternatively, the adjustment step size is determined based on the ratio of the difference between the total memory recovery amount currently recovered in this round and the preset recovery amount to the preset recovery amount, and the larger the ratio is, the larger the value of the determined adjustment step size is.

18. The method according to claim 1, characterized in that If the memory recycling process triggering condition is met, before obtaining the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device according to the historical data of memory recycling, the method further includes: It is monitored that the free memory of the electronic device is currently lower than a first value, triggering a memory recycling process.

19. The method according to claim 1, characterized in that The higher the memory recycling efficiency of an application, the higher the recycling level of the corresponding memory management group. The higher the recycling level, the greater the recycling probability.

20. The method according to claim 1, characterized in that The higher the recycling priority, the higher the recycling level of the target memory management group that needs to be traversed, and the smaller the number of target memory management groups when the number of memory management groups and the corresponding recycling levels remain unchanged.

21. The method according to claim 1, characterized in that The electronic device is a mobile phone, a tablet or a television.

22. An electronic device, characterized in that: include: a memory and a processor, the memory being coupled to the processor; The memory stores program instructions, and when the program instructions are executed by the processor, the electronic device executes the memory recovery method as described in any one of claims 1 to 21.

23. A computer-readable storage medium comprising a computer program, characterized in that: When the computer program runs on an electronic device, the electronic device executes the memory recycling method as described in any one of claims 1 to 21.

24. A memory recovery method, characterized in that: Applied to electronic equipment, the method comprises: If the memory recycling process triggering condition is met, the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device is obtained according to the historical data of memory recycling; According to the acquired memory recycling efficiency, setting the recycling level of the memory management group corresponding to each application; Based on the recycling priority and the recycling level of each memory management group, the target memory management group that needs to be traversed is determined, the target memory management group is scanned, and the scanned recyclable memory is recycled.

25. The method according to claim 24, characterized in that According to the acquired memory recycling efficiency, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; The reclaim level of the memory management group is set to the first reclaim level.

26. The method according to claim 24, characterized in that According to the acquired memory recycling efficiency, the recycling level of the memory management group corresponding to each application is set, including: Obtaining an application whitelist, wherein the application whitelist records at least one first application; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set.

27. The method according to claim 26, characterized in that Get the application whitelist, including: Read the first whitelist from the existing configuration file; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; Setting the recycling level of the memory management group to the first recycling level; The recycling level of the memory management group corresponding to the first application in the first whitelist is adjusted to the second recycling level.

28. The method according to claim 26, characterized in that Get the application whitelist, including: Identify the foreground application; Generate a second whitelist according to the identified foreground application, where the applications in the second whitelist are the foreground applications; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; Setting the recycling level of the memory management group to the first recycling level; The recycling level of the memory management group corresponding to the foreground application is adjusted to the second recycling level.

29. The method according to claim 26, characterized in that Get the application whitelist, including: Read the first whitelist from the existing configuration file; Identify the foreground application; Adding the foreground application to the first whitelist to obtain a third whitelist; According to the acquired memory recycling efficiency and the application whitelist, the recycling level of the memory management group corresponding to each application is set, including: For each memory management group, determining a first recycling efficiency range to which the memory recycling efficiency of the memory management group belongs; In the correspondence between the configured recovery efficiency ranges and recovery levels, searching for the first recovery level corresponding to the first recovery efficiency range; Setting the recycling level of the memory management group to the first recycling level; The recycling level of the memory management group corresponding to each application in the third whitelist is adjusted to the second recycling level.

30. The method according to any one of claims 27 to 29, characterized in that The second recycling level is the lowest recycling level.

31. The method according to any one of claims 25, 27 to 29, characterized in that: In the correspondence between the recovery efficiency range and the recovery level, the higher the recovery efficiency value corresponding to the recovery efficiency range is, the higher the recovery level corresponding to the recovery efficiency range is.

32. The method according to claim 24, characterized in that According to the historical data of memory recycling, the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device is obtained, including: For each application, obtain the memory scan amount and memory recovery amount of the memory management group corresponding to the application in the last recovery; A memory recovery efficiency of a memory management group corresponding to the application is determined according to the memory scan amount and the memory recovery amount.

33. The method according to claim 32, characterized in that Determining the memory recovery efficiency of the memory management group corresponding to the application according to the memory scan amount and the memory recovery amount includes: Determining a first memory recovery efficiency of the file page of the memory management group corresponding to the application according to a first memory scan amount and a first memory recovery amount of the file page of the memory management group corresponding to the application in the last recovery; Determining a second memory recycling efficiency of the anonymous pages of the memory management group corresponding to the application according to a second memory scan amount and a second memory recycling amount in a previous recycling; The memory reclaim efficiency of the memory management group corresponding to the application is determined according to the first memory reclaim efficiency and the second memory reclaim efficiency.

34. The method according to claim 33, characterized in that The memory recovery efficiency of the memory management group corresponding to the application is equal to the product of the first memory recovery efficiency and the first coefficient and the sum of the second memory recovery efficiency.

35. The method according to claim 34, characterized in that The first coefficient is determined according to the ratio of the recycling rate of the file pages to the recycling rate of the anonymous pages.

36. The method according to claim 24, characterized in that Based on the recycling priority and the recycling level of each memory management group, determine the target memory management group that needs to be traversed, scan the target memory management group, and recycle the scanned recyclable memory, including: Determine a first target recycling level corresponding to the initial recycling priority according to the corresponding relationship between the recycling priority and the recycling level; Determine a memory management group corresponding to a recycling level equal to or higher than the first target recycling level as a first target memory management group; The first target memory management group is scanned, and the scanned first reclaimable memory is reclaimed.

37. The method according to claim 36, characterized in that Before determining the first target recycling level corresponding to the initial recycling priority according to the correspondence between the recycling priority and the recycling level, the method further includes: The initial recycling priority is determined according to the preset recycling volume of this recycling. The larger the preset recycling volume is, the lower the determined initial recycling priority is.

38. The method according to claim 36, characterized in that Also includes: If the first reclaimable memory is less than a preset reclaim amount, determining a first target reclaim priority according to the initial reclaim priority and the adjustment step size, the first target reclaim priority being lower than the initial reclaim priority; Determine, according to the correspondence between recycling priorities and recycling levels, a second target recycling level corresponding to the first target recycling priority, wherein the second target recycling level is equal to or lower than the first target recycling level; Determine a memory management group corresponding to a recycling level equal to or higher than the second target recycling level as a second target memory management group; The second target memory management group is scanned, and the scanned second reclaimable memory is reclaimed.

39. The method according to claim 38, characterized in that Also includes: If the sum of the first reclaimable memory and the second reclaimable memory is less than the preset reclaim amount, determining a second target reclaim priority according to the first target reclaim priority and the adjustment step, the second target reclaim priority being lower than the first target reclaim priority; According to the corresponding relationship between the recycling priority and the recycling level, the third target recycling priority corresponding to the second target recycling priority is determined. The third target recycling level is equal to or lower than the second target recycling level; Determine a memory management group corresponding to a recycling level equal to or higher than the third target recycling level as a third target memory management group; The third target memory management group is scanned, and the scanned third reclaimable memory is reclaimed.

40. The method according to claim 38 or 39, characterized in that The adjustment step size is a fixed value; or, the adjustment step size is determined as follows: Determine the adjustment step size according to the difference between the total memory recovery amount currently recovered in this round and the preset recovery amount, the larger the difference is, the larger the value of the determined adjustment step size is; Alternatively, the adjustment step size is determined based on the ratio of the difference between the total memory recovery amount currently recovered in this round and the preset recovery amount to the preset recovery amount, and the larger the ratio is, the larger the value of the determined adjustment step size is.

41. The method according to claim 24, characterized in that If the memory recycling process triggering condition is met, before obtaining the memory recycling efficiency of the memory management group corresponding to each application in the current electronic device according to the historical data of memory recycling, the method further includes: It is monitored that the free memory of the electronic device is currently lower than a first value, triggering a memory recycling process.

42. The method according to claim 24, characterized in that The higher the memory recycling efficiency of an application, the higher the recycling level of the corresponding memory management group. The higher the recycling level, the greater the recycling probability.

43. The method according to claim 24, characterized in that The higher the recycling priority, the higher the recycling level of the target memory management group that needs to be traversed, and the smaller the number of target memory management groups when the number of memory management groups and the corresponding recycling levels remain unchanged.

44. The method according to claim 24, characterized in that The electronic device is a mobile phone, a tablet or a television.

Citation Information

Patent Citations

  • Memory reclamation methods and electronic devices

    CN116185890B

  • Memory recycling method and apparatus, computer apparatus and computer readable storage medium

    CN108205498A

  • Memory recovery method and device and electronic equipment

    CN110727607A

  • Memory recovery method and device, storage medium and electronic equipment

    CN111831440A

  • Memory recovery method and device

    CN113778662A