A memory manager management method and electronic device

By creating and managing memory data structures in electronic devices, asynchronously releasing memory pages and using asynchronous threads to detect memory status, the problem of memory leakage caused by incomplete memory manager release under universal kernel images is solved, and memory usage and release efficiency are improved. .

CN117724828BActive Publication Date: 2024-10-18HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310879426.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-17
Publication Date
2024-10-18
Estimated Expiration
2043-07-17

AI Technical Summary

Technical Problem

In electronic devices that use universal kernel images, the kernel code cannot be modified directly, causing the memory manager memcg to be unable to effectively release system memory, and memory leaks may occur.

Method used

By creating the first and second data structures to manage the memory pages in the system memory and the swap partition respectively, and asynchronously releasing the memory pages when the application stops running, ensuring that the second data structure has been released before releasing the first data structure, utilizing asynchronous The thread detects whether the memory page linked list is empty to block the release of the first data structure and reduce the possibility of memory leaks.

Benefits of technology

It effectively avoids memory leaks, improves memory usage and release efficiency, and ensures the integrity and security of the memory manager when releasing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117724828B_ABST
    Figure CN117724828B_ABST
Patent Text Reader

Abstract

The present application provides a management method and electronic device of a memory manager, and relates to the field of computer technology. This solution improves the problem of memory leakage after memcg is released in an electronic device that enables a universal kernel image. The specific solution is: in response to the start-up of an application, a memory manager memcg corresponding to the application is created; memcg corresponds to a first data structure and a second data structure, and the second data structure is a data structure created based on code data in the form of a kernel object, and is used to manage the second memory page of the application in the second storage space; in response to the stop of the application, the first memory page and the second memory page are asynchronously released; after determining that the second memory page has been released, the second data structure is released; when the second data structure has been released, it is determined that memcg is in an unused state, and the first memory page has been released, the first function is called to release the first data structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a management method of a memory manager and an electronic device. Background Art

[0002] During the operation of electronic devices, the memory manager (memory cgroup, memcg) can be used to manage the memory pages of applications in the system memory (the part of the internal memory except the swap partition). If you need to expand the storage range managed by memcg (for example, to use the memcg mechanism to manage the swap partition), you need to modify the kernel code related to memcg.

[0003] For electronic devices that use a generic kernel image (GKI), the kernel code cannot be modified directly. Instead, the corresponding kernel object (KO) code can be mounted on the kernel code through a hook function to expand the storage range managed by memcg.

[0004] However, in the case where KO code is mounted on the kernel code, in the related art, in the scenario of releasing memcg (releasing the system memory occupied and managed by memcg), a memory leak problem may occur. Summary of the invention

[0005] The embodiment of the present application provides a memory manager management method and electronic device, which are used to avoid the problem of memory leakage after memcg is released when KO code is mounted on kernel code, and improve memory utilization.

[0006] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:

[0007] In a first aspect, an embodiment of the present application provides a memory manager management method, which is applied to an electronic device with a universal kernel image enabled, the method comprising: in response to the startup and operation of an application, creating a memory manager memcg corresponding to the application; the memcg corresponds to a first data structure and a second data structure, the first data structure is a data structure created based on code data in the universal kernel image, and is used to manage a first memory page of the application in a first storage space; the second data structure is a data structure created based on code data in the form of a kernel object, and is used to manage a second memory page of the application in a second storage space; in response to the stop of the application, asynchronously releasing the first memory page and the second memory page; after determining that the second memory page has been released, releasing the second data structure; when the second data structure has been released, it is determined that the memcg is in an unused state, and the first memory page has been released, calling a first function to release the first data structure.

[0008] In the above embodiment, the release of the first data structure is blocked before the release of the second data structure, so as to avoid the problem of abnormal release of the second data structure created based on the KO code and reduce the possibility of memory leak.

[0009] In some embodiments, the condition for calling the first function is not satisfied until the second data structure is released.

[0010] In the above embodiment, the function for releasing the first data structure can be called only when the second data structure has been released, so as to block the release of the first data structure before the second data structure is released.

[0011] In some embodiments, the first data structure includes a first quantity, and the first quantity is used to indicate the number of functional modules that are using the memcg; after creating the memory manager memcg corresponding to the application, the method further includes: in response to the completion of the creation of the second data structure, the value of the first quantity is increased by one; after determining that the second data structure has been released, the method further includes: subtracting one from the value of the first quantity; when the value of the first quantity is 0, it is determined that the memcg is in an unused state.

[0012] The above-mentioned first number can be the number of css references in the memcg data structure. Whether the number of css references is zero is also the condition for the native code to decide whether to release the first data structure. In the above embodiment, after the second data structure is created, by increasing the value of the number of css references, the process of blocking the release of the first data structure before the second data structure is released is achieved while reducing the amount of code program changes.

[0013] In some embodiments, the code data in the universal kernel image includes a first jump function, and the first jump function indicates the code data in the form of the kernel object used to create the second data structure; the creation of the memory manager memcg corresponding to the application includes: in the process of creating the first data structure according to the code data in the universal kernel image, creating the second data structure based on the code data in the form of the kernel object indicated by the first jump function.

[0014] In some embodiments, before the asynchronous release of the first memory page and the second memory page, the method further includes: starting the release of the memcg, wherein the code data for releasing the memcg in the universal kernel image includes a second jump function, and the second jump function indicates the first code data in the form of the kernel object for creating an asynchronous thread; in the process of starting the release of the memcg, based on the first code data indicated by the second jump function, creating the asynchronous thread, and the asynchronous thread is used to detect the release of the second memory page.

[0015] In the above embodiment, asynchronous threads are used to enable the release of memory pages managed by the first data structure and the release of memory pages managed by the second data structure to be performed asynchronously, thereby reducing the release time of the memory pages and improving the release efficiency of memcg.

[0016] In some embodiments, after the asynchronous release of the first memory page and the second memory page, the method further includes: determining that the second memory page has been released when the asynchronous thread detects that the memory page linked list in the second data structure is empty.

