Memory management method, electronic equipment and computer readable storage medium

The problem of increasing device memory footprint is solved by saving and freeing GPU physical memory when the application switches to the background, and the response speed and user experience are improved.

CN119987995APending Publication Date: 2025-05-13HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411824312.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

In electronic devices, when the application switches to the background, the physical GPU memory occupied cannot be released, resulting in a gradual increase in physical GPU memory usage, resulting in a decrease in the remaining available memory of the device, a decrease in response speed, and affecting the user experience.

Method used

Implement a memory management method. When an application is detected to switch to the background, it saves its contents in the GPU physical memory to disk and frees up the corresponding GPU physical memory to reduce memory usage. When the application switches back to the foreground, redistributes the GPU physical memory and restores previously saved content from disk to ensure the application is functioning properly.

Benefits of technology

By releasing the physical GPU memory of the background application, the memory usage is reduced, the remaining available memory of the device is increased, the system response speed and fluency are improved, and the user experience is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119987995A_ABST
    Figure CN119987995A_ABST
Patent Text Reader

Abstract

The invention is suitable for the technical field of terminals, and particularly relates to a memory management method, electronic equipment and a computer readable storage medium. According to the method, when it is detected that the first application is switched to the background state, the electronic device can determine that the first application does not need to display an image and does not need to carry out graphic rendering, that is, it can be determined that the first application does not need to use a GPU physical memory currently. At the moment, the electronic equipment can store the first content stored in the first GPU physical memory corresponding to the first application to a disk, and can release the first GPU physical memory, so that the occupation of the GPU physical memory is reduced, the remaining available physical memory of the electronic equipment can be increased, the response speed of the electronic equipment to user operation is increased, the fluency of the system is improved, and the user experience is improved. And user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application. The application number of the original application is 202410799228.5, and the original application date is June 19, 2024. The entire contents of the original application are incorporated into this application by reference. Technical Field

[0002] The present application belongs to the field of terminal technology, and in particular, relates to a memory management method, an electronic device, and a computer-readable storage medium. Background Art

[0003] Electronic devices such as mobile phones and tablets generally include a graphics processing unit (GPU). The GPU can be used for graphics rendering, for example, for rendering images that the application needs to display. When the application performs graphics rendering through the GPU, the relevant data of the graphics rendering can be stored in the physical memory corresponding to the GPU (i.e., GPU physical memory or GPU memory). When the application enters the background, the GPU physical memory occupied by the application will not be released, resulting in an increase in the number of applications performing graphics rendering in the electronic device, and the GPU physical memory is occupied more and more, resulting in less and less physical memory remaining in the electronic device, causing the electronic device to respond to user operations more and more slowly, affecting the user experience. Summary of the invention

[0004] The embodiments of the present application provide a memory management method, an electronic device, and a computer-readable storage medium, which can reduce the occupancy 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 the fluency of the system, and enhance the user experience.

[0005] In a first aspect, an embodiment of the present application provides a memory management method, which may include:

[0006] When it is detected that the first application is switched to the background state, saving the first content stored in the first GPU physical memory corresponding to the first application to the disk;

[0007] Release the physical memory of the first GPU.

[0008] In the memory management method provided above, when it is detected that the first application has switched to the background state, the electronic device can determine that the first application does not need to display images and does not need to perform graphics rendering, that is, it can be determined that the first application does not currently need to use the GPU physical memory. 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 can release the first GPU physical memory to reduce the occupancy of the GPU physical memory, which can increase the remaining available physical memory of the electronic device, improve the response speed of the electronic device to user operations, improve the fluency 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 a disk may include:

[0010] Obtaining a virtual address space corresponding to the first application;

[0011] Determining, according to the virtual address space, the first GPU physical memory corresponding to the first application;

[0012] The first content stored in the physical memory of the first GPU is obtained, and the first content is saved to the disk.

[0013] It should be understood that for an application started and run in an electronic device, the operating system of the electronic device can allocate a corresponding virtual address space for the application. Among them, when the application is an application that requires graphics rendering, the GPU in the electronic device can obtain the virtual address space corresponding to the application and save it. In other words, for an application that requires graphics rendering, when the application is running, the GPU can store the corresponding relationship between the application and the virtual address space corresponding to the application.

[0014] In the memory management method provided in this embodiment, when it is determined that the first application switches to the background state, the GPU in the electronic device can determine the virtual address space corresponding to the first application based on the corresponding relationship, and can determine the first GPU physical memory corresponding to the first application based on the virtual address space corresponding to the first application, thereby obtaining the first content stored in the first GPU physical memory, and can save the first content to the disk, so as to release the first GPU physical memory.

[0015] In one example, the virtual address space includes at least one virtual address, and each of the virtual addresses corresponds to a virtual page.

[0016] Determining the first GPU physical memory corresponding to the first application according to the virtual address space may include:

[0017] A first physical page corresponding to the first application is determined according to a virtual page corresponding to the virtual address and a first GPU page table, wherein a mapping relationship between the virtual page and the first physical page is stored in the first GPU page table, and the first GPU physical memory includes at least one of the first physical pages.

[0018] It should be noted that the virtual address space may include at least one virtual address. Generally, the virtual address space may include multiple virtual addresses. The virtual address may include a virtual page number and a virtual page offset. That is, the virtual address space may be divided into multiple virtual pages of fixed size. Each virtual page may have a corresponding virtual address. In other words, each virtual address may point to a corresponding virtual page.

[0019] Similarly, a physical address space (e.g., GPU physical memory) may include at least one physical address. Generally, a GPU physical memory may include multiple physical addresses. A physical address may include a physical page number and a physical page offset. That is, the GPU physical memory may be divided into multiple GPU physical pages (or physical pages) of a fixed size. Each physical page may have a corresponding physical address. In other words, each physical address may 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 needs to perform graphics rendering, the GPU may maintain a GPU page table corresponding to the application, and the GPU page table may include a mapping relationship between a virtual page and a physical page corresponding to the application. That is, for a running first application, the first GPU physical memory corresponding to the first application may be divided into a plurality of physical pages of a fixed size (i.e., a first physical page). The GPU may store a first GPU page table corresponding to the first application, and the first GPU page table may include a mapping relationship between a virtual page corresponding to the first application and a first physical page.

[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 (that is, the first physical page) corresponding to each virtual address based on the 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] Exemplarily, the acquiring the first content stored in the physical memory of the first GPU and saving the first content to the disk may include:

[0024] The first content stored in each of the first physical pages is acquired, and the first content stored in each of the first physical pages is saved to the disk.

[0025] It should be understood that the content stored in the first GPU physical memory may refer to the content stored in each first physical page included in the first GPU physical memory. Therefore, when it is determined that the first application is switched to the background state, the GPU in the electronic device can obtain the first content stored in each first physical page, and can save the first content stored in each first physical page to the disk, so as to release the first GPU physical memory (i.e., each first physical page).

[0026] In some embodiments, the method may further include:

