Search

EP-4738118-A1 - MEMORY MANAGEMENT METHOD, MEMORY MANAGEMENT APPARATUS AND ELECTRONIC DEVICE

EP4738118A1EP 4738118 A1EP4738118 A1EP 4738118A1EP-4738118-A1

Abstract

Embodiments of this application provide a memory management method, a memory management apparatus, and an electronic device. The memory management method includes: receiving a first input of a user, where the first input is used to enable a first application to enter a background state; blocking an interface related to access to a buffer in a first buffer set, where the buffer in the first buffer set belongs to a buffer related to decoding of a first video played by the first application; and reclaiming physical memory corresponding to the buffer in the first buffer set. According to the memory management method, the memory management apparatus, and the electronic device provided in embodiments of this application, physical memory corresponding to a buffer related to video decoding can be reclaimed, so that available physical memory of an entire system is increased. This increases a response speed of the electronic device and improves user experience.

Inventors

  • SONG, Yuanzheng
  • WANG, Chengke
  • JI, Kecheng
  • LIN, HAIMING
  • LI, XUHUI

Assignees

  • Huawei Technologies Co., Ltd.

Dates

Publication Date
20260506
Application Date
20240430

Claims (20)

  1. A memory management method, applied to an electronic device, and comprising: receiving a first input of a user, wherein the first input is used to enable a first application to enter a background state; blocking an interface related to access to a buffer in a first buffer set, wherein the buffer in the first buffer set belongs to a buffer related to decoding of a first video played by the first application; and reclaiming physical memory corresponding to the buffer in the first buffer set.
  2. The method according to claim 1, wherein the method further comprises: receiving a second input of the user, wherein the second input is used to switch the first application back to a foreground state; reallocating physical memory to the buffer in the first buffer set; and unblocking the interface related to the access to the buffer in the first buffer set.
  3. The method according to claim 2, wherein the first buffer set comprises at least one of a second buffer, a third buffer, a fourth buffer, and a fifth buffer, wherein the second buffer is an empty input buffer that is in an input buffer queue and that is held by a media module; the third buffer is an output buffer that is being filled with a decoding result and that is held by the media module; the fourth buffer is an output buffer that is filled with a decoding result, that is to be used by the first application, that is in an output buffer queue, and that is held by the media module; the fifth buffer is an output buffer that is filled with a decoding result and that is held by the first application; and the media module is configured to decode the first video.
  4. The method according to claim 2 or 3, wherein blocking the interface related to the access to the buffer in the first buffer set comprises: freezing at least one process or thread of the first application when the at least one process or thread of the first application uses the interface related to the access to the buffer in the first buffer set; and/or unblocking the interface related to the access to the buffer in the first buffer set comprises: unfreezing the at least one process or thread of the first application.
  5. The method according to claim 3, wherein when the first buffer set comprises the third buffer, reclaiming the physical memory corresponding to the buffer in the first buffer set comprises: recording a decoding location corresponding to the decoding result filling the third buffer, and reclaiming physical memory corresponding to the third buffer; and reallocating the physical memory to the buffer in the first buffer set comprises: reallocating physical memory to the third buffer, re-decoding, based on the decoding location, data corresponding to the decoding result, and then filling the reallocated physical memory; or reclaiming the physical memory corresponding to the buffer in the first buffer set comprises: compressing the decoding result filling the third buffer, and reclaiming physical memory corresponding to the third buffer; and reallocating the physical memory to the buffer in the first buffer set comprises: reallocating physical memory to the third buffer, decompressing the compressed decoding result, and then filling the reallocated physical memory; or reclaiming the physical memory corresponding to the buffer in the first buffer set comprises: swapping out, through page swapping, the decoding result filling the third buffer, and reclaiming physical memory corresponding to the third buffer; and reallocating the physical memory to the buffer in the first buffer set comprises: reallocating physical memory to the third buffer, and swapping the swapped-out decoding result in the reallocated physical memory.
  6. The method according to claim 3 or 5, wherein when the first buffer set comprises the fourth buffer, reclaiming the physical memory corresponding to the buffer in the first buffer set comprises: compressing the decoding result filling the fourth buffer, and reclaiming physical memory corresponding to the fourth buffer; and reallocating the physical memory to the buffer in the first buffer set comprises: reallocating physical memory to the fourth buffer, decompressing the compressed decoding result, and then filling the reallocated physical memory; or reclaiming the physical memory corresponding to the buffer in the first buffer set comprises: swapping out the decoding result in the fourth buffer through page swapping, and reclaiming physical memory corresponding to the fourth buffer; and reallocating the physical memory to the buffer in the first buffer set comprises: reallocating physical memory to the fourth buffer, and swapping the swapped-out decoding result in the reallocated physical memory.
  7. The method according to any one of claims 1 to 6, wherein the interface related to the access to the buffer in the first buffer set comprises a first interface and a second interface, the first interface is used by the first application to obtain the second buffer, and the second interface is used by the first application to obtain the fourth buffer.
  8. The method according to claim 7, wherein when the first application uses the media module in a synchronous mode, the first interface is used by the first application to actively obtain the second buffer, and the second interface is used by the first application to actively obtain the fourth buffer; or when the first application uses the media module in an asynchronous mode, the first interface is used by the first application to obtain the second buffer actively released by the media module, and the second interface is used by the first application to obtain the fourth buffer actively released by the media module.
  9. A memory management apparatus, comprising: a first application, configured to receive a first input of a user, wherein the first input is used to enable a first application to enter a background state; and a media module, configured to: block an interface related to access to a buffer in a first buffer set, wherein the buffer in the first buffer set belongs to a buffer related to decoding of a first video played by the first application; and reclaim physical memory corresponding to the buffer in the first buffer set.
  10. The apparatus according to claim 9, wherein the first application is further configured to receive a second input of the user, wherein the second input is used to switch the first application back to a foreground state; and the media module is further configured to: reallocate physical memory to the buffer in the first buffer set; and unblock the interface related to the access to the buffer in the first buffer set.
  11. The apparatus according to claim 10, wherein the first buffer set comprises at least one of a second buffer, a third buffer, a fourth buffer, and a fifth buffer, wherein the second buffer is an empty input buffer that is in an input buffer queue and that is held by the media module; the third buffer is an output buffer that is being filled with a decoding result and that is held by the media module; the fourth buffer is an output buffer that is filled with a decoding result, that is to be used by the first application, that is in an output buffer queue, and that is held by the media module; the fifth buffer is an output buffer that is filled with a decoding result and that is held by the first application; and the media module is configured to decode the first video.
  12. The apparatus according to claim 10 or 11, wherein the media module is specifically configured to: freeze at least one process or thread of the first application when the at least one process or thread of the first application uses the interface related to the access to the buffer in the first buffer set; and/or unfreeze the at least one process or thread of the first application.
  13. The apparatus according to claim 11, wherein when the first buffer set comprises the third buffer, the media module is specifically configured to: record a decoding location corresponding to the decoding result filling the third buffer, and reclaim physical memory corresponding to the third buffer; and reallocate physical memory to the third buffer, re-decode, based on the decoding location, data corresponding to the decoding result, and then fill the reallocated physical memory; or compress the decoding result filling the third buffer, and reclaim physical memory corresponding to the third buffer; and reallocate physical memory to the third buffer, decompress the compressed decoding result, and then fill the reallocated physical memory; or swap out, through page swapping, the decoding result filling the third buffer, and reclaim physical memory corresponding to the third buffer; and reallocate physical memory to the third buffer, and swap the swapped-out decoding result in the reallocated physical memory.
  14. The apparatus according to claim 11 or 13, wherein when the first buffer set comprises the fourth buffer, the media module is specifically configured to: compress the decoding result filling the fourth buffer, and reclaim physical memory corresponding to the fourth buffer; and reallocate physical memory to the fourth buffer, decompress the compressed decoding result, and then fill the reallocated physical memory; or swap out the decoding result in the fourth buffer through page swapping, and reclaim physical memory corresponding to the fourth buffer; and reallocate physical memory to the fourth buffer, and swap the swapped-out decoding result in the reallocated physical memory.
  15. The apparatus according to any one of claims 9 to 14, wherein the interface related to the access to the buffer in the first buffer set comprises a first interface and a second interface, the first interface is used by the first application to obtain the second buffer, and the second interface is used by the first application to obtain the fourth buffer.
  16. The apparatus according to claim 15, wherein when the first application uses the media module in a synchronous mode, the first interface is used by the first application to actively obtain the second buffer, and the second interface is used by the first application to actively obtain the fourth buffer; or when the first application uses the media module in an asynchronous mode, the first interface is used by the first application to obtain the second buffer actively released by the media module, and the second interface is used by the first application to obtain the fourth buffer actively released by the media module.
  17. The apparatus according to claim 11, wherein the apparatus further comprises an activity manager service, configured to: send a first message to the media module based on the first input, wherein the first message indicates that the buffer related to decoding of the first video can be reclaimed; and send a second message to the media module based on the second input, wherein the second message indicates to switch the first application back to the foreground.
  18. An electronic device, comprising one or more processors and one or more storages, wherein the one or more storages store one or more computer programs, the one or more computer programs comprise instructions, and when the instructions are executed by the one or more processors, the memory management method according to any one of claims 1 to 8 is performed.
  19. A chip, comprising a processor and a communication interface, wherein the communication interface is configured to receive a signal and transmit the signal to the processor, and the processor processes the signal, so that the memory management method according to any one of claims 1 to 8 is performed.
  20. A readable storage medium, wherein the readable storage medium stores instructions, and when the instructions are run on a computer, the memory management method according to any one of claims 1 to 8 is performed.

