Search

CN-122019120-A - Memory recycling method and device

CN122019120ACN 122019120 ACN122019120 ACN 122019120ACN-122019120-A

Abstract

A memory recovery method and device are used for reasonably recovering memory resources occupied by an application in a background, and reducing memory data to be recovered after the application is switched to the foreground, so that the problem of blocking is avoided. The method includes the electronic device determining cold data and hot data in target memory data of any application in the foreground. When the memory idle amount of the electronic device is smaller than the first threshold, the electronic device can determine the memory recovery amount of any application in the background according to the memory recovery total amount, and release the target memory data of any application according to the memory recovery amount of the application and the data amount of the cold data and the data amount of the hot data of the application.

Inventors

  • LIU YUTAO
  • CHEN JIAN
  • XU YIPING
  • GAO ENBO
  • LI XUHUI
  • FANG SIWEI
  • CHEN CHAOFAN
  • Lan Dongwan

Assignees

  • 华为终端有限公司

Dates

Publication Date
20260512
Application Date
20250929

Claims (16)

  1. 1. The memory recycling method is characterized by being applied to electronic equipment and comprising the following steps of: When a first application is in a foreground, determining cold data and hot data in target memory data of the first application, wherein the first application is any application; when the memory idle amount of the electronic equipment is smaller than a first threshold value, determining the memory recovery amount of at least one second application in the background according to the memory recovery total amount; The target memory data of each second application is released by the following steps: And releasing the target memory data of the target second application according to the memory recovery amount of the target second application, the data amount of the cold data and the data amount of the hot data of the target second application, wherein the target second application is any one of the at least one second application.
  2. 2. The method of claim 1, wherein releasing the target memory data of the target second application based on the memory reclamation amount of the target second application and the data amount of the cold data and the data amount of the hot data of the target second application comprises: Determining the recovery amount of the cold data and the recovery amount of the hot data of the target second application according to the recovery amount of the memory of the target second application and the data amount of the cold data and the data amount of the hot data of the target second application, wherein the sum of the recovery amount of the cold data and the recovery amount of the hot data of the target second application is more than or equal to the recovery amount of the memory of the target second application, the recovery amount of the cold data is more than 0, and the recovery amount of the hot data is more than or equal to 0; Determining cold data to be recovered in the cold data of the target second application according to the recovery quantity of the cold data, and releasing the cold data to be recovered; And when the recovery amount of the thermal data is larger than 0, determining thermal data to be recovered in the thermal data of the target second application according to the recovery amount of the thermal data, and releasing the thermal data to be recovered.
  3. 3. The method of claim 2, wherein determining the amount of recovered cold data and the amount of recovered hot data for the target second application based on the amount of memory recovered for the target second application and the amount of cold data and the amount of hot data for the target second application comprises: When the recovery amount of the memory of the target second application is smaller than or equal to a second threshold value, determining that the recovery amount of the cold data is the recovery amount of the memory of the target second application and the recovery amount of the hot data is 0, wherein the second threshold value is smaller than the data amount of the cold data of the target second application; When the recovery amount of the memory of the target second application is larger than the second threshold and smaller than a third threshold, determining that the recovery amount of the cold data is the second threshold, and the recovery amount of the hot data is the difference between the recovery amount of the memory of the target second application and the second threshold, wherein the third threshold is larger than the data amount of the cold data of the second application; And when the recovery amount of the memory of the target second application is greater than or equal to the third threshold, determining that the recovery amount of the cold data is a fourth threshold, and determining that the recovery amount of the hot data is the difference between the recovery amount of the memory of the target second application and the fourth threshold, wherein the fourth threshold is smaller than the data amount of the cold data of the target second application and is greater than the second threshold.
  4. 4. The method of claim 3, wherein the second threshold is determined from a first set proportion to the amount of cold data of the target second application, wherein the third threshold is determined from a second set proportion to the amount of cold data of the target second application, and wherein the fourth threshold is set from a third set proportion to the amount of cold data of the target second application, wherein the first proportion is less than the third set proportion and the third set proportion is less than the second set proportion.
  5. 5. The method of any of claims 2-4, wherein the cold data to be reclaimed comprises a plurality of cold data occupying non-contiguous memory space and the hot data to be reclaimed comprises a plurality of hot data occupying non-contiguous memory space.
  6. 6. The method of any of claims 2-5, wherein after releasing the heat data to be recovered, the method further comprises: And after the target second application is switched to the foreground, recovering the thermal data to be recovered.
  7. 7. The method of any one of claims 1-6, wherein the method further comprises: When the memory idle amount of the electronic equipment is smaller than a fifth threshold value, determining at least one first system service on which at least one third application in the background depends; Closing part or all of the at least one third application and part or all of the at least one first system service.
  8. 8. The method of claim 7, wherein the shutting down some or all of the at least one first system service comprises: Determining recycling priority of a plurality of applications running by the electronic equipment, wherein the plurality of applications comprise the at least one third application; determining a reclamation priority for each first system service based on the reclamation priorities of at least one application that depends on each first system service; and closing part or all of the at least one first system service according to the recycling priority of the at least one first system service.
  9. 9. The method of any of claims 1-8, wherein determining the memory reclamation amount for the at least one second application in the background based on the memory reclamation amount comprises: Determining the memory recovery amount of each second application according to the memory recovery amount and the number of the at least one second application, wherein the memory recovery amount of each second application is the same, or Dividing the plurality of second applications into a plurality of groups when the at least one second application is a plurality of second applications, and determining the memory reclamation amount of each group according to the memory reclamation amount, determining the memory reclamation amount of each second application contained in each group according to the memory reclamation amount of each group and the number of the second applications contained in each group, wherein the memory reclamation amounts of different groups are different, the memory reclamation amounts of the plurality of second applications of the same group are the same, or And determining the memory recycling amount of each second application according to the memory recycling amount and the sequence of switching each second application to the background.
  10. 10. The method of any of claims 1-9, wherein the cold data of the first application is memory data that the first application has not accessed within a first period of time, the hot data of the first application is memory data that the first application has accessed within the first period of time, and the first period of time is a period of time between two adjacent memory reclamation by the electronic device.
  11. 11. The method of any of claims 1-10, wherein the target memory data does not include data in direct memory access, DMA, memory access, system library files, and system resource files.
  12. 12. The method of any of claims 1-11, wherein the target memory data includes anonymous pages and file pages therein.
  13. 13. A memory reclamation apparatus comprising means or modules for performing the method as recited in any one of claims 1-12.
  14. 14. An electronic device, the electronic device comprising: A memory for storing computer program instructions; A processor for executing the computer program instructions to support the electronic device to implement the method of any one of claims 1-12.
  15. 15. A computer readable storage medium, characterized in that the storage medium has stored therein a computer program or instructions which, when executed by a communication device, is adapted to carry out the method according to any one of claims 1-12.
  16. 16. A computer program product, characterized in that it when the computer program product is executed by a computer, receives that the computer performs the method according to any of claims 1-12.