[0027] According to the first GPU page table and the first physical page corresponding to each of the first contents, the correspondence between the first contents and the virtual page is recorded.

[0028] In the memory management method provided in this embodiment, when the first content stored in each first physical page is saved to the disk, the GPU in the electronic device can record the corresponding relationship 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 can fill each first content into the second physical page in the second GPU physical memory respectively. Subsequently, the GPU in the electronic device can establish a mapping relationship between the virtual page and the second physical page according to the first content filled in each second physical page and the corresponding relationship between the first content and the virtual page, so as to re-establish the GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application can be mapped to the correct physical page according to the re-established GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, so that the first application can be used normally, that is, the first application can display the image correctly.

[0029] In some other embodiments, the method may further include:

[0030] The first GPU page table is released.

[0031] In the memory management method provided in this embodiment, when it is determined that the first application switches to the background state, when the first GPU physical memory corresponding to the first application is released, the first GPU page table corresponding to the first application can also be released, which can avoid erroneous mapping between the virtual page and the physical page corresponding to the first application.

[0032] In a possible implementation, the first GPU physical memory may include all GPU physical memory occupied by the first application, or may include part of 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 may be a relatively large texture memory occupied by the first application.

[0034] In some embodiments, the method may further include:

[0035] When it is detected that the first application is switched 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 switches 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 normally access the GPU physical memory and can be used normally.

[0037] In one example, reallocating the second GPU physical memory for the first application may include:

[0038] Determine the size of the physical memory of the second GPU;

[0039] According to 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 to the first application based on the size of the second GPU physical memory.

[0041] In a 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 according to the memory size occupied by the first content.

[0043] In the memory management method provided by the implementation, when the first content stored in the physical memory of the first GPU is saved to the disk, the GPU in the electronic device can record the memory size occupied by the first content. Therefore, when the second GPU physical memory is reallocated for the first application, the GPU in the electronic device can quickly and accurately determine the size of the second GPU physical memory according to 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 in the disk, and can determine the memory size occupied by the first content, so as to determine the size of the second GPU physical memory according to 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 physical memory of the first GPU, and determine the size of the physical memory of the second GPU according to the size of the physical memory of the first GPU.

[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 can 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 for the first application, the method may further include:

[0049] The first content is obtained from the disk, and the first content is filled into the second GPU physical memory.

[0050] In the memory management method provided in this embodiment, after reallocating the second GPU physical memory for the first application, the GPU in the electronic device can obtain the previously saved first content from the disk, and can fill the second GPU physical memory with the first content, so that the first application can correctly access the GPU physical memory, thereby allowing the first application to be used normally.

[0051] In one example, the second GPU physical memory includes at least one second physical page.

[0052] The acquiring the first content from the disk and filling the first content into the second GPU physical memory may include:

[0053] The first content is obtained from the disk, and the first content is filled into the second physical page included in the second GPU physical memory.

[0054] In another example, the method may further include:

[0055] determining a virtual page corresponding to the first content;

[0056] A second GPU page table is constructed according to a virtual page corresponding to the first content and a second physical page corresponding to the first content, wherein the second GPU page table stores a mapping relationship between the second physical page and the virtual page, and the second physical page corresponding to the first content is a second physical page filled with the first content.

[0057] Exemplarily, determining the virtual page corresponding to the first content may include:

[0058] The virtual page corresponding to the first content is determined according to the correspondence between the first content and the virtual page.

[0059] In the memory management method provided in this example, when the first content stored in each first physical page is saved to the disk, the GPU in the electronic device can record the corresponding relationship 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 can fill each first content into the second physical page in the second GPU physical memory respectively. Subsequently, the GPU can establish a mapping relationship between the virtual page and the second physical page according to the first content filled in each second physical page and the corresponding relationship between the first content and the virtual page, so as to re-establish the second GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application can be mapped to the correct physical page according to the re-established second GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, so that the first application can be used normally, that is, the first application can display the image correctly.

[0060] In a possible implementation, the mapping relationship between the virtual page and the physical page 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 the first content stored in each first physical page is saved to the disk, the GPU can record the storage position of each first content in the physical memory of the first GPU, that is, it can record the physical page number of each first content in the physical memory of the first GPU. Therefore, after rebuilding the second GPU physical memory corresponding to the first application, the GPU can fill each first content into the second physical page at the corresponding position in the physical memory of the second GPU according to the storage position of each first content in the physical memory of the first GPU. Subsequently, the GPU can establish a mapping relationship between the virtual page and the second physical page according to the sequential mapping to re-establish the second GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application can be mapped to the correct physical page according to the re-established second GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, so that the first application can be used normally, that is, the first application can display the image correctly.

[0061] In a second aspect, an embodiment of the present application provides a memory management device, which may include:

[0062] A content saving module, configured to save the first content stored in the first GPU physical memory corresponding to the first application to a disk when detecting that the first application is switched to a background state;

[0063] The memory release module is used to release the physical memory of the first GPU.

[0064] In some embodiments, the content saving module is specifically used to obtain a virtual address space corresponding to the first application; determine the first GPU physical memory corresponding to the first application according to 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, and each of the virtual addresses corresponds to a virtual page.

[0066] The content saving module is further used to determine the first physical page corresponding to the first application according to the virtual page corresponding to the virtual address and the first GPU page table, the mapping relationship between the virtual page and the first physical page is stored in the first GPU page table, and the first GPU physical memory includes at least one of the first physical pages.

[0067] Exemplarily, 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 corresponding relationship between the first content and the virtual page according to the first GPU page table and the first physical page corresponding to each of the first contents.

[0070] In some other embodiments, the device may further include:

[0071] The page table release module is used to release the first GPU page table.

[0072] In a possible implementation, the first GPU physical memory may include all GPU physical memory occupied by the first application, or may include part of 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 it is detected that the first application is switched 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 reallocate the second GPU physical memory for the first application according to the size of the second GPU physical memory.

[0076] In a possible implementation, the memory allocation module is further configured to determine a memory size occupied by the first content, and determine a size of the second GPU physical memory according to the memory size occupied by the first content.

[0077] In another possible implementation, the memory allocation module is further configured to determine a size of the first GPU physical memory, and determine a size of the second GPU physical memory according to the size of the first GPU physical memory.

[0078] In some embodiments, the apparatus may further include:

[0079] A content filling module is used to obtain 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 configured 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 apparatus may further include:

[0083] A virtual page determination module, used to determine a virtual page corresponding to the first content;

[0084] The page table construction module is used to construct a second GPU page table according to the virtual page corresponding to the first content and the second physical page corresponding to the first content, wherein the second GPU page table stores a 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 filled with the first content.

[0085] Exemplarily, the virtual page determination module is specifically configured to determine the virtual page corresponding to the first content according to a correspondence between the first content and the virtual page.

[0086] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein 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] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the computer implements the memory management method described in any one of the above-mentioned first aspects.

[0088] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when executed on an electronic device, enables the electronic device to execute the memory management method described in any one of the above-mentioned first aspects.

