A memory recycling method and device

By establishing memory resource grouping on electronic devices and dynamically binding with the target kernel thread, the lock competition problem in multi-threaded memory recycling is solved, memory recycling efficiency and system fluency are improved, and user experience is improved.

CN114443510BActive Publication Date: 2025-07-04VIVO MOBILE COMM CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210087228.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-25
Publication Date
2025-07-04
Estimated Expiration
2042-01-25

AI Technical Summary

Technical Problem

When multiple threads are used to recycle memory in the prior art, there is serious competition for locks, which leads to electronic devices being prone to lag and splash screen problems in scenarios where memory usage is too high, affecting the user experience.

Method used

By establishing multiple memory resource groups, each group corresponds to at least one application, and dynamically binds it to the target kernel thread, the target kernel thread uses memory recovery when the memory reaches the threshold, reducing lock competition.

Benefits of technology

Reduces lock competition between target kernel threads, improves memory recycling efficiency, reduces memory bumps, and improves system fluency and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443510B_ABST
    Figure CN114443510B_ABST
Patent Text Reader

Abstract

The present application discloses a memory recycling method and device, belonging to the technical field of memory management. The memory recycling method includes: establishing a plurality of memory resource groups, each of the memory resource groups corresponding to at least one application program of an electronic device; when the used memory of the electronic device reaches a target memory threshold, recycling the memory of the memory resource groups through a target kernel thread, where the target kernel thread is a kernel thread for page recycling.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the technical field of memory management, and particularly relates to a memory recycling method and device. Background Art

[0002] Electronic devices have brought great convenience to our lives and work, and the scenarios of using electronic devices in daily work are also increasing. The speed of memory recycling is an important guarantee for the fluency of electronic devices. The native system usually uses a single thread for memory recycling, and performs memory recycling according to the remaining memory capacity. However, the memory recycling rate of a single thread is not fast. In order to improve the memory recycling rate, multiple threads are currently used for memory recycling. However, although the memory recycling speed is fast with multiple threads, there are serious lock competitions, which easily lead to performance degradation, and further lead to problems such as stuttering and flashing screens in scenarios where the memory usage of electronic devices is too high, affecting the user experience. Summary of the Invention

[0003] The purpose of the embodiments of this application is to provide a memory recycling method and device, which can solve the problem that there are serious lock competitions when using multiple threads to recycle memory in the prior art, which easily leads to performance degradation, and further leads to problems such as stuttering and flashing screens in scenarios where the memory usage of electronic devices is too high.

[0004] In a first aspect, the embodiments of this application provide a memory recycling method, which includes:

[0005] Establish multiple memory resource groups, and each of the memory resource groups corresponds to at least one application program of the electronic device;

[0006] When the used memory of the electronic device reaches the target memory threshold, recycle the memory of the memory resource groups through a target kernel thread, where the target kernel thread is a kernel thread for page recycling.

[0007] In a second aspect, the embodiments of this application provide a memory recycling device, which includes:

[0008] An establishment module, configured to establish multiple memory resource groups, and each of the memory resource groups corresponds to at least one application program of the electronic device;

[0009] A recycling module, configured to recycle the memory of the memory resource groups through a target kernel thread when the used memory of the electronic device reaches the target memory threshold, where the target kernel thread is a kernel thread for page recycling.

[0010] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.

[0011] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0012] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.

[0013] In an embodiment of the present application, memory resource groups are established according to applications on the electronic device, and the memory resource groups are dynamically bound to kernel threads for reclaiming memory. When the used memory of the electronic device reaches a certain threshold, the memory of the corresponding memory resource group can be reclaimed through the dynamically bound target kernel thread, thereby reducing lock contention between target kernel threads, and then reducing performance issues caused by lock contention, reducing memory jitter, improving system fluency, and enhancing user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 A flowchart of a memory recovery method provided in an embodiment of the present application;

[0015] Figure 2 A flowchart of another memory recycling method provided in an embodiment of the present application;

[0016] Figure 3 A schematic diagram of the memory recycling principle provided in an embodiment of the present application;

