Memory management method, apparatus and electronic device

By constructing an application-specific zspage linked list, application-based memory management is achieved, solving the problem of low efficiency in page table lookup and data migration in existing technologies, and improving memory and system performance.

CN122431599APending Publication Date: 2026-07-21VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
VIVO MOBILE COMM CO LTD
Filing Date
2026-04-15
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

In existing technologies, page-based memory management leads to complex page table lookups and frequent data migrations, which affect memory utilization efficiency and system performance.

Method used

We adopt an application-based memory management approach. By building an application-specific zspage linked list, compressed memory data is copied and swapped in units of pages, reducing page table traversal and page-by-page access.

Benefits of technology

It improves data migration efficiency, memory utilization, and system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122431599A_ABST
    Figure CN122431599A_ABST
Patent Text Reader

Abstract

The application discloses a memory management method, device and electronic equipment, and belongs to the technical field of storage. The memory management method comprises the following steps: in the case that a first application program is switched from foreground running to background running, performing compression processing on memory data of the first application program to obtain compressed memory data; and storing the compressed memory data in a zspage linked list corresponding to the first application program; wherein, in at least one application program of a first type running in the background of the electronic equipment, one application program corresponds to a group of zspage linked lists; and the first type comprises a program type of the first application program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of storage technology, specifically to a memory management method, apparatus, and electronic device. Background Technology

[0002] In related technologies, Zram compression and swap mechanisms are commonly used for memory management. This involves compressing physical memory in pages and storing it in a ZSPOOL. However, because the physical addresses of compressed memory objects are scattered within the ZSPOOL, when data needs to be written to the physical disk, the system must traverse the page table item by item to locate the physical address of each compressed object and reassemble them into complete pages through multiple memory copy operations before swapping can be performed. This page-based processing method involves complex page table lookups and management operations, as well as frequent data migrations, resulting in low overall processing efficiency and severely impacting memory utilization and system performance. Summary of the Invention

[0003] This application provides a memory management method, apparatus, and electronic device. When memory needs to be compressed and swapped, the compressed memory of the entire application can be directly copied in units of pages and swapped in, swapped out, or released together. This can reduce page table traversal and page-by-page access overhead, thereby improving the efficiency of data migration and ultimately improving memory utilization efficiency and system performance.

[0004] Firstly, a memory management method is provided for use in an electronic device, the method comprising:

[0005] When the first application switches from running in the foreground to running in the background, the memory data of the first application is compressed to obtain compressed memory data.

[0006] The compressed memory data is stored in the zspage linked list corresponding to the first application; wherein, in at least one application of the first type running in the background of the electronic device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

[0007] In this implementation, since each of the first type of applications running in the background of the electronic device corresponds to a set of zspage linked lists, when the first application switches from foreground to background operation, the memory data of the first application is compressed to obtain compressed memory data, and the compressed memory data is stored in the zspage linked list corresponding to the first application. This memory management method, by constructing an application-specific zspage linked list, allows the entire application's compressed memory to be copied directly in pages and swapped in, swapped out, or released together when memory compression and swapping are required. This reduces page table traversal and page-by-page access overhead, thereby improving data migration efficiency and ultimately enhancing memory utilization and system performance.

[0008] Optionally, the zspage linked list includes multiple linked list management structures, and the multiple linked list management structures correspond one-to-one with multiple different memory ranges of storage objects;

[0009] The step of storing the compressed memory data in the zspage linked list corresponding to the first application includes:

[0010] Based on the size of the compressed memory data, a first linked list management structure is determined among the plurality of linked list management structures, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure;

[0011] The compressed memory data is stored in the first linked list management structure.

[0012] In this embodiment, the zspage linked list includes multiple linked list management structures, each corresponding one-to-one with a different memory range of a storage object. Based on the size of the compressed memory data, a first linked list management structure is determined among the multiple linked list management structures, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure. The compressed memory data is stored in the first linked list management structure. Thus, since compressed page data of different sizes can be stored in linked list management structures of corresponding sizes, the space utilization of the zspage linked list is improved. That is, the same group of zspage linked lists can maintain more memory data, which is beneficial to improving memory utilization.

[0013] Optionally, after storing the compressed memory data in the first linked list management structure, the method further includes:

[0014] If the remaining system memory of the electronic device is less than a first threshold, the compressed memory data is migrated from the first linked list management structure to the physical disk of the electronic device, and the first mapping relationship information is stored in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

[0015] In this embodiment, when the remaining system memory of the electronic device is less than a first threshold, i.e. when the system memory of the electronic device is insufficient, the compressed memory data is migrated from the first linked list management structure to the physical disk of the electronic device, and the first mapping relationship information is stored in the pointer of the context structure of the first application. In this way, the memory space occupied by the first application can be reduced, thereby increasing the remaining memory of the electronic device.

[0016] Optionally, after migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device, the method further includes:

[0017] When all processes of the first application exit, the memory occupied by the compressed memory data is released in units of zspage, the first linked list management structure is initialized, the first mapping relationship information is cleared, and the physical disk space occupied by the compressed memory data is released.

[0018] In this embodiment, by releasing the memory occupied by the compressed memory data in units of zspages after all processes of the first application have exited, initializing the first linked list management structure, clearing the first mapping relationship information, and releasing the physical disk space occupied by the compressed memory data, the memory management method provided in this application embodiment can improve the efficiency of memory release compared to the related technology that requires traversing the page table and then releasing each compressed fragmented object (object, obj) one by one.

[0019] Optionally, after migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device, the method further includes:

[0020] When the first application switches from running in the background to running in the foreground, the compressed memory data is migrated from the physical disk to the first linked list management structure according to the first mapping relationship information;

[0021] The compressed memory data in the first linked list management structure is decompressed.

