Memory reclamation methods and apparatus

By binding an even number of recycling threads to the non-target cores of the CPU in electronic devices, the problem of low memory recycling efficiency is solved, improving memory allocation speed and device smoothness.

CN115509953BActive Publication Date: 2025-12-02VIVO MOBILE COMM CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211348720.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-31
Publication Date
2025-12-02
Estimated Expiration
2042-10-31

AI Technical Summary

Technical Problem

When electronic devices are short of memory, memory reclamation efficiency is low, resulting in slow operation speed and affecting user experience.

Method used

By identifying N recycling threads in the electronic device and binding them to recycling threads other than the target core, an even number of recycling threads are bound to the CPU cores. The target core is the CPU core with the highest operating frequency, and the target pages are recycled by an even number of recycling threads when the remaining memory is less than a first preset threshold, until the remaining memory is greater than or equal to a second preset threshold.

Benefits of technology

It improves memory release speed, avoids lag in electronic devices caused by slow memory allocation speed, and enhances device smoothness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115509953B_ABST
    Figure CN115509953B_ABST
Patent Text Reader

Abstract

This application discloses a memory reclamation method and apparatus, belonging to the field of communication technology. The method includes: determining N reclamation threads and binding the N reclamation threads to cores in the CPU of an electronic device, excluding the target core, where the target core is the CPU core with the highest operating frequency, and N is an even number greater than 0; reclamating the target page through the N reclamation threads when the remaining memory in the electronic device is less than a first preset threshold; and stopping the reclamation of the target page while the remaining memory in the electronic device is greater than or equal to a second preset threshold during the reclamation process through the N reclamation threads.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of communication technology, specifically relating to a memory reclamation method and apparatus. Background Technology

[0002] Currently, there are more and more applications on electronic devices. When many applications are running in the background, they occupy a lot of memory resources on the electronic device, which may cause the electronic device to lag. In the existing technology, when memory is insufficient, the electronic device can close some infrequently used background application processes to reclaim the memory they occupy, and then allocate the reclaimed memory to other applications.

[0003] However, if the electronic device's memory reclamation efficiency is low, the foreground applications running on the electronic device may not be able to request the required memory in time, resulting in the electronic device lagging and performing operations slowly. Summary of the Invention

[0004] The purpose of this application is to provide a memory reclamation method, apparatus, electronic device, and storage medium that can solve the problems of electronic devices lag and slow operation speed.

[0005] In a first aspect, embodiments of this application provide a memory reclamation method, which includes: determining N reclamation threads and binding the N reclamation threads to cores in the CPU of an electronic device other than the target core, where the target core is the core with the highest operating frequency in the CPU and N is an even number greater than 0; reclamating the target page through the N reclamation threads when the remaining memory in the electronic device is less than a first preset threshold; and stopping the reclamation of the target page during the reclamation of the target page through the N reclamation threads, and when the remaining memory in the electronic device is greater than or equal to a second preset threshold.

[0006] Secondly, embodiments of this application provide a memory reclamation device, which includes a processing module and a reclamation module. The processing module is used to determine N reclamation threads and bind the N reclamation threads to cores in the CPU of an electronic device, excluding the target core, where the target core is the CPU core with the highest operating frequency, and N is an even number greater than 0. The reclamation module is used to reclamate the target page through the N reclamation threads when the remaining memory in the electronic device is less than a first preset threshold; and to stop reclamating the target page during the reclamation process through the N reclamation threads, provided that the remaining memory of the electronic device is greater than or equal to a second preset threshold.

[0007] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores programs or instructions executable on the processor, and the programs or instructions, when executed by the processor, implement the steps of the method described in the first aspect.

[0008] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.

[0009] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.

[0010] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.