[0017] Figure 4 A schematic diagram of the structure of a memory recovery device provided in an embodiment of the present application;

[0018] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0019] Figure 6 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application. DETAILED DESCRIPTION

[0020] Next, the technical solutions in the embodiments of the present application will be clearly described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art belong to the scope of protection of the present application.

[0021] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same category, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / " generally indicates an "or" relationship between the associated objects before and after.

[0022] Next, in conjunction with the accompanying drawings, the memory recycling method and device provided by the embodiments of the present application will be described in detail through specific embodiments and their application scenarios.

[0023] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of a memory recycling method provided by an embodiment of the present application. As Figure 1 described, an embodiment of the present application provides a memory recycling method, which can be applied to an electronic device. The method includes the following steps:

[0024] Step 101: Establish a plurality of memory resource groups, and each of the memory resource groups corresponds to at least one application program of the electronic device;

[0025] Among them, the memory resource group is the memory cgroup group. In the embodiments of the present application, optionally, the electronic device has a memory resource controller, and the memory resource controller can group the memory resources according to certain grouping methods. Exemplarily, in some embodiments, a memory resource group can be established corresponding to each application program, that is, the memory resources occupied when a certain application program runs are the memory resources of this memory resource group. The number of application programs installed on the electronic device is the same as the number of established memory resource groups. When the application programs on the electronic device increase or decrease, the memory resource groups can be increased or decreased accordingly. By establishing memory resource groups according to application programs, the memory resources can be effectively divided, so as to subsequently recycle the memory resources of each memory resource group respectively, achieve load balancing, and avoid excessive competition during memory recycling.

[0026] Step 102: When the used memory of the electronic device reaches the target memory threshold, the memory in the memory resource group is recycled through the target kernel thread.

[0027] In this step, the electronic device determines whether the current used memory reaches the target memory threshold. When the used memory of the electronic device reaches the target memory threshold, the target kernel thread is awakened, and the memory resources in the memory resource group are recycled through the target kernel thread. The target kernel thread is a kernel thread for page recycling, that is, a kernel thread for memory recycling, also known as kswapd. That is to say, when the memory of the electronic device needs to be recycled, a certain target kernel thread can recycle the memory of at least one application program belonging to a certain memory resource group, thereby realizing multi-threaded memory recycling, improving the memory recycling efficiency. And since each target kernel thread can recycle different memory resource groups, the probability of lock contention when each target kernel thread performs memory recycling is greatly reduced, thereby improving the system performance and reducing memory thrashing.

[0028] Therefore, in the embodiment of the present application, by establishing memory resource groups according to the application programs on the electronic device, when the used memory of the electronic device reaches a certain threshold, the memory in the corresponding memory resource group can be recycled through the target kernel thread, thereby reducing the lock contention between the target kernel threads, and then reducing the performance problems caused by lock contention, reducing memory thrashing, improving the system fluency, and enhancing the user experience.

[0029] In some embodiments of the present application, after establishing a plurality of memory resource groups, each of the memory resource groups corresponding to at least one application program of the electronic device, further includes:

[0030] Dynamically bind the plurality of memory resource groups to a plurality of target kernel threads, where the target kernel thread is a kernel thread for page recycling, and each target kernel thread is correspondingly bound to at least one of the memory resource groups;

[0031] The recycling of the memory in the memory resource group through the target kernel thread includes:

[0032] Recycling the memory in the memory resource group dynamically bound to the target kernel thread through the target kernel thread.

[0033] That is to say, in the embodiments of the present application, after establishing multiple memory resource groups, the multiple memory resource groups can be dynamically bound to multiple target kernel threads. Among them, the target kernel threads are kernel threads for page recycling, that is, kernel threads for memory recycling, also known as kswapd. Moreover, each target kernel thread is correspondingly bound to at least one memory resource group. That is to say, a target kernel thread can be bound to one memory resource group, or can be bound to two or more memory resource groups. The so-called dynamic binding means that the corresponding relationship between the memory resource group and the target kernel thread is not fixed. Exemplarily, when the number of memory resource groups increases, the increased memory resource groups will be rebound to the target kernel threads. When the number of memory resource groups decreases, the number of memory resource groups correspondingly bound to the target kernel threads will also change. For example, all memory resource groups will be evenly distributed and bound to each target kernel thread again. By dynamically binding the multiple memory resource groups to the multiple target kernel threads, when subsequent recycling is required, each target kernel thread only recycles the memory of the correspondingly bound memory resource group, thus greatly reducing the lock competition between the target kernel threads, accelerating the memory recycling, and improving the fluency of the system.