[0022] In this embodiment, when the first application switches from background to foreground operation, the compressed memory data is migrated from the physical disk to the first linked list management structure according to the first mapping relationship information; the compressed memory data in the first linked list management structure is decompressed. Thus, since the swap-in process can be directly copied in units of pages and swapped in together, it is beneficial to reduce the consumption of page table traversal and page-by-page access. Moreover, when swapping out, large blocks of 64KB or larger can be swapped to improve storage performance, efficiently reclaim all GPU memory of the background application, and increase the available memory of the system.

[0023] Optionally, storing the compressed memory data in the zspage linked list corresponding to the first application includes:

[0024] If the compression process is performed for the first time on the memory data of the first application after the electronic device is powered on, a zspage linked list corresponding to the first application is created, and the compressed memory data is stored in the zspage linked list corresponding to the first application; or,

[0025] When the compression process is performed on the memory data of the first application for the Nth time after the electronic device is powered on, and N is an integer greater than 1, the compressed memory data is stored in the zspage linked list corresponding to the first application.

[0026] Optionally, the first type includes at least one of the following: GPU type; system type; direct memory access (DMA) type.

[0027] In this embodiment, by including at least one of the following in the first type: GPU type; system type; DMA type, the utilization efficiency of GPU memory, system memory, and / or DMA memory can be improved, thereby enhancing the system performance of the electronic device.

[0028] In this embodiment, when the compression process is performed on the memory data of the first application for the first time after the electronic device is powered on, a zspage linked list corresponding to the first application is created, and the compressed memory data is stored in the zspage linked list corresponding to the first application; or, when the compression process is performed on the memory data of the first application for the Nth time after the electronic device is powered on, and N is an integer greater than 1, the compressed memory data is stored in the zspage linked list corresponding to the first application. In this way, it can be ensured that each first type of application running in the background has a corresponding zspage linked list.

[0029] In a second aspect, a memory management device is provided for use in an electronic device, the device comprising:

[0030] The compression module is used to compress the memory data of the first application when the first application switches from running in the foreground to running in the background, so as to obtain compressed memory data.

[0031] A storage module is used to store the compressed memory data in a zspage linked list corresponding to the first application; wherein, in at least one application of a first type running in the background of the memory management device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

[0032] Optionally, the zspage linked list includes multiple linked list management structures, and the multiple linked list management structures correspond one-to-one with multiple different memory ranges of storage objects;

[0033] The storage module includes:

[0034] A determining submodule is used to determine a first linked list management structure among the plurality of linked list management structures based on the size of the compressed memory data, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure;

[0035] The storage submodule is used to store the compressed memory data in the first linked list management structure.

[0036] Optionally, the device further includes:

[0037] The migration module is configured to migrate the compressed memory data from the first linked list management structure to the physical disk of the memory management device when the remaining system memory size of the memory management device is less than a first threshold, and store first mapping relationship information in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

[0038] Optionally, the device further includes:

[0039] The release module is used to release the memory occupied by the compressed memory data in units of zspages when all processes of the first application exit, initialize the first linked list management structure, clear the first mapping relationship information, and release the physical disk space occupied by the compressed memory data.

[0040] Optionally, the migration module is further configured to migrate the compressed memory data from the physical disk to the first linked list management structure according to the first mapping relationship information when the first application switches from background to foreground operation;

[0041] The device further includes:

[0042] The decompression module is used to decompress the compressed memory data in the first linked list management structure.

[0043] Optionally, the storage module is specifically configured to, when the compression process is performed for the first time on the memory data of the first application after the memory management device is powered on, create a zspage linked list corresponding to the first application and store the compressed memory data in the zspage linked list corresponding to the first application; or,

[0044] The storage module is specifically used to store the compressed memory data in the zspage linked list corresponding to the first application when the compression process is the Nth time the memory management device is powered on and N is an integer greater than 1.

[0045] Optionally, the first type includes at least one of the following: GPU type; system type; DMA type.

[0046] Thirdly, an electronic device is provided, comprising a processor and a memory, wherein the memory stores a program or instructions executable on the processor, the program or instructions, when executed by the processor, perform the steps of the method described in the first aspect.

[0047] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.

[0048] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the steps of the method described in the first aspect.

[0049] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the steps of the method described in the first aspect.

[0050] In this embodiment, since each background application of the electronic device corresponds to a set of zspage linked lists, when the first application switches from foreground to background operation, the memory data of the first application is compressed to obtain compressed memory data, and the compressed memory data is stored in the zspage linked list corresponding to the first application. This memory management method, by constructing an application-specific zspage linked list, allows the entire compressed memory of the application to be copied directly in pages and swapped in, swapped out, or released together when memory compression and swapping are required. This reduces page table traversal and page-by-page access overhead, thereby improving data migration efficiency and ultimately enhancing GPU memory utilization and system performance. Attached Figure Description

[0051] Figure 1 This is a flowchart illustrating a memory management method provided in some embodiments of this application;

[0052] Figure 2 This is a flowchart illustrating a memory management method provided in some embodiments of this application;

[0053] Figure 3 This is a flowchart illustrating a memory management method provided in some embodiments of this application;

[0054] Figure 4 These are schematic diagrams of the memory management device in some embodiments of this application;

[0055] Figure 5 Schematic diagrams of the structure of electronic devices provided for some embodiments of this application;

[0056] Figure 6 A schematic diagram of the hardware structure of an electronic device provided for some embodiments of this application. Detailed Implementation

[0057] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0058] The terms "first," "second," etc., used in this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first" and "second" are generally of the same class, not limited in number; for example, the first object can be one or more. Furthermore, "or" in this application indicates at least one of the connected objects. For example, the scope of protection for "A or B" covers at least three scenarios: Scenario 1: including A but not B; Scenario 2: including B but not A; Scenario 3: including both A and B. In addition, the terms "A and / or B," "at least one of A and B," and "at least one of A or B" also cover at least the above three scenarios. The character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0059] The memory management method, apparatus, and electronic device provided in this application will be described in detail below with reference to the accompanying drawings and through some embodiments and application scenarios.

