Memory recovery method and device, electronic equipment and storage medium
By immediately performing memory recycling when the processor is idle, the problem of insufficient memory recycling speed in the prior art is solved, the memory recycling efficiency is improved, and the jamming of electronic devices caused by insufficient memory is avoided.
Patent Information
- Application Number
- CN202411648177.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-01-24
AI Technical Summary
In the prior art, electronic devices only perform memory recycling when memory is tight, resulting in slower memory recycling speed than memory application speed, which may cause electronic devices to stutter.
By obtaining the processor load information of the electronic equipment, when the processor is in an idle state, the memory is immediately recovered through the memory recycling thread to increase the number of memory recovery to maintain a high level in the free leisure.
It improves the efficiency of memory recycling, reduces the lag of electronic equipment caused by insufficient free memory, and ensures the smooth operation of electronic equipment.
Smart Images

Figure CN119356876A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory recycling technology, and in particular to a memory recycling method and device, an electronic device, and a storage medium. Background Art
[0002] When running various programs, electronic devices need to occupy a certain amount of memory space of the electronic devices. If the memory space of the electronic devices is insufficient, the operation of the electronic devices will be stuck.
[0003] In order to maintain the smooth operation of electronic devices, how to manage the memory space of electronic devices and improve the efficiency of recycling memory space is the optimization direction within the industry. Summary of the invention
[0004] The embodiments of the present application disclose a memory recycling method and device, an electronic device, and a storage medium, which can perform memory recycling when the processor of the electronic device is idle, thereby improving the memory recycling efficiency of the electronic device.
[0005] In a first aspect, an embodiment of the present application discloses a memory recovery method, which is applied to an electronic device, and the method includes:
[0006] Acquiring operation information of the electronic device, wherein the operation information includes a load of a processor of the electronic device;
[0007] If it is determined according to the load of the processor that the processor is in an idle state, the memory in the electronic device is reclaimed through a memory reclaiming thread.
[0008] A second aspect of an embodiment of the present application discloses a memory recovery device, which is applied to an electronic device, and the device further includes:
[0009] an acquisition unit, configured to acquire operation information of the electronic device, wherein the operation information includes a load of a processor of the electronic device;
[0010] The recycling unit is used to recycle the memory in the electronic device through a memory recycling thread when it is determined that the processor is in an idle state according to the load of the processor.
[0011] A third aspect of the present application discloses an electronic device, including:
[0012] A memory storing executable program code;
[0013] a processor coupled to the memory;
[0014] The processor calls the executable program code stored in the memory to execute the memory recovery method disclosed in the first aspect of the embodiment of the present application.
[0015] A fourth aspect of an embodiment of the present application discloses a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the memory recovery method disclosed in the first aspect of an embodiment of the present application.
[0016] The fifth aspect of the embodiments of the present application discloses a computer program product. When the computer program product runs on a computer, the computer executes part or all of the steps of any one of the methods of the first aspect of the embodiments of the present application.
[0017] A sixth aspect of an embodiment of the present application discloses an application publishing platform, which is used to publish a computer program product. When the computer program product runs on a computer, the computer executes part or all of the steps of any one of the methods of the first aspect of the embodiment of the present application.
[0018] Compared with the related art, the embodiments of the present application have the following beneficial effects:
[0019] In an embodiment of the present application, the electronic device can obtain the operation information of the electronic device; wherein the operation information of the electronic device may include the load of the processor of the electronic device; and then if the processor is determined to be in an idle state according to the load of the processor, the electronic device can recycle the memory in the electronic device through the memory recycling thread. It can be seen that in an embodiment of the present application, the electronic device can recycle memory when it is determined that the processor is in an idle state, which increases the number of memory recyclings, so that the free memory of the electronic device is maintained at a high level, rather than waiting until the free memory is insufficient to be used before reclaiming the memory, thereby improving the efficiency of memory recycling, and then avoiding the situation where the free memory of the electronic device is insufficient to be used as much as possible, ensuring the smooth operation of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 It is a flowchart of a memory recovery method disclosed in an embodiment of the present application;
[0022] Figure 2 It is a flowchart of another memory recovery method disclosed in an embodiment of the present application;
[0023] Figure 3 It is a flowchart of another memory recovery method disclosed in an embodiment of the present application;
[0024] Figure 4 It is a flowchart of another memory recovery method disclosed in an embodiment of the present application;
[0025] Figure 5 It is a structural schematic diagram of a memory recovery device disclosed in an embodiment of the present application;
[0026] Figure 6 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0028] It should be noted that the terms "first", "second", "third" and "fourth" in the specification and claims of the present application are used to distinguish different objects rather than to describe a specific order. The terms "including" and "having" in the embodiments of the present application and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device including a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] The embodiments of the present application disclose a memory recycling method and device, an electronic device, and a storage medium, which can perform memory recycling when the processor of the electronic device is idle, thereby improving the memory recycling efficiency of the electronic device.
[0030] The technical solution of the present application will be described in detail below in conjunction with specific embodiments.
[0031] In order to more clearly introduce the memory recycling method disclosed in the embodiment of the present application, the memory recycling technology in the related art is first introduced.
[0032] In the related art, electronic devices usually recycle memory through the kswapd recycling mechanism. The kswapd recycling mechanism is a kernel thread for memory recycling in the Linux kernel. The recycling mechanism is: when the free memory in the electronic device is lower than the low water mark threshold (low water mark), the kswapd thread is awakened to recycle memory until the free memory in the electronic device is higher than the high water mark threshold (high water mark).
[0033] It can be seen that in the related art, electronic devices only perform memory recycling when the free memory in the electronic device is lower than the low water mark threshold, that is, when the free memory available in the electronic device is tight. In practice, it is found that when memory recycling is performed only when the free memory is tight, the memory recycling speed may be slower than the memory application speed, resulting in failure to provide enough memory to the memory application party in time, which in turn causes the electronic device to freeze.
[0034] In this regard, the embodiment of the present application provides a memory recycling method to solve the technical defects in the related art. Optionally, the embodiment of the present application can be applied to various electronic devices that need to recycle memory, including but not limited to: portable electronic devices such as mobile phones and tablets, wearable devices such as smart watches and smart bracelets, or desktop devices such as desktop computers and desktop TVs, which are not limited here.
[0035] Optionally, the electronic device can obtain the operation information of the electronic device, wherein the operation information of the electronic device can include the load of the processor of the electronic device; and then if the processor is determined to be in an idle state according to the load of the processor, the electronic device can recycle the memory in the electronic device through the memory recycling thread. It can be seen that in the embodiment of the present application, the electronic device can recycle memory when it is determined that the processor is in an idle state, which increases the number of memory recyclings, so that the free memory of the electronic device is maintained at a high level, rather than waiting until the free memory is insufficient to be used before reclaiming the memory, thereby improving the efficiency of memory recycling, and then can avoid the situation where the free memory of the electronic device is insufficient to be used as much as possible, and ensure the smooth operation of the electronic device.
[0036] Exemplarily, after the electronic device opens the first application, the second application, and the third application in sequence, each application is used for a certain period of time; then the electronic device directly exits to the desktop of the electronic device and leaves it to rest; after a certain period of time, the electronic device determines that the processor is in an idle state according to the load of the processor, and the electronic device can recycle the memory in the electronic device through the memory recycling thread;
[0037] Furthermore, when the fourth application is started at this time, since the free memory has been reclaimed when the processor was idle before, the number of frame drops is reduced and the startup time is shortened during the process of starting the fourth application, thereby improving the smoothness of the operation of the electronic device.
[0038] Based on this, the memory recovery method and device, electronic device, and storage medium disclosed in the embodiments of the present application are introduced below.
[0039] See also Figure 1 , Figure 11 is a flowchart of a memory recovery method disclosed in an embodiment of the present application. Optionally, the method can be applied to the electronic device described above, or other execution entities. The present embodiment of the present application is introduced by taking the electronic device as an example, which should not be limited to the present embodiment of the present application. Optionally, the method can include the following steps:
[0040] 102. Obtain operating information of the electronic device, where the operating information includes a load of a processor of the electronic device.
[0041] In the embodiment of the present application, the electronic device can obtain the operation information of the electronic device through the operation information collection module. Optionally, the operation information collection module may include: a performance monitoring unit (Performance Monitoring Unit, PMU), HWiNFO, etc., which are not limited here.
[0042] In another embodiment, the electronic device may obtain an operation log of the electronic device, and obtain the operation information of the electronic device through the log information recorded in the operation log.
[0043] In an embodiment of the present application, the operating information of the electronic device may include: operating information of one or more hardware in the electronic device, operating information of one or more applications, operating information of one or more functions, and memory space of free memory, etc., which are not limited here.
[0044] Optionally, the one or more hardware may include: a central processing unit (CPU), a graphics processing unit (GPU), a memory module, a screen, etc., which are not limited here.
[0045] Optionally, the one or more applications may include: various applications built into the electronic device by default, or applications downloaded and installed from the Internet, which is not limited here.
[0046] Optionally, the one or more functions may include various functions that can be implemented by the electronic device, such as a memory recovery function, a screen on / off control function, etc., which are not limited here.
[0047] In the embodiment of the present application, the load of the processor of the electronic device is used to indicate the busyness of the electronic device. Optionally, the load of the processor can be indicated by the number of threads currently running on the processor. Exemplarily, the load of the processor is 4 threads, 8 threads, etc., which is not limited here.
[0048] In another embodiment, the load of the processor can be represented by the percentage of the processor currently used. Exemplarily, the load of the processor is 30%, 60%, etc., which is not selected here.
[0049] 104. If it is determined that the processor of the electronic device is in an idle state according to the load of the processor of the electronic device, the memory in the electronic device is reclaimed through a memory reclaiming thread.
[0050] In the embodiment of the present application, when the electronic device obtains the load of the processor, it can determine whether the processor is in an idle state according to the load of the processor of the electronic device.
[0051] If the processor is in an idle state, the electronic device can recycle the memory in the electronic device through a memory recycling thread, rather than waiting until the free memory is insufficient to recycle the memory, thereby improving the efficiency of memory recycling.
[0052] In addition, the processor is in an idle state, which means that the processor has sufficient capacity to run the memory recovery thread to perform memory recovery tasks without affecting other tasks. Therefore, memory recovery can be performed without causing the electronic device to freeze, thereby ensuring the smooth operation of the electronic device.
[0053] In an optional embodiment, the electronic device may determine that the processor is in an idle state by: determining whether the load of the processor is less than a load threshold.
[0054] The load threshold may be set by a developer based on a large amount of development experience, or by a user based on actual usage requirements. Typical values may include 40%, 50%, or 2 threads, 4 threads, etc., which are not limited here. Optionally, the load threshold may be less than half of the full load of the processor. For example, assuming that the full load of the processor is 100%, half is 50%, and the load threshold may be 35%, 40%, etc., which are less than 50%, which are not limited here.
[0055] Optionally, if the load of the processor is less than a load threshold, the electronic device may determine that the processor is in an idle state; if the load of the processor is not less than the load threshold, the electronic device may determine that the processor is not in an idle state.
[0056] By implementing the above method, the electronic device can determine whether the processor is in an idle state by determining whether the current processor load is less than the load threshold. This method only requires collecting the processor load and performing a simple threshold comparison, and is easy to implement, thereby reducing the implementation difficulty and cost of the method.
[0057] Optionally, the above-mentioned memory recycling thread may include: a thread created by the electronic device and used only for executing the memory recycling task when the processor is in an idle state; or
[0058] The kswapd thread described above; or,
[0059] It is a thread that can execute memory recycling tasks when the processor is in an idle state and the free memory of the electronic device is less than the space threshold, and is not limited here.
[0060] In an optional embodiment, the electronic device may create a memory reclaiming thread before reclaiming the memory in the electronic device through the memory reclaiming thread.
[0061] Optionally, the electronic device may run a memory recovery thread on a first core in the processor; optionally, the processor may further include a second core. Optionally, the power consumption of the first core is less than the power consumption of the second core, and / or the logical computing capability of the first core is lower than the logical computing capability of the second core.
[0062] Optionally, the first core may be the first N cores in the processor, and the second core may be one or more cores in the processor outside the first core, where N is a positive integer and is not limited here. Exemplarily, the first core may be cores 0 to 2, or cores 0 to 3 in the processor, and is not limited here.
[0063] It is understandable that the large cores in the processor with high power consumption and stronger logical computing capabilities are more suitable for performing more complex tasks in electronic devices, such as image optimization, running software, etc., to ensure the performance ceiling of electronic devices.
[0064] By implementing the above method, the electronic device can run the memory recovery thread through a small core with low power consumption and weak logical computing capability, thereby avoiding the situation where the processor cannot execute other more complex tasks due to the memory recovery thread occupying the large core in the processor, thereby ensuring that the processor has strong logical processing capabilities while performing memory recovery.
[0065] In the embodiment of the present application, the electronic device reclaims memory in the electronic device through the memory reclaim thread, including: reclaiming anonymous pages through the memory reclaim thread. The anonymous page may be data that does not exist in the form of a file, including: a heap, a stack, and a data segment, etc., which are not limited here.
[0066] By implementing the methods disclosed in the above embodiments, the electronic device can obtain the operation information of the electronic device; wherein the operation information of the electronic device may include the load of the processor of the electronic device; and then if the processor is determined to be in an idle state according to the load of the processor, the electronic device can recycle the memory in the electronic device through the memory recycling thread. It can be seen that in the embodiments of the present application, the electronic device can recycle memory when it is determined that the processor is in an idle state, which increases the number of memory recyclings and keeps the free memory of the electronic device at a high level, rather than waiting until the free memory is insufficient to be used before reclaiming the memory, thereby improving the efficiency of memory recycling, and then avoiding the situation where the free memory of the electronic device is insufficient to be used as much as possible, ensuring the smooth operation of the electronic device.
[0067] See also Figure 2 , Figure 2 1 is a flowchart of another memory recovery method disclosed in the embodiment of the present application. Optionally, the method can be applied to the electronic device described above, or other execution entities. The embodiment of the present application is introduced by taking the electronic device as an example, which should not be limited to the embodiment of the present application.
[0068] Optionally, the method may include the following steps:
[0069] 202. Obtain operation information of the electronic device, where the operation information includes a load of a processor of the electronic device and a memory space of a free memory of the electronic device.
[0070] In the embodiment of the present application, the operation information of the electronic device collected by the electronic device may also include: the memory space of the free memory of the electronic device.
[0071] The free memory may include: unused memory in the electronic device.
[0072] 204. If the processor is determined to be in an idle state according to the processor load, and the memory space of the free memory of the electronic device is less than the space threshold, the memory in the electronic device is reclaimed through a memory reclaiming thread; wherein the space threshold is greater than the low water mark threshold of the memory.
[0073] In the embodiment of the present application, considering that when the processor is in an idle state, there may be a situation where the free memory space in the electronic device is already sufficient, and forcibly reclaiming the memory at this time will waste the power consumption of the electronic device.
[0074] Optionally, when the electronic device determines that the processor is in an idle state according to the load of the processor, it can further determine whether the memory space of the free memory of the electronic device is less than the space threshold;
[0075] If the memory space of the free memory of the electronic device is less than the space threshold, it means that the memory space of the current free memory of the electronic device is not sufficient. For this, the memory in the electronic device can be reclaimed through a memory reclaiming thread.
[0076] It should be noted that the space threshold may be a low-level value of the memory space set by a developer or a user, and typical values may include: 200MB, 250MB, etc.
[0077] However, optionally, the space threshold may be greater than the low water mark threshold of the memory. The low water mark threshold is the lowest memory threshold that triggers other recycling mechanisms to recycle memory. Exemplarily, the low water mark threshold may be the low water mark threshold (low water mark) for triggering the kswapd recycling mechanism to recycle memory as described above.
[0078] As described above, when the free memory in the electronic device is lower than the low water mark threshold of other recycling mechanisms (such as the kswapd recycling mechanism) and triggers memory recycling, the free memory available in the electronic device is already very tight. In the embodiment of the present application, the space threshold can be greater than the low water mark threshold of the memory, that is, memory recycling can be triggered when other memory recycling mechanisms have not yet triggered memory recycling and the free memory in the electronic device is not very tight, thereby avoiding as much as possible the situation described above that memory recycling is performed only when the free memory available in the electronic device is tight, resulting in the inability to provide enough memory to the memory applicant in time, thereby causing the electronic device to freeze.
[0079] By implementing the above method, the electronic device can perform memory recycling only when the current free memory space is not sufficient, avoiding the situation where forced memory recycling is performed when the free memory is sufficient, resulting in a waste of power consumption of the electronic device; in addition, memory recycling can be triggered when other memory recycling mechanisms have not triggered memory recycling and the free memory in the electronic device is not very tight, avoiding the situation where the electronic device cannot provide sufficient memory to the memory applicant in time due to the memory recycling speed being slower than the memory application speed, which in turn causes the electronic device to freeze.
[0080] In another optional embodiment, if it is determined based on the processor load that the processor is not in an idle state, and / or the memory space of the electronic device's free memory is greater than or equal to a space threshold, the electronic device may execute step 202 again after waiting for the first period of time.
[0081] Optionally, the first duration may be set by a developer based on a large amount of development experience, or by a user based on actual usage requirements. Typical values may include 5 seconds, 6 seconds, etc., which are not limited here.
[0082] Optionally, while waiting for the first period of time, the electronic device can control the memory recovery thread to enter a sleep state, and reawaken the memory recovery thread after waiting for the first period of time, thereby avoiding the memory recovery thread preempting the processor during the waiting process, thereby improving the utilization efficiency of the processor.
[0083] By implementing the above method, when the electronic device determines that the memory recycling conditions are not met at present based on the processor load and the free memory of the electronic device, it waits for a certain period of time before performing memory recycling, thereby avoiding frequent triggering of inefficient memory recycling, and further reducing the computing power and power consumption of the electronic device.
[0084] In an optional embodiment, the operation information of the electronic device may further include: the on / off state of the memory recycling function of the electronic device, and the on / off state of the screen of the electronic device.
[0085] Among them, the memory recycling function may refer to: a function of performing memory recycling through a memory recycling thread. The switch state of the memory recycling function may include an on state and an off state, wherein the on state refers to a state in which the electronic device allows memory recycling through a memory recycling thread; the off state refers to a state in which the electronic device does not allow memory recycling through a memory recycling thread. Optionally, the on and off state of the memory recycling function may be switched by the user according to actual usage requirements, or may be switched automatically by the electronic device, which is not limited here.
[0086] Optionally, the on and off state of the screen of the electronic device may include a screen-on state and a screen-off state; wherein the screen-on state refers to a state where the screen of the electronic device is turned on, and the screen-off state may refer to a state where the screen of the electronic device is turned off, which is not limited here.
[0087] Optionally, before the electronic device recycles the memory in the electronic device through the memory recovery thread, if it is determined based on the operation information of the electronic device that the memory recovery function of the electronic device is turned on and the screen of the electronic device is in the bright screen state, the memory recovery thread of the electronic device can be awakened.
[0088] It is understandable that if the memory recycling function of the electronic device is turned on, it means that memory recycling is allowed through the memory recycling thread; and if the screen of the electronic device is in the bright screen state, it means that the user is currently using the electronic device with a high probability. In this regard, the above method can be implemented to allow memory recycling through the memory recycling thread, and the user is currently using the electronic device with a high probability. It can determine that the electronic device has a need for memory recycling, and then wake up the memory recycling thread, thereby improving the accuracy of waking up the memory recycling thread.
[0089] In another optional embodiment, if it is determined based on the operation information of the electronic device that the memory recovery function of the electronic device is in a turned-off state and / or the screen of the electronic device is in a turned-off state, the electronic device can control the memory recovery thread to give up the processor.
[0090] It is understandable that the threads in the electronic device (including the memory recovery thread) are run in the processor, and considering that the number of threads that the processor can execute in parallel is limited, when it is determined that the memory recovery function of the electronic device is in a turned off state, and / or the screen of the electronic device is in a screen-off state, that is, the electronic device will not wake up the memory recovery thread, the memory recovery thread is controlled to actively give up the processor so that other threads can use the processor, which can improve the use efficiency of the processor.
[0091] As an optional implementation, when the electronic device determines that the processor is in an idle state according to the load of the processor, the electronic device may further obtain the charging state information of the electronic device;
[0092] Optionally, if the electronic device is in a charging state, the memory in the electronic device may be reclaimed through a memory reclaiming thread.
[0093] It is understandable that the processor may be idle for only a short time, and the user may continue to use the electronic device. Reclaiming the memory too early at this time may mistakenly close some programs or functions that the user is using.
[0094] When the processor is in an idle state, if it is further determined that the electronic device is in a charging state, the current user is most likely not using the mobile phone normally, and the processor is also most likely to be idle for a period of time in the future. In this case, the memory in the electronic device can be recycled through a memory recycling thread, thereby avoiding the accidental closure of some programs or functions that the user is using, thereby improving the intelligence and flexibility of the method and improving the user experience.
[0095] In another optional implementation, if the electronic device is not in a charging state, the remaining power of the electronic device is obtained; if the remaining power is less than the power threshold, the memory in the electronic device is not recycled through the memory recycling thread;
[0096] If the remaining power is greater than or equal to the power threshold, the memory in the electronic device is reclaimed through the memory reclaiming thread.
[0097] It is understandable that recycling memory in an electronic device through a memory recycling thread consumes the power of the electronic device. Therefore, when there is not much remaining power, memory recycling may not be triggered, thereby improving the battery life of the electronic device.
[0098] By implementing the methods disclosed in the above embodiments, the electronic device can obtain the operating information of the electronic device; wherein the operating information of the electronic device may include the load of the processor of the electronic device; and if it is determined that the processor is in an idle state based on the load of the processor, the electronic device can recycle the memory in the electronic device through a memory recycling thread. It can be seen that in the embodiment of the present application, the electronic device can perform memory recycling when it is determined that the processor is in an idle state, which increases the number of memory recyclings and keeps the free memory of the electronic device at a high level, rather than waiting until the free memory is insufficient to use before performing memory recycling, thereby improving the efficiency of memory recycling, and then avoiding the situation where the free memory of the electronic device is insufficient to use as much as possible, ensuring the smooth operation of the electronic device; and, memory recycling can be performed when the memory space of the current free memory is not very sufficient, avoiding the situation where forced memory recycling is performed when the free memory is sufficient, resulting in a waste of power consumption of the electronic device; in addition, memory recycling can be triggered when other memory recycling mechanisms have not triggered memory recycling and the free memory in the electronic device is not very tight, avoiding the situation where the electronic device cannot provide enough memory to the memory applicant in time due to the memory recycling speed being slower than the memory application speed, thereby causing the electronic device to freeze; and, when memory recycling is allowed to be performed through the memory recycling thread and the user is currently using the electronic device with a high probability, it is determined that the electronic device has a need for memory recycling, and then the memory recycling thread is awakened, thereby improving the accuracy of awakening the memory recycling thread.
[0099] See also Figure 3 , Figure 3 This is a flowchart of another memory recovery method disclosed in the embodiment of the present application. Optionally, the method can be applied to the electronic device described above, or other execution entities. The embodiment of the present application is introduced by taking the electronic device as an example, which should not be limited to the embodiment of the present application.
[0100] Optionally, the method may include the following steps:
[0101] 302. Obtain operation information of the electronic device, where the operation information includes a load of a processor of the electronic device and a memory space of a free memory of the electronic device.
[0102] 304. If it is determined according to the load of the processor that the processor is in an idle state, and the memory space of the free memory of the electronic device is less than the space threshold, the memory in the electronic device is reclaimed through a memory reclaiming thread.
[0103] In an optional embodiment, when the memory recycling thread finishes the current memory recycling, the electronic device can control the memory recycling thread to enter a dormant state; and after waiting for a certain dormant period, the memory recycling thread is reawakened.
[0104] That is, the electronic device can periodically wake up the memory recovery thread to avoid the memory recovery thread occupying the processor all the time when no memory recovery task is performed, thereby improving the utilization efficiency of the processor.
[0105] Optionally, when the memory recycling thread completes the memory recycling, the electronic device can also determine whether the memory space recycled is less than a second recycling threshold; wherein the second recycling threshold can be set by the developer based on a large amount of development experience, or can be set by the user based on actual usage requirements. Typical values may include: 256KB, 512KB, etc., which are not limited here.
[0106] Optionally, if the memory space reclaimed this time is less than the second reclaiming threshold, the electronic device may increase the sleep time of the memory reclaiming thread in the sleep state this time.
[0107] It is understandable that if the memory space reclaimed by the memory recycling thread is relatively small, it means that there is relatively little free memory that can be recycled in the electronic device, and usually there will not be a large amount of free memory that can be recycled in a short period of time. In this regard, the above method is implemented. When the electronic device determines that the memory space reclaimed by the memory recycling thread is relatively small, the sleep time of the memory recycling thread can be increased to avoid frequently waking up the memory recycling thread for memory recycling, thereby reducing the power consumption of the electronic device.
[0108] In an optional embodiment, when the electronic device determines that the memory space reclaimed by the memory reclaiming thread this time is less than the second reclaiming threshold, the count value of the counter may be increased by one; and if the memory space reclaimed this time is greater than or equal to the second reclaiming threshold, the count value of the counter may be cleared. The count value of the counter represents: the target number of times that the memory space reclaimed by the memory reclaiming thread in history is less than the second reclaiming threshold.
[0109] In one embodiment, the electronic device may determine the sleep duration of the memory recycling thread in the sleep state according to the target number of times.
[0110] Optionally, the electronic device can construct an exponential function with the first value as the base and the difference between the target number and the second value as the exponent, and calculate the calculation result corresponding to the exponential function; and then determine the calculation result as the sleep duration of the memory recovery thread in the sleep state this time.
[0111] The first value and the second value may be set by developers based on a large amount of development experience. The first value and the second value may be the same or different, which is not limited here.
[0112] For example, assuming that the first value is 2, the second value is 1, the target number is 3, and the unit of the sleep time is seconds, the exponential function 2( 3-1 ), and then it can be obtained that the sleep time of the memory recycling thread in the sleep state is 4 seconds.
[0113] By implementing the above method, the electronic device can increase the sleep time of the memory recovery thread to a greater extent when the number of times the memory space has been continuously recovered in history is relatively small, so as to reduce the number of times the memory recovery thread performs inefficient memory recovery, thereby saving the power consumption of the electronic device; in addition, the sleep time of the memory recovery thread is determined based on the target number of times the memory space has been continuously recovered in history that is less than the second recovery threshold, which also improves the flexibility of the method.
[0114] In another optional embodiment, after the electronic device determines the sleep duration of the memory recovery thread in the sleep state according to the target number of times, it can determine whether the determined sleep duration of the memory recovery thread in the sleep state is greater than a third duration; the third duration can be the upper limit of the sleep duration of the memory recovery thread set by the developer or user, and typical values may include 5 minutes, 6 minutes, etc., which are not limited here.
[0115] Optionally, if the sleep time duration of the memory reclaiming thread in the sleep state this time is greater than the third time duration, the third time duration may be determined as the sleep time duration of the memory reclaiming thread in the sleep state this time.
[0116] By implementing the above method, an upper limit can be set for the sleep time of the memory recovery thread, thereby preventing the memory recovery thread from sleeping for a long time and failing to perform memory recovery work in time, which in turn leads to insufficient free memory of the electronic device, thereby improving the intelligence and compatibility of the method.
[0117] 306. If the currently reclaimed memory space is greater than or equal to the first reclaiming threshold, stop reclaiming the memory.
[0118] In an embodiment of the present application, during the process of reclaiming memory in the electronic device through a memory recovery thread, the electronic device can determine whether the currently reclaimed memory space is greater than or equal to a first recovery threshold; wherein the first recovery threshold can be set by the developer based on a large amount of development experience, or by the user based on actual usage requirements, and typical values may include 10M, 20M, etc., which are not limited here.
[0119] Optionally, if the currently reclaimed memory space is greater than or equal to a first recycling threshold, the electronic device can stop reclaiming memory to avoid the electronic device from excessively recycling memory, thereby avoiding the situation where certain running programs or functions are interrupted due to excessive memory recycling, thereby ensuring the normal operation of the electronic device.
[0120] In another embodiment, if the currently reclaimed memory space is less than the first reclaiming threshold, the electronic device can determine whether the memory space of the electronic device has been traversed; if not, the electronic device can reclaim the memory in the electronic device through the memory reclaiming thread.
[0121] In an optional embodiment, the electronic device may reclaim memory in the electronic device through a memory reclaiming thread, for example:
[0122] The electronic device determines whether there is a locked memory in the memory included in the electronic device, wherein the locked memory is memory that is not allowed to be reclaimed by the memory reclaiming thread;
[0123] If it exists, the memory other than the locked memory in the electronic device is reclaimed through the memory reclaiming thread.
[0124] By implementing the above method, the electronic device may not recycle the locked memory, thereby improving the flexibility of the method.
[0125] Optionally, after the electronic device recycles other memories except the locked memory in the electronic device through the memory recycle thread, if the currently reclaimed memory space is less than the first recycle threshold, the electronic device may obtain the current usage status of the locked memory;
[0126] If the locked memory is currently in an unused state, application information can be output, and the application information is used to apply for reclaiming the locked memory;
[0127] If a first instruction allowing the locked memory to be reclaimed is detected, the locked memory may be reclaimed by a memory reclaiming thread.
[0128] By implementing the above method, the electronic device can request to reclaim unused locked memory when the memory space currently reclaimed by the memory reclaiming thread is small, thereby improving the flexibility of the method.
[0129] By implementing the methods disclosed in the above-mentioned embodiments, the electronic device can obtain the operation information of the electronic device; wherein the operation information of the electronic device may include the load of the processor of the electronic device; and then if it is determined that the processor is in an idle state according to the load of the processor, the electronic device can recycle the memory in the electronic device through the memory recycling thread. It can be seen that in the embodiments of the present application, the electronic device can perform memory recycling when it is determined that the processor is in an idle state, which increases the number of memory recyclings, so that the free memory of the electronic device is maintained at a high level, rather than waiting until the free memory is insufficient to be used before performing memory recycling, thereby improving the efficiency of memory recycling, and then it can avoid as much as possible the situation where the free memory of the electronic device is insufficient to be used, ensuring the smooth operation of the electronic device; and, when the electronic device determines that the memory recycling thread has recycled a relatively small amount of memory space this time, it can increase the sleep time of the memory recycling thread this time to avoid frequently waking up the memory recycling thread for memory recycling, thereby reducing the power consumption of the electronic device; and, it can In the case where the number of times that the memory space has been continuously reclaimed in history is relatively large, the sleep duration of the memory recovery thread is increased to a greater extent to reduce the number of times the memory recovery thread performs inefficient memory recovery, thereby saving power consumption of the electronic device; in addition, the sleep duration of the memory recovery thread is determined based on the target number of times that the memory space has been continuously reclaimed in history is less than the second recovery threshold, which also improves the flexibility of the method; and, if the currently reclaimed memory space is greater than or equal to the first recovery threshold, the electronic device can stop reclaiming memory to avoid the electronic device from excessively reclaiming memory, thereby avoiding the situation where certain running programs or functions are interrupted due to excessive memory recovery, thereby ensuring the normal operation of the electronic device.
[0130] In order to more clearly introduce the method disclosed in the embodiment of the present application, the following Figure 4 Make an introduction, Figure 4 This is a flowchart of another memory recovery method disclosed in the embodiment of the present application.
[0131] 402. Create a memory recycling thread, and set the memory recycling thread to run on the first core.
[0132] 404. Determine whether the memory recycling function is enabled; if so, execute step 406; if not, execute step 408.
[0133] 406. Determine whether the screen of the electronic device is in a bright screen state; if so, execute step 410; if not, execute step 408.
[0134] 408. Control the memory recovery thread to give up the processor.
[0135] 410. Determine whether the processor load is less than a load threshold; if so, execute step 412; if not, execute step 414.
[0136] 412. Determine whether the memory space of the free memory is less than the space threshold; if so, execute step 416; if not, execute step 414.
[0137] 414. Control the memory recovery thread to enter a dormant state, and re-execute step 404 after dormancy for a certain period of time.
[0138] 416. Traverse the memory space of the electronic device.
[0139] 418. Determine again whether the free memory space is less than the space threshold; if so, execute step 420.
[0140] 420. Reclaim memory through the memory recycling thread.
[0141] 422. Determine whether the memory space reclaimed this time is greater than or equal to the first reclaim threshold; if not, execute step 424.
[0142] 424. Determine whether the memory space of the electronic device has been traversed; if so, execute step 426; if not, execute step 416.
[0143] 426. Determine whether the memory space reclaimed this time is less than the second reclaim threshold; if so, execute step 428.
[0144] 428. Determine, based on a target number of times that the memory space continuously reclaimed in history is less than a second reclaim threshold, a dormancy duration of the memory reclaiming thread in the dormant state this time.
[0145] See also Figure 5 , Figure 5 is a schematic diagram of the structure of a memory recovery device disclosed in an embodiment of the present application. Optionally, the device can be applied to the electronic device described above, or other execution entities. The present embodiment of the application is introduced by taking the electronic device as an example, which should not be limited to the present embodiment of the application. Optionally, the device may include an acquisition unit 502 and a recovery unit 504, wherein:
[0146] An acquisition unit 502 is used to acquire operation information of the electronic device, where the operation information includes a load of a processor of the electronic device;
[0147] The recycling unit 504 is used to recycle the memory in the electronic device through a memory recycling thread when it is determined that the processor is in an idle state according to the load of the processor.
[0148] By implementing the above device, the electronic device can obtain the operation information of the electronic device; wherein the operation information of the electronic device may include the load of the processor of the electronic device; and then if the processor is determined to be in an idle state according to the load of the processor, the electronic device can recycle the memory in the electronic device through the memory recycling thread. It can be seen that in the embodiment of the present application, the electronic device can recycle memory when it is determined that the processor is in an idle state, which increases the number of memory recyclings, so that the free memory of the electronic device is maintained at a high level, instead of waiting until the free memory is insufficient to be used before reclaiming the memory, thereby improving the efficiency of memory recycling, and then avoiding the situation where the free memory of the electronic device is insufficient to be used as much as possible, ensuring the smooth operation of the electronic device.
[0149] As an optional implementation, the recycling unit 504 is further used to determine that the processor of the electronic device is in an idle state when the load of the processor is less than a load threshold, and recycle the memory in the electronic device through a memory recycling thread.
[0150] By implementing the above device, the electronic device can determine whether the processor is in an idle state by determining whether the current processor load is less than a load threshold. This method only requires collecting the processor load and performing a simple threshold comparison, and is easy to implement, thereby reducing the implementation difficulty and cost of the method.
[0151] As an optional implementation, the operation information of the electronic device also includes: the memory space of the free memory of the electronic device; the recycling unit 504 is also used to recycle the memory in the electronic device through a memory recycling thread when it is determined that the processor is in an idle state according to the load of the processor and the memory space of the free memory of the electronic device is less than the space threshold, and the space threshold is greater than the low water mark threshold of the memory.
[0152] By implementing the above-mentioned device, the electronic device can perform memory recycling only when the current free memory space is not sufficient, thereby avoiding the situation where forced memory recycling is performed when the free memory is sufficient, resulting in a waste of power consumption of the electronic device; in addition, memory recycling can be triggered when other memory recycling mechanisms have not triggered memory recycling and the free memory in the electronic device is not very tight, thereby avoiding the situation where the electronic device cannot provide sufficient memory to the memory applicant in time due to the memory recycling speed being slower than the memory application speed, which in turn causes the electronic device to freeze.
[0153] As an optional implementation, the operation information of the electronic device further includes: a switch state of a memory recycling function of the electronic device, and a light-on and light-off state of a screen of the electronic device;
[0154] as well as, Figure 5 The device shown may further include a wake-up unit not shown in the figure, wherein:
[0155] The wake-up unit is used to wake up the memory recovery thread of the electronic device before reclaiming the memory in the electronic device through the memory recovery thread, if it is determined according to the operation information of the electronic device that the memory recovery function of the electronic device is turned on and the screen of the electronic device is in the bright screen state.
[0156] By implementing the above device, when memory recovery is allowed through the memory recovery thread and the user is currently using the electronic device with a high probability, it can be determined that the electronic device has a need to recover memory, and then the memory recovery thread is awakened, thereby improving the accuracy of awakening the memory recovery thread.
[0157] As an optional implementation, the recycling unit 504 is further configured to recycle memory in the electronic device through a memory recycling thread, and stop recycling memory if the currently recycled memory space is greater than or equal to a first recycling threshold.
[0158] When the above device is implemented, if the currently reclaimed memory space is greater than or equal to the first recycling threshold, the electronic device can stop reclaiming memory to avoid the electronic device from excessively recycling memory, thereby avoiding the situation where certain running programs or functions are interrupted due to excessive memory recycling, thereby ensuring the normal operation of the electronic device.
[0159] As an optional implementation, the recycling unit 504 is also used to control the memory recycling thread to enter a sleep state when the memory recycling thread ends the current memory recycling; and if the memory space recycled this time is less than the second recycling threshold, the sleep time of the memory recycling thread in the sleep state is increased.
[0160] By implementing the above device, when the electronic device determines that the memory space reclaimed by the memory reclaiming thread is relatively small, the sleep time of the memory reclaiming thread can be increased to avoid frequently waking up the memory reclaiming thread for memory reclaiming, thereby reducing the power consumption of the electronic device.
[0161] As an optional implementation manner, the sleep duration of the memory recycling thread in the sleep state this time is determined according to the target number of times that the memory space continuously recycled in history is less than the second recycling threshold.
[0162] By implementing the above-mentioned device, the electronic device can increase the sleep time of the memory recovery thread to a greater extent when the number of times that the memory space has been continuously recovered in history is relatively small, so as to reduce the number of times the memory recovery thread performs inefficient memory recovery, thereby saving the power consumption of the electronic device; in addition, by determining the sleep time of the memory recovery thread based on the target number of times that the memory space has been continuously recovered in history is less than the second recovery threshold, the flexibility of the method is also improved.
[0163] As an optional implementation, Figure 5 The device shown may also include a creation unit not shown, wherein:
[0164] A creation unit is used to create a memory recovery thread before reclaiming memory in the electronic device through the memory recovery thread; and run the memory recovery thread on a first core in a processor, the processor also includes a second core, and the power consumption of the first core is less than the power consumption of the second core.
[0165] By implementing the above device, the electronic device can run the memory recovery thread through a small core with low power consumption and weak logical computing capability, thereby avoiding the situation where the processor cannot execute other more complex tasks due to the memory recovery thread occupying the large core in the processor, thereby ensuring that the processor has strong logical processing capabilities while performing memory recovery.
[0166] See also Figure 6 , Figure 6 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application.
[0167] like Figure 6 As shown, the electronic device may include:
[0168] A memory 601 storing executable program codes;
[0169] a processor 602 coupled to the memory 601;
[0170] The processor 602 calls the executable program code stored in the memory 601 to execute the memory recovery method disclosed in the above embodiments.
[0171] An embodiment of the present application discloses a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the memory recycling method disclosed in the above embodiments.
[0172] The embodiments of the present application also disclose an application publishing platform, wherein the application publishing platform is used to publish a computer program product, wherein when the computer program product runs on a computer, the computer executes part or all of the steps of the method in the above method embodiments.
[0173] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. Those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required for the present application.
[0174] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the above-mentioned processes does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0175] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0176] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0177] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several requests for a computer device (which can be a personal computer, a server or a network device, etc., specifically a processor in a computer device) to perform some or all of the steps of the above-mentioned methods of various embodiments of the present application.
[0178] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0179] The memory recovery method and device, electronic device, and storage medium disclosed in the embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A memory recovery method, characterized in that: Applied to electronic equipment, the method comprises: Acquiring operation information of the electronic device, wherein the operation information includes a load of a processor of the electronic device; If it is determined according to the load of the processor that the processor is in an idle state, the memory in the electronic device is reclaimed through a memory reclaiming thread.
2. The method according to claim 1, characterized in that If it is determined according to the load of the processor that the processor is in an idle state, reclaiming the memory in the electronic device through a memory reclaiming thread, comprises: If the load of the processor is less than the load threshold, it is determined that the processor of the electronic device is in an idle state, and the memory in the electronic device is reclaimed through a memory reclaiming thread.
3. The method according to claim 1, characterized in that The operation information of the electronic device also includes: memory space of the free memory of the electronic device; If it is determined according to the load of the processor that the processor is in an idle state, reclaiming the memory in the electronic device through a memory reclaiming thread, comprises: If the processor is determined to be in an idle state based on the load of the processor, and the memory space of the free memory of the electronic device is less than a space threshold, the memory in the electronic device is reclaimed through a memory recycling thread, and the space threshold is greater than the low water mark threshold of the memory.
4. The method according to claim 1, characterized in that: The operation information of the electronic device also includes: the on / off state of the memory recycling function of the electronic device, and the on / off state of the screen of the electronic device; Furthermore, before reclaiming the memory in the electronic device through the memory reclaiming thread, the method further includes: If it is determined according to the operation information of the electronic device that the memory recovery function of the electronic device is in an on state and the screen of the electronic device is in a bright screen state, the memory recovery thread of the electronic device is awakened.
5. The method according to claim 1, characterized in that The reclaiming of memory in the electronic device through a memory reclaiming thread includes: The memory in the electronic device is reclaimed through a memory reclaiming thread, and if the currently reclaimed memory space is greater than or equal to a first reclaiming threshold, memory reclaiming is stopped.
6. The method according to claim 1, characterized in that The reclaiming of memory in the electronic device through a memory reclaiming thread includes: When the memory recycling thread finishes the current memory recycling, controlling the memory recycling thread to enter a dormant state; If the memory space reclaimed this time is less than the second reclaiming threshold, the sleep time length of the memory reclaiming thread in the sleep state this time is increased.
7. The method according to claim 6, characterized in that The sleep duration of the memory recovery thread in the sleep state this time is determined according to the target number of times that the memory space continuously recovered in history is less than the second recovery threshold.
8. The method according to any one of claims 1 to 7, characterized in that: Before reclaiming the memory in the electronic device through the memory reclaiming thread, the method further includes: Create a memory recycling thread; The memory reclaiming thread is run on a first core in the processor, the processor further includes a second core, and the power consumption of the first core is less than the power consumption of the second core.
9. A memory recovery device, characterized in that: Applied to electronic equipment, the device further comprises: an acquisition unit, configured to acquire operation information of the electronic device, wherein the operation information includes a load of a processor of the electronic device; The recycling unit is used to recycle the memory in the electronic device through a memory recycling thread when it is determined that the processor is in an idle state according to the load of the processor.
10. An electronic device, characterized in that: It comprises a memory storing executable program code and a processor coupled to the memory; wherein the processor calls the executable program code stored in the memory to execute the method according to any one of claims 1 to 8.
11. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Cited By
Memory reclamation method and apparatus, electronic device, and storage medium
WO2026103923A1