[0034] In some embodiments of the present application, the establishing of the multiple memory resource groups, where each memory resource group corresponds to at least one application program of the electronic device includes:

[0035] Establishing a corresponding memory resource group for each application program.

[0036] That is to say, in this embodiment, one application program on the electronic device corresponds to the establishment of one memory resource group. Through such a grouping establishment method, the division of the memory resource groups is more detailed, and the subsequent target kernel threads are more targeted when performing memory recycling, thereby improving the memory recycling efficiency and reducing the lock competition.

[0037] In some other embodiments of the present application, after the dynamic binding of the multiple memory resource groups to the multiple target kernel threads, it further includes:

[0038] Binding other target kernel threads except the first target kernel thread to other CPU cores of the electronic device except the first CPU core;

[0039] Among them, the main frequency of the first CPU core is higher than the target frequency threshold.

[0040] Exemplarily, in this embodiment, the electronic device includes a first CPU core and other CPU cores other than the first CPU core. Among them, the main frequency of the first CPU core is higher than that of other CPU cores, that is, the first CPU core is the big core of the electronic device, and other CPU cores are the small cores of the electronic device. By binding some target kernel threads to other CPU cores other than the first CPU core of the electronic device, the target kernel threads bound to other CPU cores will not occupy the resources of the first CPU core, thereby avoiding the situation where all target kernel threads compete for the first CPU core and then causing the application to freeze. Optionally, a first target kernel thread can be removed from all target kernel threads, and then the remaining target kernel threads are all bound to other CPU cores other than the first CPU core of the electronic device. Only the first target kernel thread uses the first CPU core, which can prevent the situation of competing for the first CPU core from occurring. The first target kernel thread can be neither bound to the first CPU core nor bound to other CPU cores, and it can freely use the first CPU core or other CPU cores.

[0041] In some other embodiments of the present application, the recycling of the memory grouped by the memory resources dynamically bound to the target kernel thread by the target kernel thread when the memory water level of the electronic device reaches the target memory threshold includes:

[0042] When the used memory of the electronic device reaches the first target memory threshold, one or more of the other target kernel threads other than the first target kernel thread are used to recycle the memory of the corresponding dynamically bound memory resource group;

[0043] When the used memory of the electronic device reaches the second target memory threshold, one or more of all target kernel threads are used to recycle the memory of the corresponding dynamically bound memory resource group;

[0044] Among them, the first target memory threshold is less than the second target memory threshold.

[0045] In this embodiment, the electronic device determines whether to wake up the target kernel thread to reclaim memory according to the currently used memory, and sets two different target memory thresholds, namely the first target memory threshold and the second target memory threshold, where the first target memory threshold is less than the second target memory threshold. When the used memory of the electronic device reaches different target memory thresholds, different reclaiming strategies are adopted. Exemplarily, if the used memory of the electronic device reaches the first target memory threshold, that is, the used memory of the electronic device is less at this time and the need for memory reclaiming is not urgent, then one or more of the other target kernel threads except the first target kernel thread are woken up to reclaim the memory of the corresponding dynamically bound memory resource group. Since the other target kernel threads except the first target kernel thread are bound to the other CPU cores of the electronic device except the first CPU core, the resources of the first CPU core are not occupied, so the smoothness of the system is basically not affected and the user experience is not affected; if the used memory of the electronic device reaches the second target memory threshold, that is, the used memory of the electronic device is more at this time and the need for memory reclaiming is relatively urgent, then one or more of all the target kernel threads are woken up to reclaim the memory of the corresponding dynamically bound memory resource group. Since the first target kernel thread is bound to the first CPU core of the electronic device, the participation of the first target kernel thread in memory reclaiming can accelerate the efficiency of memory reclaiming.