[0017] In some embodiments, when the asynchronous thread detects that the memory page linked list in the second data structure is not empty, it sleeps for a first period of time; after the asynchronous thread sleeps for the first period of time, it repeatedly detects whether the memory page linked list in the second data structure is empty.

[0018] In some embodiments, the first storage space is a system memory in an internal memory of the electronic device, and the second storage space is a swap partition and an external memory in the internal memory of the electronic device.

[0019] In some embodiments, the first memory page includes an anonymous page and a file page corresponding to the application, and the second memory page includes a compressed anonymous page corresponding to the application.

[0020] In a second aspect, an electronic device provided by an embodiment of the present application includes one or more processors and a memory; the memory is coupled to the processor, the memory is used to store computer program code, the computer program code includes computer instructions, and when one or more processors execute the computer instructions, the one or more processors are used to: in response to the start-up of the application, create a memory manager memcg corresponding to the application; the memcg corresponds to a first data structure and a second data structure, the first data structure is a data structure created based on the code data in the universal kernel image, and is used to manage the first memory page of the application in the first storage space; the second data structure is a data structure created based on the code data in the form of a kernel object, and is used to manage the second memory page of the application in the second storage space; in response to the stop of the application, the first memory page and the second memory page are asynchronously released; after determining that the second memory page has been released, the second data structure is released; when the second data structure has been released, it is determined that the memcg is in an unused state, and the first memory page has been released, a first function is called to release the first data structure.

[0021] In some embodiments, the condition for calling the first function is not satisfied until the second data structure is released.

[0022] In some embodiments, the first data structure includes a first quantity, and the first quantity is used to indicate the number of functional modules that are using the memcg; after creating the memory manager memcg corresponding to the application, the one or more processors are also used to: in response to the completion of the creation of the second data structure, increase the value of the first quantity by one; after determining that the second data structure has been released, the method also includes: subtracting the value of the first quantity by one; when the value of the first quantity is 0, determining that the memcg is in an unused state.

[0023] In some embodiments, the code data in the universal kernel image includes a first jump function, and the first jump function indicates the code data in the form of the kernel object used to create the second data structure; the one or more processors are also used to: in the process of creating the first data structure according to the code data in the universal kernel image, create the second data structure based on the code data in the form of the kernel object indicated by the first jump function.

[0024] In some embodiments, before the asynchronous release of the first memory page and the second memory page, the one or more processors are further used to: start the release of the memcg, wherein the code data for releasing the memcg in the universal kernel image includes a second jump function, and the second jump function indicates the first code data in the form of the kernel object for creating an asynchronous thread; in the process of starting the release of the memcg, based on the first code data indicated by the second jump function, create the asynchronous thread, and the asynchronous thread is used to detect the release of the second memory page.

[0025] In some embodiments, after the asynchronous release of the first memory page and the second memory page, the one or more processors are further used to: determine that the second memory page has been released when the asynchronous thread detects that the memory page linked list in the second data structure is empty.

[0026] In some embodiments, when the asynchronous thread detects that the memory page linked list in the second data structure is not empty, it sleeps for a first period of time; after the asynchronous thread sleeps for the first period of time, it repeatedly detects whether the memory page linked list in the second data structure is empty.

[0027] In some embodiments, the first storage space is a system memory in an internal memory of the electronic device, and the second storage space is a swap partition and an external memory in the internal memory of the electronic device.

[0028] In some embodiments, the first memory page includes an anonymous page and a file page corresponding to the application, and the second memory page includes a compressed anonymous page corresponding to the application.

[0029] In a third aspect, an embodiment of the present application provides a computer storage medium, including computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method in the above-mentioned first aspect and possible embodiments thereof.

[0030] In a fourth aspect, the present application provides a computer program product. When the computer program product is run on the above-mentioned electronic device, the electronic device executes the method in the above-mentioned first aspect and possible embodiments thereof.

[0031] It can be understood that the electronic devices, computer storage media and computer program products provided in the above-mentioned aspects are all applied to the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1A schematic diagram of the logical structure of memcg provided in an embodiment of the present application;

[0033] Figure 2 An example diagram of the logical structure of memcg configured with hook points provided in an embodiment of the present application;

[0034] Figure 3 An example diagram of the principle of indirectly modifying native code through a hook point provided in an embodiment of the present application;

[0035] Figure 4 An example diagram of the structure of a mobile phone provided in an embodiment of the present application;

[0036] Figure 5 This is a flowchart of the steps of the method for releasing memcg in an embodiment of the present application;

[0037] Figure 6 For use Figure 5 An example diagram of changes in the number of CSS references of the first data structure during the method shown;

[0038] Figure 7 An example diagram of blocking the release of a first data structure after establishing a second data structure provided in an embodiment of the present application;

[0039] Figure 8 For Figure 7 Based on the above, a flowchart of the method for releasing memcg provided in an embodiment of the present application is provided;

[0040] Fig. 9 For use Figure 8 An example diagram of changes in the number of CSS references of the first data structure during the method shown;

[0041] Fig.10 This is an example diagram of memcg release provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] The technical scheme in the embodiment of the present application will be described below in conjunction with the drawings in the embodiment of the present application. Wherein, in the description of the present application, unless otherwise specified, "at least one" refers to one or more, and "a plurality of" refers to two or more than two. In addition, in order to facilitate the clear description of the technical scheme of the embodiment of the present application, in the embodiment of the present application, the words "first", "second" and the like are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art will understand that the words "first", "second" and the like do not limit the quantity and execution order, and the words "first", "second" and the like do not limit necessarily different.

[0043] For ease of understanding, the technical terms involved in the embodiments of the present application are first introduced below.

[0044] Internal storage, also known as memory, includes logical memory (also known as virtual memory) and physical memory. Physical memory can be used to store page data corresponding to applications. In addition, memory can include system memory (such as called the first storage space) and swap partition. In a system built on the Linux kernel, page data is mainly stored in system memory in the form of file-backed pages and anonymous pages.

