Memory recovery method and terminal equipment

By introducing a memory recycling strategy based on application recycling priority and load status judgment into the terminal device, the problem of system crashes and freezes when the CPU or IO load is high is solved, the efficiency and flexibility of memory recycling are improved, and the recycling action is avoided. High load scenarios overlap.

CN118760618APending Publication Date: 2024-10-11SHANGHAI LONGCHEER INTELLIGENCE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410853790.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

When the CPU load or IO load is high, the memory reclamation process may cause the system to freeze or crash. It is difficult for existing technology to effectively manage memory reclamation to avoid such situations.

Method used

By introducing an application recycling priority mechanism into the system and judging by CPU and IO load status, recycling strategies are reasonably allocated, such as retaining foreground applications and recycling background applications during high loads, releasing page caches and anonymous pages, and grouping associated applications. Synchronize recycling to avoid overlap of memory recycling with high CPU load scenarios.

Benefits of technology

It improves memory recycling efficiency, avoids overlap between recycling actions and high CPU load scenarios, reduces the risk of system crashes and freezes, and makes memory recycling more intelligent and flexible.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760618A_ABST
    Figure CN118760618A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software, in particular to a memory recovery method and terminal equipment. According to the memory recovery method and device, applications in a system correspond to different recovery priorities, and the recovery priorities comprise the first recovery priority; under the condition that the number of the to-be-processed processes of the CPU is larger than the first CPU load set value, the IO load value of the system is judged; if the IO load value is larger than the first IO load set value, the foreground application is reserved, and all background applications are recycled; if the IO load value is larger than the second IO load set value and smaller than or equal to the first IO load set value, page caches of all the background applications are recycled, and the background applications corresponding to the first recycling priority are recycled. According to the memory recovery method, the recovery strategy is reasonably formulated according to the states of the IO load and the CPU load, the recovery efficiency is improved, the CPU computing power is prevented from being occupied when the memory is recovered, the recovery action can be prevented from being overlapped with the CPU high-load scene, and the system is not prone to being stuck or crashed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software technology, and in particular to a memory recovery method and terminal equipment. Background Art

[0002] Current smart terminals, especially Android phones, have various channels for acquiring applications, making it difficult to control the resource usage of applications from the source. When applying for page allocation, the page allocator first tries to allocate pages using the low watermark. If the allocation using the low watermark fails, it means that the memory is slightly insufficient. The page allocator will wake up the page recovery kernel thread of the memory node, asynchronously recover the page, and then try to allocate pages using the lowest watermark. If the allocation using the lowest watermark fails, it means that the memory is seriously insufficient, and the page allocator will directly recover the memory page. When memory is recovered, the memory to be recovered must be processed before it becomes free memory. If it is a page supported by swap, the page swap method is used to write the page data to the swap area first, and then release the physical page; there is also a type of file page supported by storage devices. If it is a clean page, that is, the file has not been modified after being read from the storage device to the memory, it can be released directly; if it is a dirty page, that is, the page has been modified after the file is read from the storage device to the memory, then it is first written back to the storage device, and then the physical page is released.

[0003] During the entire inner recycling process, when the CPU (Central Processing Unit) load is high or the IO (Input / Output) load is high, if it overlaps with the memory recycling process, it may cause the system to freeze or crash. Summary of the invention

[0004] The object of the present invention is to provide a memory recovery method and terminal device, so that when the CPU load or IO load is high, the system is not easily stuck or crashed due to the memory recovery process.

[0005] In order to solve the above technical problems, the present invention provides a memory recovery method and device, including:

[0006] Applications in the system correspond to different recycling priorities, and the recycling priorities include a first recycling priority;

[0007] When the number of CPU processes to be processed is greater than the first CPU load setting value, determining the IO load value of the system;

[0008] If the IO load value is greater than the first IO load setting value, the foreground application is retained and all background applications are recycled; if the IO load value is greater than the second IO load setting value and less than or equal to the first IO load setting value, the page cache of all background applications is recycled and the background application corresponding to the first recycling priority is recycled.

[0009] Furthermore, it also includes:

[0010] The applications in the system correspond to a plurality of set application types;

[0011] Some of the multiple set application types correspond to the first recycling priority, and another part corresponds to the second recycling priority.

[0012] Furthermore, the priority is defined according to the average memory consumption of each application type, and the greater the memory consumption, the higher the priority.

