Memory management method and device, electronic equipment and storage medium

By obtaining the attribute information of the target process and determining its page replacement strategy, the problem of lack of flexibility in memory recycling in the existing technology is solved, and the system performance is optimized, and the performance degradation of the memory pages of important processes is avoided.

CN119536962APending Publication Date: 2025-02-28GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311092840.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-28
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In the prior art, the memory recycling of applications lacks flexibility, and all processes are treated equally during memory page replacement, which may lead to the memory pages of important processes being replaced, affecting system performance.

Method used

By obtaining the attribute information of the target process, determine its corresponding page replacement policy, and replace the memory page of the target process based on the policy.

Benefits of technology

By implementing different page replacement strategies for different processes, the system performance can be optimized to avoid performance degradation caused by the replacement of memory pages of important processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536962A_ABST
    Figure CN119536962A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a memory management method and device, electronic equipment and a storage medium. The method comprises the following steps: acquiring attribute information of a target process; based on the attribute information, determining a page replacement strategy corresponding to the target process; and on the basis of the page replacement strategy, replacing a memory page corresponding to the target process. Through the method, different page replacement strategies are implemented for different processes, the system performance can be optimized, and performance reduction caused by replacement of memory pages of important processes is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] The development and popularization of electronic devices have brought great convenience to our lives and work. In daily life, there are more and more scenarios where electronic devices need to be used. However, the memory space in electronic devices is limited. When the memory space is insufficient, the electronic device will freeze, which will affect the normal use of users and greatly reduce the user experience.

[0003] To ensure that there is enough memory available in electronic devices, the systems of electronic devices usually recycle memory under certain circumstances. However, in the related art, memory recycling for applications lacks certain flexibility, and all processes of an application are treated equally when performing memory page replacement, which may cause the memory pages of some important processes to be replaced, thereby affecting the performance of the system. Summary of the invention

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

[0005] In a first aspect, an embodiment of the present application provides a memory management method, the method comprising: obtaining attribute information of a target process; determining a page replacement strategy corresponding to the target process based on the attribute information; and replacing memory pages corresponding to the target process based on the page replacement strategy.

[0006] In a second aspect, an embodiment of the present application provides a memory management device, which includes: an information acquisition unit, used to obtain attribute information of a target process; a policy determination unit, used to determine a page replacement policy corresponding to the target process based on the attribute information; and a replacement unit, used to replace memory pages corresponding to the target process based on the page replacement policy.

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

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

[0009] The embodiments of the present application provide a memory management method, device, electronic device and storage medium. First, the attribute information of the target process is obtained, and based on the attribute information, the page replacement strategy corresponding to the target process is determined, and then the memory page corresponding to the target process is replaced based on the page replacement strategy. Through the above method, different page replacement strategies are implemented for different processes, which can optimize system performance and avoid performance degradation caused by the replacement of memory pages of important processes. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] 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.

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

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

[0013] Figure 3 A flowchart of a memory management method proposed in one embodiment of the present application is shown;

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

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

[0016] Figure 6 A flowchart of a memory management method proposed in another embodiment of the present application is shown;

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

[0018] Figure 8 A structural block diagram of an electronic device used to execute a memory management method according to an embodiment of the present application is shown in real time of the present application;

[0019] Fig. 9 A storage unit in real time of the present application for storing or carrying program codes for implementing the memory management method according to an embodiment of the present application is shown. DETAILED DESCRIPTION

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

[0021] Memory management is one of the core technologies of the system, and plays a key role in improving the user experience and stability of the system. When the memory is tight, the system will experience a series of problems such as freezing, running errors, and crashes.

[0022] The inventor discovered in the study of related memory management methods that in Android or other Linux-based systems, Swap is a traditional memory management strategy that allows the operating system to "swap out" data in the memory to the hard disk (or other storage medium) to free up memory space for other processes to use. When the "swapped out" data is needed again, the operating system will "swap it back (Swap in)" from the hard disk (or other storage medium) to the memory. In the process of replacing data in the above manner, all processes are treated equally when performing memory replacement, which may cause the memory pages of some important processes to be replaced, thereby affecting the performance of the system.

[0023] Therefore, the inventors proposed a memory management method, device, electronic device, and readable storage medium in the present application. First, the attribute information of the target process is obtained, and based on the attribute information, the page replacement strategy corresponding to the target process is determined, and then the memory page corresponding to the target process is replaced based on the page replacement strategy. Through the above method, different page replacement strategies are implemented for different processes, which can optimize system performance and avoid performance degradation caused by the replacement of memory pages of important processes.

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

