Memory management method and device, electronic equipment and storage medium

By rotating the access bits of the memory page in the user space and updating the linked list, the problem of poor memory switching management flexibility in the prior art is solved, and a higher memory utilization rate is achieved.

CN119718603AActive Publication Date: 2025-03-28GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311262176.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-27
Publication Date
2025-03-28
Estimated Expiration
2043-09-27

AI Technical Summary

Technical Problem

The existing technology has poor flexibility when performing memory swap management and cannot effectively improve memory utilization.

Method used

The service program in the user space rotates the access bits of each memory page, determines more inactive pages, and updates the active linked list and inactive linked list based on the access bits within the target time period, and then performs memory exchange management.

Benefits of technology

Improve the accuracy of the memory pages replaced during memory swap management and effectively improve memory utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718603A_ABST
    Figure CN119718603A_ABST
Patent Text Reader

Abstract

The invention discloses a memory management method and device, electronic equipment and a storage medium, and the memory management method comprises the steps that rotation operation is carried out on an access bit of each memory page through a service program in a user space, the access bit of each memory page after rotation operation is a first mark, and the first mark is a second mark; the first mark is used for representing that a memory page is not accessed; and performing the rotation operation on the access bit of each memory page again through the service program, and updating an active linked list and an inactive linked list based on the access bit of each memory page in a target time period, the target time period is a time period from the previous rotation operation to the current rotation operation; and performing memory exchange management based on the updated active linked list and inactive linked list. The method can effectively improve the memory utilization rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic devices, and more specifically, to a memory management method, device, electronic device and storage medium. Background Art

[0002] With the rapid advancement of science and technology and living standards, electronic devices (such as smart phones, tablet computers, etc.) have become one of the commonly used electronic products in people's lives. In electronic devices, memory is one of the important components. It is a bridge for communication with the central processing unit (CPU). Since the capacity of memory is limited, it is usually necessary to manage the memory. In related technologies, memory swapping mechanisms are usually used to manage memory to increase available memory, but the flexibility of memory swapping management in related technologies is poor, and memory utilization cannot be effectively improved. Summary of the invention

[0003] The present application proposes a memory management method, device, electronic device and storage medium, which can effectively improve memory utilization.

[0004] In a first aspect, an embodiment of the present application provides a memory management method, the method comprising: performing a rotation operation on the access bit of each memory page through a service program in a user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed; performing the rotation operation on the access bit of each memory page again through the service program, and updating an active linked list and an inactive linked list based on the access bit of each memory page within a target time period, the target time period being a time period from the last rotation operation to the current rotation operation; performing memory swap management based on the updated active linked list and inactive linked list.

[0005] In a second aspect, an embodiment of the present application provides a memory management device, comprising: a first rotation module, a second rotation module and a memory exchange module, wherein the first rotation module is used to perform a rotation operation on the access bit of each memory page through a service program in a user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed; the second rotation module is used to perform the rotation operation on the access bit of each memory page again through the service program, and update the active linked list and the inactive linked list based on the access bit of each memory page within a target time period, and the target time period is the time period from the last rotation operation to the current rotation operation; the memory exchange module is used to perform memory exchange management based on the updated active linked list and the inactive linked list.

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

