Search

CN-122019117-A - Memory management method and electronic equipment

CN122019117ACN 122019117 ACN122019117 ACN 122019117ACN-122019117-A

Abstract

The embodiment of the application provides a memory management method and electronic equipment. In this approach, the electronic device may configure the memory control group for each applet process separately, rather than adding the entire applet process universe to the same memory control group. In this way, isolation between applets is enhanced, and the electronic device can make corresponding memory optimization for one applet with respect to the running state of the applet without considering the running states of other applets. After a applet switches from a foreground run to a background run, the electronic device can perform memory optimization for the applet, including compressing anonymous pages as previously described. In some possible cases, performing memory optimization may also perform a dump in addition to compressing anonymous pages. By implementing the method, the memory can be more effectively managed.

Inventors

  • CHEN LIGENG
  • LIU XING
  • AN NING

Assignees

  • 荣耀终端股份有限公司

Dates

Publication Date
20260512
Application Date
20241112

Claims (16)

  1. 1. A memory management method, applied to an electronic device having a memory, comprising: In response to initiating an operation of the first applet in a first application, creating a process of the first applet and running the first applet in the first application based on the process of the first applet; the process of the first applet is allocated with a first memory page in the memory, the first memory page is used for storing content required for running the applet; The electronic equipment further comprises a second memory control group, wherein the second memory control group is used for managing a second memory page, and the second memory control group is used for managing a second memory page which is a memory page of the memory and is allocated to the process of the second applet; switching the first applet from foreground to background; Compressing contents in an anonymous page in the first memory page to obtain anonymous page compression data; Storing the anonymous page compression data to a compression memory area in the memory, and releasing the anonymous page in the first memory page.
  2. 2. The method according to claim 1, wherein the method further comprises: if the first applet is in the background running state within the first preset time period after the switch to the background, part or all of the anonymous page compressed data is dumped from the compressed memory area to the first disk area outside the memory, and the memory space with the dumped content in the compressed memory area is released.
  3. 3. The method according to claim 2, wherein dumping part or all of the anonymous page compressed data from the compressed memory area into the first disk area outside the memory, in particular comprises: Under the condition that the available space of the memory is smaller than or equal to a first space threshold value, dumping all the anonymous page compression data from the compression memory area to the first disk area; and under the condition that the available space of the memory is determined to be larger than a first space threshold, dumping the part of the anonymous page compressed data from the compressed memory area to the first disk area.
  4. 4. The method of claim 2, wherein a portion or all of the anonymous page compressed data is dumped from the compressed memory area into a first disk area outside of memory, and wherein prior to releasing the compressed memory area, the method further comprises: determining that the available space of the memory is smaller than a first space threshold; Dumping part or all of the anonymous page compressed data from the compressed memory area to a first disk area outside the memory, wherein the method specifically comprises the following steps: subtracting the available space of the memory from a first space threshold to obtain a first difference; When the first difference value is larger than or equal to the memory space occupied by the compressed memory area, dumping all the anonymous page compressed data from the compressed memory area to the first disk area; And under the condition that the first difference value is smaller than the memory space occupied by the compressed memory area, dumping a first part of the anonymous page compressed data from the compressed memory area to the first disk area, wherein the size of the memory space occupied by the first part in the compressed memory area is equal to or larger than the first difference value.
  5. 5. The method of claim 3 or 4, wherein the first spatial threshold is greater than or equal to a memory spatial threshold that triggers display of a first prompt, the first prompt being for prompting a user that there is insufficient memory.
  6. 6. The method of any of claims 1-5, wherein the compressed memory region and the first memory page are released if the first applet is closed within a first predetermined time period after switching to background.
  7. 7. The method of any of claims 2-5, wherein after the portion of anonymous page compressed data is dumped from the compressed memory area into the first volume outside of memory, the method further comprises: under the condition of closing the first applet, releasing the memory space and the first memory page, the contents of which are not dumped, in the compressed memory area; In the event that all of the anonymous page compressed data is dumped from the compressed memory area into the first disk area, the method further comprises: and under the condition of closing the first applet, releasing the first memory page.
  8. 8. The method of claim 7, wherein in the case of releasing the first memory page, the method further comprises: And releasing the first disk area.
  9. 9. The method according to claim 1, wherein the method further comprises: Switching the first applet from background to foreground; Decompressing the anonymous page compression data in the compressed memory area to restore the anonymous page in the first memory page; and running the first applet on the basis of the first memory page.
  10. 10. The method according to any one of claims 2-5, further comprising: Switching the first applet from background to foreground; Converting the anonymous page compression data in the first disk area back to a compression memory area; Decompressing the anonymous page compression data in the compressed memory area to restore the anonymous page in the first memory page; and running the first applet on the basis of the first memory page.
  11. 11. The method of any of claims 1-8, wherein the second applet is in a foreground run state after the switch to background.
  12. 12. The method according to any one of claims 2-8, 10, wherein compressing the content on the anonymous page in the first memory page results in anonymous page compression data, comprising: and starting counting after switching to the background, and compressing contents in the anonymous pages in the first memory page under the condition that a second preset time length is confirmed to be reached, so as to obtain anonymous page compression data, wherein the second preset time length is smaller than the first preset time length.
  13. 13. An electronic device comprising one or more processors and memory coupled to the one or more processors, the memory to store computer program code comprising computer instructions that the one or more processors invoke to cause the electronic device to perform the method of any of claims 1-12.
  14. 14. A computer readable storage medium comprising computer instructions which, when run on an electronic device, cause the electronic device to perform the method of any of claims 1-12.
  15. 15. A chip system for application to an electronic device, wherein the chip system comprises one or more processors for invoking computer instructions to cause the electronic device to perform the method of any of claims 1-12.
  16. 16. A computer program product comprising instructions which, when run on an electronic device, cause the electronic device to perform the method of any of claims 1-12.