[0089] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0090] Figure 1 It is a schematic diagram of a GPU performing graphics rendering;

[0091] Figure 2 is a schematic diagram of the structure of an electronic device to which the memory management method provided in an embodiment of the present application is applicable;

[0092] Figure 3 Schematic diagram of software architecture to which the memory management method provided in the embodiment of the present application is applicable;

[0093] Figure 4 It is a flowchart of the memory management method provided in the embodiment of the present application;

[0094] Figure 5 is a schematic diagram of releasing part of GPU physical memory provided by an embodiment of the present application;

[0095] Figure 6 It is a schematic diagram of releasing GPU physical memory and rebuilding GPU physical memory provided by an embodiment of the present application;

[0096] Figure 7 It is a flowchart of a method for releasing GPU physical memory provided by an embodiment of the present application;

[0097] Figure 8 It is a schematic diagram of the process of rebuilding GPU physical memory provided in an embodiment of the present application. DETAILED DESCRIPTION

[0098] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0099] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0100] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0101] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0102] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0103] In addition, the “plurality” mentioned in the embodiments of the present application should be interpreted as two or more.

[0104] The steps involved in the memory management method provided in the embodiments of the present application are only examples. Not all steps are mandatory steps, or not all information or messages are mandatory. They can be increased or decreased as needed during use. The same step or steps or messages with the same function in different embodiments of the present application can be referenced and learned from each other.

[0105] The business scenarios described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. A person of ordinary skill in the art will appreciate that, with the evolution of network architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0106] Electronic devices such as mobile phones and tablet computers generally include GPUs. GPUs can be used for graphics rendering, for example, for rendering images required to be displayed by an application. When an application performs graphics rendering through a GPU, the relevant data of the graphics rendering can be stored in the GPU physical memory.

[0107] For example, see Figure 1 , Figure 1 A schematic diagram of a GPU performing graphics rendering is shown.

[0108] like Figure 1 As shown, when an application (such as application A) installed in an electronic device needs to display an image, application A can send the to-be-rendered data corresponding to the image to the GPU, for example, a picture, a font, or a coordinate point to be rendered data can be sent to the GPU. The GPU can apply to use a portion of the physical memory of the electronic device as the GPU physical memory corresponding to application A, and after obtaining the to-be-rendered data corresponding to the image, the to-be-rendered data corresponding to the image can be saved to the GPU physical memory corresponding to application A.

[0109] When the GPU renders the image, the GPU can obtain the to-be-rendered data corresponding to the image from the GPU physical memory corresponding to application A. Subsequently, the GPU can decode and calculate the to-be-rendered data corresponding to the image, and can save the decoded and calculated texture and other data to the GPU physical memory corresponding to application A. Finally, the electronic device can send the processed texture and other data to the display module (e.g., display screen) to display the image, thereby realizing the display of the image by application A.

[0110] When application A enters the background, the GPU physical memory occupied by application A will not be released, resulting in an increase in the occupation of GPU physical memory as the number of applications performing graphics rendering increases. This results in less and less remaining available physical memory in the electronic device, causing the electronic device to respond more and more slowly to user operations, affecting the user experience.

[0111] To solve the above problems, an embodiment of the present application provides a memory management method, an electronic device, and a computer-readable storage medium. In the method, when it is detected that the first application switches to the background state, the electronic device can determine that the first application does not need to display images and does not need to perform graphics rendering, that is, the GPU physical memory is not currently needed. At this time, the electronic device can determine the first GPU physical memory corresponding to the first application, and can obtain the first content stored in the first GPU physical memory. Subsequently, the electronic device can save the first content to the disk, and can release the first GPU physical memory to reduce the occupancy of the GPU physical memory, which can increase the remaining available physical memory of the electronic device, improve the response speed of the electronic device to user operations, improve the fluency of the system, and enhance the user experience.

[0112] In the embodiment of the present application, the electronic device may be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, a laptop computer, a desktop computer, or the like that may include a GPU. The embodiment of the present application does not impose any restrictions on the specific type of the electronic device.

[0113] The following first introduces the electronic device involved in the embodiment of the present application. Figure 2 , Figure 2 A schematic structural diagram of an electronic device 200 is shown.

[0114] The electronic device 200 may include a processor 210, an external memory interface 220, an internal memory 221, a universal serial bus (USB) interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, an antenna 2, a mobile communication module 250, a wireless communication module 260, an audio module 270, a speaker 270A, a receiver 270B, a microphone 270C, an earphone interface 270D, a sensor module 280, a button 290, a motor 291, an indicator 292, a camera 293, a display screen 294, and a subscriber identification module (SIM) card interface 295, etc. The sensor module 280 may include a pressure sensor 280A, a gyroscope sensor 280B, an air pressure sensor 280C, an acceleration 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, and the like.

[0115] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 200. In other embodiments of the present application, the electronic device 200 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0116] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0117] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0118] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, 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. The interface 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 understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 200. In other embodiments of the present application, the electronic device 200 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0121] The charging management module 240 is used to receive charging input from a 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, the internal memory 221, the display screen 294, the camera 293, and the wireless communication module 260.

[0123] The wireless communication function of the electronic device 200 can be implemented through the antenna 1, the antenna 2, the mobile communication module 250, the wireless communication module 260, the modem processor and the 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 a single or multiple communication frequency bands.

[0125] The mobile communication module 250 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 200. The mobile communication module 250 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 250 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 250 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 250 can be set in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 250 can be set in the same device as at least some of the modules of the processor 210.

[0126] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate 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 the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 270A, a receiver 270B, etc.), or displays an image or video through a display screen 294. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 210 and be set in the same device as the mobile communication module 250 or other functional modules.

[0127] The wireless communication module 260 can provide wireless communication solutions 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), infrared (IR), etc., which are applied to the electronic device 200. 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 the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 210. The wireless communication module 260 can also receive the signal to be sent from the processor 210, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0128] In some embodiments, the antenna 1 of the electronic device 200 is coupled to the mobile communication module 250, and the antenna 2 is coupled to the wireless communication module 260, so that the electronic device 200 can communicate with the network and other devices through 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 technology, etc. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).

[0129] The electronic device 200 implements the display function through a GPU, a display screen 294, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 294 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 210 may include one or more GPUs, which execute program instructions to generate or change display information.

[0130] The display screen 294 is used to display images, videos, etc. The 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 or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 200 may include 1 or N display screens 294, where N is a positive integer greater than 1.

[0131] The electronic device 200 can realize the shooting function 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 static images or videos. In some embodiments, the electronic device 200 may include 1 or N cameras 293, where N is a positive integer greater than 1.

[0133] Digital signal processors are used to process digital signals. In addition to processing digital image signals, they can also process other digital signals.