[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored. The program code can be called by a processor to execute the memory management method provided in the first aspect above.

[0008] The solution provided by the present application is to perform a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed, and then the access bit of each memory page is rotated again by the service program, and based on the access bit of each memory page in the target time period, the active linked list and the inactive linked list are updated, and the target time period is the time period from the last rotation operation to the current rotation operation, and memory swap management is performed based on the updated active linked list and the inactive linked list. In this way, the access bit of the memory page can be actively rotated, so as to determine more inactive pages, improve the accuracy of the memory pages swapped out during memory swap management, and thus effectively improve memory utilization. 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 flow chart of a memory management method according to an embodiment of the present application is shown.

[0011] Figure 2 A schematic flow chart of a memory management method according to another embodiment of the present application is shown.

[0012] Figure 3 A schematic flow chart of a memory management method according to another embodiment of the present application is shown.

[0013] Figure 4 A flowchart of a memory management method according to another embodiment of the present application is shown.

[0014] Figure 5 A block diagram of a memory management device according to an embodiment of the present application is shown.

[0015] Figure 6 It is a block diagram of an electronic device according to an embodiment of the present application for executing the memory management method according to an embodiment of the present application.

[0016] Figure 7 It is a storage unit of an embodiment of the present application for storing or carrying program codes for implementing the memory management method according to an embodiment of the present application. DETAILED DESCRIPTION

[0017] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.

[0018] Memory (also known as random access memory, RAM) refers to the memory used when running a program (i.e., running memory). It can only store data temporarily and is used to exchange cache data with the processor, but the memory itself cannot be used to store data for a long time. When an electronic device is running, the CPU will transfer the data that needs to be calculated to the memory for calculation. When the calculation is completed, the CPU will transmit the result. The operation of the memory also determines the stable operation of the electronic device. Since the physical memory of an electronic device is limited, and the use of memory by a process is uncertain, there is always a possibility that the physical memory will run out. In response to the situation where memory resources are tight, electronic devices usually manage memory through memory swapping.

[0019] Among them, in Android or other Linux-based systems, memory swap is a traditional memory management strategy that allows the operating system to "swap out" the data in the memory to the hard disk, compress it to other memory areas, flash memory and other storage media to free up memory space for other processes. When the "swapped out" data is needed again, the operating system will "swap it back" from the above storage media to the memory, but if the above storage medium is a physical disk, due to the access rate limit of the physical disk (the current mainstream disk read and write rate is usually at the level of hundreds of megabytes / second), the whole process is very time-consuming. During this process, users may feel that the system is abnormally slow.

[0020] The following is an introduction to the technical terms involved in memory swapping in related technologies.

[0021] Swap Space: It is a special hard disk partition, which is used by the system as Swap storage space. The size of Swap Space is usually set by the system administrator when the system is installed or configured, and is usually determined based on the system's RAM size and application requirements.

[0022] Swapiness: is a system parameter that controls the system's reliance on Swap. The Swapiness value ranges from 0 to 100. A higher value indicates that the system is more inclined to swap out data to Swap Space, while a lower value indicates that the system is more inclined to keep data in memory as much as possible.

[0023] Swap In and Swap Out: When the system memory is insufficient, the operating system will trigger Swap Out to swap out the selected memory page to Swap Space. When a swapped-out page is needed again, the system will trigger Swap In to swap the page from Swap Space back to the memory.

[0024] Usually, when performing Swap Out, that is, memory page interaction, the electronic device can use different memory replacement strategies. In the related art, the management of memory pages can usually be implemented based on the Second Chance Algorithm, which is also called the clock page replacement algorithm. It is an improved FIFO (first-in-first-out) page replacement algorithm. The page replacement algorithm determines whether a page needs to be replaced each time a page replacement is required. It considers the access bit of the page. If the bit is set (that is, the access bit is 1), then the 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 page is still 0, it will be replaced. However, since a page with an access bit of 1 needs to be scanned at least twice during page replacement before it can be swapped out, in some cases, every time a memory page needs to be swapped out, some memory pages with their access bits set may not be accessed in the future, which will cause them to be swapped out only the next time a memory page is swapped out, thereby failing to improve memory utilization more effectively.

[0025] In response to the above problems, the inventors have proposed a memory management method, device, electronic device, and storage medium provided in the embodiments of the present application, which can realize active rotation of the access bits of the memory pages, thereby determining more inactive pages, improving the accuracy of the memory pages swapped out during memory swap management, and thus effectively improving memory utilization. The specific memory management method is described in detail in the subsequent embodiments.

[0026] The memory management method provided in the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0027] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a memory management method provided by an embodiment of the present application. In a specific embodiment, the memory management method is applied to Figure 5 The memory management device 500 and the electronic device 100 ( Figure 6 ). The following will take an electronic device as an example to illustrate the specific process of this embodiment. Of course, it can be understood that the electronic device used in this embodiment can be a smart phone, a tablet computer, a smart watch, an e-book, etc., which is not limited here. Figure 1 The process shown is described in detail, and the memory management method may specifically include the following steps:

[0028] Step S110: performing a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed.