[0011] In this embodiment, the electronic device can determine N (N being an even number greater than 0) recycling threads and bind these N recycling threads to CPU cores other than the target core, which is the CPU core with the highest operating frequency. Then, when the remaining memory in the electronic device is less than a first preset threshold, the electronic device can reclaim the target page through the even number of recycling threads. During the process of reclaiming the target page through the N recycling threads, and when the available memory of the electronic device is greater than or equal to a second preset threshold, the reclamation of the target page stops. In this solution, since the electronic device can reclaim the target page through N recycling threads, the memory release speed can be improved, thereby increasing the speed at which the electronic device requests memory. This avoids the problem of the electronic device running lag due to slow memory request speed. Moreover, by binding the N recycling threads to CPU cores other than the target core, the problem of the recycling threads and UI threads competing for memory resources of the super-large core (i.e., the target core of the CPU) and causing the electronic device to run lag is avoided. Thus, while improving the memory reclamation efficiency of the electronic device, the smoothness of the electronic device's operation is also improved. Attached Figure Description

[0012] Figure 1 This is a flowchart of a memory reclamation method provided in an embodiment of this application;

[0013] Figure 2 This is a schematic diagram of the structure of a memory reclamation device provided in an embodiment of this application;

[0014] Figure 3This is one of the hardware structure diagrams of an electronic device provided in the embodiments of this application;

[0015] Figure 4 This is a second schematic diagram of the hardware structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0016] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0017] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0018] The memory reclamation method provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.

[0019] Currently, the development and widespread use of electronic devices have brought great convenience to users' lives and work. Users are using electronic devices in more and more situations in daily life, and the number of applications on these devices is also increasing. As the memory occupied by these applications continues to grow, the available memory on electronic devices becomes increasingly limited. Therefore, when applications on electronic devices need to request a large amount of memory, slow memory allocation or inability to allocate memory may occur. In some applications that have speed requirements for memory allocation, slow memory allocation can cause the electronic device to lag or drop frames. The main reason for slow memory allocation is slow memory reclamation. In existing technologies, electronic devices can use a dedicated reclamation thread (such as the kswapd thread) to handle memory reclamation. However, the kswapd thread needs to reclaim both file pages and anonymous pages simultaneously, resulting in low reclamation efficiency. Furthermore, when certain applications on an electronic device require a large amount of memory, the kswapd thread is frequently awakened to perform memory reclamation. Since the kswapd thread is a kernel thread, it is often scheduled by the CPU of the electronic device to run on the high-performance core. At this time, if the CPU load is high, the kswapd thread will compete for resources with the user interface (UI) thread (the high-performance core manages more memory resources and runs at the highest frequency, so the UI thread can promptly request the required memory resources) on the high-performance core. This can cause the UI thread to be unable to obtain memory resources in time, which may lead to lag in the electronic device and affect the user's interactive experience.

[0020] In this embodiment, the electronic device can determine N (N being an even number greater than 0) recycling threads and bind these N recycling threads to CPU cores other than the target core, which is the CPU core with the highest operating frequency. Then, when the remaining memory in the electronic device is less than a first preset threshold, the electronic device can reclaim the target page through the even number of recycling threads. During the process of reclaiming the target page through the N recycling threads, and when the available memory of the electronic device is greater than or equal to a second preset threshold, the reclamation of the target page stops. In this solution, since the electronic device can reclaim the target page through N recycling threads, the memory release speed can be improved, thereby increasing the speed at which the electronic device requests memory. This avoids the problem of the electronic device running lag due to slow memory request speed. Moreover, by binding the N recycling threads to CPU cores other than the target core, the problem of the recycling threads and UI threads competing for memory resources of the super-large core (i.e., the target core of the CPU) and causing the electronic device to run lag is avoided. Thus, while improving the memory reclamation efficiency of the electronic device, the smoothness of the electronic device's operation is also improved.

[0021] The execution entity of the memory reclamation method provided in this application embodiment can be a memory reclamation device, which can be an electronic device or a functional module in an electronic device. The following uses an electronic device as an example to illustrate the technical solution provided in this application embodiment.

