Memory management method, electronic equipment and storage medium

CN120641881APending Publication Date: 2025-09-12HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202480009756.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-07-14
Filing Date
2024-03-05
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

The existing memory management solution requires corresponding modifications to the kernel code, which leads to the inability to directly modify the kernel code in some areas, which limits the update of the kernel code and the reduction of memory pressure.

Method used

By creating a memory control group group in the memory management engine, and separating from the kernel code, the management of memory space is achieved to avoid direct modification of the kernel code.

Benefits of technology

While reducing memory pressure, it is not restricted by the modification of kernel code, which improves the flexibility and scalability of memory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120641881A_ABST
    Figure CN120641881A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of terminals, in particular to a memory management method, electronic equipment and a storage medium, the method comprises the steps that the memory management method is written in a kernel layer in a software code mode and is separated from kernel codes, and a kernel can call the software codes through a calling function to manage memory space; according to the method, the anonymous page corresponding to the application program is compressed to the block space, the compressed page corresponding to the application program is dumped to the universal flash memory and the like, so that the memory pressure can be reduced under the condition that kernel codes are not modified.
Need to check novelty before this filing date? Find Prior Art

Description

Memory management method, electronic device and storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on July 14, 2023, with application number 2023108731790 and application name “A memory management method, electronic device and storage medium”. The entire contents of the above application are incorporated by reference into this application. Technical Field

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

[0003] When an electronic device starts an application, it will request memory space to store the application's related data, such as file pages and anonymous pages. Among them, file pages are recyclable memory, and the data in the file pages are backed up in other storage devices. Therefore, the data in the file pages can be directly discarded to free up the memory space corresponding to the file pages. Later, when the data in the file pages is needed, it can be retrieved from other storage devices. Anonymous pages store data in the running process (such as intermediate results of logical operations). These data are likely to be accessed multiple times in a short period of time during the operation of the application, so these data cannot be directly discarded. However, during the operation of the application, the data that needs to be stored through anonymous pages may increase. If anonymous pages are constantly allocated in the memory to store this data, the storage burden of the memory will increase.

[0004] To this end, some technical solutions currently exist that, when memory pressure is high, dump the data in anonymous pages to other storage devices, such as disks or general-purpose flash memory, and then read this data back into anonymous pages in memory when needed. Implementing this memory management solution requires corresponding modifications to the kernel code.

[0005] Summary of the Invention

[0006] In order to solve the problem that existing memory management solutions require corresponding modifications to the kernel code, embodiments of the present application provide a memory management method, electronic device, and storage medium.

[0007] A first aspect of an embodiment of the present application provides a memory management method, which is applied to an electronic device. The electronic device includes a kernel layer, and the kernel layer includes a memory management engine and a kernel. The memory management method includes: if a first memory of the electronic device meets a first preset condition, the kernel calls a memory control group in the memory management engine to compress data in some anonymous pages of the first memory, and stores the compressed data in a first storage space in the first memory; if the first memory of the electronic device meets a second preset condition, the kernel calls the memory control group in the memory management engine to store part or all of the compressed data in the first storage space in the second memory.

[0008] Based on the above solution, modifications to the code in the memory management engine will not affect the kernel code, thereby reducing memory pressure while being unrestricted by kernel code modifications.

[0009] It can be understood that the first memory may be a memory, and the first storage space in the first memory may be a block space divided from the memory, and the block space may store compressed data that is not frequently accessed.

[0010] In some optional instances, the first storage is a memory, and the second storage is a disk or a general flash memory.

[0011] In some optional instances, the first preset condition includes: the data storage capacity of the first memory is greater than the first preset data storage capacity; the second preset condition includes: the data storage capacity of the first memory is greater than the second preset data storage capacity; the difference in data storage capacity between the first preset data storage capacity and the second preset data storage capacity is within a preset difference range.

[0012] In some optional examples, the data storage capacity of the first memory being greater than the first preset data storage capacity can be described as: the storage pressure of the first memory satisfies the first preset condition. The data storage capacity of the second memory being greater than the second preset data storage capacity can be described as: the storage pressure of the second memory satisfies the second preset condition.

[0013] In some optional examples, the first preset data storage capacity may be equal to the second preset data storage capacity, the first preset data storage capacity may be greater than the second preset data storage capacity, or the first preset data storage capacity may be less than the second preset data storage capacity.

[0014] In an embodiment of the present application, when the data storage capacity of the first memory is greater than the first preset data storage capacity, that is, when the memory pressure meets the first preset condition, the data in some anonymous pages in the first memory can be compressed and the compressed data can be stored in the first storage space in the first memory, thereby reducing the memory pressure. When the data storage capacity of the first memory is greater than the second preset data storage capacity, that is, when the memory pressure meets the second preset condition, the data in part or all of the compressed data in the first storage space can be stored in the second memory, thereby reducing the memory pressure.