[0029] Among them, the memory page is a management unit of memory management. In the memory paging storage management, the virtual memory space of a process is divided into several pieces of equal size, called pages or pages; the page sizes are different, such as 4KB pages, 16KB pages, 64KB pages, 2MB pages, 1GB pages, etc. Memory pages can include anonymous pages, file pages, etc., which are not limited here; anonymous pages refer to pages without file backgrounds, such as heaps, stacks, data segments, etc.; file pages refer to pages with file backgrounds, which are caches generated in memory after the program reads the file. File pages are also called file caches. The virtual address space of the process in the kernel is managed according to the virtual memory area, which includes the code segment (code) virtual memory area and the data segment (data) virtual memory area.

[0030] User space is the space where user programs (including applications and various utilities) run, also known as user state. In user space, processes can perform non-privileged operations, such as reading files, updating variables, etc. Corresponding to user space is kernel space, which is the space where the operating system kernel runs, also known as kernel state. Kernel space is usually divided into some areas, each area is used for different kernel functions, for example, some areas may be used to manage memory, file systems, and network interfaces. In the related art, memory management is usually performed by the kernel of the operating system, and user-level applications usually do not interfere with memory management. The access bits of each memory page are also managed by the kernel. In this case, the kernel may not be able to effectively improve memory utilization when performing memory management. For example, when memory management is performed through a clock page replacement algorithm, the kernel clears the memory page with an access bit of 1 each time it scans. Then, the page with an access bit of 1 requires at least two scans during page replacement before it can be swapped out. In some cases, each time a memory page needs to be swapped out, some memory pages with access bits set may not be accessed in the future, so they will be swapped out only the next time a memory page is swapped out, which will affect the improvement of memory utilization.

[0031] Therefore, in an embodiment of the present application, the access bits of each memory page can be rotated by a service program in the user space to actively rotate the access bits of the memory page, so that the user space can interfere with the rotation of the access bits of the memory page, so that more inactive pages can be determined when performing memory swap management, thereby effectively improving memory utilization. Among them, the rotation operation of the access bits of the memory page can be to clear the access bits of the memory page so that the access bits of each memory page after the rotation operation are the first flag, and the first flag can be "0" to indicate that the memory page has not been accessed, that is, the memory page can be swapped out; the access bit is one of the page table entries of the memory page, and the page table entry of the memory page can also include a status bit, a modification bit, an external memory address, a resident bit, a protection bit, etc.

[0032] In some implementations, the above service program in the user space may be an application installed in the electronic device for initiating a rotation operation of the access bit of the memory page to the kernel. When the service program performs a rotation operation on the access bit of each memory page, it may initiate a request to the kernel through a system-level interface to instruct the kernel to perform the above rotation operation; based on the request, the kernel may perform a rotation operation on the access bit of each memory page, so that the access bit of each memory page is the first flag.

[0033] In some embodiments, the memory page rotation operation performed by the service program in the user space may be performed when the kernel may perform memory exchange management in the near future. That is, when the kernel may perform memory exchange management in the near future, the memory management method provided by the embodiment of the present application is executed, thereby making it possible to have more memory pages with access bits as the first flag during subsequent memory exchange management. Optionally, the electronic device can obtain the remaining memory size. If the remaining memory size is not greater than the first threshold value and is greater than the second threshold value, the access bit of each memory page can be rotated by the service program in the user space. Among them, the second threshold value is the threshold value for triggering the electronic device to perform memory exchange management. That is to say, when the remaining memory size is not greater than the second threshold value, the memory exchange management will be triggered. In this way, when the remaining memory size is small but the memory exchange management is not triggered, the rotation operation can be actively triggered by the service program in the user space.

[0034] Of course, the specific triggering timing and conditions for rotating the access bits of each memory page through the service program in the user space may not be limited. For example, whether to rotate the access bits of the memory page through the above service program may be determined based on the number of currently running applications.

[0035] In an embodiment of the present application, after the access bit of each memory page after the rotation operation is the first flag, the kernel will automatically set the access bit of the accessed memory page to the second flag according to the access status of the memory page. The second flag is used to indicate that the memory page is accessed. For example, the second flag can be "1".