[0045] External memory is the "external memory" relative to the internal memory of electronic devices. Among them, external memory can include read-only memory (ROM), hard disk, floppy disk, CD, USB flash drive, embedded multimedia card (embedded multimedia card, emmc), universal flash storage (universal flash storage, UFS), multimedia card, etc.

[0046] The above anonymous pages and file pages can be collectively referred to as memory pages.

[0047] Among them, anonymous pages are memory pages that are not marked with names by the operating system. The virtual memory address (VMA) cannot distinguish different anonymous pages by name. In this way, memory pages without name tags are called anonymous pages. When anonymous pages are recycled, in order for the kernel to be able to access the corresponding anonymous pages later, the anonymous pages cannot be directly released (i.e. deleted) in the system memory. They need to be swapped out from the system memory to the Swap partition for compressed storage. The data in the Swap partition can be accessed by the CPU. Anonymous pages specifically refer to system memory pages that are dynamically allocated during program execution, including heaps, stacks, data segments, etc.

[0048] File pages, the operating system provides memory pages with name tags, and the corresponding file names are recorded on the VMA. Different file pages can be distinguished according to the file names. The system memory pages with name tags are called file pages. When the file page is recycled, the file page can be directly released (that is, deleted) in the system memory. Afterwards, the kernel can load the file page from the external memory to the system memory according to the file name of the file page, and then read it. File pages specifically refer to memory pages that store file-type data, including code segments, library files, and file data accessed by program interactions.

[0049] Taking the scenario of an electronic device playing music as an example, the system memory occupied by the program data of the electronic device running the player belongs to anonymous pages, and the system memory occupied by the music files loaded from the electronic device from the external storage into the system memory belongs to file pages.

[0050] zram, also known as zRAM, is a function of the CPU core that provides virtual memory compression. For example, the zram function compresses anonymous pages swapped out to the swap partition.

[0051] Currently, electronic devices can create a memcg for each application through a memory manager (memory cgroup, memcg) mechanism to manage the memory pages of the application. Each running application corresponds to a memcg.

[0052] Exemplarily, the memcg corresponds to at least one least recently used (LRU) linked list. The memory page corresponding to the memcg, such as the first memory page, can be found through the LRU linked list corresponding to the memcg.

[0053] It is understandable that electronic devices can use memcg to manage the memory pages of applications. For example, when there is insufficient memory in an electronic device, memcg can be used to determine the target anonymous page whose data is not updated or updated slowly in the anonymous page corresponding to the application running in the background or kept alive for a long time. Then, the target anonymous page is swapped out from the system memory to the swap partition and compressed to reduce the size of the memory space occupied by the target anonymous page, thereby reclaiming part of the memory space occupied by the application.

[0054] In some embodiments, Figure 1 As shown, memcg may include a memcg data structure (struct) and a plurality of function functions for managing the life cycle of memcg.

[0055] Among them, the above-mentioned memcg data structure can be called the first data structure. Among them, the first data structure includes corresponding memory resource control statistical information (cgroup_subsys_state, css), and the css contains a field indicating a reference counter, which carries the number of references, indicating the number of times the memcg is currently referenced. Of course, the first data structure can also include other types of data, for example, it can also include information indicating memcg (used to establish a corresponding relationship between the first data structure and memcg), LRU linked list information, etc., please refer to the relevant technology for details and will not be repeated here. In this way, the first data structure can contain multiple types of data, which can be used to indicate the corresponding memcg.

[0056] In addition, the above-mentioned multiple function functions can also be called memcg operation sets. Different function functions can call kernel code segments that implement different functions to achieve different types of management of the life cycle of memcg.

[0057] For example, the above multiple functions may include:

[0058] 1) A function (mem_cgroup_alloc) used to create a memcg corresponding to an application may be referred to as function 1.

[0059] 2) A function (css_tryget_online) for indicating that the number of references of css (also referred to as the number of css references, or the first number) is increased by one, such as referred to as function function 2. This function function 2 is usually called when a function module in the kernel requests to use memcg and executes corresponding management matters. Among them, the above-mentioned management matters may include managing the memory space occupied by the application (such as recycling the system memory occupied by the memory page of the application), migrating memory pages, modifying the control field corresponding to memcg, etc., and the specific reference to the relevant technology will not be repeated here.

[0060] 3) A function (css_put) used to indicate that the number of css references is reduced by one, such as function 3. Function 3 and function 2 need to be called in pairs. For example, when a function module in the kernel layer requests to use memcg to perform corresponding management tasks, function 2 can be called to increase the number of css references of memcg by one. Afterwards, if the function module has completed the corresponding management tasks, memcg needs to be released, and function 3 is called to reduce the number of css references of memcg by one.

[0061] 4) A function (css_cgroup_online) for associating memcg with the cgroup corresponding to the application, such as function 4. In the cgroup corresponding to the application, in addition to associating memcg for managing memory resources, subsystems for managing other types of resources may also be associated.

[0062] 5) A function (css_offline, such as function 5) used to trigger the release of memcg.

[0063] 6) A function for releasing the memcg data structure (mem_cgroup_free, such as function 6), etc. The kernel may call function 6 to release the first data structure when function 5 has been called and the number of references corresponding to css is 0.

[0064] For an electronic device configured with an operating system of a Linux kernel, a set of kernel codes corresponding to memcg is configured in the operating system, such as native codes (code data associated with memcg that comes with the operating system).