[0015] In some optional instances, the memory control group in the memory control group includes relevant information of the memory space for storing relevant data of the application, and the kernel calls the memory control group in the memory management engine to store part or all of the compressed data in the first storage space to the second memory, including: the kernel sends an information acquisition instruction to the memory management engine; the kernel obtains relevant information of the memory space for storing relevant data of the application, and based on the relevant information, stores part or all of the compressed data in the first storage space to the second memory.

[0016] It can be understood that the memory control group corresponding to the application may include a method for managing the memory space storing the relevant data of the application, and relevant information describing the memory space storing the relevant data of the application.

[0017] In some optional instances, the method further includes: when detecting that an application is started, creating a first memory control group corresponding to the application in the kernel to obtain a first memory control group group; creating a second memory control group corresponding to the first memory control group in the memory management engine to obtain a second memory control group group.

[0018] In some optional instances, the kernel calls the memory control group in the memory management engine to compress data in some anonymous pages of the first memory, and stores the compressed data in the first storage space in the first memory, including: the kernel calls the second memory control group in the memory management engine to make the life cycle of the first memory control group in the first memory control group the same as the life cycle of the corresponding second memory control group in the second memory control group; wherein the life cycle of the first memory control group includes the first memory control group being in any one of the life stages of going online, going offline, removed and released; based on the life stage of each first memory control group in the first memory control group, compressing the data in some anonymous pages of the first memory, and storing the compressed data in the first storage space in the first memory.

[0019] In the embodiment of the present application, by synchronizing the first memory control group and the second memory control group, the storage space of the first memory can be managed based on the entire life cycle of the application.

[0020] In some optional instances, compressing data in some anonymous pages of the first memory and storing the compressed data in the first storage space in the first memory includes: compressing data in some anonymous pages of the first memory whose access frequency is lower than the average access frequency, and storing the compressed data in the first storage space in the first memory.

[0021] In the embodiment of the present application, memory pressure can be reduced by compressing data in some anonymous pages whose access frequency is lower than the average access frequency.

[0022] In some optional instances, the kernel calls the memory control group in the memory management engine to store part or all of the compressed data in the first storage space to the second memory, including: the kernel calls the second memory control group in the memory management engine so that the life cycle of the first memory control group in the first memory control group is the same as the life cycle of the corresponding second memory control group in the second memory control group; wherein the life cycle of the first memory control group includes the first memory control group being in any one of the life stages of going online, going offline, removed and released; based on the life stage of each first memory control group in the first memory control group, obtaining part of the compressed data in the first storage space and storing it in the second memory.

[0023] In some optional instances, storing part or all of the compressed data in the first storage space to the second memory includes: dumping part or all of the compressed data in the first storage space whose access frequency is lower than the average access frequency to the second memory.

[0024] In an embodiment of the present application, by dumping part or all of the compressed data with an access frequency lower than the average access frequency to the second memory, the memory pressure can be reduced, the frequent reading of the second memory can be reduced, and the service life of the second memory can be increased.

[0025] In some optional instances, the electronic device includes a non-uniform memory access architecture, and the method includes: if the node memory in the non-uniform memory access architecture meets a first preset condition, the kernel calls the memory management process in the memory management engine to compress the data in some anonymous pages of the node memory, and stores the compressed data in the first storage space in the first memory; if the node memory in the non-uniform memory access architecture meets a second preset condition, the kernel calls the memory management process in the memory management engine to store part or all of the compressed data in the node memory in the second memory.

[0026] In a second aspect, the present application provides an electronic device comprising: a memory for storing instructions executed by one or more processors of the electronic device; and a processor, which is one of the one or more processors of the electronic device, for executing the memory management method mentioned in the present application.

[0027] In a third aspect, the present application provides a readable storage medium having instructions stored thereon. When the instructions are executed on an electronic device, the electronic device executes the memory management method mentioned in the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] FIG1 is a schematic diagram showing a memory management method according to some embodiments of the present application;

[0029] FIG2 is a schematic diagram showing another memory management method according to some embodiments of the present application;

[0030] FIG3 shows a schematic diagram of a software structure of an electronic device according to some embodiments of the present application;

[0031] FIG4 shows a schematic diagram of the software structure of another electronic device according to some embodiments of the present application;

[0032] FIG5 is a flow chart showing a memory management method according to some embodiments of the present application.

[0033] FIG6 is a schematic diagram illustrating a process of synchronizing the life cycles of a memory control group in a memory management engine and a memory control group in a memory management module in a kernel according to some embodiments of the present application;

[0034] FIG7 is a schematic diagram showing a process of managing memory according to some embodiments of the present application;

[0035] FIG8 shows a schematic diagram of the hardware structure of an electronic device according to some embodiments of the present application. DETAILED DESCRIPTION

[0036] The illustrative embodiments of the present application include, but are not limited to, a memory management method, an electronic device, and a medium.