[0036] Step S120: The service program performs the rotation operation on the access bit of each memory page again, and updates the active linked list and the inactive linked list based on the access bit of each memory page within a target time period, wherein the target time period is the time period from the last rotation operation to the current rotation operation.

[0037] In an embodiment of the present application, after the access bit of each memory page is rotated by the service program in the user space, the access bit of each memory page can be rotated again by the above service program, so that the access bit of each memory page is all the first flag again. In addition, the active linked list and the inactive linked list can be updated based on the access bit of each memory page in the target time period, and the target time period is the time period from the last rotation operation to the current rotation operation, that is, based on the access bit of each memory page during the two rotation operations, the active linked list and the inactive linked list are updated. Among them, the active linked list and the inactive linked list are two linked lists used to implement page replacement in the operating system. The memory pages in the active linked list are considered to be "hot", that is, these memory pages have been recently accessed, or may be accessed in the near future. These memory pages are considered to be active and will not be replaced out of the memory; the memory pages in the inactive linked list are considered to be "cold", that is, these memory pages have not been accessed in the recent period of time, or are unlikely to be accessed in the future. These memory pages are considered to be inactive and may be replaced out of the memory.

[0038] In some embodiments, when the active linked list and the inactive linked list are updated based on the access bit of each memory page in the target time period, the first memory page whose access bit in the target time period is the first mark can be added to the inactive linked list, and the second memory page whose access bit in the target time period is the second mark can be added to the active linked list based on the access bit of each memory page in the above target time period. In this way, the active linked list and the inactive linked list can be matched with the access status of the memory pages in the target time period, so that when the kernel performs memory interaction management according to the active linked list and the inactive linked list, it can more accurately determine the pages to be swapped out, so that more memory pages are swapped out.

[0039] Step S130: performing memory swap management based on the updated active linked list and inactive linked list.

[0040] In an embodiment of the present application, after the active linked list and the inactive linked list are updated based on the access bit of each memory page in the above target time period, memory exchange management can be performed based on the updated active linked list and the inactive linked list. Among them, when it is necessary to swap out a memory page, according to the principle of locality of the application, the probability of the memory page in the active linked list being accessed later is high, so at least part of the memory pages can be selected from the updated inactive linked list for swapping out, while the memory pages in the active linked list are not swapped out. Through the memory management method provided by the embodiment of the present application, the service program in the user space can actively trigger the rotation operation to match the active linked list and the inactive linked list with the actual access situation of the memory page, so that more memory pages are in the inactive linked list, and then after the memory swap is performed based on the inactive linked list, the memory utilization rate can be improved.

[0041] In some implementations, after the above active linked list and the inactive linked list are updated, memory swap management may be performed based on the updated active linked list and the inactive linked list when the memory swap condition is met.

[0042] In one possible implementation, the memory exchange condition may be that the remaining memory size is not greater than the above second threshold value. That is, if the remaining memory size of the electronic device is not greater than the second threshold value, it indicates that the memory is tight, so memory exchange management can be performed, and when memory exchange management is performed, it is based on the above updated active linked list and inactive linked list.

[0043] In a possible implementation, the memory swap condition may also be that the current available memory cannot satisfy the more memory requested by any process, that is, when a process requests more memory and the current available memory can no longer satisfy the request, the memory pages in the inactive linked list may be swapped out. Optionally, when swapping out the memory pages in the inactive linked list, the memory pages may be selected in sequence to be swapped out according to the order in which the memory pages enter the inactive linked list from earliest to latest, until the current memory demand is met.

[0044] The memory management method provided in the embodiment of the present application can realize active rotation operations on the access bits of memory pages through the service program in the user space, thereby determining more inactive pages, improving the accuracy of memory pages swapped out during memory swap management, and thus effectively improving memory utilization.

[0045] See also Figure 2 , Figure 2 A flow chart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 2The process shown is described in detail, and the memory management method may specifically include the following steps:

[0046] Step S210: When the active rotation conditions are met, the access bit of each memory page is rotated through the service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed.

[0047] In an embodiment of the present application, the electronic device can perform a rotation operation on the access bit of each memory page through a service program in the user space when the active rotation condition is met, that is, when the active rotation condition is met, the memory management method provided by the embodiment of the present application is executed. Among them, the active rotation condition can be used to screen the operating scenarios applicable to the memory management method provided by the embodiment of the present application. When the active rotation condition is met, it means that the memory management method provided by the embodiment of the present application is applicable to the current operating scenario. When the active rotation condition is not met, it means that the memory management method provided by the embodiment of the present application is not applicable to the current operating scenario.

