Memory recovery method and electronic equipment
Patent Information
- Application Number
- CN202480012474.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2023-08-07
- Filing Date
- 2024-03-21
- Publication Date
- 2025-09-19
AI Technical Summary
In electronic devices that enable the memory control subsystem mechanism, a large amount of data may occur during the memory recovery process and then be quickly loaded back to the system memory, affecting the memory recovery efficiency.
According to the application popularity, the system memory occupied by the application data is differentially recycled to reduce the amount of data repeatedly released and reloaded. The specific method is to determine a memory amount for each application, which decreases with the increase in application popularity and is recycled according to the memory amount when recycling.
It improves memory recycling efficiency, avoids excessive memory recycling when the application is popular, and reduces the risk of long-term use of system memory for applications with low application popularity.
Smart Images

Figure CN120677470A_ABST
Abstract
Description
Memory recycling method and electronic device
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on August 7, 2023, with application number 202310991388.5 and invention name “A 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 computer technology, and in particular to a memory recycling method and electronic device. Background Art
[0003] The internal memory of an electronic device (such as called RAM) is used to temporarily store the CPU's calculation data and the data exchanged with external storage such as hard disks. The memory is the bridge for communication between the external storage and the CPU. All applications need to run based on memory resources.
[0004] Of course, the memory resources of electronic devices are limited. When the memory is insufficient, the operating system will clear the data of infrequently used applications in the memory, which is called memory recycling.
[0005] In the related art, in an electronic device that has a memory control subsystem mechanism enabled, a large amount of data may be released and then quickly loaded back into the system memory during the memory recycling process, affecting the memory recycling efficiency of the electronic device.
[0006] Summary of the Invention
[0007] The embodiments of the present application provide a memory recovery method and electronic device, which differentially recover the system memory occupied by the application's data according to the application popularity of the application, reduce the amount of data that is repeatedly released and reloaded, and improve memory recovery efficiency.
[0008] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0009] In a first aspect, an embodiment of the present application provides a memory recovery method. The method is applied to an electronic device, in which each application corresponds to a memory control subsystem memcg, and the method includes: determining a first memory amount corresponding to a first application running in the background, wherein the first memory amount indicates the amount of memory to be recovered from the system memory occupied by the first application, and the first memory amount decreases as the application popularity of the first application increases, and the application popularity indicates the activity level of the application running in the background. According to the first memory amount, the system memory occupied by the first application is recovered.
[0010] In the above embodiment, the electronic device that enables the memcg mechanism, in the process of reclaiming system memory, realizes differential recovery of the system memory occupied by the application according to the application heat. For example, as the application heat increases, the amount of reclaimed memory will decrease accordingly, and as the application heat decreases, the amount of reclaimed memory will increase accordingly. On the one hand, it can avoid a large amount of system memory occupied by being recycled when the application heat is high, reduce the released application data (such as anonymous pages), and quickly reload it back into the system memory. On the other hand, it can avoid applications with low application heat from occupying a large amount of system memory for a long time.
[0011] In some embodiments, before determining the first memory amount corresponding to the first application running in the background, the method further includes: determining a first reclaimable memory amount corresponding to the first application; the first memory amount is not greater than the first reclaimable memory amount.
[0012] In the above embodiment, the size of the determined first memory amount is limited by the amount of reclaimable memory of the application, so as to avoid too much system memory being reclaimed at a single time by a single application, resulting in the system memory occupied by some applications not being reclaimed, that is, the problem of uneven system memory recovery occurs among multiple background applications.
[0013] In some embodiments, determining a first reclaimable memory amount corresponding to the first application includes: determining an application score of the first application as a first score; the application score of the first application decreases as the application popularity of the first application increases; determining the first reclaimable memory amount based on the first score, a second memory amount corresponding to the first application, and a third memory amount; wherein the second memory amount indicates the size of all anonymous pages in the first application, and the third memory amount indicates the size of anonymous pages in the first application that have been swapped out from the system memory.
[0014] In the above embodiment, the amount of reclaimable memory for an application is affected not only by the popularity of the application, but also by the total size of all anonymous pages of the application and the size of the transferred anonymous pages. This avoids the problem of excessively high system memory being reclaimed after multiple memory reclamation cycles for highly popular applications.
[0015] In some embodiments, the first reclaimable memory amount is determined based on the first score, the second memory amount and the third memory amount corresponding to the first application, including: determining the transfer storage ratio corresponding to the first score; the transfer storage ratio is used to determine the ratio of the transferable anonymous page size in a single application, and the higher the first score, the higher the corresponding transfer storage ratio; the product of the transfer storage ratio and the second memory amount is determined as the first anonymous page size; and the third memory amount is removed from the first anonymous page size to determine the first reclaimable memory amount.
[0016] In the above embodiment, the problem of excessive total amount of system memory being reclaimed after multiple memory reclaims for highly popular application programs is avoided.
[0017] In some embodiments, if the determined first amount of reclaimable memory is less than zero, its value is revised to zero.
[0018] In the above embodiment, when the application score of the application program changes, the above method may calculate a first reclaimable memory amount less than zero. By correcting the first reclaimable memory amount less than zero, fault tolerance is improved.
[0019] In some embodiments, determining the first memory amount includes: obtaining a first ratio between the first reclaimable memory amount and a fourth memory amount, the fourth memory amount refers to the sum of the reclaimable memory amounts corresponding to all the applications whose application score is the first score and running in the background; and determining the product of the first ratio and the fifth memory amount as the first memory amount, the fifth memory amount refers to the total amount of memory that needs to be reclaimed from all applications whose application score is the first score.
[0020] In the above embodiment, the amount of system memory to be reclaimed from applications with the same application popularity is evenly distributed based on the ratio of the reclaimable memory to the total reclaimable memory of applications with the same score. Thus, for applications with the same popularity, the amount of system memory to be reclaimed is determined by the total anonymous page size of the application and the size of the transferred anonymous pages. This avoids the situation where some applications with the same application popularity have excessive system memory reclaimed while the system memory occupied by other applications remains unreclaimed, thereby improving the efficiency of memory reclamation.
[0021] In some embodiments, each of the applications corresponds to a memcg data structure, and the memcg data structure includes a field for carrying the amount of reclaimable memory; after determining the first amount of reclaimable memory, the method also includes: writing the determined first amount of reclaimable memory into the memcg data structure of the corresponding first application; the determination of the first amount of memory also includes: obtaining a fourth amount of memory; obtaining the fourth amount of memory includes: after the reclaimable memory amount has been written into the memcg data structure of the application running in the background, obtaining the reclaimable memory amount from the memcg data structure of the application running in the background whose application score is the first score; adding all the obtained reclaimable memory amounts to obtain the corresponding fourth amount of memory.
[0022] In some embodiments, after reclaiming the system memory occupied by the first application according to the first memory amount, the method further includes: using the difference between the first reclaimable memory amount of the first application and the first memory amount to update the reclaimable memory amount in the memcg data structure of the first application.
[0023] In the above embodiment, after each recycling, the amount of reclaimable memory in the memcg data structure can be updated. In the next recycling, the process of re-determining the amount of reclaimable memory can be omitted, shortening the time required for memory recycling and improving memory recycling efficiency.
[0024] In some embodiments, determining the first memory amount also includes: counting the total amount of reclaimable memory corresponding to all the applications running in the background of the electronic device; obtaining the fifth memory amount; wherein the proportion of the fifth memory amount in the total amount of memory that needs to be reclaimed by the electronic device is equal to the proportion of the fourth memory amount in the total amount of reclaimable memory of the electronic device.
[0025] In some embodiments, according to the first memory amount, the system memory occupied by the first application is reclaimed, including: among the anonymous pages of the first application, determining a target memory page whose system memory occupancy is the first memory amount, and the activity level of the target memory page is lower than that of other anonymous pages of the first application; swapping the target memory page out of the system memory.
[0026] In the above example, the amount of system memory reclaimed for an application is affected by the popularity of the application. During the memory reclamation process, the activity level of the application data in the application also affects whether the application data is released, reducing the possibility of the application data being loaded back into the system memory quickly after being released.
[0027] In some embodiments, the method further includes: determining a sixth memory amount corresponding to a second application running in the background, wherein the sixth memory amount indicates the amount of memory that needs to be reclaimed from the system memory occupied by the second application, and the anonymous page size stored by the second application in the system memory and the anonymous page size swapped out from the system memory are both the same as those of the first application; when the application heat of the second application is lower than the application heat of the first application, the sixth memory amount is greater than the first memory amount; according to the sixth memory amount, the system memory occupied by the second application is reclaimed, and the sum of the first memory amount and the sixth memory amount is not greater than the total memory amount that needs to be reclaimed by the electronic device.
[0028] In the above embodiment, different applications have different application popularity and different amounts of reclaimed system memory, which prevents active applications from having too much system memory reclaimed while inactive applications occupy system memory for a long time.
[0029] In a second aspect, an embodiment of the present application provides an electronic device, which includes one or more processors and a memory; the memory is coupled to the processor, and the memory is used to store computer program code, and the computer program code includes computer instructions. When one or more processors execute the computer instructions, the one or more processors are used to: determine a first amount of memory corresponding to a first application running in the background, wherein the first amount of memory indicates the amount of memory to be reclaimed from the system memory occupied by the first application, and the first amount of memory decreases as the application heat of the first application increases, and the application heat indicates the activity level of the application running in the background; according to the first amount of memory, reclaim the system memory occupied by the first application.
[0030] In some embodiments, before determining the first amount of memory corresponding to the first application running in the background, the one or more processors are used to: determine a first amount of reclaimable memory corresponding to the first application; the first amount of memory is not greater than the first amount of reclaimable memory.
[0031] In some embodiments, the one or more processors are further used to: determine that the application score of the first application is a first score; the application score of the first application decreases as the application popularity of the first application increases; determine the first reclaimable memory amount based on the first score, the second memory amount and the third memory amount corresponding to the first application; wherein the second memory amount indicates the size of all anonymous pages in the first application, and the third memory amount indicates the size of anonymous pages in the first application that have been swapped out from the system memory.
[0032] In some embodiments, the one or more processors are further used to: determine the transfer storage ratio corresponding to the first score; the transfer storage ratio is used to determine the ratio of the anonymous page size that can be transferred in a single application, and the higher the first score, the higher the corresponding transfer storage ratio; multiply the product of the transfer storage ratio and the second memory amount to determine the first anonymous page size; and remove the third memory amount from the first anonymous page size to determine the first reclaimable memory amount.
[0033] In some embodiments, the one or more processors are further used to: obtain a first ratio between the first reclaimable memory amount and the fourth memory amount, where the fourth memory amount refers to the sum of the reclaimable memory amounts corresponding to all the applications whose application score is the first score and running in the background; and determine the product of the first ratio and the fifth memory amount as the first memory amount, where the fifth memory amount refers to the total amount of memory that needs to be reclaimed from all applications whose application score is the first score.
[0034] In some embodiments, each of the applications corresponds to a memcg data structure, and the memcg data structure includes a field for carrying the amount of reclaimable memory; after determining the first amount of reclaimable memory, the one or more processors are further used to: write the determined first amount of reclaimable memory into the memcg data structure of the corresponding first application; the determination of the first amount of memory also includes: obtaining a fourth amount of memory; obtaining the fourth amount of memory includes: after the reclaimable memory amount has been written into the memcg data structure of the application running in the background, obtaining the reclaimable memory amount from the memcg data structure of the application running in the background whose application score is the first score; adding all the obtained reclaimable memory amounts to obtain the corresponding fourth amount of memory.
[0035] In some embodiments, the one or more processors are further configured to update the reclaimable memory amount in the memcg data structure of the first application using a difference between the first reclaimable memory amount of the first application and the first memory amount.
[0036] In some embodiments, the above-mentioned one or more processors are also used to: count the total amount of reclaimable memory corresponding to all the applications running in the background of the electronic device; obtain the fifth amount of memory; wherein, the proportion of the fifth amount of memory in the total amount of memory that needs to be reclaimed by the electronic device is equal to the proportion of the fourth amount of memory in the total amount of reclaimable memory of the electronic device.
[0037] In some embodiments, the one or more processors are further used to: determine, among the anonymous pages of the first application, a target memory page whose system memory occupancy is the first memory amount, and the activity level of the target memory page is lower than that of other anonymous pages of the first application; and swap the target memory page out of the system memory.
[0038] In some embodiments, the one or more processors are further used to: determine a sixth memory amount corresponding to a second application running in the background, wherein the sixth memory amount indicates the amount of memory that needs to be reclaimed from the system memory occupied by the second application, and the anonymous page size stored by the second application in the system memory and the anonymous page size swapped out from the system memory are both the same as those of the first application; when the application heat of the second application is lower than the application heat of the first application, the sixth memory amount is greater than the first memory amount; according to the sixth memory amount, the system memory occupied by the second application is reclaimed, and the sum of the first memory amount and the sixth memory amount is not greater than the total memory amount that needs to be reclaimed by the electronic device.
[0039] In a third aspect, an embodiment of the present application provides a computer storage medium, comprising computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method in the above-mentioned first aspect and its possible embodiments.
[0040] In a fourth aspect, the present application provides a computer program product. When the computer program product is run on the above-mentioned electronic device, the electronic device executes the method in the above-mentioned first aspect and its possible embodiments.
[0041] It can be understood that the electronic devices, computer storage media and computer program products provided in the above aspects are all applied to the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 is an example diagram of the corresponding least recently used linked list when the memcg mechanism is not enabled;
[0043] Figure 2 is an example diagram of the corresponding least recently used linked list when the memcg mechanism is enabled;
[0044] FIG3 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0045] FIG4 is a diagram illustrating an example of a software structure of an electronic device provided in an embodiment of the present application;
[0046] FIG5 is a flowchart of the steps of a memory recovery method provided in an embodiment of the present application;
[0047] FIG6 is a flow chart of the sub-steps of S101 in FIG5 ;
[0048] FIG7 is an example diagram of the first space size, the second space size, and the third space size corresponding to application a in an embodiment of the present application;
[0049] FIG8 is a diagram illustrating an example scenario of memory recycling for application programs in the same application set according to an embodiment of the present application;
[0050] FIG9 is a diagram illustrating an example scenario of memory recycling for application programs in different application sets provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the description of the present application, unless otherwise specified, "at least one" means one or more, and "a plurality of" means two or more than two. In addition, in order to facilitate the clear description of the technical solutions in the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art will understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.
[0052] For ease of understanding, the technical terms involved in the embodiments of this application are first introduced below.
[0053] External memory is the "external memory" relative to the internal memory of electronic devices. Among them, external memory can include read-only memory (ROM), hard disk, floppy disk, optical disk, USB flash drive, embedded multimedia card (EMMC), universal flash storage (UFS), multimedia card, etc.
[0054] Internal memory, also known as RAM, is used to store page data corresponding to applications. This memory can also include system memory and swap partitions. In systems built on the Linux kernel, page data is primarily stored in system memory using file-backed pages and anonymous pages.
[0055] The above anonymous pages and file pages can be collectively referred to as memory pages.
[0056] Among them, anonymous pages are memory pages that are not tagged with names by the operating system. The Virtual Memory Address (VMA) cannot distinguish different anonymous pages based on their names. Thus, memory pages without name tags are called anonymous pages. When anonymous pages are recycled, in order for the kernel to be able to access the corresponding anonymous pages later, the anonymous pages cannot be directly released (i.e., deleted) in the system memory. Instead, they need to be swapped out from the system memory to the Swap partition for compressed storage. The data in the Swap partition can be accessed by the CPU. Anonymous pages specifically refer to system memory pages that are dynamically allocated during program execution, including heaps, stacks, data segments, etc.
[0057] File pages, the operating system provides memory pages with name tags, and the corresponding file names are recorded on the VMA. Different file pages can be distinguished according to the file names, and the system memory pages with name tags are called file pages. When the file page is recycled, the file page can be directly released (that is, deleted) in the system memory. Afterwards, the kernel can load the file page from the external memory to the system memory according to the file name of the file page, and then read it. File pages specifically refer to memory pages that store file-type data, including code segments, library files, and file data accessed by program interactions.
[0058] Taking the scenario of an electronic device playing music as an example, the system memory occupied by the program data of the electronic device running the player belongs to anonymous pages, and the system memory occupied by the music files loaded from the electronic device from the external memory into the system memory belongs to file pages.
[0059] ZRAM, also known as zRAM, is a CPU core feature that provides virtual memory compression. For example, zRAM compresses anonymous pages swapped out to the swap partition.
[0060] The swap partition is an area allocated from the memory. If the memory space is insufficient, there is no need to kill the application. Instead, the anonymous pages of the application are swapped out to the swap partition and compressed. When the application is enabled again, this part of the data can be directly restored to the system memory, saving the time required to restart the application.
[0061] The memory swap mechanism (swap mechanism) writes data stored in infrequently accessed memory to external memory, reclaiming this memory space and making it available for use by other processes. For example, a swap area is created on the hard disk. Through the swap area, inactive memory pages are swapped to the hard disk, effectively increasing memory usage.
[0062] The least recently used (LRU) algorithm is a commonly used memory page replacement algorithm. It is understandable that if a piece of data has not been accessed in the recent period, then the possibility of being accessed in the future is also very small. When memory reclamation is required, the least recently used memory page is selected to be reclaimed to reclaim the memory space of this part of the memory page. In the LRU linked list, memory pages are arranged in ascending order according to the corresponding first time interval. Among them, the first time interval refers to the time interval between the time point when the memory page was last used and the current time point. In this way, in the LRU linked list, the memory page that is closer to the end of the linked list is accessed earlier (that is, the memory page is colder), and the memory page that is closer to the head of the linked list is accessed more recently (that is, the memory page is hotter). When reclaiming memory, recycling starts from the end of the linked list.
[0063] In some embodiments, a memory watermark may be pre-configured in the electronic device to indicate conditions for triggering memory space reclamation. When the amount of system memory occupied in the electronic device exceeds the memory watermark, reclamation of the system memory may be triggered.
[0064] In some embodiments, the memory pages of all applications in the electronic device are mounted on the LRU linked list of the same node. The same node corresponds to multiple LRU linked lists, such as an inactive anonymous linked list, an active anonymous linked list, an inactive file linked list, an active file linked list, and a non-recycled linked list.
[0065] Exemplarily, the inactive anonymous linked list is loaded with anonymous pages that have not been accessed in the recent period. For example, the inactive anonymous linked list includes page descriptors of anonymous pages that have not been accessed in the recent period. The end point of the recent period is the current time point, and the length is a preset duration. When memory is recycled, the anonymous page to be released (such as the target memory page) can be determined from the inactive anonymous linked list and swapped out to the swap partition. In addition, the anonymous pages in the inactive anonymous linked list can be arranged according to the interval length of the corresponding first time interval, so that the anonymous page with a shorter first time interval is arranged near the head of the linked list, and the anonymous page with a longer first time interval is arranged near the tail of the linked list. The electronic device can preferentially determine the anonymous page near the tail of the linked list as the target memory page.
[0066] The active anonymous list is used to mount anonymous pages that have been accessed recently. Anonymous pages in the active anonymous list cannot be swapped out directly to the swap partition. In some embodiments, the first time interval corresponding to the anonymous pages in the active anonymous list is greater than a preset length. In other words, if the anonymous page has not been accessed recently, it can be placed in the inactive anonymous list.
[0067] The inactive file list is used to mount file pages that have not been accessed recently. During memory reclamation, the system memory occupied by file pages in the inactive file list can be directly reclaimed. Similar to the inactive anonymous list, the difference lies in the type of memory pages mounted.
[0068] The active file list is used to mount file pages that have been accessed recently. The system memory occupied by file pages in the active file list cannot be directly reclaimed. Similar to the active anonymous list, the difference lies in the type of memory pages mounted.
[0069] The non-reclaimable linked list is used to mount locked memory pages that cannot be reclaimed. They may be anonymous pages or file pages.
[0070] As shown in Figure 1, the electronic device includes APP1, APP2, APP3 and APP4 running. Among them, APP1, APP2, APP3 and APP4 can be running in the foreground or in the background, and are not specifically limited in this example. Exemplarily, as shown in Figure 1, in the memory pages corresponding to APP1, APP2, APP3 and APP4, anonymous pages (inactive anonymous) that have not been accessed in the recent period are mounted on the inactive anonymous linked list corresponding to the node. Exemplarily, in the memory pages corresponding to APP1, APP2, APP3 and APP4, anonymous pages (active anonymous) that have been accessed in the recent period are mounted on the active anonymous linked list of the node. Exemplarily, in the memory pages corresponding to APP1, APP2, APP3 and APP4, file pages (inactive file) that have not been accessed in the recent period are mounted on the inactive file linked list of the node. Exemplarily, in the memory pages corresponding to APP1, APP2, APP3 and APP4, file pages (active file) that have been accessed in the recent period are mounted on the active file linked list of the node. For example, among the memory pages corresponding to APP1, APP2, APP3, and APP4, locked memory pages (unevictable) are mounted on the non-recycling linked list of the node.
[0071] When the system memory usage of an electronic device exceeds the corresponding memory watermark, the electronic device can traverse the inactive anonymous linked list and inactive file linked list corresponding to the node and select the target memory page that can be released (e.g., deleted or swapped out to the swap partition and compressed). For example, the target memory page is the memory page at the end of the inactive anonymous linked list or the end of the inactive file linked list.
[0072] If the target memory page is a file page, you can delete the file page and reclaim the system memory occupied by it. If the target memory page is an anonymous page, it is swapped out to the swap partition and compressed. This reclaims the system memory occupied by the target memory page, which is also called reclaiming system memory.
[0073] In the subsequent embodiments, description will be made by taking the target memory page to be released as an anonymous page as an example. The determination of the target memory page from the LRU linked list of the application mentioned in the subsequent embodiments may refer to determining the target memory page from an inactive anonymous linked list.
[0074] In other embodiments, the electronic device can manage the system memory occupied by different applications through a memory control subsystem (memory cgroup, memcg) mechanism. Thus, the electronic device can create a memcg for each application. Each application corresponds to a data node, and different applications have different data nodes. Furthermore, each data node corresponds to multiple LRU linked lists, and the LRU linked lists of the same data node contain memory pages of the same application.
[0075] As shown in Figure 2, the electronic device includes running APP1 and APP2. APP1 and APP2 can be running in the foreground or in the background, which is not specifically limited in this example.
[0076] Exemplarily, as shown in FIG2 , memcg1 is mounted after the node in the electronic device, and memcg1 is used to manage the memory pages corresponding to APP1 . Anonymous pages that have not been accessed in the recent period are mounted on the inactive anonymous linked list corresponding to memcg1 .
[0077] As shown in Figure 2, among the memory pages corresponding to APP1, anonymous pages that have been accessed recently are mounted on memcg1's active anonymous list. Among the memory pages corresponding to APP1, file pages that have not been accessed recently are mounted on memcg1's inactive file list. Among the memory pages corresponding to APP1, file pages that have been accessed recently are mounted on memcg1's active file list. Among the memory pages corresponding to APP1, locked memory pages are mounted on memcg1's non-reclaimable list.
[0078] As shown in Figure 2, memcg2 is mounted after the node in the electronic device. In the memory page corresponding to APP2, the anonymous page that has been accessed in the recent period is mounted on the active anonymous linked list of memcg2. In the memory page corresponding to APP2, the file page that has not been accessed in the recent period is mounted on the inactive file linked list of memcg2. In the memory page corresponding to APP2, the file page that has been accessed in the recent period is mounted on the active file linked list of memcg2. In the memory page corresponding to APP2, the locked memory page is mounted on the non-recycling linked list of memcg2. Of course, when there are more applications running in the electronic device, the electronic device can also include more data nodes, and the LRU linked list of each data node is mounted with the memory page of the corresponding application.
[0079] In a scenario where the system memory usage of an electronic device exceeds the corresponding memory watermark, the electronic device can sequentially traverse the LRU linked list corresponding to each data node, select the target memory page, and reclaim the system memory occupied by the target memory page. When the system memory meets the preset conditions, stop traversing the LRU linked list corresponding to the remaining data nodes. The preset conditions may be: the system memory usage after recovery is not greater than the memory watermark, or the difference between the memory watermark and the system memory usage after recovery is not less than a preset threshold.
[0080] It is understandable that after electronic devices use the memcg mechanism to manage system memory, the management granularity of the electronic devices for system memory can be refined to the application level. Currently, the memcg mechanism has been widely used in most electronic devices.
[0081] However, for an electronic device with the memcg mechanism enabled, if the electronic device contains multiple background running applications, during the memory recycling process, the system memory occupied by applications with a higher probability of use may be recycled, while the system memory occupied by applications with a lower probability of use may not be recycled.
[0082] It is understandable that during the memory recycling process of the electronic device, the LRU linked list of each application is indiscriminately traversed to determine the target memory page that can be released. In this way, a scenario may occur where the LRU linked list of an application with a higher probability of use is traversed before the LRU linked list of an application with a lower probability of use. In addition, after the system memory occupied by the application with a higher probability of use is recycled, if the system memory meets the preset conditions, the recycling of the system memory occupied by other applications will also stop. In this way, in the scenario where the LRU linked list of an application with a higher probability of use is traversed before the LRU linked list of an application with a lower probability of use, the system memory occupied by the application with a higher probability of use is recycled, while the system memory occupied by the application with a lower probability of use is not recycled.
[0083] Furthermore, the target memory page identified from the LRU linked list of an application with a high probability of use has a lower access probability than other memory pages of that application, but has a higher access probability than memory pages of applications with a low probability of use. After the system memory occupied by the target memory page of an application with a high probability of use is reclaimed, it may be loaded back into the system memory a short time later, or even trigger memory reclamation again. Clearly, this not only fails to alleviate memory pressure, but also affects the service life of the storage device.
[0084] Taking the scenario where the system memory occupied by anonymous page 1 of APP1 is reclaimed while APP1 and APP2 are kept alive in the background as an example, the usage probability of APP1 is higher than that of APP2. When performing memory recycling, the LRU linked list corresponding to APP1 is first traversed, and anonymous page 1 is determined as the target memory page. After anonymous page 1 is swapped out to the swap partition (or external memory), it is determined that the recycled system memory meets the preset conditions, and the electronic device does not continue to reclaim the system memory occupied by APP2.
[0085] Afterwards, the electronic device detects the user's instruction to run App 1 in the foreground and needs to reload anonymous page 1 from the swap partition (or external memory) back to the system memory. During this process, the time interval between swapping out to the swap partition or external memory and reloading back to the system memory is called the reload interval.
[0086] It is understandable that the probability of APP1 being used is higher than that of APP2, and the probability of APP1's anonymous page 1 being accessed is also higher than that of APP2's anonymous page 2, where anonymous page 2 is a memory page mounted on the inactive anonymous linked list corresponding to APP2. After anonymous page 1 is recycled, the electronic device will not recycle the system memory occupied by anonymous page 2 because the system memory has met the preset conditions. However, the probability of anonymous page 2 being accessed is lower than that of anonymous page 1. In comparison, it is more likely that the reload interval corresponding to anonymous page 1 is shorter than the reload interval corresponding to anonymous page 2. However, the electronic device only recycles anonymous page 1 and does not recycle anonymous page 2, causing anonymous page 2 to occupy the system memory all the time. After anonymous page 1 is released, it will be reloaded into the system memory. In this way, repeated release and reloading not only fails to alleviate memory pressure, but also reduces the life of the storage device.
[0087] Furthermore, even for applications with the same probability of being used, the order in which they are traversed may cause some applications to have their system memory reclaimed while others may not. In this unequal reclaim scenario, if the recycled application needs to run in the foreground, the memory pages required to be loaded back into the system memory will be larger and take longer to load.
[0088] To improve the above-mentioned problems, an embodiment of the present application provides a memory recovery method that can be applied to electronic devices with the memcg mechanism enabled. In scenarios where memory recovery is required, the electronic device can predetermine the size of the memory to be recovered for each application. The higher the probability of application use, the smaller the corresponding memory to be recovered. The lower the probability of application use, the larger the corresponding memory to be recovered. For applications with the same probability of use, the size of the memory to be recovered corresponding to each application is determined according to the size of the recyclable memory.
[0089] Afterwards, when traversing the LRU linked list of each application, the system memory occupied by the application is reclaimed according to the size of the memory to be reclaimed corresponding to the application.
[0090] In this way, electronic devices that enable the memcg mechanism can also reclaim system memory in a balanced manner, avoiding the situation where memory pages with a higher access probability are reclaimed while memory pages with a lower access probability are not reclaimed. It also reduces the memory reclaim size of a single application and improves the efficiency of reloading the reclaimed memory pages of the application.
[0091] Exemplarily, the electronic device may be a mobile phone, a tablet computer, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), an augmented reality (AR) or virtual reality (VR) device, etc. The embodiments of the present application do not impose any special restrictions on the specific form of the electronic device. In the subsequent embodiments, a mobile phone configured with a Linux kernel is mainly used as an example for explanation.
[0092] Please refer to FIG3 , which is a schematic structural diagram of a mobile phone provided in an embodiment of the present application.
[0093] As shown in Figure 3, the mobile phone may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0094] Among them, the above-mentioned sensor module 180 may include sensors such as pressure sensor, gyroscope sensor, air pressure sensor, magnetic sensor, acceleration sensor, distance sensor, proximity light sensor, fingerprint sensor, temperature sensor, touch sensor, ambient light sensor and bone conduction sensor.
[0095] It should be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the mobile phone. In other embodiments, the mobile phone may include more or fewer components than shown, or some components may be combined or separated, or arranged differently. The components shown in the illustrations may be implemented in hardware, software, or a combination of software and hardware.
[0096] 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.
[0097] The controller is the nerve center and command center of the mobile phone. It can generate operation control signals based on instruction opcodes and timing signals to complete the control of instruction fetching and execution.
[0098] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0099] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0100] It is understood that the interface connection relationship between the modules illustrated in this embodiment is only for illustrative purposes and does not constitute a structural limitation on the mobile phone. In other embodiments, the mobile phone may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0101] The mobile phone implements its display functionality through a GPU, display 194, and an application processor. The GPU is a microprocessor for image processing that connects display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0102] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the phone's storage capacity. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage. For example, files such as music and videos can be stored on the external memory card.
[0103] The internal memory 121 can be used to store computer executable program code, which includes instructions. The internal memory 121 can include a program storage area and a data storage area. In addition, the internal memory 121 can include a high-speed random access memory and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the mobile phone by running the instructions stored in the internal memory 121 and / or the instructions stored in the memory provided in the processor.
[0104] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED).
[0105] The mobile phone can realize the shooting function through the ISP, camera 193, video codec, GPU, display 194 and application processor.
[0106] The ISP processes data fed back by camera 193. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and converted into a visible image. The ISP can also perform algorithmic optimization on image noise, brightness, and skin tone. It can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within camera 193.
[0107] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the mobile phone may include N cameras 193, where N is a positive integer greater than 1.
[0108] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when a mobile phone selects a frequency, the DSP performs a Fourier transform on the frequency energy.
[0109] Video codecs are used to compress or decompress digital video. A mobile phone may support one or more video codecs. This allows it to play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.
[0110] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU enables intelligent cognitive applications in mobile phones, such as image recognition, face recognition, voice recognition, and text comprehension.
[0111] A software system developed based on the Linux kernel runs on top of the above components. The software system can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. In the embodiments of this application, the Android system with a layered architecture is used as an example to illustrate the software system architecture of a mobile phone.
[0112] As shown in FIG4 , the above software system architecture includes an application layer (Application, APP), an application framework layer (also called application framework layer or Framework) and a kernel layer (Kernel).
[0113] For example, the application layer may include a series of application packages. As shown in FIG4 , the application package may include applications such as camera, gallery, calendar, call, map, etc.
[0114] For example, the application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0115] In addition, the application framework layer can also manage applications and record the running status of each application (for example, foreground, background or stopped running status), as well as the time point of state switching.
[0116] In some embodiments, as shown in FIG4 , the application framework layer further includes an application evaluation module, which can obtain the application's running status and state transition time from the application framework layer. Furthermore, the application evaluation module can also calculate an application score corresponding to each application based on the running status and state transition time according to preconfigured rules. Different application scores correspond to different usage probabilities, while the same application scores correspond to the same usage probabilities. Furthermore, the changing trend of the application score can indicate the changing trend of the usage probability. For example, a higher application score indicates a lower usage probability for the application, while a lower application score indicates a higher usage probability for the application. Of course, in other embodiments, a higher application score may indicate a higher usage probability for the application, while a lower application score may indicate a lower usage probability for the application. This depends on the specific rules used to calculate the application score, and this is not specifically limited in the present embodiment. In the subsequent embodiments, a higher application score indicates a lower usage probability, while a lower application score indicates a higher usage probability.
[0117] Exemplarily, the kernel layer is a layer between hardware and software that provides interaction with the hardware. The kernel layer may include various functional modules and drivers.
[0118] As shown in Figure 4, the kernel layer includes a memory reclamation module. After obtaining the application scores from the application evaluation module, this memory reclamation module determines the amount of system memory to be reclaimed occupied by each application. The process for determining the amount of memory to be reclaimed is described in subsequent embodiments and is not detailed here. Subsequently, while traversing the LRU linked lists of each application, the system memory occupied by that application is reclaimed based on the amount of memory to be reclaimed.
[0119] In addition, the memory recycling module can also monitor the memory status of the electronic device and trigger a memory recycling process when it detects that the memory recycling conditions are met. The memory recycling conditions may include the system memory usage exceeding the memory waterline.
[0120] It is understandable that the above software system architecture may also include layers not shown in FIG4 , such as the HAL layer, Android runtime, system library, etc., which will not be described in detail here.
[0121] The following describes, with reference to the accompanying drawings, a process of memory recycling in an electronic device with the memcg mechanism enabled in an embodiment of the present application.
[0122] In an embodiment of the present application, the electronic device may evaluate the application score of an application program running in the background.
[0123] In some embodiments, the electronic device may periodically evaluate application scores corresponding to application programs running in the background.
[0124] As an implementation method, the application score corresponding to the application running in the background is evaluated as follows:
[0125] S1, the application evaluation module can obtain the running status and state switching time point of each application from the application framework layer at a preset time interval.
[0126] The application evaluation module can determine the application currently running in the background based on the running status of each application. The application evaluation module can also determine the time when the background-running application most recently switched to background operation based on the state switching time point. The application evaluation module can then determine the current background operation duration of the background-running application based on the current system time and the time when it most recently switched to background operation. Furthermore, the application evaluation module can also determine the usage frequency of each background-running application based on the state switching time point. For example, the usage frequency can be the number of times each application switched to foreground operation during a specified time period, where the specified time period can be between a first time point and the current time point. The first time point can be the early morning of the same day, or a time point with a specified interval from the current time point. Furthermore, the application evaluation module can also predict the user's usage habits for each application based on the state switching time point, such as the time period during which the application is frequently used, or groups of applications that are frequently used.
[0127] S2. After obtaining the running status and state switching time points of each application, the application evaluation module can also evaluate the corresponding scores of the application from multiple dimensions such as application type, background running time, usage frequency, and usage habits.
[0128] In some embodiments, the application evaluation module can evaluate the application's corresponding score based on the application's operation record data, taking into account multiple dimensions such as application type, background operation time, usage frequency, and usage habits. The operation record data may include the time points when the application was running in the foreground, the time points when it was running in the background, and the application service provision status information during the background operation.
[0129] Taking the score of the application type dimension as an example, the score of the first type of application in the application type dimension is 1, and the score of the non-first type of application in the application type dimension is 2, and the score of 1 is smaller than the score of 2.
[0130] The first type may indicate an application in a specific state. For example, the specific state may be an application running in the background and normally providing corresponding application services. For example, in the exemplary scenario, a music application is running in the background and playing music normally, and its score in the application type dimension is determined to be 1.
[0131] In other embodiments, the first type may also indicate an application with a specific identifier. For example, the specific identifier may be an identifier assigned to the application in response to a user's pre-selection of the application, and the specific identifier may be used to distinguish applications that have not been pre-selected by the user.
[0132] Taking the background runtime score as an example, the longer an app runs in the background, the higher its score. The shorter an app runs in the background, the lower its score. Electronic devices can pre-configure different background runtime intervals and corresponding scores. This allows you to match an app's background runtime score to its own.
[0133] Taking the frequency of use score as an example, the less frequently an app is used, the higher its score is. The more frequently an app is used, the lower its score is.
[0134] Taking the score for the usage habit dimension as an example, if the usage habit for an application indicates that the application is currently used, the score for the application type dimension is 3. If the usage habit for an application indicates that the application is not currently used, the score for the application type dimension is 4, which is greater than 3.
[0135] S3, after obtaining the scores of the application in each dimension, the application evaluation module can fit the application score corresponding to the application according to the scores corresponding to each dimension.
[0136] In some embodiments, a preconfigured algorithm can be used to fit the scores corresponding to each dimension to obtain the application score corresponding to the application. For example, the scores of each dimension can be processed in combination with the weights of different dimensions, and then the processed scores can be superimposed to obtain the application score.
[0137] In other embodiments, when the running state of any application changes, the electronic device may be triggered to evaluate the application score corresponding to the application running in the background. For example, when an application running in the foreground switches to running in the background, the electronic device may be triggered to evaluate the application score corresponding to the application currently running in the background.
[0138] In other embodiments, the electronic device may not only periodically evaluate the application scores corresponding to background running applications, but may also trigger the evaluation of the application scores corresponding to any application when the application switches from foreground running to background running.
[0139] In an embodiment of the present application, after determining the application scores of the applications running in the background, the electronic device may also determine the size of the to-be-reclaimed memory corresponding to each application running in the background.
[0140] For example, each time the application evaluation module obtains an application score of an application program, the application score may be sent to the memory recycling module.
[0141] As another example, when the memory recycling module identifies a scenario where memory recycling is required, the application score of each application program running in the background is obtained from the application evaluation module.
[0142] As an implementation manner, the memory recycling module in the electronic device may calculate the size of the to-be-reclaimed memory corresponding to each background-running application program according to the application score from the application evaluation module.
[0143] In some embodiments, as shown in FIG5 , the process of calculating the size of the to-be-reclaimed memory corresponding to each background application is as follows:
[0144] S101, determining the reclaimable memory size of each application running in the background, where the value of the reclaimable memory size is affected by the popularity of the application.
[0145] The popularity of an application can indicate the activity level of the application while it is running in the background. For example, an application with a high probability of being used (or a high probability of being switched to the foreground) has a higher popularity, while an application with a low probability of being used (or a high probability of being switched to the foreground) has a lower popularity.
[0146] For example, the application popularity of the above-mentioned application can be indicated by the application score of the application. In the above-mentioned embodiment, the process of evaluating the application score can also be an evaluation of the application popularity. Of course, the higher the application score, the lower the application popularity corresponding to the application, and the lower the application score, the higher the application popularity corresponding to the application. In the actual operation process, the application score of the application can decrease as the application popularity increases, and increase as the application popularity increases.
[0147] In some embodiments, the higher the application score, the larger the value of the reclaimable memory size determined. The lower the application score, the smaller the value of the reclaimable memory size determined.
[0148] In other embodiments, in addition to being affected by the application heat, the reclaimable memory size of the application may also be affected by the size of anonymous pages that have been dumped by the application.
[0149] As shown in FIG6 , the above S101 may further include the following sub-steps:
[0150] S101-1, traverse the memcg corresponding to each background application.
[0151] In some embodiments, the memory recycling module may traverse the memcg data structure corresponding to the background application. Exemplarily, the memcg data structure may include a data node for associating with the LRU linked list, a field for recording an application identifier, etc. The application identifier is used to uniquely identify an application.
[0152] As another example, the memcg data structure may further include a field for recording an application score. That is, after the application evaluation module determines the application score of an application, the application score may be passed to the kernel layer and written into the field for recording the application score in the memcg data structure of the application.
[0153] As another example, the memcg data structure may also include other types of data, such as anonymous pages of the application in the system memory and the size of the storage space occupied, such as the first space size.
[0154] The anonymous pages of the application that have been swapped out to the swap partition (e.g., compressed pages) and the amount of storage space occupied by the compressed pages in the swap partition are referred to as the second space size. For another example, the anonymous pages of the application that have been swapped out to external memory (e.g., dump pages) and the amount of storage space occupied by the dump pages in the external memory are referred to as the third space size.
[0155] For example, as shown in Figure 7, storage area a1 in system memory is used to store anonymous pages for application a, storage area a2 in the swap partition is used to store compressed pages for application a, and storage area a3 in external memory is used to store dumped pages for application a. Storage area a1 is 40MB in size, a2 is 5MB in size, and a3 is 15MB in size. Thus, the corresponding first space size in application a's memcg data structure is 40MB, the second space size is 5MB, and the third space size is 15MB.
[0156] As an implementation method, the memory recovery module can match the memcg data structure corresponding to the background running application according to the application identifier of the background running application, and then traverse the memcg data structure of each background running application in turn.
[0157] S101 - 2 , when traversing to the memcg of application a, obtain the application score a, the first space size, the second space size, and the third space size of application a.
[0158] In some embodiments, the above-mentioned application a is an example of an application running in the background. It can be understood that when traversing the memcg of other applications running in the background, the application score, first space size, second space size and third space size of the application can also be obtained.
[0159] In some embodiments, the sum of the first, second, and third memory sizes of the first application may be referred to as a second memory amount. The second memory amount indicates the size of all anonymous pages of the application. The sum of the second and third memory sizes of the first application may be referred to as a third memory amount. The third memory amount indicates the size of the anonymous pages of the application that have been transferred to storage.
[0160] In addition, the first memory size, second memory size, third memory size, and application score a corresponding to application A can all be obtained from the memcg data structure corresponding to application A. The second memory size and third memory size can indicate the storage space occupied by anonymous pages swapped out of system memory in application A.
[0161] S101 - 3 , querying the corresponding transfer-storage ratio a according to the application score a and the pre-configured first list.
[0162] In some embodiments, a first list may be preconfigured in the electronic device. The first list may indicate the transfer ratios corresponding to different application scores. For example, the first list may include application score a and corresponding transfer ratio a.
[0163] When application a is the first application, the first score of the first application is application score a, and the transfer ratio corresponding to the first score can be determined as transfer ratio a through the first list. In addition, the higher the first score, the higher the corresponding transfer ratio.
[0164] Among them, the transfer ratio can indicate the ratio between the anonymous page size of the application that can be transferred and the size of all anonymous pages (anonymous pages contained in the system memory, compressed pages in the swap partition, and transfer pages in the external memory). The size of the anonymous page that can be transferred is not less than the size of the anonymous pages that have been swapped out to the swap partition and the external memory. In addition, in the first list, the higher the application score, the larger the corresponding transfer ratio, and the lower the application score, the smaller the corresponding transfer ratio. In this way, after determining the application score a of application a, the memory recovery module can use the application score a to match the transfer ratio a corresponding to the application score a from the first list.
[0165] S101 - 4 , calculating the reclaimable memory size a corresponding to the application a according to the transfer storage ratio a, the first space size, the second space size, and the third space size corresponding to the application a.
[0166] In some embodiments, the first, second, and third memory sizes corresponding to application a can be added together to obtain the size corresponding to all anonymous pages of application a. The transfer ratio a and the sizes corresponding to all anonymous pages are then used to determine the size of anonymous pages that can be transferred. The transferred anonymous page size is then subtracted from the size of anonymous pages that can be transferred to obtain the reclaimable memory size a. The transferred anonymous page size is equal to the sum of the second and third memory sizes.
[0167] S101 - 5 , when the reclaimable memory size a is not less than 0, the reclaimable memory size a is associated with the memcg of the application a.
[0168] In some embodiments, the above-mentioned reclaimable memory size a (or reclaimable memory amount) can be written into the field for storing the reclaimable memory amount in the memcg data structure of application a, so that the reclaimable memory size a is associated with the memcg of application a.
[0169] It is understandable that, in theory, the reclaimable memory size a is not less than 0. Of course, during actual operation, the calculated reclaimable memory size a may be less than 0 based on the transfer ratio a and the first, second, and third space sizes corresponding to application a. For example, in a scenario where the application score of an application changes from a larger value to a smaller value, some anonymous pages have been swapped out to the swap partition or external memory when the application score is larger. If the anonymous pages swapped out to the swap partition or external memory are not loaded back into system memory before the application score becomes smaller, then after the application score becomes smaller, the calculated "anonymous page size that can be transferred" based on the transfer ratio corresponding to the smaller application score may be less than the actual size of the anonymous pages transferred. According to S101-4 above, if the value of the determined reclaimable memory size a is less than 0, in this scenario, the calculated value of the reclaimable memory size a can be revised to 0. After the value of the reclaimable memory size a is revised to 0, the reclaimable memory size a can also be associated with the memcg of application a.
[0170] In the above embodiment, the higher the corresponding application score, the larger the reclaimable memory size determined by the above method is, and the lower the corresponding application score, the smaller the reclaimable memory size determined by the above method is. In this way, the reclaimable memory size (maximum reclaimable amount) corresponding to the application with a higher usage probability is smaller, avoiding excessive reclaiming of system memory occupied by applications with a higher usage probability, and providing conditions for balanced reclaiming of system memory occupied by various applications within a time limit.
[0171] As an implementation approach, the algorithm for determining the reclaimable memory size of each application can be implemented as follows:
[0172] It is understood that the reclaimable memory size is the maximum amount of memory that can be reclaimed from the system memory occupied by the application program, determined based on the application score. After obtaining the reclaimable memory sizes corresponding to all the applications, the process may proceed to S102.
[0173] S102, traverse each application running in the background, and when traversing to application a, determine the memory size to be reclaimed corresponding to application a, and reclaim the system memory occupied by application a according to the memory size to be reclaimed, and the memory size to be reclaimed is not larger than the reclaimable memory size.
[0174] The "to-be-reclaimed memory size" refers to the amount of memory reclaimed from the system memory occupied by the application when memory reclamation is actually performed. This can also be referred to as the "memory size to be reclaimed" from the application. The value of this "to-be-reclaimed memory size" is limited by the reclaimable memory size, which is also affected by the application's popularity. This ensures that the amount of to-be-reclaimed memory corresponding to each application is affected by the application's popularity, preventing high-popularity applications from having too much system memory reclaimed.
[0175] In addition, the size of memory to be reclaimed corresponding to the first application can be called the first memory amount, and the size of memory to be reclaimed corresponding to the second application can be called the sixth memory amount. The first memory amount is affected by the application popularity of the first application. The higher the application popularity of the first application, the lower the corresponding first memory amount, and the lower the popularity of the first application, the higher the corresponding first memory amount. In short, the first memory amount decreases as the application popularity of the first application increases. Of course, the first memory amount is also limited by the reclaimable memory size of the first application (that is, the first reclaimable memory amount). When the application popularity of the first application is high, it is avoided that the total amount of system memory reclaimed by the first application is too much after multiple memory recycling.
[0176] Similarly, the second memory amount is affected by the popularity of the second application. The higher the popularity of the second application, the lower the corresponding second memory amount, and the lower the popularity of the second application, the higher the corresponding second memory amount. In short, the second memory amount decreases as the popularity of the second application increases. Of course, the second memory amount is also limited by the reclaimable memory size of the second application (i.e., the second reclaimable memory amount).
[0177] In addition, in a scenario where the first space size, the second space size, and the third space size corresponding to the first application and the second application are all the same, if the application popularity of the second application is lower than the application popularity of the first application, the second memory amount is greater than the first memory amount.
[0178] In some embodiments, the process of determining the size of memory to be reclaimed corresponding to each application program may be as follows:
[0179] A1. Divide the applications running in the background into multiple application sets according to the application scores, wherein the divided application set a includes application a.
[0180] In some embodiments, application programs with the same application score may be grouped into the same application set, and application programs with different application scores may belong to different application sets.
[0181] In other embodiments, multiple consecutive score intervals may be pre-divided, and then applications with scores in the same score interval are grouped together as applications. In the following embodiments, applications with the same score are grouped together.
[0182] A2 determines the total memory space that needs to be reclaimed this time.
[0183] In some embodiments, the memory reclaiming module may obtain the currently occupied system memory size and the memory watermark, and obtain the total memory space size to be reclaimed based on the currently occupied system memory size and the memory size indicated by the memory watermark.
[0184] In other embodiments, each time the electronic device executes memory recycling, the reclaimed memory space size is fixed. In this scenario, the memory recycling module can obtain a pre-configured memory size value as the total memory space size to be recycled.
[0185] In another embodiment, the memory recovery module can obtain the currently occupied system memory size and the target memory size, and determine the total memory space size that needs to be recovered based on the difference between the currently occupied system memory size and the target memory size. The above-mentioned target memory size may be smaller than the memory size indicated by the memory waterline. The above-mentioned target memory size refers to the occupied system memory size retained after each memory recovery, and the target space size may be a fixed value or a variable value. For example, the target memory size may be determined based on the actual available system memory size and a set ratio. In a scenario where the actual available system memory becomes less, the above-mentioned target memory size may also change.
[0186] A3, based on the total memory space that needs to be reclaimed, determine the memory size to be reclaimed from the system memory occupied by each application set, such as the fourth space size.
[0187] In some embodiments, the fourth space size corresponding to each application set can also be allocated according to the application score corresponding to each application set. The higher the application score corresponding to the application set, the larger the corresponding fourth space size. The lower the application score corresponding to the application set, the smaller the corresponding fourth space size.
[0188] In this embodiment, differentiated system memory recycling can be achieved for application sets with different application scores, reducing the problem of uneven system memory recycling, that is, more system memory is recycled for application sets with high usage frequency, and less system memory is recycled for application sets with low usage frequency.
[0189] As an implementation manner, the above-mentioned method of allocating the corresponding fourth space size to each application set may include:
[0190] Obtain a matching allocation ratio table. In which, multiple allocation ratio tables can be pre-configured in the electronic device, and the allocation ratio table includes multiple application scores and corresponding allocation ratio values. There are differences in the application scores corresponding to different allocation ratio tables. For example, the number of application scores included in different allocation ratio tables is different, or the value of at least one application score in different allocation ratio tables is different. The sum of multiple allocation ratio values in the same allocation ratio table is 100%. At the same time, in the allocation ratio table, the larger the application score, the higher the corresponding allocation ratio value. The smaller the application score, the lower the corresponding allocation ratio value.
[0191] For example, the allocation ratio table 1 includes application score 1, application score 2, and application score 3. In the scenario where application score 1 is greater than application score 2, and application score 2 is greater than application score 3, the allocation ratio value corresponding to application score 1 in the allocation ratio table 1 can be 70%, the allocation ratio value corresponding to application score 2 can be 20%, and the allocation ratio value corresponding to application score 3 can be 10%.
[0192] For another example, allocation ratio table 2 includes application score 1 and application score 4. In a scenario where application score 1 is greater than application score 4, the allocation ratio value corresponding to application score 1 in allocation ratio table 2 can be 60%, and the allocation ratio value corresponding to application score 4 can be 40%.
[0193] It is understandable that the pre-configured multiple different allocation ratio tables can cope with the scenario of dividing different application sets. The allocation ratio values in each allocation ratio table can be empirical values.
[0194] In the multiple allocation ratio tables, the matching allocation ratio table includes the same application scores as the application scores of the actually divided application sets. Thus, in different application set division scenarios, the matching allocation ratio tables determined are different.
[0195] For example, the application sets actually divided include application set 1, application set 2, and application set 3, and the application set corresponds to application score 1. Application set 2 corresponds to application score 2. Application set 3 corresponds to application score 3. In this scenario, the matching allocation ratio table can be allocation list 1, and the application scores in allocation list 1 (application score 1, application score 2, and application score 3) are exactly the same as the application scores of the application sets actually divided (application set 1, application set 2, and application set 3). The application sets actually divided include application set 1 and application set 4, and the application set corresponds to application score 1. Application set 4 corresponds to application score 4. In this scenario, the matching allocation ratio table can be allocation list 2, and the application scores in allocation list 2 (application score 1, application score 4) are exactly the same as the application scores of the application sets actually divided (application set 1, application set 4).
[0196] After determining the matching allocation ratio table, the corresponding allocation ratio value is searched according to the application score of each divided application set. Then, the fourth space size for comparison of the application set is determined based on the product of the allocation ratio value and the total memory space to be reclaimed.
[0197] In this way, the amount of memory required to be reclaimed (e.g., the size of the fourth space) for different application sets is affected by the application scores. Application sets with a higher probability of use (corresponding to lower application scores) require less memory to be reclaimed, while application sets with a lower probability of use (corresponding to lower application scores) require more memory to be reclaimed. This prevents applications with a higher probability of use from having too much memory reclaimed, while applications with a lower probability of use from having too little memory reclaimed.
[0198] As another implementation, the above-mentioned method of allocating the corresponding fourth space size to each application set may further include:
[0199] (1) Based on the reclaimable memory size of the applications in each application set, the total reclaimable memory size corresponding to each application set is calculated, which is called the fifth space size or the fourth memory amount. For example, the reclaimable memory sizes of all applications in the same application set are added together to obtain the fifth space size corresponding to the application set.
[0200] (2) Based on the fifth space size corresponding to each application set, the total reclaimable memory size corresponding to the electronic device is calculated, which is referred to as the sixth space size. For example, the fifth space sizes corresponding to all application sets are added together to obtain the sixth space size corresponding to the electronic device.
[0201] (3) Determine the fourth space size corresponding to the application set based on the sixth space size corresponding to the electronic device, the fifth space size of the application set, and the total memory space size to be reclaimed. For example, determine the recycling ratio corresponding to the application set based on the ratio between the fifth space size of the application set and the sixth space size of the electronic device, and then determine the fourth space size corresponding to the application set based on the product of the recycling ratio of the application set and the total memory space size to be reclaimed.
[0202] In this way, the amount of memory required to be reclaimed (e.g., the size of the fourth space) for different application sets is affected not only by the application score but also by the reclaimable memory size of the application set. Application sets with a higher probability of use (corresponding to a lower application score) require less memory to be reclaimed, while application sets with a lower probability of use (corresponding to a lower application score) require more memory to be reclaimed. This also prevents applications with a higher probability of use from having too much memory reclaimed, while applications with a lower probability of use from having too little memory reclaimed.
[0203] A4: Determine the to-be-reclaimed memory size corresponding to the application according to the fourth space size corresponding to the application set, the total reclaimable memory size corresponding to the application set, and the reclaimable memory size of the application.
[0204] The total reclaimable memory size corresponding to the above application set may also be referred to as the fifth space size.
[0205] For example, the ratio 1 between the reclaimable memory size a of application a and the fifth space size corresponding to application set a (e.g., the first ratio) can be obtained. Then, the product of the ratio 1 and the fourth space size corresponding to application set a (e.g., the fifth memory amount) can be obtained as the to-be-reclaimed memory size corresponding to application a. Of course, the to-be-reclaimed memory sizes corresponding to other applications in application set a can also be determined in the same manner.
[0206] It's understandable that the fourth space size of each application collection obtained through steps A1-A3 above can remain constant during the application traversal process. After executing steps A1-A3, the fourth space size of each application collection can be stored. Thereafter, each time any application is traversed, the fourth space size of the corresponding application collection can be queried, and then, based on A4, the size of the application's memory to be reclaimed can be calculated.
[0207] In other embodiments, the electronic device may not be divided into application sets. Thus, as another implementation, the process of determining the size of the memory to be reclaimed corresponding to each application program may also be as follows:
[0208] B1. For each background application, obtain the application score of the traversed application. For example, if application a is traversed, obtain application score a.
[0209] B2. Then, the total reclaimable memory size of all application programs corresponding to the application score a is counted to obtain the fifth space size (eg, called the first ratio) corresponding to the application score a.
[0210] B3. Then, the sum of the reclaimable memory sizes of all applications in the electronic device is counted to obtain a sixth space size, which is called the total reclaimable memory.
[0211] B4. Determine the total memory size that needs to be reclaimed this time. The method for obtaining the total memory size that needs to be reclaimed this time can refer to the above A2 and will not be repeated here.
[0212] B5. Afterwards, based on the sixth space size, the total memory size that needs to be reclaimed this time, and the fifth space size corresponding to the application score a, the memory size that needs to be reclaimed from all application programs corresponding to the application score a is determined, that is, the fourth space size corresponding to the application score a is obtained.
[0213] B6. After obtaining the fourth memory size corresponding to application score a, the memory size to be reclaimed for application a is determined based on the fourth and fifth memory sizes of application score a and the reclaimable memory size a corresponding to application a. The next application is then traversed and the above steps are repeated.
[0214] It's understandable that the aforementioned "to-be-reclaimed memory size" refers to the actual amount of space that needs to be reclaimed from the application. By calculating the to-be-reclaimed memory size using this method, memory can be evenly reclaimed for applications within the same application set. Of course, within the same application set, the more reclaimable memory an application has, the more to-be-reclaimed memory it will correspond to, while the less reclaimable memory an application has, the less to-be-reclaimed memory it will correspond to.
[0215] In an embodiment of the present application, after determining the size of the memory to be reclaimed corresponding to the application, the electronic device may also reclaim the system memory occupied by the application according to the size of the memory to be reclaimed.
[0216] For example, the reclamation process involves determining the size of the memory to be reclaimed for application a when traversing the memcg corresponding to application a. Then, from the LRU linked list corresponding to application a, n target memory pages are selected, where the activity level of the selected target memory pages is lower than that of other anonymous pages of application a.
[0217] In addition, the system memory usage of the n target memory pages is the same as or similar to the size of the memory to be reclaimed. When the system memory usage of the n target memory pages is similar to the size of the memory to be reclaimed, the system memory usage of the n target memory pages is not less than the size of the memory to be reclaimed. It can also be said that the memory size occupied by the n target memory pages matches the size of the memory to be reclaimed corresponding to the application a.
[0218] Exemplarily, n can be a positive integer greater than 0. When n=1, the system memory size occupied by the corresponding target memory page is not less than the to-be-reclaimed memory size corresponding to application a. When n is greater than 1, the total system memory size occupied by the corresponding n target memory pages is not less than the to-be-reclaimed memory size corresponding to application a, and the total system memory size occupied by the corresponding n-1 target memory pages is less than the to-be-reclaimed memory size corresponding to application a. Then, the system memory occupied by the target memory pages of application a is reclaimed.
[0219] In some embodiments, during the process of traversing the memcg of the application, if the size of the memory actually reclaimed is equal to or greater than the size of the memory required to be reclaimed, the traversal is stopped.
[0220] In some embodiments, each time a memcg is traversed and the corresponding target memory page is determined and reclaimed, the memory size occupied by the target memory page (e.g., the seventh space size) can be obtained. Then, the difference between the reclaimable memory size of the application and the seventh space size is obtained, e.g., the eighth space size. Then, the eighth space size is written into the field for storing the reclaimable size in the memcg data structure.
[0221] In this way, when the application score of the application program does not change, there is no need to repeatedly execute the step of calculating the reclaimable memory size of the application program, thereby shortening the processing time consumption of memory reclamation.
[0222] In an exemplary scenario, as shown in FIG8 , the application scores corresponding to APP1, APP2, and APP3 are the same, and in the first list, the transfer storage ratio corresponding to the application score is 60%. In the scenario shown in FIG8 , the anonymous page size of APP1 in the system memory is 40MB, and the anonymous page size that has been transferred is 20MB (that is, the size of the space occupied in the swap partition and external memory). The anonymous page size of APP2 in the system memory is 60MB, and the anonymous page size that has been transferred is 20MB. The anonymous page size of APP3 in the system memory is 30MB, and the anonymous page size that has been transferred is 20MB. According to the method provided in the aforementioned embodiment, it can be determined that the reclaimable memory size corresponding to APP1 is 16MB, the reclaimable memory size corresponding to APP2 is 28MB, and the reclaimable memory size corresponding to APP3 is 10MB. The total reclaimable memory size corresponding to the application set to which APP1, APP2, and APP3 belong is 54MB. Of course, the reclaimable memory size is determined based on the transfer memory ratio corresponding to the application score, which determines the maximum amount of space in the system memory occupied by the application that can be reclaimed. The actual amount of space to be reclaimed by the application is no larger than the reclaimable memory size. When determining that 27MB of system memory needs to be reclaimed from the application set consisting of APP1, APP2, and APP3, according to the above embodiment, the amount of space to be reclaimed corresponding to APP1 can be determined to be (27 / 54)*16=8MB, the amount of space to be reclaimed corresponding to APP2 can be determined to be (27 / 54)*28=14MB, and the amount of space to be reclaimed corresponding to APP3 can be determined to be (27 / 54)*10=5MB.
[0223] After memory reclamation, the anonymous page size of APP1 in system memory is 32MB, and the size of the transferred anonymous pages is 28MB. The anonymous page size of APP2 in system memory is 46MB, and the size of the transferred anonymous pages is 34MB. The anonymous page size of APP3 in system memory is 25MB, and the size of the transferred anonymous pages is 25MB.
[0224] In short, among applications with the same application score (or the same application popularity), under different system memory usage (first space size) and different transfer storage capacity (the sum of the second space size and the third space size), the corresponding reclaimable memory amount (or, reclaimable memory size) is different, and the amount of memory to be reclaimed (or, memory size to be reclaimed) is also different.
[0225] In an exemplary scenario, as shown in FIG9 , the application scores corresponding to APP1 and APP4 are different, the application score of APP1 is greater than the application score of APP4, and in the first list, the transfer storage ratio corresponding to the application score of APP1 is 60%, and the transfer storage ratio corresponding to the application score of APP4 is 50%. In the scenario shown in FIG9 , the anonymous page size of APP1 in the system memory is 40MB, and the transferred anonymous page size is 20MB. The anonymous page size of APP4 in the system memory is 40MB, and the transferred anonymous page size is 20MB. According to the method provided in the aforementioned embodiment, it can be determined that the reclaimable memory size corresponding to APP1 is 16MB, and the reclaimable memory size corresponding to APP4 is 10MB. When the occupied system memory and the transferred anonymous page size are the same, due to the difference in application scores, the reclaimable memory sizes corresponding to APP1 and APP4 are different.
[0226] In addition, due to the difference in application scores, the fourth space size corresponding to the application sets to which APP1 and APP4 belong also differs. For example, 27MB needs to be recovered from the application set to which APP1 belongs, and the total reclaimable memory size corresponding to the application set is 54MB. 20MB needs to be recovered from the application set to which APP4 belongs, and the total reclaimable memory size corresponding to the application set is 30MB. In this way, according to the aforementioned embodiment, it can be determined that the size of the space to be reclaimed corresponding to APP1 is (27 / 54)*16=8MB, and the size of the space to be reclaimed corresponding to APP4 is (20 / 30)*10=6.6MB. In this way, after memory recovery, the anonymous page size of APP1 in the system memory is 32MB, and the size of the anonymous page that has been transferred to storage is 28MB. The anonymous page size of APP4 in the system memory is 33.4MB, and the size of the anonymous page that has been transferred to storage is 26.6MB.
[0227] Obviously, applications with different application scores can achieve differentiated memory recycling through the method provided in the above embodiment, avoiding the situation where too much system memory is recycled for applications with high application popularity, while less system memory is recycled for applications with low application popularity, reducing the number of anonymous pages that are repeatedly released and reloaded, and improving the recycling efficiency of system memory.
[0228] As an implementation method, the algorithm for traversing the application and performing memory recycling can be as follows:
[0229] An embodiment of the present application further provides an electronic device, which may include: a memory and one or more processors. The memory and processor are coupled. The memory is used to store computer program code, which includes computer instructions. When the processor executes the computer instructions, the electronic device can perform the steps performed by the mobile phone in the above embodiment. Of course, the electronic device includes but is not limited to the above memory and one or more processors.
[0230] The present application also provides a chip system that can be applied to the terminal device in the aforementioned embodiment. The chip system includes at least one processor and at least one interface circuit. The processor can be the processor in the aforementioned electronic device. The processor and the interface circuit can be interconnected via a line. The processor can receive and execute computer instructions from the memory of the aforementioned electronic device via the interface circuit. When the computer instructions are executed by the processor, the electronic device can execute the various steps performed by the mobile phone in the aforementioned embodiment. Of course, the chip system can also include other discrete components, which are not specifically limited in the present application.
[0231] In some embodiments, through the description of the above embodiments, those skilled in the art can clearly understand that for the convenience and brevity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0232] 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.
[0233] 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 computer-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, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as flash memory, mobile hard disk, read-only memory, random access memory, magnetic disk or optical disk.
[0234] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present invention should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. A memory recovery method, characterized in that: Applied to an electronic device, each application in the electronic device corresponds to a memory control subsystem memcg, and the method includes: Determine a first memory amount corresponding to a first application running in the background, wherein the first memory amount indicates an amount of memory that needs to be reclaimed from the system memory occupied by the first application, and the first memory amount decreases as the application heat of the first application increases, and the application heat indicates the activity level of the application running in the background; The system memory occupied by the first application is reclaimed according to the first memory amount.
2. The method according to claim 1, characterized in that: Before determining the first memory amount corresponding to the first application running in the background, the method further includes: Determine a first reclaimable memory amount corresponding to the first application; the first memory amount is not greater than the first reclaimable memory amount.
3. The method according to claim 2, characterized in that The determining a first reclaimable memory amount corresponding to the first application includes: Determining that an application score of the first application is a first score; the application score of the first application decreases as the application popularity of the first application increases; The first reclaimable memory amount is determined based on the first score, the second memory amount and the third memory amount corresponding to the first application; wherein the second memory amount indicates the size of all anonymous pages in the first application, and the third memory amount indicates the size of anonymous pages that have been swapped out from the system memory in the first application.
4. The method according to claim 3, characterized in that: Determining the first reclaimable memory amount according to the first score, the second memory amount corresponding to the first application, and the third memory amount includes: Determine a transfer storage ratio corresponding to the first score; the transfer storage ratio is used to determine a ratio of a size of anonymous pages that can be transferred in a single application program, and the higher the first score, the higher the corresponding transfer storage ratio; Determine the product of the transfer storage ratio and the second memory amount as a first anonymous page size; The first reclaimable memory amount is determined by subtracting the third memory amount from the first anonymous page size.
5. The method according to claim 3, characterized in that: The determining the first memory amount includes: Obtaining a first ratio between a first reclaimable memory amount and a fourth memory amount, wherein the fourth memory amount refers to the sum of reclaimable memory amounts corresponding to all the application programs whose application scores are the first scores and running in the background; The product of the first ratio and a fifth memory amount is determined as the first memory amount, and the fifth memory amount refers to the total amount of memory that needs to be recovered from all application programs whose application scores are the first scores.
6. The method according to claim 4, characterized in that Each of the applications corresponds to a memcg data structure, and the memcg data structure includes a field for carrying the amount of reclaimable memory; after determining the first amount of reclaimable memory, the method further includes: Writing the determined first reclaimable memory amount into the memcg data structure of the corresponding first application; The determining the first memory amount further includes: obtaining a fourth memory amount; The obtaining of the fourth memory amount comprises: the memcg data structure of the application program running in the background After the reclaimable memory amounts have been written in, the reclaimable memory amount is obtained from the memcg data structure of the application whose application score is the first score and is running in the background; all the obtained reclaimable memory amounts are added together to obtain the corresponding fourth memory amount.
7. The method according to claim 6, characterized in that After reclaiming the system memory occupied by the first application according to the first memory amount, the method further includes: The reclaimable memory amount in the memcg data structure of the first application is updated by using a difference between the first reclaimable memory amount of the first application and the first memory amount.
8. The method according to claim 5, characterized in that The determining the first memory amount further comprises: Counting the total amount of reclaimable memory corresponding to all the applications running in the background of the electronic device; Obtain the fifth amount of memory; wherein the proportion of the fifth amount of memory in the total amount of memory that needs to be recycled by the electronic device is equal to the proportion of the fourth amount of memory in the total amount of recyclable memory of the electronic device.
9. The method according to claim 1, characterized in that: The reclaiming the system memory occupied by the first application according to the first memory amount includes: Determine, among anonymous pages of the first application, a target memory page whose system memory occupancy is the first memory amount, wherein the activity level of the target memory page is lower than that of other anonymous pages of the first application; The target memory page is swapped out from the system memory.
10. The method according to claim 1, characterized in that The method further comprises: Determine a sixth memory amount corresponding to a second application running in the background, wherein the sixth memory amount indicates an amount of memory to be reclaimed from the system memory occupied by the second application, and an anonymous page size stored in the system memory and an anonymous page size swapped out from the system memory by the second application are both the same as those of the first application; and when an application heat of the second application is lower than an application heat of the first application, the sixth memory amount is greater than the first memory amount; According to the sixth memory amount, the system memory occupied by the second application is reclaimed, and the sum of the first memory amount and the sixth memory amount is not greater than the total memory amount that needs to be reclaimed by the electronic device.
11. An electronic device, characterized in that: Each application in the electronic device corresponds to a memory control subsystem memcg, and the electronic device includes: a processor and a memory, and the memory is used to store computer instructions. When the processor executes the computer instructions, the electronic device executes the method as described in any one of claims 1-10.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a computer program or instructions. When the computer program or instructions are executed on a computer, the computer is caused to perform the method according to any one of claims 1 to 10.