Memory recovery method and device, electronic equipment and storage medium

By considering the target heap mapping area and memory page activity of the target application in memory recycling, the memory page to be recycled is determined, which solves the problem that memory recycling affects system performance in the prior art and achieves more efficient memory usage.

CN119576802APending Publication Date: 2025-03-07GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311147624.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-06
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

Existing memory recovery technologies will affect system performance when performing memory recovery and fail to effectively consider the activity of memory pages.

Method used

By obtaining the target heap mapping area of ​​the target application, if the application running state changes are detected, the rotation operation is triggered, and the active linked list and the inactive linked list are determined in response to the memory recovery operation, and the memory page to be recycled is determined from the inactive linked list for memory recovery.

Benefits of technology

Determine the memory page to be recycled based on the memory size occupied by the heap mapping area and the activity level of the memory page, reducing the impact of memory recycling on performance and improving memory usage efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576802A_ABST
    Figure CN119576802A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a memory recovery method and device, electronic equipment and a storage medium. The method comprises the steps that a target heap mapping area corresponding to a target application is obtained, and the target heap mapping area is a heap mapping area with the occupied memory exceeding a preset value; if it is detected that the running state of the target application changes, a rotation operation is triggered, an active linked list and a non-active linked list corresponding to the target heap mapping area are determined, and memory pages in the active linked list are accessed memory pages within the preset time period; in response to a memory recovery operation, determining a to-be-recovered memory page from the inactive linked list; and performing memory recovery on the to-be-recovered memory page. According to the technical scheme, the to-be-recycled memory page is determined according to the memory size occupied by the heap mapping area and the active degree of the memory page, memory recycling is conducted on the to-be-recycled memory page, the performance influence caused by memory recycling is reduced, and the memory use efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of memory recycling technology, and specifically relates to a memory recycling method, device, electronic device and storage medium. Background Art

[0002] Memory recycling is one of the core technologies of the system, and plays a key role in improving the user experience of the system and the stability of the system operation. When the memory is tight, the system will experience a series of problems such as freezing, operation errors, and crashes. In related technologies, memory recycling will affect the performance of the system. Summary of the invention

[0003] In view of the above problems, the present application proposes a memory recovery method, device, electronic device and storage medium to improve the above problems.

[0004] In a first aspect, an embodiment of the present application provides a memory recovery method, the method comprising: obtaining a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value; if it is detected that the running state of the target application has changed, triggering a rotation operation, determining an active linked list and an inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period; in response to a memory recovery operation, determining memory pages to be recovered from the inactive linked list; and performing memory recovery on the memory pages to be recovered.

[0005] In a second aspect, an embodiment of the present application provides a memory recovery device, comprising: an area acquisition unit, used to acquire a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value; a linked list determination unit, used to trigger a rotation operation if a change in the running state of the target application is detected, and determine an active linked list and an inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period; a page acquisition unit, used to determine the memory pages to be recovered from the inactive linked list in response to a memory recovery operation; and a recovery unit, used to perform memory recovery on the memory pages to be recovered.

[0006] In a third aspect, an embodiment of the present application provides an electronic device, comprising one or more processors and a memory; one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the above-mentioned method.

[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored, wherein the above method is executed when the program code is run.

[0008] The embodiments of the present application provide a memory recovery method, device, electronic device and storage medium. First, a target heap mapping area corresponding to a target application is obtained, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value. If a change in the running state of the target application is detected, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period. Then, in response to a memory recovery operation, the memory pages to be recovered are determined from the inactive linked list, and memory recovery is performed on the memory pages to be recovered. Through the above method, the memory pages to be recovered are determined according to the size of the memory occupied by the heap mapping area and the activity level of the memory pages, so that memory recovery is performed on the memory pages to be recovered, thereby reducing the performance impact caused by memory recovery and improving memory usage efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0010] Figure 1 A schematic diagram of an application scenario of a memory recycling method proposed in an embodiment of the present application is shown;

[0011] Figure 2 A schematic diagram of an application scenario of a memory recycling method proposed in an embodiment of the present application is shown;

[0012] Figure 3 A flowchart of a memory recovery method proposed in an embodiment of the present application is shown;

[0013] Figure 4 A flowchart of a memory recycling method proposed in another embodiment of the present application is shown;

[0014] Figure 5 A flowchart of a memory recycling method proposed in another embodiment of the present application is shown;

[0015] Figure 6 A structural block diagram of a memory recovery device proposed in an embodiment of the present application is shown;

[0016] Figure 7A structural block diagram of a memory recovery device proposed in an embodiment of the present application is shown;

[0017] Figure 8 A structural block diagram of an electronic device or a server for executing a memory recycling method according to an embodiment of the present application is shown;