[0060] Please see Figure 1 , Figure 1 This is a flowchart illustrating a memory management method provided in an embodiment of this application. The memory management method is applied to an electronic device and includes the following steps:

[0061] Step 101: When the first application switches from running in the foreground to running in the background, the memory data of the first application is compressed to obtain compressed memory data.

[0062] The first application mentioned above can be of various types, such as a Graphics Processing Unit (GPU) application, a system application, etc. Correspondingly, the memory management method described above can be used to manage the GPU memory of the application, and can also be used to manage the application's dmabuff memory and / or system management memory. For ease of understanding, this application embodiment takes the first application as a GPU application and the memory data as GPU memory data as an example to further explain the memory management method. The first application can be of various types of GPU applications, such as video playback applications, three-dimensional (3D) game applications, virtual reality (VR) applications, augmented reality (AR) applications, etc.

[0063] The scenarios in which the first application switches from running in the foreground to running in the background can include various scenarios. For example, scenarios in which the first application switches from running in the foreground to running in the background can include: when the user finishes using the first application, they do not swipe up to delete the first application, but instead return directly to the desktop of the electronic device; or, when the user finishes using the first application, they do not swipe up to delete the first application, but instead open other applications, etc.

[0064] Understandably, when the first application is switched to the background and is inactive, the compression function can be triggered to compress the memory data of the first application.

[0065] The compression of the memory data of the first application may include compressing all discrete memory data of the first application.

[0066] Step 102: Store the compressed memory data in the zspage linked list corresponding to the first application; wherein, in at least one application of the first type running in the background of the electronic device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

[0067] The first type can be configured as needed. For example, the first type may include at least one of the following: GPU type; system type; DMA type. When the first type includes a GPU type, the memory management method can be used to manage the GPU memory of the electronic device, wherein the GPU memory is GPU display-related memory. When the first type includes a system type, the memory management method can be used to manage the system memory of the electronic device, wherein the system memory includes general anonymous memory and file memory. When the first type includes a DMA type, the memory management method can be used to manage the DMA memory of the electronic device, wherein the DMA memory is shared memory among different devices, and different devices can directly access the DMA memory without going through the GPU after mapping.

[0068] In some embodiments of this application, the first type may be a GPU type. In this case, the first type including the program type of the first application may mean that the program type of the first application is a GPU type.

[0069] In some embodiments of this application, the first type may also include a GPU type and a system type. In this case, the first type including the program type of the first application may mean that the program type of the first application is a GPU type or a system type.

[0070] In some embodiments of this application, the first type may also include a system type. In this case, the first type including the program type of the first application may mean that the program type of the first application is a system type.

[0071] In some embodiments of this application, the first type may also include GPU type, system type, and DMA type. In this case, the first type including the program type of the first application may mean that the program type of the first application is GPU type, system type, or DMA type.

[0072] In some embodiments of this application, the first type may also include GPU type and DMA type. In this case, the first type including the program type of the first application may mean that the program type of the first application is GPU type or DMA type.

[0073] In some embodiments of this application, the first type may also include a system type and a DMA type. In this case, the first type including the program type of the first application may mean that the program type of the first application is a system type or a DMA type.

[0074] In some embodiments of this application, the first type may also include a DMA type. In this case, the first type including the program type of the first application may mean that the program type of the first application is a DMA type.

[0075] It should be noted that when the first application is a DMA type application, the first application can refer to an application that uses the DMA mechanism for data transfer.

[0076] For ease of understanding, this application embodiment takes the first type as an example that only includes the GPU type, and further explains the memory management method.

[0077] It is understandable that electronic devices can have various types of GPU applications installed, and that more than one GPU application may be running simultaneously in the background while the user is using the device. The aforementioned "one application corresponding to one set of zspage linked lists" means that the electronic device can create a dedicated zspage linked list for each GPU application running in the background. For example, please see... Figure 2In some embodiments of this application, GPU application A and GPU application B are two different GPU applications running in the background of an electronic device, ZSPAGELIST_B is a zspage linked list corresponding to GPU application A; ZSPAGELIST_C is a zspage linked list corresponding to GPU application B.

[0078] In some embodiments of this application, the aforementioned set of zspage linked lists may consist of multiple linked lists of different sizes.

[0079] In this implementation, since each background application in the electronic device corresponds to a set of zspage linked lists, when the first application switches from foreground to background operation, the memory data of the first application is compressed to obtain compressed memory data, which is then stored in the zspage linked list corresponding to the first application. This memory management method, by constructing application-specific zspage linked lists, allows the entire application's compressed memory to be copied directly page-by-page and swapped in, swapped out, or released together when memory compression and swapping are required. This reduces page table traversal and page-by-page access overhead, thereby improving data migration efficiency and ultimately enhancing GPU memory utilization and system performance.

[0080] Optionally, the zspage linked list includes multiple linked list management structures, and the multiple linked list management structures correspond one-to-one with multiple different memory ranges of storage objects;

[0081] The step of storing the compressed memory data in the zspage linked list corresponding to the first application includes:

[0082] Based on the size of the compressed memory data, a first linked list management structure is determined among the plurality of linked list management structures, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure;

[0083] The compressed memory data is stored in the first linked list management structure.