[0134] Video codecs are used to compress or decompress digital videos. The electronic device 200 may support one or more video codecs. Thus, the electronic device 200 may play or record videos in a variety of coding formats, such as moving picture experts group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0135] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the electronic device 200 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0136] The external memory 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 memory interface 220 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0137] The internal memory 221 can be used to store computer executable program codes, which include instructions. The internal memory 221 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 200 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 221 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 210 executes various functional applications and data processing of the electronic device 200 by running instructions stored in the internal memory 221 and / or instructions stored in a memory provided in the processor.

[0138] The electronic device 200 can implement audio functions such as music playing and recording through the audio module 270, the speaker 270A, the receiver 270B, the microphone 270C, the headphone jack 270D, and the application processor.

[0139] The audio module 270 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 270 can also be used to encode and decode audio signals.

[0140] The key 290 includes a power key, a volume key, etc. The key 290 can be a mechanical key or a touch key. The electronic device 200 can receive key input and generate key signal input related to user settings and function control of the electronic device 200.

[0141] Motor 291 can generate vibration prompts. Motor 291 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.

[0142] Indicator 292 may be an indicator light, which may 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 the electronic device 200 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. For example, the software system of the electronic device 200 may adopt an Android operating system (OS), a Harmony OS, or an IOS of a layered architecture. In some implementations, the operating system of the electronic device 200 may adopt a layered architecture.

[0145] Figure 3 It is a software structure block diagram of the electronic device 200 according to an embodiment of the present application.

[0146] The layered architecture divides the software into several layers, each with clear roles and division of labor. The 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 library, and the kernel layer.

[0147] The application layer can include a series of application packages.

[0148] like Figure 3 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0149] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0150] like Figure 3 As shown, 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] The activity management service is used to manage activities, such as managing the life cycle of activities. An activity is a component that can contain a user interface and is mainly used to interact with users, such as making calls, sending emails, and viewing maps. Most of the content that users can see in an application is provided by the activity component. In an application, multiple activities can be included.

[0152] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0153] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0154] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0155] The phone manager is used to provide communication functions of the electronic device 200, such as management of call status (including connecting, hanging up, etc.).

[0156] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0157] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0158] The runtime includes the core library 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 function that the Java language needs to call, and the other part is the core library of the operating system.

[0160] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0161] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0162] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0163] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[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 drawing engine for 2D drawings.

[0166] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0167] To facilitate understanding, the key technical terms that may be involved in the embodiments of the present application are first introduced below.

[0168] Foreground: refers to the state where the application is being opened, operated, or currently displayed by the user. An application in the foreground state can perform some operations that the user can notice.

[0169] Background: refers to the application is still running, but no longer displayed on the screen, and the user no longer directly operates or pays attention to the status of the application. The operations performed by the application in the background state are generally not directly noticed by the user.

[0170] Process: refers to the execution of an application. A process can be regarded as an independent program. A process is the basic unit of resource allocation and the basic unit of scheduling and operation. For example, when a user runs an application, the system creates a process and allocates resources (such as CPU resources and / or GPU resources, etc.) to the process. Then, the process is placed in the ready queue of the process. When the process is selected by the scheduler, the system allocates CPU resources and / or GPU resources to the process, so that the process can actually run.

[0171] Virtual memory (VA): It can also be called "logical memory". Virtual memory is a memory management technology that allows the system to provide each process with an address space that is larger than the actual physical memory. This address space can be called the virtual address space, and the actual physical memory can be called the physical address space. The virtual address space can include one or more virtual addresses. 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 and is used to store running programs and data. The physical memory of an electronic device can also be called the system memory of the electronic device.

[0173] GPU physical memory: also known as GPU memory, refers to the physical memory corresponding to the GPU in the electronic device. GPU physical memory can be used to store data related to graphics rendering. That is, when a running application is an application that requires graphics rendering, the GPU can allocate the corresponding GPU physical memory for the application, and can store the graphics rendering-related data corresponding to the application in the GPU physical memory corresponding to the application. Among them, the GPU physical memory can be part of the system memory. For example, the GPU physical memory corresponding to the integrated graphics card can be part of the system memory, that is, the GPU physical memory corresponding to the integrated graphics card will occupy a part of the system memory, resulting in a reduction in system memory. Alternatively, the GPU physical memory can be a physical memory separate from the system memory. For example, a discrete graphics card can have an independent GPU physical memory, that is, the discrete graphics card will not occupy the system memory.

[0174] Page: In the memory management process, a page is the smallest unit of the address space, that is, a page can be the smallest unit of the virtual address space and the physical address space. Generally, a page is 4 kilobytes (KB).

[0175] Generally, the system can divide both the virtual address space and the physical address space into multiple fixed-size pages, and can maintain a page table for each process, which is used to store the mapping relationship between the virtual pages and physical pages in the 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 virtual address, the system can determine the virtual page corresponding to the virtual address, and can find the physical page mapped to the virtual page according to the page table corresponding to the process, and can determine the physical address corresponding to the mapped physical page, so that the process can access the physical memory according to the physical address. Among them, the virtual address can include the virtual page number and the virtual page offset. The physical address can include the physical page number and the physical page offset. Therefore, the system can determine the virtual page according to the virtual address, and can determine the physical address according to 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 fails to find the corresponding physical page by searching the page table, or finds the corresponding physical page but does not have access rights, a page fault will occur.

[0178] Page fault: An error triggered by a hardware interrupt that can be corrected by software logic.

[0179] Page fault exceptions may include hard page fault exceptions, soft page fault exceptions, and invalid page fault exceptions. Hard page fault exceptions may also be referred to as major page fault exceptions, and soft page fault exceptions may also be referred to as minor page fault exceptions.

[0180] Hard page fault exception: refers to the virtual address that the process needs to access, and there is no corresponding physical page in the physical memory. When a hard page fault exception occurs, the system can read the corresponding data from the disk to the physical memory, that is, it can apply for a physical page in the physical memory to save the data, and can establish a mapping relationship between the virtual page corresponding to the virtual address and the physical page, so that when the process accesses the virtual address, it can be mapped to the corresponding physical address to access the physical memory.

[0181] Soft page fault exception: refers to the virtual address that the process needs to access, and there is a corresponding physical page in the physical memory, but it may be called in by other processes, and the process that issued the page fault exception is unaware of it. When a soft page fault exception occurs, the system only needs to establish a mapping relationship between the virtual page corresponding to the virtual address and the physical page, and does not need to read the corresponding data from the disk to the physical memory. Soft page fault exceptions usually occur in scenarios where multiple processes share a memory area.

[0182] Invalid page fault exception: refers to the physical address accessed by the process is out of bounds, or a null pointer reference. At this time, the system can send an exception notification and end the process.

[0183] Similarly, GPU physical memory can be managed by the GPU in the electronic device. For each running application, the GPU can maintain a GPU page table for the corresponding process, and the GPU page table can store the mapping between virtual pages and GPU physical pages (also directly referred to as physical pages). When a process needs to access a virtual address, the GPU can determine the virtual page corresponding to the virtual address, and can map the virtual page to the corresponding GPU physical page according to the GPU page table corresponding to the process, and can determine the physical address corresponding to the mapped GPU physical page, so that the process can access the GPU physical memory according to the physical address.