Description

This application claims priority to Chinese Patent Application No. 202311039158.5, filed with the China National Intellectual Property Administration on August 16, 2023 and entitled "MEMORY MANAGEMENT METHOD, MEMORY MANAGEMENT APPARATUS, AND ELECTRONIC DEVICE", which is incorporated herein by reference in its entirety. TECHNICAL FIELD Embodiments of this application relate to the field of electronic technologies, and more specifically, to a memory management method, a memory management apparatus, and an electronic device. BACKGROUND When an application enters the background, an operating system may perform memory reclamation in various manners when memory is insufficient, for example, perform memory reclamation in a manner like page discarding, page swapping, or page write-back, to relieve memory pressure. In a video playing scenario, a large quantity of input or output buffers are used. After a video enters the background, a related buffer is not destructed, and still occupies a large amount of physical memory. As a result, memory of an electronic device becomes smaller as a quantity of video applications started by a user increases. In addition, the video application and a hardware decoder invoked by a media module usually share physical memory, but the operating system does not have a memory reclamation mechanism for the shared memory. SUMMARY Embodiments of this application provide a memory management method, a memory management apparatus, and an electronic device, so that a buffer related to video decoding can be reclaimed when a video is played in the background; and normal video playing is not affected when a video playing application is switched back to the foreground subsequently. This improves user experience. According to a first aspect, a memory management method is provided, applied to an electronic device, and including: receiving a first input of a user, where the first input is used to enable a first application to enter a background state; blocking an interface related to access to a buffer in a first buffer set, where the buffer in the first buffer set belongs to a buffer related to decoding of a first video played by the first application; and reclaiming physical memory corresponding to the buffer in the first buffer set. When the first video is played in the background, playing of the first video is paused. In this embodiment, when the first video is in the background, physical memory corresponding to the buffer related to decoding of the first video may be reclaimed, and an interface related to access to the corresponding buffer may be blocked. In this way, even if a plurality of video applications are run in the background, occupied memory of an entire system is reduced, and a response speed of the electronic device to the user is increased. This improves user experience. With reference to the first aspect, in some implementations of the first aspect, the method further includes: receiving a second input of the user, where the second input is used to switch the first application back to a foreground state; reallocating physical memory to the buffer in the first buffer set; and unblocking the interface related to the access to the buffer in the first buffer set. In this embodiment, after the first application is switched back to the foreground, the first video automatically starts to be played or continues to be played after a user operation. In this case, the physical memory needs to be reallocated to the buffer whose the physical memory is reclaimed, and the related interface needs to be unblocked after the physical memory is reallocated. Therefore, successive playing of the first video is not affected. Optionally, after the first video enters the background, the first application may be cleared due to an Android memory clearance mechanism or manually cleared by the user. In this case, the first application needs to be cold started to be switched back to the foreground. In this case, there is no need to reallocate the physical memory to the buffer whose physical memory is reclaimed. With reference to the first aspect, in some implementations of the first aspect, the first buffer set includes at least one of a second buffer, a third buffer, a fourth buffer, and a fifth buffer, where the second buffer is an empty input buffer that is in an input buffer queue and that is held by a media module; the third buffer is an output buffer that is being filled with a decoding result and that is held by the media module; the fourth buffer is an output buffer that is filled with a decoding result, that is to be used by the first application, that is in an output buffer queue, and that is held by the media module; the fifth buffer is an output buffer that is filled with a decoding result and that is held by the first application; and the media module is configured to decode the first video. In this embodiment, a buffer in a specific state may be reclaimed based on a status of the buffer related to d