[0018] Fig. 9 A storage unit in an embodiment of the present application is shown for storing or carrying program code for implementing a memory recycling method according to an embodiment of the present application. DETAILED DESCRIPTION

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

[0020] Kswapd is a kernel thread in the Linux kernel that is responsible for reclaiming memory when memory resources are tight. It works mainly by swapping out inactive memory pages to the hard disk.

[0021] The inventor discovered in the study of related memory recovery methods that the page replacement algorithm adopted by Kswapd is an algorithm called the Second Chance Algorithm. The Second Chance Algorithm is also called the clock page replacement algorithm, which is an improved FIFO (First In First Out) page replacement algorithm. When judging whether a memory page needs to be replaced, it will consider the access bit of the memory page. If the access bit of the memory page is set, then the memory page will get a "second chance", that is, it will not be replaced temporarily, and the access bit will be cleared. In the next round of inspection, if the access bit of the memory page is still zero, then it will be replaced. Performing page replacement in the above manner will cause all memory pages to be treated equally, without considering that different pages may have different importance, which will cause important memory pages to be replaced, thereby affecting the performance of the system.

[0022] Therefore, the inventors proposed the memory recovery method, device, electronic device and storage medium in the present application. First, the target heap mapping area corresponding to the target application is obtained, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value. If it is detected that the running state of the target application has changed, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period, and then in response to the memory recovery operation, the memory pages to be recovered are determined from the inactive linked list, and memory recovery is performed on the memory pages to be recovered. Through the above method, the memory pages to be recovered are determined according to the memory size occupied by the heap mapping area and according to the activity level of the memory pages, so as to perform memory recovery on the memory pages to be recovered, thereby reducing the performance impact caused by memory recovery and improving memory usage efficiency.

[0023] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0024] In an embodiment of the present application, the memory recovery method provided can be executed by an electronic device. In this mode of being executed by an electronic device, all steps in the memory recovery method provided by the embodiment of the present application can be executed by the electronic device. For example, Figure 1 As shown, the processor of the electronic device 100 executes to obtain the target heap mapping area corresponding to the target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value; if it is detected that the running state of the target application has changed, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are the memory pages that have been accessed within the preset time period; in response to a memory recovery operation, the memory pages to be recovered are determined from the inactive linked list; and memory recovery is performed on the memory pages to be recovered.

[0025] Furthermore, the memory recovery method provided in the embodiment of the present application can also be executed by a server (cloud). Correspondingly, in this method executed by the server, the server can execute to obtain the target heap mapping area corresponding to the target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value; if it is detected that the running state of the target application has changed, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are the memory pages that have been accessed within the preset time period; in response to the memory recovery operation, the memory pages to be recovered are determined from the inactive linked list; and memory recovery is performed on the memory pages to be recovered.

[0026] In addition, the electronic device and the server may also perform the operation in collaboration. In this mode, some steps of the memory recovery method provided in the embodiment of the present application are performed by the electronic device, while other steps are performed by the server.

[0027] For example, Figure 2 As shown, the electronic device 100 can execute a memory recovery method including: obtaining a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value, and then the server 200 executes if it is detected that the running state of the target application has changed, triggering a rotation operation, determining an active linked list and an inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period; in response to a memory recovery operation, determining memory pages to be recovered from the inactive linked list; and performing memory recovery on the memory pages to be recovered.

[0028] It should be noted that in this method of collaborative execution by the electronic device and the server, the steps respectively executed by the electronic device and the server are not limited to the methods introduced in the above examples. In actual applications, the steps respectively executed by the electronic device and the server can be dynamically adjusted according to actual conditions.

[0029] It should be noted that the electronic device 100 can be Figure 1 and Figure 2 In addition to the smartphone shown in the figure, it can also be a car device, a wearable device, a tablet computer, a laptop computer, a smart speaker, etc. The server 120 can be an independent physical server, or a server cluster or a distributed system composed of multiple physical servers.

[0030] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0031] See also Figure 3 , a memory recovery method provided in an embodiment of the present application is applied to Figure 1 or Figure 2 The electronic device or server shown, the method comprising:

[0032] Step S110: obtaining a target heap mapping area corresponding to the target application, wherein the target heap mapping area is a heap mapping area that occupies a memory exceeding a preset value.

[0033] In an embodiment of the present application, the target heap mapping area is a heap mapping area determined from a plurality of heap mapping areas corresponding to the target application, wherein the heap mapping area refers to the process virtual address allocated to the target application by the malloc() function, and the process virtual address refers to the virtual space address that the process can address. The malloc function is a function that allocates a memory block of num_bytes bytes in length, and can apply to the system for allocation of a memory space of a specified size bytes. The full name of maloc is memory allocation, which is called dynamic memory allocation in Chinese. It is used to apply for a continuous memory block area of ​​a specified size and returns the allocated memory area address with a void* type. When the specific location of the memory is unknown, if you want to bind the real memory space, you need to use dynamic memory allocation, and the allocated size is the size required by the program.