[0184] However, the GPU does not support page faults. That is to say, when the GPU physical memory is part of the system memory, if the GPU physical memory occupied by the application is released when the application retreats to the background, an error will occur when the application returns to the foreground and accesses the GPU physical memory again. Therefore, when the application retreats to the background, the GPU memory occupied by the application is generally not released, resulting in more and more GPU physical memory being occupied as the number of applications used by users increases, and the remaining available physical memory of the entire system decreases, causing the electronic device to respond more and more slowly to the user's operations, resulting in a poor user experience.

[0185] When the GPU physical memory is a physical memory separate from the system memory, when the application exits the background, the GPU physical memory occupied by the application is generally not released. As a result, as the number of users using more and more applications increases, the GPU physical memory occupancy also increases, and the remaining available GPU physical memory of the electronic device becomes less and less, which will reduce the speed of GPU graphics rendering, causing the electronic device to respond more and more slowly to user operations, resulting in a poor user experience.

[0186] The embodiment of the present application provides a memory management method, which can release the GPU physical memory corresponding to the application when the application enters the background state, and when the application returns to the foreground state, it will not affect the normal use of the application. The physical memory available to the entire machine can be increased, or the GPU physical memory available to the entire machine can be increased, thereby improving the response speed of the electronic device, improving the fluency of the system, and improving the user experience.

[0187] That is to say, when the GPU physical memory is part of the system memory, the memory management method provided in the embodiment of the present application can release the GPU physical memory corresponding to the application when the application enters the background state, so as to increase the remaining available physical memory of the electronic device, improve the response speed of the electronic device, improve the fluency of the system, and improve the user experience. When the GPU physical memory is a physical memory separate from the system memory, the memory management method provided in the embodiment of the present application can release the GPU physical memory corresponding to the application when the application enters the background state, so as to increase the available GPU physical memory of the electronic device, improve the speed of the electronic device for graphics rendering, improve the response speed of the electronic device, and improve the user experience.

[0188] The following is an illustrative description using an example in which the GPU physical memory is a part of the system memory.

[0189] The memory management method provided in the embodiment of the present application will be described in detail below with reference to the accompanying drawings and specific application scenarios.

[0190] See also Figure 4 , Figure 4 FIG. 1 is a schematic flow chart of a memory management method provided in an embodiment of the present application. The method can be applied to an electronic device including a GPU, for example, a mobile phone, a tablet computer, or a laptop computer. Figure 4 As shown, the method may include:

[0191] S401: When detecting that a first application is switched to a background state, the electronic device determines a first GPU physical memory corresponding to the first application.

[0192] S402: The electronic device obtains first content stored in a physical memory of a first GPU, and saves the first content stored in the physical memory of the first GPU to a disk.

[0193] S403: The electronic device releases the first GPU physical memory.

[0194] Exemplarily, the first application may be any application in the electronic device that needs to perform graphics rendering. The first application may be a system application, or may be a third-party application. It should be understood that a system application may refer to an application provided by a provider of an operating system of an electronic device. A third-party application may refer to an application provided by a provider of an operating system of a non-electronic device. That is, a third-party application may refer to an application provided by other providers (providers other than the operating system).

[0195] For example, the application market, text messages, and cameras that come with the electronic device (or can be called pre-installed) can be applications provided by the provider of the operating system of the electronic device, that is, the application market, text messages, and cameras that come with the electronic device can be called system applications. It can be an application provided by a non-operating system provider, that is, downloaded from the application market etc. can be called third-party applications.

[0196] Exemplarily, when the first application is running in the foreground of the electronic device, the user can execute a certain input (hereinafter referred to as the first input) to switch the first application to the background state. That is, the first input can be used to switch the first application from the foreground state to the background state. In other words, when the user executes the first input, the first application can be in the foreground state. After detecting the first input executed by the user, the electronic device can switch the first application from the foreground state to the background state.

[0197] It should be noted that the embodiments of the present application do not limit the first input for switching the first application to the background state, and can be specifically determined according to the actual scenario. For example, the first input can be an input in which the user returns to the desktop or the main interface by swiping up at the bottom of the display screen or by clicking the home button (virtual button, floating button, or physical button) on the display interface. For example, the first input can be an input in which the user calls up the multitasking interface on the current interface so that the first application enters the background state. For example, the user can call up the multitasking interface by swiping up at the bottom of the display screen and pausing, and can click on the windows of other applications on the multitasking interface to make other applications enter the foreground state and the first application enter the background state.

[0198] In some embodiments, the electronic device can monitor the status of each application through the activity management service (AMS). That is, the electronic device can monitor the status of the first application through the AMS. When it is detected that the first application switches to the background state, the AMS can determine that the first application does not currently need to display the image, that is, it can be determined that the first application does not currently need to render graphics, and thus it can be determined that the first application does not currently need to use the GPU physical memory. At this time, the AMS can determine that the first application is an application that can release the GPU physical memory according to the memory management method provided in the embodiment of the present application. Therefore, the AMS can instruct the GPU to release the first GPU physical memory corresponding to the first application to reclaim the first GPU physical memory corresponding to the first application to increase the remaining available physical memory of the electronic device.

[0199] For example, the AMS may send information (hereinafter referred to as the first information) to the GPU to instruct the GPU to retreat to the background through the first information, and to release the first GPU physical memory corresponding to the first application. After obtaining the first information, the GPU may determine the first GPU physical memory corresponding to the first application according to S401 to S403, may obtain the first content stored in the first GPU physical memory, may save the first content to the disk, and may release the first GPU physical memory.

[0200] Exemplarily, the AMS may send the first information to the GPU via an input / output control (ioctl) interface. Ioctl is an interface in a device driver for managing the I / O channels of an electronic device. Among them, managing the I / O channels may refer to controlling some characteristics of the electronic device. It should be understood that the content and usage of the ioctl interface may refer to the prior art, and the embodiments of the present application are not limited thereto.

[0201] It should be understood that releasing the first GPU physical memory corresponding to the first application may refer to releasing all GPU physical memory occupied by the first application; or, may refer to releasing part of the GPU physical memory occupied by the first application. Figure 5 As shown, the interface of the first application may include images and text, that is, the GPU physical memory occupied by the first application may include texture memory occupied by image data, and may also include constant memory occupied by data such as text and fonts. Among them, the texture memory occupied by image data is generally larger, larger than the constant memory occupied by data such as text and fonts. Releasing the first GPU physical memory corresponding to the first application may be releasing the texture memory occupied by image data. Figure 5 As shown, the contents of 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 switches to the foreground state, the AMS may 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 may send information (hereinafter referred to as the second information) to the GPU to indicate to the GPU through the second information that the first application has returned to the foreground and that the GPU physical memory of the first application needs to be rebuilt. After obtaining the second information, the GPU may reallocate the second GPU physical memory for the first application. After allocating the second GPU physical memory, the electronic device may obtain the first content previously saved to the disk, may fill the first content into the reallocated second GPU physical memory, and may 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-mentioned monitoring of the status of each application by AMS is only an exemplary explanation and should not be understood as a limitation on the embodiments of the present application. In the embodiments of the present application, the electronic device may also monitor the status of each application through other services. The specific method of the electronic device monitoring the status of each application can be determined according to the actual scenario.