[0025] In the embodiment of the present application, the memory management method provided can be executed by an electronic device. In this way, all steps in the memory management method provided by the embodiment of the present application can be executed by the electronic device. For example, Figure 1 As shown, the attribute information of the target process is obtained through the processor of the electronic device 100; based on the attribute information, the page replacement strategy corresponding to the target process is determined; based on the page replacement strategy, the memory page corresponding to the target process is replaced.

[0026] Furthermore, the memory management method provided in the embodiment of the present application can also be executed by a server (cloud). Correspondingly, in this mode of execution by the server, the server can execute to obtain the attribute information of the target process; based on the attribute information, determine the page replacement strategy corresponding to the target process; based on the page replacement strategy, replace the memory page corresponding to the target process.

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

[0028] For example, Figure 2 As shown, the electronic device 100 can execute the memory management method including: obtaining the attribute information of the target process, and then the server 200 determines the page replacement strategy corresponding to the target process based on the attribute information; based on the page replacement strategy, replaces the memory page corresponding to the target process.

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

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

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

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

[0033] Step S110: Obtain attribute information of the target process.

[0034] In the embodiment of the present application, the target process is a process that is determined to need to perform memory page replacement. The target process may be one or more. In the case where there are multiple target processes, the multiple target processes may be multiple processes belonging to the same application or multiple processes belonging to different applications, which is not specifically limited here.

[0035] The attribute information of the target process is information used to characterize the operation characteristics and implementation functions of the target process. For example, the attribute information of the target process may include user visibility and functions, wherein whether the process has user visibility can be understood as whether the process is within the user visible range. When the target process is within the user visible range, it can be determined that the target process has user visibility.

[0036] In the embodiment of the present application, each application corresponds to multiple processes, and the multiple processes are used to implement different functions of the application. For each process, an attribute field can be added to store the attribute information corresponding to the process, and then when the attribute information of the target process needs to be obtained, the attribute information corresponding to the target process can be obtained from the attribute field.

[0037] Optionally, in the embodiment of the present application, the target process may be determined in a variety of ways.

[0038] As a method, in response to a memory recycling trigger event, a non-running process corresponding to a currently running application can be obtained, and the non-running process can be used as a target process. The memory recycling trigger event is generated when memory recycling is triggered. Optionally, memory recycling can be triggered during the use of memory or periodically. For example, during the use of memory, if the currently applied memory is greater than the remaining memory, memory recycling can be triggered.

[0039] Specifically, when an application is in the running state, not all processes corresponding to the application are running. Only when a function of the application is to be used, the process responsible for implementing the function may be in the running state. Therefore, when a memory recycling trigger event occurs, in response to the memory recycling trigger event, a process that is not in the running state among all processes corresponding to the currently running application is determined as a target process.

[0040] As another way, the target process can be determined according to the importance of the process to the application, and the process with lower or lowest importance to the application can be determined as the target process. The importance of the process to the application can be determined by the function implemented by the process, or the importance of the process to the application can be determined by the memory size occupied by the process.

[0041] When the importance of a process to an application can be determined by the functions implemented by the process, if the functions implemented by the process are related to user interaction, then it can be determined that the importance of the process to the application is higher; conversely, if the functions implemented by the process are unrelated to user interaction, then it can be determined that the importance of the process to the application is lower.

[0042] When the importance of a process to an application can be determined by the size of memory occupied by the process, the larger the size of memory occupied by the process, the more important the process to the application is; conversely, the smaller the size of memory occupied by the process, the less important the process to the application is.

[0043] Optionally, the target process may be determined by other methods, which will not be described in detail here.

[0044] Step S120: Based on the attribute information, determine the page replacement strategy corresponding to the target process.

[0045] In an embodiment of the present application, a page replacement strategy refers to a pre-set strategy for replacing memory pages of a target process. Optionally, the page replacement strategy may include not replacing memory pages to be replaced, or replacing memory pages to be replaced according to a specified page replacement algorithm. When the page replacement strategy is a strategy for replacing memory pages to be replaced according to a specified page replacement algorithm, the page replacement strategy can be understood as a memory page placement algorithm or a memory recycling algorithm, which is not specifically limited here.

[0046] Among them, the page replacement strategy can be an algorithm with different replacement speeds or recycling speeds. For example, the page replacement strategy can include one of the first-in-first-out (FIFO) algorithm, the least recently used (Least Recently Used, LRU) algorithm, the clock algorithm, the second chance (Second Chance) algorithm, the least frequently used (LFU) algorithm, the least recently used K times (Least Recently Used K, LRU-K) algorithm and the best replacement algorithm. Of course, the page replacement strategy can also be other replacement algorithms, which are not specifically limited here.