[0034] The target heap mapping area is a heap mapping area whose memory usage exceeds a preset value among the multiple heap mapping areas corresponding to the target application, wherein the preset value is a pre-set memory value that needs to be reclaimed. In an embodiment of the present application, the target heap mapping area may be at least one heap mapping area among the multiple heap mapping areas corresponding to the target application. Among them, the target application is an application that is determined to need to reclaim memory. The target application may be a third-party application installed in the electronic device, or a system application in the electronic device, which is not specifically limited here.

[0035] In the embodiments of the present application, the target application may be determined in a variety of ways.

[0036] As one of the ways, the target application can be determined based on the priorities of multiple applications. Specifically, the corresponding priorities can be set in advance for different applications, so that when determining the target application, the application at the target priority among the multiple applications can be determined as the target application. The target priority is the pre-set priority of the application that needs to reclaim memory, for example, the target priority can be the lowest priority or the highest priority.

[0037] As another method, the target application may be determined according to the running status of multiple applications. Specifically, when determining the target application according to the running status of multiple applications, an application in the target running status among the multiple applications may be determined as the target application. The target running status may be a pre-set running status of an application that needs to reclaim memory, for example, the target running status may be a foreground running status or a background running status.

[0038] As another method, the target application can be determined according to the memory size occupied by multiple applications. Specifically, when determining the target application according to the memory size occupied by multiple applications, the memory size currently occupied by each of the multiple applications can be obtained first, and then the application whose memory currently occupies a preset value among the multiple applications can be determined as the target application. The preset value can be a preset memory size occupied by an application that needs to reclaim memory, for example, the preset value can be 500MB.

[0039] Optionally, at least two of the above methods may be combined to determine the target application from multiple applications. Of course, the number of target applications determined by the above methods may be more than one.

[0040] After the target application is determined in the above manner, the target heap mapping area can be determined from the multiple heap mapping areas corresponding to the target application. When there are multiple target applications, there must be multiple target heap mapping areas; when there is only one target application, there must be at least one target heap mapping area.

[0041] Step S120: If it is detected that the running state of the target application changes, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are the memory pages that have been accessed within the preset time period.

[0042] In an embodiment of the present application, the running state of the target application may include a foreground running state, a background running state, a non-running state, a suspended state, etc. The change in the running state of the target application refers to the change of the running state of the target application from a first state to a second state. Among them, the first state is one of the foreground running state, the background running state, the non-running state, and the suspended state, and the second state is one of the foreground running state, the background running state, the non-running state, and the suspended state that is different from the first state. For example, if the first state is the background running state, then the second state can be one of the foreground running state, the non-running state, and the suspended state.

[0043] The rotation operation refers to walking the memory pages in the target heap mapping area in turn within a period of time. After walking a memory page, switch to the next memory page until all memory pages are walked and the memory pages to be recycled are determined. The rotation operation is divided into two times. The first time is to clear the access bits of all memory pages. The second time is to put the memory pages that have been accessed during this period, that is, the memory pages with access bits of 1, into the active linked list, and put the remaining memory pages into the inactive linked list. The access bit is used to record whether the memory page has been accessed. If the memory page has been accessed, the access bit of the memory page is 1; if the memory page has not been accessed, the access bit of the memory page is 0.

[0044] When a change in the running state of the target application is detected, a rotation operation is triggered. First, the access bits of all memory pages in the target heap mapping area are set to zero, and then the memory pages that have been accessed within the preset time period are placed in the active linked list, and the remaining memory pages are placed in the inactive linked list, so as to obtain the active linked list and the inactive linked list corresponding to the target heap mapping area. The preset time period refers to the preset time period after the first rotation operation, and the preset time period can be a time period set in ms or s. For example, the preset time period can be set to 20ms.

[0045] As a method, one target heap mapping area corresponds to one active linked list and one inactive linked list. If there are multiple target heap mapping areas, then multiple active linked lists and multiple inactive linked lists can be determined, that is, the memory pages in each target heap mapping area that have been accessed within a preset time period are placed in the corresponding active linked list, and the memory pages in each target heap mapping area that have not been accessed within the preset time period are placed in the corresponding inactive linked list. Furthermore, when placing the memory pages in each target heap mapping area that have been accessed within a preset time period into the corresponding active linked list, some memory pages may have been accessed more than once within the preset time period. At this time, the memory pages that have been accessed within the preset time period can be placed in the active linked list according to the number of times the memory page has been accessed, wherein the more times the memory page has been accessed, the closer the memory page is placed in the active linked list.