[0204] It should be understood that after releasing the first GPU physical memory corresponding to the first application, if the first application is cleaned up by the operating system through a memory cleaning mechanism, such as being cleaned up by the operating system's preset memory cleaning mechanism (low memory killer, LMK), or being manually cleaned up by the user on the multitasking interface, the first application will not return to the foreground state before the next cold start. At this time, the electronic device may no longer need to rebuild the second GPU physical memory corresponding to the first application.

[0205] Exemplarily, when the first application switches to the background state, the user can execute a certain input (hereinafter referred to as the second input) to switch the first application to the foreground state. That is, the second input can be used to switch the first application from the background state to the foreground state. In other words, when the user executes the second input, the first application can be in the background state. After detecting the second input executed by the user, the electronic device can switch the first application from the background state to the foreground state.

[0206] It should be noted that the second input for switching the first application to the foreground state is not limited in the embodiment of the present application, and can be determined specifically according to the actual scenario. For example, the second input can be that the user swipes up from the bottom of the display screen and pauses to call up the multitasking interface, and can click on the window of the second application on the multitasking interface to make the second application enter the foreground state.

[0207] See also Figure 6 , Figure 6 A schematic diagram of releasing GPU physical memory and rebuilding GPU physical memory provided by an embodiment of the present application is shown.

