Memory management method and device, electronic equipment and storage medium

By judging based on the number of inactive pages in advance and performing memory swaps, the system efficiency reduction caused by the exchange when there is insufficient memory in the prior art is solved, and the advance release of memory and the improvement of system efficiency are achieved.

CN119597437APending Publication Date: 2025-03-11GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311163144.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-08
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

The prior art only performs memory swap when memory is insufficient, resulting in reduced system operation efficiency and increased system load.

Method used

By obtaining the number of inactive pages in the target memory group, if it is greater than the target threshold, the inactive pages will be swapped out to the target storage area in advance to achieve early memory release.

Benefits of technology

Free up memory in advance, improve system operation efficiency, avoid temporary emergency measures when memory is tight, and reduce system load.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597437A_ABST
    Figure CN119597437A_ABST
Patent Text Reader

Abstract

The invention discloses a memory management method and device, electronic equipment and a storage medium, and the memory management method comprises the steps: obtaining the number of inactive pages in a target memory group as a first number, the target memory group being any one of a plurality of memory groups, the plurality of memory groups are obtained by grouping memory pages in a memory according to a target grouping rule; if the first number is larger than a target threshold value, at least part of the inactive pages in the target memory group are swapped out to a target storage area. According to the method, memory release can be performed in advance, and the system operation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] With the rapid advancement of science and technology and living standards, electronic devices (such as smart phones, tablet computers, etc.) have become one of the commonly used electronic products in people's lives. In electronic devices, memory is one of the important components. It is a bridge for communication with the central processing unit (CPU). Since the capacity of memory is limited, it is usually necessary to manage the memory. In related technologies, memory swapping mechanisms are usually used to manage memory to increase available memory. However, in related technologies, memory swapping is usually performed only when memory is insufficient, which affects the system operation efficiency. Summary of the invention

[0003] The present application proposes a memory management method, device, electronic device and storage medium, which can realize early memory release and improve system operation efficiency.

[0004] In a first aspect, an embodiment of the present application provides a memory management method, the method comprising: obtaining the number of inactive pages in a target memory group as a first number, the target memory group being any one of a plurality of memory groups, the plurality of memory groups being obtained by grouping memory pages in the memory according to a target grouping rule; if the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area.

[0005] In a second aspect, an embodiment of the present application provides a memory management device, comprising: a quantity acquisition module and a memory swap-out module, wherein the quantity acquisition module is used to obtain the number of inactive pages in a target memory group as a first quantity, and the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule; the memory swap-out module is used to swap out at least part of the inactive pages in the target memory group to a target storage area if the first quantity is greater than a target threshold.