[0046] In an embodiment of the present application, the system can monitor whether the running state of the target application has changed. When the system detects that the running state of the target application has changed, a rotation operation is triggered to start rotating the memory pages in the target heap mapping area of ​​the target application.

[0047] Step S130: In response to the memory reclaiming operation, determining the memory page to be reclaimed from the inactive linked list.

[0048] In an embodiment of the present application, after the active linked list and the inactive linked list corresponding to the target heap mapping area are determined in the above manner, in response to a memory recovery operation, the memory page to be recovered is determined from the inactive linked list. The memory recovery operation may be an operation triggered by a specified application, wherein the specified application may be a pre-set application that needs to allocate a large amount of memory, such as a game application.

[0049] When it is detected that the specified application is about to be started, the memory recycling operation is triggered, and the memory pages to be recycled that need to be recycled are determined from the inactive linked list corresponding to the target heap mapping area.

[0050] As another method, the memory recycling operation can also be triggered when the current remaining memory is detected to be lower than the preset memory. That is, the current remaining memory is monitored in real time, and when it is detected that the current remaining memory is lower than the preset memory, the memory recycling operation is triggered to start determining the memory pages to be recycled in the inactive linked list corresponding to the target heap mapping area.

[0051] When determining the memory pages to be reclaimed from the inactive linked list corresponding to the target heap mapping area, the number of memory pages to be reclaimed can be determined according to the size of the memory to be allocated. The larger the memory to be allocated, the more memory pages to be reclaimed are determined from the inactive linked list. Conversely, the smaller the memory to be allocated, the smaller the number of memory pages to be reclaimed are determined from the inactive linked list.

[0052] When there is only one target heap mapping area, the number of memory pages to be reclaimed can be determined from an inactive linked list according to the memory size to be allocated. The larger the memory to be allocated, the more memory pages to be reclaimed are determined from an inactive linked list. Conversely, the smaller the memory to be allocated, the fewer memory pages to be reclaimed are determined from an inactive linked list.

[0053] In the case of multiple target heap mapping areas, the number of memory pages to be reclaimed can be determined from multiple inactive linked lists according to the size of memory to be allocated, wherein the larger the memory to be allocated, the more memory pages to be reclaimed are determined from multiple inactive linked lists, and conversely, the smaller the memory to be allocated, the fewer memory pages to be reclaimed are determined from multiple inactive linked lists. At this time, the number of memory pages to be reclaimed determined from each inactive linked list may be consistent or inconsistent.

[0054] When the number of memory pages to be reclaimed determined from each inactive linked list is inconsistent, the number of memory pages to be reclaimed corresponding to each of the multiple inactive linked lists can be determined according to the memory size occupied by the target heap mapping area corresponding to each of the multiple inactive linked lists. The larger the memory occupied by the target heap mapping area, the more memory pages to be reclaimed can be determined from the corresponding inactive linked list. Conversely, the smaller the memory occupied by the target heap mapping area, the smaller the number of memory pages to be reclaimed determined from the corresponding inactive linked list.

[0055] Optionally, the number of memory pages to be reclaimed corresponding to each of the multiple inactive linked lists can also be determined according to the priority of each target heap mapping area corresponding to each of the multiple inactive linked lists, wherein the higher the priority of the target heap mapping area, the fewer the number of memory pages to be reclaimed determined from the corresponding inactive linked list, and conversely, the lower the priority of the target heap mapping area, the more the number of memory pages to be reclaimed determined from the corresponding inactive linked list. In an embodiment of the present application, the priority of the heap mapping area can be set after dividing the multiple heap mapping areas corresponding to the target application.

[0056] Optionally, in an embodiment of the present application, the memory page to be recovered can also be determined from the inactive linked list according to the memory recovery algorithm used. Among them, the memory recovery method can also be called a page replacement algorithm, and the page replacement algorithm can include a first in first out (FIFO) algorithm, a least recently used (Least Recently Used, LRU) algorithm, a clock (Clock) algorithm, a second chance (Second Chance) algorithm, a least frequently used (LFU) algorithm, a least recently used K times (Least Recently Used K, LRU-K) algorithm and a best replacement algorithm and other algorithms. Of course, the page replacement algorithm can also be other replacement algorithms, which are not specifically limited here.

[0057] Further, in an embodiment of the present application, if the number of memory pages in the inactive linked list does not meet the number of memory pages that need to be reclaimed, then the memory pages to be reclaimed can be selected from the active linked list. When selecting the memory pages to be reclaimed from the active linked list, the memory pages to be reclaimed can also be determined in the aforementioned manner.