[0022] This application provides a memory reclamation method. Figure 1 A flowchart of a memory reclamation method provided in an embodiment of this application is shown. Figure 1 As shown, the memory reclamation method provided in this application embodiment may include the following steps 201 to 203.

[0023] Step 201: The electronic device determines N recycling threads and binds the N recycling threads to the CPU cores of the electronic device other than the target core.

[0024] In this embodiment of the application, the target core is the CPU core with the highest operating frequency, and N is an even number greater than 0.

[0025] For example, if a CPU has three cores, namely a first core, a second core, and a target core, and the operating frequency of the first core is lower than that of the second core, and the operating frequency of the second core is lower than that of the target core, after the electronic device obtains N recycling threads, the electronic device can bind these N recycling threads to the first core and the second core. In this way, during the memory reclamation process through the N recycling threads, the electronic device will not compete for the thread resources of the target core, thereby avoiding the problem of the recycling threads competing with the UI thread for the memory resources of the super core (i.e., the target core of the CPU), which would cause the electronic device to lag.

[0026] Optionally, in the embodiments of this application, step 201 above can be specifically implemented by step 201a below.

[0027] Step 201a: The electronic device determines the number of reclamation threads based on the amount of memory reclamation of X target applications in the electronic device over at least two consecutive predetermined durations, where X is an integer greater than 1.

[0028] In this embodiment of the application, if the number of recycling threads determined by the electronic device is odd, the electronic device rounds up the number of recycling threads to obtain an even number of recycling threads.

[0029] Optionally, in this embodiment of the application, the aforementioned X target applications are applications pre-set by the electronic device or determined by the electronic device based on the user's usage time.

[0030] For example, an electronic device can obtain the amount of memory reclaimed by the five most frequently used applications within 10 minutes and record it as N1. Then, it can record the amount of memory reclaimed by the five applications every 10 minutes and record it as NT. Then, it can calculate 2*(NT / N1) and round it up to determine the number of reclaiming threads.

[0031] Optionally, in this embodiment of the application, after determining the number of recycling threads, the electronic device can update the number of recycling threads based on the current system pressure value and the determined number of recycling threads.

[0032] It should be noted that the electronic device can re-determine the number of recycling threads every preset time interval based on the amount of memory reclaimed by X target applications over at least two consecutive predetermined time intervals.

[0033] Optionally, in this embodiment of the application, the electronic device can determine the current pressure value of the system based on the time taken for the memory allocation path to be reclaimed, and update the number of reclaiming threads based on the pressure value.

[0034] For example, when the average time taken for the electronic device to reclaim memory allocation paths exceeds 100ms, the electronic device can determine the number of reclaiming threads obtained as the number of reclaiming threads currently in use; or when there is a single reclaiming session that lasts longer than 2 seconds in the time taken for the electronic device to reclaim memory allocation paths, the electronic device can determine the number of reclaiming threads obtained as the number of reclaiming threads currently in use.

[0035] Optionally, in this embodiment of the application, when the system recycling pressure in the electronic device is greater than or equal to a preset threshold, the electronic device can immediately update the number of recycling threads, or when the system recycling pressure in the electronic device is less than the preset threshold, the electronic device can update the number of recycling threads every preset time interval.

[0036] Specifically, electronic devices can update the number of recycling threads through the underlying Kernel node within the electronic device.

[0037] In this embodiment, the electronic device can dynamically determine the number of current recycling threads based on the amount of memory reclaimed by X target applications over at least two consecutive predetermined durations. This allows the device to select an appropriate number of recycling threads based on its current system state, thereby improving the efficiency of memory reclamation while reducing the power consumption of running multiple recycling threads.

[0038] Step 202: If the remaining memory in the electronic device is less than the first preset threshold, the electronic device reclaims the target page through N reclamation threads.

[0039] Optionally, in this embodiment of the application, the above-mentioned targets include: file pages and anonymous pages.