Description

Memory recycling method and device Technical Field The present application relates to the field of terminal technologies, and in particular, to a memory recovery method and apparatus. Background Currently, when a user uses an electronic device such as a mobile phone, a tablet, a personal computer, etc., a plurality of applications are usually opened, and the currently used applications are switched back and forth. In order to improve the use experience of the user, after the application is switched to the background, the electronic device does not close the process of the application, so that the application still maintains the original state after being switched to the foreground. However, each time an application is opened, one more memory resource is consumed, and when the memory resource consumed by the opened application is excessive, normal operation of the electronic device is affected. Therefore, when the memory idle amount of the electronic equipment is low, the electronic equipment can process the application in the background to recover part of memory resources, so that the normal operation of the electronic equipment is ensured. However, the existing memory resource recycling scheme cannot reasonably recycle the memory resources occupied by the application in the background state, so that a large amount of memory data needs to be restored after the application is switched to the foreground, a problem of blocking occurs, and the use experience of a user is affected. Disclosure of Invention The application provides a memory recycling method and device, which are used for reasonably recycling memory resources occupied by an application in the background, reducing memory data to be recovered after the application is switched to the foreground, avoiding the problem of blocking and improving the user experience. In a first aspect, an embodiment of the present application provides a memory reclamation method, which may be applied to an electronic device in a memory reclamation system. The method comprises the steps that when a first application is in a foreground, the electronic device determines cold data and hot data in target memory data of the first application, wherein the first application is any application, when the memory idle amount of the electronic device is smaller than a first threshold value, the electronic device determines memory recovery amount of at least one second application in the background according to the memory recovery total amount, the electronic device releases the target memory data of each second application according to the memory recovery amount of the target second application and the data amount of the cold data and the hot data of the target second application, and releases the target memory data of the target second application, wherein the target second application is any one of the at least one second application. By adopting the method, when the application is in the foreground, the electronic equipment can determine the cold data and the hot data of the application, and after the application is switched to the background, the electronic equipment does not determine the cold data and the hot data of the application again, so that the cold data and the hot data of the application are ensured to be in line with the application access condition when the application is in the foreground. Because the existing data release mechanisms are all used for releasing the cold data preferentially, when the electronic equipment releases the target memory data of each second application according to the data volume of the cold data and the data volume of the hot data of each second application, the cold data in the second application can be released preferentially, and the data volume of the hot data in the second application is reduced, so that the data volume of the hot data required to be recovered when the subsequent second application is switched to the foreground is reduced, the problem of blocking is avoided, and the user experience is improved. In one possible design, the electronic device determines the recovery amount of the cold data and the recovery amount of the hot data of the target second application according to the recovery amount of the memory of the target second application and the data amount of the cold data and the data amount of the hot data of the target second application, wherein the sum of the recovery amount of the cold data and the recovery amount of the hot data of the target second application is the same as the recovery amount of the memory of the target second application, the recovery amount of the cold data is more than 0, and the recovery amount of the hot data is more than or equal to 0; The electronic equipment determines cold data to be recovered in the cold data of the target second application according to the recovery amount of the cold data, and releases the cold data to be recovered; when the recovery amount of the thermal data is l