[0046] Thus, by setting two different target memory thresholds, when the used memory is less, the first target kernel thread is not allowed to occupy the resources of the first CPU core to minimize the occupation of computing resources and ensure the smoothness of the system; when the used memory is more, the resources of the first CPU core can be utilized by the first target kernel thread to accelerate the efficiency of memory reclaiming.

[0047] Among them, the woken-up and enabled target kernel thread only reclaims the memory of the memory resource group bound to it. When reclaiming memory, all memory resource groups are traversed to find the memory resource group bound to the currently woken-up target kernel thread, and then its memory is reclaimed. If there is no binding relationship, this memory resource group is not skipped.

[0048] In the embodiment of the present application, optionally, the first target memory threshold and the second target memory threshold can be preset, and the second target memory threshold can be increased by a predetermined value, such as 10M, on the basis of the first target memory threshold.

[0049] In some embodiments of the present application, the dynamically binding the multiple memory resource groups to the multiple target kernel threads includes:

[0050] When the number of the memory resource groups and / or the number of target kernel threads changes, rebind the memory resource groups to each of the target kernel threads according to the number of the target kernel threads;

[0051] Wherein, the difference between the numbers of the memory resource groups bound by any two of the target kernel threads after rebinding is less than a target value.

[0052] Exemplarily, when the number of application programs on an electronic device changes, the number of the memory resource groups established correspondingly will also change, or a user changes the number of active target kernel threads, so that the number of the target kernel threads changes. Then, when at least one of the number of the memory resource groups and the number of the target kernel threads changes, allocate all the memory resource groups evenly according to the number of the target kernel threads, and rebind the memory resource groups to each target kernel thread, so that the difference between the numbers of the memory resource groups bound by any two target kernel threads after rebinding is less than the target value, to ensure the balance of the memory resource groups corresponding to each target kernel thread when the number of the memory resource groups and / or the number of the target kernel threads changes. Optionally, the target value can be set in advance. For example, the target value is 2, that is, the difference between the numbers of the memory resource groups bound by any two target kernel threads is less than 2. Dynamically binding the memory resource groups to the target kernel threads can achieve the effect of evenly balancing the memory resource groups corresponding to each target kernel thread in real time, thereby reducing memory thrashing.

[0053] For example, when the number of the memory resource groups bound by a certain target kernel thread decreases, the memory resource groups corresponding to other target kernel threads will be balanced to this target kernel thread to achieve an overall balance effect; for another example, when the memory resource groups increase, the increased memory resource groups will be dynamically bound to the corresponding target kernel threads to achieve an overall balance effect.

[0054] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of another memory recycling method provided by an embodiment of the present application. As Figure 2 shown, an embodiment of the present application provides another memory recycling method, and the method includes:

[0055] Step 201: Establish memory resource groups for each application program to manage the use of memory resources;

[0056] Among them, a memory resource group is established for each application program. For example, a memory resource group mem_cgroup1 is established for the application program APP1, a memory resource group mem_cgroup2 is established for the application program APP2, a memory resource group mem_cgroup2 is established for the application program APP2, a memory resource group mem_cgroup3 is established for the application program APP3, a memory resource group mem_cgroup4 is established for the application program AP,4, a memory resource group mem_cgroup5 is established for the application program APP5, and so on.

[0057] Step 202: Dynamically bind multiple memory resource groups to multiple target kernel threads;

[0058] In this step, multiple memory resource groups are dynamically bound to multiple target kernel threads through a dynamic binding algorithm. Among them, at least one memory resource group is bound to one target kernel thread. For example, the memory resource group mem_cgroup1 and the memory resource group mem_cgroup2 are dynamically bound to the target kernel thread kswapd0, the memory resource group mem_cgroup3 and the memory resource group mem_cgroup4 are dynamically bound to the target kernel thread kswapd1, and the memory resource group mem_cgroup5 is dynamically bound to the target kernel thread kswapd3.

