Memory management method and device, electronic equipment and storage medium
By dividing the application's memory pages into the target memory group and applying the corresponding memory swap strategy, the problem of poor memory swap management flexibility in the existing technology is solved, and the precise management of the application's memory pages is achieved, and the system performance is improved.
Patent Information
- Application Number
- CN202311148077.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-06
- Publication Date
- 2025-03-07
AI Technical Summary
The existing technology has poor flexibility when performing memory swap management and cannot accurately manage the memory pages of the application, resulting in the memory pages of important applications being swapped out, affecting the running speed.
By dividing its memory page into the target memory group based on the user identifier of the target application, and memory swap management is carried out according to the memory swap policy of the memory group, targeted management of the application's memory page.
Improves the accuracy of memory swap management, ensures that the memory pages of important applications are not swapped out by mistake, and improves the system's running speed and stability.
Smart Images

Figure CN119576803A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of electronic devices, and more specifically, to a memory management method, device, electronic device and storage medium. Background Art
[0002] With the rapid advancement of science and technology and living standards, electronic devices (such as smart phones, tablet computers, etc.) have become one of the commonly used electronic products in people's lives. In electronic devices, memory is one of the important components. It is a bridge for communication with the central processing unit (CPU). Since the capacity of memory is limited, it is usually necessary to manage the memory. In related technologies, memory swapping mechanisms are usually used to manage memory to increase available memory. However, the flexibility of memory swapping management in related technologies is poor, and it is impossible to accurately perform memory swapping management on the memory pages of applications. Summary of the invention
[0003] The present application proposes a memory management method, device, electronic device and storage medium, which can achieve targeted memory swap management of the memory pages of the application, thereby improving the accuracy of memory swap management.
[0004] In a first aspect, an embodiment of the present application provides a memory management method, the method comprising: based on a target user identifier corresponding to a currently running target application, dividing the memory pages corresponding to the target application into a target memory group; based on a memory swap policy corresponding to the target memory group, performing memory swap management on the memory pages in the target memory group.
[0005] In a second aspect, an embodiment of the present application provides a memory management device, comprising: a memory grouping module and a memory exchange module, wherein the memory grouping module is used to divide the memory pages corresponding to the target application into a target memory group based on a target user identifier corresponding to the currently running target application; and the memory exchange module is used to perform memory exchange management on the memory pages in the target memory group based on a memory exchange policy corresponding to the target memory group.
[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 divides the memory pages of an application into corresponding memory groups according to a user identifier corresponding to the application, and then performs memory swap management on the memory pages in the memory group according to a memory swap policy corresponding to the memory group, thereby achieving targeted memory swap management of the memory pages of the application and improving the accuracy of memory swap management. 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 diagram of a memory management method according to an embodiment of the present application is shown.
[0011] Figure 2 A schematic flow chart of a memory management method according to another embodiment of the present application is shown.
[0012] Figure 3 A schematic diagram of memory page grouping provided in an embodiment of the present application is shown.
[0013] Figure 4 A schematic diagram of memory page grouping provided in an embodiment of the present application is shown.
[0014] Figure 5 A schematic flow chart of a memory management method according to another embodiment of the present application is shown.
[0015] Figure 6 A flowchart of a memory management method according to another embodiment of the present application is shown.
[0016] Figure 7 A schematic flow chart of a memory management method according to yet another embodiment of the present application is shown.
[0017] Figure 8 A flowchart 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] In the related art, when performing memory swap management, all memory pages are usually managed according to a fixed memory swap strategy, which may cause the memory pages of some important applications to be swapped out, affecting the running speed. For example, when using the LRU algorithm to determine the memory pages to be swapped out, if a process of an important application has not been accessed for the longest time, and the process is a key process for the operation of the application, then swapping out the process will affect the running speed of the application, thereby affecting the user's use of the application.
[0030] In view of 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 targeted memory swap management of the memory pages of the application and improve the accuracy of memory swap management. The specific memory management method will be described in detail in the subsequent embodiments.
[0031] The memory management method provided in the embodiment of the present application is described in detail below with reference to the accompanying drawings.
[0032] 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. 9The memory management device 700 and the electronic device 100 ( 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:
[0033] Step S110: Based on a target user identifier corresponding to a currently running target application, memory pages corresponding to the target application are divided into a target memory group.
[0034] In an embodiment of the present application, when an electronic device manages memory, it can divide the memory pages corresponding to the target application into a target memory group according to the target user identifier (User Identification, UID) corresponding to the target application for the currently running target application, so as to perform corresponding memory exchange management for the memory pages in the target memory group, thereby realizing targeted memory exchange management for the memory pages of the target application. Among them, the target application can be any application running by the electronic device. UID is based on the application in the operating system. Each program has a UID. If the UIDs of application 1 and application 2 are different, in some cases, the two cannot read each other's data, which improves the security of the application; when an application is installed in the electronic device, the operating system will assign a UID. Therefore, based on the target UID corresponding to the target application, the memory page corresponding to the target application can be determined and divided into the target memory group. Optionally, the memcg grouping mechanism in the Linux system can be used as the implementation carrier of the memory group.
[0035] It is understandable that when an application is running, it needs to occupy memory to store data during the running process. The size of the memory space occupied by different applications in different running states is not necessarily the same; the memory page is the unit of memory management by the operating system. The unit memory size occupied by the memory page may not be limited. The unit memory size occupied by the memory page set by different electronic devices may be different. The application running in the electronic device can occupy multiple memory pages in the memory, and the size of the memory space occupied by it corresponds to the size occupied by all the corresponding memory pages. Among them, the memory page 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 the memory after the program reads the file. File pages are also called file caches.
[0036] In some implementations, the electronic device may use the newly running application as the target application each time it detects a newly running application, and divide the memory page corresponding to the target application into the target memory group based on the target UID corresponding to the target application, so that when the electronic device performs memory swap management on the memory, it can adopt the corresponding memory swap strategy for the target memory group to perform memory swap management.
[0037] In some embodiments, considering that when an electronic device performs memory exchange management on a memory, it is mainly when the memory is insufficient (for example, the remaining memory is less than the set memory threshold, the memory requirements of the current process cannot be met, and the memory space cannot be allocated for the new process, etc.), the memory page that needs to be swapped out will be selected and swapped out to other storage areas. Therefore, it is possible to predict whether the electronic device will perform memory exchange management after the target duration. According to the prediction result, if the prediction result indicates that the memory exchange management will be performed after the target duration, the memory page corresponding to each application in the currently running application can be divided into the corresponding memory group at the current moment, that is, each application can be used as a target application, and the memory page corresponding to the target application can be divided into the target memory group based on the target user identifier corresponding to the target application. Among them, the specific value of the target duration can be unlimited, for example, it can be 3 minutes, 5 minutes, 10 minutes, etc. In this way, it can be realized that before the predicted electronic device performs memory exchange management, the memory pages of the running application are grouped, so that before the memory exchange management is performed, the memory pages in the memory group can be performed according to the memory exchange strategy of each memory group. The electronic device may predict whether the electronic device will perform memory swap management after a target time period at every first interval time period, and the first interval time period may be 30 seconds, 1 minute, 3 minutes, etc.
[0038] In a possible implementation, a pre-trained memory exchange prediction model is stored in the electronic device. The memory exchange prediction model may be pre-trained based on historical status information collected at different times. The historical status information is the device status information collected by the electronic device during historical operation, and the historical status information is marked with a corresponding memory exchange tag. The device status information may include: historical moment, total memory size, remaining memory size at the historical moment, running applications at the historical moment, and other information related to the current state of the electronic device at the historical moment. The memory exchange tag is used to characterize whether the electronic device performs memory exchange management after the target duration of the historical moment. Among them, the memory exchange prediction model may be a support vector machine (SVM), a neural network, a naive Bayes classifier, etc., and the specific model type of the memory exchange prediction model may not be limited.
[0039] Among them, when the electronic device needs to predict whether memory swap management will be performed after the target duration, it can obtain the current device status information, that is, the current time, the total memory size, the remaining memory size of the electronic device at the current time, the application running at the current time and other information, and then input the current device status information into the above memory swap prediction model to obtain the prediction result. According to the prediction result, it can be determined whether the electronic device will perform memory swap management after the target duration.
[0040] Optionally, the prediction result may be a classification result of whether the electronic device will perform memory exchange management after a target duration, and the classification result includes two categories: performing memory exchange management and not performing memory exchange management. Therefore, the classification result may directly indicate whether the electronic device will perform memory exchange management after the target duration. The prediction result may also be a probability value representing whether the electronic device will perform memory exchange management after the target duration. The probability value is positively correlated with the possibility that the electronic device will perform memory exchange management after the target duration. That is, the larger the probability value, the greater the possibility that the electronic device will perform memory exchange management after the target duration. The smaller the collision probability value, the smaller the possibility that the electronic device will perform memory exchange management after the target duration. Therefore, based on the prediction result, it may also be determined whether the electronic device will perform memory exchange management after the target duration.
[0041] Optionally, the above memory exchange prediction model can be trained in the following way: obtain the historical status information of the electronic device at different historical moments in the historical operation process, and obtain the record of whether the memory exchange management is performed after the target duration of each historical moment. According to the obtained record, the historical status information of each historical moment can be marked with the above memory exchange label, thereby obtaining a sample data set; when the memory exchange prediction model is obtained by training based on the sample data set, the historical status information can be input into the initial prediction model to obtain the prediction result output by the initial prediction model for the input historical status information, and the target loss value of the initial prediction model can be determined according to the prediction result and the memory exchange label marked by the historical status information; after determining the target loss value corresponding to the initial detection model, the initial prediction model can be iteratively trained according to the target loss value to obtain the final memory exchange prediction model. Among them, the initial prediction model can be a neural network, a Softmax logistic regression model, a support vector machine, etc., and the specific initial prediction model can be not limited; when determining the target loss value, the loss value can be determined according to the difference between the prediction result and the memory exchange label marked by the historical status information.
[0042] When the initial prediction model is iteratively trained according to the target loss value, the model parameters of the initial prediction model can be adjusted according to the calculated target loss value; the historical state information is repeatedly input into the initial prediction model to obtain the prediction result output by the memory swap prediction model for the input historical state information, and based on the prediction result and the memory swap label marked by the historical state information, the target loss value corresponding to the initial prediction model can be determined, and the model parameters of the initial prediction model can be adjusted according to the target loss value until the training end condition is met to obtain the trained memory swap prediction model. The training end condition of iterative training may include: the number of iterative training reaches the target number; or the total loss value of the initial prediction model meets the set condition.
[0043] In the above implementation, if it is determined that the electronic device does not perform memory swap management after the target duration at the current moment, the memory pages of the running applications may not be grouped, that is, the memory pages of each application are not divided into corresponding memory groups, thereby reducing the consumption of processing resources of the electronic device.
[0044] Of course, in the embodiment of the present application, the triggering method for dividing the memory pages corresponding to the target application into corresponding memory groups may not be limited. For example, in a subsequent embodiment, when it is determined that the device status information meets the memory grouping conditions, the memory pages corresponding to the target application are divided into the target memory group based on the target UID corresponding to the target application.
[0045] In some embodiments, the target memory group may include only memory pages corresponding to the target application; the target memory group may also include memory pages corresponding to multiple applications, and the memory usage requirements of the multiple applications are matched. The usage requirements may be memory access speed, memory access frequency, etc. For example, the difference between the memory access speeds required by multiple applications in the same memory group at runtime is not greater than the target speed threshold, and the difference between the required memory access frequencies is not greater than the target frequency threshold.
[0046] Step S120: performing memory swap management on memory pages in the target memory group based on the memory swap policy corresponding to the target memory group.
[0047] In an embodiment of the present application, after the target UID corresponding to the target application is divided into the target memory group, the memory pages corresponding to the target application can be managed by memory exchange based on the memory exchange policy corresponding to the target memory group. The memory exchange policy corresponding to the target memory group can be determined according to the memory usage requirements of the application corresponding to the memory page in the target memory group and the importance of the application, wherein the memory usage requirements may include memory access speed, memory access frequency, etc., and the importance of the application can be predetermined (for example, determined according to user operations) or determined according to the number of runs and the running frequency of the application. For example, if the memory access speed required at runtime is high and the memory access is frequent, its memory exchange policy can be determined as a policy of not performing memory exchange, that is, when the electronic device performs memory exchange management, it will not determine the memory pages that need to be swapped out from the target memory group; for another example, if the memory access speed required at runtime is low and the memory access frequency is low, its memory exchange policy can be determined as an exchange policy corresponding to the first-in-first-out (FIFO) algorithm, that is, when the electronic device performs memory exchange management, the memory page that first enters the cache is determined from the target memory group as the memory page that needs to be swapped out.
[0048] In some embodiments, when the electronic device performs memory exchange management on the memory pages in the target memory group based on the memory exchange strategy corresponding to the target memory group, it can be performed when the triggering conditions for memory exchange management are met (for example, the remaining memory is less than the set memory threshold, the memory requirements of the current process cannot be met, or the memory space cannot be allocated for the new process, etc.), that is, when the electronic device needs to perform memory exchange management on the memory, it can determine whether the memory page in the target memory group needs to be swapped out, and the memory page to be swapped out when the memory page needs to be swapped out based on the memory exchange strategy corresponding to the target memory group. For example, if the memory exchange strategy corresponding to the target memory group is the exchange strategy corresponding to LRU, then the memory page that has not been accessed for the longest time can be determined from the target memory group according to the LRU algorithm, and the memory page is used as the memory page to be swapped out, and the data in the memory page to be swapped out is swapped out to the corresponding swap area; for another example, if the memory exchange strategy corresponding to the target memory group is the exchange strategy corresponding to the FIFO algorithm, then the memory page that first enters the cache can be determined from the target memory group according to the FIFO algorithm, and the memory page is used as the memory page to be swapped out, and the data in the memory page to be swapped out is swapped out to the corresponding swap area.
[0049] In some embodiments, the memory exchange policy corresponding to the above target memory group can also be determined by the electronic device according to a pre-trained policy recognition model. Among them, the policy recognition model can be pre-trained according to the application information of different applications, and the application information can be information such as the memory access frequency when the application is running, the type of process created when the application is running, the number of processes created when the application is running, and the memory size occupied when the application is running, and the application information is marked with a policy label corresponding to the memory exchange policy. Among them, the policy recognition model can be a neural network, a naive Bayes classifier, etc., and of course, the specific model type of the policy recognition model can be unlimited. When determining the memory exchange policy corresponding to the target memory group, the electronic device can obtain the application information of the application corresponding to the memory page in the target memory group, and then input the application information into the above policy recognition model, and obtain the recognition result output by the policy recognition model. According to the recognition result, the memory exchange policy can be determined and used as the memory exchange policy corresponding to the target memory group. It can be understood that the above application information usually affects the application's demand for memory usage, and when the demand for memory usage is different, the memory exchange policy to be used may also be different, so the memory exchange policy can be identified according to the above application information.
[0050] In a possible implementation, a mapping relationship between multiple sample applications and memory exchange strategies can be obtained in advance, and the mapping relationship can be set by the developer for each sample application according to the memory usage requirements of the multiple sample applications; then the application information of each sample application is obtained, and the corresponding policy label is annotated for the application information of each sample application according to the above mapping relationship; when the policy recognition model is trained, the application information of the sample application can be input into the initial recognition model to obtain the recognition result output by the initial recognition model for the input application information, and the loss value of the initial recognition model can be determined according to the recognition result and the policy label annotated with the application information; after the loss value corresponding to the initial recognition model is determined, the initial recognition model can be iteratively trained according to the loss value to obtain the final policy recognition model. Wherein, when determining the above loss value, the loss value can be determined according to the difference between the recognition result and the policy label annotated with the above application information.
[0051] The memory management method provided in the embodiment of the present application divides the memory pages of an application into corresponding memory groups according to a user identifier corresponding to the application, and then performs memory swap management on the memory pages in the memory group according to a memory swap policy corresponding to the memory group, thereby achieving targeted memory swap management of the memory pages of the application and improving the accuracy of memory swap management.
[0052] See also Figure 2 , Figure 2 A flow chart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 2 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0053] Step S210: Based on a target user identifier corresponding to a currently running target application, a memory page corresponding to the target user identifier is determined.
[0054] In an embodiment of the present application, when the electronic device divides the memory pages corresponding to the target application into the target memory group based on the target UID corresponding to the target application, it can determine the memory pages corresponding to the target user identifier based on the target UID, so as to divide the memory pages corresponding to the target application into the target memory group. It can be understood that in order to distinguish the relevant information of different applications at runtime, the operating system usually binds the UID to the relevant information of the application at runtime. Therefore, using the target UID of the target application, the memory page corresponding to the target user identifier can be determined, that is, the memory page occupied by the target application at runtime.
[0055] In some implementations, since processes in the operating system are associated with UIDs in addition to process identifiers (PIDs), in order to query different processes of an application, when determining the memory page corresponding to the target UID, all processes corresponding to the target user identifier can be determined as target processes, and then the memory page of the target process can be determined as the memory page corresponding to the target UID.
[0056] Step S220: Divide the memory page corresponding to the target user identifier into a target memory group.
[0057] In an embodiment of the present application, after determining the memory page corresponding to the above target UID, the memory page corresponding to the target UID can be divided into a target memory group, so that when the electronic device performs memory exchange management on the memory, the corresponding memory exchange strategy can be adopted for the target memory group to perform memory exchange management.
[0058] In some implementations, the target memory group may correspond to at least one application, that is, the target memory group may include memory pages corresponding to the UID of one application, or may include memory pages corresponding to the UIDs of multiple applications. Where the target memory group includes memory pages corresponding to the UIDs of multiple applications, at least one of the memory usage requirements of the multiple applications and the importance of the applications is matched with each other, and the memory usage requirements of the applications may include memory access speed, memory access frequency, tolerance to data read and write delays, etc.
[0059] In one possible implementation, the electronic device may assign different priorities to applications based on at least one of the application's memory usage requirements and the importance of the application, obtain the priority corresponding to the application, and establish a mapping relationship between the UID corresponding to the application and the priority based on the priority corresponding to the application. Among them, if the priority of the application is divided according to the demand for memory usage, the memory usage requirements of the applications of the same priority are matched, and the level of the memory usage requirements of the applications is positively correlated or negatively correlated with the priority of the application, that is, the higher the memory usage requirement of the application, the higher the priority of the application, or the higher the memory usage requirement of the application, the lower the priority of the application; if the priority of the application is divided according to the importance of the application, the importance of the application of the same priority is matched, and the importance of the application is positively correlated or negatively correlated with the priority of the application, that is, the higher the importance of the application, the higher the priority of the application, or the higher the importance of the application, the lower the priority of the application; if the priority of the application is divided according to the demand for memory usage and the importance of the application, the memory usage requirements of the applications of the same priority and the importance of the application are matched, and the level of the memory usage requirements and the importance of the application are positively correlated or negatively correlated with the priority of the application, that is, the higher the memory usage requirement and the importance of the application, the higher the priority of the application, or the higher the memory usage requirement and the importance of the application, the lower the priority of the application.
[0060] In the above implementation, different memory groups can be established for different priorities, and each memory group includes memory pages corresponding to the UID of the priority corresponding to the memory group; when the memory pages corresponding to the target UID are divided into the target memory group, the target priority corresponding to the target UID can be determined, and then the memory pages corresponding to the target UID can be divided into the target memory group corresponding to the target priority. It can be understood that since the same priority may correspond to the UID of at least one application, the target memory group may include memory pages corresponding to the target UID, and may also include memory pages corresponding to the UIDs of other applications. In the above implementation, it can be implemented that for applications with the same priority, their memory pages are divided into the same memory group, and subsequently the memory pages in the memory group are managed by memory exchange through the memory exchange policy corresponding to the memory group, so that it can be implemented that for applications with the same priority, the corresponding memory exchange policy is used to perform memory exchange management.
[0061] For example, see Figure 3 , the currently running applications include the application corresponding to UID1, the application corresponding to UID2, and the application corresponding to UID3. The priority corresponding to UID1 is the same as the priority corresponding to UID3. Then the memory pages corresponding to UID1 (i.e., the memory pages corresponding to process 1, process 2, process 3, and process 4) and the memory pages corresponding to UID3 (i.e., the memory pages corresponding to process 7, process 8, and process 9) can be divided into memory group 1, and the memory pages corresponding to UID2 (i.e., the memory pages corresponding to process 5 and process 6) can be divided into memory group 2.
[0062] In a possible implementation, the applications may be classified to obtain a mapping relationship between the UID and the category of the application, and memory groups of different categories may be established. When the applications are classified, different applications may be classified based on at least one of the application's memory usage requirements and the application's importance. If the applications are classified based on the memory usage requirements, the memory usage requirements of applications in the same category match each other; if the applications are classified based on the application's importance, the importance of applications in the same category match each other; if the applications are classified based on both the application's memory usage requirements and the application's importance, the memory usage requirements and the application's importance in the same category match each other.
[0063] In the above implementation, the target category corresponding to the target UID can be determined for the target UID, and then the memory pages corresponding to the target UID can be divided into the memory group corresponding to the target category. It can be understood that since the same priority may correspond to the UID of at least one application, the target memory group may include memory pages corresponding to the target UID, and may also include memory pages corresponding to the UIDs of other applications. In the above implementation, it can be implemented that for applications in the same category, their memory pages are divided into the memory group corresponding to the category, and subsequently the memory pages in the memory group are managed by memory exchange through the memory exchange policy corresponding to the memory group, so that it can be implemented that for applications in the same category, the corresponding memory exchange policy is adopted to perform memory exchange management.
[0064] In some implementations, a corresponding memory group may be allocated for each application, that is, each memory group corresponds to the UID of each application. When the memory pages corresponding to the target UID are allocated to the target memory group, a target memory group corresponding to the target UID may be established, and the memory pages corresponding to the target user UID may be allocated to the target memory group, wherein different UIDs correspond to different memory groups. In this manner, after the memory pages are allocated to the corresponding memory groups for each running application, the corresponding memory swap strategy may be used to perform internal swap management for each application. For example, please refer to Figure 4 , the currently running applications include the applications corresponding to UID1, the applications corresponding to UID2, and the applications corresponding to UID3. Memory group 1 can be established for UID1, and the memory pages corresponding to UID1 (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 UID2, and the memory pages corresponding to UID2 (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 UID3, and the memory pages corresponding to UID3 (that is, the memory pages corresponding to process 7, process 8, and process 9) can be divided into memory group 3.
[0065] Among them, it should be noted that the method of dividing a separate memory group for each application's UID may exist. There may be applications with the same memory usage requirements and importance, and the memory swap policies corresponding to their memory groups may be the same. For example, the application corresponding to UID1 and the application corresponding to UID2 have the same importance and memory usage requirements, so the memory swap policies determined for the memory group corresponding to UID1 and the memory group corresponding to UID2 may be the same.
[0066] In some embodiments, after the memory pages corresponding to the target UID are divided into the target memory group, if there are new memory pages corresponding to the target UID, for example, the target application has a new process, there will be new memory pages, and the new memory pages can be divided into the target memory group.
[0067] Step S230: performing memory swap management on memory pages in the target memory group based on the memory swap policy corresponding to the target memory group.
[0068] In the embodiment of the present application, step S230 can refer to the contents of other embodiments and will not be repeated here.
[0069] The memory management method provided in the embodiment of the present application determines the memory page corresponding to the UID according to the UID corresponding to the running application, and then divides the memory page corresponding to the UID into the memory group corresponding to the UID, and then performs memory swap management on the memory pages in the memory group according to the memory swap policy corresponding to the memory group, thereby realizing targeted memory swap management of the memory pages of the application and improving the accuracy of memory swap management.
[0070] See also Figure 5 , Figure 5 A flow chart of a memory management method provided by another embodiment of the present application is shown. The memory management method is applied to the above electronic device. Figure 5 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0071] Step S310: Based on a target user identifier corresponding to a currently running target application, memory pages corresponding to the target application are divided into target memory groups.
[0072] In the embodiment of the present application, step S310 can refer to the contents of other embodiments and will not be repeated here.
[0073] Step S320: Based on the target priority corresponding to the target user identifier, determine a memory exchange policy corresponding to the target priority as the memory exchange policy corresponding to the target memory group, wherein different memory exchange policies correspond to different priorities.
[0074] In an embodiment of the present application, different priorities can be divided for different applications, and priorities corresponding to different UIDs can be obtained. The priority corresponding to the UID can be divided according to at least one of the memory usage requirements of the application corresponding to the UID and the importance of the application, wherein, if the priority of the application is divided according to the memory usage requirements, the memory usage requirements of applications of the same priority are matched, and the level of the memory usage requirements of the application is positively correlated with the priority of the application, that is, the higher the memory usage requirements of the application, the higher the priority of the application; if the priority of the application is divided according to the importance of the application, the importance of applications of the same priority is matched, and the importance of the application is positively correlated with the priority of the application, that is, the higher the importance of the application, the higher the priority of the application; if the priority of the application is divided according to the memory usage requirements of the application and the importance of the application, the memory usage requirements of applications of the same priority and the importance of the application are matched, and the level of the memory usage requirements of the application is positively correlated with the priority of the application, that is, the higher the memory usage requirements of the application and the importance of the application, the higher the priority of the application. Since the priority corresponding to the UID is divided according to at least one of the memory usage requirements of the application corresponding to the UID and the importance of the application, when determining the memory swap strategy, the memory swap strategy corresponding to the target priority can be determined based on the target priority corresponding to the target UID, and the memory swap strategies corresponding to different priorities are different.
[0075] In some embodiments, the electronic device may pre-store mapping relationships corresponding to different priorities and memory exchange strategies, and the mapping relationships are determined according to the memory usage requirements and the importance of the applications corresponding to the different priorities, wherein if the priority is divided according to the memory usage requirements, the mapping relationship is determined according to the memory usage requirements of the applications; if the priority is divided according to the importance of the applications, the mapping relationship is determined according to the importance of the applications; if the priority is divided according to the memory usage requirements and the importance of the applications, the mapping relationship is determined according to the memory usage requirements and the importance of the applications. For example, the priority of the application includes priority 1, priority 2, and priority 3 in descending order, and the priority is determined according to the importance of the applications, the higher the priority, the higher the importance of the application corresponding to the UID; for priority 1, a strategy of not performing memory swapping can be set, that is, when the memory pages in the memory group are managed by memory swapping using the strategy, the memory pages in the memory group will not be swapped out; for priority 2, a strategy corresponding to the LRU algorithm can be set to keep the recently used data in the memory; for priority 3, a swap strategy corresponding to the FIFO algorithm can be set to reduce the processing resources occupied by memory swapping management. In the above implementation, when determining the memory swap strategy corresponding to the target priority based on the target priority corresponding to the target user identifier, the memory swap strategy corresponding to the target priority can be determined according to the above mapping relationship.
[0076] In some embodiments, the above priorities are positively correlated with the application's memory usage requirements and the importance of the application. When determining the memory exchange strategy corresponding to the target priority based on the target user identifier, it can be determined whether the target priority is the first priority (i.e., the highest priority). If the target priority is the first priority, the memory exchange strategy corresponding to the target priority is determined to be the first strategy that does not perform memory swapping, and the first strategy is used as the memory exchange strategy corresponding to the target memory group, and the first priority is the highest priority; if the target priority is not the first priority, the target algorithm corresponding to the target priority is determined from a variety of page swap algorithms, and the memory exchange strategy corresponding to the target algorithm is used as the memory exchange strategy corresponding to the target memory group. In other words, for the highest priority, the corresponding application's memory usage requirements and the importance of the application are the highest, so for the memory pages in the memory group corresponding to the priority, it is not necessary to swap out to avoid affecting the operation of the application; and for other priorities that are not the highest priority, the corresponding page swap algorithm can be used for memory swap management, wherein the multiple page swap algorithms can be LRU algorithm, FIFO algorithm, clock page replacement algorithm, least frequently used replacement (Least Frequently Used, LFU) algorithm, etc. For other priorities other than the highest priority, the accuracy of swapping out pages can be determined based on a variety of page algorithms, and a corresponding page swap algorithm is set for each other priority level. For priorities other than the first priority level, the higher the priority level, the higher the accuracy of the corresponding page swap algorithm in determining the swapping out pages.
[0077] In a possible implementation, the priority of the application can be divided into a first priority, a second priority and a third priority, wherein the first priority is the highest priority, the second priority is lower than the first priority, and the third priority is lower than the second priority; the multiple page interaction algorithms may include an LRU algorithm and a FIFO algorithm. It can be understood that the priority corresponding to the UID is divided according to at least one of the memory usage requirements of the application corresponding to the UID and the importance of the application, so the memory usage requirements and the importance of the application corresponding to the first priority are the highest, the memory usage requirements and the importance of the application corresponding to the second priority are the second, and the memory usage requirements and the importance of the application corresponding to the third priority are the lowest. Therefore, if the target priority is the second priority, since the LRU algorithm has a high accuracy in determining the memory page to be swapped out, the LRU algorithm can be determined from multiple page swap algorithms, and the second strategy corresponding to the LRU algorithm is used as the memory swap strategy corresponding to the target memory group; if the target priority is the third priority, since the FIFO algorithm consumes less processing resources when determining the memory page to be swapped out, the FIFO algorithm can be determined from multiple page swap algorithms, and the third strategy corresponding to the FIFO algorithm is used as the memory swap strategy corresponding to the target memory group.
[0078] Step S330: Based on the memory swap policy corresponding to the target memory group, memory swap management is performed on the memory pages in the target memory group.
[0079] In the embodiment of the present application, step S330 can refer to the contents of other embodiments and will not be repeated here.
[0080] The memory management method provided in the embodiment of the present application divides the memory pages of the application into corresponding memory groups according to the UID corresponding to the application, and then determines the memory swap strategy corresponding to the priority according to the priority corresponding to the UID, and then performs memory swap management on the memory pages in the memory group according to the determined memory swap strategy, thereby realizing targeted memory swap management of the memory pages of the application and improving the accuracy of memory swap management.
[0081] See also Figure 6 , Figure 6 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 6 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0082] Step S410: Based on a target user identifier corresponding to a currently running target application, memory pages corresponding to the target application are divided into target memory groups.
[0083] In the embodiment of the present application, step S410 can refer to the contents of other embodiments and will not be repeated here.
[0084] Step S420: Based on the correspondence between different user identifiers and memory exchange policies, determine the memory exchange policy corresponding to the target user identifier as the memory exchange policy corresponding to the target memory group.
[0085] In an embodiment of the present application, the electronic device may pre-store a correspondence between different UIDs and memory exchange strategies. The correspondence may be determined based on the memory usage requirements of applications with different UIDs and the importance of the applications. The memory usage requirements may include memory access speed, memory access frequency, etc. The importance of the application may be determined based on the number of historical runs and the historical running duration. For example, the importance of the application may be positively correlated with the number of historical runs and the historical running duration. When determining the memory exchange strategy corresponding to the target memory group, the memory exchange strategy corresponding to the target UID may be determined based on the correspondence, and used as the memory exchange strategy corresponding to the target memory group.
[0086] In some embodiments, the application's memory usage requirements and the importance of the application can be divided into three levels. For the application with the highest level of usage requirements or the highest level of importance, the memory exchange policy corresponding to its UID can be determined as a policy of not performing memory exchange, that is, when the electronic device performs memory exchange management, it will not determine the memory pages that need to be swapped out from the target memory group; for the application with a secondary level of usage requirements or a secondary level of importance, the memory exchange policy corresponding to its UID can be determined as a policy corresponding to the LRU algorithm; for the application with the lowest level of usage requirements or the lowest level of importance, the memory exchange policy corresponding to its UID can be determined as a policy corresponding to the FIFO algorithm. In this way, a correspondence between different UIDs and memory exchange policies can be established. Of course, the above correspondence is only an example, and the actual correspondence can be determined based on the available memory exchange policies and the needs of memory exchange management.
[0087] Step S430: performing memory swap management on memory pages in the target memory group based on the memory swap policy corresponding to the target memory group.
[0088] In the embodiment of the present application, step S430 can refer to the contents of other embodiments and will not be repeated here.
[0089] The memory management method provided in the embodiment of the present application divides the memory pages of an application into corresponding memory groups according to the UID corresponding to the application, and then determines the corresponding memory exchange strategy according to the correspondence between different UIDs and memory exchange strategies, and performs memory exchange management on the memory pages in the memory group according to the determined memory exchange strategy, thereby realizing targeted memory exchange management of the memory pages of the application and improving the accuracy of memory exchange management.
[0090] See also Figure 7 , Figure 7 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 7 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0091] Step S510: Based on a target user identifier corresponding to a currently running target application, memory pages corresponding to the target application are divided into target memory groups.
[0092] In the embodiment of the present application, step S510 can refer to the contents of the aforementioned embodiment and will not be described again here.
[0093] Step S520: If it is determined based on the memory swap policy corresponding to the target memory group that the target memory page in the target memory group needs to be swapped out, the target memory page is swapped out to the target storage area corresponding to the target memory group.
[0094] In an embodiment of the present application, when memory exchange management is performed on the memory pages in the target memory group based on the memory exchange strategy corresponding to the target memory group, if it is determined that the target memory page in the target memory group needs to be swapped out, the target memory page can be swapped out to the target storage area corresponding to the target memory group. For example, the above memory exchange strategy is a strategy corresponding to the LRU algorithm. If it is determined that the page that has not been accessed for the longest time in the target memory group is the target memory page, then the target memory page is the memory page that needs to be swapped out; for another example, the above memory exchange strategy is a strategy corresponding to the FIFO algorithm. If it is determined that the memory page that first enters the cache in the target memory group is the target memory page, then the target memory page is the memory page that needs to be swapped out. Among them, the target memory area can be a compressed memory area, a flash memory, or an area in a disk. It can be understood that corresponding to different memory groups, the memory pages therein can set corresponding swap areas to achieve that the memory pages in the memory group can be swapped out to the corresponding destination (i.e., the target storage area).
[0095] In some embodiments, when it is determined that the target memory page in the target memory group needs to be swapped out, the target priority corresponding to the target UID can be determined, and then the swap area corresponding to the target priority can be determined as the target storage area. The data read and write speeds of the swap areas corresponding to different priorities are different; the target memory page is swapped out to the target storage area. Among them, the division method of the priorities corresponding to different UIDs can refer to the content of the aforementioned embodiment, which will not be repeated here. Since the application programs corresponding to UIDs of different priorities have different memory usage requirements and importance, the speeds of swapping out the memory pages and swapping the data of the memory pages back to the memory are different, and the swap destination will affect the speed of swapping out and swapping back the memory pages. Therefore, 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. 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 the flash memory, and the swap area corresponding to the third priority can be a storage area in the disk.
[0096] The memory management method provided in the embodiment of the present application divides the memory pages of an application into corresponding memory groups according to the UID corresponding to the application, and then performs memory swap management on the memory pages in the memory group according to the memory swap policy corresponding to the memory group, thereby achieving targeted memory swap management on the memory pages of the application and improving the accuracy of memory swap management; in addition, when it is determined that the target memory page in the memory group needs to be swapped out, the target memory page is 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.
[0097] See also Figure 8 , Figure 8 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 8 The process shown is described in detail, and the memory management method may specifically include the following steps:
[0098] Step S610: Obtain current device status information.
[0099] In the embodiment of the present application, the device status information may include the current remaining memory size, the current system time, the number of currently running applications, etc. Understandably, considering that when an electronic device performs memory swap management on the memory, it is mainly when there is insufficient memory (for example, the remaining memory is less than the set memory threshold, the memory requirements of the current process cannot be met, and memory space cannot be allocated for new processes, etc.), that the memory pages that need to be swapped out are selected and swapped out to other storage areas. Therefore, the current device status information of the electronic device can be obtained, and the situation in which the electronic device may need to perform memory swap management can be determined based on the device status information, and then the memory pages are grouped and memory swap management is performed.
[0100] Step S620: if the device status information satisfies the memory grouping condition, the memory page corresponding to the target application is divided into a target memory group based on the target user identifier corresponding to the currently running target application.
[0101] In an embodiment of the present application, after obtaining the current device status information, it can be determined whether the device status information satisfies the memory grouping conditions; if the device status information satisfies the memory grouping conditions, it indicates that the electronic device may be about to perform memory exchange management, so the memory pages corresponding to the target application can be divided into the target memory group based on the target UID corresponding to the currently running target application; if the device status information does not meet the memory grouping conditions, the memory pages of the application may not be grouped. Among them, in the case where the device status information meets the memory grouping conditions, the memory pages corresponding to each running application can be divided into the corresponding memory group according to the UID corresponding to the application. In this way, it is possible to group the memory pages of the running applications before the electronic device may perform memory exchange management, so that before performing memory exchange management, the memory pages in the memory group can be managed according to the memory exchange policy of each memory group.
[0102] In some implementations, the above device status information may include the remaining memory size. If the remaining memory size is not greater than the first threshold and greater than the second threshold, it can be determined that the device status information meets the memory grouping condition. The second threshold is a threshold for triggering the electronic device to perform memory swap management. That is, when the remaining memory size is not greater than the second threshold, the memory swap management will be triggered. In this way, the memory pages of the running application can be grouped when the remaining memory size is small but the memory swap management is not triggered.
[0103] In some embodiments, the above device status information may include the current system time. If the current system time is in a preset time period, it can be determined that the device status information meets the memory grouping condition, wherein the preset time period is a predetermined time period when the memory occupancy rate of the electronic device is high. It can be understood that when the current time is in a time period when the memory occupancy rate of the electronic device is high, the electronic device is likely to perform memory exchange management due to insufficient memory, so in this case, the memory pages of the application can be grouped.
[0104] In some implementations, the above device status information may include the number of currently running applications. If the number of currently running applications is greater than the target number, it can be determined that the device status information meets the memory grouping condition. The specific value of the target number may not be limited, for example, it may be 5, 8, 15, etc. It can be understood that when the number of currently running applications is greater than the target number, the electronic device is running more applications and it is very likely that more processes will be added, resulting in insufficient memory. Therefore, in this case, the memory pages of the applications may also be grouped.
[0105] In the above implementation, the electronic device groups the memory pages corresponding to the application only when its current device status information meets the memory grouping condition, that is, the memory group will exist only when the device status information meets the memory grouping condition. Therefore, when the current device status information does not meet the memory grouping condition, there is no memory group, that is, the electronic device manages all existing memory pages uniformly, so a preset memory exchange strategy can be used to perform memory exchange management on all existing memory pages.
[0106] Step S630: Based on the memory swap policy corresponding to the target memory group, memory swap management is performed on the memory pages in the target memory group.
[0107] In the embodiment of the present application, step S630 can refer to the contents of the aforementioned embodiment and will not be described again here.
[0108] The memory management method provided in the embodiment of the present application obtains the current device status information of the electronic device. When the device status information meets the memory grouping condition, the memory pages of the application are divided into corresponding memory groups according to the user identifier corresponding to the application, and then the memory pages in the memory group are managed by memory exchange according to the memory exchange policy corresponding to the memory group. This method can not only realize targeted memory exchange management of the memory pages of the application and improve the accuracy of memory exchange management, but also can reduce the consumption of processing resources by eliminating the need to perform memory exchange management for each memory group separately when the device status information does not meet the memory grouping condition.
[0109] See also Fig. 9 , which shows a structural block diagram of a memory management device 700 provided in an embodiment of the present application. The memory management device 700 applies the above-mentioned electronic device, and the memory management device 700 includes: a memory grouping module 710 and a memory exchange module 720. Among them, the memory grouping module 710 is used to divide the memory pages corresponding to the target application into a target memory group based on the target user identifier corresponding to the currently running target application; the memory exchange module 720 is used to perform memory exchange management on the memory pages in the target memory group based on the memory exchange policy corresponding to the target memory group.
[0110] In some implementations, the memory grouping module 710 may be specifically configured to determine the memory page corresponding to the target user identifier based on the target user identifier corresponding to the currently running target application; and to divide the memory page corresponding to the target user identifier into a target memory group.
[0111] In a possible implementation, the memory grouping module 710 may also be used to determine all processes corresponding to the target user identifier as target processes; and determine the memory pages corresponding to the target processes as the memory pages corresponding to the target user identifier.
[0112] In a possible implementation, the memory grouping module 710 can also be used to determine the target priority corresponding to the target user identifier; divide the memory page corresponding to the target user identifier into a target memory group corresponding to the target priority, wherein the target memory group includes memory pages corresponding to user identifiers of the same priority.
[0113] In a possible implementation, the memory grouping module 710 may also be used to establish a target memory group corresponding to the target user identifier, and divide the memory pages corresponding to the target user identifier into the target memory group, wherein different user identifiers correspond to different memory groups.
[0114] In some embodiments, the memory management device 700 may further include a policy determination module, which may be used to determine a memory exchange policy corresponding to the target priority based on the target priority corresponding to the target user identifier before performing memory exchange management on the memory pages in the target memory group based on the memory exchange policy corresponding to the target memory group, as the memory exchange policy corresponding to the target memory group, wherein different memory exchange policies correspond to different priorities.
[0115] In one possible implementation, the policy determination module can be specifically used to, if the target priority is the first priority, determine the memory swap policy corresponding to the target priority as the first policy of not performing memory swapping, and use the first policy as the memory swap policy corresponding to the target memory group, and the first priority is the highest priority; if the target priority is not the first priority, determine the target algorithm corresponding to the target priority from multiple page swap algorithms, and use the memory swap policy corresponding to the target algorithm as the memory swap policy corresponding to the target memory group.
[0116] Optionally, the policy determination module can also be used to, if the target priority is the second priority, determine the least recently used algorithm from multiple page swap algorithms, and use the second policy corresponding to the least recently used algorithm as the memory swap policy corresponding to the target memory group, and the second priority is less than the first priority; if the target priority is the third priority, determine the first-in-first-out algorithm from multiple page swap algorithms, and use the third policy corresponding to the least recently used algorithm as the memory swap policy corresponding to the target memory group, and the third priority is less than the second priority.
[0117] In some embodiments, the memory management device 700 may further include a policy determination module, which may be used to determine the memory exchange policy corresponding to the target user identifier based on the correspondence between different user identifiers and memory exchange policies, as the memory exchange policy corresponding to the target memory group, before performing memory exchange management on the memory pages in the target memory group based on the memory exchange policy corresponding to the target memory group.
[0118] In some embodiments, the memory exchange module 720 can be specifically used to swap out the target memory page to the target storage area corresponding to the target memory group if it is determined that the target memory page in the target memory group needs to be swapped out based on the memory exchange policy corresponding to the target memory group.
[0119] In a possible implementation, the memory exchange module 720 can also be used to determine the target priority corresponding to the target user identifier if it is determined based on the memory exchange policy corresponding to the target memory group that the target memory page in the target memory group needs to be swapped out; determine the swap area corresponding to the target priority as the target storage area, the data reading and writing speeds of the swap areas corresponding to different priorities being different; and swap out the target memory page to the target storage area.
[0120] In some embodiments, the memory grouping module 710 can be specifically used to obtain current device status information; if the device status information meets the memory grouping conditions, the memory pages corresponding to the target application are divided into the target memory group based on the target user identifier corresponding to the currently running target application.
[0121] 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.
[0122] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0123] 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.
[0124] To summarize, the solution provided by the present application divides the memory pages of an application into corresponding memory groups according to the user identifier corresponding to the application, and then performs memory swap management on the memory pages in the memory group according to the memory swap policy corresponding to the memory group, thereby achieving targeted memory swap management of the memory pages of the application and improving the accuracy of memory swap management.
[0125] 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.
[0126] 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.
[0127] 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.
[0128] 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 800 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0129] The computer readable storage medium 800 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer readable storage medium 800 has storage space for program code 810 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 810 can be compressed, for example, in an appropriate form.
[0130] 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: Based on a target user identifier corresponding to a currently running target application, the memory page corresponding to the target application is divided into a target memory group; Based on the memory swap policy corresponding to the target memory group, memory swap management is performed on the memory pages in the target memory group.
2. The method according to claim 1, characterized in that The dividing the memory pages corresponding to the target application into the target memory group based on the target user identifier corresponding to the currently running target application comprises: Based on a target user identifier corresponding to a currently running target application, determining a memory page corresponding to the target user identifier; The memory page corresponding to the target user identifier is divided into a target memory group.
3. The method according to claim 2, characterized in that The determining, based on a target user identifier corresponding to a currently running target application, a memory page corresponding to the target user identifier, comprises: Determine all processes corresponding to the target user identifier as target processes; The memory page corresponding to the target process is determined as the memory page corresponding to the target user identifier.
4. The method according to claim 2, characterized in that: The dividing the memory page corresponding to the target user identifier into a target memory group includes: Determine the target priority corresponding to the target user identifier; The memory page corresponding to the target user identifier is divided into a target memory group corresponding to the target priority, wherein the target memory group includes memory pages corresponding to user identifiers of the same priority.
5. The method according to claim 2, characterized in that: The dividing the memory page corresponding to the target user identifier into a target memory group includes: A target memory group corresponding to the target user identifier is established, and memory pages corresponding to the target user identifier are divided into the target memory group, wherein different user identifiers correspond to different memory groups.
6. The method according to claim 1, characterized in that Before performing memory swap management on the memory pages in the target memory group based on the memory swap policy corresponding to the target memory group, the method further includes: Based on the target priority corresponding to the target user identifier, a memory exchange policy corresponding to the target priority is determined as the memory exchange policy corresponding to the target memory group, wherein different memory exchange policies correspond to different priorities.
7. The method according to claim 6, characterized in that The determining, based on the target priority corresponding to the target user identifier, a memory swap policy corresponding to the target priority as the memory swap policy corresponding to the target memory group includes: If the target priority is the first priority, determining that the memory swap policy corresponding to the target priority is the first policy that does not perform memory swapping, and using the first policy as the memory swap policy corresponding to the target memory group, the first priority being the highest priority; If the target priority is not the first priority, a target algorithm corresponding to the target priority is determined from a plurality of page swap algorithms, and a memory swap policy corresponding to the target algorithm is used as a memory swap policy corresponding to the target memory group.
8. The method according to claim 7, characterized in that If the target priority is not the first priority, determining a target algorithm corresponding to the target priority from a plurality of page swap algorithms, and using a memory swap strategy corresponding to the target algorithm as a memory swap strategy corresponding to the target memory group, including: If the target priority is the second priority, determining a least recently used algorithm from a plurality of page swap algorithms, and using a second strategy corresponding to the least recently used algorithm as a memory swap strategy corresponding to the target memory group, the second priority being lower than the first priority; If the target priority is the third priority, a first-in-first-out algorithm is determined from a plurality of page swap algorithms, and a third strategy corresponding to the least recently used algorithm is used as a memory swap strategy corresponding to the target memory group, and the third priority is lower than the second priority.
9. The method according to claim 1, characterized in that: Before performing memory swap management on the memory pages in the target memory group based on the memory swap policy corresponding to the target memory group, the method further includes: Based on the correspondence between different user identifiers and memory exchange policies, the memory exchange policy corresponding to the target user identifier is determined as the memory exchange policy corresponding to the target memory group.
10. The method according to any one of claims 1 to 9, characterized in that: The performing memory swap management on the memory pages in the target memory group based on the memory swap policy corresponding to the target memory group includes: If it is determined based on the memory swap policy corresponding to the target memory group that the target memory page in the target memory group needs to be swapped out, the target memory page is swapped out to the target storage area corresponding to the target memory group.
11. The method according to claim 10, characterized in that If it is determined that a target memory page in the target memory group needs to be swapped out based on the memory swap policy corresponding to the target memory group, swapping out the target memory page to a target storage area corresponding to the target memory group includes: If it is determined that the target memory page in the target memory group needs to be swapped out based on the memory swap policy corresponding to the target memory group, then determining the target priority corresponding to the target user identifier; 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; The target memory page is swapped out to the target storage area.
12. The method according to any one of claims 1 to 9, characterized in that: The dividing the memory pages corresponding to the target application into the target memory group based on the target user identifier corresponding to the currently running target application comprises: Get the current device status information; If the device status information satisfies the memory grouping condition, the memory page corresponding to the target application is divided into a target memory group based on a target user identifier corresponding to the currently running target application.
13. A memory management device, characterized in that: The device comprises: a memory grouping module and a memory switching module, wherein: The memory grouping module is used to divide the memory pages corresponding to the target application program currently running into the target memory group based on the target user identifier corresponding to the target application program currently running; The memory exchange module is used to perform memory exchange management on the memory pages in the target memory group based on the memory exchange policy corresponding to the target memory group.
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.