[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 obtains the number of inactive pages in the target memory group as the first number, the target memory group is any memory group in multiple memory groups, and the multiple memory groups are obtained by grouping the memory pages in the memory according to the target grouping rule. If the first number is greater than the target threshold, at least part of the inactive pages in the target memory group are swapped out to the target storage area. In this way, when the number of inactive pages in any memory group after the memory pages are grouped is greater than the target threshold, the memory pages are swapped out, so that the memory can be released in advance and the system operation efficiency is improved. 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 diagram of memory grouping provided in an 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 schematic flow chart of a memory management method according to another embodiment of the present application is shown.

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

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

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

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

[0018] Fig. 9 A block diagram of a memory management device according to an embodiment of the present application is shown.

[0019] Fig.10 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.

[0020] Fig.11 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

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

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

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

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

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

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

[0027] Page Replacement Algorithm: Swap management in Linux systems is mainly based on a page replacement algorithm called "Least Recently Used" (LRU). Simply put, the LRU algorithm records the last time each memory page was accessed. When a swap is needed, the system will choose to swap out the page that has not been accessed for the longest time, because such a page is least likely to be needed again in the near future.

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

[0029] Usually, when performing Swap Out, i.e. memory page interaction, electronic devices can use different memory replacement strategies. Currently, Linux memory management can use the LRU (Least Recently Used) algorithm, that is, the least recently used page replacement algorithm, to determine which pages should be swapped out of memory. The LRU algorithm is based on the idea that if a piece of data has not been accessed in the recent period of time, it is unlikely to be accessed in the future. Therefore, when the system memory is insufficient, Linux will select pages from the inactive list (Inactive List) for replacement.

[0030] Specifically, the memory management subsystem of the Linux kernel will perform memory page replacement in the following situations:

[0031] (1) When the system's physical memory is tight, the kernel's memory reclaimer (kswapd) will be awakened and begin to select pages in the inactive list for replacement and remove them from physical memory. The main goal of this process is to reclaim memory in order to provide space for new memory requests.

[0032] (2) When a process requests more memory and the system's currently available memory can no longer satisfy the request, the kernel will directly trigger page replacement. In this case, a process called direct memory reclaim will begin, which will try to reclaim pages in the inactive list to provide space for the current memory request as soon as possible.

[0033] This process is automatically performed by the Linux kernel, and in most cases, user-level applications cannot directly affect this process. Regardless of the method used to request memory, the system will only release an amount of memory equal to the memory size required by the applicant.

[0034] However, the inventors have discovered from research that when performing memory swap management, memory swap is usually performed when memory is insufficient. However, if memory swap is performed when memory is insufficient, the memory swap process will take time, which will affect the operation of processes that need to apply for memory, and thus affect the system operation efficiency. Moreover, when memory is tight, temporary emergency measures (i.e., swapping out memory pages) will consume system resources and thus increase the system load.

[0035] In response to the above problems, the inventors have proposed a memory management method, device, electronic device, and storage medium provided in the embodiments of the present application, which can realize swapping out memory pages when the number of inactive pages in any memory group after the memory pages are grouped is greater than the target threshold, thereby enabling memory release in advance and improving system operation efficiency. The specific memory management method will be described in detail in the subsequent embodiments.

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

[0037] 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 Fig. 9 The memory management device 800 and the electronic device 800 ( Fig.10). 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:

[0038] Step S110: obtaining the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule.

[0039] In an embodiment of the present application, when the electronic device manages the memory, the memory pages in the memory can be grouped according to the target grouping rules to obtain multiple memory groups, and the memory pages in each memory group can be managed separately. Among them, when the electronic device manages the memory pages in each memory group, it can obtain the number of inactive pages in the target memory group, and use the number of inactive pages as the first number, so as to determine whether the memory pages in the target memory group need to be swapped out at present according to the first number; inactive pages refer to memory pages located in the inactive linked list. Among them, memory pages can include anonymous pages, file pages, etc., which are not limited here; anonymous pages refer to pages without file background, such as heaps, stacks, data segments, etc.; file pages refer to pages with file backgrounds, which are caches generated in memory after the program reads the file. File pages are also called file caches.

[0040] In the operating system of an electronic device, the active linked list and the inactive linked list are two linked lists used to implement the page replacement algorithm in the operating system. The page replacement algorithm is a method for managing memory, which is used to determine which pages should be replaced out of the memory to leave space for other pages. The active linked list and the inactive linked list are the two linked lists used in this process; memory pages in the active linked list are considered "hot", that is, these memory pages have been recently accessed or may be accessed in the near future. These memory pages are considered active and will not be replaced out of the memory; memory pages in the inactive linked list are considered "cold", that is, these memory pages have not been accessed in the recent period of time, or are unlikely to be accessed in the future. These memory pages are considered inactive and may be replaced out of the memory.

[0041] In some embodiments, when obtaining the number of inactive pages in a target memory group, the electronic device can search for memory pages belonging to the target memory group from an inactive linked list currently maintained by the operating system, and determine the number of memory pages found, and use the number as the number of inactive pages in the target memory group.

[0042] In some implementations, the electronic device groups memory pages in the memory according to a target grouping rule, which may be grouped according to memory pages of different applications, memory pages of different processes, or memory pages of different system services. Optionally, the memcg grouping mechanism in the Linux system may be used as a carrier for implementing the memory group.

[0043] In a possible implementation, the electronic device may group memory pages according to different applications. The electronic device may determine the memory page corresponding to each currently running application, establish a memory group corresponding to each application, and divide the memory page corresponding to each application into the memory group corresponding to each application. When determining the memory page corresponding to each application, all processes belonging to the application may be determined based on the UID of each application, and the memory pages corresponding to all processes of the application may be used as the memory page corresponding to the application.

[0044] For example, see Figure 2 , the currently running applications include application 1, application 2 and application 3. Memory group 1 can be established for application 1, and the memory pages corresponding to application 1 (that is, the memory pages corresponding to process 1, process 2, process 3 and process 4) can be divided into memory group 1. Memory group 2 can be established for application 2, and the memory pages corresponding to application 2 (that is, the memory pages corresponding to process 5 and process 6) can be divided into memory group 2. Memory group 3 can be established for application 3, and the memory pages corresponding to application 3 (that is, the memory pages corresponding to process 7, process 8 and process 9) can be divided into memory group 3.

[0045] In a possible implementation, the electronic device may be grouped according to the memory pages of different processes. In the operating system of the electronic device, the applications and system services running therein may create different processes, which may occupy memory. For each process, a corresponding memory group may be created, and the memory pages corresponding to each process may be divided into its corresponding memory group. For each process, the memory pages corresponding to all threads of each process may be determined, and the determined memory pages may be divided into its corresponding memory group.

[0046] In one possible implementation, electronic devices can be grouped according to the memory pages of different system services. System services refer to programs, routines or processes that perform specified system functions to support other programs, especially underlying programs. For example, system services include camera services, multimedia services, Bluetooth communication services, mobile network communication services, application lifecycle management services, etc. There is a fundamental difference between system services and ordinary applications. System services can run without user login and when the user has logged out, while the application will be terminated when the user has not logged out. Electronic devices can be grouped according to the memory pages of different system services, and a memory group corresponding to each system service can be created for each running system service, and then the memory page corresponding to each system service is divided into the created memory group.

[0047] Optionally, the electronic device can query the process created by each of the above system services at runtime, obtain the process of each system service, and then determine the memory page corresponding to the process of each system service as the memory page corresponding to each system service, and then divide the memory page corresponding to each system service into the corresponding memory group.

[0048] Optionally, considering that some processes may belong to multiple system services, that is, some system services may share some processes during operation, for example, system service A and system service B share process 1, and process 1 belongs to both system service A and system service B. Then, when dividing the memory pages of these system services, it is impossible to determine the memory group to which the memory pages corresponding to the shared processes belong. Therefore, after determining the process of each system service, the first process belonging to multiple system services can be determined based on the process of each system service, and then the first process can be filtered out from the process of each system service to obtain the second process of each system service (that is, the process remaining after filtering out the first process from the process of each system service), and then the memory page corresponding to the second process of each system service is determined as the memory page corresponding to each system service.

[0049] Of course, in the embodiment of the present application, the specific grouping rules for grouping memory pages in the memory may not be limited, and the grouping rules for memory pages may be dynamically adjusted according to different services, user behaviors and other factors.

[0050] In some embodiments, the electronic device may group memory pages in the memory if a grouping condition is met, and the grouping condition may correspond to the target grouping rule adopted for the grouping. For example, if the electronic device is grouped according to the memory pages of different applications, the memory pages in the memory may be grouped when at least two applications are running in the electronic device; for another example, if the electronic device is grouped according to the memory pages of different system services, the memory pages in the memory may be grouped when at least two system services are running in the electronic device; for another example, if the electronic device is grouped according to the memory pages of different processes, the memory pages in the memory may be grouped when a preset number of processes are running in the electronic device. Of course, the specific grouping conditions may not be limited.

[0051] In some embodiments, after each update of the active linked list and the inactive linked list, the step of obtaining the number of inactive pages in the target memory group as the first number can be executed, that is, the memory management method provided in the embodiment of the present application is executed; or the step of obtaining the number of inactive pages in the target memory group as the first number can be executed at each target time interval, that is, the memory management method provided in the embodiment of the present application is executed.

[0052] Step S120: If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area.

[0053] In an embodiment of the present application, after the electronic device obtains the number of inactive pages in the target memory group (i.e., the first number), it can compare the first number with the target threshold; if, according to the comparison result, it is determined that the first number is greater than the target threshold, it means that the number of inactive pages in the target memory group is too large, and there are more memory pages that may be replaced in the target memory group. Therefore, when memory exchange is performed under insufficient memory conditions, the possibility of memory pages in the target memory group being swapped out is also greater, so the memory pages in the target memory group can be memory exchanged at present, that is, at least part of the inactive pages in the target memory group are swapped out to the target storage area; if, according to the comparison result, it is determined that the first number is not greater than the target threshold (i.e., less than or equal to the target threshold), the memory pages in the target memory group may not be memory exchanged. Among them, the target threshold can be a predetermined threshold value for triggering the swapping out of inactive pages in the memory group, and its specific value can be not limited; the target memory area can be a compressed memory area, a flash memory, or an area in a disk. Therefore, when the number of inactive pages in any memory group is greater than the target threshold, the memory pages can be swapped, that is, memory is released, so that there is no need to release memory only when the memory is insufficient, thereby achieving early release of memory and improving the operating efficiency of the operating system.

[0054] In some embodiments, the electronic device may swap out a portion of the inactive pages in the target memory group to the target storage area at one time, for example, swap out half of the inactive pages in the target memory group to the target storage area; the electronic device may swap out the inactive pages in the target memory group to the target storage area at one time; the electronic device may also swap out a portion of the inactive pages in the target memory group to the target storage area multiple times. Of course, the specific manner in which the electronic device swaps out the inactive pages in the target memory group to the target storage area may not be limited.

[0055] In the embodiment of the present application, the electronic device can determine the number of inactive pages in each memory group after grouping the memory pages in the memory, and swap out at least part of the inactive pages in the memory group to the target storage area when the determined number is greater than the target threshold. In other words, different memory groups can be used as target memory groups in turn, and the process of step S110 and step S220 can be performed.

[0056] The memory management method provided in the embodiment of the present application can realize grouping of memory pages, and when the number of inactive pages in any memory group is greater than a target threshold, the memory pages can be swapped out, thereby releasing memory in advance, improving system operating efficiency, avoiding temporary emergency measures when memory is tight, and reducing system load.

[0057] 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:

[0058] Step S210: obtaining the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule.

[0059] In the embodiment of the present application, step S210 can refer to the contents of other embodiments and will not be repeated here.

[0060] Step S220: If the first number is greater than a target threshold, the inactive pages in the target memory group are swapped out in batches to a target storage area.

[0061] In an embodiment of the present application, after the electronic device obtains the number of inactive pages in the target memory group (i.e., the first number), if it is determined that the first number is greater than the target threshold, when performing memory exchange on the inactive pages in the target memory group, the inactive pages in the target memory group can be swapped out in batches to the target storage area, that is, the inactive pages in the target memory group can be swapped out to the target storage area in batches, thereby avoiding system pressure caused by releasing a large number of pages at one time.

[0062] In some embodiments, when a first number of inactive pages in a target memory group is greater than a target threshold, when the inactive pages in the target memory group are swapped out to a target storage area in batches, the inactive pages in the target memory group can be swapped out to the target storage area in multiple times, and the number of inactive pages swapped out to the target storage area each time is determined by the first number.

[0063] In a possible implementation, the number of inactive pages swapped out to the target storage area each time may be positively correlated with the first number, that is, the larger the number of inactive pages in the target memory group, the more inactive pages are swapped out to the target storage area each time. Among them, the number of inactive pages swapped out to the target storage area each time may be linearly related to the first number, or nonlinearly related, and the mapping relationship between the number of inactive pages swapped out to the target storage area each time and the first number may not be limited, and it is only necessary to ensure that the number of inactive pages swapped out to the target storage area each time can be positively correlated with the first number. It can be understood that the larger the number of inactive pages in the target memory group, the larger the number of memory pages that can be swapped out. Therefore, the larger the number of inactive pages in the target memory group, the larger the number of inactive pages swapped out each time can also be, so as to reduce the number of memory swaps.

[0064] In some embodiments, when the inactive pages in the target memory group are swapped out in batches to the target storage area, the memory swapping of the inactive pages in the target memory group may be stopped when the number of inactive pages in the target memory group is reduced to a set number.

[0065] In a possible implementation, the set number can be 0, that is, when all inactive pages in the target memory group are swapped out, the memory swapping of inactive pages in the target memory group is stopped. It can be understood that since the number of inactive pages in the target memory group is greater than the target threshold, it means that there are too many inactive pages in the target memory group, so the inactive pages in the target memory group are less likely to be currently accessed, so all inactive pages in the target memory group can be swapped out to the target storage area by batch swapping out inactive pages.

[0066] In one possible implementation, the set number may be the product of the first number and a set ratio, and the set ratio may be 0.2, 0.3, 0.4, etc. That is, when the number of inactive pages in the target memory group is reduced to a certain level, the memory swapping of inactive pages in the target memory group may be stopped to avoid swapping out too many memory pages and affecting operating efficiency.

[0067] In some embodiments, when the inactive pages in the target memory group are swapped out in batches to the target storage area, the inactive pages in the target memory group can be sorted according to the order in which the inactive pages in the target memory group enter the inactive linked list from earliest to latest, and then the inactive pages in the target memory group can be swapped out in batches to the target storage area according to the sorting result. Optionally, the inactive pages can be divided into multiple batches according to the sorting result, and the inactive pages in the batches that are swapped out earlier enter the inactive linked list earlier. In this way, when the inactive pages in the target memory group are swapped out in batches to the target storage area, the memory pages that have not been accessed for a longer time can be swapped out from the memory.

[0068] The memory management method provided in the embodiment of the present application can realize that after the memory pages are grouped, when the number of inactive pages in any memory group is greater than the target threshold, the memory pages will be swapped out, thereby enabling memory release in advance, improving system operating efficiency, and avoiding temporary emergency measures when memory is tight, thereby reducing system load; in addition, when swapping out inactive pages in a memory group, they are swapped out in batches, thereby avoiding system pressure caused by releasing a large number of pages at one time.

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

[0070] Step S310: obtaining the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule.

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

[0072] Step S320: If the first number is greater than the target threshold and the priority corresponding to the target memory group is the first priority, a second number of inactive pages in the target memory group is swapped out to the target storage area each time, and the second number is determined by the product of the first number and the first ratio.

[0073] Step S330: If the first number is greater than the target threshold and the priority corresponding to the target memory group is the second priority, a third number of inactive pages in the target memory group are swapped out to the target storage area each time, and the third number is determined by the product of the first number and the second ratio. The first priority is higher than the second priority, and the first ratio is smaller than the second ratio.

[0074] In an embodiment of the present application, for multiple memory groups obtained after grouping memory pages in the memory according to the target grouping rule, each memory group may correspond to a priority. The priority corresponding to the memory group can be divided according to at least one of the importance of the running subject to which the memory pages in the memory group belong and the demand for memory usage. The running subject may be an application, a system service, the importance of the process, etc. Among them, if the memory group is obtained by grouping the memory pages of different applications, the running subject may be an application; if the memory group is obtained by grouping the memory pages of different system services, the running subject may be a system service; if the memory group is obtained by grouping the memory pages of different processes, the running subject may be a process.

[0075] The priorities corresponding to the memory groups may include a first priority and a second priority, and the first priority is higher than the second priority. When the priorities of the memory groups are divided according to the demand for memory usage, the memory usage requirements of the operating entities corresponding to the memory groups of the same priority are matched, and the memory usage requirements of the operating entities corresponding to the memory groups of the first priority are higher than the memory usage requirements of the operating entities corresponding to the memory groups of the second priority; when the priorities of the memory groups are divided according to the importance of the operating entities, the importance of the operating entities corresponding to the memory groups of the same priority are matched, and the importance of the operating entities corresponding to the memory groups of the first priority is higher than the importance of the memory groups of the second priority.

[0076] In an embodiment of the present application, after the electronic device obtains the number of inactive pages in the target memory group (i.e., the first number), if it is determined that the first number is greater than the target threshold, the priority corresponding to the target memory group can be determined; if the priority corresponding to the target memory group is the first priority, then when the inactive pages in the target memory group are swapped out in batches to the target storage area, the second number of inactive pages in the target memory group can be swapped out to the target storage area each time, and the second number is determined by the product of the first number and the first ratio; if the priority corresponding to the target memory group is the second priority, then when the inactive pages in the target memory group are swapped out in batches to the target storage area, the third number of inactive pages in the target memory group can be swapped out to the target storage area each time, and the third number is determined by the product of the first number and the second ratio, the first priority is higher than the second priority, and the first ratio is smaller than the second ratio. Among them, the first ratio and the second ratio are less than 0, and the specific values ​​of the first ratio and the second ratio may not be limited, for example, the first ratio may be 0.05, and the second ratio may be 0.1; since the second number is determined by the product of the first number and the first ratio, the third number is determined by the product of the first number and the second ratio, and the first ratio is less than the second ratio, therefore, when the inactive pages in the memory group with a higher priority are swapped out, the number of inactive pages swapped out each time is relatively small, and conversely, when the inactive pages in the memory group with a lower priority are swapped out, the number of inactive pages swapped out each time is relatively large. It can be understood that for the memory group with the first priority, since its corresponding operating subject has a higher demand for memory usage and a higher degree of importance, its memory pages are more likely to be accessed again, and in order to avoid affecting its operating efficiency, relatively fewer inactive pages can be swapped out each time; for the memory group with the second priority, since its corresponding operating subject has a lower demand for memory usage and a lower degree of importance, its memory pages are less likely to be accessed again, and relatively more inactive pages can be swapped out each time.

[0077] In some embodiments, when determining the second quantity above, the product of the first quantity and the first ratio can be obtained. If the product is not an integer, the obtained product can be rounded to obtain the second quantity. If the product is an integer, the product can be directly used as the second quantity. Similarly, the third quantity can be determined based on the product of the first quantity and the second ratio. For example, if the first quantity is 40 and the first ratio is 0.1, the second quantity can be determined to be 4; if the first quantity is 40 and the second ratio is 0.2, the second quantity can be determined to be 8.

[0078] Exemplarily, memory groups are obtained by grouping memory pages of different applications. For applications running in the foreground, their memory usage requirements and importance are higher, so the priority corresponding to their memory groups can be the first priority, and the number of inactive pages swapped out each time is a% of the first number; for applications running in the background, their memory usage requirements and importance are lower, so the priority corresponding to their memory groups can be the second priority, and the number of inactive pages swapped out each time is b% of the first number, and b% is greater than a%.

[0079] The memory management method provided in the embodiment of the present application can realize that after the memory pages are grouped, when the number of inactive pages in any memory group is greater than a target threshold, the memory pages are swapped out, thereby enabling memory release in advance, improving system operating efficiency, and avoiding temporary emergency measures when memory is tight, thereby reducing system load; in addition, when swapping out inactive pages in a memory group, they are swapped out in batches, thereby avoiding system pressure caused by releasing a large number of pages at one time; and when swapping out inactive pages in a memory group in batches, the number of inactive pages swapped out each time is related to the priority corresponding to the memory group, thereby reducing the impact of swapping out memory pages on operating efficiency.

[0080] See also Figure 5 , Figure 5 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 5 The process shown is described in detail, and the memory management method may specifically include the following steps:

[0081] Step S410: obtaining the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule.

[0082] Step S420: If the first number is greater than a target threshold, and the priority corresponding to the target memory group is a first priority, then at first intervals, some inactive pages in the target memory group are swapped out to the target storage area.

[0083] Step S430: If the first number is greater than the target threshold and the priority corresponding to the target memory group is the second priority, then at every second time interval, some inactive pages in the target memory group are swapped out to the target storage area, the first priority is higher than the second priority, and the first time duration is greater than the second time duration.

[0084] In an embodiment of the present application, for multiple memory groups obtained after grouping memory pages in the memory according to the target grouping rule, each memory group may correspond to a priority. The priority corresponding to the memory group can be divided according to at least one of the importance of the running subject to which the memory pages in the memory group belong and the demand for memory usage. The running subject may be an application, a system service, the importance of the process, etc. Among them, if the memory group is obtained by grouping the memory pages of different applications, the running subject may be an application; if the memory group is obtained by grouping the memory pages of different system services, the running subject may be a system service; if the memory group is obtained by grouping the memory pages of different processes, the running subject may be a process.

[0085] The priorities corresponding to the memory groups may include a first priority and a second priority, and the first priority is higher than the second priority. When the priorities of the memory groups are divided according to the demand for memory usage, the memory usage requirements of the operating entities corresponding to the memory groups of the same priority are matched, and the memory usage requirements of the operating entities corresponding to the memory groups of the first priority are higher than the memory usage requirements of the operating entities corresponding to the memory groups of the second priority; when the priorities of the memory groups are divided according to the importance of the operating entities, the importance of the operating entities corresponding to the memory groups of the same priority are matched, and the importance of the operating entities corresponding to the memory groups of the first priority is higher than the importance of the memory groups of the second priority.

[0086] In an embodiment of the present application, after the electronic device obtains the number of inactive pages in the target memory group (i.e., the first number), if it is determined that the first number is greater than the target threshold, the priority corresponding to the target memory group can be determined; if the priority corresponding to the target memory group is the first priority, then when the inactive pages in the target memory group are swapped out to the target storage area in batches, some of the inactive pages in the target memory group are swapped out to the target storage area at intervals of a first time length; if the priority corresponding to the target memory group is the second priority, then when the inactive pages in the target memory group are swapped out to the target storage area in batches, some of the inactive pages in the target memory group are swapped out to the target storage area at intervals of a second time length, and the first time length is greater than the second time length. Among them, the specific values ​​of the first duration and the second duration may not be limited, for example, the first duration may be 30 seconds, and the second duration may be 40 seconds; since the first duration is greater than the second duration, when swapping out inactive pages in a memory group with a higher priority, the time interval between two adjacent swapping out of inactive pages is longer, and conversely, when swapping out inactive pages in a memory group with a lower priority, the time interval between two adjacent swapping out of inactive pages is shorter. It can be understood that for the memory group of the first priority, since its corresponding operating subject has a higher demand for memory usage and importance, its memory pages are more likely to be accessed again, and in order to avoid affecting its operating efficiency, the memory pages can be swapped out at a relatively low frequency; for the memory group of the second priority, since its corresponding operating subject has a lower demand for memory usage and importance, its memory pages are less likely to be accessed again, and the memory pages can be swapped out at a relatively high frequency.

[0087] It should be noted that the memory management method provided in the embodiment of the present application can also be combined with the memory management method in the previous embodiment. Specifically, if the first number is greater than the target threshold value, and the priority corresponding to the target memory group is the first priority, then at each first time interval, the second number of inactive pages in the target memory group is swapped out to the target storage area, and the second number is determined by the product of the first number and the first ratio; if the first number is greater than the target threshold value, and the priority corresponding to the target memory group is the second priority, then at each second time interval, the third number of inactive pages in the target memory group is swapped out to the target storage area, and the third number is determined by the product of the first number and the second ratio, the first priority is higher than the second priority, the first ratio is less than the second ratio, and the first duration is greater than the second duration.

[0088] The memory management method provided in the embodiment of the present application can realize that after the memory pages are grouped, when the number of inactive pages in any memory group is greater than a target threshold, the memory pages are swapped out, thereby enabling early memory release, improving system operating efficiency, and avoiding temporary emergency measures when the memory is tight, thereby reducing system load; in addition, when swapping out inactive pages in a memory group, they are swapped out in batches, thereby avoiding system pressure caused by releasing a large number of pages at one time; and when swapping out inactive pages in a memory group in batches, the frequency of memory swapping is related to the priority corresponding to the memory group, thereby reducing the impact of swapping out memory pages on operating efficiency.

[0089] See also Figure 6 , Figure 6 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 6 The process shown is described in detail, and the memory management method may specifically include the following steps:

[0090] Step S510: obtaining the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule.

[0091] In the embodiment of the present application, step S510 can refer to the contents of other embodiments and will not be repeated here.

[0092] Step S520: Determine a target threshold corresponding to the target memory group.

[0093] In an embodiment of the present application, after obtaining the number of inactive pages in the target memory group (i.e., the first number), the electronic device can determine a target threshold value that needs to be compared with the first number, and the target threshold value corresponds to the target memory group. In this way, for different memory groups, the number threshold value that triggers the swapping out of inactive pages therein is different, thereby being able to meet more business needs.

[0094] In some embodiments, for multiple memory groups obtained by grouping memory pages in the memory according to the target grouping rule, each memory group may correspond to a priority, and the priority may be divided based on at least one of the importance of the running subject to which the memory pages in the memory group belong and the memory usage requirements, and the running subject may be an application, a system service to which it belongs, the importance of a process to which it belongs, etc. Among them, if the memory group is obtained by grouping the memory pages of different applications, the running subject may be the application; if the memory group is obtained by grouping the memory pages of different system services, the running subject may be the system service; if the memory group is obtained by grouping the memory pages of different processes, the running subject may be the process.

[0095] When the priorities of memory groups are divided according to the demand for memory usage, the memory usage demands of the operating subjects corresponding to the memory groups of the same priority are matched, and the level of the memory usage demand of the operating subjects corresponding to the memory groups is positively correlated with the priority of the operating subjects corresponding to the memory groups, that is, the higher the memory usage demand of the operating subjects corresponding to the memory groups, the higher the priority of the memory groups; when the priorities of memory groups are divided according to the importance of the operating subjects, the importance of the operating subjects corresponding to the memory groups of the same priority are matched, and the importance of the operating subjects corresponding to the memory groups is positively correlated with the priority of the memory groups, that is, the higher the importance of the operating subjects corresponding to the memory groups, the higher the priority of the memory groups; if the priorities of memory groups are divided according to the memory usage demands of the operating subjects corresponding to the memory groups and the importance of the operating subjects, the memory usage demands and the importance of the operating subjects corresponding to the memory groups of the same priority are matched, and the level of the memory usage demands and the importance of the operating subjects corresponding to the memory groups are positively correlated with the priority of the memory groups, that is, the higher the memory usage demands and the importance of the operating subjects corresponding to the memory groups, the higher the priority of the memory groups.

[0096] In the above method, when determining the target threshold corresponding to the target memory group, the target priority corresponding to the target memory group can be determined; then the memory replacement threshold corresponding to the target priority is determined as the target threshold, and the memory replacement thresholds corresponding to different priorities are different. It can be understood that the operating entities corresponding to memory groups of different priorities have different memory usage requirements and the importance of the operating entities. Therefore, the memory replacement thresholds that trigger memory swapping can also be different, so as to better ensure the normal operation of the operating entities corresponding to the memory groups.

[0097] In a possible implementation, the memory replacement threshold is related to the priority level, that is, when the priority level is higher, the corresponding memory replacement threshold is higher, and when the priority level is lower, the corresponding memory replacement threshold is lower. Therefore, for a memory group with a relatively high priority level, the memory replacement threshold that triggers memory swapping is also higher, and the possibility of inactive pages being swapped out is lower, thereby better ensuring the operation of the running subject.

[0098] Step S530: If the first number is greater than the target threshold, swap out at least part of the inactive pages in the target memory group to the target storage area.

[0099] In the embodiment of the present application, step S530 can refer to the contents of other embodiments and will not be repeated here.

[0100] The memory management method provided in the embodiment of the present application can realize grouping of memory pages, and when the number of inactive pages in any memory group is greater than a target threshold, the memory pages are swapped out, thereby releasing memory in advance and improving system operating efficiency, and avoiding temporary emergency measures when memory is tight and reducing system load; in addition, the target threshold for triggering memory swapping corresponds to the priority of the memory group, thereby being able to meet more business needs.

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

[0102] Step S610: creating an active linked list and an inactive linked list corresponding to each memory group in a plurality of memory groups, wherein the active linked list includes active pages in the memory group, and the inactive linked list includes inactive pages in the memory group.

[0103] In an embodiment of the present application, the operating system of the electronic device usually maintains an active linked list and an inactive linked list for all memory pages. In order to better manage the memory pages in each memory group, an active linked list and an inactive linked list corresponding to each memory group can be created for each memory group in the multiple memory groups. Among them, the implementation method of the active linked list and the inactive linked list corresponding to each memory group, and the update rules for the memory pages in the active linked list and the inactive linked list can be the same as the implementation method and update rules of the operating system maintaining an active linked list and an inactive linked list for all memory pages.

[0104] Step S620: Obtain the number of memory pages in the inactive linked list corresponding to the target memory group as the first number.

[0105] In an embodiment of the present application, when obtaining the number of inactive pages in the target memory group, the number of memory pages in the inactive linked list corresponding to the target memory group can be obtained as the first number based on the inactive linked list corresponding to the target memory group.

[0106] In some embodiments, before obtaining the number of inactive pages in the target memory group, the active linked list and the inactive linked list corresponding to the target memory group can also be rotated to update the active linked list and the inactive linked list corresponding to the target memory group, so that the status of the active linked list and the inactive linked list corresponding to the target memory group are the latest status, and the number of inactive pages determined is more accurate.

[0107] In this embodiment, the rotation operation of the active linked list and the inactive linked list may include that each time a memory page is accessed, the rotation algorithm will put it into the active linked list or the inactive linked list according to its access frequency. At the same time, the active linked list and the inactive linked list will be adjusted, that is, the pages that have not been accessed for a long time will be transferred from the active linked list to the inactive linked list, or the frequently accessed pages will be transferred from the inactive linked list to the active linked list. Therefore, before determining the number of inactive pages in the target memory group, the active linked list and the inactive linked list corresponding to the target memory group are first rotated, so that the current page status of the active linked list and the inactive linked list is the latest status, so that when determining the number of inactive pages in the target memory group, the actual number of inactive pages can be accurately determined.

[0108] Step S630: If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area.

[0109] In the embodiment of the present application, step S630 can refer to the contents of other embodiments and will not be repeated here.

[0110] The memory management method provided in the embodiment of the present application can realize that after the memory pages are grouped, when the number of inactive pages in any memory group is greater than the target threshold, the memory pages are swapped out, thereby releasing the memory in advance and improving the system operation efficiency, and avoiding temporary emergency measures when the memory is tight and reducing the system load; in addition, when managing each memory group, an active linked list and an inactive linked list are created for each memory group, so that the memory pages in each memory group can be better managed.

[0111] See also Figure 8 , Figure 8A 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 8 The process shown is described in detail, and the memory management method may specifically include the following steps:

[0112] Step S710: obtaining the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule.

[0113] In the embodiment of the present application, step S710 can refer to the contents of other embodiments and will not be repeated here.

[0114] Step S720: If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area corresponding to the target memory group.

[0115] In an embodiment of the present application, after the electronic device obtains the number of inactive pages in the target memory group (i.e., the first number), if it is determined that the first number is greater than the target threshold, when performing memory swapping on the inactive pages in the target memory group, at least part of the inactive pages in the target memory group may be swapped out to the target storage area corresponding to the target memory group. It can be understood that corresponding swap areas may be set for the memory pages in different memory groups, so that the memory pages in the memory group can be swapped out to the corresponding destination (i.e., the target storage area).

[0116] In some embodiments, when performing memory swapping on inactive pages in a target memory group, a target priority corresponding to the target memory group can be determined, and then a swap area corresponding to the target priority can be determined as a target storage area, and the data read and write speeds of the swap areas corresponding to different priorities are different; then at least part of the inactive pages in the target memory group are swapped out to the target storage area corresponding to the target memory group. Among them, the division method of the priorities corresponding to different memory groups can refer to the content of the aforementioned embodiment, and will not be repeated here. Since the operating entities corresponding to memory groups of different priorities have different memory usage requirements and importance, the speeds of swapping out memory pages and swapping back memory data of memory pages are different, and the swapped out destination will affect the speed of swapping out and swapping back memory pages, so the correspondence between different priorities and swap areas can be predetermined. For example, the priorities include the first priority, the second priority, and the third priority from high to low, then the swap area corresponding to the first priority can be a compressed memory area, the swap area corresponding to the second priority can be a storage area in a flash memory, and the swap area corresponding to the third priority can be a storage area in a disk.

[0117] The memory management method provided in the embodiment of the present application can realize that after the memory pages are grouped, when the number of inactive pages in any memory group is greater than the target threshold, the memory pages will be swapped out, thereby enabling early memory release and improving system operating efficiency, and avoiding temporary emergency measures when memory is tight and reducing system load; in addition, when it is determined that the inactive pages in the memory group need to be swapped out, the inactive pages are swapped out to the storage area corresponding to the memory group, thereby enabling the memory pages in the memory group to be swapped out to the corresponding destination.

[0118] See also Fig. 9 , which shows a structural block diagram of a memory management device 800 provided in an embodiment of the present application. The memory management device 800 applies the above-mentioned electronic device, and the memory management device 800 includes: a quantity acquisition module 810 and a memory swap module 820. Among them, the quantity acquisition module 810 is used to obtain the number of inactive pages in the target memory group as a first number, and the target memory group is any memory group of a plurality of memory groups, and the plurality of memory groups are obtained by grouping the memory pages in the memory according to the target grouping rule; the memory swap module 820 is used to swap out at least part of the inactive pages in the target memory group to the target storage area if the first number is greater than the target threshold.

[0119] In some implementations, the memory swap module 820 may be specifically configured to batch swap out inactive pages in the target memory group to the target storage area if the first number is greater than a target threshold.

[0120] In a possible implementation, the memory swap module 820 can also be specifically used to swap out the inactive pages in the target memory group to the target storage area in multiple times if the first number is greater than the target threshold, wherein the number of inactive pages swapped out to the target storage area each time is determined by the first number.

[0121] Optionally, the memory swap-out module 820 can also be specifically used to swap out a second number of inactive pages in the target memory group to the target storage area each time if the first number is greater than a target threshold and the priority corresponding to the target memory group is the first priority, and the second number is determined by the product of the first number and the first ratio; if the first number is greater than the target threshold and the priority corresponding to the target memory group is the second priority, then swap out a third number of inactive pages in the target memory group to the target storage area each time, and the third number is determined by the product of the first number and the second ratio, the first priority is higher than the second priority, and the first ratio is smaller than the second ratio.

[0122] Optionally, the memory swap module 820 can also be specifically used to swap out some inactive pages in the target memory group to the target storage area at every first time interval if the first number is greater than a target threshold and the priority corresponding to the target memory group is a first priority; if the first number is greater than a target threshold and the priority corresponding to the target memory group is a second priority, swap out some inactive pages in the target memory group to the target storage area at every second time interval, the first priority being higher than the second priority, and the first time interval being greater than the second time interval.

[0123] In some embodiments, the memory swap module 820 can be specifically used to determine a target threshold corresponding to the target memory group; if the first number is greater than the target threshold, at least part of the inactive pages in the target memory group are swapped out to the target storage area.

[0124] In a possible implementation, the memory swap module 820 may also be used to determine a target priority corresponding to the target memory group; determine a memory replacement threshold corresponding to the target priority as the target threshold, and different memory replacement thresholds corresponding to different priorities are different.

[0125] In some embodiments, the memory management device 800 may further include a linked list creation module. The linked list creation module may be specifically used to create an active linked list and an inactive linked list corresponding to each of the multiple memory groups before obtaining the number of inactive pages in the target memory group as the first number, wherein the active linked list includes active pages in the memory group, and the inactive linked list includes inactive pages in the memory group. The quantity acquisition module 810 may be specifically used to obtain the number of memory pages in the inactive linked list corresponding to the target memory group as the first number.

[0126] In a possible implementation, the memory management device 800 may further include a linked list update module. The linked list update module is used to perform a rotation operation on the active linked list and the inactive linked list corresponding to the target memory group before obtaining the number of memory pages in the inactive linked list corresponding to the target memory group as the first number, so as to update the active linked list and the inactive linked list corresponding to the target memory group.

[0127] In some embodiments, the memory management device 800 may further include a memory grouping module, which is used to determine the memory pages corresponding to each currently running application before obtaining the number of inactive pages in the target memory group as the first number; establish a memory group corresponding to each application, and divide the memory pages corresponding to each application into the memory group corresponding to each application.

[0128] In some embodiments, the memory swap module 820 may be specifically configured to swap out at least a portion of inactive pages in the target memory group to a target storage area corresponding to the target memory group if the first number is greater than a target threshold.

[0129] In a possible implementation, the memory swap module 820 can also be used to determine the target priority corresponding to the target memory group if the first number is greater than a target threshold; determine the swap area corresponding to the target priority as the target storage area, the swap areas corresponding to different priorities having different data read and write speeds; and swap out at least part of the inactive pages in the target memory group to the target storage area.

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

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

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

[0133] In summary, the solution provided by the present application obtains the number of inactive pages in the target memory group as the first number, the target memory group is any memory group in a plurality of memory groups, and the plurality of memory groups are obtained by grouping the memory pages in the memory according to the target grouping rule. If the first number is greater than the target threshold, at least part of the inactive pages in the target memory group is swapped out to the target storage area. Thus, it is possible to swap out the memory pages when the number of inactive pages in any memory group after the memory pages are grouped is greater than the target threshold, thereby enabling memory release in advance and improving system operation efficiency.

[0134] Please refer to Fig.10, 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.

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

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

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

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

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

Claims

1. A memory management method, characterized in that: The method comprises: Acquire the number of inactive pages in a target memory group as a first number, wherein the target memory group is any one of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule; If the first number is greater than a target threshold, at least part of the inactive pages in the target memory group are swapped out to a target storage area.

2. The method according to claim 1, characterized in that If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area includes: If the first number is greater than a target threshold, the inactive pages in the target memory group are swapped out in batches to a target storage area.

3. The method according to claim 2, characterized in that If the first number is greater than a target threshold, swapping out inactive pages in the target memory group to a target storage area in batches includes: If the first number is greater than the target threshold, the inactive pages in the target memory group are swapped out to the target storage area in multiple times, wherein the number of inactive pages swapped out to the target storage area each time is determined by the first number.

4. The method according to claim 3, characterized in that If the first number is greater than the target threshold, swapping out the inactive pages in the target memory group to the target storage area in multiple times includes: If the first number is greater than the target threshold value, and the priority corresponding to the target memory group is the first priority, swapping out a second number of inactive pages in the target memory group to the target storage area each time, the second number being determined by multiplying the first number by the first ratio; If the first number is greater than the target threshold and the priority corresponding to the target memory group is the second priority, a third number of inactive pages in the target memory group are swapped out to the target storage area each time, and the third number is determined by the product of the first number and the second ratio. The first priority is higher than the second priority, and the first ratio is smaller than the second ratio.

5. The method according to claim 3, characterized in that: If the first number is greater than the target threshold, swapping out the inactive pages in the target memory group to the target storage area in multiple times includes: If the first number is greater than a target threshold value, and the priority corresponding to the target memory group is a first priority, then at intervals of a first time length, some inactive pages in the target memory group are swapped out to a target storage area; If the first number is greater than the target threshold and the priority corresponding to the target memory group is the second priority, some inactive pages in the target memory group are swapped out to the target storage area every second time period, the first priority is higher than the second priority, and the first time period is greater than the second time period.

6. The method according to claim 1, characterized in that If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area includes: determining a target threshold corresponding to the target memory group; If the first number is greater than the target threshold, at least part of the inactive pages in the target memory group are swapped out to the target storage area.

7. The method according to claim 6, characterized in that The determining a target threshold value corresponding to the target memory group includes: Determining a target priority corresponding to the target memory group; A memory replacement threshold corresponding to the target priority is determined as the target threshold, and memory replacement thresholds corresponding to different priorities are different.

8. The method according to claim 1, characterized in that Before obtaining the number of inactive pages in the target memory group as the first number, the method further includes: Creating an active linked list and an inactive linked list corresponding to each memory group in the multiple memory groups, wherein the active linked list includes active pages in the memory group, and the inactive linked list includes inactive pages in the memory group; The obtaining the number of inactive pages in the target memory group as the first number includes: The number of memory pages in the inactive linked list corresponding to the target memory group is obtained as the first number.

9. The method according to claim 8, characterized in that Before obtaining the number of memory pages in the inactive linked list corresponding to the target memory group as the first number, the method further includes: Perform a rotation operation on the active linked list and the inactive linked list corresponding to the target memory group to update the active linked list and the inactive linked list corresponding to the target memory group.

10. The method according to any one of claims 1 to 8, characterized in that: Before obtaining the number of inactive pages in the target memory group as the first number, the method further includes: Determine the memory page corresponding to each currently running application; A memory group corresponding to each application is established, and memory pages corresponding to each application are divided into the memory group corresponding to each application.

11. The method according to any one of claims 1 to 8, characterized in that: If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area includes: If the first number is greater than a target threshold, at least part of the inactive pages in the target memory group are swapped out to a target storage area corresponding to the target memory group.

12. The method according to claim 11, characterized in that If the first number is greater than a target threshold, swapping out at least part of the inactive pages in the target memory group to a target storage area corresponding to the target memory group includes: If the first number is greater than a target threshold, determining a target priority corresponding to 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 priorities are different; At least a portion of inactive pages in the target memory group are swapped out to the target storage area.

13. A memory management device, characterized in that: The device comprises: a quantity acquisition module and a memory swap module, wherein: The quantity acquisition module is used to acquire the number of inactive pages in a target memory group as a first number, wherein the target memory group is any memory group of a plurality of memory groups, and the plurality of memory groups are obtained by grouping memory pages in the memory according to a target grouping rule; The memory swap module is used to swap out at least part of the inactive pages in the target memory group to the target storage area if the first number is greater than a target threshold.

14. 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 12.

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