[0058] When selecting a memory page to be reclaimed from the active linked list, since the memory pages in the active linked list are placed according to the number of times they have been accessed, the memory page placed at the end of the active linked list can be determined as the memory page to be reclaimed.

[0059] Through the above method, the memory pages to be reclaimed are determined preferentially from the inactive linked list, which can minimize the performance impact caused by page replacement.

[0060] Step S140: reclaiming the memory page to be reclaimed.

[0061] In the embodiment of the present application, after the memory pages to be reclaimed are determined in the aforementioned manner, memory reclamation is started for the determined memory pages to be reclaimed, that is, the determined memory pages to be reclaimed are swapped out to a hard disk or other storage medium.

[0062] The present application provides a memory recovery method, which first obtains the target heap mapping area corresponding to the target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value, and if a change in the running state of the target application is detected, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period, and then in response to the memory recovery operation, the memory pages to be recovered are determined from the inactive linked list, and memory recovery is performed on the memory pages to be recovered. Through the above method, the memory pages to be recovered are determined according to the memory size occupied by the heap mapping area and the activity level of the memory pages, so that memory recovery is performed on the memory pages to be recovered, which reduces the performance impact caused by memory recovery and improves memory usage efficiency.

[0063] See also Figure 4 , a memory recovery method provided in an embodiment of the present application is applied to Figure 1 or Figure 2 The electronic device or server shown, the method comprising:

[0064] Step S210: obtaining a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies a memory exceeding a preset value.

[0065] As a method, obtaining a target heap mapping area corresponding to a target application includes: obtaining multiple heap mapping areas corresponding to the target application, wherein the multiple heap mapping areas are obtained by dividing a memory mapping area of ​​the target application according to preset rules; and taking a heap mapping area whose memory pages occupy the largest memory among the multiple heap mapping areas as the target heap mapping area.

[0066] The preset rule may be understood as a preset rule for dividing the memory mapping area corresponding to the target application. For example, the preset rule may be set to divide the memory mapping area of ​​the target application according to the language type in which the target application is written.

[0067] When dividing the memory mapping area of ​​the target application according to the language type in which the target application is written, the memory mapping area corresponding to the target application can be divided into several heap mapping areas according to the languages ​​used to write the target application. For example, if the target application A is written in C language and Java language, the memory mapping area of ​​the target application A can be divided into two heap mapping areas: Java heap mapping area and Native heap mapping area.

[0068] In an embodiment of the present application, after the memory mapping area of ​​the target application is divided into multiple corresponding heap mapping areas in the above manner, the memory size currently occupied by each heap mapping area can be counted first. After obtaining the memory size currently occupied by each heap mapping area, the multiple heap mapping areas can be sorted according to the memory size occupied by each heap mapping area to obtain multiple sorted heap mapping areas.

[0069] After obtaining multiple sorted heap mapping areas, a heap mapping area arranged at a specified position can be selected from the sorted multiple heap mapping areas as a target heap mapping area, wherein the specified position is a pre-set position for obtaining the target heap mapping area. For example, the specified position can be set to the first position, that is, the heap mapping area arranged at the first position among the sorted multiple heap mapping areas is determined as the target heap mapping area.

[0070] Furthermore, in an embodiment of the present application, when sorting multiple heap mapping areas according to the memory size occupied by each heap mapping area, the multiple heap mapping areas can be sorted in order of occupied memory from large to small or from small to large to obtain multiple sorted heap mapping areas.

[0071] After obtaining the sorted multiple heap mapping areas, a heap mapping area that occupies the largest memory among the sorted multiple heap mapping areas is determined as a target heap mapping area.

[0072] Step S220: If it is detected that the running state of the target application changes, a first rotation operation is triggered.

[0073] In an embodiment of the present application, after the target application is determined, the running status changes of the target application are monitored. When the running status of the target application is monitored to change, for example, the target application switches from the background to the foreground, a rotation operation is triggered. At this time, the first rotation operation is started, that is, the access bits of all memory pages in the target heap mapping area of ​​the target application are set to zero.

[0074] Step S230: setting the access bits of the memory pages included in the target heap mapping area to 0 through the first rotation operation.

[0075] In an embodiment of the present application, when the access bits of the memory pages included in the target heap mapping area are set to 0 through the first rotation operation, the access bits of the memory pages included in the target heap mapping area whose access bits are not zero can be modified, that is, the access bits of the memory pages are changed from 1 to 0.

[0076] Step S240: triggering a second rotation operation within a preset time period to determine an active linked list and an inactive linked list corresponding to the target heap mapping area.