[0040] In this embodiment of the application, a file page is used to represent reclaimable memory in an electronic device; an anonymous page is used to represent memory allocated to the electronic device.

[0041] In this embodiment, the electronic device can reclaim the remaining memory through N recycling threads, thereby reducing the running time of a single recycling thread and avoiding the problem of the electronic device overheating and consuming a lot of power due to the long running time of a single recycling thread.

[0042] Optionally, in this embodiment, the above-mentioned N recycling threads can be user-defined; or determined by the electronic device based on specific parameters (i.e., the file compression speed and random read / write speed of the target page described below).

[0043] It should be noted that each of the above N recycling threads is a kswapd thread.

[0044] Specifically, the number of recycling threads can be customized by the user. The user can set the number of recycling threads in the recycling thread settings interface. Then, after obtaining the number of recycling threads input by the user, the electronic device performs a downward even-number operation on the number of recycling threads to obtain N recycling threads.

[0045] For example, the electronic device can determine how many kswapd threads need to be initialized based on the number of kswapd threads set by the user. It can determine whether the value set by the user is even. If it is even, the electronic device initializes that many kswapd threads. If it is odd, it subtracts one to make it an even number as the number of kswapd threads to be initialized.

[0046] Optionally, in this embodiment of the application, the electronic device may display a prompt message on the recycling thread settings interface to prompt the user to input at least two items.

[0047] Optionally, in this embodiment of the application, the user can reset the number of kswapd threads in the recycling thread settings interface during the memory reclamation process of the electronic device. Then, the electronic device can re-initialize according to the number of kswapd threads set by the user (i.e., the downward even-selection process mentioned above), and then perform the next memory reclamation operation according to the number of re-initialized threads.

[0048] Optionally, in this embodiment of the application, the "electronic device reclaims the target page through N recycling threads" in step 202 above can be specifically implemented through step 301 below.

[0049] Step 301: The electronic device reclaims file pages through M out of N recycling threads, and reclaims anonymous pages through L other recycling threads besides M out of N recycling threads, where M and L are even numbers less than N.

[0050] For example, the condition for running N kswapd threads is still that the remaining memory is below the low water level (i.e., the first preset threshold mentioned above). Half of the N kswapd threads reclaim file pages and half reclaim anonymous pages, thereby accelerating the reclamation in parallel.

[0051] Optionally, the electronic device can allocate a corresponding number of kswapd threads to the application based on the application's usage.

[0052] For example, if the application is a foreground application, two kswapd threads are allocated to the application, meaning that the electronic device can wake up two kswapd threads at a time when the application performs memory reclamation; if the application is a background application, one kswapd thread is allocated to the application, meaning that the electronic device can wake up one kswapd thread at a time when the application performs memory reclamation.

[0053] In this embodiment, the electronic device can reclaim file pages and anonymous pages separately through N recycling threads. In this way, the electronic device can perform memory reclamation in parallel, thereby improving the efficiency of memory reclamation.

[0054] Optionally, in this embodiment of the application, the "electronic device reclaims file pages through M of the N recycling threads" in step 301 can be specifically implemented through step 301a.

[0055] Step 301a: When the CPU load in the electronic device is greater than or equal to a predetermined load, the electronic device prioritizes the reclamation of file pages through M reclamation threads.

[0056] It is understandable that since electronic devices require relatively little CPU resources to reclaim file pages, when the CPU load is greater than or equal to a predetermined load, electronic devices can prioritize reclaiming file pages. This allows for memory reclamation while ensuring the normal operation of the electronic device, thereby improving the efficiency of memory reclamation.

[0057] Optionally, in this embodiment of the application, the "electronic device reclaims anonymous pages through L recycling threads other than M recycling threads out of N recycling threads" in step 301 above can be specifically implemented through step 301b below.

[0058] Step 301b: When the CPU load in the electronic device is less than the predetermined load, anonymous pages are reclaimed preferentially through L reclamation threads.