[0047] Among them, the first-in-first-out algorithm: replace pages according to the time sequence of the pages entering the memory, and the page that enters the memory first is replaced first. That is, the page that has been in the memory the longest is selected for replacement.

[0048] Least Recently Used Algorithm: Replace pages based on how recently they were used. The least recently used pages are replaced first. The system sets an access field on each page to record the time T since the page was last accessed. When a page is to be replaced, the page with the largest T is selected.

[0049] Clock algorithm: Arrange the physical blocks into a ring and scan them cyclically through a pointer. If the page pointed to by the pointer can be replaced and is not used, the page is selected for replacement. Otherwise, its access bit is cleared and the scan continues.

[0050] Second chance algorithm: Based on the clock algorithm, the concept of access bit is added. If the page is accessed, the access bit is set to 1. If the access bit is 0, the page is selected for replacement and the scan continues.

[0051] Least frequently used algorithm: Replace pages based on how frequently they are used, with the pages with the lowest frequency of use being replaced first.

[0052] Least Recently Used K algorithm: It is an improvement of the LRU algorithm. It not only considers the most recent use of the page, but also the use of the previous K times. Compared with the LRU algorithm, the LRU-K algorithm needs to maintain an additional queue to record the history of all cached pages being accessed. Only when the page is accessed K times will it be put into the cache. When a page needs to be replaced, the LRU-K algorithm will choose to replace the page whose Kth access time is the longest from the current time.

[0053] Optimal page replacement algorithm: When a page fault occurs, the last page to be accessed in memory is selected for replacement. The only problem with this algorithm is that it cannot be implemented. When a page fault occurs, the operating system cannot know when each page will be accessed next time. Although this algorithm cannot be implemented, the optimal page replacement algorithm can be used to measure and compare the performance of implementable algorithms and is a good evaluation algorithm.

[0054] As a way, different target processes correspond to different page replacement strategies. In the embodiment of the present application, the corresponding relationship between the attribute information and the page replacement strategy can be pre-set, so that after the attribute information of the target process is obtained, the corresponding page replacement strategy can be found according to the attribute information of the target process.

[0055] Optionally, one type of attribute information may correspond to at least one page replacement strategy. Wherein, when one type of attribute information corresponds to multiple page replacement strategies, any one of the multiple page replacement strategies may be used as the page replacement strategy corresponding to the target process.

[0056] Furthermore, the replacement speeds of multiple page replacement strategies may be the same or different. When the replacement speeds of multiple page replacement strategies are the same, any one of the multiple page replacement strategies may be selected as the page replacement strategy corresponding to the target process; when the replacement speeds of multiple page replacement strategies are different, a page replacement strategy with a corresponding replacement speed may be selected from the multiple page replacement strategies as the page replacement strategy for the target process. The corresponding replacement speed may be determined according to the number of memory pages that need to be replaced. The more memory pages that need to be replaced, the faster the replacement speed of the selected page replacement strategy. Conversely, the fewer memory pages that need to be replaced, the slower the replacement speed of the selected page replacement strategy.

[0057] Step S130: Based on the page replacement strategy, replace the memory page corresponding to the target process.

[0058] In an embodiment of the present application, after the corresponding page replacement strategy is obtained, the memory page of the target process can be replaced using the obtained page replacement strategy.

[0059] In response to the page replacement instruction, the memory page corresponding to the target process is replaced based on the page replacement policy. The page replacement instruction can be triggered in a variety of ways.

[0060] As one of the ways, the page replacement instruction can be triggered when it is detected that the current free memory is lower than the preset memory. Among them, the preset memory is a pre-set memory size that indicates insufficient free memory. In an embodiment of the present application, whenever a process is started, or a new memory page is generated and needs to be stored in the memory, it triggers the acquisition of the current free memory once. If the current free memory is lower than the preset memory, it indicates that the current memory is insufficient, and the memory pages already stored in the memory need to be replaced with other storage media to make room for the new page. Among them, the new page can be generated for the process that has just been started, or it can be generated for other already running processes, which is not specifically limited here.

[0061] Optionally, it is also possible to detect in real time whether the current free memory is lower than the preset memory, and trigger the page replacement instruction when it is detected that the current free memory is lower than the preset memory. Alternatively, it is also possible to periodically detect the free memory, and trigger the page replacement instruction when it is detected that the current free memory is lower than the preset memory.

[0062] As another method, the page replacement instruction can also be triggered periodically. Specifically, the page replacement instruction is pre-set, and the triggering time period of the page replacement instruction is set. Whenever the triggering time of the page replacement instruction is reached, the page replacement instruction is triggered.