[0065] Without modifying the native code, the electronic device can manage the life cycle of memcg in the manner indicated by the native code, and manage the memory pages of the application in the system memory (the part of the electronic device's memory excluding the swap partition) through memcg, that is, the management scope of memcg is the system memory.

[0066] When the native code is modified, the management scope of memcg can be extended to the swap partition and external memory, where the swap partition and external memory can be collectively referred to as the second storage space. It can be understood that when the management scope is extended to the swap partition and external memory, the electronic device can also manage it through memcg after compressing the target anonymous page to the swap partition. In this way, the electronic device can also transfer the target anonymous page in the swap partition to the external memory to further release the memory resources of the electronic device. In addition, after the target anonymous page is swapped out to the external memory, it can also be managed through memcg.

[0067] Most device manufacturers will choose to modify the native code to extend the storage range that can be managed by memcg and improve the effective usage of memory in electronic devices.

[0068] However, when GKI is enabled in an electronic device, the kernel code of the electronic device belongs to the code data in the general kernel image and cannot be modified directly. Thus, the native code corresponding to mencg also belongs to the code data in the general kernel image and cannot be modified directly.

[0069] Of course, if Figure 2 As shown, a hook point can be added to the native code. During the process of the kernel executing the native code, the hook point can instruct the kernel to jump to execute the newly added code (such as code data in the form of kernel objects), and the newly added code can expand the management scope of memcg to the swap partition and external memory.

[0070] Among them, the above-mentioned newly added code can be code data in the form of kernel object (KO), which does not need to be embedded in the native code. It is loaded into the memory when it is needed and unloaded from the memory when it is not needed. In this way, the native code can be indirectly modified. In this way, the native part of memcg can be created based on the native code, which is responsible for managing the memory pages of the application in the system memory. Based on the newly added code, the extended part of memcg can be created, which is responsible for managing the compressed pages (anonymous pages swapped out from the system memory to the swap partition and compressed) and transfer pages (compressed pages swapped out from the swap partition to the external memory) of the application in the swap partition and external memory. The above-mentioned compressed pages and transfer pages can also be called second memory pages.

[0071] In some embodiments, the hook points may include data hook points and function hook points.

[0072] For example, Figure 2 As shown, the data hook point can be a pointer, which can indicate a jump to access another data structure. For example, the data hook point can be configured in the memcg data structure (ie, the first data structure) to indicate a jump to access another data structure, such as the second data structure.

[0073] For example, in the process of indirectly modifying the native code, a hook point for jumping to access the second data structure can be configured in the first data structure, wherein the second data structure corresponds to the same memcg as the first data structure, and the second data structure can be an extension of the first data structure. The first data structure is related to the native code of memcg and includes the data types involved in the native code corresponding to memcg. The second data structure is related to the newly added code of memcg and includes the data types involved in the newly added code corresponding to memcg.

[0074] In addition, the second data structure may include information indicating memcg (used to associate with memcg), compressed page linked list information, transferred page linked list information, zram data, transferred data, transfer times, etc. The multi-type data corresponding to the second data structure is suitable for implementing the newly added code for expanding the storage range managed by memcg.

[0075] As another example, the function hook point may indicate a control flow transfer, and the function hook point may be configured in the native code. In this way, the kernel may jump to execute the newly added code during the execution of the native code.

[0076] like Figure 2 As shown, a function hook point is configured in the native code corresponding to the function function 1, such as called the first jump function. The function hook point can indicate the jump execution of the new code corresponding to the new function function 1, which can realize the creation of the extended part of memcg, for example, creating a second data structure.

[0077] by Figure 3For example, in response to the running of the application, the function 1 of memcg can be called. In this way, after calling the function 1 of memcg, the native code corresponding to the function 1 can be executed to create the first data structure. If a function hook point is configured in this part of the native code, and when the function hook point is executed, the newly added function 1 indicated by the function hook point is jumped to execute, and the newly added code corresponding to the newly added function 1 can create the second data structure. After executing the newly added code corresponding to the newly added function 1, return to continue to execute the unexecuted part of the native code corresponding to the function 1.

[0078] Of course, the number and location of the function hook points configured in the native code corresponding to memcg can be determined according to the actual situation. In this way, in addition to the hook points that can be configured in the native code corresponding to function 1, the corresponding hook points can also be configured in the native code of other function functions to indirectly modify the native code.

[0079] When a hook point is configured in the native code corresponding to memcg, when releasing all the memory space managed and occupied by memcg, it is easy to encounter the problem that the first data structure is released but the second data structure is not released.

[0080] It can be understood that the release and creation of the second data structure are not controlled by the native code, while the release and creation of the first data structure are controlled by the native code. In addition, the release condition of the first data structure is that the number of css references is 0, and the release condition of the second data structure is that the corresponding compressed page and transfer page are cleared, and there is no necessary connection between the two. In this way, after the electronic device releases the first data structure, the problem of the second data structure not being successfully released may occur. That is, not only will the data hook point originally pointing from the first data structure to the second data structure become a wild pointer, but there may also be problems such as memory leaks and memcg management exceptions.

[0081] In order to improve the above problems, an embodiment of the present application provides a memory manager management method, which can be applied to electronic devices.

[0082] Exemplarily, the electronic device may be a mobile phone, a tablet computer, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), an augmented reality (AR) or a virtual reality (VR) device, etc. The embodiment of the present application does not impose any special restrictions on the specific form of the electronic device. In the subsequent embodiments, a mobile phone configured with a Linux kernel is mainly used as an example for explanation.

[0083] Please refer to Figure 4 , is a structural diagram of a mobile phone provided in an embodiment of the present application.

[0084] like Figure 4 As shown, the mobile phone may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

[0085] Among them, the above-mentioned sensor module 180 may include sensors such as pressure sensor, gyroscope sensor, air pressure sensor, magnetic sensor, acceleration sensor, distance sensor, proximity light sensor, fingerprint sensor, temperature sensor, touch sensor, ambient light sensor and bone conduction sensor.

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

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

[0088] The controller can be the nerve center and command center of the mobile phone. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0089] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0090] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0091] It is understandable that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation on the mobile phone. In other embodiments, the mobile phone may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0092] The mobile phone implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0093] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the mobile phone. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos can be stored in the external memory card.

[0094] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The internal memory 121 may include a program storage area and a data storage area. In addition, the internal memory 121 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 110 executes various functional applications and data processing of the mobile phone by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.

[0095] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc.

[0096] The mobile phone can realize the shooting function through ISP, camera 193, video codec, GPU, display 194 and application processor.

