Memory management method and device, electronic equipment and computer readable medium
By grouping processes running in the Android system and allocating memory replacement policies for each group, the problem of lack of flexibility in the Swap memory management strategy in the existing technology is solved, and more reasonable memory swap operations and higher system performance are achieved.
Patent Information
- Application Number
- CN202311092833.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-28
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, the Swap memory management policy settings are not reasonable enough. The threads of each application are treated equally in Swap memory, lack flexibility, and cannot be distinguished based on the importance or sensitivity of the application.
By obtaining multiple processes currently running by the electronic device, grouping operations are performed according to the process identification of each process, obtaining the corresponding group of each process identification, and assigning the corresponding memory replacement policy to each group, determining the target memory page to be swapped based on the memory replacement policy of the target group, and performing the memory swapping operation.
The targeted settings of cache replacement policies for different groups are realized, making the memory swap operation more reasonable and improving system performance and user experience.
Smart Images

Figure CN119536615A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory technology, and more specifically, to a memory management method, device, electronic device and computer-readable medium. Background Art
[0002] In Android or other Linux-based systems, Swap is a traditional memory management strategy that allows the operating system to "swap out" data in memory to the hard disk (or other storage media) to free up memory space for other processes. When the "swapped out" data is needed again, the operating system will "swap it back" from the hard disk to the memory. However, the current settings for the swap operation are not reasonable enough. Summary of the invention
[0003] The present application proposes a memory management method, device, electronic device and computer-readable medium to improve the above-mentioned defects.
[0004] In a first aspect, an embodiment of the present application provides a memory management method, including: obtaining multiple processes currently running on an electronic device, each of the processes corresponding to at least one memory page; performing a grouping operation according to a process identifier of each process to obtain a group corresponding to each process identifier; assigning a corresponding memory replacement strategy to each group; determining a target memory page to be swapped out corresponding to the target group based on the memory replacement strategy corresponding to the target group; and performing a memory swapping operation on the target memory page.
[0005] In the second aspect, the embodiment of the present application also provides a memory management device, including: an acquisition unit, a grouping unit, an allocation unit, a determination unit and an operation unit. The acquisition unit is used to acquire multiple processes currently running on the electronic device, each of which corresponds to at least one memory page; the grouping unit is used to perform a grouping operation according to the process identifier of each process to obtain a group corresponding to each process identifier; the allocation unit is used to assign a corresponding memory replacement strategy to each group; the determination unit is used to determine the target memory page to be swapped out corresponding to the target group based on the memory replacement strategy corresponding to the target group; the operation unit is used to perform a memory swap operation on the target memory page.
[0006] In a third aspect, an embodiment of the present application also provides an electronic device, comprising: one or more processors; a swap area; one or more applications, wherein the one or more applications are stored in the swap area and configured to be executed by the one or more processors, and the one or more applications are configured to execute the above method.
[0007] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the readable storage medium stores a program code executable by a processor, and when the program code is executed by the processor, the processor executes the above method.
[0008] The memory management method, device, electronic device and computer-readable medium provided by the present application obtain multiple processes currently running on the electronic device, perform grouping operations according to the process ID of each process, obtain the group corresponding to each process ID, assign a corresponding memory replacement strategy to each group, determine the target memory page to be swapped out corresponding to the target group based on the memory replacement strategy corresponding to the target group; and perform a memory swap operation on the target memory page. Therefore, the process ID of each currently running thread can be grouped, so that corresponding cache replacement strategies can be set for different groups, making the setting of cache replacement strategies more targeted and making the setting of swap-out operations more reasonable.
[0009] Other features and advantages of the embodiments of the present application will be described in the subsequent description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purposes and other advantages of the embodiments of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0011] Figure 1 A method flow chart of a memory management method provided by an embodiment of the present application is shown;
[0012] Figure 2 A method flow chart of a memory management method provided by another embodiment of the present application is shown;
[0013] Figure 3 A method flow chart of a memory management method provided by another embodiment of the present application is shown;
[0014] Figure 4 A module block diagram of a memory management device provided by an embodiment of the present application is shown;
[0015] Figure 5 A structural block diagram of an electronic device provided in an embodiment of the present application is shown;
[0016] Figure 6A storage unit for storing or carrying program codes for implementing a memory management method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0017] In order to make those skilled in the art better understand the present application scheme, the technical scheme in the present application embodiment will be clearly and completely described below in conjunction with the drawings in the present application embodiment. Obviously, the described embodiment is only a part of the present application embodiment, rather than all the embodiments. The components of the present application embodiment usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the present application for protection, but merely represents the selected embodiment of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0018] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0019] Mobile computing technology is changing with each passing day, and handheld terminals represented by smart phones and tablet computers have also been widely popularized and applied. With the development of mobile computing technology, especially the great progress of mobile processor technology, the application scope of these handheld terminals has developed from traditional communication and camera functions to high-speed Internet access, 3D games, high-definition video and other functions commonly found in today's smart phones and tablet computers.
[0020] At present, in Android or other Linux-based systems of electronic devices, a memory management strategy Swap is set. For example, Swap is a traditional memory management strategy that allows the operating system to "swap out" the data in the memory to the hard disk (or other storage media) to free up memory space for other processes. When the "swapped out" data is needed again, the operating system will "swap it back" from the hard disk to the memory. The following are the main mechanisms of Linux Swap management:
[0021] 1.Swap Space: This is a special hard disk partition that is used by the system as a swap storage space. The size of the swap space is usually set by the system administrator during system installation or configuration, and is usually determined based on the system's RAM size and application requirements.
[0022] 2. Swapiness: This 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 data out to Swap Space, while a lower value indicates that the system is more inclined to keep data in memory as much as possible.
[0023] 3. 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 swapping is required, the system will select the page that has not been accessed for the longest time to swap out, because such a page is least likely to be needed again in the near future.
[0024] 4. Swap In & Swap Out: When the system memory is insufficient, Linux 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.
[0025] 5. Overcommit and OOM Killer: Linux system allows memory "overcommit", that is, the total amount of memory requested by the application can exceed the sum of physical RAM and Swap Space. When the over-allocated memory is really needed, if there is not enough memory space, the system will trigger the "Out Of Memory Killer" (OOM Killer) process, automatically ending some processes to free up memory space.
[0026] Then, the inventor found in the research that the current swap operation setting is not reasonable enough. That is, each thread of the application is treated equally when swapping memory, and all threads adopt the same memory management strategy, which is not flexible enough.
[0027] Therefore, in order to overcome the above defects, the present application embodiment provides a memory management method, such as Figure 1 The method comprises: S101 to S105.
[0028] S101: Acquire multiple processes currently running on the electronic device, each of the processes corresponding to at least one memory page.
[0029] An application (APP) is usually a collection of multiple programs, each program corresponds to at least one process, and each process corresponds to at least one thread, that is, a process can be single-threaded or multi-threaded. It can be understood that a process is an instance, that is, a process can correspond to a function of an application. For example, the video playback function of an application can be a process of the application. Usually, the process of an application when it is running is the main process, and each function under the application can be a sub-process of the main process.
[0030] As an implementation method, when a process is running, the process will be allocated at least one memory page. Specifically, multiple threads under the process will be allocated at least one memory space, which can refer to at least one memory page, wherein the memory page refers to the smallest unit for managing memory in the operating system. It is a way for the operating system to divide the physical memory and logical address space into blocks of equal size. In virtual memory management, the memory is divided into continuous fixed-size page frames, and the logical address space is divided into memory pages of the same size as the page frame. Each memory page contains a certain number of continuous bytes. Therefore, a process corresponds to at least one thread, and each thread corresponds to one less memory page, so each process corresponds to at least one memory page, and the data stored in the memory of each process refers to the data in the memory of each memory page corresponding to the process.
[0031] S102: Perform a grouping operation according to the process ID of each process to obtain a group corresponding to each process ID.
[0032] As an implementation method, a process corresponds to an identifier, which may be a process identifier (PID) of the process, that is, each group corresponds to a process identifier. For example, the multiple processes currently running on the electronic device include process 1, process 2, process 3, and process 4. The process identifier of process 1 is PID1, the process identifier of process 2 is PID2, the process identifier of process 3 is PID3, and the process identifier of process 4 is PID4. The grouping results of the multiple processes are shown in Table 1:
[0033] Table 1
[0034] Process Identifier Memory Pages Group PID1 Memory page 11, memory 12, memory page 13, memory page 14 Group 1 PID2 Memory page 21, memory 22, memory page 23 Group 2 PID3 Memory page 31, memory 32 Group 3 PID4 Memory page 41, memory 42, memory page 43, memory page 44 Group 4
[0035] It can be seen from Table 1 above that different processes correspond to different groups. Correspondingly, multiple memory pages corresponding to different processes also correspond to different groups. Therefore, the current multiple memory pages can be divided into different groups according to the process ID, thereby realizing the grouping of memory data.
[0036] In addition, as mentioned above, a process may correspond to multiple threads. After determining the corresponding group for each process, the threads under the process also correspond to the group. That is, each process corresponds to at least one thread, and all threads corresponding to each process belong to the group corresponding to the process. For example, the threads corresponding to the process of PID1 include thread 1, thread 2, and thread 3. Thread 1 corresponds to memory page 11, that is, the data of thread 1 is stored in memory page 11. Thread 2 corresponds to memory page 12, and thread 3 corresponds to memory page 13 and memory page 14. Therefore, thread 1, thread 2, and thread 3 also correspond to group 1.
[0037] As an implementation method, the first trigger condition for triggering the electronic device to group multiple running processes may include: 1.1. The remaining memory is less than a first threshold; 1.2. A new application is detected to be running; 1.3. The user actively triggers; 1.4. Sets a time period (a time period when the user is accustomed to using the mobile phone frequently); 1.5. Model prediction.
[0038] Exemplarily, the above-mentioned first trigger condition can also be understood as a condition for triggering the electronic device to perform memory recycling, wherein the implementation method of condition 1.1 is to obtain the remaining memory of the electronic device, determine whether the remaining memory is greater than the first threshold, and if it is greater than the first threshold, obtain multiple processes currently running in the electronic device and perform subsequent operations. Among them, the first threshold can be set according to actual use needs, which is used to characterize that the current memory usage rate is high, there is a risk of jamming, and the memory needs to be recycled. For condition 1.2, a detection module is provided in the electronic device. When a new application is started, the detection module can detect that there is a new application started. It can be understood that the new application refers to the application that has been started. For condition 1.3, the user's active triggering method can be that the user inputs a trigger request for instructing the electronic device to perform grouping and set a memory replacement strategy operation on a specified interface. The specified interface can be a memory management setting interface for setting the application. For example, the trigger request is input by operating a specified control of the specified interface, and the specified control can be a button.
[0039] For condition 1.4, the electronic device can set a time period, during which the electronic device will trigger grouping and subsequent operations. For example, after the electronic device enters the time period, the method of the embodiment of the present application is executed, that is, the currently running processes are grouped according to PID and subsequent operations are performed. After the grouping is completed, it is monitored in real time whether there are new processes or threads being run. If so, the new threads or processes are grouped according to PID. For condition 1.5, a detection model can be pre-trained, and the detection model can determine the jamming risk of the electronic device based on the operating parameters of the electronic device. If the jamming risk is greater than the specified risk, grouping and subsequent operations are triggered, wherein the operating parameters of the electronic device include memory usage, screen refresh rate, CPU usage, etc.
[0040] S103: Allocate a corresponding memory replacement strategy to each group.
[0041] As an implementation method, the memory replacement strategy refers to a strategy for determining the memory pages to be swapped out when there is a demand for memory recovery. Exemplarily, in an embodiment of the present application, the memory replacement strategy may include a least recently used algorithm (Least Recently Used, LRU), a first-in first-out algorithm (First-In First-Out, FIFO), and prohibition of swapping out, etc. Among them, the memory replacement strategies assigned to all groups may not be completely the same, that is, the memory replacement strategies corresponding to some groups are the same, and the memory replacement strategies corresponding to some groups are different, so that the corresponding memory replacement strategy can be configured for each group in a targeted manner.
[0042] Considering the differences between LRU and FIFO as follows: Replacement strategy: FIFO: According to the order in which data enters the cache, the first data to enter will be eliminated first, LRU: According to the recent use of the data, the data block that has not been used for the longest time will be eliminated; Cache elimination criteria: FIFO: Based on the order of time, the earliest data to enter the cache will be eliminated first, LRU: Based on the frequency and time of data use, the least recently used data will be eliminated first; Performance: FIFO: It has the advantages of being simple and easy to implement, but it may result in a low cache hit rate, because the recently used data may be eliminated when the cache is full, LRU: It is usually better at keeping the recently used data in the cache, so it can improve the cache hit rate. However, it is relatively complex to implement and requires the maintenance of a timestamp or access frequency record.
[0043] In general, FIFO eliminates data in order, while LRU eliminates data based on data usage. The choice of algorithm depends on the specific application scenario and the requirement for cache hit rate. If the access pattern of the data is independent of time, FIFO may be a simple and effective choice. If you want to replace data more accurately based on data usage and improve cache hit rate, then LRU may be more suitable. Therefore, based on the characteristics of each memory replacement strategy and the characteristics or usage requirements of each process, a corresponding memory replacement strategy can be set for each process group, without limitation here.
[0044] Among them, the memory replacement policy corresponding to some groups is to prohibit swapping out, that is, the group does not respond to swapout, and the memory pages of the group will not be set as the target memory pages to be swapped out when the operating system performs a swap-out operation. Of course, the memory pages of the group can be swapped out in other ways, for example, by manual cleaning.
[0045] S104: Determine the target memory page to be swapped out corresponding to the target group based on the memory replacement policy corresponding to the target group.
[0046] As an implementation manner, the second trigger condition for triggering memory recycling may be:
[0047] 2.1. Insufficient memory: When the system memory resources are tight and cannot meet the memory requirements of the currently running process, the operating system will choose to move part of the process data and status out to the swap space or page file to release memory resources. This can be done by checking the gap between the available memory and the required memory to determine whether a Swap Out operation is required. Specifically, the electronic device may obtain the current remaining memory and determine whether the remaining memory is less than a second threshold. If it is less than the second threshold, it is determined that the second trigger condition is met, that is, the operation of S104 is performed, wherein the second threshold can be set based on actual use. For example, the second threshold can be less than the first threshold, so that when the aforementioned first trigger condition includes condition 1, the grouping can be completed before the remaining memory is less than the second threshold, that is, it can be submitted to provide policy support for memory recovery.
[0048] 2.2. Background task optimization: In some cases, the operating system may optimize the resource usage of background tasks to provide better response performance to foreground tasks. When the system detects that background tasks occupy more memory resources, it may choose to move some background task data and status to the swap space, thereby freeing up memory for foreground tasks to use.
[0049] It should be noted that the triggering conditions of the Swap Out operation are related to the configuration of the operating system and hardware devices. Different operating systems may adopt different strategies to decide when to perform the Swap Out operation, such as judging based on memory usage, process priority, and user settings. In actual applications, the operating system will dynamically manage memory resources according to the memory management strategy to achieve optimal performance and resource utilization efficiency. The aforementioned second trigger is just two examples. This application does not impose any restrictions on the triggering conditions for memory reclaim.
[0050] It is understandable that the operating system usually uses various memory replacement strategies (such as LRU algorithm, FIFO algorithm, clock algorithm, etc.) to manage pages in memory. When memory space needs to be allocated for a new page or process, if there is not enough free memory, the system will select some loaded pages for replacement according to the memory replacement strategy, that is, perform a Swap Out operation.
[0051] Therefore, an implementation method for detecting that a target group needs to be swapped out may be that, when the electronic device satisfies the second trigger condition, the operating system of the electronic device determines that the target group needs to be swapped out. The target group may be at least one of the multiple groups. As an implementation method, the group whose corresponding strategy is to prohibit the swapping algorithm does not need to perform the operations of determining the target memory page to be swapped out and performing subsequent memory swapping, while the group whose strategy is to prohibit the use of algorithms other than the swapping algorithm shall be used as the target group, that is, all of them shall be required to perform the operations of determining the target memory page to be swapped out and performing subsequent memory swapping.
[0052] S105: Perform a memory swap-out operation on the target memory page.
[0053] It is understandable that the data of the target memory page in the memory can be moved out to the specified swap area, which can be a hard disk or other storage medium. As an implementation method, the interactive areas corresponding to all processes can be the same or different areas in the same storage medium, or areas of different storage media, which will be described in detail in the subsequent embodiments.
[0054] Therefore, the embodiment of the present application obtains multiple processes currently running on the electronic device, performs a grouping operation according to the process ID of each process, obtains the group corresponding to each process ID, assigns a corresponding memory replacement strategy to each group, and determines the target memory page to be swapped out corresponding to the target group based on the memory replacement strategy corresponding to the target group; and performs a memory swap-out operation on the target memory page. Therefore, the process ID of each currently running thread can be grouped, so that corresponding cache replacement strategies can be set for different groups, making the setting of the cache replacement strategy more targeted and making the setting of the swap-out operation more reasonable.
[0055] See also Figure 2 , an embodiment of the present application provides a memory management method, specifically, the method includes: S201 to S206.
[0056] S201: Acquire multiple processes currently running on the electronic device, each of the processes corresponding to at least one memory page.
[0057] S202: Perform a grouping operation according to the process ID of each process to obtain a group corresponding to each process ID.
[0058] S203: Allocate a corresponding memory replacement strategy to each group.
[0059] S204: Determine the target memory page to be swapped out corresponding to the target group based on the memory replacement policy corresponding to the target group.
[0060] It should be noted that the contents of the aforementioned steps that are not described in detail can be referred to the aforementioned embodiments and will not be repeated here.
[0061] S205: Determine the target swap area corresponding to the target memory page.
[0062] As an implementation method, the target interactive area may be a storage area for storing data swapped out of the memory, and the target swap area may be a designated memory area, a memory compression area, a flash memory or a hard disk, etc., wherein the designated memory area may be an area of the same type as the storage area of the target page in the memory, or the designated memory area is the corresponding storage area of the target memory page in the memory. Therefore, if the designated memory area is selected as the target swap area, the purpose is not to swap out the target memory page. The memory compression area is an area in the memory dedicated to performing memory compression operations, that is, a storage area is set in the memory, and the data stored in the storage area will be subjected to memory compression operations. Among them, memory compression is a technology for compactly storing data in the memory to reduce memory usage. It compresses the data in the memory page, thereby providing more available memory space without increasing access delay. The principle of memory compression is to utilize the repetition and redundancy in the data. When there are multiple similar pages or duplicate data in the system, memory compression can convert these data into a more compact representation, thereby reducing memory usage. Common compression algorithms include dictionary coding, arithmetic coding, Huffman coding, etc.
[0063] As an implementation method, all groups may be set to the same target exchange area, or different target exchange areas may be set. Specifically, if all groups are set to the same target exchange area, the target exchange area may be set to a hard disk or a flash memory. If the target exchange areas corresponding to all groups are not all the same, the setting method may be to allocate a corresponding exchange area to each group, that is, each group has a corresponding exchange area, and the target exchange area may refer to a memory, or different storage areas in the same memory, which is not limited here.
[0064] As an implementation method, the swap area corresponding to each group is related to the memory replacement strategy corresponding to the group. For example, for a group whose memory replacement strategy is to prohibit swapping out algorithms, the corresponding swap area is a specified memory area or a memory compression area. For a group whose memory replacement strategy is to prohibit algorithms other than swapping out algorithms, for example, a group corresponding to an LRU or FIFO algorithm, the corresponding swap area is a flash memory or a hard disk.
[0065] S206: Transfer the data of the target memory page in the memory to the target swap area.
[0066] It should be noted that by setting a prohibition swap algorithm for a group, some groups may not perform memory swap operations. Of course, the target memory page corresponding to each group may be determined in another way. Specifically, a processing sequence may be pre-set, and the target memory page to be swapped out corresponding to each group may be determined in turn based on the processing sequence.
[0067] Specifically, after determining the multiple groups corresponding to the multiple processes currently running on the electronic device, a processing order is set for each combination, and a memory swap operation is performed on each group in sequence based on the order of the processing order from front to back, until. Specifically, when the electronic device meets the second trigger condition, the first group of the processing order is used as the target group, and based on the memory replacement strategy of the target group, the target memory page to be swapped out corresponding to the target group is determined, and the data of the target memory page of the target group in the memory is swapped out. After that, it is detected whether the electronic device meets the second trigger condition. If the second trigger condition is met, the group after the target group in the processing order is used as the new target group, and the memory replacement strategy based on the target group is returned to determine the target memory page to be swapped out corresponding to the target group and the subsequent steps of performing a swap operation on the target memory page, until all groups perform the swap operation or it is detected that the electronic device does not meet the second trigger condition.
[0068] As an implementation mode, in the processing sequence, the group that meets the specified condition is located at the back of the processing sequence, that is, among the multiple groups corresponding to the processes currently running on the electronic device, the group that meets the specified condition is determined, and in the processing sequence, the group that does not meet the specified condition is located at the front of the group that meets the specified condition. Thus, when the second trigger condition is met, when the aforementioned content is executed based on the processing sequence, the target memory page can be preferentially determined from the group that does not meet the specified condition, so that after the memory page of the group that does not meet the specified condition is swapped out, before the group that meets the specified condition is processed, it is possible that the memory swapping operation of the group that does not meet the specified condition has already made the electronic device have more memory space, that is, the electronic device does not need to meet the second trigger condition.
[0069] As an implementation method, the groups of the specified conditions can be pre-set. Since each group corresponds to a process identifier, and each process corresponds to an application, each group corresponds to an application. Then, the group that meets the specified conditions can be determined based on the application corresponding to the group. For example, a preset list can be set, and each process corresponding to each application in the preset list belongs to a specified process. Then, when grouping multiple processes currently running on the electronic device, the group corresponding to the specified process can be set to the group that meets the specified conditions.
[0070] See also Figure 3 , an embodiment of the present application provides a memory management method, specifically, the method includes: S301 to S306.
[0071] S301: Acquire multiple processes currently running on the electronic device, each of the processes corresponding to at least one memory page.
[0072] S302: Perform a grouping operation according to the process ID of each process to obtain a group corresponding to each process ID.
[0073] S303: Determine the importance category of the process corresponding to each group, where the importance category includes an important category and an unimportant category.
[0074] As an implementation mode, after the electronic device obtains the groups corresponding to the multiple processes currently running, the user can set the corresponding importance category for each group. Exemplarily, when the electronic device determines that the first trigger condition is met, the multiple processes currently running on the electronic device are obtained, the group corresponding to each process is determined, and then the grouping interface is displayed on the electronic device, and the user sets the importance category for each group in the grouping interface. As an implementation mode, the grouping interface displays the process ID corresponding to each group and the description information corresponding to the process ID. The description information is used to characterize the function of the process corresponding to the process ID. The user can understand the process corresponding to the description information through the description information, and thus set the importance category for the group corresponding to the process based on the function of the process.
[0075] As an implementation mode, the grouping interface may be a pop-up window, which is displayed on a designated interface of the electronic device. The designated interface may be the interface currently displayed by the electronic device when the electronic device detects that the first trigger condition is met. In addition, the designated interface may also be an interface corresponding to a setting application of the operating system. After the electronic device acquires multiple groups, a prompt message is displayed on the electronic device. The prompt message is used to instruct the user to set the importance type of each group. For example, the prompt message may be information displayed on the top status bar of the electronic device. The user clicks on the prompt message to display the designated interface and display the grouping interface within the designated interface. For example, the grouping interface may be the aforementioned pop-up window, and the corresponding importance type is set for each group through the grouping interface.
[0076] As another implementation, the importance category corresponding to each group can be set based on the category of the application to which the process of each group belongs. Exemplarily, after the electronic device obtains the group corresponding to each process currently running on the electronic device, the application corresponding to each group is determined, and the importance category of each process is determined based on the first parameter of the application. The first parameter may include the frequency of use and the type. For example, the importance category of the process corresponding to the application with a usage frequency greater than the specified frequency can be set to the important category, and the importance category of the process corresponding to the application with a usage frequency less than the specified frequency can be set to the unimportant category. For another example, the importance category of the process corresponding to the application of a preset type can be set to the important category, and the importance category of the process corresponding to the application other than the preset type can be set to the unimportant category. Among them, the preset type can be a type pre-set based on usage requirements. For example, the preset type can be a game type, a video type, etc.
[0077] As an implementation method, the attributes of a thread can be divided into a first attribute and a second attribute, wherein the first attribute is used to characterize that the thread is related to user perception, and the second attribute is used to characterize that the thread is not related to user perception. Specifically, user perception relevance may refer to at least one of the user's vision, hearing, and touch being perceived, that is, if the thread is the first attribute, it means that the thread is a thread related to user interaction. If the thread is the second attribute, it means that the thread is related to the user's vision, hearing, and touch, that is, it is not a thread related to user interaction.
[0078] As mentioned above, a process may include at least one thread, so after determining the group corresponding to each process, the attributes of each thread under each process are determined, and then the target proportion of threads with the first attribute under each process is determined. The target proportion refers to the ratio of the number of threads with the first attribute to the number of all threads corresponding to a process. The importance category of the process whose target proportion is greater than the specified threshold is determined as an important category, and the importance category of the process whose target proportion is less than or equal to the specified threshold is determined as an unimportant category.
[0079] As an implementation method, reference data of a thread is obtained, and thread attributes corresponding to the thread are determined based on the reference data of the thread. Exemplarily, the reference data of a thread may include identity information and operation data, and the identity information may include information used to characterize the identity of the thread, such as the name of the thread or the name of the application of the thread. The operation data of a thread refers to the operating environment or data generated by the thread when the application of the thread is running. For example, the operation data of the thread may include the running time, load, the type of CPU running, and the running cycle. Therefore, the reference data of each thread may include at least one of the name, running time, load, the type of CPU running, and the running cycle.
[0080] It should be noted that the running time of a thread can be the life cycle of the thread. Specifically, in the life cycle of a thread, it will go through five states: New, Runnable, Running, Blocked, and Dead. When a program creates a thread using the new keyword, the thread is in a new state (initial state). At this time, it is just like other Java objects. The Java virtual machine only allocates memory for it and initializes its member variable values. At this time, the thread object does not show any dynamic characteristics of the thread, and the program will not execute the thread execution body of the thread. When the thread object calls the Thread.start() method, the thread is in the ready state, and the Java virtual machine will create a method call stack and a program counter for it. The thread in this state does not start running, it just means that the thread can run. If the thread in the ready state obtains CPU resources, it starts to execute the thread execution body of the run method, and the thread is in the running state. The blocked state is when the thread gives up the right to use the CPU for some reason and temporarily stops running. Only when the thread enters the ready state can it have the opportunity to switch to the running state. When the run() method is executed, that is, when the technology is run, the thread will end normally. It should be noted that the running time of the thread can be the state from the creation of the thread to the end, or from the running to the end, which is not limited here.
[0081] The running parameter corresponding to the thread is load data, which can be the data processing volume of the thread, wherein the data processing volume can be the data processed by the thread per unit time. For example, if the thread is an audio playback thread, then the corresponding data processing volume is the audio data played per unit time. For another example, if the thread is a thread related to interface rendering, then the corresponding data processing volume is the image data rendered by the thread per unit time. In addition, the load data can also be the processor usage rate of the thread, that is, the CPU usage rate. In other words, the load data is the CPU usage rate occupied by the thread, that is, the resources allocated by the processor to the thread.
[0082] The types of CPUs can include large cores and small cores. Specifically, the type of CPU corresponds to the identifier of the CPU. For example, cpu0 to cpu3 are all small cores, and cpu4 to cpu7 are all large cores. Then, the identifier of the CPU on which the thread is running is determined, and then the type of CPU on which the thread is running is determined based on the correspondence between the CPU identifier and the type. Specifically, the CPU on which the thread is running refers to the thread running on the CPU, that is, the thread is in the task queue of the CPU. Specifically, each CPU has a task running queue, and the thread running on the CPU has its identifier in the task running queue of the CPU. Therefore, by checking the task running queue of the target processor, the CPU on which the target thread is running can be determined, and then the corresponding type of the CPU can be determined, that is, whether it is a large core or a small core.
[0083] The operation cycle of a thread refers to the operation interval of the thread, which can be the time interval between two consecutive operations of the thread. Specifically, the moment when the thread is run each time within a preset time period can be determined, and based on the moment when the thread is run each time, the average time interval between two consecutive operations of the thread within the preset time period can be determined as the operation cycle of the thread. As an implementation, the execution interval of a thread can characterize the time interval between the execution of the thread once and the execution of the thread again. For example, the thread is executed according to a specified time period, and therefore, the execution interval can be the time interval between two consecutive executions of the thread. For example, when displaying a video screen or playing audio, the time interval method is used to execute the threads related to the video screen display or audio playback at intervals, so that the screen is displayed or the audio is played at intervals, which can reduce power consumption and enable the user to perceive the continuity of the video screen or audio in terms of hearing and vision.
[0084] As an implementation method, the reference data of the multiple threads can be collected based on the Systrace software installed in the electronic device. Specifically, when the electronic device is running, the electronic device obtains the data collected by the Systrace software, that is, the Systrace file. By analyzing the Systrace file, the reference data of each thread of the electronic device can be obtained.
[0085] Specifically, the thread related to user interaction can refer to the thread used to obtain the operation data generated when the user operates the application, or the thread used to output data related to user perception. For the former, the user operation can be a sliding operation or a click operation on a certain interface of the application. If the application includes a thread that can detect sliding operations and click operations, then the thread belongs to the thread related to user interaction. For the latter, the output of data related to user perception can be data that can be perceived by the user's hearing or vision, such as playing audio data and video data.
[0086] In addition, the thread related to user interaction may also be a thread related to each display interface of the application, that is, a thread serving the display interface. For example, taking a video playback interface of an application as an example, a video playback control is provided on the video playback interface, and the thread used to serve the video playback control so that the video playback control can play the video belongs to the thread related to user interaction.
[0087] The aforementioned data related to user operations, data that can be perceived by users, or the interface displayed by the application are all data related to user interaction for users. Compared with some threads that run in the background and have no interaction with users, if the threads that can generate or obtain these data have a lag, the user can strongly feel it.
[0088] It should be noted that the classification model is pre-trained based on the reference data of the sample thread and the thread attributes of the sample thread that are marked. Exemplarily, the reference data of the sample thread and the thread attributes corresponding to the sample thread are input into the initial classification model. Specifically, each data in the reference data of each sample thread is used as a feature point, so that the reference data multiplied by each sample is used as the feature vector of the sample thread, and the attribute label of the thread attribute of the sample thread that is manually marked is used as the expected classification result of the thread. Then, the classification model obtains the actual classification result of the sample thread based on the feature vector of the sample thread, and trains the initial classification model based on the difference between the actual classification result and the expected classification result. Through continuous iterative training, the training of the initial classification model is completed, and the trained classification model can classify the thread into the first attribute and the second attribute based on the reference data of the thread.
[0089] S304: Allocate a corresponding memory replacement strategy to each group based on the importance category of the process corresponding to each group.
[0090] As an implementation method, the memory replacement policy includes the aforementioned LRU, FIFO and no swapping policies. The memory replacement policy of important processes can be set to no swapping, and the memory replacement policy of unimportant processes can be set to LRU or FIFO.
[0091] As an implementation method, the group of important analogies can be further divided into a first category and a second category, wherein the first category is more important than the second category. Taking the aforementioned method of dividing importance categories by target proportion as an example, specifically, the importance category of the process whose target proportion is greater than a specified threshold is an important category, and the importance category of the process whose target proportion is less than or equal to the specified threshold is an unimportant category. Furthermore, the importance category of the process whose target proportion is greater than a first threshold and less than a second threshold is set to the second category, and the importance category of the process whose target proportion is greater than the second threshold is set to the first category, wherein the first threshold is greater than or equal to the specified threshold, and the first threshold is less than the second threshold.
[0092] In addition, FIFO and LRU are two common page replacement algorithms used to manage page tables and caches in computer operating systems. Their main differences are as follows: FIFO: replace pages in the order they enter the memory, that is, the pages that enter the memory first will be replaced first, LRU: replace pages according to their usage time, that is, the least recently used pages will be replaced; FIFO: Since only the entry order of pages is considered, regardless of whether the pages are frequently used, the FIFO strategy will cause low-frequency pages to be retained in the memory for a long time, which may lead to a high page fault rate, LRU: By tracking the usage time of pages, the LRU strategy can more accurately identify pages that have not been used recently and replace them, thereby helping to reduce the page fault rate; FIFO: simple to implement, only need to maintain a page queue, LRU: more complex to implement, need to maintain a page access history or use a more efficient data structure (such as a bidirectional linked list in the LRU cache algorithm) to record the order of page usage.
[0093] In general, the FIFO policy is suitable for situations that are not very sensitive to the time characteristics of the page access pattern, while the LRU policy pays more attention to the actual usage of the page and can make relatively good use of cache and memory resources, but its implementation is relatively complex.
[0094] Therefore, the memory replacement policy of the first category group is to prohibit swapping out, the memory replacement policy of the second category group is LRU, and the memory replacement policy of the unimportant category group is FIFO.
[0095] S305: Determine the target memory page to be swapped out corresponding to the target group based on the memory replacement policy corresponding to the target group.
[0096] S306: Perform a memory swap-out operation on the target memory page.
[0097] See also Figure 4, which shows a structural block diagram of a memory management device 400 provided in an embodiment of the present application. The device may include: an acquisition unit 401, a grouping unit 402, an allocation unit 403, a determination unit 404 and an operation unit 405.
[0098] The acquisition unit 401 is used to acquire multiple processes currently running on the electronic device, each of which corresponds to at least one memory page.
[0099] The grouping unit 402 is used to perform a grouping operation according to the process identifier of each process to obtain a group corresponding to each process identifier.
[0100] The allocation unit 403 is used to allocate a corresponding memory replacement strategy to each group.
[0101] Furthermore, the allocation unit 403 is also used to determine the importance category of the process corresponding to each group, where the importance category includes an important category and an unimportant category; based on the importance category of the process corresponding to each group, a corresponding memory replacement strategy is allocated to each group.
[0102] The determination unit 404 is configured to determine the target memory page to be swapped out corresponding to the target group based on the memory replacement policy corresponding to the target group.
[0103] The operation unit 405 is configured to perform a memory swap-out operation on the target memory page.
[0104] Furthermore, the operation unit 405 is further configured to determine a target swap area corresponding to the target memory page; and transfer the data of the target memory page in the memory to the target swap area.
[0105] Furthermore, the operation unit 405 is further configured to determine the target swap area corresponding to the group where the target memory page is located based on the swap area corresponding to each group obtained in advance.
[0106] Furthermore, the operation unit 405 is further configured to allocate a corresponding swap area to each group before determining the target swap area corresponding to the target memory page.
[0107] Furthermore, the operation unit 405 is also used to perform a grouping operation according to the process identifier of each process. After obtaining the group corresponding to each process identifier, if a new process is detected to be running, the process identifier corresponding to the new process is determined, and the new process is used as the first process; it is determined whether there is a group corresponding to the identifier of the first process in the pre-obtained groups; if there is no group corresponding to the identifier of the first process, a new group is assigned to the first process.
[0108] Furthermore, each process corresponds to at least one thread, and all threads corresponding to each process belong to the group corresponding to the process.
[0109] 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.
[0110] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0111] 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.
[0112] Please refer to Figure 5 , 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, 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 swap area 120, and one or more applications, wherein the one or more applications may be stored in the swap area 120 and configured to be executed by one or more processors 110, and the one or more programs are configured to execute the method described in the aforementioned method embodiment.
[0113] 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 exchange area 120, and calling data stored in the exchange area 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.
[0114] The exchange area 120 may include a random access memory (RAM) or a read-only memory. The exchange area 120 may be used to store instructions, programs, codes, code sets or instruction sets. The exchange area 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.
[0115] Please refer to Figure 6 , which shows a structural block diagram of a computer-readable medium provided in an embodiment of the present application. The computer-readable medium 600 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0116] The computer readable medium 600 may be an electronic exchange area such as a flash memory, an EEPROM (Electrically Erasable Programmable Read-Only Exchange Area), an EPROM, a hard disk, or a ROM. Optionally, the computer readable medium 600 includes a non-transitory computer-readable storage medium. The computer readable medium 600 has storage space for program code 610 that performs any method steps in the above method. These program codes can be read from or written to one or more computer program products. The program code 610 can be compressed, for example, in a suitable form.
[0117] Therefore, the memory management method, device, electronic device and computer-readable medium provided by the present application obtain multiple processes currently running on the electronic device, perform grouping operations according to the process identifier of each process, obtain the group corresponding to each process identifier, assign a corresponding memory replacement strategy to each group, and determine the target memory page to be swapped out corresponding to the target group based on the memory replacement strategy corresponding to the target group; perform a memory swap operation on the target memory page. Therefore, the process identifier of each currently running thread can be grouped, so that corresponding cache replacement strategies can be set for different groups, making the setting of cache replacement strategies more targeted and making the setting of swap-out operations more reasonable.
[0118] In addition, all applications are treated equally when swapping memory, and cannot be differentiated based on the importance or sensitivity of the application. The swap management policy lacks flexibility and cannot be dynamically adjusted according to the nature or needs of the application. When the pages of important or sensitive applications are swapped out, it may affect performance. The inability to prioritize the replacement of pages that are not obvious to users may lead to a degraded user experience.
[0119] 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: include: Acquire multiple processes currently running on the electronic device, each of the processes corresponding to at least one memory page; Perform grouping operations according to the process ID of each process to obtain the group corresponding to each process ID; Assign a corresponding memory replacement strategy to each group; Determine the target memory page to be swapped out corresponding to the target group based on the memory replacement policy corresponding to the target group; A memory swap-out operation is performed on the target memory page.
2. The method according to claim 1, characterized in that The performing a memory swap-out operation on the target memory page comprises: Determine a target swap area corresponding to the target memory page; The data of the target memory page in the memory is transferred to the target swap area.
3. The method according to claim 2, characterized in that The determining the target swap area corresponding to the target memory page includes: Based on the pre-acquired swap area corresponding to each group, a target swap area corresponding to the group where the target memory page is located is determined.
4. The method according to claim 3, characterized in that Before determining the target swap area corresponding to the target memory page, the method further includes: Assign a corresponding swap area to each group.
5. The method according to claim 1, characterized in that The method further comprises: performing a grouping operation according to the process identifier of each process to obtain a group corresponding to each process identifier; If it is detected that a new process is running, a process identifier corresponding to the new process is determined, and the new process is used as the first process; Determining whether there is a group corresponding to the identifier of the first process among the pre-obtained groups; If there is no group corresponding to the identifier of the first process, a new group is allocated to the first process.
6. The method according to claim 1, characterized in that Each process corresponds to at least one thread, and all threads corresponding to each process belong to the group corresponding to the process.
7. The method according to any one of claims 1 to 6, characterized in that: The allocation of a corresponding memory replacement strategy to each group includes: Determine an importance category of the process corresponding to each group, wherein the importance category includes an important category and an unimportant category; Based on the importance category of the process corresponding to each group, a corresponding memory replacement strategy is assigned to each group.
8. A memory management device, characterized in that: include: An acquisition unit, used to acquire multiple processes currently running on the electronic device, each of the processes corresponding to at least one memory page; A grouping unit, used to perform a grouping operation according to the process ID of each process to obtain a group corresponding to each process ID; An allocation unit, used to allocate a corresponding memory replacement strategy to each group; A determination unit, configured to determine a target memory page to be swapped out corresponding to the target group based on a memory replacement policy corresponding to the target group; An operation unit is used to perform a memory swap-out operation on the target memory page.
9. An electronic device, characterized in that: include: one or more processors; Exchange area; One or more applications, wherein the one or more applications are stored in the swap area and are configured to be executed by the one or more processors, the one or more applications being configured to execute the method according to any one of claims 1-7.
10. A computer-readable medium, characterized in that The computer-readable medium stores a program code executable by a processor, and when the program code is executed by the processor, the processor executes the method according to any one of claims 1 to 7.
Citation Information
Cited By
Memory management method and device, electronic equipment, medium and computer program product
CN122044895A
Memory management method and apparatus, electronic device, medium, and computer program product
CN122044895B