[0077] In the embodiment of the present application, the preset time period is a preset time period for waiting for the second rotation operation, and the preset time period refers to a preset time period after the first rotation operation, and the preset time period can be a time period set in ms or s. The second rotation operation is an operation for dividing the memory pages in the target heap mapping area.

[0078] After the first rotation operation is performed, after waiting for a preset period of time, the rotation operation is triggered again, and at this time, an active linked list and an inactive linked list corresponding to the target heap mapping area are generated.

[0079] As a method, the second rotation operation is triggered within a preset time period to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, including: triggering the second rotation operation within the preset time period, putting the memory pages included in the target heap mapping area, whose access bits are 1, into the first linked list to obtain the active linked list, wherein the access bit is 1, which means that the memory page has been accessed within the preset time period; putting the memory pages included in the target heap mapping area, whose access bits are not 1, into the second linked list to obtain the inactive linked list, wherein the access bit is not 1, which means that the memory page has not been accessed within the preset time period.

[0080] The first linked list is a linked list for storing memory pages that have been accessed within a preset time period; and the second linked list is a linked list for storing memory pages that have not been accessed within a preset time period.

[0081] In an embodiment of the present application, when generating an active linked list and an inactive linked list corresponding to a target heap mapping area, the memory pages that have been accessed among the memory pages included in the target heap mapping area within a preset time period can be placed into a first linked list, and the memory pages that have not been accessed can be placed into a second linked list to obtain an active linked list and an inactive linked list.

[0082] Step S250: In response to the memory reclaiming operation, determining the memory page to be reclaimed from the inactive linked list.

[0083] Step S260: reclaiming the memory page to be reclaimed.

[0084] As a method, after reclaiming the memory page to be reclaimed, the method further includes: obtaining the memory currently occupied by the target application; if the memory currently occupied by the target application exceeds a threshold, determining a new target heap mapping area from the multiple heap mapping areas; and rotating the new target heap mapping area until the memory occupied by the target application is lower than the threshold.

[0085] The threshold is a preset memory size occupied by the application when memory recycling is required.

[0086] In an embodiment of the present application, after performing a memory recovery operation on the memory pages in the target heap mapping area of ​​the target application, it can be determined again whether the memory usage of the current target application exceeds the threshold. If the memory usage of the current target application still exceeds the threshold, then the memory pages in other heap mapping areas of the target application can be rotated.

[0087] At this time, the selected new heap mapping area may be arranged in the second heap mapping area for the memory occupied by the multiple heap mapping areas corresponding to the target application, or in the heap mapping area at other positions, which is not specifically limited here.

[0088] After each memory recycling is performed on a memory page in a heap mapping area, it can be determined whether the memory usage of the current target application exceeds the threshold. If the memory usage of the target application still exceeds the threshold, the next heap mapping area is rotated until all heap mapping areas corresponding to the target application have completed the rotation operation. At this time, if the memory usage of the target application still exceeds the threshold, the process described in steps S210 to S260 can be repeated until the memory usage of the target application is less than the threshold.

[0089] The present application provides a memory recycling method which can manage memory more finely and improve memory usage efficiency by dividing memory mapping areas.

[0090] See also Figure 5 , a memory recovery method provided in an embodiment of the present application is applied to Figure 1 or Figure 2 The electronic device or server shown, the method comprising:

[0091] Step S310: Obtain the running status and occupied memory of each of the multiple applications.

[0092] In the embodiment of the present application, multiple applications may refer to all application programs in the electronic device, or may refer to multiple preset application programs, which is not specifically limited here.

[0093] Before reclaiming the memory of the target heap mapping area of ​​the target application, it is necessary to first determine the target application. At this time, the running status of each of the multiple applications and the memory size occupied by each of the multiple applications can be obtained.

[0094] Step S320: Determine, among the multiple applications, an application that is in the foreground and occupies a memory exceeding a threshold as a target application.

[0095] In an embodiment of the present application, after obtaining the running status of each of the multiple applications and the memory size occupied by each of the multiple applications, the application that is running in the foreground and occupies a memory exceeding a threshold can be determined as the target application.

[0096] Step S330: Obtain a target heap mapping area corresponding to the target application.

[0097] Step S340: If it is detected that the running state of the target application changes, a rotation operation is triggered by running a service program in the user space to determine the active linked list and the inactive linked list corresponding to the target heap mapping area.

[0098] The user space service program refers to a service process specifically used for performing rotation operations.

[0099] In an embodiment of the present application, the system monitors the running status of the target application in real time. When the system detects that the running status of the target application has changed, it can send an indication message to the service process running in the user space to prompt the service process running in the user space to trigger a rotation operation.

[0100] Step S350: In response to the memory reclaiming operation, determining the memory page to be reclaimed from the inactive linked list.

[0101] Step S360: reclaiming the memory page to be reclaimed.