[0059] It is understandable that since electronic devices require a large amount of CPU resources to reclaim anonymous pages, they can prioritize reclaiming anonymous pages when the CPU load is less than the predetermined load.

[0060] In this embodiment, the electronic device can dynamically select the memory to be reclaimed first based on the CPU load pressure, avoiding the situation where anonymous pages are still reclaimed even when the CPU load pressure in the electronic device is too high, resulting in low memory reclamation efficiency. This improves the flexibility and efficiency of memory reclamation in the electronic device.

[0061] Optionally, in this embodiment of the application, the "electronic device reclaims the target page through N recycling threads" in step 202 above can be specifically implemented through the following steps 401 and 402.

[0062] Step 401: The electronic device determines the target value based on the file compression speed and random read / write speed of the target page.

[0063] In this embodiment of the application, the target value is used to indicate the number of target pages to be reclaimed by N reclamation threads.

[0064] It should be noted that the target value mentioned above is the swappiness value.

[0065] Optionally, in this embodiment of the application, the electronic device can determine the number of target pages that can be reclaimed by the electronic device based on the average current file compression speed and the average current random read / write speed of the target page; or, the electronic device can determine the number of target pages that can be reclaimed by the electronic device based on the average historical file compression speed and the average historical file random read / write speed of the target page.

[0066] For example, the electronic device specifies a swappiness value between 0 and 200. The initial value of swappiness is generally the system default setting, typically 60. As the electronic device operates, it records the average file compression speed of the target page every 500ms, denoted as A, and the average random file read / write speed, denoted as F. Then, A and F are used to calculate the real-time swappiness value, using the following formula:

[0067] swappiness = N·X = 200N / (N+1) (Formula 1)

[0068] Where N is the ratio of A to F, and X is a constant, X = 200 / (N+1).

[0069] Step 402: If the change between the target value and the historical value is greater than or equal to the third preset threshold, the electronic device determines the number of target pages to be recycled by the N recycling threads based on the target value.

[0070] In this embodiment of the application, the aforementioned historical value is the target value determined when the first page of the history is recycled.

[0071] For example, if the absolute value of the difference between the currently calculated swappiness value and the previous value changes by more than 5%, the swappiness value is updated. Then, based on the updated swappiness value, the number of file pages and anonymous pages to be reclaimed is determined again, and memory reclamation is performed in a loop.

[0072] In this embodiment, the electronic device can dynamically adjust the target value in real time according to the file compression speed and random read / write speed of the target page, thereby balancing the reclamation ratio of the current file page and the current anonymous page, and thus achieving the most efficient memory reclamation effect.

[0073] Step 203: During the process of reclaiming the target page through N reclamation threads, and if the remaining memory of the electronic device is greater than or equal to the second preset threshold, the electronic device stops reclamation of the target page.

[0074] For example, the condition for N kswapd threads to stop running is still that the remaining memory is higher than the high water level (i.e., the second preset threshold mentioned above).

[0075] In this embodiment of the application, the electronic device can detect the current remaining memory in real time, and stop reclaiming the target page when the remaining memory is greater than or equal to a second preset threshold.

[0076] This application provides a memory reclamation method. An electronic device can identify N (N is an even number greater than 0) reclamation threads and bind these N threads to CPU cores other than the target core (the CPU core with the highest operating frequency). Then, when the remaining memory in the electronic device is less than a first preset threshold, the electronic device can reclaim the target page using the even number of reclamation threads. During the reclamation of the target page using the N threads, if the available memory of the electronic device is greater than or equal to a second preset threshold, the reclamation of the target page stops. In this solution, since the electronic device can reclaim the target page using N reclamation threads, the speed of memory release can be improved, thereby increasing the speed of memory allocation by the electronic device. This avoids the problem of the electronic device running slowly due to slow memory allocation. Furthermore, by binding the N reclamation threads to CPU cores other than the target core, the problem of reclamation threads and UI threads competing for memory resources of the high-performance core (i.e., the target CPU core) and causing the electronic device to run slowly is avoided. Thus, while improving the memory reclamation efficiency of the electronic device, the smoothness of its operation is also improved.