[0013] Further, the background applications with associated relationships are divided into groups to obtain multiple application groups;

[0014] If the IO load value is greater than the second IO load setting value and less than or equal to the first IO load setting value, and the number of CPU processes to be processed is greater than the first CPU load setting value but less than or equal to the second CPU load setting value, then when the current background application is recycled, all background applications in the same application group as the recycled application are synchronously recycled, and anonymous pages of all background applications are recycled.

[0015] Furthermore, recycling the background application includes: closing the background application and releasing memory.

[0016] Furthermore, reclaiming the page cache of the background application includes: directly releasing clean pages and / or releasing memory after writing the contents of dirty pages back to the disk.

[0017] Furthermore, reclaiming the anonymous page of the background application includes: saving the anonymous page to the swap space.

[0018] Furthermore, the first IO load setting value and the second IO load setting value are both positively correlated with the hardware queue depth of the disk and the software queue depth of the system.

[0019] Further, the maximum number of IO operations of the disk is equal to the sum of the hardware queue depth of the disk at a first set multiple and the software queue depth of the system at a second set multiple;

[0020] The first IO load setting value is a third setting multiple of the maximum number of IO operations of the disk, and the second IO load setting value is a fourth setting multiple of the maximum number of IO operations of the disk.

[0021] Furthermore, the value range of the third setting multiple is 0.4-0.5, and the value range of the fourth setting multiple is 0.2-0.3.

[0022] Furthermore, both the first CPU load setting value and the second CPU load setting value are positively correlated with the number of CPUs.

[0023] Furthermore, the first CPU load setting value is a fifth set multiple of the number of CPUs; and the second CPU load setting value is a sixth set multiple of the number of CPUs.

[0024] Furthermore, the value range of the fifth setting multiple is 1-2, and the value range of the sixth setting multiple is 4-5.

[0025] The present invention also provides a terminal device, including a CPU, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the CPU, the CPU and the storage medium communicate through the bus, and the CPU executes the machine-readable instructions to execute the memory recovery method described in any one of the above technical solutions.

[0026] Compared with the prior art, the present invention has at least the following beneficial effects:

[0027] The memory recovery method of the present invention reasonably formulates a recovery strategy according to the status of the IO load and the CPU load, thereby improving the recovery efficiency and avoiding the occupation of the CPU computing power when recovering the memory. It can avoid the overlap of the recovery action and the CPU high load scenario, and is not likely to cause the system to freeze or crash.

[0028] Furthermore, the present invention also combines user usage habits and application types to make the inner layer recycling strategy more intelligent and flexible. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 A schematic diagram of a flow chart of an embodiment of a memory recycling method of the present invention;

[0030] Figure 2 This is the working state diagram of the CPU when processing tasks;

[0031] Figure 3 A schematic diagram of grouping related applications in the memory recovery method of the present invention;

[0032] Figure 4 A schematic diagram of the memory recycling method of the present invention for prioritizing applications;

[0033] Figure 5 A schematic diagram of dividing the working domain of the memory recovery method of the present invention. DETAILED DESCRIPTION

[0034] The memory recovery method and terminal device of the present invention will be described below in conjunction with a schematic diagram, wherein a preferred embodiment of the present invention is shown. It should be understood that those skilled in the art can modify the present invention described herein while still achieving the advantageous effects of the present invention. Therefore, the following description should be understood as being widely known to those skilled in the art and not as a limitation of the present invention.

[0035] The serial numbers of the components herein, such as "first", "second", etc., are only used to distinguish the objects described and do not have any order or technical meaning. The "connection" and "coupling" mentioned in this application, unless otherwise specified, include direct and indirect connections (couplings). In the description of the present invention, it should be understood that the orientation or positional relationship indicated by the terms "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", etc. are based on the orientation or positional relationship shown in the accompanying drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation to the present invention.

[0036] The present invention is described in more detail in the following paragraphs by way of example with reference to the accompanying drawings. The advantages and features of the present invention will become more apparent from the following description and claims. It should be noted that the drawings are in very simplified form and in non-precise proportions, and are only used to facilitate and clearly assist in illustrating the purpose of the embodiments of the present invention.

[0037] Below is the accompanying drawing of the specification Figure 1 and Figure 5 The memory recycling method of the present invention is described.

[0038] In one embodiment, if Figure 1 As shown, the memory recovery method includes:

