Memory control method and apparatus, and electronic device and readable storage medium
By grouping processes into private and public buffers to manage memory, the problems of low memory management efficiency and high power consumption in existing technologies are solved, achieving more efficient memory allocation and use.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- VIVO MOBILE COMM CO LTD
- Filing Date
- 2025-10-09
- Publication Date
- 2026-04-23
AI Technical Summary
In electronic devices, existing technologies that allocate memory on an application-by-application basis may lead to inefficient inter-process memory management and increased power consumption. In particular, when switching between applications, the system may not have enough available free memory and may need to slowly reclaim memory before it can be allocated.
Processes are grouped into private and public buffers. When a process releases memory, it is reclaimed to the private buffer of its own process group and the public buffer of the associated process group. This allows for selection from multiple buffers when allocating memory, reducing the triggering of slow reclamation.
It improves memory management efficiency, reduces the power consumption of electronic devices, and ensures flexibility and efficiency in inter-process memory allocation.
Smart Images

Figure CN2025126501_23042026_PF_FP_ABST
Abstract
Description
Memory control methods, devices, electronic devices and readable storage media
[0001] Cross-reference to related applications
[0002] This application claims priority to Chinese Patent Application No. 2024114321105, filed on October 14, 2024, the entire contents of which are incorporated herein by reference. Technical Field
[0003] This application belongs to the field of electronic technology, specifically relating to a memory control method, apparatus, electronic device, and readable storage medium. Background Technology
[0004] In electronic device systems, memory allocation is done on a process-by-process basis. When multiple processes are running simultaneously, if process A releases some memory, that memory will be reclaimed by the system and may be immediately allocated to process B. Therefore, if process A needs memory again, the system may not have enough available free memory, requiring a slow memory reclamation process to allocate the necessary memory to process A.
[0005] To address the aforementioned issues, electronic devices typically allocate memory by application. This involves grouping processes created by the same application and storing the memory released by processes within the same group in a buffer corresponding to that group. When reallocating memory for processes within that group, memory in that buffer can be allocated first, and processes in other groups cannot use the memory in that buffer.
[0006] However, in practice, applications often use the functions of application B, or electronic devices frequently switch between multiple applications. In these situations, if the buffer corresponding to the group containing application A's process contains a lot of memory, it may lead to insufficient available free memory in the system. Other application processes (such as application B) will still need to trigger slow memory reclamation to allocate the required memory. Therefore, the above-mentioned method of allocating memory on an application-by-application basis may still result in situations where slow memory reclamation is required to allocate the necessary memory to a process, leading to increased power consumption and lower memory management efficiency in electronic devices. Summary of the Invention
[0007] The purpose of this application is to provide a memory control method, apparatus, electronic device, and readable storage medium that can reduce the power consumption of electronic devices and improve the efficiency of memory management.
[0008] In a first aspect, embodiments of this application provide a memory control method, the method comprising: upon determining that a first process releases first memory, acquiring a process group associated with the first process; if the first process is associated with at least two process groups, then reclaiming the first memory to a first buffer and / or a second buffer. Wherein, the at least two process groups include the process group containing the first process and the process group containing processes associated with the first process, the first buffer is a private buffer corresponding to the process group containing the first process, and the second buffer is a public buffer corresponding to the at least two process groups associated with the first process.
[0009] Secondly, embodiments of this application provide a memory control device, comprising: an acquisition module and a reclamation module. The acquisition module is configured to acquire process groups associated with the first process when it is determined that the first process is releasing first memory. The reclamation module is configured to reclam the first memory into a first buffer and / or a second buffer if the first process is associated with at least two process groups. The at least two process groups include the process group containing the first process and the process group containing processes associated with the first process. The first buffer is a private buffer corresponding to the process group containing the first process, and the second buffer is a common buffer corresponding to the at least two process groups associated with the first process.
[0010] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, wherein the memory stores a program or instructions executable on the processor, and the program or instructions, when executed by the processor, implement the steps of the memory control method as described in the first aspect.
[0011] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the memory control method as described in the first aspect.
[0012] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the memory control method as described in the first aspect.
[0013] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the memory control method as described in the first aspect.
[0014] In this embodiment, when it is determined that the first process releases the first memory, the process group associated with the first process is obtained. If the first process is associated with at least two process groups, the first memory is reclaimed to a first buffer and / or a second buffer. The at least two process groups include the process group where the first process resides and the process group where the processes associated with the first process reside. The first buffer is a private buffer corresponding to the process group where the first process resides, and the second buffer is a public buffer corresponding to the at least two process groups associated with the first process. Thus, for a process, since the first memory released by the process is reclaimed to the private buffer corresponding to the process group where the process resides and / or the public buffer corresponding to the at least two process groups when the process is associated with at least two process groups, for any given process, when allocating memory for the process, it can be allocated not only from the private buffer of the process group where the process resides but also from the public buffer corresponding to the process groups associated with the process. That is, when allocating memory for any process, if the amount of free memory available is relatively large, there is no need to trigger slow reclamation to reclaim memory, reducing the power consumption of the electronic device and improving the efficiency of memory management. Attached Figure Description
[0015] Figure 1 is one of the flowcharts of the memory control method provided in the embodiments of this application;
[0016] Figure 2 is a second schematic flowchart of the memory control method provided in the embodiments of this application;
[0017] Figure 3 is a third flowchart illustrating the memory control method provided in this application embodiment;
[0018] Figure 4 is a fourth flowchart illustrating the memory control method provided in the embodiments of this application;
[0019] Figure 5 is a fifth flowchart illustrating the memory control method provided in the embodiments of this application;
[0020] Figure 6 is a schematic diagram of process grouping and buffer provided in an embodiment of this application;
[0021] Figure 7 is a schematic diagram of the memory control device provided in an embodiment of this application;
[0022] Figure 8 is a schematic diagram of the structure of the electronic device provided in an embodiment of this application;
[0023] Figure 9 is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of this application. Detailed Implementation
[0024] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0025] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0026] The terms "at least one," "at least one of," etc., used in the specification and claims of this application refer to any one, any two, or a combination of two or more of the included items. For example, at least one of a, b, and c can mean: "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" refers to two or more items, and its meaning is similar to that of "at least one."
[0027] The memory control method, apparatus, electronic device, and readable storage medium provided in this application will be described in detail below with reference to the accompanying drawings and through specific embodiments and application scenarios.
[0028] First, the technical terms involved in the embodiments of this application will be explained.
[0029] Slow reclamation: When the system's memory defragmentation tool (memFree) is running out of memory, it needs to scan all memory pages to confirm whether they can be reclaimed when the application requests memory. This process is time-consuming and can easily cause system lag.
[0030] Control groups (cgroups) are a feature originating from the Linux kernel used for resource management and control of processes and process groups. In the Android system, cgroups are used to implement system-level resource management, ensuring that resource usage across different applications is allocated and controlled appropriately. The Android system can use cgroups to group applications or processes for resource limits, priority settings, and monitoring, ensuring system stability, performance, and security. cgroups are typically organized by application, with each application's processes grouped into a separate cgroup.
[0031] Components: A process is composed of a number of loosely connected components, with different types of components carrying out different functions of the process. For example, an activity is responsible for displaying content; a service is responsible for invisible tasks; and a content provider provides data sharing.
[0032] Buddy System: In Android, the Buddy System algorithm is typically used for kernel physical memory management, especially in page frame allocation. By using the Buddy System algorithm, the Android kernel can manage physical memory more efficiently, reduce memory fragmentation, and improve the efficiency of memory allocation and deallocation, thereby improving system performance and stability.
[0033] Adjustment Value (Adj): In Android, the Adj value is an indicator used to represent process priority. The Adj value is an integer representing the process's importance and priority within the system. The system uses this value to schedule processes and allocate resources.
[0034] Next, the application scenarios of the memory control method provided in the embodiments of this application will be introduced.
[0035] The memory control method provided in this application can be applied to scenarios of memory allocation or memory reclamation.
[0036] In memory allocation scenarios, memory allocation in electronic device systems is done on a process-by-process basis, and the memory allocated to each process changes dynamically as the application runs. For example, if one process of the application requires more memory, more memory is allocated to it, while another process requires less memory, less memory is allocated to it. Furthermore, memory allocation may be done by reserving memory for a process from a buffer or by allocating memory from the system.
[0037] In memory reclamation scenarios, the memory occupied by a process will be reclaimed by the system after the process finishes running, or, depending on the memory reclamation policy of the electronic device system, a portion of the memory occupied by a process will be reclaimed by the system after reaching a set threshold; alternatively, the memory occupied by a process can be reclaimed into a buffer so that the process can be quickly allocated memory when it needs it again.
[0038] This application provides a memory control method. When it is determined that a first process releases first memory, the method obtains the process group associated with the first process. If the first process is associated with at least two process groups, the first memory is reclaimed to a first buffer and / or a second buffer. The at least two process groups include the process group where the first process resides and the process group where the processes associated with the first process reside. The first buffer is a private buffer corresponding to the process group where the first process resides, and the second buffer is a common buffer corresponding to the at least two process groups associated with the first process. Thus, for a process, since the first memory released by the process is reclaimed to the private buffer corresponding to the process group and / or the common buffer corresponding to the at least two process groups when the process is associated with at least two process groups, for any given process, memory allocation can be done not only from the private buffer of the process group where the process resides but also from the common buffer corresponding to the process groups associated with the process. That is, when allocating memory to any process, if the amount of free memory available is relatively large, there is no need to trigger slow memory reclamation, reducing the power consumption of electronic devices and improving the efficiency of memory management.
[0039] The execution subject of the memory control method provided in this application embodiment can be a memory control device. Exemplarily, the memory control device can be an electronic device, or a functional component or functional entity within the electronic device. The memory control method provided in this application embodiment will be described executively below using an electronic device as an example.
[0040] Figure 1 is a flowchart illustrating the memory control method provided in an embodiment of this application. As shown in Figure 1, the memory control method provided in an embodiment of this application may include the following steps 101 and 102.
[0041] Step 101: When the electronic device determines that the first process has released the first memory, it obtains the process group associated with the first process.
[0042] In this embodiment, the first process can be a process created during application runtime. An application runtime may create multiple processes, and the first process can be any one of these multiple processes. It is understood that the memory control method provided in this embodiment can be used for memory allocation and reclamation for any process in the electronic device.
[0043] In this embodiment of the application, the first memory may be part or all of the memory occupied by the first process.
[0044] Optionally, in this embodiment of the application, the electronic device may determine to release the first memory occupied by the first process when it is determined that the task executed by the first process has ended, or that the running state of the first process is terminated or suspended, or that the system's free memory is insufficient. Here, the aforementioned task ending includes task completion, task cancellation, or task failure.
[0045] For example, once the task executed by the first process is completed, the memory occupied by the first process is no longer needed and can be released. For instance, taking the first process as an example of executing a data processing task, once the data processing is completed and the results are output, the memory used to store the original data and intermediate results can be released.
[0046] For example, if the task executed by the first process is canceled or fails for some reason, the memory associated with that task can be released to avoid memory leaks. The memory associated with that task can be all or part of the memory occupied by the first process.
[0047] For example, when the first process switches from a running state to a terminated state, the first memory occupied by the first process is no longer needed, and the electronic device can release the first memory occupied by the first process. This ensures efficient use of memory.
[0048] For example, in some cases, the first process may be suspended, i.e., its execution is paused. If the suspension is temporary and the first process may resume execution in the future, the initial memory occupied by the first process may not be released immediately. However, if the suspension is permanent, such as because the first process is canceled or the system lacks sufficient free memory, the initial memory occupied by the first process may be released.
[0049] For example, when an electronic device system has insufficient free memory, the system may trigger a memory reclamation mechanism to release the first memory that is no longer used in the first process.
[0050] Optionally, in this embodiment of the application, the electronic device may determine the process group in which the first process is located and the process group in which the processes associated with the first process are located as the process group associated with the first process.
[0051] It should be noted that the processes associated with the first process are those that interact with the first process through components and those that share memory with the first process. For a detailed explanation, please refer to the relevant description in step 301. Furthermore, the electronic device is a group of processes associated with the first process; that is, the specific implementation of determining the group to which the first process belongs and the process groups to which the processes associated with the first process belong can be found in the relevant descriptions in steps 301 and 302.
[0052] Step 102: If the first process is associated with at least two process groups, the electronic device will reclaim the first memory to the first buffer and / or the second buffer.
[0053] In this embodiment of the application, the process grouping described above may include at least one process. This process grouping may be referred to as a memory control group (memCgroup).
[0054] Optionally, in this embodiment of the application, when the process group includes at least two processes, there is an association relationship between any two of the at least two processes. This association relationship includes: the two processes interacting with each other, or the two processes sharing memory.
[0055] It should be noted that the existence of component interaction between any two processes mentioned above can be understood as one or more processes interacting with each other.
[0056] For example, taking any two processes as process A and process B, the interaction between components of the above two processes may include: process A binding to the service component of process B, process A accessing the provider component of process B, the activity component of process A interacting with the service component of process B, the service component of process A interacting with the service component of process B, and so on.
[0057] For example, taking any two processes as the desktop process and the display process, the sharing of memory between these two processes may include: when the desktop process is in the foreground, it shares the same memory in the same buffer with the display process surfaceflinger.
[0058] In this embodiment of the application, the above-mentioned at least two process groups may include the process group in which the first process is located and the process group in which the process associated with the first process is located.
[0059] For example, suppose process B is associated with process A and process B is associated with process C. Process A and process B are in process group 1, and process C is in process group 2. Taking process B as the first process, process B is associated with two groups: process group 1 (i.e., the process group where the first process is located) and process group 2 (i.e., the process group where the processes associated with the first process are located). Alternatively, taking process C as the first process, process C is associated with two groups: process group 1 (i.e., the process group where the processes associated with the first process are located) and process group 2 (i.e., the process group where the first process is located).
[0060] In this embodiment, the first buffer can be a private buffer corresponding to the process group to which the first process belongs. The memory in this private buffer is only available to processes within the process group to which the first process belongs, and cannot be used by processes in other process groups. For example, this private buffer can be called a PRIVATE CACHE.
[0061] In this embodiment, the second buffer can be a shared buffer corresponding to at least two process groups associated with the first process. The memory in this shared buffer is available for use by processes within those at least two process groups, but not by processes within other process groups. For example, this shared buffer can be called TOTALCACHE.
[0062] Optionally, in this embodiment of the application, referring to FIG1 and FIG2, the above step 102 can be specifically implemented by the following steps 1021 and 1022.
[0063] Step 1021: If the first process is associated with at least two groups and the first process is the main process of the process group to which the first process belongs, the electronic device will reclaim the first memory to the first buffer.
[0064] Example 1: Suppose process B is associated with process A and process C. Processes A and B are in process group 1, and process C is in process group 2. Process A is the master process of process group 1, process B is the secondary process of process group 1, and process C is the master process of process group 2. Taking process C as the first process, since process C is associated with both process group 1 and process group 2, and is the master process of process group 2, the electronic device will reclaim the memory released by process C into the private buffer corresponding to process group 2 (i.e., the first buffer).
[0065] Optionally, in this embodiment of the application, the electronic device may reclaim the first memory to the first buffer. The electronic device first marks the first memory as free and records the group information to which the first memory belongs, that is, records the group identifier of the process group to which the first process belongs. Then, it maintains the correspondence between the group identifier and the first memory in the first buffer so that when allocating memory later, the first memory can be allocated to the process in the process group indicated by the group identifier.
[0066] For example, assuming the process group associated with the first process is memCgroup1, after the electronic device marks the first memory as free, it records the group identifier of the process group memCgroup1 associated with the first process, and records the correspondence between the first memory and the group identifier of memCgroup1 in the PRIVATE CACHE1 corresponding to memCgroup1.
[0067] Furthermore, if the first buffer is insufficient to store the first memory, the electronic device may store a portion of the first memory in the first buffer and the other portion in the second buffer.
[0068] Optionally, in this embodiment, the electronic device may first divide the first memory into two parts. Then, the electronic device marks the first part of the memory as free and records the group information to which the first part of the memory belongs, i.e., records the group identifier of the process group to which the first process belongs. It then maintains the correspondence between the group identifier and the first part of the memory in a first buffer, so that when allocating memory later, the first part of the memory can be allocated to processes within the process group indicated by the group identifier. Furthermore, the electronic device marks the second part of the memory as free and records the group information to which the second part of the memory belongs, i.e., records the group identifiers of at least two process groups associated with the first process. It then maintains the correspondence between at least two group identifiers and the second part of the memory in a second buffer, so that when allocating memory later, the second part of the memory can be allocated to processes within the process groups indicated by the at least two group identifiers.
[0069] Step 1022: If the first process is associated with at least two groups and the first process is a subprocess of the process group to which the first process belongs, the electronic device will reclaim the first memory to the second buffer.
[0070] Example 2, in conjunction with Example 1 above, taking process B as the first process, since process B is associated with process group 2 and process group 1, and process B is a subprocess of process group 1, the electronic device will reclaim the memory released by process B to the common buffer (i.e., the second buffer) corresponding to process group 2 and process group 2.
[0071] Optionally, in this embodiment of the application, the electronic device may reclaim the first memory to the second buffer as follows: the electronic device first marks the first memory as free and records the group information to which the first memory belongs, that is, records the group identifiers of at least two process groups associated with the first process, and then maintains the correspondence between at least two group identifiers and the first memory in the second buffer so that when allocating memory later, the first memory can be allocated to the process in the process group indicated by the at least two group identifiers.
[0072] For example, assuming that the process groups associated with the first process are memCgroup1 and memCgroup2, and the first process is in memCgroup1 and is a secondary process in memCgroup1, the electronic device marks the first memory as free, records the group identifier of the process group memCgroup1 associated with the first process and the group identifier of memCgroup2, and records the correspondence between the first memory and the group identifiers of memCgroup1 and memCgroup2 in the TOTAL CACHE corresponding to memCgroup1 and memCgroup2.
[0073] In this embodiment, when the first process is associated with at least two process groups, if the first process is the main process of its process group, the memory released by the first process is reclaimed to the private buffer, or the private buffer and the public buffer, corresponding to its process group; if the first process is a secondary process of its process group, the memory released by the first process is reclaimed to the public buffer corresponding to the at least two process groups it is associated with, so that the first memory can be used not only by the processes in the process group to which the first process is located, but also by the processes in the process groups associated with the first process. Thus, the amount of free memory available to the processes associated with the first process is relatively large, so there is no need to trigger slow reclamation to reclaim memory, thereby reducing the power consumption of electronic devices and improving the efficiency of memory management.
[0074] Optionally, in this embodiment of the application, after step 101 above, the memory control method provided in this embodiment of the application may further include step 103.
[0075] Step 103: If the first process is associated with a process group, the electronic device will reclaim the first memory into the first buffer.
[0076] Optionally, in this embodiment of the application, if the first process is associated with a process group, the process group associated with the first process can be the process group to which the first process belongs.
[0077] It should be noted that the implementation process of the above-mentioned electronic device reclaiming the first memory to the first buffer can be found in the relevant description of step 102 above, and will not be repeated here in the embodiments of this application.
[0078] Optionally, in this embodiment of the application, referring to FIG1 and FIG3, after the above step 102, the memory control method provided in this embodiment of the application may further include the following step 201.
[0079] Step 201: When the electronic device determines that the first process needs to be allocated second memory, it allocates second memory for the first process from the first buffer and / or the second buffer.
[0080] In this embodiment of the application, the above-mentioned first process waiting to be allocated second memory can be understood as the first process needing to be allocated second memory, that is, the first process needs to use second memory.
[0081] Optionally, in this embodiment of the application, if the first process has no memory available or insufficient memory, the electronic device may determine that the first process needs to be allocated second memory. Alternatively, when creating the first process, the electronic device needs to allocate second memory for the first process, that is, the electronic device determines that the second process needs to be allocated second memory.
[0082] Optionally, in this embodiment of the application, when the process group to which the first process is located corresponds to the first buffer, the electronic device can allocate second memory for the first process from the first buffer.
[0083] For example, if the memory of the first buffer is greater than or equal to the memory of the second buffer, the electronic device allocates the second memory from the first buffer for the first process; if the memory of the first buffer is less than the memory of the second buffer, the electronic device allocates the second memory from the memory reclaimed by the system for the first process.
[0084] It should be noted that the memory in the first buffer mentioned above is all free memory, that is, memory that is not used or occupied.
[0085] Optionally, in this embodiment of the application, when the process group where the first process is located corresponds to the first buffer and the second buffer, the electronic device may first allocate memory for the first process from the first buffer, and then allocate memory for the first process from the first buffer and / or the second buffer according to the memory of the first buffer, the memory of the second buffer and the second memory.
[0086] Optionally, in this embodiment of the application, referring to FIG3 and FIG4, the above step 201 can be implemented by the following steps 2011 or 2012.
[0087] Step 2011: If it is determined that the first process is to be allocated second memory and the memory of the first buffer is greater than or equal to the second memory, the electronic device allocates second memory for the first process from the first buffer.
[0088] Step 2012: If it is determined that the first process is to be allocated second memory, the memory of the first buffer is less than the second memory, and the memory of the second buffer is greater than or equal to the second memory, the electronic device allocates second memory to the first process from the second buffer.
[0089] Optionally, in this embodiment of the application, when it is determined that the first process is to be allocated second memory, the memory of the first buffer is less than the second memory, and the memory of the second buffer is greater than or equal to the second memory, the electronic device can allocate a portion of memory for the first process from the first buffer and allocate a portion of memory for the first process from the second buffer, and the sum of these two portions of memory is equal to the second memory.
[0090] Optionally, in this embodiment of the application, if it is determined that the first process needs to be allocated second memory, the memory of the first buffer is less than the second memory, and the memory of the second buffer is less than the second memory, the electronic device allocates second memory to the first process from the memory reclaimed by the system.
[0091] For example, if the memory of the first buffer is greater than or equal to the memory of the second buffer, that is, the memory of the first buffer is sufficient for the use of the first process, the electronic device allocates the second memory from the first buffer for the first process. If the memory of the first buffer is less than the memory of the second buffer, it is determined whether the memory of the second buffer is less than the memory of the second buffer. If not, the second memory is allocated from the second buffer for the first process; if so, the second memory is allocated from the memory reclaimed by the system for the first process.
[0092] It should be noted that the memory in the second buffer mentioned above is all free memory, that is, memory that is not occupied or used.
[0093] [Corrected according to Rule 91, 27.10.2025] For example, suppose the process group where the first process is located is memCgroup1, and the private buffer corresponding to memCgroup1 is PRIVATE CACHE, and the corresponding public buffer is TOTAL CACHE. Then, first determine whether the memory of PRIVATE CACHE is sufficient. If yes, then allocate the second memory for the first process from PRIVATE CACHE. If not, then determine whether the memory of PRIVATE CACHE is sufficient. If yes, then allocate the second memory for the first process from TOTAL CACHE. If not, then allocate the second memory for the first process from the memory reclaimed by the system.
[0094] In this embodiment of the application, when allocating memory for the first process, if the private buffer corresponding to the process group where the first process is located is insufficient, the electronic device allocates memory for the first process from the public buffer corresponding to the process group where the first process is located, without triggering slow reclamation, which can improve memory allocation efficiency.
[0095] It should be noted that step 201 can be executed after step 102 or before step 101. This application embodiment does not limit this. Figure 3 is only an example of step 201 being executed after step 102.
[0096] Optionally, in the embodiments of this application, before step 101 above, the memory control method provided in the embodiments of this application may further include the following steps 301 and 302.
[0097] Step 301: When there is a relationship between the first process and the second process, the electronic device determines the main process and the secondary process in the first process and the second process according to the importance level of the first process and the importance level of the second process.
[0098] In this embodiment of the application, the relationship between the first process and the second process may include: the first process and the second process having component interaction, or the first process and the second process sharing memory.
[0099] Optionally, in this embodiment of the application, the above-mentioned importance level may include priority and creation time point, and the above-mentioned step 301 can be implemented by the following steps 3011 or 3012.
[0100] Step 3011: When the priority of the first process is different from that of the second process, the electronic device determines the main process and the secondary process in the first process and the second process according to the priority of the first process and the priority of the second process.
[0101] Optionally, in this embodiment, the aforementioned priority is used to represent the importance of a process in the system, and can be represented by an Adj value. Furthermore, the electronic device can be configured to have a smaller Adj value representing a higher priority, or a larger Adj value representing a higher priority; this embodiment does not limit this.
[0102] It should be noted that the priority of a process can be determined based on the user's visibility and perception of that process. Processes that are visible or perceptible to the user have a higher priority than processes that are invisible or imperceptible to the user.
[0103] For example, since foreground processes are visible to the user, they have a higher priority than background processes. A process playing music in the background has a higher priority than a process performing a task in the background that is imperceptible to the user.
[0104] Optionally, in this embodiment of the application, when the priority of the first process is different from that of the second process, the electronic device can determine the process with higher priority among the first process and the second process as the main process, and determine the other process as the secondary process.
[0105] For example, suppose the Adj value of the first process is 100 and the Adj value of the second process is 200, and the smaller the Adj value, the higher the priority. Then the priority of the first process is higher than that of the second process. In this case, the electronic device can designate the first process as the main process and the second process as the secondary process.
[0106] Step 3012: If the priority of the first process is the same as that of the second process, the electronic device determines the main process and the secondary process in the first process and the second process based on the creation time of the first process and the creation time of the second process.
[0107] Optionally, in this embodiment of the application, when the priority of the first process and the priority of the second process are the same, the electronic device can determine the process with the earlier creation time of the first process and the second process as the main process and the other process as the secondary process based on the creation time of the first process and the creation time of the second process.
[0108] For example, assuming that the first process and the second process have the same priority, and the first process is created at 10:00 and the second process is created at 10:01, then the first process was created earlier than the second process. In this case, the electronic device can designate the first process as the main process and the second process as the secondary process.
[0109] In this way, the electronic device determines the main process and the secondary process in the first process and the second process according to their priorities and creation time, which facilitates the subsequent division of process groups and the setting of memory allocation and memory reclamation strategies.
[0110] Step 302: The electronic device groups the main process and the secondary process according to the grouping status of the main process and the grouping status of the secondary process.
[0111] In this embodiment of the application, the grouping status of a process can be used to indicate whether the process has been grouped, and the grouping status can include grouped or not grouped.
[0112] Optionally, in this embodiment, the grouping status of a process can be determined by judging whether the process belongs to a certain process group. If it is determined that the process belongs to a certain process group, the grouping status of the process is determined to be grouped; if it is determined that the process does not belong to a certain process group, the grouping status of the process is determined to be ungrouped.
[0113] It should be noted that a process belonging to a process group can be understood as a correspondence between the process and the group identifier of that process group.
[0114] Optionally, in the embodiments of this application, step 302 above can be implemented by the following steps 3021 to 3023.
[0115] Step 3021: When the main process is in a grouped state and the secondary process is in an ungrouped state, the electronic device adds the secondary process to the process group where the main process is located.
[0116] For example, if the main process already belongs to process group memCgroup1 and the secondary process has not yet been grouped, the electronic device can also add the secondary process to memCgroup1.
[0117] Step 3022: When the grouping status of the main process is ungrouped and the grouping status of the secondary process is grouped, the electronic device creates a process group for the main process.
[0118] In this embodiment of the application, the main process and the secondary process are located in different process groups.
[0119] For example, if the main process does not belong to any process group and the secondary process belongs to process group memCgroup2, then process group memCgroup1 is created for the main process.
[0120] Step 3023: When both the main process and the secondary process are in an ungrouped state, the electronic device creates a process group for the main process and adds the secondary process to the process group where the main process is located.
[0121] For example, if neither the main process nor the secondary process belongs to any process group, the electronic device creates a process group memCgroup1 for the main process and adds the secondary process to memCgroup1 as well.
[0122] Thus, based on the grouping status of the main process and the secondary process, after grouping the main process and the secondary process, the process groups associated with the main process and the secondary process can be determined according to the relationship between the main process and the secondary process, as well as the process groups where the main process and the secondary process are located, thereby determining how to reclaim and allocate memory in the future.
[0123] Optionally, in this embodiment of the application, after step 302 above, the memory control method provided in this embodiment of the application may further include the following step 303.
[0124] Step 303: If the association between the first process and the second process is terminated, and the first process meets the removal conditions, the electronic device will remove the first process from the process group in which the first process is located.
[0125] In this embodiment of the application, the termination of the association between the first process and the second process may include: the end of component interaction between the first process and the second process, or the end of memory sharing between the first process and the second process.
[0126] It should be noted that the termination of the interaction between the components of the first process and the second process can be understood as the termination of the interaction between the components of the first process and the second process, or the termination of the interaction between the components of the first process and the components of the second process.
[0127] For example, taking process A as the first process and process B as the second process, the end of the component interaction between the first process and the second process may include: unbinding the service components of process A and process B, ending process A's access to the provider component of process B, closing the provider component of process B, ending the interaction between the activity component of process A and the service component of process B, ending the interaction between the service component of process A and the service component of process B, etc.
[0128] For example, taking the first process as the desktop process and the second process as the display process, the end of the shared memory between the first process and the second process can be: the desktop process switches from being in the foreground to being in the background, while the display process continues to run in the foreground. In this case, the two use different memory.
[0129] In this embodiment of the application, the above removal conditions may include: the first process is a secondary process, or the first process is a primary process and the process group to which the first process belongs does not include other processes.
[0130] In one example of this application, if the association between the first process and the second process is terminated, and if the first process is a subprocess within the first process and the second process, the electronic device will remove the first process from the process group to which the first process belongs.
[0131] For example, suppose process A is associated with process B, process A is the main process and process B is the secondary process, and process A is in process group 1 and process B is in process group 2. Taking process B as the first process, if the association between process A and process B is broken, process B will be removed from process group 2.
[0132] Optionally, in the embodiments of this application, the group containing the first process does not include other processes, which may include: the group containing the first process only includes the first process before the association between the first process and the second process is terminated; or, the group containing the first process includes the first process and the secondary process before the association between the first process and the second process is terminated, and the secondary process has been removed after the association between the first process and the second process is terminated.
[0133] In another example of this application, if the association between the first process and the second process is terminated, and if the first process is the main process in the first process and the second process, and there are no other processes in the process group to which the first process is located, then the electronic device will remove the first process from the process group to which the first process is located.
[0134] For example, suppose process A is associated with process B, process A is the main process and process B is the secondary process, and process A is in process group 1 and process B is in process group 2. Taking process A as the first process and process group 1 as the only process A, if the association between process A and process B is broken, process A will be removed from process group 1.
[0135] For example, suppose process A is associated with process B, process A is the main process and process B is the secondary process, and both process A and process B are in process group 1. Taking process A as the first process, if the association between process A and process B is broken, the electronic device will remove both process B and process A from process group 1.
[0136] In another example of this application, if the association between the first process and the second process is terminated, and if the first process is the main process in the first process and the second process, and there are other processes in the process group to which the first process belongs, then the first process is not removed.
[0137] For example, suppose process A is associated with process B, process A is the main process and process B is the secondary process, and process A is in process group 1 and process B is in process group 2. Taking process A as the first process, and process group 1 also includes processes C and D as an example, if the association between process A and process B is broken, there is no need to remove process A from process group 1.
[0138] In this way, after the association between the first process and the second process is severed, the first process that meets the removal conditions will be removed. This will prevent processes that are not associated with the process group from occupying the memory of the private or public buffer corresponding to the process group, thus avoiding the situation where processes within the process group cannot be allocated memory, thereby improving the efficiency and success rate of memory allocation.
[0139] Optionally, in this embodiment of the application, after step 102 above, the memory control method provided in this embodiment of the application may further include the following steps 104 and 105.
[0140] Step 104: The electronic device obtains the recycling duration of the first memory in the first buffer or the second buffer.
[0141] Optionally, in this embodiment, the aforementioned recycling time of the first memory in the first buffer can be understood as the time after the first memory is recycled to the first buffer and has been associated with the first buffer. Similarly, the aforementioned recycling time of the first memory in the second buffer can be understood as the time after the first memory is recycled to the second buffer and has been associated with the second buffer.
[0142] Optionally, in this embodiment, the electronic device can determine the recycling duration of the first memory in the first buffer based on the difference between the time when the first memory was recycled to the first buffer and the current time. Similarly, the electronic device can determine the recycling duration of the first memory in the second buffer based on the difference between the time when the first memory was recycled to the second buffer and the current time.
[0143] For example, assuming the first memory was reclaimed to the first buffer at 10:00 and the current time is 10:02, then it can be determined that the first memory has been reclaimed from the first buffer for 2 minutes, meaning the first memory has been associated with the first buffer for 2 minutes. Assuming the first memory was reclaimed to the second buffer at 10:00 and the current time is 10:03, then it can be determined that the first memory has been reclaimed from the second buffer for 3 minutes, meaning the first memory has been associated with the second buffer for 3 minutes.
[0144] Step 105: If the reclamation duration is greater than or equal to the duration threshold, the electronic device will reclaim the first memory to the system buffer of the electronic device.
[0145] Optionally, in this embodiment, the aforementioned duration threshold corresponds to the first process and can be set according to the type of the first process. The type of the first process may include foreground, visible, perceptible, recently used, background service, etc.
[0146] Optionally, in this embodiment of the application, the electronic device can set different duration thresholds for different types of processes based on the process type. For example, the electronic device can set the duration threshold for foreground processes to 3 minutes, and the duration threshold for recently used processes to 5 minutes, etc.
[0147] It should be noted that the above duration threshold can be understood as the duration during which the first memory can be allocated to processes in the process group corresponding to the first buffer, or the duration during which the first memory can be allocated to processes in at least two process groups corresponding to the second buffer.
[0148] For example, assuming a duration threshold of 5 minutes, this means that the first memory can be allocated to processes in the process group corresponding to the first buffer within 5 minutes of being reclaimed to the first buffer, and needs to be reclaimed by the Buddy system after 5 minutes. Alternatively, this means that the first memory can be allocated to processes in the process group corresponding to the second buffer within 5 minutes of being reclaimed to the second buffer, and needs to be reclaimed by the Buddy system after 5 minutes.
[0149] In this embodiment of the application, the above-mentioned system buffer is a buffer for allocating memory for any process in the electronic device. That is to say, when any process in the electronic device needs to allocate memory, it can allocate memory from the system buffer.
[0150] It should be noted that the above-mentioned reclamation of the first memory to the system buffer of the electronic device can be understood as reclamation of the first memory to the Buddy system.
[0151] In this way, if some memory in any buffer exceeds the reclamation time, some memory in any buffer will be released to the Buddy system for use by other processes, thus avoiding the situation where other processes need to slowly reclaim the memory they need.
[0152] The memory control method provided in this application does not simply group processes into a process group based on a single process or a process created by a single application. Instead, it groups processes according to the component interaction relationships and memory page sharing relationships of each process. After grouping, it determines the memory allocation strategy and memory reclamation strategy based on the process groups associated with each process. It also creates a two-level cache of private buffer and public buffer to solve the problem of increased power consumption and reduced efficiency caused by the need for slow reclamation after memory release and re-allocation of memory in complex usage scenarios, which cannot be solved by native cgroups. This reduces the power consumption of electronic devices and improves memory allocation efficiency.
[0153] Figure 5 is a flowchart illustrating the memory control method provided in an embodiment of this application. The method may include the following steps 501 to 511.
[0154] Step 501: The electronic device determines whether process A and process B interact as components or whether process A and process B share memory.
[0155] Step 502: The electronic device obtains the priority of process A and the priority of process B, determines the process with higher priority as the main process, and determines the process with lower priority as the secondary process.
[0156] Step 503: The electronic device determines whether the main process is in a certain process group. If yes, proceed to step 504; otherwise, proceed to step 505.
[0157] Step 504: The electronic device determines whether the secondary process is in a certain process group. If yes, proceed to step 506; otherwise, proceed to step 507.
[0158] Step 505: The electronic device creates a process group for the main process and returns to step 504.
[0159] Step 506: If the secondary process is associated with two process groups, the electronic device will associate the memory reclamation policy and memory allocation policy of the secondary process with the common buffer corresponding to the two process groups.
[0160] It should be noted that associating the memory reclamation strategy of the secondary process with the common buffer corresponding to the two process groups described above can be understood as the electronic device reclaiming the memory released by the secondary process into the common buffer corresponding to the two process groups associated with the secondary process when the secondary process releases memory. Similarly, associating the memory allocation strategy of the secondary process with the common buffer corresponding to the two process groups described above can be understood as the electronic device allocating memory for the secondary process not only from the private buffer corresponding to the process group to which the secondary process belongs, but also from the common buffer corresponding to the two process groups associated with the secondary process.
[0161] Step 507: The electronic device adds the secondary process to the process group where the main process is located.
[0162] Step 508: If the secondary process is associated with a process group, the electronic device associates the memory reclamation policy and memory allocation policy of the secondary process with the private buffer corresponding to the process group to which the secondary process belongs.
[0163] It should be noted that associating the memory reclamation strategy of the secondary process with the private buffer corresponding to the process group to which the secondary process belongs can be understood as the electronic device reclaiming the memory released by the secondary process into the private buffer corresponding to the process group to which the secondary process belongs (i.e., the process group to which the main process belongs) when releasing memory. Similarly, associating the memory allocation strategy of the secondary process with the private buffer corresponding to the process group to which the secondary process belongs can be understood as the electronic device allocating memory from the private buffer corresponding to the process group to which the secondary process belongs when allocating memory for the secondary process.
[0164] Step 509: The electronic device sets a first duration threshold and a second duration threshold for the recycling time for the first process and the second process according to the types of the first process and the second process.
[0165] It should be noted that step 509 can be implemented after step 508, after step 504, or after step 502. This application embodiment only uses the example of step 509 being implemented after step 508 for illustrative purposes.
[0166] Step 510: The electronic device determines that the association between the first process and the second process has been severed.
[0167] Step 511: If the memory released by the first process takes longer to be recycled in the buffer than the first time threshold, the electronic device will reclaim the memory released by the first process into the Buddy system; if the memory released by the second process takes longer to be recycled in the buffer than the second time threshold, the electronic device will reclaim the memory released by the second process into the Buddy system.
[0168] It should be noted that the specific implementation process of steps 501 to 511 above can be found in the relevant description of the above embodiments. To avoid repetition, this embodiment will not repeat the description here.
[0169] The following example illustrates memory grouping, memory reclamation, and memory allocation strategies. Assume process A first binds to the service component of process B, and process B is then added to the process group memCgroup1 where process A resides. Subsequently, process C accesses the provider component of process B; process C resides in memCgroup2. Memory released by process A will be placed in PRIVATE CACHE1 corresponding to memCgroup1; memory released by process C will be placed in PRIVATE CACHE2 corresponding to memCgroup2; because process B is associated with two memCgroups, the memory released by process B will be placed in TOTAL CACHE. Memory in TOTAL CACHE is only mapped to memCgroup1 and memCgroup2, and only processes within these two memCgroups can allocate it.
[0170] The memory control method provided in the embodiments of this application will be further explained below with reference to Figure 6.
[0171] Referring to Figure 6, when the electronic device runs application A, it creates processes A, B, and E; when running application B, it creates processes C and D. Process A is bound to the service component of process B, process A accesses the provider component of process C, and processes A and C share memory pages. The electronic device can group processes A, B, C, and D according to the memory grouping policy cMemCgroup. For example, the electronic device can group these four processes into the same process group, group1. Then, the electronic device associates the memory reclamation / allocation policy with a private cache or a public cache, where the private cache can include private cache1, private cache2, private cache3, etc. After the memory reclamation time in the private cache or public cache reaches a certain threshold, the electronic device reclaims the memory to the Buddy system.
[0172] It should be noted that each of the above method embodiments, or various possible implementations of each method embodiment, can be executed individually or in combination of any two or more. The specific implementation can be determined according to actual usage requirements, and this application embodiment does not impose any restrictions on this.
[0173] The memory control method provided in this application can be executed by a memory control device. This application uses the execution of the memory control method by a memory control device as an example to illustrate the memory control device provided in this application.
[0174] Figure 7 is a schematic diagram of the structure of the memory control device provided in an embodiment of this application. The memory control device includes: an acquisition module 701 and a recycling module 702.
[0175] The aforementioned acquisition module 701 is used to acquire the process group associated with the first process when it is determined that the first process releases the first memory.
[0176] The aforementioned recycling module 702 is used to reclaim the first memory to a first buffer and / or a second buffer if the first process is associated with at least two process groups.
[0177] The at least two process groups include the process group where the first process is located and the process group where the process associated with the first process is located. The first buffer is a private buffer corresponding to the process group where the first process is located, and the second buffer is a public buffer corresponding to the at least two process groups associated with the first process.
[0178] Optionally, in this embodiment of the application, the above-mentioned recycling module 702 is specifically used to recycle the first memory to the first buffer if the first process is associated with at least two groups and the first process is the main process of the process group to which the first process is located; or, if the first process is associated with at least two groups and the first process is the secondary process of the process group to which the first process is located, the first memory is recycled to the second buffer.
[0179] Optionally, in the embodiments of this application, the memory control device may further include an allocation module.
[0180] The aforementioned allocation module is used to allocate second memory to the first process from the first buffer and / or the second buffer when it is determined that the first process needs to be allocated second memory.
[0181] Optionally, in this embodiment of the application, the allocation module is specifically used to allocate second memory from the first buffer to the first process when the memory of the first buffer is greater than or equal to the second memory; or, when the memory of the first buffer is less than the second memory and the memory of the second buffer is greater than or equal to the second memory, allocate second memory from the second buffer to the first process.
[0182] Optionally, in the embodiments of this application, the memory control device may further include a determination module and a grouping module.
[0183] The aforementioned determining module is used to determine the main process and the secondary process in the first process and the second process, based on the importance level of the first process and the importance level of the second process, before obtaining the process group associated with the first process when the first process releases the first memory, and when there is an association between the first process and the second process.
[0184] The aforementioned grouping module is used to group the main process and the secondary processes according to the grouping status of the main process and the grouping status of the secondary processes.
[0185] The relationship between the first process and the second process may include: the first process and the second process interacting with each other, or the first process and the second process sharing memory.
[0186] Optionally, in this embodiment of the application, the above-mentioned determining module is specifically used to determine the main process and the secondary process in the first process and the second process according to the priority of the first process and the priority of the second process when the priority of the first process and the priority of the second process are different; or, when the priority of the first process and the priority of the second process are the same, to determine the main process and the secondary process in the first process and the second process according to the creation time of the first process and the creation time of the second process.
[0187] Optionally, in this embodiment of the application, the grouping module is specifically used to add the secondary process to the process group where the main process is located when the grouping status of the main process is grouped and the grouping status of the secondary process is ungrouped; or, when the grouping status of the main process is ungrouped and the grouping status of the secondary process is grouped, create a process group for the main process; wherein the main process and the secondary process are located in different process groups; or, when the grouping status of both the main process and the secondary process is ungrouped, create a process group for the main process and add the secondary process to the process group where the main process is located.
[0188] Optionally, in the embodiments of this application, the memory control device may further include a removal module.
[0189] The aforementioned removal module is specifically used to remove the first process from the process group to which the first process belongs if the first process meets the removal conditions when the association between the first process and the second process is terminated.
[0190] The termination of the association between the first process and the second process may include: the end of component interaction between the first process and the second process, or the end of shared memory between the first process and the second process. The removal conditions may include: the first process being a secondary process, or the first process being the primary process and the process group to which the first process belongs not including other processes.
[0191] Optionally, in the embodiments of this application, the memory control device may further include an acquisition module.
[0192] The aforementioned acquisition module is specifically used to acquire the recycling duration of the first memory in the first buffer or the second buffer.
[0193] The aforementioned recycling module is also used to reclaim the first memory to the system buffer of the electronic device if the recycling duration is greater than or equal to the duration threshold. This system buffer is a buffer that allocates memory for any process in the electronic device.
[0194] The memory control device provided in this application reclaims the first memory released by the first process to the private buffer corresponding to the process group where the first process is located or the public buffer corresponding to the at least two process groups when the first process is associated with at least two process groups. Therefore, when allocating memory for the process associated with the first process in other process groups, it can allocate memory not only from the private buffer of other process groups but also from the public buffer. That is, if the amount of free memory available to the process associated with the first process is relatively large, there is no need to trigger slow reclamation to reclaim memory, which reduces the power consumption of the memory control device and improves the efficiency of memory management.
[0195] The memory control device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device, augmented reality / virtual reality device, robot, wearable device, super mobile personal computer, netbook, or personal digital assistant, etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the specific implementation.
[0196] The memory control device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0197] The memory control device provided in this application can implement the various processes implemented in the various embodiments of the above-described memory control method. To avoid repetition, it will not be described again here.
[0198] Optionally, as shown in FIG8, this application embodiment also provides an electronic device 900, including a processor 901 and a memory 902. The memory 902 stores a program or instructions that can run on the processor 901. When the program or instructions are executed by the processor 901, they implement the various steps of the above memory control method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0199] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0200] Figure 9 is a schematic diagram of the hardware structure of an electronic device that implements an embodiment of this application.
[0201] The electronic device 1000 includes, but is not limited to, components such as: radio frequency unit 1001, network module 1002, audio output unit 1003, input unit 1004, sensor 1005, display unit 1006, user input unit 1007, interface unit 1008, memory 1009, and processor 1010.
[0202] Those skilled in the art will understand that the electronic device 1000 may also include a power supply (such as a battery) for powering various components. The power supply can be logically connected to the processor 1010 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. The electronic device structure shown in Figure 9 does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0203] The processor 1010 is used to obtain the process group associated with the first process when it is determined that the first process releases the first memory.
[0204] The processor 1010 described above is also configured to reclaim the first memory to a first buffer and / or a second buffer if the first process is associated with at least two process groups.
[0205] The at least two process groups include the process group where the first process is located and the process group where the process associated with the first process is located. The first buffer is a private buffer corresponding to the process group where the first process is located, and the second buffer is a public buffer corresponding to the at least two process groups associated with the first process.
[0206] Optionally, in this embodiment of the application, the processor 1010 is specifically used to reclaim the first memory to the first buffer if the first process is associated with at least two groups and the first process is the main process of the process group to which the first process is located; or, if the first process is associated with at least two groups and the first process is the secondary process of the process group to which the first process is located, to reclaim the first memory to the second buffer.
[0207] Optionally, in this embodiment of the application, the processor 1010 is further configured to allocate second memory for the first process from the first buffer and / or the second buffer when it is determined that the first process needs to be allocated second memory.
[0208] Optionally, in this embodiment of the application, the processor 1010 is specifically used to allocate second memory from the first buffer for the first process when the memory of the first buffer is greater than or equal to the second memory; or, when the memory of the first buffer is less than the second memory and the memory of the second buffer is greater than or equal to the second memory, allocate second memory from the second buffer for the first process.
[0209] Optionally, in this embodiment of the application, the processor 1010 is further configured to, before obtaining the process group associated with the first process when it is determined that the first process has released the first memory, determine the main process and the secondary process in the first process and the second process according to the importance level of the first process and the importance level of the second process when there is an association between the first process and the second process; and, group the main process and the secondary process according to the grouping status of the main process and the grouping status of the secondary process.
[0210] The relationship between the first process and the second process may include: the first process and the second process interacting with each other, or the first process and the second process sharing memory.
[0211] Optionally, in this embodiment of the application, the processor 1010 is specifically used to determine the main process and the secondary process in the first process and the second process according to the priority of the first process and the priority of the second process when the priority of the first process and the priority of the second process are different; or, when the priority of the first process and the priority of the second process are the same, to determine the main process and the secondary process in the first process and the second process according to the creation time of the first process and the creation time of the second process.
[0212] Optionally, in this embodiment of the application, the processor 1010 is specifically configured to add the secondary process to the process group where the main process is located when the grouping status of the main process is grouped and the grouping status of the secondary process is ungrouped; or, when the grouping status of the main process is ungrouped and the grouping status of the secondary process is grouped, create a process group for the main process; wherein the main process and the secondary process are located in different process groups; or, when the grouping status of both the main process and the secondary process is ungrouped, create a process group for the main process and add the secondary process to the process group where the main process is located.
[0213] Optionally, in this embodiment of the application, the processor 1010 is specifically used to remove the first process from the process group to which the first process belongs if the first process meets the removal conditions when the association between the first process and the second process is terminated.
[0214] The termination of the association between the first process and the second process may include: the end of component interaction between the first process and the second process, or the end of shared memory between the first process and the second process. The removal conditions may include: the first process being a secondary process, or the first process being the primary process and the process group to which the first process belongs not including other processes.
[0215] Optionally, in this embodiment of the application, the processor 1010 is specifically used to obtain the recycling duration of the first memory in the first buffer or the second buffer; and if the recycling duration is greater than or equal to the duration threshold, the first memory is recycled to the system buffer of the electronic device, the system buffer being a buffer for allocating memory for any process in the electronic device.
[0216] The electronic device provided in this application embodiment reclaims the first memory released by the first process to the private buffer corresponding to the process group where the first process is located or the public buffer corresponding to the at least two process groups when the first process is associated with at least two process groups. Therefore, when allocating memory for the process associated with the first process in other process groups, it can allocate memory not only from the private buffer of other process groups but also from the public buffer. That is, if the free memory available to the process associated with the first process is relatively large, there is no need to trigger slow reclamation to reclaim memory, thereby reducing the power consumption of the electronic device and improving the efficiency of memory management.
[0217] It should be understood that, in this embodiment, the input unit 1004 may include a graphics processing unit (GPU) 10041 and a microphone 10042. The GPU 10041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 1006 may include a display panel 10061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. 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 a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.
[0218] The memory 1009 can be used to store software programs and various data. The memory 1009 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 1009 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 109 in the embodiments of this application includes, but is not limited to, these and any other suitable types of memory.
[0219] 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 handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into the processor 1010.
[0220] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the memory control method embodiments described above and achieve the same technical effects. To avoid repetition, they will not be described again here.
[0221] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0222] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the memory control method embodiments described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0223] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0224] This application provides a computer program product that is stored in a storage medium and executed by at least one processor to implement the various processes of the memory control method embodiments described above, and can achieve the same technical effects. To avoid repetition, it will not be described again here.
[0225] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0226] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0227] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A memory control method, the method comprising: If it is determined that the first process releases the first memory, obtain the process group associated with the first process; If the first process is associated with at least two process groups, then the first memory is reclaimed to the first buffer and / or the second buffer; The at least two process groups include the process group where the first process is located and the process group where the process associated with the first process is located. The first buffer is a private buffer corresponding to the process group where the first process is located, and the second buffer is a public buffer corresponding to the at least two process groups associated with the first process.
2. The method of claim 1, wherein, The method further includes: If it is determined that the first process needs to be allocated the second memory, the second memory is allocated to the first process from the first buffer and / or the second buffer.
3. The method of claim 1 or 2, wherein, Before obtaining the process group associated with the first process after determining that the first process has released the first memory, the method further includes: When there is a relationship between the first process and the second process, the main process and the secondary process are determined in the first process and the second process according to the importance level of the first process and the importance level of the second process; Based on the grouping status of the main process and the grouping status of the secondary processes, the main process and the secondary processes are grouped. The relationship between the first process and the second process includes: the first process and the second process interacting with each other, or the first process and the second process sharing memory.
4. The method according to claim 3, wherein, The step of determining the main process and the secondary process in the first process and the second process based on the importance levels of the first process and the second process includes: If the priority of the first process is different from that of the second process, the main process and the secondary process are determined in the first process and the second process according to the priority of the first process and the priority of the second process. If the priority of the first process is the same as that of the second process, the main process and the secondary process are determined in the first process and the second process based on their creation time.
5. The method of claim 3, wherein, The step of grouping the main process and the secondary processes according to the grouping status of the main process and the grouping status of the secondary processes includes: If the main process is in a grouped state and the secondary process is in an ungrouped state, the secondary process is added to the process group in which the main process is located. If the main process is in an ungrouped state and the secondary process is in a grouped state, a process group is created for the main process; wherein the main process and the secondary process are in different process groups. If both the main process and the secondary process are in an ungrouped state, a process group is created for the main process, and the secondary process is added to the process group where the main process is located.
6. A memory control device, the device comprising: Acquisition module and recycling module; The acquisition module is used to acquire the process group associated with the first process when it is determined that the first process releases the first memory; The recycling module is configured to reclaim the first memory to a first buffer and / or a second buffer if the first process is associated with at least two process groups. The at least two process groups include the process group where the first process is located and the process group where the process associated with the first process is located. The first buffer is a private buffer corresponding to the process group where the first process is located, and the second buffer is a public buffer corresponding to the at least two process groups associated with the first process.
7. The apparatus of claim 6, wherein, The device also includes a distribution module; The allocation module is configured to allocate the second memory to the first process from the first buffer and / or the second buffer when it is determined that the first process needs to be allocated the second memory.
8. The apparatus of claim 6 or 7, wherein, The device also includes a determination module and a grouping module; The determining module is used to determine the main process and the secondary process in the first process and the second process, based on the importance level of the first process and the importance level of the second process, before obtaining the process group associated with the first process when the first process releases the first memory, and when there is an association between the first process and the second process. The grouping module is used to group the main process and the secondary process according to the grouping status of the main process and the grouping status of the secondary process. The relationship between the first process and the second process includes: the first process and the second process interacting with each other, or the first process and the second process sharing memory.
9. The apparatus of claim 8, wherein, The determining module is specifically used for: If the priority of the first process is different from that of the second process, the main process and the secondary process are determined in the first process and the second process according to the priority of the first process and the priority of the second process. If the priority of the first process is the same as that of the second process, the main process and the secondary process are determined in the first process and the second process based on their creation time.
10. The apparatus of claim 8, wherein, The grouping module is specifically used for: If the main process is in a grouped state and the secondary process is in an ungrouped state, the secondary process is added to the process group in which the main process is located. If the main process is in an ungrouped state and the secondary process is in a grouped state, a process group is created for the main process; wherein the main process and the secondary process are in different process groups. If both the main process and the secondary process are in an ungrouped state, a process group is created for the main process, and the secondary process is added to the process group where the main process is located.
11. An electronic device comprising a processor and a memory, the memory storing a program or instructions executable on the processor, the program or instructions, when executed by the processor, implementing the steps of the memory control method as described in any one of claims 1 to 5.
12. A readable storage medium storing a program or instructions that, when executed by a processor, implement the steps of the memory control method as described in any one of claims 1 to 5.
13. A chip comprising a processor and a communication interface, the communication interface being coupled to the processor, the processor being configured to run a program or instructions to implement the memory control method as described in any one of claims 1 to 5.
14. A computer program product stored in a storage medium, the program product being executed by at least one processor to implement the memory control method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
A method and a device for sharing a cache between application programs
CN109726017A
Memory management method and device
CN115129459A
Memory control method and device, electronic equipment and readable storage medium
CN119396574A
Detection of over-access of memory shared among multiple processes
US20180341428A1