[0097] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.

[0098] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the mobile phone may include N cameras 193, where N is a positive integer greater than 1.

[0099] Digital signal processors are used to process digital signals. In addition to processing digital image signals, they can also process other digital signals. For example, when a mobile phone selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

[0100] Video codecs are used to compress or decompress digital videos. A mobile phone can support one or more video codecs. In this way, the mobile phone can play or record videos in multiple coding formats, such as: Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0101] NPU is a neural network (NN) computing processor. It can quickly process input information and continuously self-learn by drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain. NPU can realize applications such as intelligent cognition of mobile phones, such as image recognition, face recognition, voice recognition, text understanding, etc.

[0102] On top of the above components, a software system developed based on the Linux kernel is run. Among them, the above software system can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture, etc. In the embodiment of the present application, the Android system of the layered architecture is taken as an example to illustrate the software system architecture of the mobile phone. Exemplarily, the software system architecture of the above mobile phone includes at least a kernel layer. The kernel layer includes at least a memory management module, which can execute the native code corresponding to memcg to create the memcg corresponding to the application, and manage the memory pages of the application corresponding to memcg in the system memory. In addition, the memory management module can also jump to execute the newly added code according to the hook point in the native code during the execution of the native code, and mount the compressed page of the application (anonymous page compressed to the swap partition) on the compressed page linked list corresponding to memcg, and the dump page of the application (anonymous page compressed and dumped to the external memory) is mounted on the dump page linked list corresponding to memcg, so that the space occupied by the application in the swap partition and the external memory can be managed by memcg.

[0103] The following describes the implementation details of releasing memcg by the electronic device in an embodiment of the present application in conjunction with the accompanying drawings.

[0104] In some embodiments, when any application or service is started in an electronic device, a memcg corresponding to the application can be created. According to the native code corresponding to the memcg, the native part of the created memcg can manage the memory pages of the application in the system memory. In this way, after the memcg is created, the memory resources allocated to the application can be associated with the LRU corresponding to the memcg, which is convenient for management. In addition, after the memcg is created, the first data structure is loaded in the memory of the electronic device.

[0105] As an implementation method, in the scenario of starting and running the application, in response to starting and running the application, the memory management module can execute function 1 (mem_cgroup_alloc) in the native code to create a first data structure. The first data structure includes the number of css references.

[0106] It is understandable that in addition to the memory management module for managing memcg, the kernel layer of the electronic device also includes other functional modules. Different functional modules have different functions, such as a functional module for reclaiming memory space, a functional module for migrating memory space occupied by various applications, a functional module for modifying the control field of memcg, etc.

[0107] The above-mentioned functional modules can request the memory management module to use memcg and perform corresponding management matters. For example, the functional module for managing memory space can request the memory management module to use memcg and execute the recovery of memory space occupied by memory pages managed by memcg. In this scenario, the function function 2 (css_tryget_online) can be called by the memory management module to increase the number of CSS references of memcg corresponding to the application by one, indicating that a new functional module is using the memcg and performing corresponding management matters. In the case where no functional module uses memcg, the initial value of the corresponding number of CSS references can be 0. In some embodiments, in the case where no functional module uses memcg, it can be said that memcg is in an unused state. In other embodiments, when the number of CSS references is 0, it can be determined that memcg is in an unused state.

[0108] In addition, after the above-mentioned functional module executes the corresponding management matters based on the memcg, the function 3 (css_put) can be called through the memory management module to reduce the number of css references of the memcg corresponding to the application by one, indicating that one functional module using memcg is reduced.

[0109] When the number of css references is 0, the first data structure is eligible for release.

[0110] In some embodiments, a hook point is configured in the native code corresponding to memcg, and the above hook point can instruct the jump to execute the newly added code (to expand the management scope of memcg to the code data of the swap partition and external memory). Before the function 1 (mem_cgroup_alloc) called by the memory management module returns the execution result, the hook can instruct the memory management module to jump to execute the newly added code and create a second data structure corresponding to the first data structure.

[0111] In this way, after memcg is created, the second data structure is also loaded in the memory of the electronic device. In some embodiments, when the electronic device closes the application, it is also necessary to release the memcg corresponding to the application. It can be understood that the above-mentioned release of the memcg corresponding to the application may include releasing the storage resources (including system memory, swap partition and external memory, etc.) occupied by the memory pages, compressed pages and transfer pages managed by memcg and releasing the first data structure and the second data structure corresponding to memcg.

[0112] In some embodiments, after the application stops running, the electronic device releases the process of memcg, such as Figure 5 As shown:

[0113] S1, calls function 5 to release memcg.

[0114] In some embodiments, after the memory management module calls function function 5, the native function corresponding to function function 5 can be executed. After executing the native function corresponding to function function 5, not only can the memory page managed by memcg be released, but also the function module in the electronic device can be blocked from using memcg. In this way, when the function module of the electronic device calls function function 2, the call fails. The function module in the kernel layer cannot request to use memcg. At the same time, the function module that is using memcg will also trigger the call of function function 3 after the corresponding management matters are executed, and the number of css references in the first data structure will be reduced by one.

[0115] for example, Figure 6 As shown, before the memory management module calls function 5, function module 1 and function module 2 are using memcg to perform corresponding management matters. In this scenario, the number of css references in the first data structure of memcg is 2.

[0116] In some embodiments, after calling function function 5, the number of css references in the first data structure can be increased by 1, indicating that the memory pages of memcg in the system memory will be gradually released. After that, other function modules can no longer request to use memcg, that is, the number of css references is 3 at this time and will not increase. During this period, if function module 3 requests the memory management module to use memcg, the request will fail. That is, function module 3 can call function function 2 through the memory management module, but the call will fail. In this way, even if the memory management module calls function function 2, the number of css references in the first data structure is still 3.

[0117] In addition, after calling function 5, the number of css references increases by "1", indicating that the function module for releasing the memory page of memcg in the system memory is using memcg to execute the memory page release. In this way, it is necessary to reduce "1" after the memory page of memcg in the system memory is released.

