Memory management method and device, electronic equipment and storage medium

By performing round-robin operations and linked list updates on the access bits of memory pages in user space, memory swapping management is optimized, solving the problem of low memory utilization in existing technologies and achieving more efficient memory page management.

CN119718603BActive Publication Date: 2026-02-24GUANGDONG 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
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-27
Publication Date
2026-02-24
Estimated Expiration
2043-09-27

AI Technical Summary

Technical Problem

Existing technologies have poor memory management flexibility and cannot effectively improve memory utilization. In particular, during memory swapping management, inactive pages cannot be accurately identified, resulting in low memory utilization.

Method used

The service program in user space performs a round-robin operation on the access bits of each memory page, sets a first flag to indicate that it has not been accessed, and then performs the round-robin operation again. Based on the access bits within the target time period, the active list and inactive list are updated to optimize memory swapping management.

Benefits of technology

It improves the accuracy of memory pages swapped out during memory swapping, effectively increasing memory utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718603B_ABST
    Figure CN119718603B_ABST
Patent Text Reader

Abstract

The application discloses a memory management method and device, electronic equipment and storage medium. The memory management method comprises: performing rotation operation on the access bit of each memory page by 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 represent that the memory page is not accessed; performing the rotation operation on the access bit of each memory page again by the service program, and updating the active link table and the non-active link table based on the access bit of each memory page in a target time period, wherein the target time period is the time period from the previous rotation operation to the present rotation operation; and performing memory swap management based on the updated active link table and non-active link table. The method can effectively improve the memory utilization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of electronic equipment technology, and more specifically, to a memory management method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the rapid advancement of technology and living standards, electronic devices (such as smartphones and tablets) have become commonplace in people's lives. Memory is a crucial component in these devices, serving as the bridge between the central processing unit (CPU) and the electronic memory. Since memory capacity is limited, it typically requires management. Related technologies often utilize memory swapping mechanisms to manage memory and increase available memory; however, these mechanisms lack flexibility and fail to effectively improve memory utilization. Summary of the Invention

[0003] This application proposes a memory management method, apparatus, electronic device, and storage medium that can effectively improve memory utilization.

[0004] In a first aspect, embodiments of this application provide a memory management method, the method comprising: performing a round-robin operation on the access bits of each memory page through a service program in user space, wherein the access bits of each memory page after the round-robin operation are a first flag, the first flag being used to indicate that the memory page has not been accessed; performing the round-robin operation again on the access bits of each memory page through the service program, and updating an active list and an inactive list based on the access bits of each memory page within a target time period, the target time period being the time period from the previous round-robin operation to the current round-robin operation; and performing memory swapping management based on the updated active list and inactive list.

[0005] Secondly, embodiments of this application provide a memory management device, comprising: a first rounding module, a second rounding module, and a memory swapping module. The first rounding module is used to perform a rounding operation on the access bits of each memory page through a service program in user space. The access bits of each memory page after the rounding operation serve as a first flag, indicating that the memory page has not been accessed. The second rounding module is used to perform the rounding operation again on the access bits of each memory page through the service program, and to update the active and inactive linked lists based on the access bits of each memory page within a target time period. The target time period is the period from the previous rounding operation to the current rounding operation. The memory swapping module is used to perform memory swapping management based on the updated active and inactive linked lists.

[0006] Thirdly, embodiments of this application provide an electronic device, including: one or more processors; a memory; and 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 perform the memory management method provided in the first aspect above.

[0007] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code, which can be invoked by a processor to execute the memory management method provided in the first aspect above.

[0008] The solution provided in this application performs a round-robin operation on the access bits of each memory page through a service program in user space. The access bits of each memory page after the round-robin operation serve as a first flag, indicating that the memory page has not been accessed. Then, the service program performs another round-robin operation on the access bits of each memory page. Based on the access bits of each memory page within a target time period (from the time of the previous round-robin operation to the time of the current round-robin operation), the active and inactive lists are updated. Memory swapping management is then performed based on the updated active and inactive lists. This allows for proactive round-robin operation on the access bits of memory pages, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping management, and ultimately effectively improving memory utilization. Attached Figure Description

[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0010] Figure 1 A flowchart illustrating a memory management method according to an embodiment of this application is shown.

[0011] Figure 2 A flowchart illustrating a memory management method according to another embodiment of this application is shown.