[0059] In the embodiment of the present application, optionally, the target kernel thread kswapd0 is not bound to any CPU core of the electronic device, and the target kernel threads kswapd1, kswapd2, etc. are bound to the small CPU cores of the electronic device.

[0060] Step 203: The target kernel thread triggers memory recycling when the water level condition is met;

[0061] Among them, the water level is the water level of the memory of the electronic device, which is used to measure the remaining memory capacity of the electronic device. For the target kernel thread kswapd0, the set water level condition is to use the native water level water_mark, that is, when the water level reaches the native water level water_mark, the target kernel thread kswapd0 is triggered to perform memory recycling; for the target kernel threads kswapd1, kswapd2, etc. bound to the small CPU cores, the delta_mark value is added to the native water level, that is, water_mark+delta_mark, that is, when the water level reaches water_mark+delta_mark, the target kernel threads kswapd1, kswapd2, etc. are triggered to perform memory recycling.

[0062] Step 204: Traverse all memory resource groups and reclaim memory through the target kernel threads to which the memory resource groups belong.

[0063] When corresponding water level conditions are met, reclaim the memory resources of a memory resource group through the target kernel thread bound to the memory resource group. Specifically, all memory resource groups can be traversed to find the memory resource group bound to the target kernel thread, and then the target kernel thread is used to reclaim the memory of the memory resource group.

[0064] Please refer to Figure 3 , Figure 3 which is a schematic diagram of the memory reclaim principle provided by the embodiments of the present application. As Figure 3 shown in the upper part, in the prior art, when reclaiming memory, it is necessary to start reclaiming pages from the tail of the page replacement algorithm linked list lru_list. For example, when multiple kernel threads (such as kswapd0 and kswapd1) reclaim pages from the tail, kswapd0 and kswapd1 will isolate pages from the tail of the page replacement algorithm linked list lru_list at the same time. At this time, there is a serious competition relationship, that is, lock competition. Moreover, such a reclaiming method may cause excessive reclaiming of the memory of a certain application program. For example, if the pages at the tail of the page replacement algorithm linked list lru_list are all pages of the same application program, it will cause excessive reclaiming of the memory of this application program. When this application program is awakened again later, it needs to reapply for pages, thereby increasing the response time and occupying computing resources, and there is a problem of memory thrashing.

[0065] As Figure 3 shown in the lower part, by using the memory reclaim method in the embodiments of the present application, multiple memory resource groups (such as mem_cgroup0, mem_cgroup1, mem_cgroup2, and mem_cgroup3) are established, and the multiple memory resource groups are dynamically and evenly bound to multiple target kernel threads (such as kswapd0 and kswapd1). Then, the page replacement algorithm linked list lru_list is also evenly split into multiple linked lists. When reclaiming memory, the target kernel thread corresponding to the bound memory resource group is used to reclaim memory, that is, memory reclaiming is carried out dispersedly, thereby reducing the competition between multiple target kernel threads, improving the rate of memory reclaiming. Moreover, since the reclaimed memory is scattered in different memory resource groups, it is equivalent to reclaiming part of the memory on multiple application programs, so the memory will not be over-reclaimed, and thus the problem of memory thrashing caused by local over-reclaiming can be avoided.

[0066] In summary, in the embodiments of the present application, by establishing memory resource groups according to the application programs on the electronic device and dynamically binding the memory resource groups to the kernel threads for memory recycling, when the used memory of the electronic device reaches a certain threshold, the memory of the corresponding memory resource group can be recycled through the dynamically bound target kernel thread, thereby reducing the lock competition between the target kernel threads, then reducing the performance problems caused by lock competition, reducing memory thrashing, improving system fluency, and enhancing the user experience.

[0067] It should be noted that for the memory recycling method provided in the embodiments of the present application, the execution subject may be a memory recycling device, or a control module in the memory recycling device for executing the memory recycling method. In the embodiments of the present application, taking the memory recycling device as the execution subject of the memory recycling method as an example, the memory recycling device provided in the embodiments of the present application is described.

[0068] Please refer to Figure 4 , Figure 4 which is a schematic structural diagram of a memory recycling device provided in an embodiment of the present application. As Figure 4 shown, in another embodiment of the present application, a memory recycling device is further provided. The device 400 includes:

[0069] A establishing module 401, configured to establish a plurality of memory resource groups, each of the memory resource groups corresponding to at least one application program of the electronic device;

[0070] A recycling module 402, configured to recycle the memory of the memory resource group through a target kernel thread when the used memory of the electronic device reaches a target memory threshold, where the target kernel thread is a kernel thread for page recycling.

[0071] Optionally, the establishing module includes:

[0072] An establishing unit, configured to establish a corresponding memory resource group for each application program.

[0073] Optionally, the device further includes:

[0074] A first binding module, configured to dynamically bind the plurality of memory resource groups to a plurality of target kernel threads, where the target kernel thread is a kernel thread for page recycling, and each of the target kernel threads is correspondingly bound to at least one of the memory resource groups;

[0075] The recycling module includes:

[0076] A recycling unit, configured to recycle the memory of the memory resource group dynamically bound to the target kernel thread through the target kernel thread when the used memory of the electronic device reaches a target memory threshold.

[0077] Optionally, the device further comprises:

[0078] A second binding module, used to bind other target kernel threads except the first target kernel thread to other CPU cores except the first CPU core of the electronic device;

[0079] The main frequency of the first CPU core is higher than the target frequency threshold.

[0080] Optionally, the recycling module includes:

[0081] A first recycling unit is used to recycle the memory of the corresponding dynamically bound memory resource group through one or more of other target kernel threads except the first target kernel thread when the used memory of the electronic device reaches a first target memory threshold;

[0082] A second recycling unit is used to recycle the memory of the corresponding dynamically bound memory resource group through one or more of all target kernel threads when the used memory of the electronic device reaches a second target memory threshold;

[0083] The first target memory threshold is smaller than the second target memory threshold.

[0084] Optionally, the first binding module includes:

[0085] a binding unit, configured to rebind the memory resource group for each of the target kernel threads according to the number of the target kernel threads when the number of the memory resource groups and / or the number of the target kernel threads changes;

[0086] The difference between the numbers of memory resource groups bound to any two of the target kernel threads after rebinding is less than the target value.

[0087] In an embodiment of the present application, memory resource groups are established according to applications on the electronic device, and the memory resource groups are dynamically bound to kernel threads for reclaiming memory. When the used memory of the electronic device reaches a certain threshold, the memory of the corresponding memory resource group can be reclaimed through the dynamically bound target kernel thread, thereby reducing lock contention between target kernel threads, and then reducing performance issues caused by lock contention, reducing memory jitter, improving system fluency, and enhancing user experience.

[0088] The memory recovery device in the embodiments of the present application can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present application do not make specific limitations.

[0089] The memory recovery device in the embodiments of the present application can be a device with an operating system. The operating system can be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present application do not make specific limitations.

[0090] The memory recovery device provided in the embodiments of the present application can implement Figures 1 to 3 each process implemented by the method embodiments. To avoid repetition, it will not be elaborated here.

[0091] Optionally, as Figure 5 shown, the embodiments of the present application further provide an electronic device 500, including a processor 501, a memory 502, a program or instruction stored on the memory 502 and executable on the processor 501. When the program or instruction is executed by the processor 501, it implements each process of the above-mentioned memory recovery method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0092] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0093] Figure 6 It is a schematic diagram of the hardware structure of an electronic device for implementing the embodiments of the present application.

[0094] The electronic device 600 includes, but is not limited to: a radio frequency unit 601, a network module 602, an audio output unit 603, an input unit 604, a sensor 605, a display unit 606, a user input unit 607, an interface unit 608, a memory 609, and a processor 6010, etc.

[0095] Those skilled in the art can understand that the electronic device 600 may further include a power source (such as a battery) for powering each component. The power source can be logically connected to the processor 6010 through a power management system, so as to manage functions such as charging, discharging, and power consumption management through the power management system. Figure 6 The structure of the electronic device shown in Figure 6 does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0096] Among them, the processor 6010 is used to establish multiple memory resource groups, and each of the memory resource groups corresponds to at least one application program of the electronic device;