[0063] As another way, the page replacement instruction can also be triggered when the startup of a designated application is detected. The designated application can be a pre-set application for triggering the page replacement instruction. In the embodiment of the present application, the designated application can be an application that uses a large memory at runtime, such as a game application. Since the designated application needs to use a large memory at runtime, in order to reserve enough memory for the designated application in advance, the page replacement instruction can be triggered when the startup of the designated application is detected, so as to replace the memory page corresponding to the target process based on the page replacement instruction and the page replacement policy.

[0064] As one approach, a memory page to be replaced corresponding to the target process is obtained; and based on the page replacement strategy, the memory page to be replaced is replaced.

[0065] The memory pages to be replaced are memory pages corresponding to the determined target process that need to be replaced. Optionally, the memory pages to be replaced may be all memory pages corresponding to the target process, or may be part of all memory pages corresponding to the target process.

[0066] In the case that the memory pages to be replaced are some of all memory pages corresponding to the target process, the memory pages to be replaced corresponding to the target process may be determined in different ways.

[0067] As a method, different page replacement strategies determine different memory pages to be replaced. Therefore, after obtaining the page replacement strategy corresponding to the target process, the memory page to be replaced corresponding to the target process can be determined based on the corresponding page replacement strategy.

[0068] Before determining the to-be-replaced memory pages corresponding to the target process based on the page replacement policy corresponding to the target process, the number of the to-be-replaced memory pages may be determined based on a variety of methods.

[0069] As one of the ways, before determining the memory pages to be replaced corresponding to the target process based on the page replacement policy corresponding to the target process, the number of memory pages to be replaced can be determined based on the memory size used when each target process is running. The number of memory pages with the same memory size as the memory size used when the target process is running among all the memory pages corresponding to the target process stored in the memory is taken as the number of memory pages to be replaced.

[0070] As another method, before determining the memory pages to be replaced corresponding to the target process based on the page replacement policy corresponding to the target process, the number of memory pages to be replaced can be determined based on the storage space size of the storage medium corresponding to each target process. The number of memory pages with the same storage space size as the corresponding storage medium among all memory pages corresponding to the target process stored in the memory is taken as the number of memory pages to be replaced.

[0071] Then, based on the page replacement policy corresponding to each target process, determine which memory pages are to be replaced.

[0072] As another method, the memory page to be replaced can be determined based on the access parameters of all memory pages corresponding to the target process. The access parameters of the memory page may include the access frequency, access duration, access timestamp, etc. corresponding to each memory page. The access frequency represents the number of times the memory page is accessed within a preset time; the access duration represents the length of time each time the memory page is accessed; and the access timestamp can represent the start time or end time of the last access to the memory page.

[0073] When the access parameter is the access frequency, the multiple memory pages may be screened based on the access frequencies corresponding to the multiple memory pages, and a memory page whose corresponding access frequency meets a specified condition is selected from the multiple memory pages as the memory page to be replaced.

[0074] Specifically, when the access parameter is the access frequency, when screening multiple memory pages, the memory pages whose corresponding access frequencies are lower than the preset access frequency among the multiple memory pages can be used as the memory pages to be replaced. The preset access frequency is a preset frequency that indicates that the memory page is rarely accessed within a preset time period. The preset time period can be any set time period, which is not specifically limited here.

[0075] When the access frequency corresponding to a memory page is lower than the preset access frequency, it can be seen that the memory page will not be accessed frequently. It can be seen from the side that the memory page is an unimportant memory page. Therefore, you can choose to replace the memory page first, and then replace it back to memory when you need to access the memory page later.

[0076] When the access parameter is an access timestamp, the multiple memory pages may be screened based on the access timestamps corresponding to the multiple memory pages, and a memory page whose corresponding timestamp meets a specified condition may be selected from the multiple memory pages as the memory page to be replaced.

[0077] Specifically, when the access parameter is an access timestamp, when screening multiple memory pages, the memory page whose corresponding access timestamp is farthest from the current time among the multiple memory pages can be used as the memory page to be replaced. At this time, the access timestamp can refer to the end time of the last access to the memory page.

[0078] Similarly, when the access timestamp corresponding to a memory page is the timestamp farthest from the current time, it can be seen that the memory page is unlikely to be accessed again in a short period of time. Therefore, you can choose to replace the memory page first, and then swap it back into memory when you need to access the memory page later.

[0079] When the access parameter is the access duration, the multiple memory pages may be screened based on the access durations corresponding to the multiple memory pages, and memory pages whose corresponding durations meet the specified conditions may be selected from the multiple memory pages as memory pages to be replaced.