[0077] It should be noted that the memory reclamation method provided in this application can be executed by a memory reclamation device, an electronic device, or a functional module or entity within an electronic device. This application uses a memory reclamation device executing the memory reclamation method as an example to illustrate the memory reclamation device provided in this application.

[0078] Figure 2 A schematic diagram of a possible structure of the memory reclamation device involved in an embodiment of this application is shown. For example... Figure 2 As shown, the memory recycling device 70 may include a processing module 71 and a recycling module 72.

[0079] The processing module 71 is used to determine N recycling threads and bind the N recycling threads to the CPU cores of the electronic device, excluding the target core, where the target core is the CPU core with the highest operating frequency, and N is an even number greater than 0. The recycling module 72 is used to reclaim the target page through the N recycling threads when the remaining memory in the electronic device is less than a first preset threshold; and to stop reclaiming the target page during the process of reclaiming the target page through the N recycling threads, provided that the remaining memory of the electronic device is greater than or equal to a second preset threshold.

[0080] In one possible implementation, the first page includes a file page and an anonymous page; the recycling module 72 is specifically used to recycle the file page through M recycling threads out of N recycling threads, and to recycle the anonymous page through L other recycling threads out of N recycling threads besides M recycling threads, where M and L are even numbers less than N.

[0081] In one possible implementation, the aforementioned recycling module 72 is specifically used to prioritize the recycling of file pages through M recycling threads when the CPU load in the electronic device is greater than or equal to a predetermined load; or to prioritize the recycling of anonymous pages through L recycling threads when the CPU load in the electronic device is less than a predetermined load.

[0082] In one possible implementation, the aforementioned recycling module 72 is specifically used to determine a target value based on the file compression speed and random read / write speed of the target page. This target value is used to indicate the number of target pages to be recycled by N recycling threads. If the change between the target value and the historical value is greater than or equal to a third preset threshold, the number of target pages to be recycled by N recycling threads is determined based on the target value. The historical value is the target value determined when the target pages were recycled in the past.

[0083] In one possible implementation, the aforementioned processing module 71 is specifically used to determine the number of recycling threads based on the amount of memory reclaimed by X target applications in the electronic device over at least two consecutive predetermined durations, where X is an integer greater than 1.

[0084] This application provides a memory reclamation device. Since the memory reclamation device can reclaim target pages through N reclamation threads, it can improve the speed of memory release, thereby increasing the speed of memory allocation by the memory reclamation device. This avoids the problem of the memory reclamation device running slowly due to slow memory allocation. Moreover, by binding the N reclamation threads to CPU cores other than the target core, it avoids the problem of reclamation threads and UI threads competing for memory resources of the super core (i.e., the target core of the CPU), which would cause the memory reclamation device to run slowly. Thus, while improving the memory reclamation efficiency of the memory reclamation device, it also improves the smoothness of the memory reclamation device's operation.

[0085] The memory recycling device in this application embodiment can be a device, or a component, integrated circuit, or chip in an electronic device. The device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.

[0086] The memory reclamation device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit it.

[0087] The memory reclamation device provided in this application embodiment can achieve... Figure 1 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.

[0088] Optionally, such as Figure 3 As shown, this application embodiment also provides an electronic device 90, including a processor 91 and a memory 92. The memory 92 stores a program or instructions that can run on the processor 91. When the program or instructions are executed by the processor 91, they implement the various steps of the above-described memory reclamation method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0089] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0090] Figure 4 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.

[0091] The electronic device 100 includes, but is not limited to, components such as: radio frequency unit 101, network module 102, audio output unit 103, input unit 104, sensor 105, display unit 106, user input unit 107, interface unit 108, memory 109, and processor 110.

