CN117724828A - Management method of memory manager and electronic equipment - Google Patents

Management method of memory manager and electronic equipment Download PDF

Info

Publication number
CN117724828A
CN117724828A CN202310879426.8A CN202310879426A CN117724828A CN 117724828 A CN117724828 A CN 117724828A CN 202310879426 A CN202310879426 A CN 202310879426A CN 117724828 A CN117724828 A CN 117724828A
Authority
CN
China
Prior art keywords
memory
data structure
memcg
page
function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310879426.8A
Other languages
Chinese (zh)
Inventor
林琨力
王鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202310879426.8A priority Critical patent/CN117724828A/en
Publication of CN117724828A publication Critical patent/CN117724828A/en
Pending legal-status Critical Current

Links

Landscapes

  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The application provides a management method of a memory manager and electronic equipment, and relates to the technical field of computers. The scheme improves the problem of memory leakage after memcg release of the electronic equipment which enables the universal kernel mirror image. The specific scheme is as follows: responding to the starting operation of the application program, and creating a memory manager memcg corresponding to the application program; memcg corresponds to a first data structure and a second data structure, the second data structure being a data structure created based on code data in the form of kernel objects for managing a second memory page of an application in a second memory space; responding to the stopping operation of the application program, and asynchronously releasing the first memory page and the second memory page; releasing the second data structure after determining that the second memory page has been released; in the event that the second data structure has been released, the memcg is determined to be in an unused state, and the first memory page has been released, a first function is invoked for releasing the first data structure.

Description