[0080] Specifically, when the access parameter is the access duration, when screening multiple memory pages, the memory pages whose corresponding access duration is less than the preset duration can be used as the memory pages to be replaced. The preset duration can be any pre-set duration.

[0081] The present application provides a memory management method, which first obtains the attribute information of the target process, determines the page replacement strategy corresponding to the target process based on the attribute information, and then replaces the memory page corresponding to the target process based on the page replacement strategy. By implementing different page replacement strategies for different processes through the above method, system performance can be optimized to avoid performance degradation caused by the replacement of memory pages of important processes.

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

[0083] Step S210: Obtain attribute information of the target process.

[0084] Step S220: Based on the attribute information, determine the memory group corresponding to the target process.

[0085] In an embodiment of the present application, a memory group refers to a group obtained by grouping different processes, and each memory group includes at least one process. Among them, the memory group is implemented based on the memory control group (memcg) mechanism in Linux. The memory resource controller of the control group (cgroupa) is used to control the memory usage of a group of processes, and the control group that enables the memory resource controller is referred to as the memory control group (memcg). That is, a memory group is a group of processes that enable the same memory resource controller.

[0086] As a method, the target processes can be dynamically grouped according to the attribute information of the target processes to obtain corresponding memory groups. The running state included in the attribute information of the target process can be changed in real time, so the same target process may belong to different memory groups at different times.

[0087] When determining the memory group corresponding to the target process based on the attribute information, the memory group corresponding to the target process may be determined based on one or more pieces of information in the attribute information.

[0088] In the case where the memory group corresponding to the target process is determined based on one item of the attribute information, the memory group corresponding to the target process may be determined based on the function of the application program that the target process is responsible for and included in the attribute information.

[0089] Specifically, target processes that are responsible for the same functions of the application program may be divided into the same memory group.

[0090] When determining the memory group corresponding to the target process based on multiple pieces of information in the attribute information, the memory group corresponding to the target process can be determined based on the function of the application that the target process is responsible for included in the attribute information and the running status of the target process.

[0091] Specifically, target processes that are responsible for the same application program functions and have the same running status may be divided into the same memory group.

[0092] Furthermore, when determining the memory group corresponding to the target process based on multiple pieces of information in the attribute information, the memory group corresponding to the target process can also be determined based on the function of the application for which the target process is responsible included in the attribute information, and the running status of the application.

[0093] Specifically, when the running state of the application is a specified state, target processes with the same functions as the responsible application can be divided into the same memory group.

[0094] Step S230: using the page replacement policy corresponding to the memory group as the page replacement policy corresponding to the target process, wherein different memory groups correspond to different page replacement policies.

[0095] In the embodiment of the present application, different memory groups correspond to different page replacement strategies. Specifically, the correspondence between the memory group and the page replacement strategy can be pre-set, and after the memory group corresponding to the target process is determined, the page replacement strategy corresponding to the memory group corresponding to the target process can be determined based on the correspondence between the memory group and the page replacement strategy.

[0096] Step S240: Acquire the target storage medium corresponding to the memory group, wherein different memory groups correspond to different storage media.

[0097] In the embodiment of the present application, the target storage medium is a storage medium determined to store the memory page to be replaced of the target process, wherein the target storage medium can be at least one of a swap area, a file system cache, a ZRAM, an external storage device, a flash memory, and a disk.

[0098] Swap area: Allocate a certain amount of space on the disk as an extension of the memory. When the memory is insufficient, you can swap infrequently used pages to the swap area to free up memory. When you need to access the swapped out pages, you can bring them back into the memory.

[0099] File system cache: Cache frequently used file system pages in memory to improve file system access speed. When memory is insufficient, infrequently used file system pages can be swapped to the swap area to free up memory.

[0100] ZRAM: A technology that creates compressed block devices in memory, which can use memory as a virtual disk. Its main role is to reduce memory pressure and improve system performance, especially on devices with limited memory capacity. When the system needs more memory, ZRAM can use the free memory space as a virtual disk to store unused pages, thus avoiding swapping these pages to disk. It uses a compression algorithm to compress pages into blocks in memory and store them in a dedicated memory cache. This compression technology can effectively reduce the page size to half or less of the original size, so that more pages can be stored in memory. When the system needs a page, it can take the compressed block from ZRAM and decompress it, and then put it into memory.

[0101] External storage devices: such as hard disks or solid-state drives. When memory is insufficient, infrequently used pages can be swapped to external storage devices to free up memory. However, compared with swapping to the swap area, swapping to external storage devices is slower and can easily lead to reduced system performance.