[0037] The memory management method described in the embodiments of the present application can be applied to an electronic device, which can also be referred to as a user equipment (UE), a mobile station (MS), a mobile terminal, etc. Optionally, the electronic device can have the ability to communicate with one or more core networks via a radio access network (RAN). For example, the electronic device can be a mobile phone (also called a "cellular" phone) or a mobile computer.

[0038] As mentioned above, in some technical solutions, memory management can be performed by storing data in anonymous pages in other storage devices. For example, FIG1 shows a method of performing memory management in a mobile phone 100 by storing anonymous pages in a universal flash memory. As shown in FIG1 , the mobile phone 100 includes a processor 101, a memory 102, and a universal flash memory 103. In the process of running an application, the processor 101 will apply to the memory 102 for memory space for storing data related to the application, such as file pages 1021 and anonymous pages 1022-1 to 1022-n1. If the memory pressure meets the first preset condition, for example, if there is a large amount of related data stored and a large number of anonymous pages, some or all of the data stored in the anonymous pages will be dumped to the universal flash memory 103.

[0039] For example, data A stored in anonymous page 1022-1 is transferred to page 103-1 of the universal flash memory to free up the memory space corresponding to anonymous page 1022-1. When data A is needed, data A is read from page 103-1 of the universal flash memory into anonymous page 1022-1 of memory 102. However, frequently reading data from the universal flash memory 103 can affect the lifespan of the universal flash memory 103.

[0040] To this end, in some specific instances, by compressing only the infrequently accessed data in the anonymous page to a set area in the memory and then dumping it to the universal flash memory according to the size of the memory storage pressure, the frequency of reading data from the universal flash memory is reduced, thereby reducing the impact on the service life of the universal flash memory.

[0041] As shown in Figure 2, mobile phone 200 includes a processor 201, memory 202, and general-purpose flash memory 203. Part of memory 202 is divided into block space 2021, file pages 2022, and anonymous pages 2023-1 through 2023-n1. As previously described, when running an application, processor 201 requests memory space from memory 202 to store application-related data, such as file pages 2022 and anonymous pages 2023-1 through 2023-n1. If memory pressure meets a first preset condition, for example, if there is a large amount of stored relevant data or a large number of anonymous pages, some or all of the infrequently accessed data in the anonymous pages will be compressed and stored in the block space. However, since the block space is a portion of memory allocated from the memory, the infrequently accessed data stored in the block space is still actually stored in the memory. The amount of infrequently accessed data requiring block space storage is likely to increase as the application runs. Continuously storing this data in the block space will further increase the memory storage burden. Therefore, if the memory pressure meets the second preset condition, such as a large amount of compressed data, some or all of the data in the block space will be dumped to the universal flash memory. The first preset condition and the second preset condition can be the same, for example, the first preset condition is that the data storage capacity of the memory is greater than the first preset data storage capacity, and the second preset condition is that the data storage capacity of the memory is greater than the second preset data storage capacity, and the first preset data storage capacity and the second preset data storage capacity are equal.

[0042] For example, when the memory pressure meets the first preset condition, data B stored in anonymous page 2023-1 is compressed and stored in compressed page 2021-1 of block space 2021, thereby freeing up the memory space corresponding to anonymous page 2023-1. When the memory pressure meets the second preset condition, data B in compressed page 2021-1 is dumped to dump page 203-1 of universal flash memory 203, thereby freeing up the memory space corresponding to compressed page 2021-1. When data B is needed, data B is read from dump page 203-1 of universal flash memory 203 into compressed page 2021-1 of memory 202.

[0043] However, these memory management methods require intrusive modification of kernel code, and in some regions, kernel code cannot be directly modified, resulting in limited kernel code updates. This problem is explained below with reference to Figure 3.

[0044] Specifically, Figure 3 shows a schematic diagram of the software structure of an electronic device, where the electronic device can be an electronic device running an Android or Linux system. As shown in Figure 3, the software structure of the electronic device can include an application layer 301 and a kernel layer 302. Kernel layer 302 can include a kernel 3021, which can include an information collection module 3021-1 and a memory management module 3021-2. Information collection module 3021-1 can collect memory status information (such as memory pressure) and transmit it to memory management module 3021-2. When memory pressure is high, memory management module 3021-2 can manage the memory space storing application-related data based on memory management methods (such as compressing anonymous pages into block space and dumping compressed pages into general flash memory). However, these memory management methods require invasive modification of kernel code, and in some regions, kernel code cannot be directly modified, resulting in limited kernel code updates.

[0045] In order to solve the above problems, an embodiment of the present application provides a memory management method, which can be written in the kernel layer in the form of software code, and written in a software module different from the software module where the kernel code is located. For example, a kernel and a memory management engine are provided in the kernel layer of an electronic device, the kernel stores the kernel code, and the memory management engine stores the relevant code of the memory management method. The kernel can manage the memory space by calling the software code by calling functions, such as compressing the anonymous pages corresponding to the application to the block space, dumping the compressed pages corresponding to the application to the general flash memory, etc. Modifications to the code in the memory management engine will not affect the kernel code, thereby reducing memory pressure while not being restricted by kernel code modifications.

