Memory management method and device, electronic equipment and storage medium
By grouping the memory pages of different processes of the target application and swapping them out to the target storage area as needed, the problem of poor memory switching management flexibility in the prior art is solved, and more efficient storage resource utilization is achieved.
Patent Information
- Application Number
- CN202311265611.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-27
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2043-09-27
AI Technical Summary
The prior art has poor flexibility when performing memory switching management and cannot effectively utilize the storage resources of electronic devices.
By grouping the memory pages corresponding to different processes of the target application, multiple memory groups are obtained. The target process information of the process corresponding to the memory pages in the same memory group matches. 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 is swapped out to the target storage area corresponding to the target memory group where the first memory page is located.
When memory swap management is implemented for memory swap pages of processes of the same application, it can be swapped out to the destination corresponding to the memory group where it is located, improving flexibility during memory swap, and effectively utilizing the storage resources of electronic devices.
Smart Images

Figure CN119718606A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electronic devices, and more specifically, to a memory management method, device, electronic device and storage medium. Background Art
[0002] With the rapid advancement of science and technology and living standards, electronic devices (such as smart phones, tablet computers, etc.) have become one of the commonly used electronic products in people's lives. In electronic devices, memory is one of the important components. It is a bridge for communication with the central processing unit (CPU). Since the capacity of memory is limited, it is usually necessary to manage the memory. In the related art, a memory exchange mechanism is usually used to manage the memory to increase the available memory, but the flexibility of memory exchange management in the related art is poor, and the storage resources of the electronic device cannot be effectively utilized. Summary of the invention
[0003] The present application proposes a memory management method, device, electronic device and storage medium, which can improve the flexibility of memory management.
[0004] In a first aspect, an embodiment of the present application provides a memory management method applied to an electronic device, the method comprising: for a target application currently running on the electronic device, grouping memory pages corresponding to different processes of the target application to obtain multiple memory groups, and the target process information of the processes corresponding to the memory pages in the same memory group are matched; if it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, swapping the first memory page out to a target storage area corresponding to the target memory group where the first memory page is located.
[0005] In a second aspect, an embodiment of the present application provides a memory management device, which is applied to an electronic device, and the device includes: a memory grouping module and a memory exchange module, wherein the memory grouping module is used to group the memory pages corresponding to different processes of a target application currently running on the electronic device to obtain multiple memory groups, and the target process information of the processes corresponding to the memory pages in the same memory group is matched; the memory exchange module is used to swap out 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] In a third aspect, an embodiment of the present application provides an electronic device, comprising: one or more processors; a memory; one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are configured to execute the memory management method provided in the first aspect above.
[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a program code is stored. The program code can be called by a processor to execute the memory management method provided in the first aspect above.
[0008] The solution provided by the present application is to group the memory pages corresponding to different processes of the target application currently running on the electronic device to obtain multiple memory groups, and the target process information of the processes corresponding to the memory pages in 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, 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. Thus, when the memory pages of the processes of the same application are managed for memory swapping, they can be swapped out to the destination (i.e., the target storage area) corresponding to the memory group where they are located, thereby improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 A schematic flow chart of a memory management method according to an embodiment of the present application is shown.
[0011] Figure 2 A schematic flow chart of a memory management method according to another embodiment of the present application is shown.
[0012] Figure 3 A schematic flow chart of a memory management method according to another embodiment of the present application is shown.
[0013] Figure 4 A flowchart of a memory management method according to another embodiment of the present application is shown.
[0014] Figure 5 A schematic flow chart of a memory management method according to yet another embodiment of the present application is shown.
[0015] Figure 6 A block diagram of a memory management device according to an embodiment of the present application is shown.
[0016] Figure 7 It is a block diagram of an electronic device according to an embodiment of the present application for executing the memory management method according to an embodiment of the present application.
[0017] Figure 8 It is a storage unit of an embodiment of the present application for storing or carrying program codes for implementing the memory management method according to an embodiment of the present application. DETAILED DESCRIPTION
[0018] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0019] Memory (also known as random access memory, RAM) refers to the memory used when running a program (i.e., running memory). It can only store data temporarily and is used to exchange cache data with the processor, but the memory itself cannot be used to store data for a long time. When an electronic device is running, the CPU will transfer the data that needs to be calculated to the memory for calculation. When the calculation is completed, the CPU will transmit the result. The operation of the memory also determines the stable operation of the electronic device. Since the physical memory of an electronic device is limited, and the use of memory by a process is uncertain, there is always a possibility that the physical memory will run out. In response to the situation where memory resources are tight, electronic devices usually manage memory through memory swapping.
[0020] Among them, in Android or other Linux-based systems, memory swap is a traditional memory management strategy that allows the operating system to "swap out" the data in the memory to the hard disk, compress it to other memory areas, flash memory and other storage media to free up memory space for other processes. When the "swapped out" data is needed again, the operating system will "swap it back" from the above storage media to the memory, but if the above storage medium is a physical disk, due to the access rate limit of the physical disk (the current mainstream disk read and write rate is usually at the level of hundreds of megabytes / second), the whole process is very time-consuming. During this process, users may feel that the system is abnormally slow.
[0021] The replacement destination of the memory page may usually be ZRAM (compressed memory area) or FLASH (flash memory). The memory page replaced to ZRAM can be swapped back to the memory faster than the memory page replaced to FLASH. The choice of destination depends on the system configuration and the current resource usage. If the system has ZRAM enabled and there is enough space, the memory page may be replaced to ZRAM first; if the ZRAM space is full or ZRAM is not enabled, the memory page will be replaced to FLASH. In the related art, when performing memory swap management, the memory page is first replaced to ZRAM, and when the ZRAM space is full, it will be replaced to ZRAM. In this way, the allocation method is not flexible enough. For some memory pages, it may be more suitable to replace them directly to FLASH rather than to ZRAM first; and this may result in a high occupancy rate of ZRAM, while other storage resources are not effectively utilized.
[0022] In response to the above problems, the inventors have proposed a memory management method, device, electronic device, and storage medium provided in the embodiments of the present application, which can achieve memory swap management for the memory pages of the process of the same application program, and can swap them out to the destination (i.e., the target storage area) corresponding to the memory group where they are located, thereby improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device. The specific memory management method is described in detail in the subsequent embodiments.
[0023] The memory management method provided in the embodiment of the present application is described in detail below with reference to the accompanying drawings.
[0024] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a memory management method provided by an embodiment of the present application. In a specific embodiment, the memory management method is applied to Figure 6 The memory management device 600 and the electronic device 100 ( Figure 7 ). The following will take an electronic device as an example to illustrate the specific process of this embodiment. Of course, it can be understood that the electronic device used in this embodiment can be a smart phone, a tablet computer, a smart watch, an e-book, etc., which is not limited here. Figure 1 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0025] Step S110: for the target application currently running on the electronic device, memory pages corresponding to different processes of the target application are grouped to obtain multiple memory groups, and target process information of processes corresponding to memory pages in the same memory group are matched.
[0026] The target application is any application running on the electronic device. When the electronic device manages the memory, the memory pages corresponding to different processes of the target application can be grouped to obtain multiple memory groups, and the memory pages in each memory group can be managed separately. Among them, the memory page refers to the smallest unit used to manage memory in the operating system. It is a way for the operating system to divide the physical memory and logical address space into blocks of equal size. In virtual memory management, the memory is divided into continuous fixed-size page frames (page frames), and the logical address space is divided into memory pages (pages) of the same size as the page frames. Each memory page contains a certain number of consecutive bytes. An application is usually a collection of multiple programs, each program corresponds to at least one process, and each process corresponds to at least one thread, that is, a process can be single-threaded or multi-threaded. It can be understood that a process is an instance, that is, a process can correspond to a function of the application. For example, the video playback function of the application can be a process of the application. Usually, the process when the application is running is the main process, and the various functions under the application can be sub-processes of the main process; when the process of the application is running, the process will be allocated at least one memory page, wherein, therefore, a process corresponds to at least one thread, each thread corresponds to at least one memory page, then each process corresponds to at least one memory page, and the data stored in the memory of each process refers to the data in the memory of each memory page corresponding to the process.
[0027] In an embodiment of the present application, the electronic device groups memory pages corresponding to different processes of the target application, and can group memory pages corresponding to different processes according to the target process information of each process of the target application, so that the target process information of the process corresponding to the memory page in each memory group obtained is matched. The target process information includes: at least one of the function information of the process, the memory consumption information of the process, and the process priority. Of course, the target process information can also include the memory requirement information of the process, such as the memory access speed and access frequency required by the process. The function information of the process refers to the function corresponding to the process when the application is running, for example, realizing interface refresh, realizing data interaction, file processing, network connection, etc.; the memory consumption information of the process can refer to the number of memory pages occupied by the process, etc.; the process priority is the basis for the operating system to allocate CPU time resources, which determines when the process runs and how much CPU time it occupies. Each process has a priority, and the higher the priority, the process will usually be executed first, while the lower priority process will wait longer. Optionally, the memcg grouping mechanism in the Linux system can be used as the implementation carrier of the memory group.
[0028] In some embodiments, the memory pages corresponding to all processes of the target application can be grouped according to the memory requirement information corresponding to each process of the target application, and multiple memory groups can be obtained, and the memory requirement information of the processes corresponding to the memory pages in each memory group are matched with each other. For example, the difference between the memory access speeds required by multiple processes corresponding to the memory pages in the same memory group during operation is not greater than the target speed threshold, and the difference between the required memory access frequencies is not greater than the target frequency threshold. Each memory group includes memory pages corresponding to at least one process. It can be understood that since the memory requirement information of the processes corresponding to the memory pages in the same memory group is matched with each other, it is convenient to perform targeted memory swap management on the memory pages in each memory group.
[0029] In some implementations, the memory pages corresponding to all processes of the target application may be grouped according to the process priority corresponding to each process of the target application, and multiple memory groups may be obtained, and the process priorities of the processes in each memory group (i.e., the processes corresponding to the memory pages) may match each other, for example, the process priorities corresponding to the processes in the same memory group may be the same. Each memory group includes a memory page corresponding to at least one process.
[0030] Of course, the specific method of grouping the memory pages corresponding to different processes of the target application program according to the above target process information may not be limited.
[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, the first memory page is swapped out to a target storage area corresponding to the target memory group where the first memory page is located.
[0032] In an embodiment of the present application, after grouping the 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. Wherein, 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 above different memory groups, the memory pages therein can be set with corresponding swap areas to achieve the memory pages in the memory group, which can be swapped out to the corresponding target storage area, and then the memory pages corresponding to the corresponding process are swapped out to the corresponding destination (i.e., the target storage area). Wherein, the target memory area can be a compressed memory area, a flash memory, an area in a disk, etc. In this way, it can be avoided that all memory pages are preferentially swapped out to ZRAM, thereby avoiding the high occupancy rate of ZRAM and causing some memory pages that need to be swapped back (Swap In) at a faster speed to be unable to be swapped out to ZRAM, and different storage resources can be effectively utilized.
[0033] In some embodiments, when managing each of the above memory groups, the first memory page can be swapped out when it is determined according to the memory swap strategy that the first memory page corresponding to the first process in the target memory group needs to be swapped out. For example, the above memory swap strategy is a strategy corresponding to the LRU algorithm. If it is determined that the page that has not been accessed for the longest time in the target memory group is the first memory page, then the first memory page is the memory page that needs to be swapped out; for another example, the above memory swap strategy is a strategy corresponding to the FIFO algorithm. If it is determined that the memory page that first enters the cache in the target memory group is the first memory page, then the first memory page is the memory page that needs to be swapped out. It should be noted that if the usage of the swap area (Swap Space) of any memory group exceeds the limit, or the system's Swap Space has been used up, when it is determined that the memory pages in the memory group need to be swapped out, the memory pages in the memory group can be directly recycled.
[0034] In some embodiments, since the target process information of the process corresponding to the memory pages in each memory group in the above multiple memory groups matches each other, 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 process corresponding to the memory pages in the memory group. In this way, the storage area to which the memory pages in each memory group need to be swapped out can be matched with the target process information of the memory pages therein, thereby meeting the needs of the process. It should be noted that, among the above multiple memory groups, the swap areas corresponding to different memory groups (i.e., the storage areas to which the memory pages need to be swapped out) can be different, or the swap areas corresponding to some memory groups can be the same.
[0035] In some embodiments, the electronic device can group the memory pages corresponding to different processes of each application, and then when a memory page in any group needs to be swapped out, the memory page to be swapped out is swapped out to the storage area corresponding to the memory group where the memory page is located. In other words, the memory management method provided in the embodiment of the present application can be executed for each application.
[0036] The memory management method provided in the embodiment of the present application is to obtain multiple memory groups by grouping the memory pages corresponding to different processes of the target application currently running on the electronic device, and the target process information of the processes corresponding to the memory pages in 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, 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. In this way, when the memory pages of the processes of the same application are managed for memory swapping, they can be swapped out to the destination (i.e., the target storage area) corresponding to the memory group where they are located, thereby improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device.
[0037] See also Figure 2 , Figure 2 A flow chart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 2 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0038] Step S210: for the target application currently running on the electronic device, memory pages corresponding to different processes of the target application are grouped to obtain multiple memory groups, and target process information of processes corresponding to memory pages in the same memory group is matched.
[0039] In the embodiment of the present application, step S210 can refer to the contents 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, the memory usage priority corresponding to the target memory group is determined as the target priority according to the target process information of the process corresponding to the memory page in the target memory group.
[0041] In an embodiment of the present application, when 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 according to 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 can be understood that since the target process information is the function information of the process, the memory consumption information of the process, the process priority, the required memory access speed, the required access frequency, etc., the target process information can reflect the process's speed requirements for Swap In, and the target process information corresponding to the memory pages in the same memory group is matched with each other, so the processes corresponding to the memory pages in different process groups have the same Swap In speed requirements, so the memory usage priority can be divided according to different target process information, and the memory usage priority can be positively correlated or negatively correlated with the higher 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 the functional information of the process, the Swap In speed required by the process for implementing the interface refresh is higher than the Swap In speed required by the process for other functional information; when the target process information includes the process priority, the higher the process priority, the higher the Swap In speed required by the process; when the target process information includes the required memory access speed, the higher the required memory access speed, the higher the Swap In speed required by the process; when the target process information includes the required access frequency, the higher the required access frequency, the higher the Swap In speed required by the process. Accordingly, the memory usage priority can be divided according to different target process information.
[0043] In a possible implementation, when the target process information includes multiple types of information, for example, simultaneously including the function information of the process, the memory consumption information of the process, the process priority, the required memory access speed, and the required access frequency, each type of information of the process corresponding to the memory page in the process group can be quantified into a score, and then the score corresponding to each type of information is weighted and summed according to the weight corresponding to each type of information to obtain a total score, and then the memory usage priority is determined according to the total score, wherein the memory usage priority can be positively correlated with the total score.
[0044] Exemplarily, for the above target process group, the target process information corresponding to the memory page is: the process is used for interface refresh (i.e., functional information), the memory consumption information is the first memory consumption, 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, it can be determined that the score corresponding to the functional information is 1, the score corresponding to the memory consumption information is the first ratio of the first memory consumption to the maximum memory consumption, 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 corresponding to the functional information (0.2), the weight corresponding to the memory consumption information (0.2), the weight corresponding to the process priority (0.2), the weight corresponding to the memory access speed (0.2), and the weight corresponding to the memory access frequency (0.2), the total score is: 1*0.2+first ratio*0.2+1*0.2+second ratio*0.2+third ratio*0.2; after the total score is determined, the process priority can be determined according to the total score.
[0045] Optionally, each memory usage priority may 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 may be determined based on the score range to which the total score belongs. For example, the memory usage priority includes a first priority, a second priority, a third priority, and a 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. For the target memory group, when the above total score is determined to be 0.75, it can be determined that the score range to which 0.75 belongs is 0.7 to 0.8, and based on this score range, it can be obtained that the memory usage priority corresponding to the target memory group is the third priority.
[0046] In one possible implementation, when determining the memory usage priority corresponding to 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 process corresponding to the memory page 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, and the data reading and writing speeds of the swap areas corresponding to different memory usage priorities are different.
[0048] In an embodiment of the present application, after determining the memory usage priority (i.e., 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, and 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 higher speed of the required Swap In, 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 higher speed of the required Swap In, 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 embodiments, the memory usage priority may include a first priority, a second priority, and a third priority, the first priority being higher than the second priority, the second priority being higher than the third priority, and the memory usage priority may be positively correlated with the higher speed of the required Swap In. After determining the above target priority, if the target priority is the first priority, the swap area corresponding to the target priority is determined to be the 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 swap area corresponding to the target priority is determined to be the storage area in the target storage module, and the storage area in the target storage module is used as the target storage area, and the target storage module is a storage module other than the memory. It can be understood that in the case where the target priority is the highest priority, the Swap In speed required is the highest, so the ZRAM with the fastest data read and write speed can be determined as the swap area corresponding to the target priority, and in the case where the target priority is not the highest priority, the memory pages in the target memory group are more suitable for directly swapping out to the non-ZRAM swap area, so the storage area in other storage modules can be determined as the swap area corresponding to the target priority.
[0050] In a possible implementation, when the target priority is not the first priority, when determining the swap area corresponding to the target priority as the storage area in the target storage module, it can be that 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, and 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, and the third priority is lower than the second priority. It can be understood that since the second priority is higher than the third priority, the Swap In speed of the process required by the memory page in the memory group corresponding to the second priority is higher, so when the target priority is the second priority, the storage area in the FLASH with a relatively fast data reading and writing speed can be determined as the swap area corresponding to the target memory group, and when the target priority is the third priority, the storage area in the disk is determined as the swap area corresponding to the target memory group.
[0051] Step S240: swapping out the first memory page to the target storage area.
[0052] In the embodiment of the present application, step S240 can refer to the contents of other embodiments and will not be repeated here.
[0053] The memory management method provided in the embodiment of the present application can realize memory swap management for the memory pages of the process of the same application program, and can swap them out to the destination (i.e., the target storage area) corresponding to the memory group to which they are located, thereby improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device; 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, so that the data reading and writing speed of the swap area corresponding to the memory group can meet the Swap In speed requirement of the process corresponding to the memory page in the memory group.
[0054] See also Figure 3 , Figure 3 A flow chart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 3 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0055] Step S310: for the target application currently running on the electronic device, memory pages corresponding to different processes of the target application are grouped to obtain multiple memory groups, and target process information of processes corresponding to 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, the swap area corresponding to the target memory group is determined as the target storage area based on a first mapping relationship, wherein the first mapping relationship includes a mapping relationship between each memory group in the multiple memory groups and the swap area, and the first mapping relationship is determined based on the target process information of the process corresponding to the memory page in each memory group.
[0057] In an embodiment of the present application, for each of the above memory groups, the mapping relationship between each memory group and the swap area can be determined according to the target process information of the process corresponding to the memory page in each memory group, so as to obtain 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 according to the mapping relationship between the target memory group and the interactive area in the first mapping relationship, and the determined swap area is used as the target storage area.
[0058] It can be understood that since the target process information is the function information of the process, the memory consumption information of the process, the process priority, the required memory access speed, the required access frequency, etc., the target process information can reflect the process's speed requirement for SwapIn, and the target process information corresponding to the memory pages in the same memory group matches each other, so the processes corresponding to the memory pages in different process groups have the same Swap In speed requirement. Therefore, the swap area can be determined according to the target process information of the process corresponding to the memory pages in the memory group, and then the mapping relationship between the memory group and the interactive area is obtained, and the data read and write speed of the swap area can be positively correlated with the higher the required Swap In speed, that is, the higher the required Swap In speed, the higher the corresponding data read and write speed of the swap area.
[0059] Step S330: swapping out the first memory page to the target storage area.
[0060] In the embodiment of the present application, step S330 can refer to the contents of other embodiments and will not be repeated here.
[0061] The memory management method provided in the embodiment of the present application can realize memory swap management for the memory pages of the process of the same application program, and can swap them out to the destination (i.e., the target storage area) corresponding to the memory group to which they are located, thereby improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device; in addition, when determining the swap area corresponding to the memory group, the corresponding swap area is determined by determining the mapping relationship based on the target process information of the process corresponding to the memory page in each memory group, so that the data reading and writing speed of the swap area corresponding to the memory group can meet the Swap In speed requirement of the process corresponding to the memory page in the memory group.
[0062] See also Figure 4 , Figure 4 A schematic diagram of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 4 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0063] Step S410: For a target application currently running on the electronic device, memory pages corresponding to different processes of the target application are grouped to obtain multiple memory groups, wherein the multiple memory groups include a first memory group and a second memory group, wherein the processes corresponding to the memory pages in the first memory group are target processes for interface refresh, and the processes corresponding to the memory pages in the second memory group are other processes of the target application except the target process.
[0064] In an embodiment of the present application, when grouping memory pages corresponding to different processes of a 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 divided into a first memory group; then, other processes except the target process among all processes of the target application can be determined, and the other processes can be divided into a 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, a memory group where the first memory page is located is determined as a target memory group.
[0066] Step S430: If the target memory group is the first memory group, it is determined according to the first mapping relationship that the swap area corresponding to the target memory group is 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, determine, based on the first mapping relationship, that the swap area corresponding to the target memory group is a storage area in the flash memory, and use the storage area in the flash memory as the target storage area.
[0068] In the embodiment of the present application, for the first memory group, the processes corresponding to the memory pages therein are all target processes for interface refresh. In order to ensure the performance of the target process, the mapping relationship between the first memory group and the swap area in the first mapping relationship determined can be that the swap area corresponding to the first memory group is a compressed memory area with a faster data read and write speed than the flash memory; and for the second memory group where the memory pages of other processes are located, the mapping relationship between the second memory group and the swap area in the first mapping relationship determined can be that the swap area corresponding to the second memory group is a storage area in the flash memory with a slower data read and write speed than the compressed memory area. Therefore, in the case where 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, it can be determined that the swap area corresponding to the first process group is a compressed memory area; if the memory group to which the first memory page belongs is the second memory group, then according to the first mapping relationship, it can be determined that the swap area corresponding to the second process group is a compressed memory area.
[0069] Step S450: swapping out the first memory page to the target storage area.
[0070] In the embodiment of the present application, step S450 can refer to the contents of other embodiments and will not be repeated here.
[0071] The memory management method provided in the embodiment of the present application can implement memory swap management for the memory pages of the process of the same application, and divide the memory pages corresponding to the process used for interface refresh and the memory pages corresponding to other processes into different memory groups. When the memory pages in the memory group corresponding to the process used for interface refresh need to be swapped out, the memory pages are swapped out to the compressed memory area, and when the memory pages in the memory group corresponding to other processes need to be swapped out, the memory pages are swapped out to the storage area in the flash memory, thereby ensuring the performance of the interface refresh process and improving the response speed and stability of the application when it is running.
[0072] See also Figure 5 , Figure 5 A flow chart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 5 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0073] Step S510: Obtain the remaining storage capacity of the compressed memory area.
[0074] In an embodiment of the present application, the electronic device can obtain the remaining storage capacity of the ZRAM in real time, so as to determine whether the ZRAM can accommodate a large number of swapped-out memory pages at the same time according to the current remaining memory capacity.
[0075] Step S520: if the remaining storage capacity is less than a first threshold, for a target application currently running on the electronic device, memory pages corresponding to different processes of the target application are grouped to obtain a plurality of memory groups.
[0076] In an embodiment of the present application, after obtaining the remaining storage capacity of the ZRAM, the remaining storage capacity can be compared with a first threshold value, and the first threshold value is used as a condition for determining whether the ZRAM can accommodate a large number of swapped memory pages at the same time. If the remaining storage capacity is less than the first threshold value, it means that the ZRAM cannot accommodate a large number of swapped memory pages at the same time. Therefore, the target application currently running on the electronic device can be used to group the memory pages corresponding to different processes of the target application to obtain multiple memory groups, so that the memory pages can be swapped out to the corresponding storage area according to the memory group where the memory pages to be swapped out are located, thereby reducing the load of the ZRAM and effectively utilizing the storage resources other than the ZRAM in the electronic device. Among them, the specific value of the first threshold value can be determined according to the actual size of the ZRAM, and can also be determined by referring to the number of currently existing memory pages. For example, when there are many currently existing memory pages, the first threshold value can be set relatively large, so that when the remaining storage capacity of the ZRAM is large, the grouping of the memory pages of the application can be triggered, so as to effectively deal with the need to swap out a large number of memory pages at the same time, and the memory pages to be swapped out can be swapped out to the corresponding storage area immediately.
[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, the first memory page is swapped out to a target storage area corresponding to the target memory group where the first memory page is located.
[0078] In the embodiment of the present application, step S530 can refer to the contents of the aforementioned embodiment and will not be described again here.
[0079] It should be noted that, when the above remaining storage amount is less than the first threshold, in addition to performing the above processing flow for the previously running target application, for other running applications, the memory pages corresponding to different processes of the application can also be grouped to obtain multiple memory groups, and then when the memory pages in any memory group need to be swapped out, the memory pages can be swapped out to the target storage area corresponding to the memory group.
[0080] Step S540: If the remaining storage capacity is greater than or equal to the first threshold, and it is determined that the second memory page needs to be swapped out, the second memory page is swapped out to the compressed memory area, and the second memory page is any memory page in the memory of the electronic device.
[0081] In the embodiment of the present application, when it is determined that the remaining storage capacity is greater than or equal to the first threshold, the memory pages of the application may not be grouped, and when any memory page in the memory needs to be swapped out, it may be swapped out to the ZRAM. When the remaining storage capacity of the ZRAM is less than the first threshold, the above steps S520 and S530 are performed again.
[0082] The memory management method provided in the embodiment of the present application performs grouping of memory pages corresponding to different processes of an application to obtain multiple memory groups only when the remaining memory amount of the compressed memory area is less than a first threshold value, and then when a memory page in any memory group needs to be swapped out, the memory page is swapped out to a target storage area corresponding to the memory group; and when the remaining memory amount of the compressed memory area is greater than or equal to the first threshold value, when the memory page needs to be swapped out, it is directly swapped out to the compressed memory area, thereby further improving the flexibility of memory swap management, effectively utilizing the advantage of the relatively fast data reading and writing speed of the compressed memory area, and improving system performance.
[0083] See also Figure 6 , which shows a structural block diagram of a memory management device 600 provided in an embodiment of the present application. The memory management device 600 applies the above-mentioned electronic device, and the memory management device 600 includes: a memory grouping module 610 and a memory exchange module 620. Among them, the memory grouping module 610 is used to group the memory pages corresponding to different processes of the target application currently running on the electronic device, and obtain multiple memory groups, and the target process information of the processes corresponding to the memory pages in the same memory group is matched; the memory exchange 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 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.
[0084] In some embodiments, the memory exchange module 620 can be specifically used to, if it is determined that the first memory page in the target memory group needs to be swapped out, then, based on the target process information of the process corresponding to the memory page in the target memory group, determine the memory usage priority corresponding to the target memory group as the target priority; determine the swap area corresponding to the target priority as the target storage area, the data reading and writing speeds of the swap areas corresponding to different memory usage priorities are different; and swap out the first memory page to the target storage area.
[0085] In a possible implementation, the memory exchange module 620 can also be used to, if the target priority is the first priority, determine that the exchange area corresponding to the target priority is a compressed memory area, and use the compressed memory area as the target storage area; if the target priority is not the first priority, determine that the exchange area corresponding to the target priority is a storage area in the target storage module, and use the storage area in the target storage module as the target storage area, and the target storage module is a storage module other than the memory.
[0086] Optionally, the memory exchange module 620 can also be used to, if the target priority is the second priority, determine that the exchange area corresponding to the target priority is a storage area in the flash memory, and use the storage area in the flash memory as the target storage area, and the second priority is lower than the first priority; if the target priority is the third priority, determine that the exchange area corresponding to the target priority is a storage area in the disk, and use the storage area in the disk as the target storage area, and the third priority is lower than the second priority.
[0087] In some embodiments, the memory exchange module 620 can be specifically used to determine the swap area corresponding to the target memory group as the target storage area based on a first mapping relationship 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 mapping relationship including a mapping relationship between each memory group in the multiple memory groups and the swap area, the first mapping relationship being determined based on the target process information of the process corresponding to the memory page in each memory group; swapping the first memory page out to the target storage area.
[0088] In a possible implementation, 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 a target process for interface refresh, and the process corresponding to the memory page in the second memory group is other processes of the target application except the target process. The memory exchange 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, determine that the swap area corresponding to the target memory group is a compressed memory area, and use the compressed memory area as the target storage area; if the target memory group is the second memory group, then according to the first mapping relationship, determine that the swap area corresponding to the target memory group is a storage area in the flash memory, and use the storage area in the flash memory as the target storage area.
[0089] In some implementations, the target process information includes at least one of process function information, process memory consumption information, and process priority.
[0090] In some implementations, the memory management device 600 may further include a storage acquisition module. The storage acquisition module is used to acquire the remaining storage capacity of the compressed memory area; the memory grouping module 610 may be specifically used to group memory pages corresponding to different processes of the target application currently running on the electronic device to obtain multiple memory groups if the remaining storage capacity is less than a first threshold.
[0091] In a possible implementation, the memory exchange module 620 can also be used to, after obtaining the remaining storage capacity of the compressed memory area, if the remaining storage capacity is greater than or equal to a first threshold, and it is determined that a second memory page needs to be swapped out, swap the second memory page out to the compressed memory area, where the second memory page is any memory page in the memory of the electronic device.
[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0093] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0094] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.
[0095] In summary, the solution provided by the present application is to obtain multiple memory groups by grouping the memory pages corresponding to different processes of the target application currently running on the electronic device, and the target process information of the processes corresponding to the memory pages in 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, 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. In this way, when the memory pages of the processes of the same application are managed for memory swapping, they can be swapped out to the destination (i.e., the target storage area) corresponding to the memory group where they are located, thereby improving the flexibility of memory swapping and effectively utilizing the storage resources of the electronic device.
[0096] Please refer to Figure 7 , which shows a structural block diagram of an electronic device provided in an embodiment of the present application. The electronic device 100 may be an electronic device capable of running applications, such as a smart phone, a tablet computer, a smart watch, an e-book, etc. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications may be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more applications are configured to execute the method described in the aforementioned method embodiment.
[0097] The processor 110 may include one or more processing cores. The processor 110 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 can be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), and programmable logic array (PLA). The processor 110 can integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 110, but may be implemented separately through a communication chip.
[0098] The memory 120 may include a random access memory (RAM) or a read-only memory (ROM). The memory 120 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the electronic device 100 during use.
[0099] Please refer to Figure 8 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 800 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0100] The computer readable storage medium 800 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer readable storage medium 800 has storage space for program code 810 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 810 can be compressed, for example, in an appropriate form.
[0101] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A memory management method, characterized in that: Applied to electronic equipment, the method comprises: For a target application currently running on the electronic device, memory pages corresponding to different processes of the target application are grouped to obtain a plurality of memory groups, and target process information of processes corresponding to memory pages in the same memory group are matched; 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 is swapped out to a target storage area corresponding to the target memory group where the first memory page is located.
2. 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, swapping out the first memory page to a target storage area corresponding to the target memory group where the first memory page is located includes: If it is determined that the first memory page in the target memory group needs to be swapped out, determining the memory usage priority corresponding to the target memory group as the target priority according to the target process information of the process corresponding to the memory page in the target memory group; Determine a swap area corresponding to the target priority as the target storage area, wherein the data reading and writing speeds of the swap areas corresponding to different memory usage priorities are different; Swap out the first memory page to the target storage area.
3. The method according to claim 2, characterized in that The step of determining the exchange area corresponding to the target priority as the target storage area includes: If the target priority is the first priority, determining that the swap area corresponding to the target priority is a compressed memory area, and using the compressed memory area as the target storage area; If the target priority is not the first priority, the exchange area corresponding to the target priority is determined to be the storage area in the target storage module, and the storage area in the target storage module is used as the target storage area. The target storage module is a storage module other than the memory.
4. The method according to claim 3, characterized in that If the target priority is not the first priority, determining that the exchange area corresponding to the target priority is a storage area in a target storage module, and using the storage area in the target storage module as the target storage area, comprises: If the target priority is the second priority, determining that the swap area corresponding to the target priority is a storage area in the flash memory, and using the storage area in the flash memory as the target storage area, the second priority being 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 a storage area in the disk, and the storage area in the disk is used as the target storage area. The third priority is lower than the second priority.
5. 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, swapping out the first memory page to a target storage area corresponding to the target memory group where the first memory page is located includes: If it is determined that the first memory page corresponding to the first process of the target application needs to be swapped out, a swap area corresponding to the target memory group is determined as the target storage area according to a first mapping relationship, wherein the first mapping relationship includes a mapping relationship between each memory group in the plurality of memory groups and the swap area, 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; Swap out the first memory page to the target storage area.
6. The method according to claim 5, characterized in that The multiple memory groups include a first memory group and a second memory group, the process corresponding to the memory pages in the first memory group is a target process for interface refresh, and the process corresponding to the memory pages in the second memory group is other processes in the process of the target application except 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, determining the swap area corresponding to the target memory group as the target storage area according to the first mapping relationship, includes: If it is determined that a first memory page corresponding to the first process of the target application needs to be swapped out, determining a memory group where the first memory page is located as a target memory group; If the target memory group is the first memory group, determining, according to the first mapping relationship, that the swap area corresponding to the target memory group is a compressed memory area, and using the compressed memory area as the target storage area; If the target memory group is the second memory group, it is determined according to the first mapping relationship that the swap area corresponding to the target memory group is a storage area in the flash memory, and the storage area in the flash memory is used as the target storage area.
7. The method according to claim 1, characterized in that The target process information includes: at least one of process function information, process memory consumption information and process priority.
8. The method according to any one of claims 1 to 7, characterized in that: The swap area to which the memory pages in the memory of the electronic device are swapped out includes a compressed memory area. Before grouping the memory pages corresponding to different processes of the target application program currently running to obtain a plurality of memory groups, the method further includes: Obtaining the remaining storage capacity of the compressed memory area; If the remaining storage capacity is less than the first threshold, the step of grouping memory pages corresponding to different processes of the target application currently running on the electronic device to obtain multiple memory groups is executed.
9. The method according to claim 8, characterized in that After obtaining the remaining storage capacity of the compressed memory area, the method further includes: If the remaining storage amount is greater than or equal to a first threshold, and it is determined that a second memory page needs to be swapped out, the second memory page is swapped out to the compressed memory area, and the second memory page is any memory page in the memory of the electronic device.
10. A memory management device, characterized in that: Applied to electronic equipment, the device comprises: a memory grouping module and a memory exchange module, wherein: The memory grouping module is used to group memory pages corresponding to different processes of the target application currently running on the electronic device to obtain multiple memory groups, and the target process information of the processes corresponding to the memory pages in the same memory group are matched; The memory exchange module is used for swapping out a first memory page to a target storage area corresponding to a 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.
11. An electronic device, characterized in that: include: one or more processors; Memory; One or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by a processor to execute the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Space use method and device
CN111522659A
System and method for realizing swap-out and swap-in of memory
CN113296932A
Virtual memory management method and electronic equipment
CN113722087A
Memory management method and device, equipment and storage medium
CN114253873A
Application program processing method and device and storage medium
CN115344357A