[0048] In some embodiments, the active rotation condition may include: the first target application is switched from the background running state to the foreground running state. That is, if the first target application is switched from the background running state to the foreground running state, the access bit of each memory page can be rotated through the service program in the user space, that is, the memory management method provided by the embodiment of the present application is executed. Among them, the foreground running state refers to the state in which the electronic device displays the application interface of the application on the screen. When the application is in the foreground running state, the user can see the application interface of the application on the screen; the background running state relative to the foreground running state refers to the state in which the electronic device does not display the application interface of the application on the screen, and the user cannot interact with the running interface of the application, but the application still occupies the system resources of the electronic device when it is in the background.

[0049] In this embodiment, the first target application can be any application. It can be understood that when the first target application switches from the background running state to the foreground running state, it means that the application currently running in the foreground has changed. Then, at this time, many memory pages whose access bits were previously marked as the second flag may not be accessed. For example, the memory page corresponding to the process responsible for interface refresh of the application previously running in the foreground will not be accessed. Therefore, the memory page rotation operation is actively triggered by the service program in the user space, and memory swap management is performed through subsequent steps, thereby improving the hit rate of the swapped memory pages, and then improving memory utilization.

[0050] In some embodiments, the active rotation condition may include: the number of the second target application programs running reaches the first threshold. That is, if the number of the second target application programs running reaches the first threshold, the access bit of each memory page can be rotated by the service program in the user space, that is, the memory management method provided by the embodiment of the present application is executed. Among them, the second target application can be an application whose number of memory pages frequently accessed during operation is higher than the target number, that is, when the second target application is running, in its corresponding memory page, there are more than the target number of memory pages frequently accessed. It can be understood that when the number of the second target application programs running reaches the first threshold, it means that the number of memory pages currently frequently accessed is large, so the access bit of the memory page can be actively cleared, so that the access bit of the memory page that will not be accessed for some time period becomes the first flag, and these memory pages that are currently frequently accessed are also likely to be accessed within the target time period, and the access bit becomes the second flag, and then after the subsequent rotation operation, the updated active list can include these memory pages, and then accurately swap out the memory pages that are not frequently accessed.

[0051] In some embodiments, the active rotation condition may include: when the third target application is running, the fourth target application changes from a non-running state to a running state, and the fourth target application is an application associated with the third target application. That is, when the third target application is currently running, if it is detected that the fourth target application associated with the third target application changes from a non-running state to a running state, the access bit of each memory page is rotated through the service program in the user space. It can be understood that when two associated applications are running at the same time, the memory pages of the two applications are very likely to be frequently accessed at this time. For example, when implementing a task of application collaboration, the memory page of the application that implements the task is currently likely to be frequently accessed. Therefore, the access bit of the memory page can be actively cleared, so that the access bit of some memory pages that will not be accessed within a period of time becomes the first flag, and these memory pages that are likely to be frequently accessed are also likely to be accessed within the target time period. After that, the access bit becomes the second flag, and then after the subsequent rotation operation, the updated active list can include these memory pages, and then accurately swap out the memory pages that are not frequently accessed.

[0052] Of course, the specific active rotation conditions may not be limited in the embodiments of the present application.

[0053] Step S220: The service program performs the rotation operation on the access bit of each memory page again, and updates the active linked list and the inactive linked list based on the access bit of each memory page within a target time period, wherein the target time period is the time period from the last rotation operation to the current rotation operation.

[0054] Step S230: performing memory swap management based on the updated active linked list and inactive linked list.

[0055] In the embodiment of the present application, step S220 and step S230 may refer to the contents of other embodiments and will not be described in detail here.

[0056] It should be noted that, when the active rotation conditions are not met, the electronic device can maintain the access bits of each memory page according to the method of setting the access bits of the memory page in the relevant technology. For example, when the memory page is accessed, the access bit is set to the second flag; for another example, when the clock page replacement algorithm is used for memory exchange management, if the access bit of any memory page currently scanned is the second flag (that is, the access bit is 1), its access bit is cleared.