[0039] S100: Applications in the system correspond to different recycling priorities, where the recycling priorities include a first recycling priority;

[0040] S200: When the number of CPU processes to be processed is greater than the first CPU load setting value, determine the IO load value of the system;

[0041] S300: If the IO load value exceeds the first IO load setting value, the foreground application is retained and all background applications are recycled; if the IO load value is greater than the second IO load setting value and less than or equal to the first IO load setting value, the page cache of all background applications is recycled and the background application corresponding to the first recycling priority is recycled.

[0042] The memory recycling method of this embodiment reasonably formulates a recycling strategy according to the status of the IO load and the CPU load, which can avoid overlapping of recycling actions with CPU high load scenarios and is not likely to cause system freezing or crashing.

[0043] Among them, in step S200, the IO load value is positively correlated with the hardware queue depth of the disk and the software queue depth of the system. Specifically, since the CPU processing speed is much faster than the disk read and write speed, after the CPU issues an IO instruction, it will not wait for it to complete and return, but continue to send the following instructions. If the previous instruction is executed, the disk notification will tell the CPU through interruption or polling, etc., but the CPU cannot send IO instructions indefinitely during the waiting period, so the disk will have a queue depth limit, called the hardware queue depth (hw_queue_depth) of the disk, and the IO request sent by the CPU cannot exceed the hardware queue depth; each core of the multi-core processor has a queue to cache IO instructions, and this cache will occupy memory and therefore cannot be increased indefinitely. This limit is called the software queue depth (soft_queue_depth) of the system. The maximum number of IO operations (max_io) of the disk is equal to the sum of the hardware queue depth of the disk at the first set multiple A and the software queue depth of the system at the second set multiple B.

[0044] In one of the preferred embodiments, the first setting multiple A is 1, the second setting multiple B is 2, and the maximum number of IO operations of the disk max_io=(soft_queue_depth×2)+hw_queue_depth.

[0045] In other embodiments, the values ​​of the first setting multiple A and the second setting multiple B may be adjusted according to actual conditions, for example, the first setting multiple A is set to 1.5 and the second setting multiple B is set to 2.1.

[0046] In one embodiment, the first IO load setting value is a third setting multiple C of the maximum number of IO operations of the disk, and the second IO load setting value is a fourth setting multiple D of the maximum number of IO operations of the disk.

[0047] Further, the third setting multiple C has a value range of 0.4-0.5, preferably 0.5, and the fourth setting multiple D has a value range of 0.2-0.3, preferably 0.3. In other embodiments, the third setting multiple C can also be 0.45, and the fourth setting multiple D can be 0.25.

[0048] Define the system status normal, high, and emergency, corresponding to the system pressure from low to high. Then, the IO load status can be divided into three types according to the IO load value:

[0049] io_emergency, IO load value>C×max_io;

[0050] io_high, D×max_io≥IO load value>D×max_io;

[0051] io_normal, IO load value ≤ D × max_io;

[0052] Specifically, since the CPU load refers to the pressure on the system caused by the processes that need to be processed at a certain point in time, all processes time-share the CPU, and each CPU can only process one process in a microscopic time, all other processes that meet all conditions but have not yet obtained the CPU are in the ready queue, such as Figure 2 As shown in the figure, there are multiple tasks in the ready queues of CPU0 and CPU1, which means that there are 4 and 3 processes waiting to be processed by the CPU at the moment of the figure. The number of processes to be processed by the CPU indicates the current pressure of the CPU.

[0053] The first CPU load setting value is defined as the fifth setting multiple E of the number of CPUs; the second CPU load setting value is defined as the sixth setting multiple F of the number of CPUs.

[0054] Further, the fifth setting multiple E has a value range of 1-2, preferably 1, and the sixth setting multiple F has a value range of 4-5, preferably 5. In other embodiments, the fifth setting multiple E can also be 2, and the sixth setting multiple F can be 4.

[0055] Define the system states normal, high, and emergency to correspond to system pressure from low to high. If the number of processors is N, the CPU load state can be divided into three types according to the number of CPU processes to be processed:

[0056] cpu_emergency, the number of CPU pending processes>F×N;

[0057] cpu_high, F×N≥number of CPU processes to be processed>E×N;

[0058] cpu_normal: the number of CPU pending processes ≤ E×N.