[0046] As shown in FIG4 , in some optional embodiments, the software structure of the electronic device may include an application layer 401 and a kernel layer 402. Kernel layer 402 may include a kernel 4021 and a memory management engine 4022. Kernel 4021 may include an information acquisition module 4021-1 and a memory management module 4021-2. When information acquisition module 4021-1 detects that memory pressure meets a preset condition, the kernel may read the software code of the memory management method in memory management engine 4022 into memory management module 4021-2 by calling a function, and manage the memory based on the software code of the memory management method read from memory management module 4021-2.

[0047] In some optional examples, the calling function may be a hook function provided by the kernel, or may be another function in the kernel that can call the code in the memory management engine.

[0048] The memory management method mentioned in the embodiment of the present application is described in detail below. FIG5 shows a flow chart of a memory management method, which can be applied to an electronic device. As mentioned above, the electronic device may include an application layer and a kernel layer. The kernel layer may include a kernel and a memory management engine. The kernel may include an information acquisition module and a memory management module. As shown in FIG5 , the memory management method may include:

[0049] 501: When each application is started, the memory management module in the kernel creates a first memory control group corresponding to the application to obtain a first memory control group group.

[0050] It can be understood that the memory control group corresponding to the application may include a method for managing the memory space storing the relevant data of the application, and relevant information describing the memory space storing the relevant data of the application.

[0051] It is understandable that when an application is started, it can apply to the memory for memory space to store data related to the application, such as file pages and anonymous pages. In addition, the memory management module in the kernel can create a first memory control group (memory control group, memcg) corresponding to the application, so that the kernel can manage the memory space for storing data related to the application according to the first memory control group. Among them, the kernel needs to call the second memory control group in the memory management engine based on the calling function, so that the first memory control group in the memory management module in the kernel is synchronized with the second memory control group in the memory management engine to achieve management of the memory space for storing data related to the application.

[0052] In some optional instances, the first memory control group may have a first identifier, and the first identifier may be a unique identity of the first memory control group.

[0053] It is understood that an electronic device may include one or more applications. These applications may be system applications or third-party applications. For example, an electronic device may have installed applications such as a browser, a game application, a music application, and a shopping application. When each application is launched, it may request memory space to store application-related data, such as file pages and anonymous pages.

[0054] For example, when the browser is first started, it can apply to the memory for storing the relevant data of the browser, such as anonymous page 1, and the memory management module in the kernel can create a first memory control group corresponding to the browser (the first identifier is memcg 11 ), so that the kernel can use the first memory control group (the first identifier is memcg 11) to manage anonymous page 1 storing relevant data of the browser. When the game application is started at the second time, it can apply to the memory for memory space storing relevant data of the game application, such as anonymous page 2, and the memory management module in the kernel can create a first memory control group corresponding to the game application (the first identifier is memcg 12 ), so that the kernel can use the first memory control group (the first identifier is memcg 12 ) to manage the anonymous page 2 storing the relevant data of the game application. The first time is earlier than the second time.

[0055] In some optional instances, when the process of an application is started, it can apply to the memory for memory space to store the relevant data of the process, and the memory management module in the kernel can create a first memory control group corresponding to the application corresponding to the process, so that the kernel can manage the memory space of the relevant data of the application process according to the first memory control group.

[0056] For example, when process a of the music application is started at the third time and process b is started at the fourth time, memory space for storing relevant data of process a, such as anonymous page 3, can be requested from the memory. At the same time, memory space for storing relevant data of process b, such as anonymous page 4, can be requested from the memory.

[0057] If the first memory control group corresponding to the music application does not exist in the memory management module in the kernel, the memory management module in the kernel can create a first memory control group (the first identifier is memcg 13 ), so that the kernel can use the first memory control group (the first identifier is memcg 13 ) to manage the anonymous page 3 of process a storing the music application and the anonymous page 4 of process b managing the music application.

[0058] It can be understood that the multiple first memory control groups created by the memory management module in the kernel can be called the first memory control group group of the memory management module. For example, based on the example listed above, the first memory control group corresponding to the browser created by the memory management module in the kernel (the first identifier is memcg 11 ), the first memory control group corresponding to the game application (the first identifier is memcg 12 ), and the first memory control group corresponding to the music application (the first identifier is memcg 13 ) can constitute the first memory control group of the memory management module.

[0059] 502: Create a second memory control group corresponding to each first memory control group in the memory management engine to obtain a second memory control group group.