[0084] In some embodiments of this application, when the first application is a GPU application, the memory data is GPU memory data. GPU memory data is typically stored in the form of pages, where a page is typically 4KB in size. Therefore, the compressed page size after compressing a page ranges from 1 byte to 4096 bytes. Based on this, 1 byte to 4096 bytes can be converted into multiple storage object memory ranges, thus obtaining multiple different storage object memory ranges, each of which can be considered a tier. For example, when there are 6 tiers, the multiple different storage object memory ranges can be: 1 byte to 128 bytes, 128 bytes to 256 bytes, 256 bytes to 512 bytes, 512 bytes to 1024 bytes, 1024 bytes to 2048 bytes, and 2048 bytes to 4096 bytes. It is understood that the compressed page size range of 1 byte to 4096 bytes and the number of tiers of 6 are only an example in the embodiments of this application. In fact, when the page size changes, the compressed page size range can also change accordingly, and the number of tiers can be set as needed. For example, in some embodiments of this application, the number of slots can also be three. In this case, the memory range of the multiple different storage objects can be: 1 byte to 256 bytes, 256 bytes to 1024 bytes, or 1024 bytes to 4096 bytes. For ease of understanding, this application embodiment takes a compressed page size range of 1 byte to 4096 bytes and a number of slots of 6 as an example to further explain the internal management method provided by this application embodiment.

[0085] It is understandable that the number of linked list management structures included in the zspage linked list is the same as the number of slots mentioned above. Each slot corresponds to one linked list management structure. That is, when the number of slots is 6, the number of linked list management structures included in the zspage linked list is 6.

[0086] In some embodiments of this application, when the size of a page in GPU memory data is 255 bytes after compression, the compressed page will be stored in a linked list management structure corresponding to the 128-byte to 256-byte range.

[0087] In some embodiments of this application, the pointer to the linked list management structure can be stored in the GPU context structure of the GPU application to establish a connection. The location of the compressed object in the GPU mapping (MAP) is recorded. This location includes the index of the zspage linked list in all linked lists of the application and the object index of the compressed object in the linked list. In some embodiments of this application, the linked list indexes for bytes 1-128 can be set to 0, 128-256 bytes to 1, 256-512 bytes to 2, 512-1024 bytes to 3, 1024-2048 bytes to 4, and 2048-4096 bytes to 5. The object index of the first compressed object stored in a linked list is 0, the object index of the second compressed object stored in a linked list is 1, and the object indices of subsequent compressed objects are incremented sequentially. For example, the compressed object size of the first page of the first application is 255K. After hash calculation, this compressed object size is suitable for a linked list corresponding to the 128-byte to 256-byte range, with a linked list index of 1. The management structure of this linked list is located in the GPU context of the first application, and the address of the next free object in the linked list is found. Since there is currently one page in the linked list that does not contain any compressed objects, the address of the next free object is the starting address of the unique page in the linked list. The compressed memory is copied into this list, and the linked list index 1 and object index 0 are combined to form 0x00010000, which is stored in the page table corresponding to the original page in the GPU. The value of the next free object is updated to the address offset 256K from the page's starting address. After this storage is completed, if the current page has no available space after storing 16 objects, a new page needs to be allocated, the pages linked, the number of pages managed by the linked list updated, and the address of the next free object updated.

[0088] In some embodiments of this application, the linked list management structure stores the physical page frame number (pfn) and total page count of the starting page of each linked list; pages in the same linked list are linked together unidirectionally using a linked list structure. Finally, the GPU memory compressed size of the entire application is calculated.

[0089] In this embodiment, the zspage linked list includes multiple linked list management structures, each corresponding one-to-one with a different memory range of a storage object. Based on the size of the compressed memory data, a first linked list management structure is determined among the multiple linked list management structures, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure. The compressed memory data is stored in the first linked list management structure. Thus, since compressed pages of different sizes can be stored in linked list management structures of corresponding sizes, the space utilization of the zspage linked list is improved. That is, the same group of zspage linked lists can maintain more memory data, which is beneficial to improving memory utilization.

[0090] Optionally, after storing the compressed memory data in the first linked list management structure, the method further includes:

[0091] If the remaining system memory of the electronic device is less than a first threshold, the compressed memory data is migrated from the first linked list management structure to the physical disk of the electronic device, and the first mapping relationship information is stored in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

[0092] The size of the first threshold can be set according to the total memory of the system. For example, in some embodiments of this application, the size of the first threshold can be 20% of the total memory of the system, or in some embodiments of this application, the size of the first threshold can be 30% of the total memory of the system. The specific value can be set as needed.

[0093] In some embodiments of this application, the process of migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device and storing the first mapping relationship information in the pointer of the context structure of the first application may include the following steps:

[0094] Create virtual disk space in units of 64K based on the size of the compressed memory data.

[0095] Please see Figure 2The process involves directly copying consecutive pages from the zspage linked list of the GPU memory of the first application to the virtual disk space. The zspage linked list stores compressed objects from the GPU memory, which are the compressed memory data mentioned above. Each virtual disk space starts at address 0. After copying the data to the virtual disk space in the order of the linked list, the starting offset of each linked list is recorded and saved in the linked list head structure. For example, if linked list indices 0-5 use 50, 200, 120, 200, 100, and 20 pages respectively, then the starting virtual space offsets of each linked list are 0K, 50×4K, (50+200)×4K, (50+200+120)×4K… and the last one is (50+200+120+200+100)×4K. During the migration of the compressed memory data from the zspage linked list to the virtual disk space, a marker can be added to the first application to indicate that its GPU memory is temporarily inaccessible.

[0096] The system swaps all contents of the virtual disk to the physical disk in 64K or larger I / O units and records the mapping relationship between the virtual disk and the physical disk, i.e., the first mapping relationship mentioned above. For example, if the virtual space is actually stored in two segments on the physical disk, the system saves four values, including the starting sector number and length of the two physical disk segments, in a pointer to the GPU context structure in a dictionary-like structure, and then exits.

[0097] In this embodiment, when the remaining system memory of the electronic device is less than a first threshold, i.e. when the system memory of the electronic device is insufficient, the compressed memory data is migrated from the first linked list management structure to the physical disk of the electronic device, and the first mapping relationship information is stored in the pointer of the context structure of the first application. In this way, the memory space occupied by the first application can be reduced, thereby increasing the remaining memory of the electronic device.