[0208] like Figure 6 As shown, through the above steps, when the first application retreats to the background and does not need to display images or use the GPU physical memory, the electronic device can store the content stored in the first GPU physical memory to the disk ( Figure 6 The first application can be represented as a disk in the text file, and the first GPU physical memory corresponding to the first application can be reclaimed to increase the physical memory available to the entire system and improve the smoothness of the system. When the first application returns to the foreground state again, the electronic device can reallocate the second GPU physical memory for the first application and load the first content previously saved to the disk into the reallocated second GPU physical memory ( Figure 6 It can be represented as reading the disk), which may not affect the normal use of the first application, and the virtual address of the first application does not change during the whole process.

[0209] That is, the embodiment of the present application can release the GPU physical memory to increase the remaining available physical memory of the electronic device without modifying the virtual address of the first application and without the first application being aware of it, thereby improving the smoothness of the system, and can accurately display the image when the first application returns to the foreground state without affecting the normal use of the first application.

[0210] The following is a detailed description of the process of releasing GPU physical memory by an electronic device.

[0211] See also Figure 7 , Figure 7 A flow chart of a method for releasing GPU physical memory provided by an embodiment of the present application is shown. The flow chart takes the electronic device detecting the state of the first application through the AMS as an example for illustrative description. Figure 7 As shown, the method may include:

[0212] S701: When detecting that a first application is switched to a background state, the AMS notifies the GPU that the first application exits to the background.

[0213] In the embodiment of the present application, the AMS in the electronic device can monitor the state of the first application in real time. When it is detected that the first application is started, that is, it is detected that the first application enters the foreground state but does not switch 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 GPU physical memory in the electronic device is managed by the GPU in the electronic device, that is, the release or allocation of the GPU physical memory is performed by the GPU. Therefore, when detecting that the first application is started and running, the AMS can send information (hereinafter referred to as the third information) to the GPU, and the third information can be used to notify the GPU that the first application is started and running, and the GPU physical memory needs to be allocated to the first application. After the GPU obtains the third information, it can allocate the corresponding GPU physical memory (such as the first GPU physical memory) to the first application.

[0215] When the first application is running, the AMS can continue to monitor the status of the first application. When detecting that the first application switches from the foreground state to the background state, the AMS can determine that the first application does not currently need to use the GPU physical memory, that is, it can be determined that the first GPU physical memory corresponding to the first application can be released. At this time, the AMS can notify the GPU that the first application retreats to the background, and the first GPU physical memory corresponding to the first application can be released.

[0216] For example, the AMS may send the first information to the GPU through an ioctl interface. The first information may be used to notify the GPU that the first application is retired to the background, and the first GPU physical memory corresponding to the first application may be released.

[0217] S702: The GPU determines a virtual address space corresponding to the first application.

[0218] It should be understood that for an application started and run in an electronic device, the operating system of the electronic device can allocate a corresponding virtual address space for the application. Among them, when the application is an application that requires graphics rendering, the GPU can obtain the virtual address space corresponding to the application and save it. In other words, for an application that requires graphics rendering, when the application is running, the GPU can store the corresponding relationship between the application and the virtual address space corresponding to the application (hereinafter referred to as the corresponding relationship A).

[0219] Therefore, after obtaining the first information, the GPU can determine the virtual address space corresponding to the first application according to the correspondence A, and can determine the first GPU physical memory corresponding to the first application according to the virtual address space corresponding to the first application, so as to release the first GPU physical memory.

[0220] It should be noted that the virtual address space may include at least one virtual address. Generally, the virtual address space may include multiple virtual addresses. The virtual address may include a virtual page number and a virtual page offset. That is, the virtual address space may be divided into multiple virtual pages of fixed size. Each virtual page may have a corresponding virtual address. In other words, each virtual address may point to a corresponding virtual page.

[0221] Similarly, a physical address space (e.g., GPU physical memory) may include at least one physical address. Generally, a GPU physical memory may include multiple physical addresses. A physical address may include a physical page number and a physical page offset. That is, the GPU physical memory may be divided into multiple GPU physical pages (or physical pages) of a fixed size. Each physical page may have a corresponding physical address. In other words, each physical address may 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, the size of a physical page and the size of a virtual page may both be 4 KB.

[0223] S703: The GPU determines the first physical page corresponding to each virtual address according to the GPU page table.

[0224] In the embodiment of the present application, for the running application that needs to perform graphics rendering, the GPU may maintain a GPU page table corresponding to the application, and the GPU page table may include a mapping relationship between the virtual page and the physical page corresponding to the application. Therefore, after determining each virtual address corresponding to the first application, the GPU may determine the physical page (i.e., the first physical page) corresponding to each virtual address based on each virtual address and the GPU page table corresponding to the first application, that is, determine 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 the virtual address based on the virtual address, thereby determining the virtual page corresponding to the virtual address. After determining the virtual page corresponding to each virtual address, the GPU can determine the first physical page corresponding to each virtual address based on the virtual page corresponding to each virtual address and the GPU page table corresponding to the first application.

[0226] S704: The GPU obtains the first content stored in each first physical page.

[0227] S705 . The GPU saves the first content stored in each first physical page to a disk.

[0228] S706: The GPU releases each first physical page corresponding to the first application.

[0229] In some embodiments, after determining the first physical page corresponding to each virtual address of the first application, the GPU can obtain the content (i.e., the first content) stored in each first physical page. 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 release the mapping relationship between the virtual page corresponding to the first application and the first physical page, and reclaim the first GPU physical memory corresponding to the first application, that is, reclaim all GPU physical memory occupied by the first application.

[0230] In other embodiments, after determining the first physical page 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 page that needs 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 the image data based on the first content stored in each first physical page, and can determine the first physical page storing the image data as the target physical page that needs to be released. After determining the target physical page, the GPU can save the first content stored in each target physical page to the disk respectively, and can release each target physical page and delete the mapping relationship between each target physical page and the virtual page to reclaim part of the GPU physical memory occupied by the first application.

[0231] In a possible implementation, when the first content stored in each first physical page is saved to the disk, the GPU can record the corresponding relationship between each first content and the virtual page (hereinafter referred to as the corresponding relationship B) according to 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 obtain each first content from the disk, and can fill each first content into the second physical page in the second GPU physical memory. Subsequently, the GPU can establish a mapping relationship between the virtual page and the second physical page according to the first content filled in each second physical page and the corresponding relationship B between the first content and the virtual page, so as to re-establish the GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application can be mapped to the correct physical page according to the re-established GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, so that the first application can be used normally, that is, the first application can display the image correctly.

[0232] For example, when the first GPU physical memory includes the first physical page A1, the first physical page A2, the first physical page A3, and the first physical page A4, and the virtual page includes the virtual page B1, the virtual page B2, the virtual page B3, and the virtual page B4, and the first physical page A1 can be mapped to the virtual page B4, the first physical page A2 can be mapped to the virtual page B3, the first physical page A3 can be mapped to the virtual page B2, and the first physical page A4 can be mapped to the virtual page B1, when the first content (e.g., the first content A1) stored in the first physical page A1 is saved to the disk, the GPU can record the corresponding relationship between the first content A1 and the virtual page B4. When the first content (e.g., the first content A2) stored in the first physical page A2 is saved to the disk, the GPU can record the corresponding relationship between the first content A2 and the virtual page B3. When the first content (e.g., the first content A3) stored in the first physical page A3 is saved to the disk, the GPU can record the corresponding relationship between the first content A3 and the virtual page B2. When saving the first content (eg, the first content A4 ) stored in the first physical page A4 to the disk, the GPU may 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 first content from the disk, that is, obtain the first content A1, the first content A2, the first content A3 and the first content A4, and can fill the first content A1, the first content A2, the first content A3 and the first content A4 into the second physical page in the second GPU physical memory respectively. For example, the second GPU physical memory may include a second physical page C1, a second physical page C2, a second physical page C3 and a second physical page C4. The GPU can fill the first content A1 into the second physical page C4, fill the first content A2 into the second physical page C3, fill the first content A3 into the second physical page C2, and fill the first content A4 into the second physical page C1.

[0234] Subsequently, the GPU can establish a mapping relationship between the virtual page and the second physical page 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 the second physical page C1, virtual page B2 mapped to the second physical page C2, virtual page B3 mapped to the second physical page C3, and virtual page B4 mapped to the second physical page C4.

[0235] In another possible implementation, the mapping relationship between the virtual page and the physical page corresponding to the first application may be a sequential mapping, that is, the first virtual page may be mapped to the first physical page, the second virtual page may be mapped to the second physical page, and the third virtual page may be mapped to the third physical page, etc. When the first contents stored in each first physical page are saved to the disk, the GPU may record the storage position of each first content in the physical memory of the first GPU, that is, record the physical page number of each first content in the physical memory of the first GPU. After rebuilding the second GPU physical memory corresponding to the first application, the GPU may fill each first content into the second physical page at the corresponding position in the physical memory of the second GPU according to the storage position of each first content in the physical memory of the first GPU. Subsequently, the GPU may establish a mapping relationship between the virtual page and the second physical page according to the sequential mapping to re-establish the GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application may be mapped to the correct physical page according to the re-established GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, thereby allowing the first application to be used normally, that is, the first application can display the image correctly.

[0236] For example, when the first GPU physical memory includes the first physical page A1, the first physical page A2, the first physical page A3 and the 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, according to the sequential mapping, it can be determined that the first physical page A1 is mapped to virtual page B1, the first physical page A2 is mapped to virtual page B2, the first physical page A3 is mapped to virtual page B3, and the 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 the disk, the GPU may record the storage location of the first content A1 in the physical memory of the first GPU as the first physical page. When saving the first content A2 stored in the first physical page A2 to the disk, the GPU may record the storage location of the first content A2 in the physical memory of the first GPU as the second physical page. When saving the first content A3 stored in the first physical page A3 to the disk, the GPU may record the storage location of the first content A3 in the physical memory of the first GPU as the third physical page. When saving the first content A4 stored in the first physical page A4 to the disk, the GPU may record the storage location of the first content A4 in the physical memory of the first GPU as the fourth physical page.

[0238] After rebuilding the second GPU physical memory corresponding to the first application, the GPU may fill each first content into the second physical page at the corresponding position in the second GPU physical memory according to the storage position of each first content in the first GPU physical memory. For example, when the second GPU physical memory may include the second physical page C1, the second physical page C2, the second physical page C3 and the second physical page C4 in sequence, the GPU may fill the first content A1 into the second physical page C1, fill the first content A2 into the second physical page C2, fill the first content A3 into the second physical page C3, and fill the first content A4 into the second physical page C4.

[0239] Subsequently, the GPU may establish a mapping relationship between the virtual page and the second physical page according to the sequential mapping 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 the second physical page C1, virtual page B2 mapped to the second physical page C2, virtual page B3 mapped to the second physical page C3, and virtual page B4 mapped to the second physical page C4.

[0240] The following is a detailed description of the process of rebuilding GPU physical memory by electronic devices.

[0241] See also Figure 8 , Figure 8 FIG. 1 is a flow chart of rebuilding GPU physical memory provided by an embodiment of the present application. The flow chart is illustrated by taking the electronic device detecting the state of the first application through the AMS as an example. Figure 8 As shown, the process of rebuilding GPU physical memory may include:

[0242] S801. When detecting that the first application is switched to the foreground state, the AMS notifies the GPU that the first application returns to the foreground.

[0243] When the first application switches to the background state, the AMS can continue to monitor the state of the first application. When detecting that the first application switches from the background state to the foreground state, the AMS can determine that the first application currently needs to use the GPU physical memory, that is, it can be determined that the GPU physical memory corresponding to the first application needs to be rebuilt. At this time, the AMS can notify the GPU that the first application returns to the foreground and the GPU physical memory corresponding to the first application needs to be rebuilt.

[0244] For example, the AMS may send the second information to the GPU through an ioctl interface. The second information may be used to notify the GPU that the first application is back to the foreground and that the GPU physical memory corresponding to the first application needs to be rebuilt.

[0245] S802: The GPU determines a virtual address space corresponding to the first application.

[0246] It should be understood that the specific content of the GPU determining the virtual address space corresponding to the first application can refer to the relevant description in the aforementioned S702, GPU determining the virtual address space corresponding to the first application, which will not be repeated here.

[0247] S803: The 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 according to 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 the 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 according to the memory size occupied by the first content.

[0249] In other embodiments, when reconstructing the second GPU physical memory corresponding to the first application, the GPU can read the first content corresponding to the first application saved in the disk, and can determine the memory size occupied by the first content, so as to determine the size of the second GPU physical memory according to the memory size occupied by the first content.

[0250] For example, the GPU may 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 may 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 may record the size of the first GPU physical memory, and may determine the size of the second GPU physical memory based on the size of the first GPU physical memory. For example, it may be determined that the size of the second GPU physical memory is the same as the size of the first GPU physical memory. For example, it may 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., the second physical page). The number of second physical pages included in the second GPU physical memory may be determined according to the size of the second GPU physical memory and the size of the second physical page. The size of the second physical page may be the same as the size of the first physical page. For example, the size of the second physical page may be 4KB, and the size of the second GPU physical memory may be an integer multiple of 4KB.