[0118] In some other embodiments, after calling function 5, the number of css references in the first data structure may no longer increase. As other functional modules release the use of memcg, css may gradually decrease to 0.

[0119] Of course, after the memory management module calls function 5, function module 1 can normally release the use of memcg and instruct the memory management module to call function 3 after executing corresponding management matters based on memcg. After function function 3 is called, the number of css references of the first data structure becomes 2. Similarly, after function module 2 executes corresponding management matters based on memcg, it can also normally instruct the memory management module to call function function 3. After function function 3 is called again, the number of css references of the first data structure becomes 1. In this way, after the memory pages of memcg in the system memory are released, the memory management module can also be instructed to call function function 3. After function function 3 is called again, the number of css references of the first data structure becomes 0.

[0120] In short, after calling function 5, the number of css references corresponding to memcg will gradually decrease to 0. Of course, Figure 6 Only the scenario where function module 1 and function module 2 execute the corresponding management items in sequence is shown. In actual application scenarios, there may be many situations in which the order in which each function module executes the corresponding management items. Of course, any function module that executes the corresponding management items can trigger the number of css references to be reduced by one. Of course, the release of the memory pages of memcg in the system memory can also trigger the number of css references to be reduced by one. In addition, there is no necessary order between the time point when the memory pages of memcg in the system memory are released and the time point when the function module executes the corresponding management items. Figure 6 This is just an exemplary scenario.

[0121] S2, checking whether the number of css references in the first data structure corresponding to memcg is 0.

[0122] In some embodiments, if the number of css references is not 0, the process goes to S3. If the number of css references is 0, the process goes to S4.

[0123] S3, after a specified time interval, check again whether the number of css references in the first data structure corresponding to memcg is 0.

[0124] In some embodiments, after a specified time interval, the process may enter S2 again to implement a cyclic query of the number of css references in the first data structure.

[0125] S4, calling function 6 to instruct to release the first data structure.

[0126] It can be understood that after function 5 has been called and the number of css references in the first data structure is 0, according to the provisions of the native code, the memory management module needs to call function 6 to release the first data structure.

[0127] In other embodiments, after calling function 5, in the scenario where the number of css references no longer increases, it is determined that the number of css references is 0, and under the condition that all memory pages of memcg in the system memory are released, function 6 can be called to release the first data structure. In an embodiment of the present application, during the creation of the second data structure, or after the creation of the second data structure, the number of css references corresponding to memcg can be increased by one. After the second data structure is released, the number of css references corresponding to memcg is reduced by one. In this way, when the second data structure still exists in the memory of the electronic device, the process of the electronic device releasing the first data structure can be blocked to avoid the situation where the first data structure is released but the second data structure has not been released, thereby improving the problems of wild pointers and memory leaks.

[0128] As an implementation method, in the process of creating the second data structure, the memory management module can be triggered to call function 2 (css_tryget_online) to increase the number of css references corresponding to memcg by 1. The "1" added to the number of css references this time needs to be released before function 3 (css_put) can be called to subtract the above "1". For the specific process, please refer to the description in the subsequent embodiments.

[0129] In another implementation, after memcg is created, the memory management module can call function 4 (css_cgroup_online) to associate the created memcg with the cgroup corresponding to the application. Figure 7 As shown, the memory management module can call function 4, and in the process of executing the native code corresponding to function 4, the newly added function 4 can be called by configuring the hook point in the native code. In this way, the newly added code corresponding to the newly added function 4 can be jumped to execute, so as to trigger the memory management module to call function 2 (css_tryget_online) and increase the number of css references corresponding to memcg by one. The "1" added to the number of css references this time needs to be released after the second data structure is released before function 3 (css_put) can be called to subtract the above "1". For the specific process, please refer to the description in the subsequent embodiments.

[0130] Thus, after memcg is created, or after memcg is associated with the cgroup of the application, even if no functional module uses the memory resources managed by memcg, the corresponding css reference count value is 1. Correspondingly, the electronic device releases memcg in the process, for example, after the application stops running, such as Figure 8 As shown:

[0131] S101, calling function 5 indicating the release of memcg, and executing the native code corresponding to function 5.

[0132] In some embodiments, the memory management module may call function function 5 (such as referred to as the first function) to execute the native code corresponding to function function 5. Exemplarily, the native code corresponding to function function 5 may be configured with a hook point (such as referred to as the second jump function), which may instruct the memory management module to jump to execute the newly added code for creating an asynchronous thread (such as referred to as the first code data in the form of a kernel object) and the newly added code for instructing to start releasing the swap partition and external memory managed by memcg. The swap partition and external memory managed by memcg refer to the storage space occupied by the compressed pages and dumped pages of the application corresponding to memcg in the swap partition and external memory.

[0133] In this way, in the process of executing the native code corresponding to function 5, it is possible to create an asynchronous thread and release the storage space occupied by the application in the swap partition and external memory, such as releasing the compressed pages on the compressed page list belonging to memcg and the transfer pages on the transfer page list.

[0134] After the asynchronous thread is created, the process enters S102.

[0135] After creating an asynchronous thread and starting to release the storage space occupied by the application in the swap partition and external memory, the unexecuted code in the native code corresponding to function 5 can continue to be executed to release the system memory managed by memcg and block the functional modules in the electronic device from using the system memory managed by memcg. The process enters S104.

[0136] In some embodiments, the above S102 and S104 may be executed asynchronously, and there is no necessary order between the two.

[0137] S102, after calling the function 5 indicating the release of memcg, periodically checking whether the swap partition and external memory managed by memcg have been released.

[0138] After calling the function 5 indicating the release of memcg, the system memory, swap partition and partition managed by memcg can be asynchronously released. For example, the storage space occupied by the compressed pages and dump pages of the application corresponding to memcg can be triggered by calling the interface of the swap partition. Each time a compressed page (or dump page) is released, it can be deleted from the compressed page linked list (or, dump page linked list) of memcg. The above-mentioned compressed page linked list and dump page linked list can be called memory page linked list.