[0102] The present application provides a memory recovery method, which first obtains the corresponding running status and occupied memory of multiple applications, and determines the application whose running status is foreground running and the memory occupied exceeds the threshold value as the target application among the multiple applications, and then obtains the target heap mapping area corresponding to the target application. If it is detected that the running status of the target application has changed, the rotation operation is triggered by running the service program in the user space, and the active linked list and the inactive linked list corresponding to the target heap mapping area are determined. Then, in response to the memory recovery operation, the memory page to be recovered is determined from the inactive linked list, and memory recovery is performed on the memory page to be recovered. Through the above method, the memory page to be recovered is determined according to the memory size occupied by the heap mapping area and the activity level of the memory page, so as to perform memory recovery on the memory page to be recovered, thereby reducing the performance impact caused by memory recovery and improving memory usage efficiency.

[0103] See also Figure 6 , a memory recovery device 400 provided in an embodiment of the present application runs on Figure 1 or Figure 2 The electronic device or server shown, the device 400 includes:

[0104] The area acquisition unit 410 is used to acquire a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies a memory exceeding a preset value.

[0105] As a method, the area acquisition unit 410 is specifically used to obtain multiple heap mapping areas corresponding to the target application, wherein the multiple heap mapping areas are obtained by dividing the memory mapping area of ​​the target application according to preset rules; and the heap mapping area whose memory pages occupy the largest memory among the multiple heap mapping areas is taken as the target heap mapping area.

[0106] As another embodiment, the area acquisition unit 410 is also specifically used to obtain the memory currently occupied by the target application; if the memory currently occupied by the target application exceeds a threshold, a new target heap mapping area is determined from the multiple heap mapping areas; and the new target heap mapping area is rotated until the memory occupied by the target application is lower than the threshold.

[0107] The linked list determination unit 420 is used to trigger a rotation operation if it detects that the running state of the target application has changed, and determine the active linked list and the inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are the memory pages that have been accessed within the preset time period.

[0108] As a method, the linked list determination unit 420 is specifically used to trigger a first rotation operation if it is detected that the running state of the target application has changed; set the access bit of the memory page included in the target heap mapping area to 0 through the first rotation operation; trigger a second rotation operation within a preset time period to determine the active linked list and the inactive linked list corresponding to the target heap mapping area.

[0109] Furthermore, the linked list determination unit 420 is also specifically used to trigger a second rotation operation within the preset time period, and put the memory pages included in the target heap mapping area, whose access bits are 1, into the first linked list to obtain the active linked list, wherein the access bit is 1, which means that the memory page has been accessed within the preset time period; and put the memory pages included in the target heap mapping area, whose access bits are not 1, into the second linked list to obtain the inactive linked list, wherein the access bit is not 1, which means that the memory page has not been accessed within the preset time period.

[0110] As another way, the linked list determination unit 420 is also specifically used to trigger a rotation operation by running a service program in the user space if a change in the running state of the target application is detected, so as to determine the active linked list and the inactive linked list corresponding to the target heap mapping area.

[0111] The page acquisition unit 430 is used to determine the memory page to be reclaimed from the inactive linked list in response to the memory reclaim operation.

[0112] The recycling unit 440 is used to recycle the memory page to be recycled.

[0113] See also Figure 7 , the device 400 further includes:

[0114] The application determination unit 450 is used to obtain the running status and occupied memory corresponding to each of the multiple applications; and determine the application whose running status is foreground running and the memory occupied exceeds the threshold as the target application.

[0115] It should be noted that the device embodiment in the present application corresponds to the aforementioned method embodiment. The specific principles in the device embodiment can be found in the contents of the aforementioned method embodiment and will not be repeated here.

[0116] The following will be combined Figure 8 An electronic device or server provided in the present application is described.

[0117] See also Figure 8 Based on the above-mentioned memory recovery method and device, the embodiment of the present application also provides another electronic device or server 800 that can execute the above-mentioned memory recovery method. The electronic device or server 800 includes one or more (only one is shown in the figure) processors 802, a memory 804 and a network module 806 that are coupled to each other. Among them, the memory 804 stores a program that can execute the content of the above-mentioned embodiment, and the processor 802 can execute the program stored in the memory 804.

[0118] Among them, the processor 802 may include one or more processing cores. The processor 802 uses various interfaces and lines to connect the various parts of the entire electronic device or server 800, and executes various functions and processes data of the electronic device or server 800 by running or executing instructions, programs, code sets or instruction sets stored in the memory 804, and calling data stored in the memory 804. Optionally, the processor 802 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 802 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 802, but implemented separately through a communication chip.

[0119] The memory 804 may include a random access memory (RAM) or a read-only memory (ROM). The memory 804 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 804 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the electronic device or server 800 during use.