[0098] Optionally, after migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device, the method further includes:

[0099] When all processes of the first application exit, the memory occupied by the compressed memory data is released in units of zspage, the first linked list management structure is initialized, the first mapping relationship information is cleared, and the physical disk space occupied by the compressed memory data is released.

[0100] The "exit of all processes of the first application" can refer to the first application exiting or stopping operation under various scenarios, or it can be described as the first application being closed. For example, the "exit of all processes of the first application" could mean that the user actively closes the first application. Alternatively, the "exit of all processes of the first application" could also mean that the first application is closed based on a pre-configured policy in the electronic device. For example, the pre-configured policy in the electronic device could include closing the first application running in the background when the memory level falls below a certain threshold.

[0101] It is understandable that when all processes of the first application exit, the memory of the first application needs to be released. Based on this, in this embodiment of the application, when all processes of the first application exit and no longer need this part of the memory, the memory occupied by the compressed object can be released directly in units of zspage by traversing each linked list, the management structure of each linked list can be initialized for the next use, the disk mapping relationship can be cleared, and the occupied physical disk space can be released.

[0102] In this embodiment, by releasing the memory occupied by the compressed memory data in units of zspages after all processes of the first application have exited, initializing the first linked list management structure, clearing the first mapping relationship information, and releasing the physical disk space occupied by the compressed memory data, the memory management method provided in this application embodiment can improve the efficiency of memory release compared to the related technology that requires traversing the page table and then releasing each compressed and scattered obj one by one.

[0103] Optionally, after migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device, the method further includes:

[0104] When the first application switches from running in the background to running in the foreground, the compressed memory data is migrated from the physical disk to the first linked list management structure according to the first mapping relationship information;

[0105] The compressed memory data in the first linked list management structure is decompressed.

[0106] The scenario where the first application switches from background to foreground execution can include various other scenarios. For example, a user might re-click the application icon of the first application from the desktop of an electronic device to access the first application. Another example is a user might access all background applications and then click on the first application to enter it. It is understood that when the first application switches to the foreground, it changes from an inactive state to an active state, requiring the previously compressed memory to be decompressed.

[0107] In some embodiments of this application, the above-mentioned migration of the compressed memory data from the physical disk to the first linked list management structure according to the first mapping relationship information may include the following steps: according to the total number of pages occupied by the compressed memory data in the zspage linked list, apply for the corresponding pages, re-establish each zspage linked list, and then read the compressed memory data back from the physical disk according to the first mapping relationship, and copy it back to the zspage linked list according to the initial offset of each linked list.

[0108] After the compressed memory data in the first linked list management structure is decompressed, the decompressed memory can be accessed directly.

[0109] In this embodiment, when the first application switches from background to foreground operation, the compressed memory data is migrated from the physical disk to the first linked list management structure according to the first mapping relationship information; the compressed memory data in the first linked list management structure is decompressed. Thus, since the swap-in process can be directly copied in units of pages and swapped in together, it is beneficial to reduce the consumption of page table traversal and page-by-page access. Moreover, when swapping out, large blocks of 64K or larger can be swapped to improve storage performance, efficiently reclaim all GPU memory of the background application, and increase the available memory of the system.

[0110] Optionally, storing the compressed memory data in the zspage linked list corresponding to the first application includes:

[0111] If the compression process is performed for the first time on the memory data of the first application after the electronic device is powered on, a zspage linked list corresponding to the first application is created, and the compressed memory data is stored in the zspage linked list corresponding to the first application; or,

[0112] When the compression process is performed on the memory data of the first application for the Nth time after the electronic device is powered on, and N is an integer greater than 1, the compressed memory data is stored in the zspage linked list corresponding to the first application.

[0113] In some embodiments of this application, if the first application is not being compressed for the first time since booting, the creation of the zspage linked list corresponding to the first application is skipped, and the step of storing the compressed memory data in the zspage linked list corresponding to the first application is directly executed. If it is the first time the memory of the first application is compressed after booting, a set of zspage linked lists dedicated to the first application is created. The creation process may include the following steps: Since the size of the compressed page ranges from 1 byte to 4096 bytes, the 1 byte to 4096 bytes is divided into a series of levels, for example, 128 bytes, 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, and 4096 bytes, a total of 6 levels. Each level corresponds to a compressed size to store objects of suitable compressed size. In some embodiments of this application, if the compressed size of a page is 255 bytes, the page will be placed in the linked list corresponding to the 256-byte level. Each slot allocates and constructs a linked list management structure. The structure members store the slot size, the number of pages managed, and the linked list containing the compressed memory. The initial length of the linked list is one page. When the existing pages in the linked list are exhausted, pages can be dynamically allocated and linked to the next free object. The structure uses a pointer or address value to point to the address of the next free object. The structure has reserved fields to store information about subsequent swapping out.

[0114] In this embodiment, when the compression process is performed on the memory data of the first application for the first time after the electronic device is powered on, a zspage linked list corresponding to the first application is created, and the compressed memory data is stored in the zspage linked list corresponding to the first application; or, when the compression process is performed on the memory data of the first application for the Nth time after the electronic device is powered on, and N is an integer greater than 1, the compressed memory data is stored in the zspage linked list corresponding to the first application. In this way, it can be ensured that each first type of application running in the background has a corresponding zspage linked list.

[0115] Optionally, the first type includes at least one of the following: GPU type; system type; DMA type.

[0116] In this embodiment, by including at least one of the following in the first type: GPU type; system type; DMA type, the utilization efficiency of GPU memory, system memory, and / or DMA memory can be improved, thereby enhancing the system performance of the electronic device.