[0097] The processor 6010 is further used to, when the used memory of the electronic device reaches the target memory threshold, recycle the memory of the memory resource groups through a target kernel thread, where the target kernel thread is a kernel thread for page recycling.

[0098] In the embodiments of the present application, by establishing memory resource groups according to the application programs on the electronic device and dynamically binding the memory resource groups to the kernel threads for recycling memory, when the used memory of the electronic device reaches a certain threshold, the memory of the corresponding memory resource groups can be recycled through the dynamically bound target kernel threads, thereby reducing the lock competition between the target kernel threads, and then reducing the performance problems caused by lock competition, reducing memory thrashing, improving the system fluency, and enhancing the user experience.

[0099] Optionally, the establishing multiple memory resource groups, and each of the memory resource groups corresponds to at least one application program of the electronic device includes:

[0100] Establishing a corresponding memory resource group for each application program.

[0101] Optionally, the processor 6010 is further used to dynamically bind the multiple memory resource groups to multiple target kernel threads, where the target kernel threads are kernel threads for page recycling, and each of the target kernel threads is correspondingly bound to at least one of the memory resource groups;

[0102] Optionally, the processor 6010 is further used to bind other target kernel threads except the first target kernel thread to other CPU cores of the electronic device except the first CPU core;

[0103] Among them, the main frequency of the first CPU core is higher than the target frequency threshold.

[0104] Optionally, the processor 6010 is further configured to, when the used memory of the electronic device reaches a first target memory threshold, recycle the memory of the memory resource groups dynamically bound correspondingly through one or more of the other target kernel threads except the first target kernel thread;

[0105] when the used memory of the electronic device reaches a second target memory threshold, recycle the memory of the memory resource groups dynamically bound correspondingly through one or more of all the target kernel threads;

[0106] wherein, the first target memory threshold is less than the second target memory threshold.

[0107] Optionally, the processor 6010 is further configured to, when the number of the memory resource groups and / or the number of the target kernel threads changes, rebind the memory resource groups to each of the target kernel threads according to the number of the target kernel threads;

[0108] wherein, the difference between the numbers of the memory resource groups bound by any two of the target kernel threads after rebinding is less than a target value.

[0109] It should be understood that, in the embodiment of the present application, the input unit 604 may include a Graphics Processing Unit (GPU) 6041 and a microphone 6042. The graphics processor 6041 processes the image data of the static pictures or videos obtained by an image capturing device (such as a camera) in a video capturing mode or an image capturing mode. The display unit 606 may include a display panel 6061. The display panel 6061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 607 includes a touch panel 6071 and other input devices 6072. The touch panel 6071 is also referred to as a touch screen. The touch panel 6071 may include two parts: a touch detection device and a touch controller. The other input devices 6072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be elaborated herein. The memory 609 may be used to store software programs and various data, including but not limited to application programs and operating systems. The processor 6010 may integrate an application processor and a modem processor. Among them, the application processor mainly processes the operating system, user interfaces, application programs, etc., and the modem processor mainly processes wireless communications. It can be understood that the above modem processor may not be integrated into the processor 6010.

[0110] The embodiments of the present application further provide a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned embodiment of the memory recycling method is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be elaborated here.

[0111] Wherein, the processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer-readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.

[0112] The embodiments of the present application further provide a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run a program or instruction to implement each process of the above-mentioned embodiment of the memory recycling method, and the same technical effect can be achieved. To avoid repetition, it will not be elaborated here.

[0113] It should be understood that the chip mentioned in the embodiments of the present application may also be referred to as a system-on-chip, a system chip, a chip system, or a system-on-chip, etc.