[0102] In an embodiment of the present application, the correspondence between the memory group and the storage medium can be pre-set, so that after determining the memory group corresponding to the target process, the corresponding storage medium can be further determined based on the memory group corresponding to the target process.

[0103] Step S250: Based on the page replacement strategy, the memory page corresponding to the target process is replaced into the target storage medium.

[0104] In the embodiments of the present application, it can be known from the foregoing content that the replacement speeds of different storage media may be different. Therefore, in order to adapt to the access frequencies of different target processes and improve the performance of the system, the memory pages to be replaced corresponding to different target processes can be replaced into different storage media.

[0105] Optionally, in an embodiment of the present application, the same target process may correspond to multiple storage media, and the memory pages to be replaced corresponding to the same target process may be replaced into different storage media. For example, after the memory pages to be replaced are determined, a part of the memory pages to be replaced may be replaced into a first storage medium, and the remaining part of the memory pages to be replaced may be replaced into a second storage medium. Among them, the first storage medium and the second storage medium are different storage media, and the replacement speeds corresponding to the first storage medium and the second storage medium are different. The replacement speed refers to the speed of storing the memory pages to be replaced into the corresponding storage medium, or calling the corresponding memory pages to be replaced from the corresponding storage medium.

[0106] How many storage media a target process specifically corresponds to can be determined based on the memory size occupied by the target process and whether the memory size used when the target process is running is consistent. Specifically, if the memory size occupied by the target process is consistent with the memory size used when the target process is running or the difference is not big, it can be determined that the storage medium corresponding to the target process is the same storage medium; if the memory size occupied by the target process is consistent with the memory size used when the target process is running and the difference is large, it can be determined that the storage medium corresponding to the target process is two, including a first storage medium and a second storage medium, and the replacement speed of the first storage medium is higher than the replacement speed of the second storage medium. Among them, the first storage medium is used to store the memory pages used when the target process is running, and the second storage medium is used to store the memory pages not used when the target process is running. Exemplarily, if the memory occupied by the target process A is 100Mb, and the target process only uses a small part of the memory during operation, such as 10Mb, in this case, the 10Mb memory page can be replaced to the first storage medium, and the 90Mb memory page can be replaced to the second storage medium.

[0107] Of course, the same storage medium can also store the to-be-replaced memory pages corresponding to different target processes. When the same storage medium is used to store the to-be-replaced memory pages corresponding to different target processes, a corresponding storage area can be pre-divided for each target process from the storage medium, and then when performing page replacement, the to-be-replaced memory page of the corresponding target process can be replaced into the corresponding storage area in the storage medium.

[0108] A memory management method provided by the present application performs memory grouping and page replacement on a target process according to the attribute information of the target process, which can improve the user experience. For example, it can reduce the delay in application startup and improve the response speed of the application.

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

[0110] Step S310: Obtain attribute information of the target process.

[0111] Step S320: Obtain attribute information corresponding to each of the multiple processes included in the target application.

[0112] In the embodiment of the present application, the target application is a determined application that needs to perform memory page replacement. A target application usually includes multiple processes, each of which may be responsible for different functions of the application. Under this premise, multiple processes of a single target application can be grouped.

[0113] Therefore, before grouping multiple processes corresponding to the target application, attribute information of each process may be obtained first.

[0114] Step S330: grouping the multiple processes based on the attribute information corresponding to each of the multiple processes to obtain multiple memory groups.

[0115] In an embodiment of the present application, after the attribute information corresponding to each of the multiple processes is obtained, the multiple processes can be grouped.

[0116] When a plurality of processes are grouped based on attribute information, the plurality of processes may be grouped based on one or more pieces of information in the attribute information.

[0117] In the case where a plurality of processes are grouped based on one item of the attribute information, the memory group corresponding to the process may be determined based on the function of the application program that the process is responsible for and included in the attribute information.

[0118] Specifically, target processes with the same application functions can be grouped into the same memory group. For example, processes related to user interaction can be grouped into one group (called a UI group), and processes unrelated to user interaction can be grouped into another group (called a service group).

[0119] In the case of grouping the plurality of processes based on a plurality of pieces of information in the attribute information, the plurality of processes may be grouped based on the functions of the application programs that the processes are responsible for and the user visibility of the processes included in the attribute information.

[0120] Specifically, processes that are responsible for the same application functions and have the same user visibility may be grouped into the same memory group.

[0121] Furthermore, when the multiple processes are grouped based on multiple items of information in the attribute information, the multiple processes can also be grouped based on the functions of the application programs that the processes are responsible for and the running status of the application programs included in the attribute information.