[0117] Please see Figure 3 , Figure 3 This application provides a flowchart illustrating a memory management method according to some embodiments, the memory management method comprising the following steps:

[0118] Step 301: When the first application switches from running in the foreground to running in the background, the memory data of the first application is compressed to obtain compressed memory data. The scenario in which the first application switches from running in the foreground to running in the background can be that the user switches back to the desktop from the application interface of the first application or opens a new chat, game or other APP. At this time, the first application is in an inactive state. The first application can be a GPU application.

[0119] Step 302: Determine whether the compression process is the first time the memory data of the first application is compressed after the electronic device is powered on. If yes, proceed to step 303; otherwise, skip step 303 and proceed to step 304.

[0120] Step 303: Create the zspage linked list corresponding to the first application. The creation process of the zspage linked list may include: Since the size of the compressed page ranges from 1 byte to 4096 bytes, it can be divided into a series of slots, for example, 128 bytes, 256 bytes, 512 bytes, 1024 bytes, 2048 bytes, and 4096 bytes, for a total of 6 slots. Each slot corresponds to a compressed size to store objects of suitable compressed size. In some embodiments of this application, if the compressed size of a page is 255 bytes, the page will be placed in the linked list corresponding to the 256-byte slot. Each slot requests and constructs a linked list management structure. The structure members store the slot size of this linked list, the number of pages managed, and the linked list storing the compressed memory. The initial length of the linked list is 1 page. When the existing pages in the linked list are used up, pages can be dynamically requested to extend the linked list to the next free object. The structure uses a pointer or address value to point to the address of the next free object. The structure contains reserved fields to store information for subsequent swapping.

[0121] Step 304: Store the compressed memory data in the zspage linked list corresponding to the first application. The compressed memory data may include compressed data from all discrete GPU memory locations of the first application. The compressed memory can be saved to a created linked list management structure according to its size, and a pointer to the linked list management structure is stored in the GPU context structure of the target application to establish a connection. Record the position of the compressed object mapped by the GPU MAP, where the position includes the index of the zspage linked list in all linked lists within the application and the object index of the compressed object within the linked list. In some embodiments of this application, the linked list index of 1 byte to 128 bytes can be set to 0, the linked list index of 128 bytes to 256 bytes to 1, the linked list index of 256 bytes to 512 bytes to 2, the linked list index of 512 bytes to 1024 bytes to 3, the linked list index of 1024 bytes to 2048 bytes to 4, and the linked list index of 2048 bytes to 4096 bytes to 5. The object index of the first compressed object stored in a linked list is 0, the object index of the second compressed object stored in a linked list is 1, and the object index of the subsequently stored compressed objects increases sequentially.

[0122] Step 305: Determine whether the remaining system memory of the electronic device is less than the first threshold. If not, end the process; if yes, proceed to step 306. As the number of background applications added by the user increases, the remaining system memory will decrease. When the remaining system memory is less than the first threshold, it can be determined that the upper-layer strategy thread is experiencing memory shortage. At this time, it is necessary to increase the remaining memory level to ensure a smooth user experience for the foreground app.

[0123] Step 306: Migrate the compressed memory data from the first linked list management structure to the physical disk of the electronic device, and store the first mapping relationship information in the pointer of the context structure of the first application. Step 306 may include: creating virtual disk spaces in 64KB units based on the compressed size. Copy pages consecutively from the GPU memory zspage linked list of the first application to the virtual disk space. Each virtual disk space starts at address 0. After copying to the virtual space according to the linked list order, record the starting offset of each linked list and save it to the linked list head structure. For example, if linked list indices 0-5 use 50, 200, 120, 200, 100, and 20 pages respectively, then the starting virtual space offsets of each linked list are 0K, 50×4K, (50+200)×4K, (50+200+120)×4K… and the last one is (50+200+120+200+100)×4K. During the migration of compressed memory data from the zspage linked list to the virtual disk space, a marker can be added to the first application to indicate that its GPU memory is temporarily inaccessible. All content in the virtual disk is swapped to the physical disk in 64K or larger I / O units, and the mapping relationship between the virtual and physical disks is recorded. For example, if the virtual space is actually stored in two segments on the physical disk, the starting sector number and length of the two physical disk segments (a total of four values) are saved in a pointer to the GPU context structure in a dictionary-like structure, and then the process exits.

[0124] Step 307: When all processes of the first application exit, release the memory occupied by the compressed memory data in units of zspage, initialize the first linked list management structure, clear the first mapping relationship information, and release the physical disk space occupied by the compressed memory data. That is, when all processes of the first application exit and no longer need this memory, the memory occupied by the compressed object can be directly released in units of zspage by traversing each linked list, each linked list management structure can be initialized for future use, the disk mapping relationship can be cleared, and the occupied physical disk space can be released.

[0125] Step 308: When the first application switches from background to foreground operation, the compressed memory data is migrated from the physical disk to the first linked list management structure according to the first mapping relationship information. For example, when the user actively opens the first application to the foreground, the corresponding pages are requested according to the total number of pages occupied by the linked lists recorded in steps 302 to 304, and each zspage linked list is re-established. The compressed GPU memory is then swapped back from the physical disk according to the mapping relationship and copied back to the linked lists according to the initial offset of each linked list.

[0126] Step 309: Decompress the compressed memory data in the first linked list management structure. It can be understood that the GPU memory can be directly accessed after decompression.

[0127] In this embodiment, by constructing a dedicated zspage linked list for each GPU application, efficient and direct mapping between GPU compressed memory physical space and virtual disk space is achieved. When compression and swapping are required, the compressed memory of the entire application can be directly copied in pages and swapped in, swapped out, or released together, reducing the overhead of page table traversal and page-by-page access. Swapping in and out in large blocks of 64K or larger improves storage performance, efficiently reclaims all GPU memory from background applications, and increases available system memory. This prevents background applications from being killed due to system memory pressure, improving keep-alive capability and system smoothness.