[0057] The memory management method provided in the embodiment of the present application can realize active rotation operations on the access bits of memory pages through the service program in the user space, so as to determine more inactive pages, improve the accuracy of memory pages swapped out during memory swap management, and thus effectively improve memory utilization; in addition, the accuracy of memory management can be guaranteed by executing the memory management method provided in the embodiment of the present application only when the active rotation conditions are met.

[0058] See also Figure 3 , Figure 3 A flowchart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 3 The process shown is described in detail, and the memory management method may specifically include the following steps:

[0059] Step S310: performing a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed.

[0060] In the embodiment of the present application, step S310 can refer to the contents of the aforementioned embodiment and will not be described again here.

[0061] Step S320: After the first time interval, the service program performs the rotation operation on the access bit of each memory page again, and updates the active linked list and the inactive linked list based on the access bit of each memory page within the target time period, and the target time period is the time period from the last rotation operation to the current rotation operation.

[0062] In an embodiment of the present application, after the access bit of each memory page is rotated by the service program in the user space, the access bit of each memory page can be rotated again by the service program after the first time interval, and the active linked list and the inactive linked list are updated based on the access bit of each memory page in the target time period. In other words, the first time interval is required between the rotation operation and the previous rotation operation, thereby ensuring that there is enough time for the memory page with a higher probability of being accessed to have its access bit changed to the second identifier after being accessed, so that the updated active linked list can include these memory pages with a higher probability of being accessed.

[0063] In some implementations, it is possible to determine in advance for each application program the target memory pages that meet the target access condition in the memory pages corresponding to each application program when the application program is historically in operation, and to count the intervals between two consecutive accesses to these target memory pages to obtain the intervals corresponding to each target memory page of each application program; and then, for each application program, based on the intervals corresponding to each target memory page of each application program, determine the target duration corresponding to each application program. The target access condition may be that the access frequency during application operation is greater than the target frequency; based on the intervals corresponding to each target memory page of each application program, determine the target duration corresponding to each application program, which may be to obtain the maximum interval duration as the target duration corresponding to each application program, or to obtain the average of the intervals corresponding to all target memory pages of each application program as the target duration corresponding to each application program.

[0064] In the above method, each time the first duration to be used is determined, the target duration corresponding to each application program that is predetermined can be obtained according to each application program that is currently running, and then the first duration can be determined according to the target duration corresponding to each application program that is currently running. The maximum value of the target durations corresponding to all the applications that are currently running can be obtained as the first duration; or the average value of the target durations corresponding to all the applications that are currently running can be obtained as the first duration.

[0065] Step S330: When the memory exchange condition is met, memory exchange management is performed based on the updated active linked list and the inactive linked list.

[0066] In the embodiment of the present application, step S330 can refer to the contents of the aforementioned embodiment and will not be repeated here.

[0067] The memory management method provided in the embodiment of the present application can realize the active rotation operation of the access bits of the memory pages through the service program in the user space, so as to determine more inactive pages, improve the accuracy of the memory pages swapped out during memory swap management, and thus effectively improve the memory utilization rate; in addition, when the duration of the previous rotation operation reaches the first duration, the rotation operation is performed again, so as to ensure that the memory pages with a higher probability of being accessed can be placed in the active linked list, thereby ensuring the accuracy of the memory swap.

[0068] See also Figure 4 , Figure 4 A schematic diagram of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 4 The process shown is described in detail, and the memory management method may specifically include the following steps:

[0069] Step S410: performing a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed.

[0070] In the embodiment of the present application, step S410 can refer to the contents of the aforementioned embodiment and will not be described again here.

[0071] Step S420: at intervals of the first time length, the service program performs the rotation operation again on the access bit of each memory page, and updates the active linked list and the inactive linked list based on the access bit of each memory page within the target time period.

[0072] In the embodiment of the present application, different from the previous embodiment, after executing step S410, that is, after the first rotation operation, the access bit of each memory page can be rotated again by the service program at intervals of the first time length, and the active linked list and the inactive linked list are updated based on the access bit of each memory page in the target time period. In this way, at any time, the memory pages that have not been accessed in the previous assessment period (i.e., the target time period) are in the inactive linked list, thereby further improving the memory utilization.