[0012] Figure 3 A flowchart illustrating a memory management method according to yet another embodiment of this application is shown.

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

[0014] Figure 5 A block diagram of a memory management apparatus according to one embodiment of this application is shown.

[0015] Figure 6 This is a block diagram of an electronic device for performing a memory management method according to an embodiment of this application.

[0016] Figure 7 It is a storage unit in this application embodiment for storing or carrying program code that implements the memory management method according to this application embodiment. Detailed Implementation

[0017] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.

[0018] Memory (also known as random access memory, RAM) refers to the memory used when a program is running (i.e., running memory). It can only temporarily store data and is used to exchange cached data with the processor; however, memory itself cannot be used for long-term data storage. When an electronic device is running, the CPU loads the data that needs to be processed into memory for computation. After the computation is complete, the CPU sends the result back out. The operation of memory also determines the stable operation of the electronic device. Since the physical memory of an electronic device is limited, and the memory usage of processes is unpredictable, there is always a possibility that physical memory will run out. To address situations where memory resources are scarce, electronic devices typically manage memory through memory swapping.

[0019] In Android or other Linux-based systems, memory swapping is a traditional memory management strategy. It allows the operating system to "swap out" data from memory to the hard drive, compress it to other memory areas, flash memory, or other storage media to free up memory space for other processes. When the swapped-out data is needed again, the operating system will "swap in" it back into memory. However, if the storage medium is a physical disk, the access speed limitations of the physical disk (current mainstream disk read / write speeds are typically in the hundreds of megabytes per second) make the entire process very time-consuming, during which the user may perceive the system as unusually slow.

[0020] The following section introduces the technical terms involved in memory swapping in related technologies.

[0021] Swap Space: This is a special hard drive partition that the system uses specifically for swap storage. The size of the swap space is usually set by the system administrator during system installation or configuration, and it usually needs to be determined reasonably based on the system's RAM size and application requirements.

[0022] Swapiness is a system parameter used to control the system's dependence on swap. The value of Swapiness ranges from 0 to 100. The higher the value, the more the system tends to swap data out to the swap space, while the lower the value, the more the system tends to keep data in memory as much as possible.

[0023] Swap In and Swap Out: When system memory is insufficient, the operating system triggers Swap Out, swapping selected memory pages into the Swap Space. When a swapped-out page is needed again, the system triggers Swap In, swapping the page back from the Swap Space into memory.

[0024] Typically, electronic devices employ different memory replacement strategies when performing swap-out operations (memory page exchanges). In related technologies, the Second Chance Algorithm is commonly used for memory page management. Also known as the clock-based page replacement algorithm, it's an improved FIFO (First-In, First-Out) page replacement algorithm. This algorithm determines whether a page needs to be replaced by checking its access bit. If the access bit is set (1), the page receives a "second chance"—it won't be replaced immediately, and the access bit is cleared. In the next check, if the access bit is still 0, the page is replaced. However, since a page with an access bit set to 1 requires at least two page swap scans to be swapped out, in some cases, some memory pages with access bits set may not be accessed in the future each time a memory page swap is needed. This means that they will only be swapped out during the next memory page swap, thus failing to effectively improve memory utilization.

[0025] To address the aforementioned problems, the inventors have proposed a memory management method, apparatus, electronic device, and storage medium as provided in the embodiments of this application. These methods can proactively perform round-robin operations on the access bits of memory pages, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping, and ultimately effectively improving memory utilization. The specific memory management method will be described in detail in the subsequent embodiments.

[0026] The memory management method provided in the embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0027] Please see Figure 1 , Figure 1 A flowchart illustrating a memory management method according to an embodiment of this application is shown. In a specific embodiment, the memory management method is applied to, for example... Figure 5 The memory management device 500 and the electronic device 100 configured with the memory management device 500 are shown. Figure 6 The following will use an electronic device as an example to illustrate the specific process of this embodiment. Of course, it is understood that the electronic device used in this embodiment can be a smartphone, tablet computer, smartwatch, e-reader, etc., and is not limited thereto. The following will focus on... Figure 1 The process shown will be described in detail. The memory management method may specifically include the following steps:

[0028] Step S110: The service program in user space performs a round-robin operation on the access bits of each memory page, wherein the access bits of each memory page after the round-robin operation are a first flag, which is used to indicate that the memory page has not been accessed.

[0029] In memory management, a memory page is a unit of memory management. In paging memory management, a process's virtual memory space is divided into several equal-sized segments called pages. Page sizes vary, such as 4KB, 16KB, 64KB, 2MB, and 1GB pages. Memory pages can include anonymous pages and file pages, among others. Anonymous pages refer to pages without a file background, such as the heap, stack, and data segment. File pages refer to pages with a file background; they are cached in memory after a program reads a file, and are also called file caches. The virtual address space of a process in the kernel is managed according to virtual memory regions, including the code segment virtual memory region and the data segment virtual memory region.

[0030] User space is the space where user programs (including applications and various utilities) run, also known as user mode. In user space, processes can perform non-privileged operations, such as reading files and updating variables. In contrast to user space is kernel space, the space where the operating system kernel runs, also known as kernel mode. Kernel space is typically divided into regions, each used for different kernel functions. For example, some regions might be used to manage memory, the file system, and network interfaces. In related technologies, memory management is typically handled by the operating system kernel. User-level applications usually do not interfere with memory management, and the access bits of each memory page are also managed by the kernel. This can lead to the kernel being unable to effectively improve memory utilization. For example, when using a clock-based page replacement algorithm, the kernel clears the memory pages with access bits set to 1 during each scan. Therefore, pages with access bits set to 1 require at least two page replacement scans to be swapped out. In some cases, some memory pages with access bits set may not be accessed in the future, meaning they will only be swapped out on the next page replacement, thus affecting memory utilization.

[0031] Therefore, in this embodiment, the access bits of each memory page can be rotated by a service program in user space to actively rotate the access bits of memory pages. This allows user space to interfere with the rotation of memory page access bits, thereby identifying more inactive pages during memory swapping management and effectively improving memory utilization. The rotation of memory page access bits can be achieved by clearing the access bits of memory pages to zero, so that the access bits of each memory page after the rotation are set as a first flag. This first flag can be "0" to indicate that the memory page has not been accessed, meaning that 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 modified bit, an external memory address, a resident bit, a protection bit, etc.

[0032] In some implementations, the service program in user space may be an application installed in the electronic device that initiates a round-robin operation on the access bits of memory pages to the kernel. When performing the round-robin operation on the access bits of each memory page, the service program can send a request to the kernel through a system-level interface to instruct the kernel to perform the above round-robin operation; based on the request, the kernel can perform the round-robin operation on the access bits of each memory page, so that the access bits of each memory page are set to the first flag.

[0033] In some implementations, the rotation operation of memory pages via a service program in user space can be performed when the kernel may soon perform memory swapping management. That is, if the kernel may soon perform memory swapping management, the memory management method provided in this application is executed, thereby allowing more memory pages with the first flag to be accessed during subsequent memory swapping management. Optionally, the electronic device can obtain the remaining memory size. If the remaining memory size is not greater than a first threshold but greater than a second threshold, then a rotation operation can be performed on the access bits of each memory page via a service program in user space. The second threshold is the threshold that triggers memory swapping management by the electronic device. That is, if the remaining memory size is not greater than the second threshold, memory swapping management will be triggered. Thus, even when the remaining memory size is small but memory swapping management has not yet been triggered, a rotation operation can be actively triggered via a service program in user space.

[0034] Of course, the specific triggering time and conditions for the service program in user space to perform the rotation operation on the access bits of each memory page are not limited. For example, it can also be determined whether to perform the rotation operation on the access bits of the memory page through the above service program based on the number of currently running applications.

[0035] In this embodiment of the application, after the access bit of each memory page is set to the first flag after the round-robin operation, 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 has been accessed. For example, the second flag can be "1".

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

[0037] In this embodiment, after the service program in user space performs a round-robin operation on the access bits of each memory page, the service program can perform another round-robin operation on the access bits of each memory page, so that all access bits of each memory page are again set to the first flag. Furthermore, the active and inactive lists can be updated based on the access bits of each memory page within a target time period. The target time period is the period from the last round-robin operation to the current round-robin operation. In other words, the active and inactive lists are updated based on the access bits of each memory page during the two round-robin operations. The active and inactive lists are two types of lists used in the operating system for page replacement. Memory pages in the active list are considered "hot," meaning they have been recently accessed or are likely to be accessed in the near future; these pages are considered active and will not be replaced out of memory. Memory pages in the inactive list are considered "cold," meaning they have not been accessed recently or are unlikely to be accessed in the future; these pages are considered inactive and may be replaced out of memory.

[0038] In some implementations, when updating the active and inactive lists based on the access bits of each memory page within a target time period, the first memory page with the first access bit in the target time period can be added to the inactive list, and the second memory page with the second access bit in the target time period can be added to the active list. This allows the active and inactive lists to match the access status of memory pages within the target time period, enabling the kernel to more accurately determine the swapped-out pages when performing memory interaction management based on the active and inactive lists, resulting in more memory pages being swapped out.

[0039] Step S130: Perform memory swapping management based on the updated active and inactive linked lists.

[0040] In this embodiment, after updating the active and inactive lists based on the access bits of each memory page within the target time period, memory swapping management can be performed based on the updated active and inactive lists. When a memory page needs to be swapped out, according to the principle of locality of reference, memory pages in the active list have a higher probability of being accessed subsequently. Therefore, at least some memory pages can be selected from the updated inactive list for swapping out, while memory pages in the active list are not swapped out. The memory management method provided in this embodiment allows service programs in user space to actively trigger a rotation operation, matching the active and inactive lists with the actual memory page access situation. This results in more memory pages being in the inactive list, thereby improving memory utilization after memory swapping based on the inactive list.

[0041] In some implementations, after updating the active and inactive linked lists, memory swapping management can be performed based on the updated active and inactive linked lists, provided that the memory swapping conditions are met.

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

[0043] In one possible implementation, the memory swapping condition can also be that the currently available memory cannot satisfy the additional memory requested by any process. That is, when a process requests more memory, and the currently available memory is insufficient to meet the request, memory pages in the inactive list can be swapped out. Optionally, when swapping out memory pages from the inactive list, memory pages can be selected sequentially according to their entry order into the inactive list, until the current memory requirement is met.

[0044] The memory management method provided in this application embodiment can actively perform a round-robin operation on the access bits of memory pages through a service program in user space, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping management, and thus effectively improving memory utilization.

[0045] Please see Figure 2 , Figure 2 A flowchart illustrating a memory management method according to another embodiment of this application is shown. This memory management method is applied to the aforementioned electronic device, and will be discussed below. Figure 2The process shown will be described in detail. The memory management method may specifically include the following steps:

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

[0047] In this embodiment, the electronic device can perform a round-robin operation on the access bits of each memory page through a service program in user space when the active round-robin condition is met. In other words, the memory management method provided in this embodiment is executed when the active round-robin condition is met. The active round-robin condition can be used to filter the operating scenarios applicable to the memory management method provided in this embodiment. When the active round-robin condition is met, it indicates that the memory management method provided in this embodiment is suitable for the current operating scenario; when the active round-robin condition is not met, it indicates that the memory management method provided in this embodiment is not suitable for the current operating scenario.

[0048] In some implementations, the active rotation condition may include: the first target application switching from a background running state to a foreground running state. That is, if the first target application switches from a background running state to a foreground running state, the access bits of each memory page can be rotated through the service program in user space, i.e., the memory management method provided in this application embodiment is executed. Here, the foreground running state refers to the state where the electronic device displays the application's interface on the screen; when the application is in the foreground running state, the user can see the application's interface on the screen. The background running state, in contrast, refers to the state where the electronic device does not display the application's interface on the screen, and the user cannot interact with the application's interface, but the application still occupies the electronic device's system resources when running in the background.

[0049] In this implementation, the first target application can be any application. Understandably, when the first target application switches from a background running state to a foreground running state, it indicates that the application currently running in the foreground has changed. At this time, many memory pages that were previously accessed with the second flag may not be accessed. For example, the memory pages corresponding to the processes of the application that were previously running in the foreground and were responsible for refreshing the interface will not be accessed. Therefore, the service program in the user space actively triggers the memory page rotation operation, and memory swapping management is performed through subsequent steps to improve the hit rate of swapped-out memory pages, thereby improving memory utilization.

[0050] In some implementations, the active rotation condition may include: the number of running second target applications reaching a first threshold. That is, if the number of running second target applications reaches the first threshold, the access bits of each memory page can be rotated through the service program in user space, i.e., the memory management method provided in this application embodiment is executed. The second target application can be an application whose number of frequently accessed memory pages exceeds a target number during runtime; that is, during runtime, more than a target number of memory pages in its corresponding memory pages are frequently accessed. Understandably, when the number of running second target applications reaches the first threshold, it indicates that the number of frequently accessed memory pages is currently large. Therefore, the access bits of memory pages can be actively cleared, causing the access bits of some memory pages that will not be accessed for a period of time to become the first flag. These currently frequently accessed memory pages are also likely to be accessed within the target time period, after which their access bits become the second flag. Subsequently, through another rotation operation, the updated active list can include these memory pages, thus accurately swapping out infrequently accessed memory pages.

[0051] In some implementations, the active rotation condition may include: when a third target application is running, a fourth target application changes from a non-running state to a running state; the fourth target application is an application associated with the third target application. That is, when a third target application is currently running, if it is detected that a fourth target application associated with the third target application changes from a non-running state to a running state, the access bits of each memory page are rotated through a service program in user space. Understandably, when two associated applications are running simultaneously, the memory pages of these two applications are highly likely to be frequently accessed. For example, when implementing a task involving application collaboration, the memory pages of the application implementing the task are likely to be frequently accessed. Therefore, the access bits of memory pages can be actively cleared, causing the access bits of memory pages that will not be accessed for a period of time to become the first flag. These memory pages that are highly likely to be frequently accessed are also likely to be accessed within the target time period, after which their access bits become the second flag. Subsequently, through another rotation operation, the updated active list can include these memory pages, thus accurately swapping out memory pages that are not frequently accessed.

[0052] Of course, the specific conditions for active rotation are not limited in this application embodiment.

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

[0054] Step S230: Perform memory swapping management based on the updated active and inactive linked lists.

[0055] In the embodiments of this application, steps S220 and S230 can be referred to the contents of other embodiments, and will not be repeated here.

[0056] It should be noted that, in cases where the active rotation condition is not met, the electronic device can maintain the access bits of each memory page according to the methods for setting the access bits of memory pages in related technologies. For example, when a memory page is accessed, the access bit is set to the second identifier; or, for example, when using a clock-based page replacement algorithm for memory swapping management, if the access bit of any currently scanned memory page is the second identifier (i.e., the access bit is 1), then its access bit is cleared to zero.

[0057] The memory management method provided in this application embodiment can actively perform a round-robin operation on the access bits of memory pages through a service program in user space, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping management, and thus effectively improving memory utilization. In addition, by executing the memory management method provided in this application embodiment only when the active round-robin conditions are met, the accuracy of memory management can be guaranteed.

[0058] Please see Figure 3 , Figure 3 A flowchart illustrating a memory management method according to another embodiment of this application is shown. This memory management method is applied to the aforementioned electronic device, and will be discussed below. Figure 3 The process shown will be described in detail. The memory management method may specifically include the following steps:

[0059] Step S310: The service program in user space performs a round-robin operation on the access bits of each memory page, wherein the access bits of each memory page after the round-robin operation are a first flag, which is used to indicate that the memory page has not been accessed.

[0060] In this embodiment, step S310 can be referred to the content of the foregoing embodiments, and will not be repeated here.

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

[0062] In this embodiment, after the service program in user space performs a round-robin operation on the access bits of each memory page, it can perform another round-robin operation on the access bits of each memory page after a first time interval. Based on the access bits of each memory page within the target time period, the active and inactive lists are updated. That is, the second round-robin operation needs to be spaced out by the first time interval from the previous one, thus ensuring sufficient time for memory pages with a high probability of being accessed to have their access bits change to the second identifier after being accessed, thereby ensuring that the updated active list includes these memory pages with a high probability of being accessed.

[0063] In some implementations, for each application, the target memory pages that meet the target access conditions can be pre-determined within their corresponding memory pages during their historical running state. The interval between two consecutive accesses of these target memory pages is then calculated to obtain the interval duration for each target memory page of each application. Then, for each application, the target duration is determined based on the interval duration for each target memory page. The target access condition can be that the application's runtime access frequency is greater than a target frequency. Determining the target duration for each application based on the interval duration for each target memory page can be achieved by obtaining the maximum interval duration or by obtaining the average of the interval durations for all target memory pages of each application.

[0064] In the above method, when determining the first duration to be used each time, a pre-determined target duration for each currently running application can be obtained, and then the first duration can be determined based on the target duration for each currently running application. Specifically, the first duration can be determined by obtaining the maximum value among the target durations of all currently running applications, or by obtaining the average value of the target durations of all currently running applications.

[0065] Step S330: If the memory swapping conditions are met, perform memory swapping management based on the updated active and inactive linked lists.

[0066] In this embodiment, step S330 can be referred to the content of the foregoing embodiments, and will not be repeated here.

[0067] The memory management method provided in this application embodiment can actively perform a round-robin operation on the access bits of memory pages through a service program in user space, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping, and thus effectively improving memory utilization. In addition, when the time elapsed since the last round-robin operation reaches a first time interval, a round-robin operation is performed again, thereby ensuring that memory pages with a high probability of being accessed are placed in the active list, thus ensuring the accuracy of memory swapping.

[0068] Please see Figure 4 , Figure 4 A flowchart illustrating a memory management method provided in another embodiment of this application is shown. This memory management method is applied to the aforementioned electronic device, and will be discussed below. Figure 4 The process shown will be described in detail. The memory management method may specifically include the following steps:

[0069] Step S410: The service program in user space performs a round-robin operation on the access bits of each memory page, wherein the access bits of each memory page after the round-robin operation are a first flag, which is used to indicate that the memory page has not been accessed.

[0070] In this embodiment, step S410 can be referred to the content of the foregoing embodiments, and will not be repeated here.

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

[0072] In this embodiment, unlike the previous embodiment, after executing step S410 (i.e., after the first rotation operation), the service program can perform another rotation operation on the access bits of each memory page at intervals of the first time period. Based on the access bits of each memory page within the target time period, the active and inactive lists are updated. This ensures that at any given time, memory pages not accessed during the previous assessment period (i.e., the target time period) remain in the inactive list, thereby further improving memory utilization.

[0073] Step S430: If the memory swapping conditions are met, perform memory swapping management based on the updated active and inactive linked lists.

[0074] In this embodiment, step S430 can be referred to the content of the foregoing embodiments, and will not be repeated here.

[0075] The memory management method provided in this application embodiment can actively perform a round-robin operation on the access bits of memory pages through a service program in user space, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping management, and thus effectively improving memory utilization. In addition, every first time interval, the service program performs another round-robin operation on the access bits of each memory page, and updates the active and inactive lists based on the access bits of each memory page within the target time period. This ensures that at any time, memory pages that have not been accessed in the previous assessment period (i.e., the target time period) are in the inactive list, thereby further improving memory utilization.

[0076] Please see Figure 5 This document illustrates a structural block diagram of a memory management device 500 provided in an embodiment of this application. The memory management device 500 utilizes the aforementioned electronic device and includes: a first rounding module 510, a second rounding module 520, and a memory swapping module 530. The first rounding module 510 performs a rounding operation on the access bits of each memory page through a service program in user space. The access bits of each memory page after the rounding operation serve as a first flag, indicating that the memory page has not been accessed. The second rounding module 520 performs the rounding operation again on the access bits of each memory page through the service program, and updates the active and inactive lists based on the access bits of each memory page within a target time period. The target time period is the period from the previous rounding operation to the current rounding operation. The memory swapping module 530 performs memory swapping management based on the updated active and inactive lists.

[0077] In some implementations, the first rotation module 510 can be specifically used to perform rotation operations on the access bits of each memory page through a service program in user space when the active rotation conditions are met.

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

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

[0080] In one possible implementation, the first rotation module 510 may be specifically used to perform a rotation operation on the access bits of each memory page through a service program in user space if a fourth target application is detected to change from an inactive state to a running state when a third target application is currently running. The fourth target application is an application associated with the third target application.

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

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

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

[0084] In some implementations, the memory swapping module 530 can be specifically used to perform memory swapping management based on the updated active and inactive linked lists when memory swapping conditions are met.

[0085] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

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

[0087] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.

[0088] In summary, the solution provided in this application performs a round-robin operation on the access bits of each memory page through a service program in user space. The access bits of each memory page after the round-robin operation serve as a first flag, indicating that the memory page has not been accessed. Then, the service program performs another round-robin operation on the access bits of each memory page. Based on the access bits of each memory page within a target time period (from the time of the previous round-robin operation to the time of the current round-robin operation), memory swapping management is performed. This proactively rounds the access bits of memory pages, thereby identifying more inactive pages, improving the accuracy of memory pages swapped out during memory swapping management, and ultimately effectively improving memory utilization.

[0089] Please refer to Figure 6 This document illustrates a structural block diagram of an electronic device according to an embodiment of this application. The electronic device 100 can be a smartphone, tablet computer, smartwatch, e-reader, or other electronic device capable of running applications. The electronic device 100 in this 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 can be stored in the memory 120 and configured to be executed by the one or more processors 110, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.

[0090] Processor 110 may include one or more processing cores. Processor 110 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets, or instruction sets stored in memory 120, and by calling data stored in memory 120. Optionally, processor 110 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 110 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 110 and may be implemented separately using a communication chip.

[0091] The memory 120 may include random access memory (RAM) or read-only memory (ROM). The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the electronic device 100 during use (such as phonebook data, audio and video data, chat log data, etc.).

[0092] Please refer to Figure 7 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 800 stores program code that can be called by a processor to execute the methods described in the above method embodiments.

[0093] The computer-readable storage medium 800 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or 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 of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 810 may be compressed, for example, in a suitable form.

[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions 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 this application.

Claims

1. A memory management method, characterized in that, The method includes: The service program in user space performs a round-robin operation on the access bits of each memory page. The access bits of each memory page after the round-robin operation are a first flag, which is used to indicate that the memory page has not been accessed. After the rotation operation is performed, the kernel sets the access bit of the accessed memory page to a second flag, which is used to indicate that the memory page has been accessed. The service program performs the rotation operation again on the access bits of each memory page, and updates the active and inactive linked lists based on the access bits of each memory page within the target time period. The target time period is the time period from the last rotation operation to the current rotation operation. Memory swapping management is performed based on the updated active and inactive linked lists.

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

3. The method according to claim 2, characterized in that, The step of performing a round-robin operation on the access bits of each memory page through a service program in user space, under the condition of meeting the active round-robin conditions, includes: If the first target application switches from background to foreground running, the service program in user space performs a round-robin operation on the access bits of each memory page.

4. The method according to claim 2, characterized in that, The step of performing a round-robin operation on the access bits of each memory page through a service program in user space, under the condition of meeting the active round-robin conditions, includes: If the number of running second target applications reaches the first threshold, then the access bits of each memory page are rotated through the service program in user space.

5. The method according to claim 2, characterized in that, The step of performing a round-robin operation on the access bits of each memory page through a service program in user space, under the condition of meeting the active round-robin conditions, includes: If a third target application is currently running, and a fourth target application is detected to change from a non-running state to a running state, then the service program in user space will perform a round-robin operation on the access bits of each memory page. The fourth target application is an application associated with the third target application.

6. The method according to claim 1, characterized in that, The step of updating the active and inactive linked lists based on the access bits of each memory page within 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 list, and the second memory page within the target time period is added to the active list. 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. The second flag is used to indicate that the memory page has been accessed.

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

8. The method according to claim 7, characterized in that, After a first time interval, the service program performs the rotation operation again on the access bits of each memory page, and updates the active and inactive linked lists based on the access bits of each memory page within the target time period, including: At each first time interval, the service program performs the rotation operation again on the access bits of each memory page, and updates the active and inactive linked lists based on the access bits of each memory page within the target time period.

9. The method according to any one of claims 1-6, characterized in that, The memory swapping management based on the updated active and inactive linked lists includes: Under the condition that the memory swapping conditions are met, memory swapping management is performed based on the updated active and inactive linked lists.

10. A memory management device, characterized in that, The device includes: a first rotation module, a second rotation module, and a memory swapping module, wherein, The first round-robin module is used to perform a round-robin operation on the access bits of each memory page through a service program in user space. After the round-robin operation, the access bits of each memory page are set as a first flag, which indicates that the memory page has not been accessed. After the round-robin operation, the kernel sets the access bits of the accessed memory pages to a second flag, which indicates that the memory pages have been accessed. The second rotation module is used to perform the rotation operation again on the access bits of each memory page through the service program, and update the active list and inactive list based on the access bits of each memory page within the target time period. The target time period is the time period from the last rotation operation to the current rotation operation. The memory swapping module is used to manage memory swapping based on the updated active and inactive linked lists.

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, the one or more programs being configured to perform the method as described in any one of claims 1-9.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-9.

Citation Information

Patent Citations

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

    CN102981962A

  • Memory scanning method and device

    CN114579253A