[0120] The network module 806 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, so as to communicate with a communication network or other devices, such as communicating with electronic devices. The network module 806 may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM) cards, memories, etc. The network module 806 may communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices via wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. For example, the network module 806 may exchange information with a base station.

[0121] Please refer to Fig. 9 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable storage medium 900 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.

[0122] The computer-readable storage medium 900 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer-readable storage medium 900 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 900 has storage space for program code 910 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 910 can be compressed, for example, in an appropriate form.

[0123] The present application provides a memory recovery method, device, electronic device and storage medium, firstly obtaining a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies memory exceeding a preset value, and if a change in the running state of the target application is detected, a rotation operation is triggered to determine an active linked list and an inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period, and then in response to a memory recovery operation, the memory pages to be recovered are determined from the inactive linked list, and memory recovery is performed on the memory pages to be recovered. Through the above method, the memory pages to be recovered are determined according to the memory size occupied by the heap mapping area and the activity level of the memory pages, so as to perform memory recovery on the memory pages to be recovered, thereby reducing the performance impact caused by memory recovery and improving memory usage efficiency.

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

Claims

1. A memory recovery method, characterized in that: The method comprises: Obtain a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies a memory exceeding a preset value; If a change in the running state of the target application is detected, a rotation operation is triggered to determine an active linked list and an inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period; In response to a memory reclaiming operation, determining a memory page to be reclaimed from the inactive linked list; Memory is reclaimed for the memory page to be reclaimed.

2. The method according to claim 1, characterized in that: If it is detected that the running state of the target application changes, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, including: If it is detected that the running state of the target application changes, triggering the first rotation operation; Setting the access bit of the memory page included in the target heap mapping area to 0 through the first rotation operation; A second rotation operation is triggered within a preset time period to determine an active linked list and an inactive linked list corresponding to the target heap mapping area.

3. The method according to claim 2, characterized in that The triggering of the second rotation operation within the preset time period to determine the active linked list and the inactive linked list corresponding to the target heap mapping area includes: Triggering a second rotation operation within the preset time period, putting memory pages included in the target heap mapping area, whose access bits are 1, into the first linked list to obtain the active linked list, wherein the access bit is 1 means that the memory page has been accessed within the preset time period; The memory pages included in the target heap mapping area and whose access bits are not 1 are placed into the second linked list to obtain the inactive linked list, wherein the access bit is not 1 which means that the memory page has not been accessed within the preset time period.

4. The method according to claim 1, characterized in that: The step of obtaining a target heap mapping area corresponding to the target application includes: Acquire multiple heap mapping areas corresponding to the target application, wherein the multiple heap mapping areas are obtained by dividing the memory mapping area of ​​the target application according to a preset rule; The heap mapping area whose memory pages occupy the largest memory among the multiple heap mapping areas is used as the target heap mapping area.

5. The method according to claim 4, characterized in that After the memory is reclaimed for the memory page to be reclaimed, the following step is further included: Obtaining the memory currently occupied by the target application; If the memory currently occupied by the target application exceeds a threshold, determining a new target heap mapping area from the multiple heap mapping areas; The new target heap mapping area is rotated until the memory occupied by the target application is lower than the threshold.

6. The method according to claim 1, characterized in that Before obtaining the target heap mapping area corresponding to the target application, the method further includes: Get the running status and memory occupied by multiple applications. An application in the plurality of applications whose running state is foreground running and whose occupied memory exceeds a threshold is determined as a target application.

7. The method according to claim 1, characterized in that If it is detected that the running state of the target application changes, a rotation operation is triggered to determine the active linked list and the inactive linked list corresponding to the target heap mapping area, including: If it is detected that the running state of the target application changes, a rotation operation is triggered by running a service program in the user space to determine the active linked list and the inactive linked list corresponding to the target heap mapping area.

8. A memory recovery device, characterized in that: The device comprises: An area acquisition unit, configured to acquire a target heap mapping area corresponding to a target application, wherein the target heap mapping area is a heap mapping area that occupies a memory exceeding a preset value; A linked list determination unit, configured to trigger a rotation operation if a change in the running state of the target application is detected, and determine an active linked list and an inactive linked list corresponding to the target heap mapping area, wherein the memory pages in the active linked list are memory pages that have been accessed within the preset time period; A page acquisition unit, configured to determine a memory page to be reclaimed from the inactive linked list in response to a memory reclaim operation; The recycling unit is used to recycle the memory page to be recycled.

9. An electronic device, characterized in that: The method comprises one or more processors; one or more programs are stored in the memory and configured to execute the method according to any one of claims 1 to 7 by the one or more processors.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 7 is executed.