[0139] In some embodiments, an asynchronous thread may be used to detect whether the swap partition and external memory managed by memcg have been released.

[0140] Exemplarily, after the asynchronous thread is created, the asynchronous thread can check the compression page linked list information and the transfer page linked list information in the second data structure. If the compression page linked list information indicates that there is no compression page on the compression page linked list and the transfer page linked list information indicates that there is no transfer page on the transfer linked list, it is determined that the swap partition and external memory managed by memcg have been released, and the process enters S103. If the compression page linked list information indicates that there is a compression page on the compression page linked list or the transfer page linked list information indicates that there is a transfer page on the transfer linked list, it is determined that the swap partition and external memory managed by memcg have not been released, and the asynchronous thread can sleep for a preset time (such as called the first time), and then repeatedly check the compression page linked list information and the transfer page linked list information in the second data structure until it is determined that the swap partition and external memory managed by memcg have been released.

[0141] S103: when it is determined that the swap partition and the external memory managed by memcg have been released, the number of css references in the first data structure is reduced by one.

[0142] In some embodiments, the memory management module may call function 3 to reduce the number of css references in the first data structure by 1. In addition, when it is determined that the swap partition and external memory managed by memcg have been released, the second data structure may also be released.

[0143] S104, after calling the function 5 indicating the release of memcg, checking whether the number of css references in the first data structure is 0.

[0144] S105, determining that the number of css references is not 0, and after a specified time interval, checking again whether the number of css references in the first data structure corresponding to memcg is 0.

[0145] by Fig. 9For example, during the creation of memcg, the number of css references of the first data structure has been increased by one. In this way, after both function module 1 and function module 2 request to use the memcg, the number of css references in the first data structure is 3. After calling function function 5 provided by memcg, the number of css references in the first data structure can be increased by 1, indicating that the memory pages of memcg in the system memory will be gradually released. Before the system memory pages are released, the corresponding first data structure cannot be released. After function function 5 is called, other function modules can no longer request to use memcg, that is, the number of css references is 4 at this time and will not increase. During this period, if function module 3 requests the memory management module to use memcg, the request will fail. That is, function module 3 instructs to call function function 2, and the call will fail. In this way, even if the memory management module calls function function 2, the number of css references of the first data structure is still 4.

[0146] In the example scenario, before S103 is executed, after function module 1 executes corresponding management matters based on memcg, it can release the reference to memcg and instruct the memory management module to call function function 3. After function function 3 is called for the first time, the number of css references of the first data structure becomes 3. Similarly, after function module 2 executes corresponding management matters based on memcg, it can also instruct the memory management module to call function function 3. After function function 3 is called for the second time, the number of css references of the first data structure becomes 2. In addition, after the memory page corresponding to memcg in the system memory is released, the memory management module can also be instructed to call function function 3. After function function 3 is called for the third time, the number of css references of the first data structure becomes 1.

[0147] In the example scenario, after S103 is executed, function module 1 and function module 2 have completed the corresponding management tasks, and the system memory pages, compressed pages, and dumped pages managed by memcg have been released, and the number of css references of the first data structure can be 0. Of course, before S103 is executed, or function module 1 and function module 2 have not completed the corresponding management tasks, or the system memory pages, compressed pages, or dumped pages managed by memcg have not been released, the number of css references of the first data structure will not be 0.

[0148] In short, after calling function 5, when the number of css references of the first data structure is 0, it indicates that the second data structure in the current electronic device has been released, the current memcg is not used by other functional modules, and the memory page of memcg in the system memory has been released. In this scenario, the first data structure can be released.

[0149] S106, determining that the number of css references is 0, and releasing the first structure data.

[0150] In some embodiments, function function 6 may be called to execute native code corresponding to function function 6 to release the first structure data.

[0151] As a way to achieve this, Fig.10 As shown, when calling the function css_offline, there is a function hook point in the native code corresponding to css_offline. In the process of executing the native code corresponding to css_offline, the function hook point can be used to jump to execute memcg_ext_release_kworker_init (new code) to create an asynchronous thread. After the asynchronous thread is created, the function hook point indicates to return to execute the native code corresponding to css_offline. After the execution of the native code corresponding to css_offline is completed, check whether the number of css references is 0.

[0152] As described in the above embodiment, during the creation of memcg, "1" will be added to the number of css references, and the added "1" needs to be subtracted after the compressed page and the dump page of the application are released. In this way, the number of css references will always be greater than 0 before it is determined that the compressed page and the dump page corresponding to the application are released.

[0153] In addition, the asynchronous thread can detect the release of the compressed page and the transfer page of the application. For example, after the asynchronous thread is created, the asynchronous thread can detect whether the compressed page list and the transfer page list of memcg are both empty. If any one of the compressed page list and the transfer page list of memcg is not empty, the asynchronous thread sleeps for a preset time, and then wakes up to detect again whether the compressed page list and the transfer page list of memcg are both empty. If both the compressed page list and the transfer page list of memcg are empty, the second data structure can be released. In addition, the asynchronous thread reduces the number of css references in the first data structure by "1". In this way, as the functional module releases the use of memcg, the number of css references will gradually decrease until it reaches 0.

[0154] In this way, although the asynchronous thread does not affect the release process of the memory page, dump page and compressed page of memcg, it can affect the value of the css reference count, that is, it will affect the judgment result of "detecting whether the value of the css reference count is 0". For example, after the asynchronous thread detects that the dump page and the compressed page have been released, the judgment result of "detecting whether the value of the css reference count is 0" may include "detecting that the value of the css reference count is 0". Before the asynchronous thread detects that the dump page and the compressed page have been released, the judgment result of "detecting whether the value of the css reference count is 0" does not include "detecting that the value of the css reference count is 0".

[0155] When the number of css references is not 0, for example, the compressed pages and dumped pages of the application are not completely released, or the functional module has not released the use of memcg, after a specified interval, check again whether the number of css references in the first data structure corresponding to memcg is 0.