[0254] S804: The GPU obtains the first content from the disk.

[0255] S805: The GPU fills the first content into a second physical page in the physical memory of the second GPU.

[0256] S806: The GPU establishes a mapping relationship between the second physical page and the virtual page corresponding to the virtual address.

[0257] In the embodiment of the present application, after allocating the second GPU physical memory for the first application, the GPU can obtain the previously saved first content from the disk, that is, can obtain the first content corresponding to each first physical page. Subsequently, the GPU can fill the second physical page 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 page and the virtual page corresponding to the first application, that is, re-establish the GPU page table corresponding to the first application, so that the first application can accurately access the GPU physical memory according to the re-established GPU page table and the virtual address corresponding to the first application, so that the first application can be used normally, that is, the first application can display the image correctly.

[0258] In a possible implementation, when the first content stored in each first physical page is saved to the disk, the GPU can record the corresponding relationship B 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 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 can fill each first content into the second physical page in the second GPU physical memory. Subsequently, the GPU can establish a mapping relationship between the virtual page and the second physical page according to the first content filled in each second physical page and the corresponding relationship B between the first content and the virtual page, so as to re-establish the GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application can be mapped to the correct physical page according to the re-established GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, so that the first application can be used normally, that is, the first application can display the image correctly.

[0259] In another possible implementation, the mapping relationship between the virtual page and the physical page corresponding to the first application may be a sequential mapping, that is, the first virtual page may be mapped to the first physical page, the second virtual page may be mapped to the second physical page, and the third virtual page may be mapped to the third physical page, etc. When the first content stored in each first physical page is saved to the disk, the GPU may record the storage position of each first content in the physical memory of the first GPU, that is, record the physical page number of each first content in the physical memory of the first GPU. Therefore, after rebuilding the second GPU physical memory corresponding to the first application, the GPU may fill each first content into the second physical page at the corresponding position in the physical memory of the second GPU according to the storage position of each first content in the physical memory of the first GPU. Subsequently, the GPU may establish a mapping relationship between the virtual page and the second physical page according to the sequential mapping to re-establish the GPU page table corresponding to the first application, so that when the first application switches to the foreground state, the virtual address of the first application may be mapped to the correct physical page according to the re-established GPU page table without modifying the virtual address of the first application, so that the first application can normally access the GPU physical memory, thereby enabling the first application to be used normally, that is, enabling the first application to display the image correctly.

[0260] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0261] Corresponding to the memory management method described in the above embodiment, the embodiment of the present application also provides a memory management device, and each module of the device can correspond to each step of the memory management method.

[0262] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0263] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by 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 embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0264] The present 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, wherein the processor may include a GPU, and when the processor executes the computer program, the electronic device implements the steps in any of the above-mentioned memory management method embodiments. Exemplarily, the structure of the electronic device may be as follows: Figure 2 shown.

[0265] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a computer, the computer implements the steps in any of the above-mentioned memory management method embodiments.

[0266] An embodiment of the present application provides a computer program product. When the computer program product is executed on an electronic device, the electronic device implements the steps in any of the above-mentioned memory management method embodiments.

[0267] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include at least: any entity or device that can carry the computer program code to the device / electronic device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.

[0268] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0269] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example 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 performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0270] In the embodiments provided in the present 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 schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0271] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0272] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A GPU memory management method, applied to electronic equipment, characterized in that: The method comprises: When it is detected that the first application is switched to the background state, saving the first content stored in the first GPU physical memory corresponding to the first application to the disk; Release the physical memory of the first GPU; The releasing of the first GPU physical memory includes: Release a first physical page of the first GPU physical memory; A first mapping relationship between the first physical page and a first virtual page corresponding to the first application is deleted.

2. The method according to claim 1, characterized in that: When detecting that the first application is switched to the background state, saving the first content stored in the first GPU physical memory corresponding to the first application to the disk includes: When it is detected that the first application is switched to the background state and the first application does not perform graphics rendering, the first content stored in the physical memory of the first GPU 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 comprises: When it is detected that the first application is switched 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 comprises: A second mapping relationship between the first virtual page and a second physical page of the second GPU physical memory is established.

5. The method according to claim 4, characterized in that: The establishing a second mapping relationship between the first virtual page and the second physical page includes: determining the first virtual page according to a third mapping relationship, where the third mapping relationship is a correspondence relationship between the first content and the first virtual page; A second mapping relationship between the first virtual page and the second physical page is established.

6. The method according to claim 2, characterized in that The first GPU physical memory includes a texture memory of the first application or a 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, and the first mapping relationship is stored in the first GPU page table.

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 a virtual address space corresponding to the first application; The first GPU physical memory is determined according to the virtual address space.

10. The method according to claim 9, characterized in that The determining the first GPU physical memory according to the virtual address space includes: The first physical page is determined according to 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 physical memory of the first GPU to a disk includes: The first content stored in the physical memory of the first GPU is saved to a disk, and the third mapping relationship between the first content and the first virtual page is recorded.

12. The method according to claim 4 or 5, characterized in that: After reallocating the second GPU physical memory for the first application, the method further includes: The first content is obtained from the disk, and the first content is filled into the second GPU physical memory.

13. The method according to claim 12, characterized in that The acquiring the first content from the disk and filling the first content into the second GPU physical memory includes: The first content is obtained from the disk, and the first content is filled 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, wherein: When the processor executes the computer program, the electronic device implements the GPU memory management method according to 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 a computer, the computer is enabled to implement the GPU memory management method according to any one of claims 1 to 13.

Citation Information

Patent Citations

  • Method and apparatus for compressing and decompressing memory occupied by processor

    CN110023906A

  • GPU time-sharing method and system based on drive packaging

    CN112506666A

  • Memory processing method and device, electronic equipment and storage medium

    CN116661697A

  • Memory management method and electronic equipment

    CN117519959A

  • Memory recovery method, electronic equipment and storage medium

    CN117742929A