Description

Memory management method and electronic equipment Technical Field The present application relates to the field of terminal and memory management, and in particular, to a memory management method and an electronic device. Background When the electronic device needs to run a task, the memory is used to store the content (including instructions and data) needed to run the task. The memory allows the processor to quickly access the content stored therein so that the task can be efficiently run. The memory can store the content of a plurality of tasks simultaneously, so that the electronic device can support the parallel operation of the plurality of tasks (including the foreground operation and the background operation). The memory space is limited, and when the tasks running in parallel are too many, the content stored in the memory is correspondingly increased. If the tasks running in the background occupy a large amount of memory space to saturate the memory, when the tasks running in the foreground of the electronic device, the tasks running in the foreground cannot normally run. For example, for user interaction, memory saturation may cause foreground running tasks to fail to respond to user operation in time due to waiting for memory resources, causing a jam. Not only the tasks of the application, the operating system itself also needs to occupy a portion of memory. In the case of memory saturation, the performance of these system-level UI components (e.g., window systems, status bars, etc.) may also be impacted, resulting in a reduced system experience for the electronic device. It can be seen that how to manage the memory space in the multitasking scenario is a problem worthy of discussion. Disclosure of Invention The application provides a memory management method and electronic equipment, which are used for rationalizing memory management in a multi-task scene. In a first aspect, the application provides a memory management method applied to an electronic device with memory, which is used for responding to the operation of starting a first applet in a first application, creating a process of the first applet, running the first applet in the first application based on the process of the first applet, distributing a first memory page in the memory to the process of the first applet, wherein the first memory page is used for storing contents required for running the applet, adding the process of the first applet into a first memory control group, wherein the first memory control group is used for managing the first memory page, and a second memory control group, wherein the process of the started second applet is added in the second memory control group, is used for managing a second memory page, the second memory page is a memory page distributed to the process of the second applet in the memory, switching the first applet from a foreground to a background, compressing the contents in the first memory page, obtaining the anonymous memory data, and compressing the contents in the first memory page, and releasing the anonymous memory data from the compressed memory page to a first memory area. In the above embodiment, the compressed memory area may be understood as the zRAM area referred to in the following embodiment. Instead of adding the process universals of all applets to the same memory control group, the electronic device may configure the memory control group for each applet process separately. In this way, isolation between applets is enhanced, and the electronic device can make a corresponding memory optimization for one applet (e.g., a first applet) for the running state of the first applet, without regard to the running states of other applets. After the first applet is switched from the foreground operation to the background operation, the electronic device may perform a memory optimization for the first applet, the memory optimization including at least compressing and releasing anonymous pages of the first applet. The memory space corresponding to the anonymous page of the first applet that is released may be used by other tasks. In combination with the first aspect, in some embodiments, the method further includes, if the first applet is in a background running state within a first preset time period after switching to the background, dumping part or all of the anonymous page compressed data from the compressed memory area to a first disk area outside the memory, and releasing the memory space in the compressed memory area where the content is dumped. The first volume in the above embodiment may be understood as the eSWAP area referred to in the embodiment that shows that there is a time interval (the first preset duration) between dumping and compressing anonymous pages, instead of dumping directly after compressing anonymous pages or letting both go directly simultaneously. This is because, after the dump, if the first applet switches from the background to the foreground, the anonymous