Memory management method, electronic device, and computer-readable storage medium
By saving the GPU physical memory content to disk and releasing the memory while the application is in the background, the problem of excessive GPU memory usage in electronic devices is solved, improving device response speed and user experience.
Patent Information
- Application Number
- PCT/CN2025/080070
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-06-19
- Filing Date
- 2025-02-28
- Publication Date
- 2025-12-26
AI Technical Summary
Excessive GPU physical memory usage in electronic devices reduces the remaining available physical memory, affecting user response speed and experience.
When an application switches to the background, the contents of the GPU physical memory it occupies are saved to disk, the memory is released, and memory is reallocated to support foreground operations.
It reduces GPU physical memory usage, increases the available physical memory of electronic devices, improves user operation response speed and system smoothness, and enhances user experience.
Smart Images

Figure CN2025080070_26122025_PF_FP_ABST
Abstract
Description
Memory management methods, electronic devices and computer-readable storage media
[0001] This application claims priority to Chinese Patent Application No. 202410799228.5, filed on June 19, 2024, entitled "Memory Management Method, Electronic Device and Computer-Readable Storage Medium", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application belongs to the field of terminal technology, and in particular relates to memory management methods, electronic devices and computer-readable storage media. Background Technology
[0003] Electronic devices such as mobile phones and tablets generally include a graphics processing unit (GPU). The GPU is used for graphics rendering, such as rendering images required by applications. When an application performs graphics rendering using the GPU, the relevant rendering data can be stored in the GPU's corresponding physical memory (i.e., GPU physical memory or GPU memory). When an application goes into the background, the GPU physical memory it occupies is not released. As the number of applications performing graphics rendering on an electronic device increases, the GPU physical memory usage increases, resulting in less and less available physical memory on the electronic device. This causes the electronic device to become increasingly responsive to user actions, negatively impacting the user experience. Summary of the Invention
[0004] This application provides a memory management method, an electronic device, and a computer-readable storage medium, which can reduce the occupation of GPU physical memory, increase the remaining available physical memory of the electronic device, improve the response speed of the electronic device to user operations, improve system smoothness, and enhance user experience.
[0005] In a first aspect, embodiments of this application provide a memory management method, which may include:
[0006] When the first application is detected to switch to the background state, the first content stored in the first GPU physical memory corresponding to the first application is saved to the disk;
[0007] Release the first GPU physical memory.
[0008] In the memory management method provided above, when the first application is detected to switch to the background state, the electronic device can determine that the first application does not need to display images or perform graphics rendering. Therefore, it can be determined that the first application does not need to use GPU physical memory at present. At this time, the electronic device can save the first content stored in the first GPU physical memory corresponding to the first application to the disk and release the first GPU physical memory to reduce the occupation of GPU physical memory. This can increase the remaining available physical memory of the electronic device, improve the response speed of the electronic device to user operations, improve the smoothness of the system, and enhance the user experience.
[0009] In some embodiments, saving the first content stored in the first GPU physical memory corresponding to the first application to the disk may include:
[0010] Obtain the virtual address space corresponding to the first application;
[0011] Based on the virtual address space, determine the first GPU physical memory corresponding to the first application;
[0012] Obtain the first content stored in the first GPU physical memory and save the first content to the disk.
[0013] It should be understood that for an application running on an electronic device, the operating system can allocate a corresponding virtual address space for that application. When the application requires graphics rendering, the GPU in the electronic device can obtain and store the virtual address space corresponding to that application. In other words, for applications requiring graphics rendering, the GPU can store the mapping between the application and its corresponding virtual address space while the application is running.
[0014] In the memory management method provided in this embodiment, when it is determined that the first application is switched to the background state, the GPU in the electronic device can determine the virtual address space corresponding to the first application according to the correspondence, and can determine the first GPU physical memory corresponding to the first application according to the virtual address space corresponding to the first application, thereby obtaining the first content stored in the first GPU physical memory, and saving the first content to the disk, thereby releasing the first GPU physical memory.
[0015] In one example, the virtual address space includes at least one virtual address, each of which corresponds to a virtual page.
[0016] Determining the first GPU physical memory corresponding to the first application based on the virtual address space may include:
[0017] Based on the virtual page corresponding to the virtual address and the first GPU page table, the first physical page corresponding to the first application is determined. The first GPU page table stores the mapping relationship between the virtual page and the first physical page. The first GPU physical memory includes at least one of the first physical pages.
[0018] It should be noted that a virtual address space can include at least one virtual address. Generally, a virtual address space can include multiple virtual addresses. A virtual address can include a virtual page number and a virtual page offset. That is, the virtual address space can be divided into multiple fixed-size virtual pages. Each virtual page can have a corresponding virtual address. In other words, each virtual address can point to a corresponding virtual page.
[0019] Similarly, a physical address space (such as GPU physical memory) can include at least one physical address. Generally, GPU physical memory can include multiple physical addresses. A physical address can include a physical page number and a physical page offset. That is, GPU physical memory can be divided into multiple fixed-size GPU physical pages (or physical pages). Each physical page can have a corresponding physical address. In other words, each physical address can point to a corresponding physical page.
[0020] The size of a physical page is generally the same as the size of a virtual page.
[0021] For a running application that requires graphics rendering, the GPU can maintain a GPU page table corresponding to that application. This GPU page table can include the mapping relationship between the virtual pages and physical pages corresponding to the application. In other words, for the first running application, the first GPU physical memory corresponding to the first application can be divided into multiple fixed-size physical pages (i.e., the first physical page). The GPU can store a first GPU page table corresponding to the first application, which can include the mapping relationship between the virtual pages and the first physical pages corresponding to the first application.
[0022] In the memory management method provided in this example, after determining the virtual address space corresponding to the first application, that is, after determining each virtual address corresponding to the first application, the GPU in the electronic device can determine the physical page (i.e. the first physical page) corresponding to each virtual address based on each virtual address and the first GPU page table corresponding to the first application, that is, determine the first GPU physical memory corresponding to the first application.
[0023] For example, obtaining the first content stored in the first GPU physical memory and saving the first content to the disk may include:
[0024] Obtain the first content stored in each of the first physical pages, and save the first content stored in each of the first physical pages to the disk.
[0025] It should be understood that the content stored in the first GPU physical memory can refer to the content stored in each of the first physical pages included in the first GPU physical memory. Therefore, when it is determined that the first application has switched to the background state, the GPU in the electronic device can obtain the first content stored in each of the first physical pages and save the first content stored in each of the first physical pages to the disk, thereby releasing the first GPU physical memory (i.e., each of the first physical pages).
[0026] In some embodiments, the method may further include:
[0027] Based on the first GPU page table and the first physical page corresponding to each of the first contents, record the correspondence between the first contents and the virtual pages.
[0028] In the memory management method provided in this embodiment, when saving the first content stored in each first physical page to the disk, the GPU in the electronic device can record the correspondence between each first content and the virtual page according to the mapping relationship between each first physical page and the virtual page (i.e., the first GPU page table corresponding to the first application). After rebuilding the second GPU physical memory corresponding to the first application, the GPU in the electronic device can obtain each first content from the disk and fill each first content into the second physical page in the second GPU physical memory. Subsequently, the GPU in the electronic device can establish the mapping relationship between the virtual page and the second physical page according to the first content filled in each second physical page and the correspondence between the first content and the virtual page, so as to rebuild the GPU page table corresponding to the first application. This allows the first application to be mapped to the correct physical page according to the rebuilt GPU page table when the first application switches to the foreground state without modifying the virtual address of the first application, so that the first application can access the GPU physical memory normally and thus the first application can be used normally, and the first application can display the image correctly.
[0029] In other embodiments, the method may further include:
[0030] Release the first GPU page table.
[0031] In the memory management method provided in this embodiment, when it is determined that the first application is switched to the background state, the first GPU page table corresponding to the first application can also be released when the first GPU physical memory corresponding to the first application is released, which can avoid incorrect mapping between the virtual page and the physical page corresponding to the first application.
[0032] In one possible implementation, the first GPU physical memory may include all the GPU physical memory occupied by the first application, or it may include a portion of the GPU physical memory occupied by the first application.
[0033] It should be understood that the portion of GPU physical memory occupied by the first application can be a relatively large amount of texture memory, etc.
[0034] In some embodiments, the method may further include:
[0035] When the first application is detected to switch to the foreground state, the second GPU physical memory is reallocated to the first application.
[0036] In the memory management method provided in this embodiment, when the electronic device detects that the first application has switched to the foreground state, the GPU in the electronic device can reallocate the second GPU physical memory for the first application, so that the first application can access the GPU physical memory normally and thus be used normally.
[0037] In one example, the reallocation of second GPU physical memory for the first application may include:
[0038] Determine the size of the second GPU physical memory;
[0039] Based on the size of the second GPU physical memory, reallocate the second GPU physical memory for the first application.
[0040] In the memory management method provided in this example, when reallocating the second GPU physical memory for the first application, the size of the second GPU physical memory can be determined first, and the second GPU physical memory can be accurately allocated for the first application based on the size of the second GPU physical memory.
[0041] In one possible implementation, determining the size of the second GPU physical memory may include:
[0042] Determine the memory size occupied by the first content, and determine the size of the second GPU physical memory based on the memory size occupied by the first content.
[0043] In the memory management method provided by this implementation, when saving the first content stored in the first GPU physical memory to the disk, the GPU in the electronic device can record the memory size occupied by the first content. Therefore, when reallocating the second GPU physical memory for the first application, the GPU in the electronic device can quickly and accurately determine the size of the second GPU physical memory based on the memory size occupied by the first content.
[0044] Alternatively, when reallocating the second GPU physical memory for the first application, the GPU can read the first content corresponding to the first application stored on the disk and determine the memory size occupied by the first content, so as to determine the size of the second GPU physical memory based on the memory size occupied by the first content.
[0045] In another possible implementation, determining the size of the second GPU physical memory may include:
[0046] Determine the size of the first GPU physical memory, and based on the size of the first GPU physical memory, determine the size of the second GPU physical memory.
[0047] In the memory management method provided by this implementation, when releasing the first GPU physical memory, the GPU in the electronic device can record the size of the first GPU physical memory and accurately determine the size of the second GPU physical memory based on the size of the first GPU physical memory.
[0048] In some embodiments, after reallocating the second GPU physical memory to the first application, the method may further include:
[0049] The first content is retrieved from the disk and then populated into the second GPU physical memory.
[0050] In the memory management method provided in this embodiment, after reallocating the second GPU physical memory to the first application, the GPU in the electronic device can retrieve the previously saved first content from the disk and fill the second GPU physical memory with the first content, so that the first application can correctly access the GPU physical memory and thus the first application can be used normally.
[0051] In one example, the second GPU physical memory includes at least one second physical page.
[0052] The step of retrieving the first content from the disk and filling the first content into the second GPU physical memory may include:
[0053] The first content is retrieved from the disk and populated into the second physical page included in the second GPU physical memory.
[0054] In another example, the method may also include:
[0055] Determine the virtual page corresponding to the first content;
[0056] A second GPU page table is constructed based on the virtual page corresponding to the first content and the second physical page corresponding to the first content. The second GPU page table stores the mapping relationship between the second physical page and the virtual page. The second physical page corresponding to the first content is the second physical page that fills the first content.
[0057] For example, determining the virtual page corresponding to the first content may include:
[0058] Based on the correspondence between the first content and the virtual page, determine the virtual page corresponding to the first content.
[0059] In the memory management method provided in this example, when saving the first content stored in each first physical page to disk, the GPU in the electronic device can record the correspondence between each first content and the virtual page according to the mapping relationship between each first physical page and the virtual page (i.e., the first GPU page table corresponding to the first application). Therefore, after rebuilding the second GPU physical memory corresponding to the first application, the GPU can obtain each first content from the disk and fill each first content into the second physical page in the second GPU physical memory. Subsequently, the GPU can establish the mapping relationship between the virtual page and the second physical page according to the first content filled in each second physical page and the correspondence between the first content and the virtual page, so as to rebuild the second GPU page table corresponding to the first application. This allows the first application to be mapped to the correct physical page according to the rebuilt second GPU page table without modifying the virtual address of the first application when it switches to the foreground state. This enables the first application to access the GPU physical memory normally, thus allowing the first application to be used normally and to display images correctly.
[0060] In one possible implementation, the mapping relationship between the virtual pages and physical pages corresponding to the first application can be a sequential mapping, that is, the first virtual page can be mapped to the first physical page, the second virtual page can be mapped to the second physical page, and the third virtual page can be mapped to the third physical page, and so on. When saving the first content stored in each first physical page to disk, the GPU can record the storage location of each first content in the first GPU physical memory, that is, it can record which physical page each first content belongs to in the first GPU physical memory. Therefore, after reconstructing the second GPU physical memory corresponding to the first application, the GPU can fill each first content into the corresponding second physical page in the second GPU physical memory according to the storage location of each first content in the first GPU physical memory. Subsequently, the GPU can establish the mapping relationship between the virtual pages and the second physical pages according to the sequential mapping, so as to rebuild the second GPU page table corresponding to the first application. This allows the first application to access the GPU physical memory normally and thus be used normally, enabling the first application to display images correctly, without modifying the virtual address of the first application.
[0061] Secondly, embodiments of this application provide a memory management device, which may include:
[0062] The content saving module is used to save the first content stored in the first GPU physical memory corresponding to the first application to the disk when the first application is detected to switch to the background state;
[0063] The memory release module is used to release the first GPU physical memory.
[0064] In some embodiments, the content storage module is specifically used to obtain the virtual address space corresponding to the first application; determine the first GPU physical memory corresponding to the first application based on the virtual address space; obtain the first content stored in the first GPU physical memory; and save the first content to the disk.
[0065] In one example, the virtual address space includes at least one virtual address, each of which corresponds to a virtual page.
[0066] The content storage module is further configured to determine the first physical page corresponding to the first application based on the virtual page corresponding to the virtual address and the first GPU page table. The first GPU page table stores the mapping relationship between the virtual page and the first physical page, and the first GPU physical memory includes at least one of the first physical pages.
[0067] For example, the content saving module is further configured to obtain the first content stored in each of the first physical pages and save the first content stored in each of the first physical pages to the disk.
[0068] In some embodiments, the apparatus may further include:
[0069] The relationship recording module is used to record the correspondence between the first content and the virtual page based on the first GPU page table and the first physical page corresponding to each of the first contents.
[0070] In other embodiments, the apparatus may further include:
[0071] The page table release module is used to release the first GPU page table.
[0072] In one possible implementation, the first GPU physical memory may include all the GPU physical memory occupied by the first application, or it may include a portion of the GPU physical memory occupied by the first application.
[0073] In some embodiments, the apparatus may further include:
[0074] The memory allocation module is used to reallocate the second GPU physical memory for the first application when the first application is detected to switch to the foreground state.
[0075] In one example, the memory allocation module is specifically used to determine the size of the second GPU physical memory; and to reallocate the second GPU physical memory for the first application based on the size of the second GPU physical memory.
[0076] In one possible implementation, the memory allocation module is further configured to determine the memory size occupied by the first content, and determine the size of the second GPU physical memory based on the memory size occupied by the first content.
[0077] In another possible implementation, the memory allocation module is further configured to determine the size of the first GPU physical memory and, based on the size of the first GPU physical memory, determine the size of the second GPU physical memory.
[0078] In some embodiments, the apparatus may further include:
[0079] The content filling module is used to retrieve the first content from the disk and fill the first content into the second GPU physical memory.
[0080] In one example, the second GPU physical memory includes at least one second physical page.
[0081] The content filling module is specifically used to obtain the first content from the disk and fill the first content into the second physical page included in the second GPU physical memory.
[0082] In another example, the device may further include:
[0083] The virtual page determination module is used to determine the virtual page corresponding to the first content;
[0084] The page table construction module is used to construct a second GPU page table based on the virtual page corresponding to the first content and the second physical page corresponding to the first content. The second GPU page table stores the mapping relationship between the second physical page and the virtual page, and the second physical page corresponding to the first content is the second physical page that fills the first content.
[0085] For example, the virtual page determination module is specifically used to determine the virtual page corresponding to the first content based on the correspondence between the first content and the virtual page.
[0086] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the electronic device implements the memory management method described in any one of the first aspects above.
[0087] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a computer, causes the computer to implement the memory management method described in any one of the first aspects above.
[0088] Fifthly, embodiments of this application provide a computer program product that, when run on an electronic device, causes the electronic device to execute the memory management method described in any one of the first aspects.
[0089] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0090] Figure 1 is a schematic diagram of GPU graphics rendering;
[0091] Figure 2 is a schematic diagram of the structure of the electronic device to which the memory management method provided in the embodiments of this application is applicable;
[0092] Figure 3 is a schematic diagram of the software architecture to which the memory management method provided in the embodiments of this application is applicable;
[0093] Figure 4 is a flowchart illustrating the memory management method provided in an embodiment of this application;
[0094] Figure 5 is a schematic diagram of releasing a portion of the GPU physical memory provided in an embodiment of this application;
[0095] Figure 6 is a schematic diagram of releasing GPU physical memory and rebuilding GPU physical memory provided in an embodiment of this application;
[0096] Figure 7 is a flowchart illustrating a method for releasing GPU physical memory according to an embodiment of this application;
[0097] Figure 8 is a schematic diagram of the process of rebuilding GPU physical memory provided in an embodiment of this application. Detailed Implementation
[0098] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0099] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0100] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0101] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0102] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0103] Furthermore, the term "multiple" mentioned in the embodiments of this application should be interpreted as two or more.
[0104] The steps involved in the memory management method provided in this application are merely examples. Not all steps are mandatory, nor are all information or message contents required. They can be added or removed as needed during use. The same step or step or message with the same function in this application can be referenced and learned from each other in different embodiments.
[0105] The business scenarios described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided in the embodiments of this application. As those skilled in the art will know, with the evolution of network architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0106] Electronic devices such as mobile phones and tablets typically include a GPU. The GPU can be used for graphics rendering, such as rendering images required by an application. When an application performs graphics rendering using the GPU, the relevant rendering data can be stored in the GPU's physical memory.
[0107] For example, please refer to Figure 1, which shows a schematic diagram of a GPU performing graphics rendering.
[0108] As shown in Figure 1, when an application (e.g., application A) installed on an electronic device needs to display an image, application A can send the data to be rendered corresponding to the image to the GPU. For example, it can send images, fonts, or coordinate points to the GPU. The GPU can request a portion of the physical memory of the electronic device as the GPU physical memory corresponding to application A, and after obtaining the data to be rendered corresponding to the image, it can save the data to be rendered corresponding to the GPU physical memory corresponding to application A.
[0109] When the GPU renders the image, it can retrieve the image's rendering data from the GPU's physical memory corresponding to application A. The GPU can then decode and compute this rendering data, saving the resulting texture data and other information to the GPU's physical memory. Finally, the electronic device can send the processed texture data to the display module (e.g., a screen) for image display, thus enabling application A to display the image.
[0110] When application A goes into the background, the GPU physical memory occupied by application A is not released. As the number of applications performing graphics rendering increases, the GPU physical memory usage of the electronic device increases, resulting in less and less available physical memory on the electronic device. This causes the electronic device to become slower and slower to respond to user operations, affecting the user experience.
[0111] To address the aforementioned problems, embodiments of this application provide a memory management method, an electronic device, and a computer-readable storage medium. In this method, when a first application is detected to have switched to a background state, the electronic device can determine that the first application does not need to display images or perform graphics rendering, meaning it does not currently need to use GPU physical memory. At this time, the electronic device can determine the first GPU physical memory corresponding to the first application and obtain the first content stored in the first GPU physical memory. Subsequently, the electronic device can save the first content to a disk and release the first GPU physical memory, thereby reducing GPU physical memory usage, increasing the remaining available physical memory of the electronic device, improving the electronic device's response speed to user operations, enhancing system smoothness, and improving the user experience.
[0112] In this embodiment, the electronic device can be a mobile phone, tablet computer, wearable device, vehicle device, laptop computer, desktop computer, or other electronic device that may include a GPU. This embodiment does not impose any restrictions on the specific type of electronic device.
[0113] The following first describes the electronic device involved in the embodiments of this application. Please refer to Figure 2, which shows a schematic diagram of the structure of the electronic device 200.
[0114] Electronic device 200 may include processor 210, external memory interface 220, internal memory 221, universal serial bus (USB) interface 230, charging management module 240, power management module 241, battery 242, antenna 1, antenna 2, mobile communication module 250, wireless communication module 260, audio module 270, speaker 270A, receiver 270B, microphone 270C, headphone jack 270D, sensor module 280, button 290, motor 291, indicator 292, camera 293, display screen 294, and subscriber identification module (SIM) card interface 295, etc. The sensor module 280 may include a pressure sensor 280A, a gyroscope sensor 280B, a barometric pressure sensor 280C, an accelerometer sensor 280D, a distance sensor 280E, a proximity light sensor 280F, a fingerprint sensor 280G, a temperature sensor 280H, a touch sensor 280J, an ambient light sensor 280K, etc.
[0115] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 200. In other embodiments of this application, the electronic device 200 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0116] Processor 210 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), baseband processors, and / or neural network processing units (NPUs). These different processing units may be independent devices or integrated into one or more processors.
[0117] The controller can generate operation control signals based on the instruction opcode and timing signals to complete the control of instruction fetching and execution.
[0118] The processor 210 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. This memory can store instructions or data that the processor 210 has just used or that are used repeatedly. If the processor 210 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.
[0119] In some embodiments, the processor 210 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0120] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the electronic device 200. In other embodiments of this application, the electronic device 200 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0121] The charging management module 240 is used to receive charging input from the charger.
[0122] The power management module 241 is used to connect the battery 242, the charging management module 240, and the processor 210. The power management module 241 receives input from the battery 242 and / or the charging management module 240 to power the processor 210, internal memory 221, display 294, camera 293, and wireless communication module 260, etc.
[0123] The wireless communication function of electronic device 200 can be implemented through antenna 1, antenna 2, mobile communication module 250, wireless communication module 260, modem processor, and baseband processor.
[0124] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 200 can be used to cover one or more communication frequency bands.
[0125] The mobile communication module 250 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 200. The mobile communication module 250 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 250 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 250 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1. In some embodiments, at least some functional modules of the mobile communication module 250 may be housed in the processor 210. In some embodiments, at least some functional modules of the mobile communication module 250 and at least some modules of the processor 210 may be housed in the same device.
[0126] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through an audio device (not limited to speaker 270A, receiver 270B, etc.) or displays images or videos through the display screen 294. In some embodiments, the modem processor may be a separate device. In other embodiments, the modem processor may be independent of the processor 210 and may be housed in the same device as the mobile communication module 250 or other functional modules.
[0127] The wireless communication module 260 can provide solutions for wireless communication applications on the electronic device 200, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 260 can be one or more devices integrating at least one communication processing module. The wireless communication module 260 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 210. The wireless communication module 260 can also receive signals to be transmitted from processor 210, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.
[0128] In some embodiments, antenna 1 of electronic device 200 is coupled to mobile communication module 250, and antenna 2 is coupled to wireless communication module 260, enabling electronic device 200 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time-Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).
[0129] Electronic device 200 implements display functions through a GPU, a display screen 294, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 294 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 210 may include one or more GPUs, which execute program instructions to generate or modify display information.
[0130] Display screen 294 is used to display images, videos, etc. Display screen 294 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, electronic device 200 may include one or N displays 294, where N is a positive integer greater than 1.
[0131] Electronic device 200 can perform shooting functions through ISP, camera 293, video codec, GPU, display screen 294 and application processor.
[0132] The ISP is used to process data fed back by the camera 293. The camera 293 is used to capture still images or videos. In some embodiments, the electronic device 200 may include one or N cameras 293, where N is a positive integer greater than 1.
[0133] A digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals.
[0134] Video codecs are used to compress or decompress digital video. Electronic device 200 may support one or more video codecs. Thus, electronic device 200 can play or record video in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0135] An NPU (Neural Processing Unit) is a neural network (NN) computing processor that, by borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, rapidly processes input information and can continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.
[0136] The external storage interface 220 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 200. The external memory card communicates with the processor 210 through the external storage interface 220 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.
[0137] Internal memory 221 can be used to store computer executable program code, which includes instructions. Internal memory 221 may include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback, image playback, etc.), etc. The data storage area may store data created during the use of electronic device 200 (such as audio data, phonebook, etc.). Furthermore, internal memory 221 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, universal flash storage (UFS), etc. Processor 210 executes various functional applications and data processing of electronic device 200 by running instructions stored in internal memory 221 and / or instructions stored in memory disposed in the processor.
[0138] Electronic device 200 can implement audio functions such as music playback and recording through audio module 270, speaker 270A, receiver 270B, microphone 270C, headphone jack 270D, and application processor.
[0139] Audio module 270 is used to convert digital audio information into analog audio signal output, and also to convert analog audio input into digital audio signal. Audio module 270 can also be used for encoding and decoding audio signals.
[0140] Buttons 290 include a power button, volume buttons, etc. Buttons 290 can be mechanical buttons or touch-sensitive buttons. Electronic device 200 can receive button input and generate key signal inputs related to user settings and function control of electronic device 200.
[0141] Motor 291 can generate vibration alerts. Motor 291 can be used for incoming call vibration alerts or for touch vibration feedback.
[0142] Indicator 292 can be an indicator light, which can be used to indicate charging status, power changes, messages, missed calls, notifications, etc.
[0143] The SIM card interface 295 is used to connect a SIM card.
[0144] The software system of electronic device 200 can adopt a layered architecture, event-driven architecture, microkernel architecture, microservice architecture, or cloud architecture. For example, the software system of electronic device 200 can adopt a layered architecture such as Android operating system (OS), Harmony OS, or iOS. In some implementations, the operating system of electronic device 200 can adopt a layered architecture.
[0145] Figure 3 is a software structure block diagram of an electronic device 200 according to an embodiment of this application.
[0146] A layered architecture divides software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the operating system is divided into four layers, from top to bottom: the application layer, the application framework layer, the runtime and system libraries, and the kernel layer.
[0147] The application layer can include a series of application packages.
[0148] As shown in Figure 3, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, and SMS.
[0149] The application framework layer provides application programming interfaces (APIs) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions.
[0150] As shown in Figure 3, the application framework layer may include an activity manager service (AMS), a window manager, a content provider, a view system, a phone manager, a resource manager, and a notification manager, etc.
[0151] Activity management services are used to manage activities, such as managing their lifecycle. An activity is a component that can contain a user interface and is primarily used to interact with the user, such as making a phone call, sending an email, and viewing a map. Most of the content that users see in an application is provided by activity components, and an application can include multiple activities.
[0152] The window manager is used to manage windowed applications. It can retrieve screen size, determine the presence of a status bar, lock the screen, and capture screenshots, among other things.
[0153] Content providers store and retrieve data, making that data accessible to applications. This data may include videos, images, audio, made and received phone calls, browsing history and bookmarks, phone books, etc.
[0154] A view system includes visual controls, such as controls for displaying text and controls for displaying images. View systems can be used to build applications. A display interface can consist of one or more views. For example, a display interface including a text notification icon could include views for displaying text and views for displaying images.
[0155] The phone manager is used to provide communication functions for electronic devices 200. For example, it manages call status (including connection and disconnection).
[0156] The file explorer provides applications with various resources, such as localized strings, icons, images, layout files, video files, and more.
[0157] The notification manager allows applications to display notifications in the status bar. These notifications can be used to deliver informational messages and can disappear automatically after a short pause, requiring no user interaction. For example, the notification manager can be used to notify users of completed downloads or message alerts. The notification manager can also display notifications as icons or scrolling text in the top status bar, such as notifications from background applications, or as dialog boxes on the screen. Examples include displaying text messages in the status bar, emitting sounds, vibrating electronic devices, and flashing indicator lights.
[0158] The runtime includes the core libraries and the virtual machine. The runtime is responsible for the scheduling and management of the operating system.
[0159] The core library consists of two parts: one part is the functionalities that the Java language needs to call, and the other part is the core library of the operating system.
[0160] The application layer and application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and application framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.
[0161] System libraries can include multiple functional modules. For example: surface manager, media libraries, 3D graphics processing libraries (e.g., OpenGLES), 2D graphics engines (e.g., SGL), etc.
[0162] The Surface Manager is used to manage the display subsystem and provides the blending of 2D and 3D layers for multiple applications.
[0163] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.
[0164] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0165] A 2D graphics engine is a graphics engine for 2D drawing.
[0166] The kernel layer is the layer between hardware and software. The kernel layer contains at least the display driver, camera driver, audio driver, and sensor driver.
[0167] For ease of understanding, the key technical terms that may be involved in the embodiments of this application will be introduced below.
[0168] Foreground: This refers to the state in which an application is being opened, operated, or currently displayed by the user. Applications in the foreground can perform actions that are noticeable to the user.
[0169] Background: This refers to an application that is still running but no longer displayed on the screen, and the user is no longer directly interacting with or paying attention to its state. Users generally won't directly notice the operations performed by an application in the background.
[0170] A process is the execution of an application. A process can be viewed as an independent program. It is the basic unit of resource allocation and scheduling. For example, when a user runs an application, the system creates a process and allocates resources to it (such as CPU and / or GPU resources). Then, the process is placed in the ready queue. When the process is selected by the scheduler, the system allocates CPU and / or GPU resources to it, and only then does the process actually run.
[0171] Virtual memory (VA): also known as logical memory. Virtual memory is a memory management technique that allows the system to provide each process with a larger address space than the actual physical memory. This address space is called the virtual address space, while the actual physical memory is called the physical address space. The virtual address space can include one or more virtual addresses, and the physical address space can include one or more physical addresses.
[0172] Physical memory (PA) refers to random access memory (RAM), which is the actual hardware memory of an electronic device used to store running programs and data. The physical memory of an electronic device can also be called its system memory.
[0173] GPU physical memory, also known as GPU memory, refers to the physical memory allocated to the GPU in an electronic device. GPU physical memory is used to store data related to graphics rendering. When a running application requires graphics rendering, the GPU can allocate corresponding GPU physical memory for that application and store the application's graphics rendering-related data in that application's dedicated GPU physical memory. GPU physical memory can be a portion of system memory. For example, the GPU physical memory of an integrated graphics card can be part of the system memory, meaning that the GPU physical memory of an integrated graphics card will consume a portion of the system memory, resulting in a reduction in system memory. Alternatively, GPU physical memory can be a separate physical memory from system memory. For example, a dedicated graphics card can have its own dedicated GPU physical memory, meaning that the dedicated graphics card does not consume system memory.
[0174] Page: In memory management, a page is the smallest unit of address space; that is, a page can be the smallest unit of both virtual and physical address space. A typical page is 4 kilobytes (KB).
[0175] Generally, a system can divide both the virtual address space and the physical address space into multiple fixed-size pages, and maintain a page table for each process. The page table stores the mapping between virtual pages and physical pages within that process. A virtual page can refer to a page in the virtual address space, and a physical page can refer to a page in the physical address space.
[0176] When a process needs to access a specific virtual address, the system can determine the virtual page corresponding to that address. Based on the process's page table, it can look up the physical page mapped to that virtual page and determine the physical address of that mapped physical page. This allows the process to access physical memory based on the physical address. The virtual address can include a virtual page number and a virtual page offset. The physical address can include a physical page number and a physical page offset. Therefore, the system can determine the virtual page based on the virtual address and the physical address based on the physical page.
[0177] For a process, not all virtual addresses have corresponding physical pages in physical memory. When a process accesses a virtual address and cannot find a corresponding physical page by looking up the page table, or finds a corresponding physical page but does not have the access permission, a page fault will occur.
[0178] A page fault is an error triggered by a hardware interrupt that can be corrected by software logic.
[0179] Page faults can include hard page faults, soft page faults, and invalid page faults. Hard page faults are also called major page faults, and soft page faults are also called minor page faults.
[0180] A hard page fault occurs when a process needs to access a virtual address, but there is no corresponding physical page in physical memory. When a hard page fault occurs, the system can read the corresponding data from the disk into physical memory. In other words, it can allocate physical pages in physical memory to store the data and establish a mapping between the virtual page corresponding to the virtual address and the physical page. This allows the process to access physical memory by mapping the virtual address to the corresponding physical address.
[0181] A soft page fault occurs when a process needs to access a virtual address, for which a corresponding physical page exists in physical memory, but this page might have been loaded by another process, and the process that issued the page fault is unaware of it. When a soft page fault occurs, the system only needs to establish a mapping between the virtual page and the physical page corresponding to that virtual address; it does not need to read the corresponding data from the disk into physical memory. Soft page faults typically occur in scenarios where multiple processes share a memory region.
[0182] Invalid page fault exception: This means that the process accesses a physical address that is out of bounds or references a null pointer. In this case, the system can send an exception notification and terminate the process.
[0183] Similarly, GPU physical memory can be managed by the GPU in an electronic device. For each running application, the GPU can maintain a GPU page table for its corresponding process. The GPU page table can store the mapping between virtual pages and GPU physical pages (also simply called physical pages). When a process needs to access a certain virtual address, the GPU can determine the virtual page corresponding to that virtual address, and according to the GPU page table for that process, it can map that virtual page to the corresponding GPU physical page, and determine the physical address corresponding to the mapped GPU physical page, thus allowing the process to access GPU physical memory according to the physical address.
[0184] However, GPUs do not support page faults. This means that when GPU physical memory is part of system memory, if an application moves to the background and releases the GPU physical memory it occupies, an error will occur when the application returns to the foreground and accesses that memory again. Therefore, GPU memory used by an application is generally not released when it moves to the background. This leads to an increase in GPU physical memory usage as the number of applications used by the user increases, resulting in less and less available physical memory in the overall system. Consequently, electronic devices become increasingly responsive to user actions, leading to a poor user experience.
[0185] When GPU physical memory is separate from system memory, the GPU physical memory occupied by the application is generally not released when the application exits the background. As the number of applications used by the user increases, the GPU physical memory usage also increases, and the remaining available GPU physical memory of the electronic device decreases. This reduces the speed of GPU graphics rendering, causing the electronic device to respond to user operations more and more slowly, resulting in a poor user experience.
[0186] This application provides a memory management method that can release the GPU physical memory corresponding to an application when the application enters the background state, and does not affect the normal use of the application when the application returns to the foreground state. This method can increase the available physical memory of the whole machine or increase the available GPU physical memory of the whole machine, thereby improving the response speed of electronic devices, enhancing system smoothness, and improving user experience.
[0187] In other words, when GPU physical memory is part of system memory, the memory management method provided in this application can release the GPU physical memory corresponding to the application when the application enters the background state, thereby increasing the remaining available physical memory of the electronic device, improving the response speed of the electronic device, enhancing system smoothness, and improving user experience. When GPU physical memory is physical memory separate from system memory, the memory management method provided in this application can also release the GPU physical memory corresponding to the application when the application enters the background state, thereby increasing the available GPU physical memory of the electronic device, improving the graphics rendering speed of the electronic device, enhancing the response speed of the electronic device, and improving user experience.
[0188] The following example illustrates this using GPU physical memory as part of the system memory.
[0189] The memory management method provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings and specific application scenarios.
[0190] Please refer to Figure 4, which shows a schematic flowchart of a memory management method provided in an embodiment of this application. This method can be applied to electronic devices containing a GPU, such as mobile phones, tablets, or laptops. As shown in Figure 4, the method may include:
[0191] S401. When the first application is detected to switch to the background state, the electronic device determines the first GPU physical memory corresponding to the first application.
[0192] S402, The electronic device obtains the first content stored in the first GPU physical memory and saves the first content stored in the first GPU physical memory to the disk.
[0193] S403, Electronic device releases first GPU physical memory.
[0194] For example, the first application can be any application in the electronic device that requires graphics rendering. The first application can be a system application or a third-party application. It should be understood that a system application can refer to an application provided by the provider of the electronic device's operating system. A third-party application can refer to an application provided by a provider other than the provider of the electronic device's operating system. That is, a third-party application can refer to an application provided by another provider (not the operating system provider).
[0195] For example, the app stores, text messaging, and cameras that come pre-installed on electronic devices can be applications provided by the operating system provider; these can be considered system applications. For instance, applications downloaded and installed from the app store onto the electronic device... or Applications can be provided by non-operating system providers, i.e., downloaded from app stores. and These can be referred to as third-party applications.
[0196] For example, when a first application is running in the foreground on an electronic device, the user can perform an input (hereinafter referred to as the first input) to switch the first application to the background. That is, the first input can be used to switch the first application from the foreground to the background. In other words, the first application can be in the foreground while the user performs the first input. After detecting the user's first input, the electronic device can switch the first application from the foreground to the background.
[0197] It should be noted that the embodiments of this application do not limit the first input for switching the first application to the background state, and can be determined according to the actual scenario. For example, the first input can be the user's input when returning to the desktop or main interface by swiping up from the bottom of the display screen or by clicking the home button (virtual button, floating button, or physical button). For example, the first input can be the user's input when bringing up the multitasking interface on the current screen, thereby putting the first application into the background state. For example, the user can bring up the multitasking interface by swiping up from the bottom of the display screen and pausing, and can click on the window of another application in the multitasking interface to bring the other application into the foreground state and the first application into the background state.
[0198] In some embodiments, the electronic device can monitor the status of each application through an Activity Management Service (AMS). Specifically, the electronic device can monitor the status of a first application through AMS. When the first application is detected to have switched to a background state, AMS can determine that the first application does not currently need to display images, meaning it does not currently need to render graphics, and therefore does not currently need to use GPU physical memory. At this point, AMS can determine that the first application is one for which GPU physical memory can be released according to the memory management method provided in this application. Therefore, AMS can instruct the GPU to release the first GPU physical memory corresponding to the first application, thereby reclaiming the first GPU physical memory corresponding to the first application and increasing the remaining available physical memory of the electronic device.
[0199] For example, AMS can send information (hereinafter referred to as the first information) to the GPU to instruct the first application to go to the background, and can release the first GPU physical memory corresponding to the first application. After obtaining the first information, the GPU can determine the first GPU physical memory corresponding to the first application according to S401 to S403, can obtain the first content stored in the first GPU physical memory, can save the first content to the disk, and can release the first GPU physical memory.
[0200] For example, AMS can send the first information to the GPU through the input / output control (ioctl) interface. Ioctl is an interface in a device driver for managing the I / O channels of an electronic device. Managing the I / O channels can refer to controlling certain characteristics of the electronic device. It should be understood that the content and usage of the ioctl interface can refer to existing technologies, and the embodiments of this application do not limit this.
[0201] It should be understood that releasing the first GPU physical memory corresponding to the first application can refer to releasing all the GPU physical memory occupied by the first application; or it can refer to releasing a portion of the GPU physical memory occupied by the first application. For example, as shown in Figure 5, the interface of the first application can include images and text, meaning that the GPU physical memory occupied by the first application can include texture memory occupied by image data, or it can include constant memory occupied by text and font data. Generally, the texture memory occupied by image data is larger, exceeding the constant memory occupied by text and font data. Releasing the first GPU physical memory corresponding to the first application can mean releasing the texture memory occupied by image data. That is, as shown in Figure 5, the content stored in the texture memory can be stored to disk, and the texture memory can be released.
[0202] In other embodiments, when the electronic device detects that the first application has switched to the foreground state, the AMS can instruct the GPU to rebuild the GPU physical memory corresponding to the first application (hereinafter referred to as the second GPU physical memory). For example, the AMS can send information (hereinafter referred to as the second information) to the GPU to instruct the GPU that the first application needs to return to the foreground and that the GPU physical memory of the first application needs to be rebuilt. After obtaining the second information, the GPU can reallocate the second GPU physical memory for the first application. After allocating the second GPU physical memory, the electronic device can obtain the first content previously saved to the disk, fill the first content into the reallocated second GPU physical memory, and establish a mapping relationship between the second GPU physical memory and the virtual address space corresponding to the first application, so that when the first application switches back to the foreground state, the first application can display the image normally without modifying the virtual address corresponding to the first application.
[0203] It should be noted that the above-described monitoring of the status of various applications via AMS is merely illustrative and should not be construed as a limitation of the embodiments of this application. In the embodiments of this application, the electronic device may also monitor the status of various applications through other services. The specific method by which the electronic device monitors the status of various applications can be determined according to the actual scenario.
[0204] It should be understood that after the first GPU physical memory corresponding to the first application is released, if the first application is cleaned up by the operating system through a memory cleanup mechanism, such as by the operating system's default memory cleanup mechanism (low memory killer, LMK), or by the user manually cleaning it up in the multitasking interface, the first application will not return to the foreground state before the next cold boot. At this time, the electronic device does not need to rebuild the second GPU physical memory corresponding to the first application.
[0205] For example, when the first application is switched to the background, the user can perform an input (hereinafter referred to as the second input) to switch the first application to the foreground. That is, the second input can be used to switch the first application from the background to the foreground. In other words, the first application can be in the background while the user performs the second input. After detecting the second input performed by the user, the electronic device can switch the first application from the background to the foreground.
[0206] It should be noted that the embodiments of this application do not limit the second input for switching the first application to the foreground state, and can be determined according to the actual scenario. For example, the second input may be that the user swipes up from the bottom of the screen and pauses to bring up the multitasking interface, and can click on the window of the second application in the multitasking interface to bring the second application to the foreground state.
[0207] Please refer to Figure 6, which shows a schematic diagram of releasing and rebuilding GPU physical memory provided in an embodiment of this application.
[0208] As shown in Figure 6, through the above steps, when the first application is moved to the background and no longer needs to display images or use GPU physical memory, the electronic device can store the content saved in the first GPU physical memory to the disk (represented as disk write in Figure 6), and can reclaim the first GPU physical memory corresponding to the first application to increase the available physical memory of the entire system and improve system smoothness. When the first application returns to the foreground, the electronic device can reallocate the second GPU physical memory for the first application and load the content previously saved to the disk into the reallocated second GPU physical memory (represented as disk read in Figure 6), without affecting the normal use of the first application, and the virtual address of the first application remains unchanged throughout the process.
[0209] In other words, the embodiments of this application can release GPU physical memory to increase the remaining available physical memory of the electronic device without modifying the virtual address of the first application or without the first application being aware of it, thereby improving the smoothness of the system. Furthermore, the images can be accurately displayed even when the first application returns to the foreground state, without affecting the normal use of the first application.
[0210] The process of releasing GPU physical memory in electronic devices is explained in detail below.
[0211] Please refer to Figure 7, which illustrates a flowchart of a method for releasing GPU physical memory according to an embodiment of this application. The flowchart uses an example of an electronic device detecting the state of a first application via AMS for illustrative purposes. As shown in Figure 7, the method may include:
[0212] S701. When the first application is detected to switch to the background state, AMS notifies the GPU to move the first application to the background.
[0213] In this embodiment, the AMS in the electronic device can monitor the status of the first application in real time. Specifically, when it detects that the first application has started running, that is, when it detects that the first application has entered the foreground state, but not switched from the background state to the foreground state, the AMS can determine that GPU physical memory needs to be allocated to the first application.
[0214] Since the physical memory of an electronic device is managed by the GPU, meaning that the release or allocation of GPU physical memory is performed by the GPU, AMS can send information (hereinafter referred to as third information) to the GPU upon detecting the startup of the first application. This third information can be used to notify the GPU that the first application has started running and that GPU physical memory needs to be allocated for it. After receiving the third information, the GPU can allocate the corresponding GPU physical memory (e.g., first GPU physical memory) for the first application.
[0215] While the first application is running, AMS can continue to monitor its status. When it detects that the first application has switched from a foreground state to a background state, AMS can determine that the first application does not currently need to use GPU physical memory, and therefore can determine that the first GPU physical memory corresponding to the first application can be released. At this time, AMS can notify the GPU to move the first application to the background, thus releasing the first GPU physical memory corresponding to the first application.
[0216] For example, AMS can send initial information to the GPU via the ioctl interface. This initial information can be used to notify the GPU that the first application has been moved to the background, and can also release the physical memory of the first GPU corresponding to the first application.
[0217] S702, GPU determines the virtual address space corresponding to the first application.
[0218] It should be understood that for an application running on an electronic device, the operating system of the electronic device can allocate a corresponding virtual address space for the application. When the application requires graphics rendering, the GPU can obtain and save the virtual address space corresponding to the application. In other words, for applications requiring graphics rendering, the GPU can store the correspondence between the application and its corresponding virtual address space while the application is running (hereinafter referred to as correspondence A).
[0219] Therefore, after obtaining the first information, the GPU can determine the virtual address space corresponding to the first application based on the correspondence A, and determine the first GPU physical memory corresponding to the first application based on the virtual address space corresponding to the first application, thereby releasing the first GPU physical memory.
[0220] It should be noted that a virtual address space can include at least one virtual address. Generally, a virtual address space can include multiple virtual addresses. A virtual address can include a virtual page number and a virtual page offset. That is, the virtual address space can be divided into multiple fixed-size virtual pages. Each virtual page can have a corresponding virtual address. In other words, each virtual address can point to a corresponding virtual page.
[0221] Similarly, a physical address space (such as GPU physical memory) can include at least one physical address. Generally, GPU physical memory can include multiple physical addresses. A physical address can include a physical page number and a physical page offset. That is, GPU physical memory can be divided into multiple fixed-size GPU physical pages (or physical pages). Each physical page can have a corresponding physical address. In other words, each physical address can point to a corresponding physical page.
[0222] The size of a physical page is generally the same as the size of a virtual page. For example, both the physical page size and the virtual page size can be 4KB.
[0223] S703 and GPU determine the first physical page corresponding to each virtual address based on the GPU page table.
[0224] In this embodiment, for a running application that requires graphics rendering, the GPU can maintain a GPU page table corresponding to that application. The GPU page table can include the mapping relationship between virtual pages and physical pages corresponding to the application. Therefore, after determining the virtual addresses corresponding to the first application, the GPU can determine the physical page (i.e., the first physical page) corresponding to each virtual address based on the virtual addresses and the GPU page table corresponding to the first application, thus determining the first GPU physical memory corresponding to the first application.
[0225] For example, for each virtual address corresponding to the first application, the GPU can determine the virtual page number corresponding to that virtual address, and thus determine the virtual page corresponding to that virtual address. After determining the virtual pages corresponding to each virtual address, the GPU can determine the first physical page corresponding to each virtual address based on the virtual pages corresponding to each virtual address and the GPU page table corresponding to the first application.
[0226] S704 and GPU retrieve the first content stored in each first physical page.
[0227] The S705 and GPU save the first content of each first physical page to the disk.
[0228] S706, GPU releases the first physical pages corresponding to the first application.
[0229] In some embodiments, after determining the first physical pages corresponding to each virtual address of the first application, the GPU can obtain the content stored in each first physical page (i.e., the first content). Subsequently, the GPU can save the first content stored in each first physical page to the disk, and can release each first physical page corresponding to the first application and delete the GPU page table corresponding to the first application, so as to remove the mapping relationship between the virtual pages and the first physical pages corresponding to the first application, and reclaim the first GPU physical memory corresponding to the first application, that is, reclaim all the GPU physical memory occupied by the first application.
[0230] In other embodiments, after determining the first physical pages corresponding to each virtual address of the first application, the GPU can obtain the first content stored in each first physical page. Subsequently, the GPU can determine the target physical pages that need to be released based on the first content stored in each first physical page. For example, the GPU can determine the first physical page storing image data based on the first content stored in each first physical page, and can determine the first physical page storing image data as the target physical page that needs to be released. After determining the target physical pages, the GPU can save the first content stored in each target physical page to disk, and can release each target physical page and delete the mapping relationship between each target physical page and the virtual page, thereby reclaiming a portion of the GPU physical memory occupied by the first application.
[0231] In one possible implementation, when saving the first content stored in each first physical page to disk, the GPU can record the correspondence between each first content and the virtual page (hereinafter referred to as correspondence B) based on the mapping relationship between each first physical page and the virtual page (i.e., the GPU page table corresponding to the first application). After rebuilding the second GPU physical memory corresponding to the first application, the GPU can retrieve each first content from the disk and fill each first content into the second physical page in the second GPU physical memory. Subsequently, the GPU can establish the mapping relationship between the virtual page and the second physical page based on the first content filled into each second physical page and the correspondence B between the first content and the virtual page, so as to rebuild the GPU page table corresponding to the first application. This allows the first application to be mapped to the correct physical page based on the rebuilt GPU page table when the first application switches to the foreground state without modifying the virtual address of the first application. This enables the first application to access the GPU physical memory normally, thus allowing the first application to be used normally and to display the image correctly.
[0232] For example, when the first GPU physical memory includes first physical pages A1, A2, A3, and A4, and the virtual pages include virtual pages B1, B2, B3, and B4, and first physical page A1 can be mapped to virtual page B4, first physical page A2 can be mapped to virtual page B3, first physical page A3 can be mapped to virtual page B2, and first physical page A4 can be mapped to virtual page B1, when saving the first content stored in first physical page A1 (e.g., first content A1) to disk, the GPU can record the correspondence between first content A1 and virtual page B4. When saving the first content stored in first physical page A2 (e.g., first content A2) to disk, the GPU can record the correspondence between first content A2 and virtual page B3. When saving the first content stored in first physical page A3 (e.g., first content A3) to disk, the GPU can record the correspondence between first content A3 and virtual page B2. When the first content (e.g., first content A4) stored in the first physical page A4 is saved to the disk, the GPU can record the correspondence between the first content A4 and the virtual page B1.
[0233] After rebuilding the second GPU physical memory corresponding to the first application, the GPU can obtain each of the first contents from the disk, namely, first contents A1, first contents A2, first contents A3 and first contents A4. The GPU can then fill the first contents A1, first contents A2, first contents A3 and first contents A4 into the second physical pages in the second GPU physical memory. For example, the second GPU physical memory may include second physical pages C1, C2, C3 and C4. The GPU can fill the first contents A1 into the second physical page C4, fill the first contents A2 into the second physical page C3, fill the first contents A3 into the second physical page C2, and fill the first contents A4 into the second physical page C1.
[0234] Subsequently, the GPU can establish a mapping relationship between virtual pages and second physical pages based on the first content filled in each second physical page and the correspondence B between the first content and the virtual page, so as to re-establish the GPU page table corresponding to the first application. For example, the re-established GPU page table may include virtual page B1 mapped to second physical page C1, virtual page B2 mapped to second physical page C2, virtual page B3 mapped to second physical page C3, and virtual page B4 mapped to second physical page C4.
[0235] In another possible implementation, the mapping relationship between the virtual pages and physical pages corresponding to the first application can be a sequential mapping, that is, the first virtual page can be mapped to the first physical page, the second virtual page can be mapped to the second physical page, and the third virtual page can be mapped to the third physical page, and so on. When saving the first content stored in each first physical page to disk, the GPU can record the storage location of each first content in the first GPU physical memory, that is, record which physical page each first content belongs to in the first GPU physical memory. After rebuilding the second GPU physical memory corresponding to the first application, the GPU can fill each first content into the corresponding second physical page in the second GPU physical memory according to the storage location of each first content in the first GPU physical memory. Subsequently, the GPU can establish the mapping relationship between the virtual pages and the second physical pages according to the sequential mapping, so as to rebuild the GPU page table corresponding to the first application. This allows the first application to access the GPU physical memory normally and thus be used normally, enabling the first application to display images correctly.
[0236] For example, when the first GPU physical memory includes first physical page A1, first physical page A2, first physical page A3 and first physical page A4 in sequence, and the virtual pages include virtual page B1, virtual page B2, virtual page B3 and virtual page B4 in sequence, it can be determined from the sequential mapping that first physical page A1 is mapped to virtual page B1, first physical page A2 is mapped to virtual page B2, first physical page A3 is mapped to virtual page B3, and first physical page A4 is mapped to virtual page B4.
[0237] When saving the first content A1 stored in the first physical page A1 to disk, the GPU can record the storage location of the first content A1 in the first GPU physical memory as the first physical page. When saving the first content A2 stored in the first physical page A2 to disk, the GPU can record the storage location of the first content A2 in the first GPU physical memory as the second physical page. When saving the first content A3 stored in the first physical page A3 to disk, the GPU can record the storage location of the first content A3 in the first GPU physical memory as the third physical page. When saving the first content A4 stored in the first physical page A4 to disk, the GPU can record the storage location of the first content A4 in the first GPU physical memory as the fourth physical page.
[0238] After reconstructing the second GPU physical memory corresponding to the first application, the GPU can fill each first content into the corresponding second physical page in the second GPU physical memory according to the storage location of each first content in the first GPU physical memory. For example, when the second GPU physical memory can sequentially include second physical pages C1, C2, C3, and C4, the GPU can fill first content A1 into second physical page C1, first content A2 into second physical page C2, first content A3 into second physical page C3, and first content A4 into second physical page C4.
[0239] Subsequently, the GPU can establish a mapping relationship between virtual pages and second physical pages based on the sequential mapping, so as to rebuild the GPU page table corresponding to the first application. For example, the rebuilt GPU page table may include virtual page B1 mapped to second physical page C1, virtual page B2 mapped to second physical page C2, virtual page B3 mapped to second physical page C3, and virtual page B4 mapped to second physical page C4.
[0240] The process of rebuilding GPU physical memory in electronic devices is explained in detail below.
[0241] Please refer to Figure 8, which illustrates a flowchart of rebuilding GPU physical memory according to an embodiment of this application. This flowchart uses the example of an electronic device detecting the state of a first application via AMS for illustrative purposes. As shown in Figure 8, the process of rebuilding GPU physical memory may include:
[0242] S801. When the first application is detected to switch to the foreground state, AMS notifies the GPU to return the first application to the foreground.
[0243] When the first application switches to the background, AMS can continue to monitor its status. When it detects that the first application has switched from the background to the foreground, AMS can determine that the first application currently needs to use GPU physical memory, and thus determine that the GPU physical memory corresponding to the first application needs to be rebuilt. At this time, AMS can notify the GPU that the first application has returned to the foreground and that the GPU physical memory corresponding to the first application needs to be rebuilt.
[0244] For example, AMS can send a second message to the GPU via the ioctl interface. This second message can be used to notify the GPU that the first application has returned to the foreground and that the GPU physical memory corresponding to the first application needs to be rebuilt.
[0245] S802, GPU determines the virtual address space corresponding to the first application.
[0246] It should be understood that the specific details of how the GPU determines the virtual address space corresponding to the first application can be found in the relevant descriptions in S702 and GPU determining the virtual address space corresponding to the first application, and will not be repeated here.
[0247] S803, GPU determines the size of the second GPU physical memory corresponding to the first application, and reallocates the second GPU physical memory for the first application based on the size of the second GPU physical memory.
[0248] In some embodiments, when saving the first content stored in the first GPU physical memory to disk, the GPU may record the memory size occupied by the first content. When reconstructing the second GPU physical memory corresponding to the first application, the GPU may determine the size of the second GPU physical memory based on the memory size occupied by the first content.
[0249] In other embodiments, when rebuilding the second GPU physical memory corresponding to the first application, the GPU can read the first content corresponding to the first application stored on the disk and determine the memory size occupied by the first content, so as to determine the size of the second GPU physical memory based on the memory size occupied by the first content.
[0250] For example, the GPU can determine that the size of the second GPU physical memory is the same as the size of the memory occupied by the first content.
[0251] For example, the GPU can determine that the size of the second GPU physical memory is greater than the size of the memory occupied by the first content.
[0252] In other embodiments, when releasing the first GPU physical memory, the GPU can record the size of the first GPU physical memory and determine the size of the second GPU physical memory based on the size of the first GPU physical memory. For example, it can be determined that the size of the second GPU physical memory is the same as the size of the first GPU physical memory. Alternatively, it can be determined that the size of the second GPU physical memory is greater than the size of the first GPU physical memory.
[0253] It should be understood that the second GPU physical memory may include at least one physical page (i.e., a second physical page). The number of second physical pages included in the second GPU physical memory can be determined based on the size of the second GPU physical memory and the size of the second physical page. The size of the second physical page can be the same as the size of the first physical page. For example, the size of the second physical page can be 4KB, and the size of the second GPU physical memory can be an integer multiple of 4KB.
[0254] S804, GPU fetches the first content from the disk.
[0255] S805, the GPU fills the first content into the second physical page in the second GPU physical memory.
[0256] S806, GPU establishes a mapping relationship between the second physical page and the virtual page corresponding to the virtual address.
[0257] In this embodiment, after allocating the second GPU physical memory to the first application, the GPU can retrieve the previously saved first content from the disk, i.e., obtain the first content corresponding to each first physical page. Subsequently, the GPU can fill the second physical pages in the second GPU physical memory with the first content corresponding to each first physical page, and can re-establish the mapping relationship between the second physical pages and the virtual pages corresponding to the first application, i.e., re-establish the GPU page table corresponding to the first application. This allows the first application to accurately access the GPU physical memory based on the re-established GPU page table and the virtual address corresponding to the first application, thereby enabling the first application to function normally and display images correctly.
[0258] In one possible implementation, when saving the first content stored in each first physical page to disk, the GPU can record the correspondence B between each first content and the virtual page based on the mapping relationship between each first physical page and the virtual page (i.e., the GPU page table corresponding to the first application). Therefore, after rebuilding the second GPU physical memory corresponding to the first application, the GPU can retrieve each first content from the disk and fill each first content into the second physical page in the second GPU physical memory. Subsequently, the GPU can establish the mapping relationship between the virtual page and the second physical page based on the first content filled into each second physical page and the correspondence B between the first content and the virtual page, so as to rebuild the GPU page table corresponding to the first application. This allows the first application to access the GPU physical memory normally and thus be used normally, enabling the first application to display images correctly, without modifying the virtual address of the first application.
[0259] In another possible implementation, the mapping relationship between the virtual pages and physical pages corresponding to the first application can be a sequential mapping, that is, the first virtual page can be mapped to the first physical page, the second virtual page can be mapped to the second physical page, and the third virtual page can be mapped to the third physical page, and so on. When saving the first content stored in each first physical page to disk, the GPU can record the storage location of each first content in the first GPU physical memory, that is, record which physical page each first content belongs to in the first GPU physical memory. Therefore, after rebuilding the second GPU physical memory corresponding to the first application, the GPU can fill each first content into the corresponding second physical page in the second GPU physical memory according to the storage location of each first content in the first GPU physical memory. Subsequently, the GPU can establish the mapping relationship between the virtual pages and the second physical pages according to the sequential mapping to rebuild the GPU page table corresponding to the first application. This allows the first application to access the GPU physical memory normally and thus be used normally, enabling the first application to display images correctly, without modifying the virtual address of the first application.
[0260] It should be understood that the sequence number of each step in the above embodiments does not imply 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 this application.
[0261] Corresponding to the memory management method described in the above embodiments, this application also provides a memory management device, the various modules of which can implement the various steps of the memory management method.
[0262] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0263] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0264] This application also provides an electronic device, which includes at least one memory, at least one processor, and a computer program stored in the at least one memory and executable on the at least one processor. The processor may include a GPU. When the processor executes the computer program, it causes the electronic device to implement the steps described in any of the above-described memory management method embodiments. For example, the structure of the electronic device may be as shown in Figure 2.
[0265] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a computer, causes the computer to implement the steps in any of the above-described memory management method embodiments.
[0266] This application provides a computer program product that, when run on an electronic device, enables the electronic device to implement the steps described in any of the above-described memory management method embodiments.
[0267] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable storage medium can include at least: any entity or device capable of carrying computer program code to a device / electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0268] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0269] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0270] In the embodiments provided in this application, it should be understood that the disclosed devices / electronic devices and methods can be implemented in other ways. For example, the device / electronic device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings or direct couplings or communication connections may be through some interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0271] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0272] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A method for GPU memory management, applied to electronic devices, characterized in that, The method includes: When the first application is detected to switch to the background state, the first content stored in the first GPU physical memory corresponding to the first application is saved to the disk; Release the first GPU physical memory; The release of the first GPU physical memory includes: Release the first physical page of the first GPU physical memory; Delete the first mapping relationship between the first physical page and the first virtual page corresponding to the first application.
2. The method according to claim 1, characterized in that, When the first application is detected to have switched to a background state, the first content stored in the first GPU physical memory corresponding to the first application is saved to the disk, including: When it is detected that the first application has switched to the background state and the first application is not performing graphics rendering, the first content stored in the first GPU physical memory corresponding to the first application is saved to the disk.
3. The method according to claim 1 or 2, characterized in that, The method further includes: When the first application is detected to switch to the foreground state, the second GPU physical memory is reallocated to the first application.
4. The method according to claim 3, characterized in that, The method further includes: Establish a second mapping relationship between the first virtual page and the second physical page of the second GPU physical memory.
5. The method according to claim 4, characterized in that, Establishing the second mapping relationship between the first virtual page and the second physical page includes: The first virtual page is determined according to a third mapping relationship, wherein the third mapping relationship is the correspondence between the first content and the first virtual page; Establish a second mapping relationship between the first virtual page and the second physical page.
6. The method according to claim 2, characterized in that, The first GPU physical memory includes the texture memory of the first application or the constant memory of the first application.
7. The method according to any one of claims 1-2 or 4-6, characterized in that, The first physical page includes the first content.
8. The method according to claim 1 or 2, characterized in that, The electronic device includes a first GPU page table, which stores the first mapping relationship.
9. The method according to claim 1 or 2, characterized in that, Before saving the first content stored in the first GPU physical memory corresponding to the first application to the disk, the method further includes: Determine the virtual address space corresponding to the first application; The physical memory of the first GPU is determined based on the virtual address space.
10. The method according to claim 9, characterized in that, Determining the first GPU physical memory based on the virtual address space includes: The first physical page is determined based on the first virtual page and the first mapping relationship.
11. The method according to claim 5, characterized in that, Saving the first content stored in the first GPU physical memory to the disk includes: Save the first content stored in the first GPU physical memory to the disk, and record the third mapping relationship between the first content and the first virtual page.
12. The method according to claim 4 or 5, characterized in that, After reallocating the second GPU physical memory to the first application, the method further includes: The first content is retrieved from the disk and then populated into the second GPU physical memory.
13. The method according to claim 12, characterized in that, The step of retrieving the first content from the disk and filling the first content into the second GPU physical memory includes: The first content is retrieved from the disk and populated into the second physical page included in the second GPU physical memory.
14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it causes the electronic device to implement the GPU memory management method as described in any one of claims 1 to 13.
15. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the computer, it causes the computer to implement the GPU memory management method as described in any one of claims 1 to 13.
Citation Information
Patent Citations
Memory management method, electronic equipment and computer readable storage medium
CN121166329A
Memory management method and terminal equipment
CN113590500A
Method and device for recovering running state of application program and storage medium
CN113849339A
Memory management method, electronic equipment and computer readable storage medium
CN114356537A
Memory management method and device, computer equipment and storage medium
CN116302491A