[0060] It can be understood that the second memory control group may include relevant information describing the memory space for storing application-related data, and a method for managing the memory space for storing application-related data. The relevant information describing the memory space for storing application-related data may include the size of the memory space for storing application-related data, and the access frequency of the relevant data in the memory space for storing application-related data, that is, the active state of the memory space for storing application-related data, etc. The method for managing the memory space for storing application-related data may include reclaiming the memory space for storing application-related data based on memory recycling parameters and relevant information describing the storage of application-related data. The method for managing the memory space for storing application-related data may also include reading data in the dump page corresponding to the application from the universal flash memory to a compressed page in the block space, and decompressing data in the compressed page corresponding to the application to an anonymous page. The second memory control group may have a second identifier, and the second identifier may be a unique identity identifier of the second memory control group.

[0061] In some optional instances, the specific method for reclaiming the memory space storing the relevant data of the application can be: based on the memory reclaim parameters and the relevant information describing the storage of the relevant data of the application, compressing the data in the anonymous page corresponding to the application and storing it in the compressed page in the block space. Based on the memory reclaim parameters and the relevant information describing the storage of the relevant data of the application, dumping the data in the compressed page corresponding to the application to the dump page in the general flash memory. The memory reclaim parameter can be a preset data reclaim amount. For example, when the amount of data stored in the memory is greater than a preset storage threshold, the compressed pages of the memory with the preset data reclaim amount can be dumped to the general flash memory.

[0062] For example, the memory management engine can create a second memory control group corresponding to the browser (the second identifier is memcg 21 ), create a second memory control group corresponding to the game application at the second time (the second identifier is memcg 22 ), create a second memory control group corresponding to the music application at the third time (the second identifier is memcg 23 ).

[0063] Among them, the second memory control group corresponding to the browser (the second identifier is memcg 21 ) includes: the size of anonymous page 1 is X1KB, the access frequency of the browser-related data stored in anonymous page 1 is higher than the average access frequency, and other related information describing the memory space for storing the browser-related data.

[0064] The second memory control group corresponding to the game application (the second identifier is memcg 22 ) includes: the size of anonymous page 1 is X2KB, the access frequency of the browser-related data stored in anonymous page 1 is higher than the average access frequency, and other relevant information describing the memory space for storing the relevant data of the game application.

[0065] The second memory control group corresponding to the music application (the second identifier is memcg 23 ) includes: the size of anonymous page 3 is X3KB, the access frequency of the relevant data of the music application stored in anonymous page 3 is lower than the average access frequency, and other relevant information describing the memory space for storing the relevant data of the music application; the size of anonymous page 4 is X4KB, the access frequency of the relevant data of the music application stored in anonymous page 4 is lower than the average access frequency, and other relevant information describing the memory space for storing the relevant data of the process of the music application.

[0066] The second memory control group corresponding to the music application (the second identifier is memcg 23 ) may also include: first compressing the data in anonymous page 3 and storing it in compressed page 1 of the block space, then compressing the data in anonymous page 4 and storing it in compressed page 2 of the block space, and first adding compressed page 3 to the compressed page linked list of the second memory control group, and then adding compressed page 4 to the compressed page linked list, etc., a method for managing the memory space for storing application-related data.

[0067] It can be understood that the plurality of second memory control groups in the memory management engine can be referred to as the second memory control group group of the memory management engine. For example, based on the example listed above, a second memory control group corresponding to the first memory control group corresponding to the browser can be created in the memory management engine (the second identifier is memcg 21 ), the second memory control group corresponding to the first memory control group corresponding to the game application (the second identifier is memcg 22 ), and the second memory control group (the second identifier is memcg 23 ), can constitute the second memory control group of the memory management engine.

[0068] In an embodiment of the present application, a second memory control group is created in the memory management engine, that is, the relevant information describing the memory space for storing application-related data and the relevant code for the method of managing the memory space for storing application-related data are written in the kernel layer and separated from the kernel code, thereby avoiding a large number of invasive modifications to the kernel code and reducing the update complexity of the relevant code for executing operations to reduce memory pressure.

[0069] 503: When the information collection module in the kernel detects that the memory pressure is high, the first memory control group and the second memory control group are synchronized.

[0070] It can be understood that synchronizing the first memory control group and the second memory control group can mean that the kernel reads the relevant information of the memory space for storing application-related data and the method for managing the memory space for storing application-related data included in the second memory control group into the first memory control group based on a calling function, so that the kernel can manage the memory space for storing application-related data based on the read method for managing the memory space for storing application-related data. For example, the kernel can first compress the data in anonymous page 3 and store it in compressed page 1 of the block space, and then compress the data in anonymous page 4 and store it in compressed page 2 of the block space, and first add compressed page 3 to the compressed page linked list of the second memory control group, and then add compressed page 4 to the compressed page linked list.

[0071] 504: When an application is destroyed, the second memory control group corresponding to the application is deleted from the second memory control group group.