Management method of memory manager and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a management method of a memory manager and an electronic device.
Background
During operation of the electronic device, memory pages of an application in system memory (portions of internal memory other than swap partitions) may be managed by a memory manager (memcg). If the memory range managed by memcg needs to be extended (e.g., implementing management of the swap partition using the memcg mechanism), the kernel code associated with the memcg needs to be modified.
For electronic equipment adopting the general kernel mirror image (generic kernel image, GKI), kernel codes cannot be directly modified, and corresponding Kernel Object (KO) codes can be mounted on the kernel codes only through a hook function, so that the memory range managed by memcg is expanded.
However, in the case where the KO code is mounted on the kernel code, in the related art, a problem of memory leakage may occur in a scenario where memcg is released (system memory occupied and managed by memcg is released).
Disclosure of Invention
The embodiment of the application provides a management method of a memory manager and electronic equipment, which are used for avoiding the problem of memory leakage after memcg release under the condition that a KO code is mounted on a kernel code, and improving the utilization rate of the memory.
In order to achieve the above purpose, the embodiments of the present application adopt the following technical solutions:
In a first aspect, an embodiment of the present application provides a management method of a memory manager, applied to an electronic device that enables a general kernel image, where the method includes: responding to the starting operation of an application program, and creating a memory manager memcg corresponding to the application program; the memcg is corresponding to a first data structure and a second data structure, wherein the first data structure is a data structure created based on code data in the general kernel image and is used for managing a first memory page of the application program 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 for managing a second memory page of the application program in a second storage space; responding to the stopping operation of the application program, and asynchronously releasing the first memory page and the second memory page; releasing the second data structure after determining that the second memory page has been released; and calling a first function for releasing the first data structure when the second data structure is released, the memcg is determined to be in an unused state and the first memory page is released.
In the above embodiment, the release of the first data structure is blocked before the release of the second data structure. The problem of abnormal release of the second data structure created based on the KO code is avoided, and the possibility of memory leakage is reduced.
In some embodiments, the condition for invoking the first function is not satisfied until the second data structure is released.
In the above embodiment, the function of releasing the first data structure is called under the condition that the second data structure is released. Blocking the release of the first data structure before the release of the second data structure is effected.
In some embodiments, a first number is included in the first data structure, the first number being used to indicate a 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 completion of creating the second data structure, incrementing the first number of values by one; after determining that the second data structure has been released, the method further comprises: subtracting one from the value of the first number; in the case where the first number has a value of 0, it is determined that the memcg is in an unused state.
The first number may be the number of css references in the memcg data structure, where whether the number of css references is zero or not is a condition that the native code decides whether to release the first data structure, and in the above embodiment, by increasing the value of the number of css references after the second data structure is created, in a case of reducing the amount of change to the code program, a procedure of blocking the first data structure from being released before the second data structure is released is implemented.
In some embodiments, code data in the generic kernel image includes a first jump function therein, the first jump function indicating code data in the form of the kernel object used to create the second data structure; the creating the memory manager memcg corresponding to the application program includes: and in the process of creating the first data structure according to the code data in the general 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.
In some embodiments, prior to the asynchronously releasing the first memory page and the second memory page, the method further comprises: initiating release of the memcg, wherein code data in the generic kernel image for releasing the memcg includes a second jump function, the second jump function indicating first code data in the form of the kernel object for creating an asynchronous thread; and in the process of starting to release the memcg, creating the asynchronous thread based on the first code data indicated by the second jump function, wherein the asynchronous thread is used for detecting the release condition of the second memory page.
In the above embodiment, by using the asynchronous thread, the memory page release managed by the first data structure and the memory page release managed by the second data structure may be performed asynchronously, so as to reduce the release duration of the memory page and improve the release efficiency of memcg.
In some embodiments, after the asynchronously releasing the first memory page and the second memory page, the method further comprises: and under the condition that the asynchronous thread detects that a memory page linked list in the second data structure is empty, determining that the second memory page is released.
In some embodiments, the first duration of dormancy is performed when the asynchronous thread detects that a linked list of memory pages in the second data structure is not empty; and repeatedly detecting whether a memory page linked list in the second data structure is empty or not after the asynchronous thread sleeps for the first time length.
In some embodiments, the first storage space is a system memory in an internal memory in the electronic device, and the second storage space is a swap partition and an external memory in the internal memory in the electronic device.
In some embodiments, the first memory page includes an anonymous page and a file page corresponding to the application program, and the second memory page includes a compressed anonymous page corresponding to the application program.
In a second aspect, an electronic device provided in an embodiment of the present application includes one or more processors and a memory; the memory is coupled to the processor, the memory for storing computer program code comprising computer instructions that, when executed by the one or more processors, operate to: responding to the starting operation of an application program, and creating a memory manager memcg corresponding to the application program; the memcg is corresponding to a first data structure and a second data structure, wherein the first data structure is a data structure created based on code data in the general kernel image and is used for managing a first memory page of the application program 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 for managing a second memory page of the application program in a second storage space; responding to the stopping operation of the application program, and asynchronously releasing the first memory page and the second memory page; releasing the second data structure after determining that the second memory page has been released; and calling a first function for releasing the first data structure when the second data structure is released, the memcg is determined to be in an unused state and the first memory page is released.
In some embodiments, the condition for invoking the first function is not satisfied until the second data structure is released.
In some embodiments, a first number is included in the first data structure, the first number being used to indicate a 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 further configured to: in response to completion of creating the second data structure, incrementing the first number of values by one; after determining that the second data structure has been released, the method further comprises: subtracting one from the value of the first number; in the case where the first number has a value of 0, it is determined that the memcg is in an unused state.
In some embodiments, code data in the generic kernel image includes a first jump function therein, the first jump function indicating code data in the form of the kernel object used to create the second data structure; the one or more processors are further configured to: and in the process of creating the first data structure according to the code data in the general 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.
In some embodiments, prior to the asynchronously releasing the first memory page and the second memory page, the one or more processors are further to: initiating release of the memcg, wherein code data in the generic kernel image for releasing the memcg includes a second jump function, the second jump function indicating first code data in the form of the kernel object for creating an asynchronous thread; and in the process of starting to release the memcg, creating the asynchronous thread based on the first code data indicated by the second jump function, wherein the asynchronous thread is used for detecting the release condition of the second memory page.
In some embodiments, after the asynchronously releasing the first memory page and the second memory page, the one or more processors are further to: and under the condition that the asynchronous thread detects that a memory page linked list in the second data structure is empty, determining that the second memory page is released.
In some embodiments, the first duration of dormancy is performed when the asynchronous thread detects that a linked list of memory pages in the second data structure is not empty; and repeatedly detecting whether a memory page linked list in the second data structure is empty or not after the asynchronous thread sleeps for the first time length.
In some embodiments, the first storage space is a system memory in an internal memory in the electronic device, and the second storage space is a swap partition and an external memory in the internal memory in the electronic device.
In some embodiments, the first memory page includes an anonymous page and a file page corresponding to the application program, and the second memory page includes a compressed anonymous page corresponding to the application program.
In a third aspect, embodiments of the present application provide a computer storage medium including computer instructions that, when executed on an electronic device, cause the electronic device to perform the method of the first aspect and possible embodiments thereof.
In a fourth aspect, the present application provides a computer program product for, when run on an electronic device as described above, causing the electronic device to perform the method of the first aspect and possible embodiments thereof as described above.
It will be appreciated that the electronic device, the computer storage medium and the computer program product provided in the above aspects are all applicable to the corresponding methods provided above, and therefore, the advantages achieved by the electronic device, the computer storage medium and the computer program product may refer to the advantages in the corresponding methods provided above, and are not repeated herein.
Drawings
FIG. 1 is a schematic diagram of the logic structure of memcg provided in an embodiment of the present application;
FIG. 2 is a diagram illustrating an example logic structure of memcg configured with hook points according to an embodiment of the present application;
FIG. 3 is a schematic illustration of indirectly modifying native code through hook points provided in an embodiment of the present application;
fig. 4 is a structural example diagram of a mobile phone according to an embodiment of the present application;
FIG. 5 is a flow chart of steps of a method of releasing memcg in an embodiment of the present application;
FIG. 6 is a graph of an example of the variation of css reference times for a first data structure during use of the method shown in FIG. 5;
FIG. 7 is an exemplary diagram of blocking release of a first data structure after a second data structure is established, as provided by embodiments of the present application;
FIG. 8 is a flow chart of steps of a method for releasing memcg according to an embodiment of the present application based on FIG. 7;
FIG. 9 is a graph of an example of the variation of css reference times for a first data structure during use of the method shown in FIG. 8;
FIG. 10 is an exemplary diagram of memcg release provided by embodiments of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application. Wherein, in the description of the present application, unless otherwise indicated, "at least one" means one or more, and "a plurality" means two or more. In addition, in order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "first", "second", and the like are used to distinguish the same item or similar items having substantially the same function and effect. It will be appreciated by those of skill in the art that the words "first," "second," and the like do not limit the amount and order of execution, and that the words "first," "second," and the like do not necessarily differ.
It is convenient to understand that technical terms related to the embodiments of the present application are first described below.
Internal memory, which may also be referred to as memory, includes logical memory (also referred to as virtual memory) and physical memory, which may be used to store page data corresponding to an application. Additionally, the memory may include system memory (e.g., referred to as a first storage space) and swap (swap) partitions. In a system built based on a Linux kernel, page data is stored in a system memory mainly by means of file pages (file-supported pages) and anonymous pages (anonymous pages).
The external memory is "external" with respect to the internal memory of the electronic device. The external Memory may include a Read Only Memory (ROM), a hard disk, a floppy disk, an optical disk, a U-disk, an embedded Memory (embeded multimedia card, emmc), a universal flash Memory (universal flashstorage, UFS), a multimedia card, and the like.
The anonymous page and the file page may be collectively referred to as a memory page.
The operation system does not provide a memory page marked by a name, and the virtual memory address (Virtual Memory Address, VMA) cannot distinguish different anonymous pages according to the name, so that the memory page without the name mark is called an anonymous page. When the anonymous page is recycled, in order that the kernel can also access the corresponding anonymous page, the anonymous page cannot be directly released (i.e. deleted) in the system memory, and the anonymous page needs to be swapped out of the system memory to the Swap partition for compressed storage, and the data in the Swap partition can be accessed by the CPU. Anonymous pages refer specifically to dynamically allocated pages of system memory during program execution, including stacks, data segments, and the like.
The file pages, the operating system provides the memory pages with name marks, the VMA records the corresponding file names, different file pages can be distinguished according to the file names, and the system memory pages with name marks are called as file pages. When the file pages are reclaimed, the file pages can be directly released (i.e. deleted) in the system memory. And then, 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 the file page. The file page specifically refers to a memory page for storing file class data, and comprises a code segment, a library file, file data accessed by program interaction and the like.
Taking a scene of playing music by the electronic device as an example, a system memory occupied by program data of the electronic device running the player belongs to an anonymous page, and a system memory occupied by a music file loaded into the system memory by the electronic device from an external memory belongs to a file page.
zRAM, also known as zRAM, is a function of the CPU core that can provide virtual memory compression. For example, anonymous pages swapped out to a swap partition are compressed by the zram function.
Currently, electronic devices may create a memcg (memory group) for each application through a memory manager mechanism for managing memory pages of the application. Each running application corresponds to memcg.
Illustratively, the memcg corresponds to at least one least recently used (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.
It will be appreciated that the electronic device may utilize memcg to manage memory pages of an application. For example, under the condition of insufficient memory in the electronic device, the target anonymous page with low data update speed or data update speed can be determined by memcg in the anonymous page corresponding to the application program running in the background or kept alive for a long time. And then, the target anonymous page is swapped out from the system memory to the swap partition, and is compressed, so that the size of the memory space occupied by the target anonymous page is reduced, and the recovery of part of the memory space occupied by the application program is realized.
In some embodiments, as shown in FIG. 1, memcg may include a memcg data structure (struct) and a plurality of functional functions for managing the lifecycle of the memcg.
Wherein the memcg data structure described above may be referred to as a first data structure. The first data structure includes corresponding memory resource control statistics (css), where the css includes a field indicating a reference counter, where the field carries a reference number of times to indicate the number of times the memcg is currently referenced. Of course, the first data structure may further include other types of data, for example, information indicating memcg (for establishing a correspondence between the first data structure and memcg), LRU linked list information, and the like, which are specifically referred to in the related art and will not be described herein. Thus, the first data structure may contain multiple types of data that may be used to indicate the corresponding memcg.
In addition, the above-mentioned multiple functional functions can also be called memcg operation set, and different functional functions can call kernel code segments for implementing different functions, so as to implement different types of management on the life cycle of memcg.
For example, the plurality of functional functions may include:
1) The function (mem_cgroup_alloc) for creating the memcg corresponding to the application may be referred to as function 1.
2) A function (css_try_online) for indicating that the number of references to css (which may also be referred to as css reference number, or first number) is increased by one, such as function 2. The function 2 is typically called when a function module in the kernel requests the use of memcg, executing the corresponding management item. The management items may include managing the memory space occupied by the application program (e.g., reclaiming the system memory occupied by the memory page of the application program), migrating the memory page, modifying the control field corresponding to the memcg, and the like, which are not described herein in detail with reference to the related art.
3) A function (css_put) for indicating that css reference number is reduced by one, such as function 3. The function 3 and the function 2 need to be called in pairs. For example, when a functional module in the kernel layer requests that a corresponding management item be performed using memcg, function 2 may be invoked, incrementing the css reference number of the memcg by one. Then, if the functional module completes the corresponding management item, memcg needs to be released, and the functional function 3 is called, and the css reference number of memcg is reduced by one.
4) A function (css_cgroup_online) for associating memcg to the cgroup corresponding to the application, such as referred to as function 4. In the cgroup corresponding to the application program, subsystems for managing other types of resources can be associated in addition to memcg for managing memory resources.
5) A function (css_offine, e.g., called function 5) for triggering release of memcg.
6) A function (mem_cgroup_free, such as called function 6) for releasing the memcg data structure, and the like. The kernel may call the function 6 under the condition that the function 5 has been called and the reference number corresponding to css is 0, so as to release the first data structure.
For an electronic device configuring an operating system of a Linux kernel, a set of kernel codes corresponding to memcg is configured in the operating system, such as what is called native codes (code data related to memcg, which is self-contained in the operating system).
In the case of unmodified native code, the electronic device may manage the lifecycle of memcg in the manner indicated by the native code, and manage memory pages of the application in system memory (the portion of the memory of the electronic device other than the swap partition) by memcg, i.e., the management scope of memcg is system memory.
In the case where the native code is modified, the management scope of memcg may extend to the swap partition and the external memory, which may be collectively referred to as a second storage space. It will be appreciated that where the management scope extends to the swap partition and the external memory, the electronic device may also manage through memcg after compressing the target anonymous page to the swap partition. Therefore, the electronic device can also restore the target anonymous page in the swap partition to the external memory, and further release the memory resource of the electronic device is realized. In addition, after the target anonymous page is swapped out to the external memory, the target anonymous page can be managed by memcg.
Most equipment manufacturers choose to modify the native code, so that the storage range which can be managed by memcg is extended, and the effective utilization rate of the memory of the electronic equipment is improved.
However, with the electronic device enabled GKI, the kernel code of the electronic device belongs to code data in the generic kernel image and cannot be directly modified. Thus, the native code corresponding to the mencg also belongs to code data in the generic kernel image, and cannot be directly modified.
Of course, as shown in FIG. 2, hook points may be added to the native code. During the process of executing the native code by the kernel, the hook point may instruct the kernel to jump to execute a new code (e.g., code data in the form of a kernel object), where the new code may implement expanding the management scope of memcg to the swap partition and the external memory.
The new code may be code data in the form of Kernel Object (KO), which is not needed to be embedded in the native code, and is loaded into the memory when needed, and unloaded from the memory when not needed. In this way, indirect modification of native code may be achieved. Thus, a native portion of memcg may be created based on the native code, responsible for managing memory pages of an application in system memory. An extension of memcg can be created based on the newly added code, responsible for managing compressed pages of the application in the swap partition and the external memory (anonymous pages swapped out from system memory to swap partition and compressed) and dump pages (compressed pages swapped out from swap partition to external memory). The compressed page and the page-to-page may also be referred to as a second memory page.
In some embodiments, the hook points may include data hook points and function hook points.
Illustratively, as shown in FIG. 2, the data hook point may be a pointer that may indicate a jump to access another data structure. For example, the data hook point may be configured within a memcg data structure (i.e., a first data structure) for indicating a jump to access another data structure, such as referred to as a second data structure.
For example, in indirectly modifying native code, a hook point may be configured in a first data structure that jumps to access a second data structure that corresponds to the same memcg as the first data structure, where the second data structure may be an extension of the first data structure. The first data structure is associated with native code of memcg and contains data types referred to in the corresponding native code of memcg. The second data structure is associated with the newly added code of memcg and contains the data type to which the newly added code corresponding to memcg relates.
In addition, the second data structure may include information indicating memcg (for association with memcg), compressed page linked list information, transfer page linked list information, zram data, transfer times, and the like. The multi-type data corresponding to the second data structure is suitable for realizing a new code expanding the storage range of memcg management.
Also illustratively, the function hook point described above may indicate a control flow transfer, which may be configured in native code. In this way, the kernel can jump to execute the new code in the process of executing the native code.
As shown in fig. 2, a function hook point, such as a first jump function, is configured in the native code corresponding to the function 1, where the function hook point may instruct to jump to execute the newly added code corresponding to the newly added function 1, and may implement creation of an extension part of memcg, for example, creation of a second data structure.
Taking fig. 3 as an example, in response to the running of an application program, the function 1 of memcg may be called. Thus, after the memcg function 1 is called, the native code corresponding to function 1 may be executed, enabling creation of the first data structure. And under the condition that the function hook point is configured in the part of the native codes and the execution is carried out to the function hook point, the newly added function 1 indicated by the function hook point is executed in a skip mode, and the newly added codes corresponding to the newly added function 1 can realize the creation of the second data structure. After the execution of the new code corresponding to the new function 1, the unexecuted part of the native code corresponding to the continued execution function 1 is returned.
Of course, the number and the positions of the configured function hook points in the native code corresponding to memcg can be determined according to practical situations. Thus, besides the configurable hook point in the native code corresponding to the function 1, the corresponding hook point can be configured in the native code of other function functions, so that the native code is indirectly modified.
In the case where a hook point is configured in the native code corresponding to memcg, when all the memory space managed and occupied by memcg is released, a problem that the first data structure is released, but the second data structure is not released easily occurs.
It will be appreciated that the release and creation of the second data structure is not controlled by the native code, while the release and creation of the first data structure is controlled by the native code. In addition, the first data structure has a release condition that css reference number is 0, and the second data structure has a release condition that the corresponding compressed page and the corresponding dump page are both emptied, and the two are not necessarily associated. Thus, after the electronic device releases the first data structure, a problem may occur in that the second data structure is not successfully released. That is, not only can the data hook point originally pointing from the first data structure to the second data structure become a wild pointer, but also problems such as memory leakage, memcg management abnormality and the like can occur.
In order to improve the above problems, the embodiments of the present application provide a management method of a memory manager, which can be applied to an electronic device.
The electronic device may be a mobile phone, a tablet computer, a laptop, a handheld computer, a notebook, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR) \virtual reality (VR) device, etc., and the specific form of the electronic device is not particularly limited, and in the following embodiments, a mobile phone with a Linux kernel is mainly described as an example.
Please refer to fig. 4, which is a schematic structural diagram of a mobile phone according to an embodiment of the present application.
As shown in fig. 4, the mobile phone may include: processor 110, external memory interface 120, internal memory 121, universal serial bus (universal serial bus, USB) interface 130, charge management module 140, power management module 141, battery 142, antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headset interface 170D, sensor module 180, keys 190, motor 191, indicator 192, camera 193, display 194, and subscriber identity module (subscriber identification module, SIM) card interface 195, etc.
The sensor module 180 may include a pressure sensor, a gyroscope sensor, a barometric sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.
It should be understood that the structure illustrated in this embodiment is not limited to a specific configuration of the mobile phone. In other embodiments, the handset may include more or fewer components than shown, or certain components may be combined, or certain components may be split, or different arrangements of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
The processor 110 may include one or more processing units, such as: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and/or a neural network processor (neural-network processing unit, NPU), etc. Wherein the different processing units may be separate devices or may be integrated in one or more processors.
The controller can be a neural center and a command center of the mobile phone. The controller can generate operation control signals according to the instruction operation codes and the time sequence signals to finish the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to reuse the instruction or data, it may be called directly from memory. Repeated accesses are avoided and the latency of the processor 110 is reduced, thereby improving the efficiency of the system.
In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous receiver transmitter (universal asynchronous receiver/transmitter, UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose input/output (GPIO) interface, a subscriber identity module (subscriber identity module, SIM) interface, and/or a universal serial bus (universal serial bus, USB) interface, among others.
It should be understood that the connection relationship between the modules illustrated in this embodiment is only illustrative, and is not limited to the structure of the mobile phone. In other embodiments, the mobile phone may also use different interfacing manners in the foregoing embodiments, or a combination of multiple interfacing manners.
The cell phone implements display functions through the GPU, the display 194, and the application processor, etc. The GPU is a microprocessor for image processing, and is connected to the display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
The external memory interface 120 may be used to connect to an external memory card, such as a Micro SD card, to extend the memory capabilities of the handset. The external memory card communicates with the processor 110 through an external memory interface 120 to implement data storage functions. For example, files such as music, video, etc. are stored in an external memory card.
The internal memory 121 may be used to store computer-executable program code that includes instructions. The internal memory 121 may include a storage program area and a storage data area. In addition, the internal memory 121 may include a high-speed random access memory, and may further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, a universal flash memory (universal flash storage, UFS), and the like. The processor 110 performs various functional applications of the cellular phone and data processing by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
The display screen 194 is used to display images, videos, and the like. The display 194 includes a display panel. The display panel may employ a liquid crystal display (liquid crystal display, LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (flex), a mini, a Micro-OLED, a quantum dot light-emitting diode (quantum dot light emitting diodes, QLED), or the like.
The cell phone may implement photographing functions through an ISP, a camera 193, a video codec, a GPU, a display 194, an application processor, and the like.
The ISP is used to process data fed back by the camera 193. For example, when photographing, the shutter is opened, light is transmitted to the camera photosensitive element through the lens, the optical signal is converted into an electric signal, and the camera photosensitive element transmits the electric signal to the ISP for processing and is converted into an image visible to naked eyes. ISP can also optimize the noise, brightness and skin color of the image. The ISP can also optimize parameters such as exposure, color temperature and the like of a shooting scene. In some embodiments, the ISP may be provided in the camera 193.
The camera 193 is used to capture still images or video. The object generates an optical image through the lens and projects the optical image onto the photosensitive element. The photosensitive element may be a charge coupled device (charge coupled device, CCD) or a Complementary Metal Oxide Semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, which is then transferred 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 the like format. In some embodiments, the handset may include N cameras 193, N being a positive integer greater than 1.
The digital signal processor is used for processing digital signals, and can process other digital signals besides digital image signals. For example, when the mobile phone selects a frequency point, the digital signal processor is used to perform fourier transform on the frequency point energy, etc.
Video codecs are used to compress or decompress digital video. The handset may support one or more video codecs. In this way, the mobile phone can play or record videos with various coding formats, for example: dynamic picture experts group (moving picture experts group, MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
The NPU is a neural-network (NN) computing processor, and can rapidly process input information by referencing a biological neural network structure, for example, referencing a transmission mode between human brain neurons, and can also continuously perform self-learning. Applications such as intelligent cognition of the mobile phone can be realized through the NPU, for example: image recognition, face recognition, speech recognition, text understanding, etc.
Above the above components, a software system developed based on a Linux kernel is run. The software system may adopt a layered architecture, an event driven architecture, a micro-core architecture, a micro-service architecture, a cloud architecture, or the like. In the embodiment of the application, taking an Android system with a layered architecture as an example, a software system architecture of a mobile phone is described. The software system architecture of the mobile phone at least comprises a kernel layer. The kernel layer at least comprises a memory management module, and the memory management module can execute the memcg corresponding to the native code creation application program and manage the memory pages of the application program corresponding to the memcg in the system memory. In addition, the memory management module can skip to execute a new added code according to a hook point in the native code in the process of executing the native code, mount a compressed page (an anonymous page compressed to a swap partition) of the application program on a compressed page linked list corresponding to the memcg, and mount a dump page (an anonymous page compressed and dumped to an external memory) of the application program on a dump page linked list corresponding to the memcg, so that space occupied by the application program in the swap partition and the external memory can be managed through the memcg.
In the following, implementation details of releasing memcg by an electronic device in an embodiment of the present application are described with reference to the accompanying drawings.
In some embodiments, in the event that any application or service is launched in the electronic device, the memcg corresponding to that application may be created. The native portion of the memcg created may manage memory pages of the application in system memory according to the native code to which the memcg corresponds. Thus, after memcg is created, the memory resources allocated to the application program for use can be associated to the LRU corresponding to memcg, so that management is convenient. In addition, after creation of the memcg, a first data structure is loaded in a memory of the electronic device.
As an implementation, in the context of a startup run of an application, in response to the startup run of the application, the memory management module may execute function 1 (mem_group_alloc) in native code, creating a first data structure. The first data structure includes css reference times.
It will be appreciated that the kernel layer of the electronic device includes other functional modules in addition to the memory management module for managing memcg. Different functional modules have different functions, such as a functional module for reclaiming memory space, a functional module for migrating memory space occupied by respective applications, a functional module for modifying a control field of memcg, etc.
The functional module may request the memory management module to use memcg to execute the corresponding management item. For example, the function module for managing memory space may request the memory management module to use memcg and perform reclamation of memory space occupied by memory pages managed by memcg. In this scenario, the function 2 (css_try_online) may be called by the memory management module, and the css reference number of memcg corresponding to the application program is increased by one, to indicate that a new function module is using the memcg, and execute corresponding management items. In the case where memcg is used by the nonfunctional module, the initial value of the corresponding css reference number may be 0. In some embodiments, where memcg is used by a nonfunctional module, it may be referred to as memcg being in an unused state. In other embodiments, when css reference number is 0, memcg may be determined to be in an unused state.
In addition, after the functional module executes the corresponding management item based on the memcg, the memory management module may call the functional function 3 (css_put), and reduce the css reference number of the memcg corresponding to the application by one, to indicate that one functional module using the memcg is reduced.
Wherein, in case the css reference number is 0, the first data structure has a released condition.
In some embodiments, a hook point is configured in the native code corresponding to the memcg, and the hook point may instruct the memory management module to jump to execute the newly added code (implementing expanding the management scope of the memcg to the code data of the swap partition and the external memory), before the function 1 (mem_group_alloc) called by the memory management module returns the execution result, the hook may instruct the memory management module to jump to execute the newly added code, and create the second data structure corresponding to the first data structure.
Thus, after memcg creation, the memory of the electronic device is also loaded with a second data structure. In some embodiments, in the case where the electronic device closes the application, the memcg corresponding to the application needs to be released. It may be appreciated that the aforementioned releasing the memcg corresponding to the application program may include releasing the memory resources (including the system memory, the swap partition, the external memory, etc.) occupied by the memory pages, the compressed pages, and the dump pages managed by the memcg, and releasing the first data structure and the second data structure corresponding to the memcg.
In some embodiments, after the application stops running, the electronic device releases the memcg process, as shown in fig. 5:
S1, calling a function 5 for indicating to release memcg.
In some embodiments, after the memory management module invokes the function 5, a native function corresponding to the function 5 may be executed. After executing the native function corresponding to the function 5, not only the memory pages managed by memcg may be released, but also the function module in the electronic device may be blocked from using memcg. Thus, the function module of the electronic device calls the function 2, and a call failure occurs. The functional module in the kernel layer cannot request to use memcg, and at the same time, the functional module using memcg triggers to call the functional function 3 after the corresponding management item is executed, and the number of css references in the first data structure is reduced by one.
For example, as shown in fig. 6, before the memory management module calls the function 5, the function module 1 and the function module 2 are executing corresponding management items using the memcg, and in this scenario, the number of css references in the first data structure of the memcg is 2.
In some embodiments, after the function 5 is invoked, the number of css references in the first data structure may be increased by 1, which indicates that the memory pages of memcg in the system memory are gradually released, and then other functional modules cannot request to use memcg any more, that is, at this time, the number of css references is 3 and will not increase any more. During this time, if the function module 3 requests the memory management module to use memcg, a request failure occurs. That is, the function module 3 may call the function 2 through the memory management module, but a call failure may occur. Thus, even if the memory management module invokes function 2, the css reference number of the first data structure is still 3.
In addition, after the function 5 is called, the number of css references is increased by "1", indicating that the function module for freeing the memory page of memcg in the system memory is executing the free transaction of the memory page using memcg. Thus, it is necessary to decrement "1" after the memory page of memcg in the system memory has been released.
In other embodiments, the number of css references in the first data structure may not be increased after the function 5 is invoked. Css may be gradually reduced to 0 as other functional modules release the use of memcg.
Of course, after the memory management module calls the function 5, the function module 1 may normally release the usage of memcg after performing the corresponding management event based on the memcg, and instruct the memory management module to call the function 3. After function 3 is called, css reference number of times of the first data structure becomes 2. Similarly, after the function module 2 performs the corresponding management event based on memcg, the memory management module may be instructed to call the function 3 normally. After function 3 is called again, the css reference number of the first data structure becomes 1. Thus, after the memory page of memcg in the system memory is released, the memory management module may also be instructed to call function 3. After function 3 is called again, css reference number of times of the first data structure becomes 0.
In summary, after the function 5 is called, the number of css references corresponding to memcg is gradually decreased to 0. Of course, fig. 6 shows only a scenario in which the functional modules 1 and 2 sequentially execute the corresponding management items. In an actual application scenario, there may be multiple situations in the sequence of each functional module completing the corresponding management item, and of course, any functional module completing the corresponding management item may trigger the css reference number to be reduced by one. Of course, memcg is released from the memory page in system memory, and may trigger css reference count minus one. In addition, memcg has no necessary sequence between the time point when the memory page in the system memory is released and the time point when the function module executes the corresponding management item, and fig. 6 is only an exemplary scenario.
S2, checking whether css reference times in the first data structure corresponding to memcg are 0.
In some embodiments, if css reference number is not 0, the flow proceeds to S3. If css reference number is 0, the flow proceeds to S4.
S3, after the interval is specified for a long time, checking whether the css reference number in the first data structure corresponding to memcg is 0 or not again.
In some embodiments, after the interval has been set for a length of time, the flow may again enter S2, enabling a cyclic query of the number of css references in the first data structure.
S4, calling a function 6 for indicating to release the first data structure.
It will be appreciated that, after the function 5 has been called, and the number of css references in the first data structure is 0, the memory management module needs to call the function 6 to release the first data structure according to the specification of the native code.
In other embodiments, after the function 5 is called, in a scenario where the number of css references is no longer increased, it is determined that the number of css references is 0, and memcg may call the function 6 to release the first data structure under a condition that memory pages in the system memory are all released. In embodiments of the present application, the number of css references corresponding to memcg may be incremented by one during creation of the second data structure, or after creation of the second data structure. After the second data structure is released, the number of css references corresponding to memcg is decremented by one. Therefore, under the condition that the second data structure exists in the memory of the electronic equipment, the flow of releasing the first data structure by the electronic equipment can be blocked, the situation that the first data structure is released but the second data structure is not released yet is avoided, and the problems of wild pointer and memory leakage are solved.
As an implementation manner, in the process of creating the second data structure, the memory management module may be triggered to call the function 2 (css_try_online), and the css reference number corresponding to memcg is increased by one. The "1" added by the number of css references at this time is required to be called after the second data structure is released, and the above "1" is subtracted from the function 3 (css_put), and for a specific process, see the description in the following embodiments.
In another implementation, after creation of the memcg, the memory management module may call function 4 (css_cgroup_online), associating the created memcg to the cgroup to which the application corresponds. As shown in fig. 7, the memory management module may call the function 4, and in the process of executing the native code corresponding to the function 4, jump and call the newly added function 4 through the hook point configured in the section of native code. Therefore, the newly added code part corresponding to the newly added function 4 can be skipped to trigger the memory management module to call the function 2 (css_try_online), and the css reference number corresponding to memcg is increased by one. The "1" added by the number of css references at this time is required to be called after the second data structure is released, and the above "1" is subtracted from the function 3 (css_put), and for a specific process, see the description in the following embodiments.
Thus, after memcg creation, or after memcg is associated with the cgroup of the application, even though the nonfunctional module uses memory resources managed by memcg, the corresponding css reference number has a value of 1. Correspondingly, the electronic device releases memcg, for example, after the application program stops running, as shown in fig. 8:
s101, calling a function 5 for indicating to release memcg, and executing a native code corresponding to the function 5.
In some embodiments, the memory management module may call the function 5 (e.g., referred to as a first function), and execute the native code corresponding to the function 5. Illustratively, the native code corresponding to the function 5 may be configured with a hook point (e.g., referred to as a second jump function), which may instruct the memory management module to jump to execute a new code for creating an asynchronous thread (e.g., referred to as first code data in the form of a kernel object) and a new code for instructing to initiate release of the swap partition and the external memory managed by the memcg. The swap partition and the external memory managed by the memcg refer to storage space occupied by the swap partition and the external memory of the compressed pages and the flash pages of the application program corresponding to the memcg.
In this way, in the process of executing the native code corresponding to the function 5, it is possible to implement creating an asynchronous thread, and releasing the storage space occupied by the application program in the swap partition and the external memory, for example, releasing the compressed pages on the compressed page linked list belonging to memcg and the dump pages on the dump page linked list.
After creating the asynchronous thread, the flow proceeds to S102.
After creating the asynchronous thread and starting to release the memory space occupied by the application program in the swap partition and the external memory, the execution of the unexecuted code in the native code corresponding to the function 5 may be continued, to release the system memory managed by memcg, and to block the system memory managed by the function module in the electronic device by memcg, and the flow proceeds to S104.
In some embodiments, S102 and S104 may be performed asynchronously, without a necessary order of precedence between the two.
S102, after a function 5 for indicating to release memcg is called, periodically detecting whether the swap partition and the external memory managed by memcg are released.
After the function 5 for indicating to release memcg is called, the system memory, the swap partition and the partition managed by the memcg can be asynchronously released, for example, the storage space occupied by the compressed page and the dump page of the application program corresponding to the memcg can be triggered and released by calling the interface of the swap partition. Wherein 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-described compressed page linked list and dump page linked list may be referred to as memory page linked list.
In some embodiments, asynchronous threads may be utilized to detect whether the swap partition and memory managed by memcg have been released.
Illustratively, after the asynchronous thread is created, the asynchronous thread may examine the compressed page linked list information and the dump page linked list information in the second data structure. If the compressed page linked list information indicates that there is no compressed page on the compressed page linked list and the dump page linked list information indicates that there is no dump page on the dump linked list, it is determined that the swap partition and the external memory managed by memcg are released, and the flow proceeds to S103. If the compressed page linked list information indicates that the compressed page is on the compressed page linked list or the stored page linked list information indicates that the stored page is on the stored page linked list, determining that the swap partition and the external memory managed by memcg are not released completely, enabling the asynchronous thread to sleep for a preset time (such as a first time), and then repeatedly checking the compressed page linked list information and the stored page linked list information in the second data structure until determining that the swap partition and the external memory managed by memcg are released.
S103, in the case that the swap partition and the external memory managed by the memcg are determined to be released, subtracting one from the css reference number in the first data structure.
In some embodiments, the memory management module may call the function 3 to reduce the number of css references in the first data structure by one. In addition, the second data structure may also be released in the event that determination is made that the swap partition and the memory managed by memcg have been released.
S104, after the function 5 for indicating to release memcg is called, detecting whether the css reference number in the first data structure is 0.
S105, determining that the css reference number is not 0, and after the interval is specified for a long time, checking whether the css reference number in the first data structure corresponding to memcg is 0 again.
Taking fig. 9 as an example, the number of css references of the first data structure has been incremented by one during creation of memcg. Thus, after both functional module 1 and functional module 2 request use of the memcg, the number of css references in the first data structure is 3. After the function 5 provided by memcg is called, the number of css references in the first data structure may be increased by 1, which indicates that the memory pages of the memcg in the system memory may be gradually released, the corresponding first data structure may not be released until the system memory pages are released, and after the function 5 is called, other function modules may not request to use memcg any more, that is, at this time, the number of css references is 4 and may not be increased any more. During this time, if the function module 3 requests the memory management module to use memcg, a request failure occurs. That is, the function module 3 instructs to call the function 2, and a call failure occurs. Thus, even if the memory management module calls the function 2, the css reference number of the first data structure is still 4.
In the exemplary scenario, before S103 is completed, after the functional module 1 completes execution of the corresponding management item based on memcg, the reference to memcg may be released, and the memory management module may be instructed to call the functional function 3. After function 3 is called for the first time, the css reference number of the first data structure becomes 3. Similarly, after the function module 2 performs the corresponding management event based on memcg, the memory management module may be instructed to call the function 3. After the function 3 is called a second time, the css reference number of the first data structure becomes 2. In addition, after the memcg is released from the corresponding memory page in the system memory, the memory management module may be instructed to call the function 3. After the third invocation of function 3, the css reference number of the first data structure becomes 1.
In the exemplary scenario, after S103 has been performed, the functional module 1 and the functional module 2 have performed corresponding management matters, and the system memory page, the compressed page, and the dump page managed by memcg have been released, and the number of css references of the first data structure may be 0. Of course, before S103 is executed, or the corresponding management items are not executed by the functional module 1 and the functional module 2, or the system memory page, the compressed page or the page transfer managed by memcg is not released, the css reference number of the first data structure is not 0.
In summary, after the function 5 is called, in the case that the css reference number 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 function modules, and the memory page of the memcg in the system memory has been released. In this scenario, the first data structure may be released.
S106, determining css reference times to be 0, and releasing the first structure data.
In some embodiments, the function 6 may be invoked, and the native code corresponding to the function 6 is executed, thereby releasing the first structure data.
As an implementation manner, as shown in fig. 10, a function hook point corresponds to a native code corresponding to a calling function css_offset. In the process of executing the native code corresponding to css_offset, the function hook point can be used for jumping to execute memcg_ext_release_kworker_init (newly added code) for creating an asynchronous thread. After the asynchronous thread is created, the function hook point indicates that the native code corresponding to css_offset is returned to be executed. After the execution of the native code corresponding to css_offset is finished, detecting whether css reference times are 0.
As in the previous embodiment, in creating memcg, "1" is added to css reference times, and the added "1" needs to be subtracted after the compressed page and the dump page of the application are released. Thus, the css reference number is always greater than 0 before it is determined that the compressed page and the page-in-place corresponding to the application program are released.
In addition, the asynchronous thread can detect the release condition of the compressed page and the page-turning page of the application program, for example, after the asynchronous thread is created, the asynchronous thread can detect whether the compressed page linked list and the page-turning linked list of memcg are empty or not, if any one of the compressed page linked list and the page-turning linked list of memcg is not empty, the asynchronous thread sleeps for a preset period of time, and then is awakened to detect whether the compressed page linked list and the page-turning linked list of memcg are empty or not again. If both the compressed page linked list and the dump page linked list of memcg are empty, the second data structure may be released, and in addition, the asynchronous thread decrements the css reference number in the first data structure by "1". Thus, as the function releases the usage of memcg, the number of css references will gradually decrease until it is 0.
Thus, although the asynchronous thread does not affect the release process of the memory pages, the transfer pages and the compression pages of memcg, the value of css reference times can be affected, that is, the judgment result of detecting whether the value of css reference times is 0 is affected. For example, after the asynchronous thread detects that the restore page and the compression page have completed releasing, the determination result of "whether the value of the number of css references is 0" may include "the value of the number of css references is 0". Before the asynchronous thread detects that the restore page and the compression page are released, the judgment result of 'detecting whether the value of the css reference number is 0' does not comprise 'detecting that the value of the css reference number is 0'.
In the case where the number of css references is not 0, for example, in the case where the compressed page and the page-to-page of the application are not completely released, or in the case where the function module does not release the use of memcg, after the interval is specified for a period of time, it is checked again whether the number of css references in the first data structure corresponding to memcg is 0.
In the case where css references 0, for example, the function module has released the use of memcg, and the compressed page and the dump page of the application are released entirely, the function mem_cgroup_free is called, releasing the first data structure.
In some embodiments, after the compressed and stored pages of the application are released, the release of the second data structure is triggered while the asynchronous thread triggers the css reference count to decrease by one. In this way, the second data structure can be released before the first data structure is released, so that the problem of memory leakage after the first data structure is released is avoided.
Thus, at the start of any application, the electronic device creates a corresponding memcg. The number of css references in the first data structure of the created memcg is set to 1. And mounting the system memory for the application program on the LRU linked list corresponding to the memcg for management. And then, any functional module requests the system memory managed by memcg, the corresponding css reference number is increased by 1, the functional module releases the requested system memory, and the corresponding css reference number is reduced by 1. During this period, the number of css references by memcg is not less than 1. Under the condition that the electronic equipment closes the application program, after the compressed page and the dump page corresponding to the application program are released, the css reference number is triggered to be reduced by one.
The embodiment of the 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 for storing computer program code, the computer program code comprising computer instructions. The computer instructions, when executed by the processor, cause the electronic device to perform the steps performed by the handset in the embodiments described above. Of course, the electronic device includes, but is not limited to, the memory and the one or more processors described above.
The embodiment of the application also provides a chip system, which can be applied to the terminal equipment in the previous embodiment. The system-on-chip includes at least one processor and at least one interface circuit. The processor may be a processor in an electronic device as described above. The processors and interface circuits may be interconnected by wires. The processor may receive and execute computer instructions from the memory of the electronic device via the interface circuit. The computer instructions, when executed by the processor, may cause the electronic device to perform the steps performed by the handset in the embodiments described above. Of course, the chip system may also include other discrete devices, which are not specifically limited in this embodiment of the present application.
In some embodiments, it will be clearly understood by those skilled in the art from the foregoing description of the embodiments, for convenience and brevity of description, only the division of the above functional modules is illustrated, and in practical application, the above functional allocation may be implemented by different functional modules, that is, the internal structure of the apparatus is divided into different functional modules to implement all or part of the functions described above. The specific working processes of the above-described systems, devices and units may refer to the corresponding processes in the foregoing method embodiments, which are not described herein.
The functional units in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the embodiments of the present application may be essentially or a part contributing to the prior art or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium, including several instructions to cause a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: flash memory, removable hard disk, read-only memory, random access memory, magnetic or optical disk, and the like.
The foregoing is merely a specific implementation of the embodiments of the present application, but the protection scope of the embodiments of the present application is not limited thereto, and any changes or substitutions within the technical scope disclosed in the embodiments of the present application should be covered by the protection scope of the embodiments of the present application. Therefore, the protection scope of the embodiments of the present application shall be subject to the protection scope of the claims.

Claims (12)

1. A method for managing a memory manager, the method being applied to an electronic device that enables generic kernel mirroring, the method comprising:
responding to the starting operation of an application program, and creating a memory manager memcg corresponding to the application program; the memcg is corresponding to a first data structure and a second data structure, wherein the first data structure is a data structure created based on code data in the general kernel image and is used for managing a first memory page of the application program 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 for managing a second memory page of the application program in a second storage space;
responding to the stopping operation of the application program, and asynchronously releasing the first memory page and the second memory page;
Releasing the second data structure after determining that the second memory page has been released;
and calling a first function for releasing the first data structure when the second data structure is released, the memcg is determined to be in an unused state and the first memory page is released.
2. The method of claim 1, wherein the condition for invoking the first function is not satisfied until the second data structure is released.
3. The method according to claim 1 or 2, characterized in that a first number is included in the first data structure, the first number being indicative of 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 completion of creating the second data structure, incrementing the first number of values by one;
after determining that the second data structure has been released, the method further comprises: subtracting one from the value of the first number; in the case where the first number has a value of 0, it is determined that the memcg is in an unused state.
4. A method according to claim 3, wherein code data in the generic kernel image includes a first jump function therein, the first jump function indicating code data in the form of the kernel object used to create the second data structure;
The creating the memory manager memcg corresponding to the application program includes: and in the process of creating the first data structure according to the code data in the general 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.
5. A method according to any of claims 1-3, wherein prior to said asynchronously releasing said first memory page and said second memory page, said method further comprises:
initiating release of the memcg, wherein code data in the generic kernel image for releasing the memcg includes a second jump function, the second jump function indicating first code data in the form of the kernel object for creating an asynchronous thread;
and in the process of starting to release the memcg, creating the asynchronous thread based on the first code data indicated by the second jump function, wherein the asynchronous thread is used for detecting the release condition of the second memory page.
6. The method of claim 5, wherein after the asynchronously releasing the first and second memory pages, the method further comprises:
And under the condition that the asynchronous thread detects that a memory page linked list in the second data structure is empty, determining that the second memory page is released.
7. The method of claim 5, wherein the first duration of dormancy occurs when the asynchronous thread detects that a linked list of memory pages in the second data structure is not empty; and repeatedly detecting whether a memory page linked list in the second data structure is empty or not after the asynchronous thread sleeps for the first time length.
8. The method of any of claims 1-7, wherein the first storage space is a system memory in an internal memory in the electronic device and the second storage space is a swap partition and an external memory in the internal memory in the electronic device.
9. The method of any of claims 1-8, wherein the first memory page comprises an anonymous page and a file page corresponding to the application, and the second memory page comprises a compressed anonymous page corresponding to the application.
10. An electronic device, wherein the electronic device enables a generic kernel image, the electronic device comprising: a processor and a memory for storing computer instructions which, when executed by the processor, cause the electronic device to perform the method of any of claims 1-9.
11. A computer readable storage medium, characterized in that the computer readable storage medium comprises a computer program or instructions which, when run on a computer, cause the computer to perform the method of any of claims 1-9.
12. A computer program product, characterized in that the computer program product comprises a computer program or instructions which, when run on a computer, cause the computer to perform the method according to any of claims 1-9.
CN202310879426.8A 2023-07-17 2023-07-17 Management method of memory manager and electronic equipment Pending CN117724828A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310879426.8A CN117724828A (en) 2023-07-17 2023-07-17 Management method of memory manager and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310879426.8A CN117724828A (en) 2023-07-17 2023-07-17 Management method of memory manager and electronic equipment

Publications (1)

Publication Number Publication Date
CN117724828A true CN117724828A (en) 2024-03-19

Family

ID=90209399

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310879426.8A Pending CN117724828A (en) 2023-07-17 2023-07-17 Management method of memory manager and electronic equipment

Country Status (1)

Country Link
CN (1) CN117724828A (en)

Similar Documents

Publication Publication Date Title
CN114443277A (en) Memory management method and device, electronic equipment and computer readable storage medium
EP3926466A1 (en) Electronic device which prefetches application and method therefor
JP2024515462A (en) Method and electronic device for performing drawing operations by an application
CN115292052A (en) Memory recovery method, electronic device and computer-readable storage medium
WO2023202429A1 (en) Garbage recycling method and electronic device
US20230385112A1 (en) Memory Management Method, Electronic Device, and Computer-Readable Storage Medium
CN115292199B (en) Video memory leakage processing method and related device
CN116774809A (en) Method and device for adjusting frequency, electronic equipment and readable storage medium
CN115687035A (en) Memory leak detection method and electronic equipment
CN111381996B (en) Memory exception handling method and device
CN114461589B (en) Method for reading compressed file, file system and electronic equipment
CN114253737B (en) Electronic device, memory recovery method thereof and medium
CN117724828A (en) Management method of memory manager and electronic equipment
CN116578422A (en) Resource allocation method and electronic equipment
CN116701298A (en) File system management method and electronic equipment
CN117130541A (en) Storage space configuration method and related equipment
CN117130824A (en) Method for processing exception, electronic equipment and storage medium
CN112783418B (en) Method for storing application program data and mobile terminal
CN116048742A (en) Data processing method and electronic equipment
CN115934302A (en) Memory leak processing method and electronic equipment
CN116743903B (en) Chip identification method and electronic equipment
CN116048562B (en) Data updating method, electronic equipment and storage medium
CN116661678B (en) Data dump method and electronic equipment
CN116049025B (en) Method for dynamically adjusting memory reclamation GC parameters, electronic equipment and storage medium
CN116643778B (en) Application program optimization method and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination