Memory management method and device, electronic equipment and storage medium
By grouping and managing the memory pages of electronic devices and optimizing memory swapping strategies based on process information, the problem of poor memory management flexibility is solved, memory swapping efficiency and storage resource utilization are improved, and system performance is enhanced.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
- Filing Date
- 2023-09-27
- Publication Date
- 2026-04-21
AI Technical Summary
Existing technologies have poor flexibility in memory management, which cannot effectively utilize the storage resources of electronic devices, resulting in time-consuming memory swapping processes and impacting system performance.
By grouping the memory pages corresponding to different processes of the target application into multiple memory groups, and determining the destination of memory pages to be swapped out based on the target process information, the memory swapping strategy is optimized, improving the flexibility of memory swapping and the utilization of storage resources.
This improves the flexibility of memory swapping and the effective utilization of storage resources, thereby enhancing the system's operational stability and response speed.
Smart Images

Figure CN119718606B_ABST
Abstract
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 utilize the storage resources of electronic devices. Summary of the Invention
[0003] This application proposes a memory management method, apparatus, electronic device, and storage medium that can improve the flexibility of memory management.
[0004] In a first aspect, embodiments of this application provide a memory management method applied to an electronic device. The method includes: grouping memory pages corresponding to different processes of a target application currently running on the electronic device to obtain multiple memory groups, wherein the target process information of the processes corresponding to memory pages in the same memory group is matched; if it is determined that a first memory page corresponding to a first process of the target application needs to be swapped out, then swapping the first memory page out to the target storage area corresponding to the target memory group where the first memory page is located.
[0005] Secondly, embodiments of this application provide a memory management device applied to an electronic device. The device includes a memory grouping module and a memory swapping module. The memory grouping module is used to group memory pages corresponding to different processes of a target application currently running on the electronic device to obtain multiple memory groups. The target process information of the processes corresponding to memory pages in the same memory group is matched. The memory swapping module is used to swap the first memory page to the target storage area corresponding to the target memory group where the first memory page is located if it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out.
[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 groups the memory pages corresponding to different processes of the target application currently running on the electronic device, resulting in multiple memory groups. The target process information of the processes corresponding to memory pages within the same memory group is matched. If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the first memory page is swapped out to the target storage area corresponding to the target memory group where the first memory page resides. Therefore, when managing memory swapping for processes of the same application, it is possible to swap them out to the destination (i.e., the target storage area) corresponding to their respective memory groups, improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device. 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 flowchart illustrating a memory management method according to yet another embodiment of this application is shown.
[0015] Figure 6 A block diagram of a memory management apparatus according to one embodiment of this application is shown.
[0016] Figure 7 This is a block diagram of an electronic device for performing a memory management method according to an embodiment of this application.
[0017] Figure 8 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
[0018] 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.
[0019] 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.
[0020] 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.
[0021] The destination for memory page swapping is typically either ZRAM (Zone-Metal RAM) or FLASH (Flash Memory). Memory pages swapped into ZRAM can be swapped back into main memory faster than those swapped into FLASH. The choice of destination depends on the system configuration and current resource usage. If ZRAM is enabled and has sufficient space, memory pages may be swapped into ZRAM first; if ZRAM is full or not enabled, memory pages will be swapped into FLASH. In related technologies, during memory swapping management, memory pages are first swapped into ZRAM, and only when ZRAM is full are they swapped back into ZRAM. This approach is inflexible; for some memory pages, direct swapping to FLASH might be more suitable than first swapping into ZRAM. Furthermore, this can lead to high ZRAM utilization while other storage resources are not effectively utilized.
[0022] 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 enable memory swapping management of memory pages for processes of the same application, allowing pages to be swapped out to their corresponding destination (i.e., target storage area) within the same memory group. This improves the flexibility of memory swapping and effectively utilizes the storage resources of the electronic device. The specific memory management method will be described in detail in subsequent embodiments.
[0023] The memory management method provided in the embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0024] 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 6 The memory management device 600 and the electronic device 100 configured with the memory management device 600 are shown. Figure 7 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:
[0025] Step S110: For the target application currently running on the electronic device, group the memory pages corresponding to different processes of the target application to obtain multiple memory groups. The target process information of the processes corresponding to the memory pages in the same memory group is matched.
[0026] The target application is any application running on the electronic device. When managing memory, the electronic device can group the memory pages corresponding to different processes of the target application into multiple memory groups, and manage the memory pages in each memory group separately. A memory page is the smallest unit used by the operating system to manage memory. It is a way for the operating system to divide physical memory and logical address space into blocks of equal size. In virtual memory management, memory is divided into contiguous, fixed-size page frames, while the logical address space is divided into memory pages of the same size as the page frames. Each memory page contains a certain number of contiguous bytes. An application is typically a collection of multiple programs, each corresponding to at least one process, and each process corresponding to at least one thread. That is, a process can be single-threaded or multi-threaded. In essence, a process is an instance, meaning a process can correspond to a function of the application. For example, the video playback function of an application can be a process of the application. Usually, the running process of an application is the main process, and the various functions within the application can be child processes of this main process. When an application's process runs, it is allocated at least one memory page. Therefore, since a process corresponds to at least one thread, and each thread corresponds to at least one memory page, each process corresponds to at least one memory page. The data stored in memory for each process refers to the data in the memory pages corresponding to that process.
[0027] In this embodiment, the electronic device groups memory pages corresponding to different processes of the target application. This can be done by grouping memory pages corresponding to different processes based on the target process information of each process of the target application, so that the target process information of the processes corresponding to the memory pages in each memory group is matched. The target process information includes at least one of the following: process function information, process memory consumption information, and process priority. Of course, the target process information may also include process memory requirement information, such as the memory access speed and access frequency required by the process. The process function information refers to the function corresponding to the process when the application is running, such as implementing interface refresh, implementing data interaction, file processing, network connection, etc. The process memory consumption information may refer to the number of memory pages occupied by the process. The process priority is the basis for the operating system to allocate CPU time resources. It determines when a process runs and how much CPU time it occupies. Each process has a priority. Processes with higher priorities are usually executed first, while processes with lower priorities will wait longer. Optionally, the memcg grouping mechanism in the Linux system can be used as the implementation carrier for memory groups.
[0028] In some implementations, memory pages corresponding to all processes of the target application can be grouped according to the memory requirement information of each process of the target application, resulting in multiple memory groups. The memory requirement information of the processes corresponding to memory pages in each memory group is mutually matched. For example, the difference in memory access speed required by multiple processes corresponding to memory pages in the same memory group is not greater than a target speed threshold, and the difference in memory access frequency required is not greater than a target frequency threshold. Each memory group includes at least one memory page corresponding to a process. Understandably, since the memory requirement information of processes corresponding to memory pages in the same memory group is mutually matched, it is convenient to perform targeted memory swapping management on the memory pages in each memory group.
[0029] In some implementations, the memory pages corresponding to all processes of the target application can be grouped according to the process priority of each process of the target application, resulting in multiple memory groups. The process priorities of the processes (i.e., the processes corresponding to the memory pages) in each memory group are matched; for example, processes in the same memory group have the same process priority. Each memory group includes at least one memory page corresponding to a process.
[0030] Of course, there is no limit to the specific method by which the memory pages corresponding to different processes of the target application are grouped based on the above target process information.
[0031] Step S120: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the first memory page is swapped out to the target storage area corresponding to the target memory group where the first memory page is located.
[0032] In this embodiment, after grouping memory pages corresponding to different processes of the target application, if it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, the first memory page can be swapped out to the target storage area corresponding to the target memory group where the first memory page is located. Here, the first process is any process of the target application, and the first memory page is any memory page corresponding to the first process. It can be understood that for the different memory groups mentioned above, corresponding swap areas can be set for the memory pages within them, so that memory pages in the memory group can be swapped out to the corresponding target storage area, thereby swapping out the memory pages corresponding to the corresponding processes to the corresponding destination (i.e., the target storage area). The target memory area can be a compressed memory area, flash memory, a region on a disk, etc. In this way, it is possible to avoid all memory pages being swapped out to ZRAM first, thereby avoiding high ZRAM occupancy rates that prevent some memory pages requiring faster swap-in speeds from being swapped out to ZRAM, and effectively utilizing different storage resources.
[0033] In some implementations, when managing each of the above memory groups, the first memory page corresponding to the first process in the target memory group can be swapped out if the memory swapping strategy determines that the first memory page needs to be swapped out. For example, if the memory swapping strategy is the LRU algorithm, and the page that has not been accessed for the longest time in the target memory group is determined to be the first memory page, then that first memory page is the memory page that needs to be swapped out. Alternatively, if the memory swapping strategy is the FIFO algorithm, and the memory page that entered the cache first in the target memory group is determined to be the first memory page, then that first memory page is the memory page that needs to be swapped out. It should be noted that if the usage of the swap space in any memory group exceeds the limit, or if the system's swap space is exhausted, then when it is determined that a memory page in that memory group needs to be swapped out, the memory page in that memory group can be directly reclaimed.
[0034] In some implementations, since the target process information of the processes corresponding to the memory pages in each of the multiple memory groups is mutually matched, the storage area to which the memory pages in each memory group need to be swapped out can be determined based on the target process information of the processes corresponding to the memory pages in that memory group. In this way, the storage area to which the memory pages in each memory group need to be swapped out can match the target process information of the memory pages within that memory group, thereby satisfying the needs of the processes. It should be noted that the swap areas (i.e., the storage areas to which the memory pages need to be swapped out) corresponding to different memory groups can be different, or some memory groups can have the same swap area.
[0035] In some embodiments, the electronic device can group the memory pages corresponding to different processes of each application, and then, when it is necessary to swap out a memory page from any group, swap the memory page to be swapped out to the storage area corresponding to the memory group where the memory page is located. That is, the memory management method provided in the embodiments of this application can be executed for each application.
[0036] The memory management method provided in this application groupes memory pages corresponding to different processes of a target application currently running on the electronic device, resulting in multiple memory groups. The target process information of the processes corresponding to memory pages within the same memory group is matched. If it is determined that a first memory page corresponding to the first process of the target application needs to be swapped out, the first memory page is swapped out to the target storage area corresponding to the target memory group where the first memory page resides. Therefore, when managing memory swapping for processes of the same application, memory pages can be swapped out to their destination (i.e., the target storage area) corresponding to their respective memory groups, improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device.
[0037] 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 2 The process shown will be described in detail. The memory management method may specifically include the following steps:
[0038] Step S210: For the target application currently running on the electronic device, group the memory pages corresponding to different processes of the target application to obtain multiple memory groups. The target process information of the processes corresponding to the memory pages in the same memory group is matched.
[0039] In this embodiment, step S210 can be referred to the content of other embodiments, and will not be repeated here.
[0040] Step S220: If it is determined that the first memory page in the target memory group needs to be swapped out, then the memory usage priority corresponding to the target memory group is determined as the target priority based on the target process information of the process corresponding to the memory page in the target memory group.
[0041] In this embodiment, once it is determined that the first memory page in the target memory group needs to be swapped out, the memory usage priority corresponding to the target memory group can be determined based on the target process information of the process corresponding to the memory page in the target memory group, and the determined memory usage priority is used as the target priority. It is understandable that since the target process information includes process functional information, process memory consumption information, process priority, required memory access speed, required access frequency, etc., the target process information can reflect the process's speed requirement for Swap In. Furthermore, the target process information corresponding to memory pages in the same memory group is mutually matched, so the processes corresponding to memory pages in different process groups have the same speed requirement for Swap In. Therefore, memory usage priorities can be divided based on different target process information, and the memory usage priority can be positively or negatively correlated with the required Swap In speed; for example, the higher the required Swap In speed, the higher the memory usage priority.
[0042] In some implementations, when the target process information includes process function information, the Swap In speed required by the process implementing the UI refresh is higher than that required by processes with other function information. When the target process information includes process priority, the higher the process priority, the higher the required Swap In speed. When the target process information includes required memory access speed, the higher the required memory access speed, the higher the required Swap In speed. When the target process information includes required access frequency, the higher the required access frequency, the higher the required Swap In speed. Therefore, memory usage priorities can be assigned based on different target process information.
[0043] In one possible implementation, when the target process information includes multiple types of information, such as process function information, process memory consumption information, process priority, required memory access speed, and required access frequency, then each type of information of the process corresponding to the memory page in the process group can be quantified into a score. Then, according to the weight corresponding to each type of information, the scores corresponding to each type of information are weighted and summed to obtain the total score. Then, the memory usage priority is determined based on the total score, wherein the memory usage priority can be positively correlated with the total score.
[0044] For example, for the above target process group, the target process information corresponding to the memory page is as follows: the process is used for interface refresh (i.e., function information), the memory consumption information is the first memory consumption amount, the process priority is priority 0, the required memory access speed is the first speed, and the required access frequency is the first frequency. Then, the score corresponding to the function information is determined to be 1, the score corresponding to the memory consumption information is the first ratio of the first memory consumption amount to the maximum memory consumption amount, the score corresponding to the process priority is 1, the score corresponding to the memory access speed is the second ratio of the first speed to the maximum access speed, and the score corresponding to the access frequency is the third ratio of the first frequency to the maximum access frequency. Then, according to the weight (0.2) corresponding to the function information, the weight (0.2) corresponding to the memory consumption information, the weight (0.2) corresponding to the process priority, the weight (0.2) corresponding to the memory access speed, and the weight (0.2) corresponding to the memory access frequency, the total score is obtained as: 1*0.2 + first ratio*0.2 + 1*0.2 + second ratio*0.2 + third ratio*0.2. After determining the total score, the process priority can be determined based on the total score.
[0045] Optionally, each memory usage priority can correspond to a different score range, and the higher the memory usage priority, the larger the minimum value of the score range. When determining the memory usage priority based on the determined total score, the memory usage priority can be determined according to the score range to which the total score belongs. For example, memory usage priorities include first priority, second priority, third priority, and fourth priority. The score range corresponding to the first priority is 0.9 to 1, the score range corresponding to the second priority is 0.8 to 0.9, the score range corresponding to the third priority is 0.7 to 0.8, and the score range corresponding to the fourth priority is 0.6 to 0.7. If the total score for the target memory group is determined to be 0.75, then the score range corresponding to 0.75 can be determined to be 0.7 to 0.8, and based on this score range, the memory usage priority corresponding to the target memory group can be obtained as the third priority.
[0046] In one possible implementation, when determining the memory usage priority of a memory group based on the target process information of the process corresponding to the memory page in the memory group, since the target process information of the processes corresponding to the memory pages in the same memory group is matched, the memory usage priority can be determined based on the target process information of the process corresponding to any memory page in the memory group.
[0047] Step S230: Determine the swap area corresponding to the target priority as the target storage area. Different memory uses swap areas corresponding to different priorities at different data read / write speeds.
[0048] In this embodiment, after determining the memory usage priority (i.e., the target priority) corresponding to the target memory group, the swap area corresponding to the target priority can be determined and used as the target storage area. The data read and write speeds of the swap areas corresponding to different memory usage priorities are different. If the memory usage priority is positively correlated with the required Swap In speed, then the higher the memory usage priority, the higher the data read and write speed of the swap area corresponding to the memory usage priority; if the memory usage priority is negatively correlated with the required Swap In speed, then the higher the memory usage priority, the lower the data read and write speed of the swap area corresponding to the memory usage priority.
[0049] In some implementations, memory usage priorities can include a first priority, a second priority, and a third priority, with the first priority being higher than the second priority, and the second priority being higher than the third priority. Memory usage priorities can be positively correlated with the required Swap In speed. After determining the target priorities, if the target priority is the first priority, the swap area corresponding to the target priority is determined as a compressed memory region, and this compressed memory region is used as the target storage region. If the target priority is not the first priority, the swap area corresponding to the target priority is determined as a storage region within the target storage module, and this storage region within the target storage module is used as the target storage region. The target storage module is any storage module other than memory. It is understandable that when the target priority is the highest, the required Swap In speed is the highest; therefore, the ZRAM, which has the fastest data read / write speed, can be determined as the swap area corresponding to the target priority. Conversely, when the target priority is not the highest priority, memory pages in the target memory group are more suitable for direct swapping to a non-ZRAM swap area; therefore, storage areas in other storage modules can be determined as the swap area corresponding to the target priority.
[0050] In one possible implementation, when the target priority is not the first priority, determining the swap area corresponding to the target priority as the storage area in the target storage module can be as follows: If the target priority is the second priority, the swap area corresponding to the target priority is determined to be the storage area in the flash memory, and the storage area in the flash memory is used as the target storage area, where the second priority is lower than the first priority; if the target priority is the third priority, the swap area corresponding to the target priority is determined to be the storage area in the disk, and the storage area in the disk is used as the target storage area, where the third priority is lower than the second priority. It is understood that since the second priority is higher than the third priority, the process requiring swap in the memory pages of the memory group corresponding to the second priority has a higher swap in speed. Therefore, when the target priority is the second priority, the storage area in the FLASH memory, which has a relatively faster data read / write speed, can be determined as the swap area corresponding to the target memory group; while when the target priority is the third priority, the storage area in the disk can be determined as the swap area corresponding to the target memory group.
[0051] Step S240: Swap the first memory page to the target storage area.
[0052] In this embodiment, step S240 can be found in other embodiments and will not be repeated here.
[0053] The memory management method provided in this application embodiment can swap memory pages of processes of the same application to their destination (i.e., target storage area) corresponding to their memory group, improving the flexibility of memory swapping and effectively utilizing the storage resources of electronic devices. In addition, when determining the swap area corresponding to the memory group, the memory usage priority is determined based on the target process information of the process corresponding to the memory page in the memory group, and then the corresponding swap area is determined based on the memory usage priority. This ensures that the data read and write speed of the swap area corresponding to the memory group can meet the Swap In speed requirements of the process corresponding to the memory page in the memory group.
[0054] 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:
[0055] Step S310: For the target application currently running on the electronic device, group the memory pages corresponding to different processes of the target application to obtain multiple memory groups. The target process information of the processes corresponding to the memory pages in the same memory group is matched.
[0056] Step S320: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined as the target storage area. The first mapping relationship includes the mapping relationship between each memory group and the swap area in the plurality of memory groups. The first mapping relationship is determined according to the target process information of the process corresponding to the memory page in each memory group.
[0057] In this embodiment, for each memory group, the mapping relationship between each memory group and the swap area can be determined based on the target process information of the process corresponding to the memory page in each memory group, thereby obtaining a first mapping relationship. If it is determined that the first memory page in the target memory group needs to be swapped out, when determining the swap area corresponding to the target memory group, the swap area corresponding to the target memory group can be determined based on the mapping relationship between the target memory group and the swap area in the first mapping relationship, and the determined swap area is used as the target storage area.
[0058] Understandably, since the target process information includes process functional information, process memory consumption information, process priority, required memory access speed, required access frequency, etc., the target process information can reflect the process's speed requirement for SwapIn. Furthermore, the target process information corresponding to memory pages in the same memory group is mutually matched. Therefore, the processes corresponding to memory pages in different process groups have the same speed requirement for SwapIn. Thus, the swap area can be determined based on the target process information of the processes corresponding to memory pages in the memory group, thereby obtaining the mapping relationship between the memory group and the swap area. Moreover, the data read and write speed of the swap area can be positively correlated with the higher the required SwapIn speed, that is, the higher the required SwapIn speed, the higher the corresponding data read and write speed of the swap area.
[0059] Step S330: Swap the first memory page to the target storage area.
[0060] In this embodiment, step S330 can be found in other embodiments and will not be repeated here.
[0061] The memory management method provided in this application embodiment can swap memory pages of processes of the same application to their corresponding destination (i.e., target storage area) within their memory group, improving the flexibility of memory swapping and effectively utilizing the storage resources of electronic devices. Furthermore, when determining the swap area corresponding to a memory group, the corresponding swap area is determined based on the mapping relationship determined by the target process information of the processes corresponding to the memory pages in each memory group. This ensures that the data read / write speed of the swap area corresponding to the memory group can meet the Swap In speed requirements of the processes corresponding to the memory pages in the memory group.
[0062] 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:
[0063] Step S410: For the target application currently running on the electronic device, group the memory pages corresponding to different processes of the target application to obtain multiple memory groups. The multiple memory groups include a first memory group and a second memory group. The process corresponding to the memory page in the first memory group is the target process used for interface refresh, and the process corresponding to the memory page in the second memory group is other processes in the target application besides the target process.
[0064] In this embodiment of the application, when grouping memory pages corresponding to different processes of the target application, the target process for interface refresh can be determined based on the functional information of the process, and the target process can be assigned to the first memory group; then, other processes besides the target process can be determined among all processes of the target application, and the other processes can be assigned to the second memory group.
[0065] Step S420: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the memory group where the first memory page is located is determined as the target memory group.
[0066] Step S430: If the target memory group is the first memory group, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined to be a compressed memory area, and the compressed memory area is used as the target storage area.
[0067] Step S440: If the target memory group is the second memory group, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined to be the storage area in the flash memory, and the storage area in the flash memory is taken as the target storage area.
[0068] In this embodiment, for the first memory group, the processes corresponding to the memory pages are all target processes used for interface refresh. To ensure the performance of the target processes, the first mapping relationship determines that the first memory group and the swap area are compressed memory regions with relatively faster data read / write speeds compared to flash memory. For the second memory group containing the memory pages of other processes, the first mapping relationship determines that the second memory group and the swap area are compressed memory regions with relatively slower data read / write speeds compared to compressed memory regions. Therefore, when it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, if the memory group to which the first memory page belongs is the first memory group, then according to the first mapping relationship, the swap area corresponding to the first process group can be determined to be a compressed memory region; if the memory group to which the first memory page belongs is the second memory group, then according to the first mapping relationship, the swap area corresponding to the second process group can be determined to be a compressed memory region.
[0069] Step S450: Swap the first memory page to the target storage area.
[0070] In this embodiment, step S450 can be found in other embodiments and will not be repeated here.
[0071] The memory management method provided in this application embodiment can manage memory swapping of memory pages for processes of the same application. It can divide the memory pages corresponding to the process used for interface refresh into different memory groups compared to memory pages corresponding to other processes. When a memory page in the memory group corresponding to the process used for interface refresh needs to be swapped out, it is swapped out to a compressed memory area. Conversely, when a memory page in the memory group corresponding to other processes needs to be swapped out, it is swapped out to a storage area in flash memory. This ensures the performance of the interface refresh process and improves the response speed and stability of the application during runtime.
[0072] Please see Figure 5 , Figure 5 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 5 The process shown will be described in detail. The memory management method may specifically include the following steps:
[0073] Step S510: Obtain the remaining storage capacity of the compressed memory region.
[0074] In this embodiment of the application, the electronic device can obtain the remaining storage amount of ZRAM in real time, so as to determine whether ZRAM can simultaneously accommodate a large number of swapped-out memory pages based on the current remaining memory amount.
[0075] Step S520: If the remaining storage is less than the first threshold, then for the target application currently running on the electronic device, the memory pages corresponding to different processes of the target application are grouped to obtain multiple memory groups.
[0076] In this embodiment, after obtaining the remaining storage capacity of the ZRAM, the remaining storage capacity can be compared with a first threshold. The first threshold serves as a condition for determining whether the ZRAM can simultaneously accommodate a large number of swapped-out memory pages. If the remaining storage capacity is less than the first threshold, it indicates that the ZRAM cannot simultaneously accommodate a large number of swapped-out memory pages. Therefore, for the target application currently running on the electronic device, the memory pages corresponding to different processes of the target application can be grouped to obtain multiple memory groups. This allows memory pages to be swapped out to the corresponding storage area as needed, thereby reducing the load on the ZRAM and effectively utilizing storage resources other than the ZRAM in the electronic device. The specific value of the first threshold is not limited; it can be determined based on the actual size of the ZRAM or by referring to the number of existing memory pages. For example, if there are many existing memory pages, the first threshold can be set relatively large so that when the remaining storage capacity of the ZRAM is large, it can trigger the grouping of application memory pages, effectively handling the situation where a large number of memory pages need to be swapped out simultaneously, and enabling the timely swapping of memory pages to the corresponding storage area.
[0077] Step S530: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the first memory page is swapped out to the target storage area corresponding to the target memory group where the first memory page is located.
[0078] In this embodiment, step S530 can be referred to the content of the foregoing embodiments, and will not be repeated here.
[0079] It should be noted that when the remaining storage is less than the first threshold, in addition to performing the above processing steps for the target application that is currently running, for other running applications, the memory pages corresponding to different processes of the application can also be grouped to obtain multiple memory groups. Then, when a memory page in any memory group needs to be swapped out, the memory page is swapped out to the target storage area corresponding to that memory group.
[0080] Step S540: If the remaining storage is greater than or equal to the first threshold, and it is determined that the second memory page needs to be swapped out, then the second memory page is swapped out to the compressed memory area, where the second memory page is any memory page in the memory of the electronic device.
[0081] In this embodiment, if the remaining storage is determined to be greater than or equal to a first threshold, the application's memory pages do not need to be grouped. If any memory page in memory needs to be swapped out, it can be swapped out to ZRAM. If the remaining storage in ZRAM is less than the first threshold, steps S520 and S530 are then executed.
[0082] The memory management method provided in this application only performs grouping of memory pages corresponding to different processes of the application into multiple memory groups when the remaining memory in the compressed memory region is less than a first threshold. Then, when a memory page in any memory group needs to be swapped out, the memory page is swapped out to the target storage region corresponding to that memory group. When the remaining memory in the compressed memory region is greater than or equal to the first threshold, and a memory page needs to be swapped out, it is directly swapped out to the compressed memory region. This further improves the flexibility of memory swapping management, effectively utilizes the relatively fast data read and write speed of the compressed memory region, and improves system performance.
[0083] Please see Figure 6 This document illustrates a structural block diagram of a memory management device 600 provided in an embodiment of this application. The memory management device 600 utilizes the aforementioned electronic device and includes a memory grouping module 610 and a memory swapping module 620. The memory grouping module 610 is used to group memory pages corresponding to different processes of a target application currently running on the electronic device, resulting in multiple memory groups. The target process information of the processes corresponding to memory pages within the same memory group is matched. The memory swapping module 620 is used to swap out the first memory page corresponding to the first process of the target application to the target storage area corresponding to the target memory group containing the first memory page if it is determined that the first memory page needs to be swapped out.
[0084] In some implementations, the memory swapping module 620 may be specifically used to determine, if it is determined that a first memory page in a target memory group needs to be swapped out, the memory usage priority corresponding to the target memory group is determined as the target priority based on the target process information of the process corresponding to the memory page in the target memory group; the swap area corresponding to the target priority is determined as the target storage area, and the data read / write speed of the swap area corresponding to different memory usage priorities is different; and the first memory page is swapped out to the target storage area.
[0085] In one possible implementation, the memory swapping module 620 can also be used to determine, if the target priority is the first priority, the swapping area corresponding to the target priority is a compressed memory area, and the compressed memory area is used as the target storage area; if the target priority is not the first priority, the swapping area corresponding to the target priority is determined to be a storage area in the target storage module, and the storage area in the target storage module is used as the target storage area, wherein the target storage module is a storage module other than memory.
[0086] Optionally, the memory swapping module 620 can also be used to determine, if the target priority is the second priority, the swapping area corresponding to the target priority is the storage area in the flash memory, and the storage area in the flash memory is used as the target storage area, wherein the second priority is lower than the first priority; if the target priority is the third priority, the swapping area corresponding to the target priority is the storage area in the disk, and the storage area in the disk is used as the target storage area, wherein the third priority is lower than the second priority.
[0087] In some implementations, the memory swapping module 620 may be specifically used to, if it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, determine the swap area corresponding to the target memory group as the target storage area according to a first mapping relationship, wherein the first mapping relationship includes the mapping relationship between each memory group and the swap area in the plurality of memory groups, and the first mapping relationship is determined according to the target process information of the process corresponding to the memory page in each memory group; and swap the first memory page out to the target storage area.
[0088] In one possible implementation, the plurality of memory groups includes a first memory group and a second memory group. The process corresponding to the memory page in the first memory group is the target process used for interface refresh, and the process corresponding to the memory page in the second memory group is another process in the target application besides the target process. The memory swapping module 620 can also be used to determine the memory group where the first memory page is located as the target memory group if it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out; if the target memory group is the first memory group, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined to be a compressed memory area, and the compressed memory area is used as the target storage area; if the target memory group is the second memory group, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined to be a storage area in flash memory, and the storage area in flash memory is used as the target storage area.
[0089] In some implementations, the target process information includes at least one of the following: process function information, process memory consumption information, and process priority.
[0090] In some embodiments, the memory management device 600 may further include a storage capacity acquisition module. The storage capacity acquisition module is used to acquire the remaining storage capacity of the compressed memory region; the memory grouping module 610 may specifically be used to group the memory pages corresponding to different processes of the target application currently running on the electronic device, if the remaining storage capacity is less than a first threshold, to obtain multiple memory groups.
[0091] In one possible implementation, the memory swapping module 620 can also be used to swap the second memory page to the compressed memory region after obtaining the remaining storage amount of the compressed memory region. If the remaining storage amount is greater than or equal to a first threshold and it is determined that the second memory page needs to be swapped out, the second memory page is any memory page in the memory of the electronic device.
[0092] 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.
[0093] In the several embodiments provided in this application, the coupling between modules can be electrical, mechanical, or other forms of coupling.
[0094] 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.
[0095] In summary, the solution provided in this application groups the memory pages corresponding to different processes of the target application currently running on the electronic device, resulting in multiple memory groups. The target process information of the processes corresponding to memory pages within the same memory group is matched. If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the first memory page is swapped out to the target storage area corresponding to the target memory group where the first memory page resides. Therefore, when managing memory swapping for processes of the same application, it is possible to swap them out to their destination (i.e., the target storage area) corresponding to their respective memory groups, improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device.
[0096] Please refer to Figure 7 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.
[0097] 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.
[0098] 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.).
[0099] Please refer to Figure 8 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.
[0100] 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.
[0101] 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, Applied to electronic devices, the method includes: For the target application currently running on the electronic device, the memory pages corresponding to different processes of the target application are grouped to obtain multiple memory groups. The target process information of the processes corresponding to the memory pages in the same memory group is matched, and the target process information includes multiple types of process information. If it is determined that the first memory page in the target memory group needs to be swapped out, then each type of information in the target process information of the process corresponding to the memory page in the target memory group is quantified into a score; Based on the weight corresponding to each type of information, the scores corresponding to each type of information are weighted and summed to obtain the total score. Based on the total score, the memory usage priority corresponding to the target memory group is determined as the target priority, and the memory usage priority is positively correlated with the total score; The swap area corresponding to the target priority is determined as the target storage area corresponding to the target memory group. The data read and write speed of the swap area corresponding to different memory usage priorities is different. The memory usage priority is positively correlated with the speed at which the memory needs to be swapped back to memory. The data read and write speed of the swap area is positively correlated with the memory usage priority. The first memory page is swapped out to the target storage area.
2. The method according to claim 1, characterized in that, The step of determining the swap area corresponding to the target priority as the target storage area corresponding to the target memory group includes: If the target priority is the first priority, then the swap area corresponding to the target priority is determined to be a compressed memory area, and the compressed memory area is used as the target storage area; If the target priority is not the first priority, then the swap area corresponding to the target priority is determined as the storage area in the target storage module, and the storage area in the target storage module is taken as the target storage area. The target storage module is a storage module other than memory.
3. The method according to claim 2, characterized in that, If the target priority is not the first priority, then determining the swap area corresponding to the target priority as the storage area in the target storage module, and using the storage area in the target storage module as the target storage area, includes: If the target priority is the second priority, then the swap area corresponding to the target priority is determined to be the storage area in the flash memory, and the storage area in the flash memory is used as the target storage area, where the second priority is lower than the first priority; If the target priority is the third priority, then the swap area corresponding to the target priority is determined to be the storage area in the disk, and the storage area in the disk is used as the target storage area, wherein the third priority is lower than the second priority.
4. The method according to claim 1, characterized in that, If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the first memory page is swapped out to the target storage area corresponding to the target memory group where the first memory page is located, including: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined as the target storage area. The first mapping relationship includes the mapping relationship between each memory group and the swap area in the plurality of memory groups. The first mapping relationship is determined according to the target process information of the process corresponding to the memory page in each memory group. The first memory page is swapped out to the target storage area.
5. The method according to claim 4, characterized in that, The plurality of memory groups include a first memory group and a second memory group. The process corresponding to the memory page in the first memory group is the target process used for interface refresh, and the process corresponding to the memory page in the second memory group is other processes in the target application besides the target process. If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined as the target storage area, including: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, then the memory group where the first memory page is located is determined as the target memory group. If the target memory group is the first memory group, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined to be a compressed memory area, and the compressed memory area is used as the target storage area; If the target memory group is the second memory group, then according to the first mapping relationship, the swap area corresponding to the target memory group is determined to be the storage area in the flash memory, and the storage area in the flash memory is taken as the target storage area.
6. The method according to claim 1, characterized in that, The target process information includes at least one of the following: process function information, process memory consumption information, and process priority.
7. The method according to any one of claims 1-6, characterized in that, The swap space to which memory pages in the memory of the electronic device are swapped out includes a compressed memory region. Before grouping memory pages corresponding to different processes of the currently running target application to obtain multiple memory groups, the method further includes: Obtain the remaining storage capacity of the compressed memory region; If the remaining storage is less than the first threshold, then the step of grouping the memory pages corresponding to different processes of the target application currently running on the electronic device to obtain multiple memory groups is executed.
8. The method according to claim 7, characterized in that, After obtaining the remaining storage capacity of the compressed memory region, the method further includes: If the remaining storage is greater than or equal to the first threshold, and it is determined that the second memory page needs to be swapped out, then the second memory page is swapped out to the compressed memory area, where the second memory page is any memory page in the memory of the electronic device.
9. A memory management device, characterized in that, The device, applied to electronic devices, includes: a memory grouping module and a memory swapping module, wherein... The memory grouping module is used to group the memory pages corresponding to different processes of the target application currently running on the electronic device, resulting in multiple memory groups. The target process information of the processes corresponding to the memory pages in the same memory group is matched, and the target process information includes multiple types of process information. The memory swapping module is configured to: if it is determined that a first memory page in a target memory group needs to be swapped out, quantify each type of information in the target process information of the process corresponding to the memory page in the target memory group into a score; perform a weighted summation of the scores corresponding to each type of information according to the weight of each type of information to obtain a total score; determine the memory usage priority corresponding to the target memory group as the target priority based on the total score, the memory usage priority being positively correlated with the total score; determine the swap area corresponding to the target priority as the target storage area corresponding to the target memory group, the data read / write speed of the swap area corresponding to different memory usage priorities is different, the memory usage priority is positively correlated with the speed at which the data needs to be swapped back to memory, and the data read / write speed of the swap area is positively correlated with the memory usage priority; and swap the first memory page out to the target storage area.
10. 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-8.
11. 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-8.
Citation Information
Patent Citations
Virtual memory management method and electronic equipment
CN113722087A
Memory management method and device, equipment and storage medium
CN114253873A