Memory management method and device, electronic equipment, medium and computer program product
By allocating an independent memory pool for each process, the lag caused by insufficient memory during running time of multiple applications in electronic devices is solved, and the device performance is improved.
Patent Information
- Application Number
- CN202411318201.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-20
- Publication Date
- 2024-11-12
AI Technical Summary
In electronic devices, when multiple applications are running at the same time, due to limited memory resources, applications running in the foreground may not be able to apply for sufficient memory space in time, resulting in lag and affecting device performance.
By allocating an independent memory pool for each process group, the process performs memory application operations in its corresponding memory pool to ensure that the process can obtain the required memory in a timely manner and avoid lag.
It effectively reduces the probability that the foreground application cannot apply for memory, improves the performance of electronic devices, and ensures the smooth operation of the application.
Smart Images

Figure CN118939431A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of electronic equipment, and specifically relates to a memory management method, device, electronic equipment, medium and computer program product. Background Art
[0002] With the development of electronic devices, more and more applications are included in electronic devices. In order to meet the needs of users, electronic devices can usually run multiple applications at the same time, and each application can run one or more processes. It can be understood that each process will occupy a certain amount of memory when running.
[0003] However, since the memory resources of electronic devices are limited, when the electronic device runs multiple applications at the same time, if the process corresponding to the application running in the foreground cannot apply for sufficient memory space in time to run, it may cause the application running in the foreground to freeze, thereby affecting the performance of the electronic device. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a memory management method, device, electronic device, medium and computer program product, which can avoid lag in applications running in the foreground and improve the performance of electronic devices.
[0005] In a first aspect, an embodiment of the present application provides a memory management method, the method comprising: when a first application is in a foreground running state, determining a first memory pool from at least one memory pool corresponding to the first application; the first memory pool corresponds to a first process group of the first application, the first process group including a first process currently running of the first application; and executing a memory request operation corresponding to the first process in the first memory pool.
[0006] In a second aspect, an embodiment of the present application provides a memory management device, which includes: a processing module; a processing module, used to determine a first memory pool from at least one memory pool corresponding to the first application when the first application is in a foreground running state; the first memory pool corresponds to a first process group of the first application, and the first process group includes a first process currently running by the first application; the processing module is also used to execute a memory request operation corresponding to the first process in the first memory pool.
[0007] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.
[0008] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0009] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.
[0010] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the first aspect.
[0011] In an embodiment of the present application, when the first application is in the foreground running state, the electronic device determines the first memory pool from at least one memory pool corresponding to the first application; the first memory pool corresponds to the first process group of the first application, and the first process group includes the first process currently running in the first application; and the memory application operation corresponding to the first process is performed in the first memory pool. Through this solution, since different process groups can correspond to different memory pools, a memory pool is usually used by a small number of processes, thereby reducing the probability that the application running in the foreground cannot apply for memory, thereby avoiding the jamming of the application running in the foreground, and improving the performance of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 This is one of the flowcharts of a memory management method provided in an embodiment of the present application;
[0013] Figure 2 This is the second flowchart of a memory management method provided in an embodiment of the present application;
[0014] Figure 3 This is the third flowchart of a memory management method provided in an embodiment of the present application;
[0015] Figure 4 is a structural diagram of a memory management device provided in an embodiment of the present application;
[0016] Figure 5 This is one of the hardware structure diagrams of an electronic device provided in an embodiment of the present application;
[0017] Figure 6 This is the second schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0018] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0019] The terms "first", "second", etc. in the specification of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0020] The terms "at least one (item)", "at least one of" and the like in the specification of the present application refer to any one, any two or a combination of more than two of the objects contained therein. For example, at least one (item) of a, b, and c can be represented by: "a", "b", "c", "a and b", "a and c", "b and c" and "a, b and c", where a, b, and c can be single or multiple. Similarly, "at least two (items)" refers to two or more, and its meaning is similar to that of "at least one (item)". The logo in the present application is text, symbol, image, etc. used to indicate information, and logos or other containers can be used as carriers for displaying information, including but not limited to text logos, image logos, symbol logos, etc.
[0021] The memory management method, device, electronic device, medium and computer program product provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0022] The memory management method, device, electronic device, medium, and computer program product provided in the embodiments of the present application can be applied to scenarios where an electronic device runs multiple applications, especially scenarios where an electronic device runs an application in the foreground.
[0023] As the functions provided by electronic devices become more diverse, the number of applications that users need to use is also increasing. In the process of users using electronic devices, since there are more and more applications in the electronic devices, the electronic devices can usually run multiple applications at the same time.
[0024] Among them, electronic devices can use processes as division units when applications are running. The memory requirements of a process during operation are very complex: on the one hand, the stack memory used by the process in user mode, the heap is a dynamically scalable memory, and the stack is used to store function variables when the program runs the code. Stack memory is requested from the BUDDY system and can be actively recycled; on the other hand, audio and video media services use DMA-BUF. Among them, DMA-BUF is a special memory manager that allows the same memory to be shared by user processes in user mode, kernel mode, and DMA devices with zero copy, so that data can be transferred efficiently; the memory corresponding to DMA-BUF is usually obtained from the BUDDY system and managed by the DMA-BUF framework, and cannot be actively recycled.
[0025] It is understandable that different types of memory are isolated from each other and cannot communicate with each other, and the release and application of memory are backed up by the BUDDY system, the lowest-level memory allocator.
[0026] Usually, the process of process operation is dynamic, and the demand for memory also shrinks dynamically according to business needs. There may be a period of time when the demand for DMA-BUF is high (such as taking pictures), and another period of time when the demand for stack memory is high (such as algorithm processing pictures). However, during the process of process operation, after releasing the memory occupied by the process in the previous period, the process may not be able to apply for the required memory again in the next period of time. For example, when there is file reading and the memory management mechanism buffer input / output (BUFFER Input / Output, BIO) is used, the DMA-BUF memory released by the process will be occupied by the file page.
[0027] Furthermore, when memory is tight, the electronic device also needs to enter a slow path to reclaim memory, such as reclaiming file pages or reclaiming anonymous pages.
[0028] The memory management method, apparatus, electronic device, medium, and computer program product provided in the embodiments of the present application, since different process groups can correspond to different memory pools, a memory pool is usually provided for use by a smaller number of processes, thereby reducing the probability that the application running in the foreground cannot apply for memory, thereby avoiding the lag of the application running in the foreground, and improving the performance of the electronic device.
[0029] The execution subject of the memory management method provided in the embodiment of the present application may be a memory management device. Exemplarily, the memory management device may be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The memory management method provided in the embodiment of the present application will be exemplarily described below using an electronic device as an example.
[0030] The present application embodiment provides a memory management method. Figure 1 FIG. 1 is a flowchart of a memory management method provided by an embodiment of the present application, which can be applied to electronic devices. Figure 1 As shown, the memory management method provided in the embodiment of the present application may include the following steps 101 and 102.
[0031] Step 101: When a first application is in a foreground running state, the electronic device determines a first memory pool from at least one memory pool corresponding to the first application.
[0032] The first memory pool may correspond to a first process group of a first application program, and the first process group may include a first process currently running in the first application program.
[0033] In some embodiments of the present application, the first application may be an application in an electronic device.
[0034] Exemplarily, assuming that the electronic device is running a video application in the foreground, the video application may be the first application.
[0035] Exemplarily, assuming that the electronic device is running a communication application and a game application in the foreground, the first application may be at least one of the communication application and the game application.
[0036] In some embodiments of the present application, the above-mentioned memory pool may be a memory block applied for in advance before the process runs, so that when there is a new memory demand during the process running, a part of the memory block can be directly taken out from the memory pool for use without applying for memory from the system memory, thereby improving the memory allocation efficiency.
[0037] In some embodiments of the present application, the electronic device may first obtain at least one memory pool before determining the first memory pool.
[0038] Each memory pool may correspond to a process group, and each process group includes at least one process.
[0039] It can be understood that each memory pool may include the memory that processes in the corresponding process group are allowed to use.
[0040] In some embodiments of the present application, the memory pool may include a certain number of memory blocks of equal size.
[0041] It is understandable that during the process of running a process, some memory applications cannot fail. If the application fails, it will affect the system service, may cause the system processing speed to be interrupted, or cause some urgent tasks that cannot wait to be continued, such as the interruption of the network card packet processing task. In this way, the memory pool obtained in advance can be used as a backup cache to provide a free memory list for the process to run.
[0042] In some embodiments of the present application, the above-mentioned process grouping may be a memory management group (Memory Controller Group, MEMCG).
[0043] It is understandable that MEMCG is a grouping of processes according to a certain strategy to provide memory resource management functions. In actual implementation, the electronic device can traverse each MEMCG based on a certain strategy to perform memory management operations such as memory recycling.
[0044] In some embodiments of the present application, the grouping strategy corresponding to the above-mentioned MEMCG may include but is not limited to: grouping by application (Application, APP), grouping by user identification (User Identification, UID)-process ID (Process ID, PID).
[0045] In some embodiments of the present application, the above grouping by application may indicate that all processes corresponding to one application are in one MEMCG.
[0046] In some embodiments of the present application, the above grouping according to UID-PID may indicate: one process is one MEMCG.
[0047] Exemplarily, take the grouping of electronic devices by application as an example. An application usually has multiple processes such as a user interface (UI) process and a background process, and the multiple processes work together to complete the services that an application can provide. However, since the multiple processes are isolated from each other in memory and the business is non-linear, their memory requirements are not the same at the same time. Therefore, it is easy for the memory released by a process in a MEMCG to be applied for by processes in other MEMCGs, making it impossible for another process in the MEMCG to obtain the required memory, resulting in the one process having to apply for memory from the system.
[0048] In some embodiments of the present application, after grouping the processes, the electronic device may establish a cache link for each process group, for linking the memory application and release of all processes in each process group through the memory pool corresponding to each process group, thereby preventing the processes of applications running in the background from preempting the resources of applications running in the foreground through local memory management.
[0049] In some embodiments of the present application, the memory included in each of the above-mentioned memory pools and allowed to be used by processes in the corresponding process group can be understood as: the processes in each of the above-mentioned process groups can use the memory in the memory pool corresponding to the process group to perform memory management operations such as memory application and release.
[0050] It is understandable that, when the first application is running in the foreground, if the process of the first application cannot apply for memory in time, the user can clearly perceive that the operation of the first application is stuck. Therefore, the electronic device can obtain the first memory pool corresponding to the process group including the process of the first application when the first application is running in the foreground, so that the first application can perform memory management operations through the memory pool dedicated to the corresponding process group, ensuring that the first process of the first application can apply for the required memory in time.
[0051] It should be noted that the above step 101 may be performed before the first process applies for system memory, or may be performed after the first process applies for system memory. This embodiment of the application is not specifically limited.
[0052] It can be understood that if the above step 101 can be performed before the first process applies for system memory, the first process can first apply for memory in the first memory pool, and if the application for memory in the first memory pool fails, then apply for memory in the system memory; if the above step 101 can be performed after the first process applies for system memory, the first process can first apply for memory in the system memory, and if the application for memory in the system memory fails, then apply for memory in the first memory pool.
[0053] In some embodiments of the present application, the above step 101 may further include the following step 101a.
[0054] Step 101a: When a first application is in the foreground and a system memory application operation corresponding to a first process fails, the electronic device determines a first memory pool from at least one memory pool.
[0055] In some embodiments of the present application, when the above step 101 is performed after the first process applies for system memory, the electronic device can run the first application in the foreground, and when the first process fails to apply for system memory, the electronic device can obtain the first memory pool from at least one memory pool. In other words, the electronic device can use the first memory pool as a backup memory for the first process to run, and when the memory cannot be applied for from the system memory, the electronic device can enable the first memory pool.
[0056] In some embodiments of the present application, during the process of the first process applying for system memory, the first process can first directly obtain memory from the system memory through the fast path, such as the first process can directly obtain memory from the per CPU page (PCP) cache or BUDDY system. At this time, the first process does not need to wait to obtain memory, and the speed is fast. In the case that the first process cannot obtain memory through the fast path, the first process can enter the slow path (slowpath) to obtain memory through memory recycling and memory regularization. At this time, the first process needs to wait to obtain memory, and the speed is slow. Among them, memory recycling refers to the recovery of cold memory applied by the user, such as releasing file pages; memory regularization refers to small unused blocks of memory, which are scattered between allocated and unallocated memory; memory defragmentation merges or reorganizes scattered memory blocks to make more efficient use of memory space.
[0057] It is understandable that, when the above step 101 is performed after the first process applies for system memory, it is equivalent to the first process enjoying the priority of memory application. In this case, only when the first process fails to apply for system memory and enters the slow path for memory recovery, will it start to consume the memory in the first memory pool, and when it can apply for system memory, it will consume the system memory. In this way, even when the system memory is not sufficient, it can seize the memory living space of other processes, so that other memories frequently enter memory recovery to obtain memory, while the first process itself has priority to use memory, thereby ensuring the smoothness of the first application when running in the foreground.
[0058] In this way, when the first application is running in the foreground and the first process fails to apply for system memory, the first process can also perform memory management operations by obtaining the first memory pool, and will not cause abnormal conditions such as task interruption due to failure to apply for system memory. This can avoid the application running in the foreground from being stuck and improve the performance of the electronic device.
[0059] In some embodiments of the present application, Figure 1 ,like Figure 2As shown, the above step 101 may include the following step 101b.
[0060] Step 101b: When the first application is in the foreground running state and the first application satisfies a first condition, the electronic device determines a first memory pool from at least one memory pool.
[0061] Among them, the above-mentioned first condition may include at least one of the following: the usage frequency of the first application is greater than or equal to the first threshold; the number of freezes of the first application is greater than or equal to the second threshold.
[0062] In some embodiments of the present application, the electronic device may measure whether the first application satisfies the first condition by counting the number of times the user launches the first application and the time the user stays on the application.
[0063] In some embodiments of the present application, the electronic device may determine that the user has used the application when the user launches the application and the dwell time on the application is greater than a third threshold.
[0064] It is understandable that if a user launches an application but stays on the application for a short time, the user may mistakenly touch the application icon and launch the application instead of intending to use the application.
[0065] In some embodiments of the present application, the electronic device obtains the number of times an application freezes, including but not limited to: the electronic device directly counts the number of times an application freezes when a user is using the application; the electronic device obtains the number of times an application freezes counted by other electronic devices; the electronic device obtains the number of times an application freezes from big data statistics via a cloud server.
[0066] In some embodiments of the present application, the first threshold, the second threshold, and the third threshold may be set by a user, or may be a default threshold of the electronic device, or may be obtained by big data statistics. The embodiments of the present application are not specifically limited.
[0067] In some embodiments of the present application, when the first application meets the first condition, the electronic device may determine that the first application is frequently used or the first application is more prone to freeze. Therefore, the electronic device may obtain the corresponding memory pool only when the first application meeting the first condition is in the foreground running state, so as to avoid freezes in the foreground running of the first application.
[0068] In this way, the electronic device can first determine the list of applications that need to use the memory pool, so that when the applications in the list are running in the foreground, they can obtain memory through the memory pool corresponding to their process group. Therefore, local memory management can be used to prevent the processes of applications running in the background from occupying the resources of applications running in the foreground, thereby avoiding the running of applications running in the foreground from being stuck and improving the performance of the electronic device.
[0069] Step 102: The electronic device executes a memory request operation corresponding to a first process in a first memory pool.
[0070] It is understandable that the electronic device can ensure the success of the first process memory application through the first memory pool.
[0071] In some embodiments of the present application, since different process groups may correspond to different memory pools, a memory pool is usually used by a smaller number of processes, thereby reducing the probability that a process in a process group cannot apply for memory. In this way, when a first application is running in the foreground, the electronic device can perform a memory application operation for the first process through the first memory pool corresponding to the first process group including the first process of the first application. Thus, local memory management can be used to prevent the process of the application running in the background from occupying the resources of the application running in the foreground.
[0072] In the memory management method provided in the embodiment of the present application, since different process groups can correspond to different memory pools, a memory pool is usually used by a small number of processes, thereby reducing the probability that the application running in the foreground cannot apply for memory, thereby avoiding the lag of the application running in the foreground, and improving the performance of the electronic device.
[0073] In some embodiments of the present application, after the above step 101, the memory management method provided by the embodiment of the present application may further include the following step 103.
[0074] Step 103: The electronic device executes a memory release operation corresponding to the first process in the first memory pool.
[0075] It is understandable that other processes in the first process group may also execute the memory release operation and memory application operation corresponding to the process in the first memory pool.
[0076] In some embodiments of the present application, the first process can release memory to the first memory pool, so that processes in other process groups cannot obtain the memory released by the first process when applying for memory, thereby achieving memory isolation between process groups.
[0077] It can be understood that, for the first process group, the processes in the first process group have priority in memory usage, and the application and release of memory in the first process group can be managed by itself.
[0078] It should be noted that the above step 103 may be performed before step 102, may be performed after step 102, or may be performed simultaneously with step 102. The present application embodiment does not make any specific limitation.
[0079] In this way, since the electronic device can execute the memory release operation of the first process in the first process group in the first memory pool, the memory released by the first process will not be preempted by other processes outside the first process group, thereby ensuring the priority of the processes in the first process group to use the memory released by the first process, thereby preventing the processes of the application running in the background from preempting the resources of the application running in the foreground.
[0080] In some embodiments of the present application, before the above step 101, the memory management method provided in the embodiment of the present application may further include the following step 104, and the above step 101 may include the following step 101c and step 101d.
[0081] Step 104: The electronic device creates a memory interface for each process group of the first application.
[0082] In some embodiments of the present application, the above-mentioned memory (cache) interface may be a high-speed cache memory interface.
[0083] In some embodiments of the present application, the cache memory interface is used to link processes belonging to the same process group together as a memory source and a target for memory release and reuse. In other words, through the cache memory interface, different processes in the same process group can use each other's released memory to complete memory reuse in the same process group, and different processes in the same process group can share memory to improve the performance of electronic devices.
[0084] Exemplarily, the first application is a camera application, and the first process group is a process corresponding to the running camera application. The first process group may include: a camera algorithm process vendor.vivo.hardware.camera3rd.provider, a project framework service cameraserver, a camera pipeline process camerahalserver, an image (graphic) memory application process android.hardware.graphics.allocator-V2-service-mediatek, a DMA-BUF asynchronous memory release process dmabuf-deferred-free-worker, and a DMA-BUF asynchronous memory application process sys-heap-charge. The electronic device can create a first cache memory interface for the first process group to link the above-mentioned multiple processes, so that the multiple processes can eliminate the memory isolation between different processes, and one process in the multiple processes can apply for the memory released by another process in the multiple processes. For example, the camera algorithm process vendor.vivo.hardware.camera3rd.provider can apply for the memory released by the process of DMA-BUF asynchronous memory release to achieve the reuse of memory in the same process group.
[0085] It should be noted that, for each process group in the electronic device, the electronic device can create a cache memory interface for it.
[0086] In some embodiments of the present application, each process group may correspond to a folder, and each folder may be regarded as a process group granularity. In other words, a process group is a group of processes in the same group folder.
[0087] In some embodiments of the present application, there are interfaces providing grouping functions under a process grouping folder, and the cache interface here is a cache interface newly added under each process grouping folder.
[0088] In some embodiments of the present application, when an electronic device creates a memory interface for a process group, the memory interface may not be enabled so that the processes in the first process group do not need to be in the first memory pool. When performing a memory request operation, the system memory can be obtained normally without being affected by the memory interface.
[0089] It can be understood that the enabling of the memory interface can be understood as activating the memory interface so that the process can perform memory application operations and memory release operations through the memory interface.
[0090] It should be noted that, in actual implementation, any other possible method can be used to make the processes in the first process group not need to be in the first memory pool, and when performing a memory application operation, the system memory can be obtained normally without being affected by the memory interface. This embodiment of the application is not specifically limited.
[0091] Step 101c: The electronic device controls the memory interface corresponding to the first process group to be in an activated state.
[0092] Step 101d: The electronic device determines a first memory pool from at least one memory pool according to the states of the memory interfaces corresponding to the respective process groups; wherein the memory interface corresponding to the first memory pool is in an activated state.
[0093] In some embodiments of the present application, the electronic device controlling the memory interface corresponding to the first process group to be in an activated state may refer to: the electronic device enabling or activating the memory interface in some way. In other words, enabling the memory interface may mean that the electronic device determines to execute the memory request operation of the first process in the first memory pool.
[0094] In some embodiments of the present application, when the first application is running in the foreground, the electronic device can determine whether to enable the first cache memory interface through the policy layer.
[0095] It is understandable that the strategy layer of the electronic device can be used to combine and integrate the data transmission of the physical layer with the data processing of the protocol layer to form a complete data processing or communication strategy. In simple terms, the strategy layer can be responsible for combining the transmission capability of the physical layer and the data processing capability of the protocol layer to form a specific, executable operation or service.
[0096] Exemplarily, when a user triggers the camera application to start, the electronic device can enable the memory interface corresponding to the process group of the camera application through the policy layer; and when a user triggers the camera application to exit or run in the background, the electronic device can close the memory interface.
[0097] It is understandable that only when the application is running in the foreground can the user perceive the performance of the application. Therefore, when the application is running in the foreground, the memory interface can be enabled to improve its performance, and when the application is running in the background, the memory interface can be disabled to return the occupied memory space.
[0098] In some embodiments of the present application, the policy layer may determine whether the memory interface is enabled or not through corresponding instructions under different running states of the application.
[0099] Exemplarily, the electronic device may enable the memory interface through the policy layer when the instruction indicates echo "enable" > memory.cache, and disable the memory interface when the instruction indicates echo "disable" > memory.cache.
[0100] It can be understood that for the first process group corresponding to the memory interface in the activated state, the release and application of its memory can be carried out in its corresponding first memory pool without being preempted by processes in other process groups. In this way, in the same process group, the memory application of one process can benefit from the memory release of another process, which has the effect of taking precedence over the memory application of processes in other process groups.
[0101] In this way, the electronic device can create an adjustable cache memory interface for the process grouping so that the processes within the process grouping can ensure system stability during the process of sharing memory.
[0102] In some embodiments of the present application, the memory management method provided in the embodiments of the present application may further include the following step 105.
[0103] Step 105: The electronic device converts unoccupied memory in the first memory pool into system memory according to a memory release cycle.
[0104] In some embodiments of the present application, the electronic device may create a REAPER mechanism to periodically check the first memory pool through a reaper thread, and release unused memory in the first memory pool to the system memory.
[0105] For example, the memory release cycle is 5s, and the first process group is MEMCG. The electronic device can trigger a periodic check of the harvester thread every 5s to read the status of the memory pool corresponding to MEMCG. If there is an unused page (PAGE) in the memory pool, the free interface is called to release the PAGE to the BUDDY system.
[0106] It is understandable that the REAPER mechanism can prevent memory leaks caused by the process not using the cache and not closing the cache interface when there is cache in the memory pool.
[0107] In some embodiments of the present application, the length of the memory release cycle may be set by the user, or may be a default of the electronic device, or may be determined based on big data. The embodiments of the present application are not specifically limited.
[0108] It should be noted that the above step 105 may be performed before the above step 101 and step 102, or after the above step 101 and step 102, or simultaneously with the above step 101 and step 102. The present application embodiment does not make any specific limitation.
[0109] In this way, the electronic device can maintain high availability of system memory by periodically releasing unused memory in the first memory pool, thereby ensuring normal operation of the system and quality of service.
[0110] In some embodiments of the present application, the memory management method provided in the embodiments of the present application may further include the following step 106.
[0111] Step 106: When the system memory application operation corresponding to the second process fails, the electronic device converts the unoccupied memory in the first memory pool into the system memory.
[0112] The second process may be a process other than the first process in the electronic device.
[0113] In some embodiments of the present application, the second process may be any process other than the first process in the electronic device.
[0114] In some embodiments of the present application, the second process mentioned above may be an important process.
[0115] It can be understood that an important process is a process that can have a significant impact on the user's use of the electronic device. For example, if a second process freezes and causes a freeze in the foreground application, the second process is an important process.
[0116] In some embodiments of the present application, the electronic device may determine whether the second process is an important preset process through flags transmitted when the second process memory is requested.
[0117] For example, taking the flags transmitted when the important process applies for memory as GFP_ATOMIC as an example, when the flags transmitted when the second process applies for memory is GFP_ATOMIC, the electronic device can determine that the second process is an important process.
[0118] In some embodiments of the present application, the failure of the system memory application operation corresponding to the second process may indicate that the current system memory is tight and the second process cannot quickly obtain the memory. In this way, the electronic device may release the memory in the first memory pool to the system memory to maintain the normal operation of the system, especially when the second process is an important process, the normal operation of the second process may be maintained.
[0119] Exemplarily, take the flags passed when an important process applies for memory as GFP_ATOMIC. When the flags passed when the second process applies for memory is GFP_ATOMIC, the electronic device can determine that the memory application of the second process needs to be performed in an atomic manner, without waiting or sleeping, and returns immediately if it fails. It can be understood that in this case, the memory application of the second process requires very high performance. If the application fails, although the system will not hang up, it will also affect the system service. In this way, the electronic device can release the memory in the first memory pool to the system memory to keep the system running normally.
[0120] It should be noted that the above step 106 may be performed before the above step 101 and step 102, or after the above step 101 and step 102, or simultaneously with the above step 101 and step 102. The present application embodiment does not specifically limit this.
[0121] In this way, since the electronic device can release the memory in the first memory pool to the system memory when the system memory application operation corresponding to the second process fails, when the system memory is tight, the high availability of the system memory can be maintained by releasing the memory in the first memory pool, thereby ensuring the normal operation of the system and the quality of service.
[0122] In some embodiments of the present application, the memory management method provided in the embodiments of the present application may further include the following step 107.
[0123] Step 107: When the first application is in the background running state, the electronic device executes the memory application operation and the memory release operation corresponding to the third process in the system memory pool.
[0124] The first process group may include a third process.
[0125] In some embodiments of the present application, when the third process is a process in the first process group, the third process may be the same as or different from the first process.
[0126] In some embodiments of the present application, the third process and the second process may be the same or different.
[0127] In some embodiments of the present application, when the first application is running in the background, since the user cannot perceive whether the first application is stuck or not, the electronic device can execute memory request and memory release operations of the third process in the system memory pool.
[0128] It should be noted that the above step 107 may be performed before the above step 101 and step 102, or after the above step 101 and step 102, or simultaneously with the above step 101 and step 102. The present application embodiment does not make any specific limitation.
[0129] In this way, since the first application is running in the background, the electronic device can perform the memory application operation and memory release operation of the third process in the system memory pool, thereby reducing unnecessary memory usage and improving the performance of the electronic device.
[0130] Each of the above-mentioned method embodiments, or various possible implementation methods in each method embodiment, can be executed separately, or any two or more of them can be executed in combination with each other. The specific implementation method can be determined according to actual usage requirements, and the embodiments of the present application do not limit this.
[0131] The following is a specific example to illustrate the memory management method provided in the embodiment of the present application.
[0132] like Figure 3 As shown, the memory management method may include the following steps 201 to 203.
[0133] Step 201: When a first application is in the foreground, the electronic device executes a memory request operation of a first process.
[0134] The first process group corresponds to the first memory pool, and the first process group includes the first process of the first application.
[0135] Step 202: The electronic device obtains memory.
[0136] The electronic device acquires the memory when at least one of the following conditions is met:
[0137] The memory interface corresponding to the first process group is in an activated state, and there is sufficient memory in the first memory pool;
[0138] The memory interface corresponding to the first process group is in an inactive state, and there is sufficient memory in the PCP;
[0139] The memory interface corresponding to the first process group is in an inactive state, there is not enough memory in the PCP, and there is enough memory in the BUDDY system.
[0140] In some embodiments of the present application, Figure 3As shown, when the memory interface corresponding to the first process group is in an activated state, the electronic device can preferentially obtain memory from the first memory pool to quickly apply for memory for the first process; when there is not enough memory in the first memory pool, the electronic device can detect whether there is enough memory in the PCP, and when there is enough memory in the PCP, it can obtain memory from the PCP; when there is not enough memory in the PCP, the electronic device can detect whether there is enough memory in the BUDDY system, and when there is enough memory in the BUDDY system, it can obtain memory from the BUDDY system; finally, when there is not enough memory in the first memory pool, the PCP and the BUDDY system, the electronic device can execute the following step 203 to wait for enough memory to be recovered.
[0141] It should be noted that in actual implementation, the order of the three judgment conditions of whether the memory interface is in an activated state, whether there is enough memory in the PCP, and whether there is enough memory in the BUDDY system can be determined according to actual needs. Figure 3 The order shown in is only an example. In actual implementation, it is also possible to first determine whether there is enough memory in the PCP, then determine whether there is enough memory in the BUDDY system, and finally determine whether the memory interface is in an activated state. This embodiment of the application is not specifically limited.
[0142] Step 203: The electronic device controls the first process to enter a slow path.
[0143] Among them, when the memory interface corresponding to the first process group is in an inactive state, there is not enough memory in the PCP, and there is not enough memory in the BUDDY system, the electronic device controls the first process to enter the slow path.
[0144] It is understandable that after the first process enters the slow path, the first process can obtain memory when memory consolidation reclaims enough memory, or can obtain memory when memory recycling can reclaim enough memory. When memory consolidation and memory recycling cannot reclaim enough memory, the electronic device can execute an Out-Of-Memory (OOM) process kill on the first process to ensure the normal operation of the system.
[0145] In this way, since different process groups can correspond to different memory pools, a memory pool is usually used by a small number of processes, thereby reducing the probability that processes in a process group cannot apply for memory. In this way, when the first application is running in the foreground, the electronic device can perform the memory application operation of the first process through the first memory pool corresponding to the first process group including the first process of the first application. Therefore, through local memory management, the process of the application running in the background can be prevented from occupying the resources of the application running in the foreground, thereby avoiding the jamming of the application running in the foreground and improving the performance of the electronic device.
[0146] The memory management method provided in the embodiment of the present application can be executed by a memory management device. In the embodiment of the present application, the memory management device provided in the embodiment of the present application is described by taking the memory management device executing the memory management method as an example.
[0147] Figure 4 FIG. 1 shows a possible structural diagram of a memory management device involved in an embodiment of the present application. Figure 4 As shown, the memory management device 40 may include: a determination module 41 and an execution module 42.
[0148] Among them, the determination module 41 is used to determine the first memory pool from at least one memory pool corresponding to the first application when the first application is in the foreground running state; the first memory pool corresponds to the first process group of the first application, and the first process group includes the first process currently running of the first application; the execution module 42 is used to execute the memory request operation corresponding to the first process in the first memory pool determined by the determination module 41.
[0149] In a possible implementation, the execution module 42 is further configured to execute a memory release operation corresponding to the first process in the first memory pool.
[0150] In a possible implementation, the above device further includes: a creation module and a control module;
[0151] The creation module is used to create a memory interface for each process group of the first application before the determination module 41 determines the first memory pool from at least one memory pool corresponding to the first application;
[0152] The control module is used to control the memory interface corresponding to the first process group to be in an activated state;
[0153] The determination module 41 is specifically configured to determine a first memory pool from at least one memory pool according to the states of the memory interfaces corresponding to the process groups; wherein the memory interface corresponding to the first memory pool is in an activated state.
[0154] In a possible implementation, the determination module 41 is specifically configured to determine a first memory pool from at least one memory pool when the first application is in a foreground running state and the first application satisfies a first condition;
[0155] The first condition includes at least one of the following:
[0156] The usage frequency of the first application is greater than or equal to a first threshold;
[0157] The number of freezes of the first application is greater than or equal to the second threshold.
[0158] In a possible implementation, the above device further includes: a conversion module;
[0159] The conversion module is used to convert the unoccupied memory in the first memory pool into system memory according to the memory release cycle.
[0160] In a possible implementation, the conversion module is used to convert unoccupied memory in the first memory pool into system memory when a system memory application operation corresponding to a second process fails; the second process is a process other than the first process in the electronic device.
[0161] In a possible implementation, the determination module 41 is specifically configured to determine a first memory pool from at least one memory pool when a system memory application operation corresponding to the first process fails.
[0162] In a possible implementation, the execution module 42 is further configured to execute a memory application operation and a memory release operation corresponding to the third process in the system memory pool when the first application is in a background running state;
[0163] Among them, the first process group includes the third process.
[0164] An embodiment of the present application provides a memory management device. Since different process groups can correspond to different memory pools, a memory pool is usually provided for use by a smaller number of processes, thereby reducing the probability that the application running in the foreground cannot apply for memory, thereby avoiding the lag of the application running in the foreground and improving the performance of the electronic device.
[0165] The memory management device in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0166] The memory management device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, or may be other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0167] The memory management device provided in the embodiment of the present application can implement the various processes implemented in the above-mentioned memory management method embodiment and achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0168] Alternatively, if Figure 5 As shown, an embodiment of the present application also provides an electronic device 500, including a processor 501 and a memory 502, wherein the memory 502 stores programs or instructions that can be executed on the processor 501, and when the program or instructions are executed by the processor 501, the various steps of the above-mentioned memory management method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not repeated here.
[0169] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.
[0170] Figure 6 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.
[0171] The electronic device 1000 includes but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009, and a processor 1010 and other components.
[0172] Those skilled in the art will appreciate that the electronic device 1000 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1010 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Figure 6 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0173] Among them, processor 1010 is used to determine a first memory pool from at least one memory pool corresponding to the first application when the first application is in the foreground running state; the first memory pool corresponds to a first process group of the first application, and the first process group includes a first process currently running of the first application; and is used to execute a memory request operation corresponding to the first process in the first memory pool determined by processor 1010.
[0174] In a possible implementation, the processor 1010 is further configured to execute a memory release operation corresponding to the first process in the first memory pool.
[0175] In a possible implementation, the processor 1010 is further configured to create a memory interface for each process group of the first application before the processor 1010 determines the first memory pool from at least one memory pool corresponding to the first application; and to control the memory interface corresponding to the first process group to be in an activated state;
[0176] The processor 1010 is specifically configured to determine a first memory pool from at least one memory pool according to states of memory interfaces corresponding to respective process groups; wherein the memory interface corresponding to the first memory pool is in an activated state.
[0177] In a possible implementation, the processor 1010 is specifically configured to determine a first memory pool from at least one memory pool when the first application is in a foreground running state and the first application satisfies a first condition;
[0178] The first condition includes at least one of the following:
[0179] The usage frequency of the first application is greater than or equal to a first threshold;
[0180] The number of freezes of the first application is greater than or equal to the second threshold.
[0181] In a possible implementation, the processor 1010 is configured to convert unoccupied memory in the first memory pool into system memory according to a memory release cycle.
[0182] In a possible implementation, the processor 1010 is configured to convert unoccupied memory in the first memory pool into system memory when a system memory application operation corresponding to a second process fails; the second process is a process other than the first process in the electronic device.
[0183] In a possible implementation, the processor 1010 is specifically configured to determine a first memory pool from at least one memory pool when a system memory application operation corresponding to a first process fails.
[0184] In a possible implementation, the processor 1010 is further configured to execute a memory application operation and a memory release operation corresponding to the third process in the system memory pool when the first application is in a background running state;
[0185] Among them, the first process group includes the third process.
[0186] An embodiment of the present application provides an electronic device. Since different process groups can correspond to different memory pools, a memory pool is usually provided for use by a smaller number of processes, thereby reducing the probability that the application running in the foreground cannot apply for memory, thereby avoiding the lag of the application running in the foreground and improving the performance of the electronic device.
[0187] It should be understood that in the embodiment of the present application, the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042, and the graphics processor 10041 processes the image data of the static picture or video obtained by the image capture device (such as a camera) in the video capture mode or the image capture mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1007 includes a touch panel 10071 and at least one of other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include two parts: a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0188] The memory 1009 can be used to store software programs and various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1009 may include a volatile memory or a non-volatile memory, or the memory 1009 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 1009 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0189] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1010.
[0190] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned memory management method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0191] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0192] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned memory management method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0193] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0194] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned memory management method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0195] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0196] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0197] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A memory management method, characterized in that: The method comprises: When a first application is in a foreground running state, determining a first memory pool from at least one memory pool corresponding to the first application; the first memory pool corresponds to a first process group of the first application, and the first process group includes a first process currently running by the first application; A memory request operation corresponding to the first process is executed in the first memory pool.
2. The method according to claim 1, characterized in that The method further comprises: A memory release operation corresponding to the first process is performed in the first memory pool.
3. The method according to claim 1 or 2, characterized in that: Before determining the first memory pool from at least one memory pool corresponding to the first application, the method further includes: Creating a memory interface for each process group of the first application; The determining the first memory pool from at least one memory pool corresponding to the first application comprises: Controlling the memory interface corresponding to the first process group to be in an activated state; According to the states of the memory interfaces corresponding to the respective process groups, a first memory pool is determined from the at least one memory pool; wherein the memory interface corresponding to the first memory pool is in an activated state.
4. The method according to claim 1, characterized in that: The step of determining the first memory pool from at least one memory pool corresponding to the first application program when the first application program is in the foreground running state includes: When the first application is in a foreground running state and the first application satisfies a first condition, determining the first memory pool from the at least one memory pool; The first condition includes at least one of the following: The usage frequency of the first application is greater than or equal to a first threshold; The number of freezes of the first application is greater than or equal to a second threshold.
5. The method according to claim 1, characterized in that The method further comprises: According to the memory release cycle, unoccupied memory in the first memory pool is converted into system memory.
6. The method according to claim 1, characterized in that The method further comprises: When a system memory application operation corresponding to a second process fails, unoccupied memory in the first memory pool is converted into system memory; the second process is a process other than the first process in the electronic device.
7. The method according to claim 1, characterized in that The determining the first memory pool from at least one memory pool corresponding to the first application comprises: When the system memory application operation corresponding to the first process fails, the first memory pool is determined from the at least one memory pool.
8. The method according to claim 1, characterized in that The method further comprises: When the first application is in the background running state, executing the memory application operation and the memory release operation corresponding to the third process in the system memory pool; The first process group includes the third process.
9. A memory management device, characterized in that: The device comprises: a determination module and an execution module; The determining module is used to determine a first memory pool from at least one memory pool corresponding to the first application when the first application is in a foreground running state; the first memory pool corresponds to a first process group of the first application, and the first process group includes a first process currently running by the first application; The execution module is used to execute the memory application operation corresponding to the first process in the first memory pool determined by the determination module.
10. The device according to claim 9, characterized in that The execution module is further used to execute a memory release operation corresponding to the first process in the first memory pool.
11. The device according to claim 9 or 10, characterized in that The device also includes: a creation module and a control module; The creating module is used to create a memory interface for each process group of the first application before the determining module determines the first memory pool from at least one memory pool corresponding to the first application; The control module is used to control the memory interface corresponding to the first process group to be in an activated state; The determination module is specifically used to determine a first memory pool from the at least one memory pool according to the states of the memory interfaces corresponding to the respective process groups; wherein the memory interface corresponding to the first memory pool is in an activated state.
12. The device according to claim 9, characterized in that The determining module is specifically configured to determine the first memory pool from the at least one memory pool when the first application is in a foreground running state and the first application satisfies a first condition; The first condition includes at least one of the following: The usage frequency of the first application is greater than or equal to a first threshold; The number of freezes of the first application is greater than or equal to a second threshold.
13. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the memory management method according to any one of claims 1 to 8 are implemented.
14. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the memory management method according to any one of claims 1 to 8 are implemented.
15. A computer program product, wherein the computer program product is stored in a storage medium, and wherein the computer program product is executed by at least one processor to implement the steps of the memory management method according to any one of claims 1 to 8.