[0092] Those skilled in the art will understand that the electronic device 100 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 110 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0093] The processor 110 is used to determine N recycling threads and bind the N recycling threads to the CPU cores of the electronic device other than the target core, where the target core is the CPU core with the highest operating frequency and N is an even number greater than 0; and when the remaining memory in the electronic device is less than a first preset threshold, the target page is recycled through the N recycling threads; and when the target page is recycled through the N recycling threads and the remaining memory of the electronic device is greater than or equal to a second preset threshold, the recycling of the target page is stopped.

[0094] This application provides an electronic device. Since the electronic device can reclaim target pages through N recycling threads, the memory release speed can be improved, thereby increasing the speed of memory allocation for the electronic device. This avoids the problem of electronic device running lag caused by slow memory allocation. Moreover, by binding the N recycling threads to the CPU cores other than the target core, the problem of electronic device running lag caused by recycling threads and UI threads competing for memory resources of the super core (i.e., the target core of the CPU) is avoided. Thus, while improving the memory reclamation efficiency of the electronic device, the smoothness of the electronic device's operation is also improved.

[0095] Optionally, in this embodiment of the application, the target page includes a file page and an anonymous page; the processor 110 is specifically used to reclaim the file page through M of the N reclamation threads, and to reclaim the anonymous page through L of the N reclamation threads other than the M reclamation threads, where M and L are even numbers less than N.

[0096] Optionally, in this embodiment of the application, the processor 110 is specifically used to prioritize the reclamation of file pages through M reclamation threads when the CPU load in the electronic device is greater than or equal to a predetermined load; or to prioritize the reclamation of anonymous pages through L reclamation threads when the CPU load in the electronic device is less than a predetermined load.

[0097] Optionally, in this embodiment of the application, the processor 110 is specifically used to determine a target value based on the file compression speed and random read / write speed of the target page. The target value is used to indicate the number of target pages to be recycled by N recycling threads. If the change between the target value and the historical value is greater than or equal to a third preset threshold, the processor 110 determines the number of target pages to be recycled by N recycling threads at present based on the target value. The historical value is the target value determined when the target pages were recycled in the past.

[0098] Optionally, in this embodiment of the application, the processor 110 is specifically used to determine the number of recycling threads based on the amount of memory reclaimed by X target applications in an electronic device over at least two consecutive predetermined durations, where X is an integer greater than 1.

[0099] The electronic device provided in this application embodiment can implement the various processes implemented in the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0100] For details on the beneficial effects of the various implementation methods in this embodiment, please refer to the beneficial effects of the corresponding implementation methods in the above method embodiments. To avoid repetition, these will not be repeated here.

[0101] It should be understood that, in this embodiment, the input unit 104 may include a graphics processing unit (GPU) 1041 and a microphone 1042. The GPU 1041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 106 may include a display panel 1061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 107 includes at least one of a touch panel 1071 and other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include a touch detection device and a touch controller. Other input devices 1072 may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, and a joystick, which will not be described in detail here.

[0102] The memory 109 can be used to store software programs and various data. The memory 109 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 109 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 109 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.

[0103] Processor 110 may include one or more processing units; optionally, processor 110 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 110.

[0104] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0105] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0106] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.

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

[0108] This application provides a computer program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the memory reclamation method embodiments described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0109] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

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