[0059] That is, in step S300, based on the CPU load status being cpu_high or cpu_emergency, if the IO load status is io_emergency, the memory recovery strategy adopted is to retain the foreground application and recycle all background applications; if the IO load status is io_high, the memory recovery measures taken include reclaiming the page cache of all background applications and reclaiming the background applications corresponding to the first recovery priority.

[0060] In one embodiment, in step S100, in order to facilitate the priority classification of applications, the following is further included:

[0061] The applications in the system correspond to a plurality of set application types;

[0062] Some of the multiple set application types correspond to the first recycling priority, and another part corresponds to the second recycling priority.

[0063] Preferably, if Figure 3 As shown, according to different uses, applications are divided into six types: reading, audio and video, social, games, office, and finance. Preferably, within each application type, the priority is defined according to the average memory consumption of the application. The greater the average memory consumption, the higher the priority of being recycled. For example, the six types of applications are sorted from large to small according to the average memory consumption, and the top three application types (reading, audio and video, and social) in average memory consumption correspond to the first recycling priority, and the remaining three application types (games, office, and finance) correspond to the second recycling priority.

[0064] Exemplarily, when the IO load state is io_high and the CPU load state is cpu_high or cpu_emergency, the page cache of all background applications is reclaimed and the background applications of the first reclaiming priority are reclaimed, that is, the memory occupied by reading, audio and video, and social applications is reclaimed.

[0065] In other embodiments, the priority level corresponding to the application type can also be customized by the user. For example, reading, audio and video, game, and social applications can be assigned the first recycling priority level, and office and finance applications can be assigned the second recycling priority level.

[0066] In one of the embodiments, in order to more efficiently recycle memory, applications with associated relationships are grouped into the same application group;

[0067] If the IO load value is greater than the second IO load setting value and less than or equal to the first IO load setting value, and the number of CPU processes to be processed is greater than or equal to the first CPU load setting value but less than or equal to the second CPU load setting value, then when the current background application is recycled, the application in the same application group as the recycled application is synchronously recycled, and the anonymous pages of all background applications are recycled.

[0068] That is, if the IO load status is io_high and the CPU load status is cpu_emergency, the memory recycling policy adopted is to recycle the page cache of all background applications and recycle the background applications corresponding to the first recycling priority.

[0069] If the IO load status is io_high and the CPU load status is cpu_high, the memory recycling policy adopted is: on the basis of recycling the page cache of all background applications and recycling the background applications corresponding to the first recycling priority, when recycling the current background application, all background applications in the same application group as the recycled application are synchronously recycled, and the anonymous pages of all background applications are recycled.

[0070] Specifically, since users use applications with associations, for example, when using Feishu and WeChat for Enterprise, Word and Excel are basically opened, and when opening stock software, bank apps are often opened; multiple shopping applications are opened, for example, when opening Taobao, JD.com or Xianyu will also be opened. Sometimes users will share shopping links to social software, so social software such as WeChat will also be opened; therefore, Figure 4 As shown, by learning user habits, associations can be established between applications, and then the associated applications can be divided into the same application group (group). For example, shopping applications such as JD.com, Taobao, and Xianyu can be divided into the same application group as social applications such as WeChat. When recycling applications, the associated applications can also be recycled together, thereby improving recycling efficiency and recycling effects. For example, if the shopping application type corresponds to the first recycling priority, and the social application type corresponds to the second recycling priority, since WeChat and JD.com are in the same application group, when recycling shopping applications such as JD.com, WeChat in the same application group as JD.com is also recycled.

[0071] Among them, the specific method of recycling background applications is to kill background applications and release memory.

[0072] The specific method of reclaiming the page cache of the background application is to directly release the clean page and / or write the content of the dirty page back to the disk and then release the memory. The clean page refers to the page that has not been modified after the file is read from the storage device to the memory, and the dirty page refers to the page that has been modified after the file is read from the storage device to the memory.

[0073] The specific method of reclaiming the anonymous pages of all background applications is to save them to the swap space (swap partition).

[0074] In order to more clearly illustrate the technical solution of this application, Figure 5 As shown, based on the CPU load and IO load status, four working domains are defined, namely:

[0075] Work domain 1: corresponds to io_emergency, cpu_emergency;

[0076] Working domain 2: corresponds to io_high, cpu_emergency;

[0077] Working domain 3: corresponds to io_high, cpu_high;

[0078] Working domain 4: corresponds to io_emergency and cpu_high.