[0072] In some optional instances, application destruction may mean that all processes of the application are destroyed. For example, when a music application is closed, both process a and process b of the music application are destroyed. In this way, the second memory control group (the second identifier is memcg 23 During this process, the memory space storing the relevant data of the music application will also be released. For example, the relevant data of process a of the music application is stored in compressed page 1 in the block space, and the relevant data of process b of the music application is stored in compressed page 2 in the block space. At this time, compressed page 1 storing the relevant data of process a of the music application will be released, and compressed page 2 storing the relevant data of process b of the music application will also be released.

[0073] In some optional embodiments, when an application is destroyed, the reference count of the second memory control group can be reduced by one when the information collection module in the kernel detects that the compressed pages of all processes storing the application are released. When the reference count in the second memory control group reaches zero, that is, when all applications are destroyed, the second memory control group can be released, that is, all data included in each second memory control group, including the relevant information of the memory space storing the relevant data of the application, the method for managing the memory space storing the relevant data of the application, and the second identifier of each second memory control group, is deleted.

[0074] 505: Update the first memory control group based on the second memory control group.

[0075] It is understandable that the kernel can read the second identifier of each second memory control group in the second memory control group group based on the calling function and match it with the first identifier of each first memory control group in the first memory control group. If the reference count of the second memory control group corresponding to the first memory control group is 0, and after the second memory control group is released, the first memory control group can be released, that is, the relevant information of the memory space for storing application-related data included in the first memory control group and the method for managing the memory space for storing application-related data are deleted, and the first identifier of the first memory control group is deleted from the first memory control group group.

[0076] The memory management method mentioned in the embodiment of the present application is introduced in detail below using a specific example.

[0077] In order to avoid intrusive modification of kernel code, the memory control group can be written in the memory management engine of the kernel layer, separated from the kernel code, and through the existing hook function (hook) in the kernel code, the memory control group in the memory management engine and the memory control group in the memory management module in the kernel can be made to have the same life cycle. Among them, the memory management engine can be hyperhold, which can connect the call stack from the upper system to the kernel, allowing the kernel to fully perceive the entire life cycle of the application and perform memory management in combination with the application generation cycle and the data access characteristics within the cycle.

[0078] As shown in FIG6 , the kernel layer 600 may include a kernel 601 and a memory management engine 602. The kernel 601 may include a memory management module 6011 (also referred to as a native memory control group management module), a memory recycling module 6012, and a node memory management module 6013. The memory management engine 602 may include a first memory management engine 6021 and a second memory management engine 6022.

[0079] In some specific implementations, a plug-in structure can be allocated at a reserved location in the kernel code (such as android_vendor_data_1) to manage memory, that is, a memory control group is created in the first memory management engine 6021, which includes relevant information describing the memory space for storing application-related data and a method for managing the memory space for storing application-related data.

[0080] In some optional instances, the data structure of the memory control group in the memory management module 6011 can be struct mem_cgroup, and the data structure of the memory control group in the first memory management engine 6021 can be struct mem_cgroup_ext. The kernel 601 can call the memory control group in the first memory management engine 6021 based on the hook function, so that the memory control group in the memory management module 6011 is synchronized with the memory control group in the first memory management engine 6021 to achieve memory management.

[0081] The method for synchronizing the memory control group in the memory management module and the memory control group in the memory management engine may be:

[0082] When an application starts, it can request memory space to store application-related data, such as file pages and anonymous pages. The memory management module in the kernel can create and bring online a first memory control group corresponding to the application, and can create a second memory control group corresponding to the first memory control group in the memory management engine. In some specific implementations, the kernel can create the first memory control group by calling the function mem_cgroup_alloc, and after successfully creating the first memory control group, it can call the function mem_cgroup_alloc_callback through the callback function trace_android_vh_mem_cgroup_alloc to create the second memory control group. The kernel can also bring online the first memory control group by calling the function mem_cgroup_online, and after successfully bringing online the first memory control group, it can call the function mem_cgroup_online_callback through the callback function trace_android_vh_mem_cgroup_online to bring online the second memory control group.

[0083] When the application is destroyed, the memory management engine can offline the second memory control group corresponding to the application, and can offline the first memory control group corresponding to the second memory control group in the memory management module in the kernel. In some specific implementations, the kernel can offline the second memory control group by calling the function mem_cgroup_css_offline_callback, and after successfully offline the second memory control group, it can call the function mem_cgroup_css_offline to offline the first memory control group through the callback function trace_android_vh_mem_cgroup_css_offline.

[0084] The memory management engine can remove the extended identifier of the second memory control group corresponding to the application, and can remove the extended identifier of the first memory control group in the memory management module in the kernel. In some specific implementations, the kernel can remove the identifier of the second memory control group by calling the function mem_cgroup_id_remove_callback, and after successfully removing the identifier of the second memory control group, can call the function mem_cgroup_id_remove through the callback function trace_android_vh_mem_cgroup_id_remove to remove the identifier of the first memory control group.

[0085] When all applications are destroyed, the memory management engine can release the second memory control group corresponding to each application, and the memory management model in the kernel can release the first memory control group corresponding to each second memory control group. In some specific implementations, the kernel can release the second memory control group by calling the function mem_cgroup__free_callback. After successfully releasing the second memory control group, the kernel can call the function mem_cgroup_free through the callback function trace_android_vh_mem_cgroup_free to release the first memory control group.

[0086] In other specific implementations, a plug-in structure can be allocated at a reserved location in the kernel code (such as android_oem_data_1) to manage the memory in the non-uniform memory access (NUMA) architecture, that is, a memory compression process corresponding to different node memories in the NUMA architecture is created in the second memory management engine 6022 to manage the corresponding node memory.

[0087] The memory recovery module 6012 may include a function get_scan_count, and may control the recovery behavior of the get_scan_count function through the function trace_android_vh_scan_type.

[0088] For example, when the node memory pressure is high, the node memory management module 6013 can compress the data in the anonymous page corresponding to the application and store it in the compressed page in the block space based on the synchronized memory management process in the memory management module 6011, or dump the data in the compressed page corresponding to the application to the dump page in the general flash memory.

[0089] In some optional examples, the data structure of the node memory management module 6013 may be struct_pglit_data, and the kernel 601 may call the memory compression process in the second memory management engine 6022 based on the hook function, so that the memory compression process in the node memory management module 6013 is synchronized with the memory management process in the second memory management engine 6022 to manage the node memory. The specific implementation of the node memory management module managing the memory of each node is described in detail in FIG.

[0090] The following describes in detail the specific implementation of the node memory management module for each node memory management. Figure 7 shows a schematic diagram of a process flow of the node memory management module for each node memory management. As shown in Figure 7, the method for the node memory management module to manage the memory of each node may include:

[0091] 701: Create a memory management process in the second memory management engine according to the identifier of each node memory.

[0092] In some optional instances, a memory management process may be created for each node memory in the second memory management engine.

[0093] 702 : Determine whether it is a non-uniform memory access architecture. If the determination is no, execute step 703 ; otherwise, execute step 706 .

[0094] In some optional embodiments, a non-uniform memory access architecture (NUMA) is a memory architecture in a multi-processor computer design where memory access time depends on the location of the memory relative to the processors.

[0095] 703: Get a globally unique memory identifier.

[0096] It can be understood that each node memory in NUMA can have a memory identifier, which can be a unique identity identifier of the node memory.

[0097] 704: Obtain the memory management process corresponding to the memory identifier.

[0098] 705: Wake up the memory management process corresponding to the memory identifier, and manage the memory corresponding to the memory identifier based on the memory management process corresponding to the memory identifier.

[0099] It can be understood that the specific method of managing the memory corresponding to the memory identifier can be referred to Figure 5, and will not be repeated here.

[0100] 706: Poll and obtain the memory identifier of each node memory.

[0101] 707: Obtain the memory management process corresponding to the memory identifier of each node memory.

[0102] 708: Wake up the memory compression process corresponding to each memory identifier, and manage the memory corresponding to each memory identifier based on the memory management process corresponding to each memory identifier.

[0103] It can be understood that the specific method of managing the memory corresponding to each memory identifier can be referred to Figure 5, and will not be repeated here.

[0104] The following describes the hardware structure of the electronic device. As shown in Figure 8, the electronic device 800 may include a processor 810, an external memory interface 820, an internal memory 821, a universal serial bus (USB) interface 830, a charging management module 840, a power management module 841, a battery 842, antenna 1, antenna 2, a mobile communication module 850, a wireless communication module 860, an audio module 870, a speaker 870A, a receiver 870B, a microphone 870C, an earphone interface 870D, a sensor module 880, a button 890, a motor 891, an indicator 892, a camera 893, a display 894, and a subscriber identification module (SIM) card interface 895. The sensor module 880 may include a pressure sensor 880A, a gyroscope sensor 880B, an air pressure sensor 880C, a magnetic sensor 880D, an acceleration sensor 880E, a distance sensor 880F, a proximity light sensor 880G, a fingerprint sensor 880H, a temperature sensor 880J, a touch sensor 880K, an ambient light sensor 880L, a bone conduction sensor 880M, etc.

[0105] It is understood that the structure illustrated in the embodiments of the present invention does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device 800 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The components shown in the diagram may be implemented in hardware, software, or a combination of software and hardware.

[0106] The processor 810 may include one or more processing units. For example, the processor 810 may include an application processor (AP), a modem processor, a graphics processing unit (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). The different processing units may be independent devices or integrated into one or more processors.

[0107] 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.

[0108] Processor 810 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 810 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 810. If processor 810 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 810 latency, and thus improves system efficiency.

[0109] The external memory interface 820 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 800. The external memory card communicates with the processor 810 via the external memory interface 820 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.

[0110] The internal memory 821 can be used to store computer executable program codes, which include instructions. The internal memory 821 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 800 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 821 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 810 executes various functional applications and data processing of the electronic device 800 by running instructions stored in the internal memory 821 and / or instructions stored in a memory provided in the processor.

[0111] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems raised by this application. In addition, in order to highlight the innovative part of this application, the above-mentioned device embodiments of this application do not introduce units / modules that are not closely related to solving the technical problems raised by this application. This does not mean that other units / modules do not exist in the above-mentioned device embodiments.

[0112] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "including a" does not exclude the presence of other identical elements in the process, method, article or device that includes the element.

[0113] While the present application has been shown and described with reference to certain preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the scope of the present application.

Claims

1. A memory management method, characterized in that: Applied to an electronic device, the electronic device includes a kernel layer, the kernel layer includes a memory management engine and a kernel, and the method includes: If the first memory of the electronic device meets the first preset condition, the kernel calls the memory control group in the memory management engine to compress the data in some anonymous pages of the first memory, and stores the compressed data in the first storage space in the first memory; If the first memory of the electronic device meets a second preset condition, the kernel calls a memory control group in the memory management engine to store part or all of the compressed data in the first storage space into the second memory.

2. The method according to claim 1, characterized in that The first storage is a memory, and the second storage is a disk or a general flash memory.

3. The method according to claim 1, characterized in that The first preset condition includes: the data storage capacity of the first memory is greater than the first preset data storage capacity; The second preset condition includes: the data storage capacity of the first memory is greater than the second preset data storage capacity; and the data storage capacity difference between the first preset data storage capacity and the second preset data storage capacity is within a preset difference range.

4. The method according to claim 1, characterized in that: The memory control group in the memory control group group includes relevant information of the memory space storing relevant data of the application program; The kernel calls the memory control group in the memory management engine to store part or all of the compressed data in the first storage space into the second memory, including: The kernel sends an information acquisition instruction to the memory management engine; The kernel obtains relevant information of the memory space storing the relevant data of the application program, and based on the relevant information, stores part or all of the compressed data in the first storage space into the second memory.

5. The method according to claim 4, characterized in that The method further comprises: When detecting that an application is started, creating a first memory control group corresponding to the application in the kernel to obtain a first memory control group group; A second memory control group corresponding to the first memory control group is created in the memory management engine to obtain a second memory control group group.

6. The method according to claim 5, characterized in that The kernel calls the memory control group in the memory management engine to compress data in some anonymous pages of the first memory, and stores the compressed data in a first storage space in the first memory, including: The kernel calls the second memory control group in the memory management engine, so that the life cycle of the first memory control group in the first memory control group is the same as the life cycle of the corresponding second memory control group in the second memory control group; wherein the life cycle of the first memory control group includes any life stage of the first memory control group being online, offline, removed and released; Based on the life stage of each first memory control group in the first memory control group group, data in some anonymous pages of the first memory are compressed, and the compressed data is stored in a first storage space in the first memory.

7. The method according to claim 6, characterized in that The step of compressing data in some anonymous pages of the first memory and storing the compressed data in a first storage space in the first memory includes: The data in the part of anonymous pages in the first memory whose access frequency is lower than the average access frequency are compressed, and the compressed data are stored in the first storage space in the first memory.

8. The method according to claim 5, characterized in that The kernel calls the memory control group in the memory management engine to store part or all of the compressed data in the first storage space into the second memory, including: The kernel calls the second memory control group in the memory management engine so that the life cycle of the first memory control group in the first memory control group is the same as the life cycle of the corresponding second memory control group in the second memory control group; wherein the life cycle of the first memory control group includes any life stage of the first memory control group being online, offline, removed and released; Based on the life stage of each first memory control group in the first memory control group group, part or all of the compressed data in the first storage space is stored in the second memory.

9. The method according to claim 8, characterized in that The storing part or all of the compressed data in the first storage space into the second storage includes: Dumping part or all of the compressed data in the first storage space whose access frequency is lower than the average access frequency to the second memory.

10. The method according to claim 1, characterized in that The electronic device includes a non-uniform memory access architecture, and the method includes: If the node memory in the non-uniform memory access architecture meets the first preset condition, the kernel calls the memory management process in the memory management engine to compress data in some anonymous pages of the node memory, and stores the compressed data in the first storage space in the first memory; If the node memory in the non-uniform memory access architecture meets the second preset condition, the kernel calls the memory management process in the memory management engine to store part or all of the compressed data in the node memory into the second memory.

11. An electronic device, characterized in that: include: A memory, used to store instructions executed by one or more processors of the electronic device, and a processor, which is one of the one or more processors of the electronic device, used to execute the memory management method described in any one of claims 1-10.

12. A readable storage medium, characterized in that: The readable storage medium stores instructions, and when the instructions are executed on an electronic device, the electronic device executes the memory management method according to any one of claims 1 to 10.