[0128] The memory management method provided in this application can be executed by a memory management device 400. This application uses the memory management device 400 executing the memory management method as an example to illustrate the memory management device 400 provided in this application embodiment.

[0129] Please see Figure 4 , Figure 4 This is a schematic diagram of a memory management device 400 provided in an embodiment of this application. The memory management device 400 is applied to an electronic device and includes:

[0130] Compression module 401 is used to compress the memory data of the first application when the first application switches from running in the foreground to running in the background, so as to obtain compressed memory data.

[0131] Storage module 402 is used to store the compressed memory data in the zspage linked list corresponding to the first application; wherein, in at least one application of the first type running in the background of the memory management device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

[0132] Optionally, the zspage linked list includes multiple linked list management structures, and the multiple linked list management structures correspond one-to-one with multiple different memory ranges of storage objects;

[0133] The storage module 402 includes:

[0134] A determining submodule is used to determine a first linked list management structure among the plurality of linked list management structures based on the size of the compressed memory data, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure;

[0135] The storage submodule is used to store the compressed memory data in the first linked list management structure.

[0136] Optionally, the device further includes:

[0137] The migration module is configured to migrate the compressed memory data from the first linked list management structure to the physical disk of the memory management device when the remaining system memory size of the memory management device is less than a first threshold, and store first mapping relationship information in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

[0138] Optionally, the device further includes:

[0139] The release module is used to release the memory occupied by the compressed memory data in units of zspages when all processes of the first application exit, initialize the first linked list management structure, clear the first mapping relationship information, and release the physical disk space occupied by the compressed memory data.

[0140] Optionally, the migration module is further configured to migrate the compressed memory data from the physical disk to the first linked list management structure according to the first mapping relationship information when the first application switches from background to foreground operation;

[0141] The device further includes:

[0142] The decompression module is used to decompress the compressed memory data in the first linked list management structure.

[0143] Optionally, the storage module 402 is specifically configured to, when the compression process is performed for the first time on the memory data of the first application after the memory management device is powered on, create a zspage linked list corresponding to the first application and store the compressed memory data in the zspage linked list corresponding to the first application; or,

[0144] The storage module 402 is specifically used to store the compressed memory data in the zspage linked list corresponding to the first application when the compression process is the Nth time the memory data of the first application is compressed after the memory management device is powered on, and N is an integer greater than 1.

[0145] Optionally, the first type includes at least one of the following: GPU type; system type; DMA type.

[0146] In this implementation, since each background application in the electronic device corresponds to a set of zspage linked lists, when the first application switches from foreground to background operation, the memory data of the first application is compressed to obtain compressed memory data, which is then stored in the zspage linked list corresponding to the first application. This memory management method, by constructing application-specific zspage linked lists, allows the entire application's compressed memory to be copied directly page-by-page and swapped in, swapped out, or released together when memory compression and swapping are required. This reduces page table traversal and page-by-page access overhead, thereby improving data migration efficiency and ultimately enhancing GPU memory utilization and system performance.

[0147] The memory management device 400 in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the specific type of device.

[0148] The memory management device 400 in this embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this embodiment does not specifically limit its use.

[0149] The memory management device 400 provided in this application embodiment can achieve... Figure 1 The various processes implemented in the method embodiments achieve the same technical effect, and will not be described again here to avoid repetition.

[0150] In some embodiments, such as Figure 5 As shown, this application embodiment also provides an electronic device 500, including a processor 501, a memory 502, and a program or instructions stored in the memory 502 and executable on the processor 501. When the program or instructions are executed by the processor 501, they implement the various processes of the above-described memory management method embodiment and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0151] Figure 6 A schematic diagram of the hardware structure of an electronic device according to an embodiment of this application.

[0152] The electronic device 600 includes, but is not limited to, components such as: radio frequency unit 601, network module 602, audio output unit 603, input unit 604, sensor 605, display unit 606, user input unit 607, interface unit 608, memory 609, and processor 610.

[0153] The processor 610 is used to compress the memory data of the first application when the first application switches from running in the foreground to running in the background, so as to obtain compressed memory data.

[0154] The memory 609 is used to store the compressed memory data in the zspage linked list corresponding to the first application; wherein, in at least one application of the first type running in the background of the electronic device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

[0155] Optionally, the zspage linked list includes multiple linked list management structures, and the multiple linked list management structures correspond one-to-one with multiple different memory ranges of storage objects;

[0156] The processor 610 is configured to determine a first linked list management structure among the plurality of linked list management structures based on the size of the compressed memory data, wherein the size of the compressed memory data is located within the memory range of the storage object corresponding to the first linked list management structure.

[0157] The memory 609 is used to store the compressed memory data in the first linked list management structure.

[0158] Optionally, the processor 610 is configured to migrate the compressed memory data from the first linked list management structure to the physical disk of the electronic device when the remaining system memory size of the electronic device is less than a first threshold, and store first mapping relationship information in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

[0159] Optionally, the processor 610 is configured to, in the case of all processes of the first application exiting, release the memory occupied by the compressed memory data in units of zspages, initialize the first linked list management structure, clear the first mapping relationship information, and release the physical disk space occupied by the compressed memory data.

[0160] Optionally, the processor 610 is configured to migrate the compressed memory data from the physical disk to the first linked list management structure according to the first mapping relationship information when the first application switches from background to foreground operation;

[0161] The processor 610 is used to decompress the compressed memory data in the first linked list management structure.

[0162] Optionally, the memory 609 is configured to, when the compression process is performed for the first time after the electronic device is powered on, create a zspage linked list corresponding to the first application and store the compressed memory data in the zspage linked list corresponding to the first application; or,

[0163] The memory 609 is used to store the compressed memory data in the zspage linked list corresponding to the first application when the compression process is the Nth time the memory data of the first application is compressed after the electronic device is powered on, and N is an integer greater than 1.