[0122] Specifically, when the running state of the application is a specified state, processes with the same functions of the application can be divided into the same memory group.

[0123] Step S340: Based on the attribute information of the target process, determine the memory group corresponding to the target process from the multiple memory groups.

[0124] Step S350: using the page replacement policy corresponding to the memory group as the page replacement policy corresponding to the target process, wherein different memory groups correspond to different page replacement policies.

[0125] In the embodiment of the present application, different page replacement strategies can be implemented for different memory groups. For example, some memory groups may not perform page replacement, while other memory groups may adopt the least recently used algorithm, and some memory groups may adopt the first-in-first-out algorithm.

[0126] Optionally, the replacement speeds of the page replacement strategies corresponding to different memory groups may be different or the same.

[0127] Similarly, when the application is in different running states, the replacement speed of the page replacement strategy corresponding to the same memory group may also be different. When the application is running in the foreground, the page replacement strategy of different memory groups can be relatively conservative; when the application is running in the background, the page replacement strategy of different memory groups can be relatively aggressive. Among them, a relatively conservative page replacement strategy means that the number of memory pages to be replaced is small, the replacement speed is slow, etc.; a relatively aggressive page replacement strategy means that the number of memory pages to be replaced is large, the replacement speed is fast, etc.

[0128] For example, application A has three processes A1, A2, and A3. The A1 process is responsible for interface rendering, and the A2 and A3 processes provide service functions. Therefore, A1 can be divided into a memory group, and A2 and A3 can be divided into a memory group. When application A runs in the foreground, A1's page replacement strategy is conservative, and pages are replaced into memory. The strategies of A2 and A3 are more conservative than A1, and pages are also replaced into memory. When application A runs in the background, A1's page replacement strategy becomes aggressive, and pages are replaced into memory. The page replacement strategies of A2 and A3 are more aggressive, and all pages will be replaced, with the target being flash memory.

[0129] Step S360: Acquire the target storage medium corresponding to the memory group, wherein different memory groups correspond to different storage media.

[0130] Step S370: Based on the page replacement strategy, the memory page corresponding to the target process is replaced into the target storage medium.

[0131] The present application provides a memory management method in which different memory groups may have different page replacement strategies and storage media, thereby fully utilizing system resources and ensuring user experience.

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

[0133] Step S410: Obtain attribute information of the target process.

[0134] Step S420: Obtain attribute information corresponding to each of the multiple processes included in the target application.

[0135] Step S430: Based on the attribute information corresponding to each of the multiple processes, determine whether the multiple processes are processes related to user interaction.

[0136] Step S440: Divide the processes related to the user interaction among the multiple processes into a first memory group, and divide the processes unrelated to the user interaction among the multiple processes into a second memory group.

[0137] Step S450: If it is determined that the target process belongs to the first memory group, the memory page to be replaced corresponding to the target process is replaced based on a first page replacement strategy, wherein the first page replacement strategy is a page replacement strategy corresponding to the first memory group.

[0138] Step S460: If it is determined that the target process belongs to the second memory group, the memory page to be replaced corresponding to the target process is replaced based on the second page replacement strategy, wherein the second page replacement strategy is the page replacement strategy corresponding to the second memory group, and the replacement efficiencies corresponding to the first page replacement strategy and the second page replacement strategy are different.

[0139] In the embodiment of the present application, the replacement efficiency of the first page replacement strategy is more conservative than that of the second page replacement strategy.

[0140] The present application provides a memory management method that implements different page replacement strategies for different processes, which can optimize system performance and avoid performance degradation caused by replacement of memory pages of important processes.

[0141] See also Figure 7 , a memory management device 500 provided in an embodiment of the present application runs on Figure 1 or Figure 2 The electronic device or server shown, the device 500 includes:

[0142] The information acquisition unit 510 is used to acquire attribute information of the target process.

[0143] The policy determination unit 520 is used to determine the page replacement policy corresponding to the target process based on the attribute information.

[0144] As a method, the policy determination unit 520 is specifically used to determine the memory group corresponding to the target process based on the attribute information; and use the page replacement policy corresponding to the memory group as the page replacement policy corresponding to the target process, wherein different memory groups correspond to different page replacement policies.

[0145] Furthermore, the policy determination unit 520 is specifically used to obtain attribute information corresponding to each of the multiple processes included in the target application; based on the attribute information corresponding to each of the multiple processes, the multiple processes are grouped to obtain multiple memory groups; based on the attribute information of the target process, the memory group corresponding to the target process is determined from the multiple memory groups.