[0156] When the number of css references is 0, for example, the function module has released the use of memcg, and the compression page and the dump page of the application are all released, the function mem_cgroup_free is called to release the first data structure.

[0157] In some embodiments, after releasing the compressed page and the dumped page of the application, the asynchronous thread triggers the CSS reference count to decrease by 1, and triggers the release of the second data structure. In this way, before releasing the first data structure, the second data structure can be released first to avoid memory leaks after the first data structure is released.

[0158] In this way, when any application is started, the electronic device will create a corresponding memcg. The number of css references in the first data structure of the created memcg is set to 1. The system memory allocated to the application is mounted on the LRU linked list corresponding to the memcg for management. Afterwards, any functional module requests to use the system memory managed by memcg, the corresponding number of css references is increased by 1, and the functional module releases the requested system memory, and the corresponding number of css references is reduced by 1. During this period, the number of css references of memcg is not less than 1. When the electronic device closes the application, after the compressed page and the transfer page corresponding to the application are released, the number of css references will be triggered to decrease by one.

[0159] The embodiment of the present application also provides an electronic device, which may include: a memory and one or more processors. The memory is coupled to the processor. The memory is used to store computer program code, and the computer program code includes computer instructions. When the processor executes the computer instructions, the electronic device can execute the various steps executed by the mobile phone in the above embodiment. Of course, the electronic device includes but is not limited to the above memory and one or more processors.

[0160] The embodiment of the present application also provides a chip system, which can be applied to the terminal device in the aforementioned embodiment. The chip system includes at least one processor and at least one interface circuit. The processor can be the processor in the above-mentioned electronic device. The processor and the interface circuit can be interconnected through a line. The processor can receive and execute computer instructions from the memory of the above-mentioned electronic device through the interface circuit. When the computer instructions are executed by the processor, the electronic device can execute the various steps executed by the mobile phone in the above-mentioned embodiment. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiment of the present application.

[0161] In some embodiments, through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0162] Each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0163] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk.

[0164] The above is only a specific implementation of the embodiment of the present application, but the protection scope of the embodiment of the present application is not limited thereto, and any changes or replacements within the technical scope disclosed in the embodiment of the present application should be included in the protection scope of the embodiment of the present application. Therefore, the protection scope of the embodiment of the present application should be based on the protection scope of the claims.

Claims

1. A method for managing a memory manager, characterized in that: Applied to an electronic device that enables a universal kernel image, the method comprises: In response to the start-up and operation of the application, a memory manager memcg corresponding to the application is created; the memcg corresponds to a first data structure and a second data structure, the first data structure is a data structure created based on the code data in the universal kernel image, and is used to organize a first memory page of the application in the first storage space; the second data structure is a data structure created based on the code data in the form of a kernel object, and is used to organize a second memory page of the application in the second storage space; In response to the application program stopping running, asynchronously releasing the first memory page and the second memory page; After determining that the second memory page has been released, releasing the second data structure; When the second data structure has been released, it is determined that the memcg is in an unused state, and the first memory page has been released, a first function is called to release the first data structure.

2. The method according to claim 1, characterized in that Before the second data structure is released, the condition for calling the first function is not satisfied.

3. The method according to claim 1 or 2, characterized in that: The first data structure includes a first quantity, where the first quantity is used to indicate the number of function modules that are using the memcg; After creating the memory manager memcg corresponding to the application, the method further includes: in response to completion of creating the second data structure, increasing the value of the first quantity by one; After determining that the second data structure has been released, the method further includes: reducing the value of the first number by one; and when the value of the first number is 0, determining that the memcg is in an unused state.

4. The method according to claim 3, characterized in that The code data in the universal kernel image includes a first jump function, wherein the first jump function indicates code data in the form of the kernel object for creating the second data structure; The creating of the memory manager memcg corresponding to the application comprises: in the process of creating the first data structure according to the code data in the universal kernel image, creating the second data structure based on the code data in the kernel object form indicated by the first jump function.

5. The method according to claim 1 or 2, characterized in that: Before the asynchronously releasing the first memory page and the second memory page, the method further includes: Starting to release the memcg, wherein the code data for releasing the memcg in the universal kernel image includes a second jump function, and the second jump function indicates the first code data in the form of the kernel object for creating an asynchronous thread; In the process of starting to release the memcg, the asynchronous thread is created based on the first code data indicated by the second jump function, and the asynchronous thread is used to detect the release status of the second memory page.

6. The method according to claim 5, characterized in that After the asynchronously releasing the first memory page and the second memory page, the method further includes: When the asynchronous thread detects that the memory page linked list in the second data structure is empty, it is determined that the second memory page has been released.

7. The method according to claim 5, characterized in that When the asynchronous thread detects that the memory page linked list in the second data structure is not empty, the asynchronous thread sleeps for a first period of time; after the asynchronous thread sleeps for the first period of time, the asynchronous thread repeatedly detects whether the memory page linked list in the second data structure is empty.

8. The method according to claim 1 or 2, characterized in that: The first storage space is a system memory in an internal memory of the electronic device, and the second storage space is a swap partition and an external memory in the internal memory of the electronic device.

9. The method according to claim 1 or 2, characterized in that: The first memory page includes an anonymous page and a file page corresponding to the application, and the second memory page includes a compressed anonymous page corresponding to the application.

10. An electronic device, characterized in that: An electronic device enables a universal kernel image, and the electronic device comprises: a processor and a memory, wherein the memory is used to store computer instructions, and when the processor executes the computer instructions, the electronic device executes the method as claimed in any one of claims 1 to 9.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a computer program or instructions. When the computer program or instructions are executed on a computer, the computer is caused to perform the method according to any one of claims 1 to 9.

12. A computer program product, characterized in that The computer program product comprises a computer program or instructions, and when the computer program or instructions are run on a computer, the computer is caused to perform the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Memory cold page processing method and electronic equipment

    CN114116191A

  • Memory management method and device, terminal and storage medium

    CN115269168A