[0073] Step S430: When the memory exchange condition is met, memory exchange management is performed based on the updated active linked list and the inactive linked list.

[0074] In the embodiment of the present application, step S430 can refer to the contents of the aforementioned embodiment and will not be described again here.

[0075] The memory management method provided in the embodiment of the present application can realize the service program in the user space to actively rotate the access bits of the memory pages, so as to determine more inactive pages, improve the accuracy of the memory pages swapped out during memory exchange management, and thus effectively improve the memory utilization rate; in addition, at each interval of the first time length, the access bits of each memory page are rotated again by the service program, and the active linked list and the inactive linked list are updated based on the access bits of each memory page in the target time period, so that at any time, the memory pages that have not been accessed in the previous assessment period (i.e., the target time period) are in the inactive linked list, thereby further improving the memory utilization rate.

[0076] See also Figure 5 , which shows a structural block diagram of a memory management device 500 provided in an embodiment of the present application. The memory management device 500 applies the above-mentioned electronic device, and the memory management device 500 includes: a first rotation module 510, a second rotation module 520 and a memory exchange module 530. The first rotation module 510 is used to perform a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed; the second rotation module 520 is used to perform the rotation operation on the access bit of each memory page again through the service program, and update the active linked list and the inactive linked list based on the access bit of each memory page in the target time period, and the target time period is the time period from the last time the rotation operation was performed to the time when the rotation operation is performed this time; the memory exchange module 530 is used to perform memory exchange management based on the updated active linked list and the inactive linked list.

[0077] In some implementations, the first rotation module 510 may be specifically configured to perform a rotation operation on the access bit of each memory page through a service program in the user space when an active rotation condition is met.

[0078] In a possible implementation, the first rotation module 510 may be specifically configured to perform a rotation operation on the access bit of each memory page through a service program in the user space if the first target application is switched from a background running state to a foreground running state.

[0079] In a possible implementation, the first rotation module 510 may be specifically configured to perform a rotation operation on the access bit of each memory page through a service program in the user space if the number of the running second target application programs reaches a first threshold.

[0080] In a possible implementation, the first rotation module 510 can be specifically used to rotate the access bits of each memory page through a service program in the user space if it is detected that a fourth target application changes from a non-running state to a running state when a third target application is currently running, and the fourth target application is an application associated with the third target application.

[0081] In some embodiments, the second rotation module 520 can also be used to add the first memory page within the target time period to the inactive linked list and the second memory page within the target time period to the active linked list based on the access bit of each memory page within the target time period, wherein the access bit of the first memory page within the target time period is a first flag, and the access bit of the second memory page within the target time period is a second flag.

[0082] In some embodiments, the second rotation module 520 can be specifically used to perform the rotation operation on the access bit of each memory page again through the service program after an interval of the first time period, and update the active linked list and the inactive linked list based on the access bit of each memory page within the target time period.

[0083] In a possible implementation, the second rotation module 520 may be further specifically used to perform the rotation operation on the access bit of each memory page again through the service program at each interval of the first time length, and update the active linked list and the inactive linked list based on the access bit of each memory page within the target time period.

[0084] In some implementations, the memory exchange module 530 may be specifically configured to perform memory exchange management based on the updated active linked list and the inactive linked list when the memory exchange condition is met.

[0085] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.

[0086] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.

[0087] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.

[0088] In summary, the solution provided by the present application is to perform a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page has not been accessed, and then the access bit of each memory page is rotated again by the service program, and based on the access bit of each memory page in the target time period, the active linked list and the inactive linked list are updated, and the target time period is the time period from the last rotation operation to the current rotation operation, and memory swap management is performed based on the updated active linked list and the inactive linked list. In this way, the access bit of the memory page can be actively rotated, thereby determining more inactive pages, improving the accuracy of the memory pages swapped out during memory swap management, and effectively improving memory utilization.

[0089] Please refer to Figure 6 , which shows a structural block diagram of an electronic device provided in an embodiment of the present application. The electronic device 100 may be an electronic device capable of running applications, such as a smart phone, a tablet computer, a smart watch, an e-book, etc. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications may be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more applications are configured to execute the method described in the aforementioned method embodiment.