[0079] The recycling strategies corresponding to the four working domains are shown in Table 1 below:

[0080] Table 1 Correspondence between work domain and recycling strategy

[0081]

[0082] The memory recycling method of this embodiment makes the inner recycling strategy more intelligent and flexible according to the status of IO load and CPU load, and further combines user usage habits and application types, greatly improves the recycling efficiency, avoids occupying CPU computing power when recycling memory, and can avoid overlapping of recycling actions with CPU high load scenarios, which is not easy to cause system jamming or crash.

[0083] It should be noted that when the CPU load status is cpu_normal or the IO load status is io_normal, the system is not prone to crash or get stuck because the overall operating pressure is relatively low. You can flexibly adopt the appropriate inner recycling method according to your needs.

[0084] The present invention also provides a terminal device, which can be a smart phone, a tablet computer, or other intelligent electronic devices.

[0085] The terminal device includes a CPU, a storage medium and a bus, the storage medium stores machine-readable instructions executable by the CPU, the CPU and the storage medium communicate through the bus, and the CPU executes the machine-readable instructions to perform the memory recovery method as described in any one of the above embodiments.

[0086] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A memory recovery method, characterized in that: include: Applications in the system correspond to different recycling priorities, and the recycling priorities include a first recycling priority; When the number of CPU processes to be processed is greater than the first CPU load setting value, determining the IO load value of the system; If the IO load value is greater than the first IO load setting value, the foreground application is retained and all background applications are recycled; if the IO load value is greater than the second IO load setting value and less than or equal to the first IO load setting value, the page cache of all background applications is recycled and the background application corresponding to the first recycling priority is recycled.

2. The memory recovery method according to claim 1, characterized in that: Also includes: The applications in the system correspond to a plurality of set application types; Some of the multiple set application types correspond to the first recycling priority, and another part corresponds to the second recycling priority.

3. The memory recovery method according to claim 2, characterized in that: Priority is defined based on the average memory consumption of each application type. The larger the memory consumption, the higher the priority.

4. The memory recovery method according to claim 1, characterized in that: Divide the background applications with associated relationships into groups to obtain multiple application groups; If the IO load value is greater than the second IO load setting value and less than or equal to the first IO load setting value, and the number of CPU processes to be processed is greater than the first CPU load setting value but less than or equal to the second CPU load setting value, then when the current background application is recycled, all background applications in the same application group as the recycled application are synchronously recycled, and anonymous pages of all background applications are recycled.

5. The memory recovery method according to claim 1, characterized in that: Recycling background applications includes: closing background applications and releasing memory.

6. The memory recovery method according to claim 1, characterized in that: Reclaiming the page cache of the background application includes: directly releasing the clean pages and / or releasing the memory after writing the contents of the dirty pages back to the disk.

7. The memory recovery method according to claim 1, characterized in that: Reclaiming anonymous pages of background applications includes: saving the anonymous pages to the swap space.

8. The memory recovery method according to claim 1, characterized in that: The first IO load setting value and the second IO load setting value are both positively correlated with the hardware queue depth of the disk and the software queue depth of the system.

9. The memory recovery method according to claim 8, characterized in that: The maximum number of disk IO operations is equal to the sum of the hardware queue depth of the disk at the first setting multiple and the software queue depth of the system at the second setting multiple; The first IO load setting value is a third setting multiple of the maximum number of IO operations of the disk, and the second IO load setting value is a fourth setting multiple of the maximum number of IO operations of the disk.

10. The memory recovery method according to claim 9, characterized in that: The value range of the third setting multiple is 0.4-0.5, and the value range of the fourth setting multiple is 0.2-0.

3.

11. The memory recovery method according to claim 2, characterized in that: The first CPU load setting value and the second CPU load setting value are both positively correlated with the number of CPUs.

12. The memory recovery method according to claim 11, characterized in that: The first CPU load setting value is a fifth set multiple of the number of CPUs; and the second CPU load setting value is a sixth set multiple of the number of CPUs.

13. The memory recovery method according to claim 12, characterized in that: The value range of the fifth setting multiple is 1-2, and the value range of the sixth setting multiple is 4-5.

14. A terminal device, characterized in that: It includes a CPU, a storage medium and a bus, the storage medium stores machine-readable instructions executable by the CPU, the CPU and the storage medium communicate through the bus, and the CPU executes the machine-readable instructions to perform the memory recovery method as described in any one of claims 1-13.