[0164] Optionally, the first type includes at least one of the following: GPU type; system type; DMA type.

[0165] Those skilled in the art will understand that the electronic device 600 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 610 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0166] It should be understood that, in this embodiment, the input unit 604 may include a graphics processing unit (GPU) 6041 and a microphone 6042. The GPU 6041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 606 may include a display panel 6061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 607 includes a touch panel 6071 and other input devices 6072. The touch panel 6071 is also called a touch screen. The touch panel 6071 may include a touch detection device and a touch controller. Other input devices 6072 may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, power buttons, etc.), a trackball, a mouse, and a joystick, which will not be described in detail here.

[0167] The memory 609 can be used to store software programs and various data. The memory 609 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 609 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 609 in this embodiment includes, but is not limited to, these and any other suitable types of memory.

[0168] Processor 610 may include one or more processing units; optionally, processor 610 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into processor 610.

[0169] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described memory management method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0170] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0171] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above memory management method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0172] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0173] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0174] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0175] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A memory management method applied to electronic devices, characterized in that, The method includes: When the first application switches from running in the foreground to running in the background, the memory data of the first application is compressed to obtain compressed memory data. The compressed memory data is stored in the zspage linked list corresponding to the first application; wherein, in at least one application of the first type running in the background of the electronic device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

2. The method according to claim 1, characterized in that, The zspage linked list includes multiple linked list management structures, and each of these multiple linked list management structures corresponds one-to-one with a different memory range of a storage object. The step of storing the compressed memory data in the zspage linked list corresponding to the first application includes: Based on the size of the compressed memory data, a first linked list management structure is determined among the plurality of linked list management structures, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure; The compressed memory data is stored in the first linked list management structure.

3. The method according to claim 2, characterized in that, After storing the compressed memory data in the first linked list management structure, the method further includes: If the remaining system memory of the electronic device is less than a first threshold, the compressed memory data is migrated from the first linked list management structure to the physical disk of the electronic device, and the first mapping relationship information is stored in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

4. The method according to claim 3, characterized in that, After migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device, the method further includes: When all processes of the first application exit, the memory occupied by the compressed memory data is released in units of zspage, the first linked list management structure is initialized, the first mapping relationship information is cleared, and the physical disk space occupied by the compressed memory data is released.

5. The method according to claim 3, characterized in that, After migrating the compressed memory data from the first linked list management structure to the physical disk of the electronic device, the method further includes: When the first application switches from running in the background to running in the foreground, the compressed memory data is migrated from the physical disk to the first linked list management structure according to the first mapping relationship information; The compressed memory data in the first linked list management structure is decompressed.

6. The method according to any one of claims 1 to 5, characterized in that, The step of storing the compressed memory data in the zspage linked list corresponding to the first application includes: If the compression process is performed for the first time on the memory data of the first application after the electronic device is powered on, a zspage linked list corresponding to the first application is created, and the compressed memory data is stored in the zspage linked list corresponding to the first application; or, When the compression process is performed on the memory data of the first application for the Nth time after the electronic device is powered on, and N is an integer greater than 1, the compressed memory data is stored in the zspage linked list corresponding to the first application.

7. The method according to claim 1, characterized in that, The first type includes at least one of the following: GPU type; system type; DMA type.

8. A memory management device, characterized in that, include: The compression module is used to compress the memory data of the first application when the first application switches from running in the foreground to running in the background, so as to obtain compressed memory data. A storage module is used to store the compressed memory data in a zspage linked list corresponding to the first application; wherein, in at least one application of a first type running in the background of the memory management device, one application corresponds to a set of zspage linked lists; the first type includes the program type of the first application.

9. The apparatus according to claim 8, characterized in that, The zspage linked list includes multiple linked list management structures, and each of these multiple linked list management structures corresponds one-to-one with a different memory range of a storage object. The storage module includes: A determining submodule is used to determine a first linked list management structure among the plurality of linked list management structures based on the size of the compressed memory data, wherein the size of the compressed memory data is within the memory range of the storage object corresponding to the first linked list management structure; The storage submodule is used to store the compressed memory data in the first linked list management structure.

10. The apparatus according to claim 9, characterized in that, The device further includes: The migration module is configured to migrate the compressed memory data from the first linked list management structure to the physical disk of the memory management device when the remaining system memory size of the memory management device is less than a first threshold, and store first mapping relationship information in the pointer of the context structure of the first application; wherein, the first mapping relationship information includes the mapping relationship between the compressed memory data and the physical disk and the first linked list management structure.

11. The apparatus according to claim 10, characterized in that, The device further includes: The release module is used to release the memory occupied by the compressed memory data in units of zspages when all processes of the first application exit, initialize the first linked list management structure, clear the first mapping relationship information, and release the physical disk space occupied by the compressed memory data.

12. The apparatus according to claim 10, characterized in that, The migration module is further configured to, when the first application switches from background to foreground operation, migrate the compressed memory data from the physical disk to the first linked list management structure according to the first mapping relationship information; The device further includes: The decompression module is used to decompress the compressed memory data in the first linked list management structure.

13. The apparatus according to any one of claims 8 to 12, characterized in that, The storage module is specifically used to create a zspage linked list corresponding to the first application and store the compressed memory data in the zspage linked list corresponding to the first application when the compression process is performed for the first time after the memory management device is powered on. or, The storage module is specifically used to store the compressed memory data in the zspage linked list corresponding to the first application when the compression process is the Nth time the memory management device is powered on and N is an integer greater than 1.

14. The apparatus according to claim 8, characterized in that, The first type includes at least one of the following: GPU type; system type; DMA type.

15. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a program or instructions that can run on the processor, and the program or instructions, when executed by the processor, implement the steps of the memory management method as described in any one of claims 1-7.