[0111] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A memory reclamation method, characterized in that, The method includes: N recycling threads are determined, and the N recycling threads are bound to the CPU of the electronic device, excluding the target core, where the target core is the CPU with the highest operating frequency and N is an even number greater than 0. If the remaining memory in the electronic device is less than a first preset threshold, the target page is reclaimed through the N reclamation threads. If, during the process of reclaiming the target page through the N reclamation threads, the remaining memory of the electronic device is greater than or equal to the second preset threshold, the reclamation of the target page is stopped. The target page is reclaimed through N reclamation threads, including: The target value is determined based on the file compression speed and random read / write speed of the target page, and the target value is used to indicate the number of target pages to be reclaimed by the N reclamation threads; If the change between the target value and the historical value is greater than or equal to a third preset threshold, the number of target pages currently being recycled by the N recycling threads is determined based on the target value, where the historical value is the target value determined when the target pages were recycled in the past. The step of determining the target value based on the file compression speed and random read / write speed of the target page includes: swappiness=N·X=200N / (N+1); Wherein, swappiness is the target value, N is the ratio of A to F, A is the average file compression speed of the target page at preset intervals, F is the average random read / write speed of the target page at preset intervals, and X is a constant.

2. The method according to claim 1, characterized in that, The target pages include: file pages and anonymous pages; the process of reclaiming the target pages through N reclamation threads includes: The file pages are reclaimed by M of the N reclamation threads, and the anonymous pages are reclaimed by L of the other N reclamation threads besides the M reclamation threads, where M and L are even numbers less than N.

3. The method according to claim 2, characterized in that, The process of reclaiming file pages through M of the N reclamation threads includes: When the CPU load in the electronic device is greater than or equal to a predetermined load, the file pages are preferentially reclaimed through the M reclamation threads; The step of reclaiming the anonymous page using L recycling threads other than the M recycling threads out of the N recycling threads includes: When the CPU load in the electronic device is less than the predetermined load, the anonymous pages are preferentially reclaimed through the L reclamation threads.

4. The method according to claim 1, characterized in that, Get N recycling threads, including: The number of recycling threads is determined based on the amount of memory reclaimed by X target applications in the electronic device over at least two consecutive predetermined durations, where X is an integer greater than 1.

5. A memory reclamation device, characterized in that, The memory reclamation device includes a processing module and a reclamation module; the processing module is used to determine N reclamation threads and bind the N reclamation threads to the CPU of the electronic device, excluding the target core, where the target core is the CPU with the highest operating frequency and N is an even number greater than 0. The recycling module is configured to recycle the target page through the N recycling threads when the remaining memory in the electronic device is less than a first preset threshold; and to stop recycling the target page when the remaining memory of the electronic device is greater than or equal to a second preset threshold during the recycling process through the N recycling threads. The recycling module is specifically used to determine a target value based on the file compression speed and random read / write speed of the target page. The target value is used to indicate the number of target pages that the N recycling threads will recycle. If the change between the target value and the historical value is greater than or equal to a third preset threshold, the module determines the number of target pages that the N recycling threads will currently recycle based on the target value. The historical value is the target value determined when the target pages were recycled in the past. The recycling module is specifically used for swappiness=N·X=200N / (N+1); Wherein, swappiness is the target value, N is the ratio of A to F, A is the average file compression speed of the target page at preset intervals, F is the average random read / write speed of the target page at preset intervals, and X is a constant.

6. The apparatus according to claim 5, characterized in that, The first page includes a file page and an anonymous page; the recycling module is specifically used to recycle the file through M recycling threads out of the N recycling threads, and to recycle the anonymous page through L other recycling threads out of the N recycling threads besides the M recycling threads, where M and L are even numbers less than N.

7. The apparatus according to claim 6, characterized in that, The recycling module is specifically used to prioritize recycling the file pages through the M recycling threads when the CPU load in the electronic device is greater than or equal to a predetermined load; or to prioritize recycling the anonymous pages through the L recycling threads when the CPU load in the electronic device is less than the predetermined load.

8. The apparatus according to claim 5, characterized in that, The processing module is specifically used to determine the number of recycling threads based on the amount of memory reclaimed by X target applications in the electronic device over at least two consecutive predetermined durations, where X is an integer greater than 1.

Citation Information

Patent Citations

  • Memory recovery method and device, storage medium and electronic equipment

    CN111831441A

  • Memory recovery method and device

    CN114443510A

  • Memory recovery method and device for application program

    CN114490438A