[0146] Optionally, the policy determination unit 520 is also specifically used to determine whether the multiple processes are processes related to user interaction based on the attribute information corresponding to each of the multiple processes; divide the processes related to user interaction among the multiple processes into a first memory group; and divide the processes unrelated to user interaction among the multiple processes into a second memory group.

[0147] The replacement unit 530 is used to replace the memory page corresponding to the target process based on the page replacement strategy.

[0148] As a method, the replacement unit 530 is specifically used to obtain the target storage medium corresponding to the memory group, wherein different memory groups correspond to different storage media; based on the page replacement strategy, the memory page corresponding to the target process is replaced to the target storage medium.

[0149] As another embodiment, the replacement unit 530 is also specifically used to replace the memory page corresponding to the target process based on a first page replacement strategy if it is determined that the target process belongs to the first memory group, wherein the first page replacement strategy is the page replacement strategy corresponding to the first memory group; if it is determined that the target process belongs to the second memory group, replace the memory page corresponding to the target process based on a second page replacement strategy, wherein the second page replacement strategy is the page replacement strategy corresponding to the second memory group, and the replacement efficiencies corresponding to the first page replacement strategy and the second page replacement strategy are different.

[0150] Optionally, the replacement unit 530 is further configured to obtain a memory page to be replaced corresponding to the target process; and replace the memory page to be replaced based on the page replacement strategy.

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

[0152] The following will be combined Figure 8 An electronic device provided by the present application is described.

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

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

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

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

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

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

[0159] The present application provides a memory management method, device, electronic device and storage medium, which first obtains the attribute information of the target process, determines the page replacement strategy corresponding to the target process based on the attribute information, and then replaces the memory page corresponding to the target process based on the page replacement strategy. Through the above method, different page replacement strategies are implemented for different processes, which can optimize system performance and avoid performance degradation caused by the replacement of memory pages of important processes.

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

Claims

1. A memory management method, characterized in that: The method comprises: Get the property information of the target process; Based on the attribute information, determining a page replacement strategy corresponding to the target process; Based on the page replacement strategy, the memory page corresponding to the target process is replaced.

2. The method according to claim 1, characterized in that The determining, based on the attribute information, a page replacement strategy corresponding to the target process includes: Based on the attribute information, determining a memory group corresponding to the target process; The page replacement policy corresponding to the memory group is used as the page replacement policy corresponding to the target process, wherein different memory groups correspond to different page replacement policies.

3. The method according to claim 2, characterized in that The replacing the memory page corresponding to the target process based on the page replacement strategy includes: Obtaining a target storage medium corresponding to the memory group, wherein different memory groups correspond to different storage media; Based on the page replacement strategy, the memory page corresponding to the target process is replaced into the target storage medium.

4. The method according to claim 2, characterized in that: The determining, based on the attribute information, a memory group corresponding to the target process includes: Obtain the attribute information corresponding to each of the multiple processes contained in the target application; Based on the attribute information corresponding to each of the multiple processes, the multiple processes are grouped to obtain multiple memory groups; Based on the attribute information of the target process, a memory group corresponding to the target process is determined from the multiple memory groups.

5. The method according to claim 4, characterized in that The grouping of the multiple processes based on the attribute information corresponding to each of the multiple processes to obtain multiple memory groups includes: Based on the attribute information corresponding to each of the multiple processes, determining whether the multiple processes are processes related to user interaction; Dividing processes related to user interaction among the multiple processes into a first memory group; The processes that are not related to user interaction among the multiple processes are divided into a second memory group.

6. The method according to claim 5, characterized in that The replacing the memory page corresponding to the target process based on the page replacement strategy includes: If it is determined that the target process belongs to the first memory group, replace the memory page corresponding to the target process based on a first page replacement strategy, wherein the first page replacement strategy is a page replacement strategy corresponding to the first memory group; If it is determined that the target process belongs to the second memory group, the memory page corresponding to the target process is replaced based on the second page replacement strategy, wherein the second page replacement strategy is the page replacement strategy corresponding to the second memory group, and the replacement efficiencies corresponding to the first page replacement strategy and the second page replacement strategy are different.

7. The method according to claim 1, characterized in that The replacing the memory page corresponding to the target process based on the page replacement strategy includes: Obtaining the memory page to be replaced corresponding to the target process; Based on the page replacement strategy, the memory page to be replaced is replaced.

8. A memory management device, characterized in that: The device comprises: An information acquisition unit, used to acquire attribute information of a target process; A policy determination unit, configured to determine a page replacement policy corresponding to the target process based on the attribute information; A replacement unit is used to replace the memory page corresponding to the target process based on the page replacement strategy.

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

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