[0090] The processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 110 can integrate one or a combination of a central processing unit (CPU), a 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 110, but may be implemented separately through a communication chip.

[0091] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). The memory 120 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 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 100 during use.

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

[0093] The computer readable storage medium 800 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 800 includes a non-transitory computer-readable storage medium. The computer readable storage medium 800 has storage space for program code 810 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 810 can be compressed, for example, in an appropriate form.

[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A memory management method, characterized in that: The method comprises: Performing a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page is not accessed; The service program performs the rotation operation again on the access bit of each memory page, and updates the active linked list and the inactive linked list based on the access bit of each memory page within a target time period, wherein the target time period is a time period from the last rotation operation to the current rotation operation; Memory swap management is performed based on the updated active linked list and the inactive linked list.

2. The method according to claim 1, characterized in that The step of rotating the access bit of each memory page through the service program in the user space includes: When the active rotation conditions are met, the access bit of each memory page is rotated through the service program in the user space.

3. The method according to claim 2, characterized in that When the active rotation condition is met, the access bit of each memory page is rotated by the service program in the user space, including: If the first target application is switched from the background running state to the foreground running state, the access bit of each memory page is rotated through the service program in the user space.

4. The method according to claim 2, characterized in that: When the active rotation condition is met, the access bit of each memory page is rotated by the service program in the user space, including: If the number of the running second target application programs reaches a first threshold, a rotation operation is performed on the access bit of each memory page through a service program in the user space.

5. The method according to claim 2, characterized in that: When the active rotation condition is met, the access bit of each memory page is rotated by the service program in the user space, including: When a third target application is currently running, if it is detected that a fourth target application changes from a non-running state to a running state, the access bit of each memory page is rotated through a service program in the user space. The fourth target application is an application associated with the third target application.

6. The method according to claim 1, characterized in that The updating of the active linked list and the inactive linked list based on the access bit of each memory page in the target time period includes: Based on the access bit of each memory page within the target time period, the first memory page within the target time period is added to the inactive linked list, and the second memory page within the target time period is added to the active linked list, wherein the access bit of the first memory page within the target time period is the first flag, and the access bit of the second memory page within the target time period is the second flag, and the second flag is used to represent that the memory page is accessed.

7. The method according to any one of claims 1 to 6, characterized in that: The step of performing the rotation operation again on the access bit of each memory page through the service program, and updating the active linked list and the inactive linked list based on the access bit of each memory page within the target time period, includes: After the first time interval, the service program performs the rotation operation again on the access bit of each memory page, and updates the active linked list and the inactive linked list based on the access bit of each memory page in the target time period.

8. The method according to claim 7, characterized in that After the first time interval, the access bit of each memory page is rotated again by the service program, and the active linked list and the inactive linked list are updated based on the access bit of each memory page in the target time period, including: At each interval of the first time length, the service program performs the rotation operation again on the access bit of each memory page, and updates the active linked list and the inactive linked list based on the access bit of each memory page in the target time period.

9. The method according to any one of claims 1 to 6, characterized in that: The memory swap management based on the updated active linked list and the inactive linked list includes: When the memory swap condition is met, memory swap management is performed based on the updated active linked list and the inactive linked list.

10. A memory management device, characterized in that: The device comprises: a first rotation module, a second rotation module and a memory exchange module, wherein: The first rotation module is used to perform a rotation operation on the access bit of each memory page through a service program in the user space, wherein the access bit of each memory page after the rotation operation is a first flag, and the first flag is used to indicate that the memory page is not accessed; The second rotation module is used to perform the rotation operation again on the access bit of each memory page through the service program, and update the active linked list and the inactive linked list based on the access bit of each memory page in a target time period, and the target time period is a time period from the last time the rotation operation is performed to the time when the rotation operation is performed this time; The memory exchange module is used to perform memory exchange management based on the updated active linked list and inactive linked list.

11. An electronic device, characterized in that: include: one or more processors; 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 method according to any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by a processor to execute the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Method for fast scanning dirty page bitmap of full-virtualization virtual machine

    CN102981962A

  • Memory scanning method and device

    CN114579253A