[0114] It should be noted that in this article, the term "comprising", "including" or any other variant thereof is intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in a reverse order according to the functions involved. For example, the methods described may be performed in an order different from that described, and various steps may be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0115] Through the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such an understanding, the technical solution of the present application, in essence, or the part that makes contributions to the prior art can be embodied in the form of a computer software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal (which may be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present application.

[0116] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific implementation manners. The above specific implementation manners are merely illustrative and not restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them belong to the protection scope of the present application.

Claims

1. A memory recycling method, characterized in that, Including: Establishing a plurality of memory resource groups, each of the memory resource groups corresponding to at least one application program of the electronic device; Dynamically binding the plurality of memory resource groups to a plurality of target kernel threads, each of the target kernel threads corresponding to bind at least one of the memory resource groups; When the used memory of the electronic device reaches a target memory threshold, recycling the memory of the memory resource group dynamically bound to the target kernel thread through the target kernel thread, wherein the target kernel thread is a kernel thread for page recycling.

2. The method according to claim 1, characterized in that, The establishing a plurality of memory resource groups, each of the memory resource groups corresponding to at least one application program of the electronic device includes: Establishing a corresponding memory resource group for each application program.

3. The method according to claim 1, characterized in that, After dynamically binding the plurality of memory resource groups to a plurality of target kernel threads, further including: Binding other target kernel threads except the first target kernel thread to other CPU cores of the electronic device except the first CPU core; Wherein, the main frequency of the first CPU core is higher than a target frequency threshold.

4. The method according to claim 3, wherein The recycling the memory of the memory resource group dynamically bound to the target kernel thread through the target kernel thread when the used memory of the electronic device reaches a target memory threshold includes: When the used memory of the electronic device reaches a first target memory threshold, recycling the memory of the memory resource group dynamically bound correspondingly through one or more of the other target kernel threads except the first target kernel thread; When the used memory of the electronic device reaches a second target memory threshold, recycling the memory of the memory resource group dynamically bound correspondingly through one or more of all the target kernel threads; Wherein, the first target memory threshold is less than the second target memory threshold.

5. The method according to claim 1, characterized in that The dynamically binding the plurality of memory resource groups to a plurality of target kernel threads includes: When the number of the memory resource groups and / or the number of the target kernel threads changes, rebinding the memory resource groups for each of the target kernel threads according to the number of the target kernel threads; Wherein, the difference between the numbers of the memory resource groups bound by any two of the target kernel threads after rebinding is less than a target value.

6. A memory recycling device, characterized in that, Including: An establishing module, configured to establish a plurality of memory resource groups, each of the memory resource groups corresponding to at least one application program of the electronic device; A recycling module, configured to recycle the memory of the memory resource group through a target kernel thread when the used memory of the electronic device reaches a target memory threshold, wherein the target kernel thread is a kernel thread for page recycling; A first binding module, configured to dynamically bind the plurality of memory resource groups to a plurality of target kernel threads, wherein the target kernel thread is a kernel thread for page recycling, and each of the target kernel threads corresponds to bind at least one of the memory resource groups; The recycling module includes: A recycling unit, configured to recycle the memory of a memory resource group dynamically bound to the target kernel thread through the target kernel thread when the used memory of the electronic device reaches a target memory threshold.

7. The device according to claim 6, characterized in that, The establishing module includes: An establishing unit, configured to establish a corresponding memory resource group for each application.

8. The device according to claim 6, characterized in that, It further includes: A second binding module, configured to bind other target kernel threads except the first target kernel thread to other CPU cores of the electronic device except the first CPU core; wherein, the main frequency of the first CPU core is higher than a target frequency threshold.

9. The device according to claim 8, wherein The recycling unit includes: A first recycling subunit, configured to recycle the memory of a corresponding dynamically bound memory resource group through one or more of the other target kernel threads except the first target kernel thread when the used memory of the electronic device reaches a first target memory threshold; A second recycling subunit, configured to recycle the memory of a corresponding dynamically bound memory resource group through one or more of all the target kernel threads when the used memory of the electronic device reaches a second target memory threshold; wherein, the first target memory threshold is less than the second target memory threshold.

10. The device according to claim 6, characterized in that, The first binding module includes: A binding unit, configured to rebind the memory resource group for each of the target kernel threads according to the number of the target kernel threads when the number of the memory resource groups and / or the number of the target kernel threads changes; wherein, the difference in the number of the memory resource groups bound by any two of the rebound target kernel threads is less than a target value.

Citation Information

Patent Citations

  • Virtual memory management method and electronic equipment

    CN113722087A