Memory control method and device, electronic equipment and readable storage medium

By obtaining process packets in electronic devices and reclaiming memory to private and public buffers, the problem of inefficient memory allocation and recycling between processes is solved, achieving more efficient memory management and reducing power consumption.

CN119396574APending Publication Date: 2025-02-07VIVO MOBILE COMM CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411432110.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

In electronic devices, memory allocation and recycling between processes are inefficient, resulting in increased system power consumption, especially in the case of multi-application switching and function sharing.

Method used

Optimize memory allocation and recycling strategies by obtaining process groups associated with processes and recycling them to private and public buffers when the process frees memory.

Benefits of technology

It improves the efficiency of memory management, reduces the power consumption of electronic devices, avoids the necessity of slow recycling, and ensures memory availability between processes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396574A_ABST
    Figure CN119396574A_ABST
Patent Text Reader

Abstract

The invention discloses a memory control method and device, electronic equipment and a readable storage medium, and belongs to the technical field of electronics. The memory control method can comprise the steps of obtaining a process group associated with a first process under the condition of determining that the first process releases a first memory; if the first process is associated with at least two process groups, the first memory is recycled to the first buffer area and / or the second buffer area, and the at least two process groups comprise 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 area is a private buffer area corresponding to a process group where the first process is located, and the second buffer area is a public buffer area corresponding to at least two process groups associated with the first process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of electronic technology, and specifically relates to a memory control method, device, electronic device and readable storage medium. Background Art

[0002] Memory allocation in electronic device systems is based on processes. When the system runs multiple processes at the same time, after process A releases a portion of memory, this portion of memory will be recycled to the system and may be immediately allocated to process B. Then, if process A needs memory again, there may be insufficient free memory available in the system, which may require slow recycling to allocate the required memory to process A.

[0003] To address the above issues, electronic devices can usually allocate memory based on applications. That is, the processes created when the same application is running are divided into a group, and the memory released by the processes in the same group is set to be stored in a buffer corresponding to the group. When reallocating memory for the processes in the group, the memory in the buffer can be allocated first, and processes in other groups cannot use the memory in the buffer.

[0004] However, in actual situations, it is common for application A to use the functions of application B, or for electronic devices to switch back and forth between multiple applications. In these cases, if the buffer corresponding to the group where the process of application A is located includes a lot of memory, it may cause insufficient free memory available in the system, and the processes of other applications (such as application B) still need to trigger slow recycling to allocate the required memory. Therefore, the above-mentioned method of allocating memory by application may still result in the situation where slow recycling needs to be entered to allocate the required memory when allocating memory to the process, resulting in increased power consumption of the electronic device and low efficiency of memory management. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a memory control method, device, electronic device and readable storage medium, which can reduce the power consumption of the electronic device and improve the efficiency of memory management.

[0006] In a first aspect, an embodiment of the present application provides a memory control method, the method comprising: obtaining a process group associated with the first process when determining that the first process releases the first memory; if the first process is associated with at least two process groups, reclaiming the first memory to a first buffer and / or a second buffer. The at least two process groups include a process group where the first process is located and a process group where processes associated with the first process are 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 at least two process groups associated with the first process.

[0007] In a second aspect, an embodiment of the present application provides a memory control device, which includes: an acquisition module and a recovery module. The acquisition module is used to acquire a process group associated with the first process when it is determined that the first process releases the first memory. The recovery module is used to recover 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 a process group where the first process is located and a process group where processes associated with the first process are 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 at least two process groups associated with the first process.

[0008] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the program or instructions are executed by the processor, the steps of the memory control method described in the first aspect are implemented.

[0009] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the memory control method described in the first aspect are implemented.

[0010] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the memory control method as described in the first aspect.

[0011] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the memory control method as described in the first aspect.

[0012] In the embodiment of the present application, 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 recovered to the first buffer and / or the second buffer, wherein 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. In this way, for a process, since when the process is associated with at least two process groups, the first memory released by the process is recovered to the private buffer corresponding to the process group where the process is located and / or the public buffer corresponding to the at least two process groups, therefore, for any process, when allocating memory for the process, it can be allocated not only from the private buffer of the process group where the process is located, but also from the public buffer corresponding to the process group associated with the process, that is, when allocating memory for any process, the amount of free memory that can be allocated is relatively large, and there is no need to trigger slow recovery to recycle memory, which reduces the power consumption of the electronic device and improves the efficiency of memory management. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 This is one of the flowcharts of the memory control method provided in the embodiment of the present application;

[0014] Figure 2 This is the second flow chart of the memory control method provided in the embodiment of the present application;

[0015] Figure 3 This is the third flow chart of the memory control method provided in the embodiment of the present application;

[0016] Figure 4 This is the fourth flowchart of the memory control method provided in the embodiment of the present application;

[0017] Figure 5 This is the fifth flow chart of the memory control method provided in the embodiment of the present application;

[0018] Figure 6 is a schematic diagram of process grouping and buffer zones provided in an embodiment of the present application;

[0019] Figure 7 is a schematic diagram of the structure of a memory control device provided in an embodiment of the present application;

[0020] Figure 8 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0021] Fig. 9 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0022] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0023] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0024] The terms "at least one (item)", "at least one of" and the like in the specification and claims of the present application refer to any one, any two or a combination of more than two of the objects included therein. For example, at least one (item) of a, b, and c can be represented by: "a", "b", "c", "a and b", "a and c", "b and c" and "a, b and c", where a, b, and c can be single or multiple. Similarly, "at least two (items)" refers to two or more, and its meaning is similar to that of "at least one (item)".

[0025] The memory control method, device, electronic device and readable storage medium provided in the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.

[0026] First, the technical terms involved in the embodiments of the present application are explained.

[0027] Slow recycling: When the system's memory cleanup tool (memFree) does not have enough memory, it is necessary to scan all memory pages when the application requests memory to confirm whether they can be recycled. This takes a long time and can easily cause system freezes.

[0028] Control group (cgroup): A function derived from the Linux kernel, used to manage and control resources for processes and process groups. In the Android system, cgroup is used to implement system-level resource management to ensure that resource usage between different applications is reasonably allocated and controlled. The Android system can use cgroup to group applications or processes to limit resources, set priorities, and monitor them to ensure system stability, performance, and security. Cgroups are usually based on applications, and each application's process is divided into a group.

[0029] Components: A process is composed of some scattered but related components. Different types of components carry different functions of the process. For example, activities carry application display-related content; services carry invisible tasks; and content providers provide data sharing.

[0030] Buddy System: In Android, the Buddy System algorithm is often used for the kernel's physical memory management, especially in the allocation of page frames (Page FrameAllocation). 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 release, thereby improving system performance and stability.

[0031] Adjustment Value (Adj value): In Android, the Adj value is an indicator used to indicate the priority of a process. The Adj value is an integer that represents the importance and priority of a process in the system. The system schedules the process and allocates resources based on this value.

[0032] Next, the application scenarios of the memory control method provided in the embodiments of the present application are introduced.

[0033] The memory control method provided in the embodiments of the present application can be applied to scenarios of memory allocation or memory recycling.

[0034] In the memory allocation scenario, the memory allocation in the electronic device system is based on the process, and the memory allocated to each process will change dynamically with the running of the application. For example, if one process of the application requires a large amount of memory, more memory will be allocated, and if another process of the application requires a small amount of memory, less memory will be allocated. In addition, when allocating memory, memory may be allocated to the process from the buffer or from the system.

[0035] In the memory recycling scenario, the memory occupied by the process will be recycled to the system after the process ends, or, affected by the memory recycling policy of the electronic device system, part of the memory occupied by the process will be recycled by the system after reaching the set threshold; alternatively, the memory occupied by the process can be recycled to the buffer so that it can be quickly allocated when the process needs memory again.

[0036] The embodiment of the present application provides a memory control method, in the case of determining that the first process releases the first memory, obtaining the process group associated with the first process; if the first process is associated with at least two process groups, the first memory is recovered to the first buffer and / or the second buffer, wherein 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. In this way, for a process, since when the process is associated with at least two process groups, the first memory released by the process is recovered to the private buffer corresponding to the process group where the process is located and / or the public buffer corresponding to the at least two process groups, therefore, for any process, when allocating memory for the process, it can be allocated not only from the private buffer of the process group where the process is located, but also from the public buffer corresponding to the process group associated with the process, that is, when allocating memory for any process, the amount of free memory that can be allocated is relatively large, and there is no need to trigger slow recovery to recycle memory, which reduces the power consumption of the electronic device and improves the efficiency of memory management.

[0037] The execution subject of the memory control method provided in the embodiment of the present application may be a memory control device. Exemplarily, the memory control device may be an electronic device, or a functional component or functional entity in the electronic device. The memory control method provided in the embodiment of the present application will be described exemplarily below by taking the execution subject as an electronic device as an example.

[0038] Figure 1 is a flow chart of the memory control method provided in the embodiment of the present application, such as Figure 1 As shown, the memory control method provided in the embodiment of the present application may include the following steps 101 and 102.

[0039] Step 101: When determining that a first process releases a first memory, the electronic device obtains a process group associated with the first process.

[0040] In the embodiment of the present application, the first process may be a process created when the application is running. An application may create multiple processes when it is running, and the first process may be any one of the multiple processes. It can be understood that the memory control method provided in the embodiment of the present application can be used to allocate memory and recycle memory for any process in the electronic device.

[0041] In the embodiment of the present application, the above-mentioned first memory may be part of the memory or all of the memory occupied by the first process.

[0042] Optionally, in an embodiment of the present 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 is completed, or when it is determined that the running state of the first process is a terminated state or a suspended state, or when it is determined that the free memory of the system is insufficient. The above-mentioned task completion includes task completion, task cancellation or task failure.

[0043] Exemplarily, when the task executed by the first process is completed, the first memory occupied by the first process is no longer needed and can be released. For example, taking the first process executing a data processing task as an example, when the data processing is completed and the result is output, the memory used to store the original data and the intermediate result can be released.

[0044] Exemplarily, when the task performed by the first process is cancelled or fails for some reason, the memory associated with the task can be released to avoid memory leaks. Wherein, the memory associated with the task can be all or part of the memory occupied by the first process.

[0045] For example, when the first process switches from the running state to the 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, so as to ensure the effective use of the memory.

[0046] For example, in some cases, the first process may be suspended, i.e., execution is suspended. If the suspension is temporary, and the first process may resume execution in the future, the first memory occupied by the first process may not be released immediately. However, if the suspension is permanent, such as because the first process is cancelled or the system has insufficient free memory, the first memory occupied by the first process may be released.

[0047] For example, when the free memory of the electronic device system is insufficient, the system may trigger a memory recycling mechanism to release the first memory that is no longer used in the first process.

[0048] Optionally, in the embodiment of the present application, the electronic device may determine the process group where the first process is located and the process group where the process associated with the first process is located as the process group associated with the first process.

[0049] It should be noted that the process associated with the first process is a process that has component interaction with the first process and a process that shares memory with the first process. For a specific explanation, please refer to the description of step 301. In addition, the electronic device groups the first process and the processes associated with the first process, that is, determines the specific implementation of the group where the first process is located and the process group where the processes associated with the first process are located. Please refer to the description of steps 301 and 302.

[0050] Step 102: If the first process is associated with at least two process groups, the electronic device recycles the first memory to the first buffer and / or the second buffer.

[0051] In the embodiment of the present application, the process grouping may include at least one process. The process grouping may be referred to as a memory control group (memCgroup).

[0052] Optionally, in an embodiment of the present application, when the process group includes at least two processes, there is an association relationship between any two of the at least two processes. The association relationship between any two processes includes: there is component interaction between the any two processes, or the any two processes share memory.

[0053] It should be noted that the existence of component interaction between any two of the above processes can be understood as the existence of interaction between one or some of the processes between any two of the above processes.

[0054] Exemplarily, taking any two processes as process A and process B as an example, the component interaction between the above any 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 the like.

[0055] Exemplarily, taking the above arbitrary two processes as a desktop process and a display process as an example, the above arbitrary two processes sharing memory may include: when the desktop process is in the foreground, it shares the same memory in the same buffer with the display process surfaceflinger.

[0056] In the embodiment of the present application, the at least two process groups mentioned above may include a process group where the first process is located and a process group where a process associated with the first process is located.

[0057] Exemplarily, assuming that 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); or, 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).

[0058] In the embodiment of the present application, the first buffer may be a private buffer corresponding to the process group where the first process is located. The memory in the private buffer is only used by processes in the process group where the first process is located, and cannot be used by processes in other process groups. Exemplarily, the private buffer may be called PRIVATE CACHE.

[0059] In an embodiment of the present application, the second buffer may be a public buffer corresponding to at least two process groups associated with the first process. The memory in the public buffer may be used by processes in the at least two process groups, but may not be used by processes in other process groups. Exemplarily, the public buffer may be called TOTAL CACHE.

[0060] Optionally, in the embodiment of the present application, combined with Figure 1 ,like Figure 2 As shown, the above step 102 can be specifically implemented through the following steps 1021 and 1022.

[0061] 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 where the first process is located, the electronic device recycles the first memory to the first buffer.

[0062] Example 1, assuming that 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, process C is in process group 2, and process A is the main process of process group 1, process B is the secondary process of process group 1, and process C is the main process of process group 2. Then, taking the first process as process C as an example, since process C is associated with process group 2 and process group 1, and process C is the main process of process group 2, the electronic device recycles the memory released by process C to the private buffer corresponding to process group 2 (i.e., the first buffer).

[0063] Optionally, in an embodiment of the present application, the above-mentioned electronic device reclaiming the first memory to the first buffer may include: 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 is located, and then maintains the correspondence between the group identifier and the first memory in the first buffer, so that when the memory is subsequently allocated, the first memory can be allocated to the process in the process group indicated by the group identifier.

[0064] Exemplarily, assuming that the process group associated with the first process is memCgroup1, after the electronic device marks the first memory as idle, 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.

[0065] Furthermore, when 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.

[0066] Optionally, in an embodiment of the present application, 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, that is, records the group identifier of the process group to which the first process belongs, and then maintains the correspondence between the group identifier and the first part of the memory in the first buffer, so that when the memory is subsequently allocated, the first part of the memory can be allocated to the process in the process group indicated by the group identifier. In addition, 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, 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 second part of the memory in the second buffer, so that when the memory is subsequently allocated, the second part of the memory can be allocated to the process in the process group indicated by the at least two group identifiers.

[0067] Step 1022: If the first process is associated with at least two groups, and the first process is a sub-process of the process group in which the first process is located, the electronic device recycles the first memory to the second buffer.

[0068] Example 2, combined with the above Example 1, taking the first process as process B as an example, since process B is associated with process group 2 and process group 1, and process B is a sub-process of process group 1, the electronic device recycles the memory released by process B to the public buffer corresponding to process group 2 and process group 2 (ie, the second buffer).

[0069] Optionally, in an embodiment of the present application, the above-mentioned electronic device reclaiming the first memory to the second buffer may include: 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 the at least two group identifiers and the first memory in the second buffer, so that when the memory is subsequently allocated, the first memory can be allocated to the process within the process group indicated by the at least two group identifiers.

[0070] Exemplarily, assuming that the process groups associated with the first process are memCgroup1 and memCgroup2, and the first process is in memCgroup1 and is a sub-process in memCgroup1, after the electronic device marks the first memory as idle, it 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.

[0071] In an embodiment of the present application, when a first process is associated with at least two process groups, if the first process is the main process of the process group to which it belongs, the memory released by the first process is recovered to a private buffer corresponding to the process group to which it belongs, or a private buffer and a public buffer; if the first process is a sub-process of the process group to which it belongs, the memory released by the first process is recovered to a public buffer corresponding to at least two process groups associated with it, so that the first memory can be used not only by processes in the process group to which the first process belongs, but also by processes in the process group associated with the first process. In this way, the amount of free memory available to the processes associated with the first process is relatively large, and there is no need to trigger slow recovery to recycle memory, thereby reducing the power consumption of electronic devices and improving the efficiency of memory management.

[0072] Optionally, in the embodiment of the present application, after the above step 101, the memory control method provided in the embodiment of the present application may further include the following step 103.

[0073] Step 103: If the first process is associated with a process group, the electronic device recycles the first memory to the first buffer.

[0074] Optionally, in the embodiment of the present application, if the first process is associated with a process group, the process group associated with the first process may be the process group to which the first process belongs.

[0075] It should be noted that the implementation process of the electronic device recycling the first memory to the first buffer can refer to the relevant description of the above step 102, and the embodiment of the present application will not be repeated here.

[0076] Optionally, in the embodiment of the present application, combined with Figure 1 ,like Figure 3 As shown, after the above step 102, the memory control method provided in the embodiment of the present application may further include the following step 201.

[0077] Step 201: When determining that a first process needs to be allocated a second memory, the electronic device allocates a second memory to the first process from a first buffer and / or a second buffer.

[0078] In the embodiment of the present application, the first process to be allocated the second memory can be understood as the first process needs to be allocated the second memory, that is, the first process needs to use the second memory.

[0079] Optionally, in the embodiment of the present application, when the first process has no available memory or insufficient memory, the electronic device may determine that the first process is to be allocated the second memory. Alternatively, when creating the first process, the electronic device needs to allocate the second memory to the first process, that is, the electronic device determines that the second process is to be allocated the second memory.

[0080] Optionally, in an embodiment of the present application, when the process group to which the first process belongs corresponds to the first buffer, the electronic device may allocate a second memory for the first process from the first buffer.

[0081] Exemplarily, if the memory of the first buffer is greater than or equal to the second memory, the electronic device allocates the second memory from the first buffer to the first process; if the memory of the first buffer is less than the second memory, the electronic device allocates the second memory to the first process from the memory reclaimed by the system.

[0082] It should be noted that the memory of the first buffer is all free memory, that is, memory that is not used or occupied.

[0083] Optionally, in an embodiment of the present application, when the process group to which the first process belongs corresponds to the first buffer and the second buffer, the electronic device may first allocate memory to the first process from the first buffer, and then allocate memory to the first process from the first buffer and / or the second buffer based on the memory of the first buffer, the memory of the second buffer, and the second memory.

[0084] Optionally, in the embodiment of the present application, combined with Figure 3 ,like Figure 4 As shown, the above step 201 can be specifically implemented through the following step 2011 or step 2012.

[0085] Step 2011: When it is determined that the first process needs to be allocated a second memory and the memory of the first buffer is greater than or equal to the second memory, the electronic device allocates the second memory to the first process from the first buffer.

[0086] Step 2012: When it is determined that the first process needs to allocate the second memory, the memory of the first buffer is smaller than the second memory, and the memory of the second buffer is greater than or equal to the second memory, the electronic device allocates the second memory to the first process from the second buffer.

[0087] Optionally, in an embodiment of the present application, when it is determined that the first process is to be allocated a 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 may allocate a portion of memory from the first buffer to the first process, and allocate a portion of memory from the second buffer to the first process, and the sum of these two portions of memory is equal to the second memory.

[0088] Optionally, in an embodiment of the present application, when it is determined that the first process needs to be allocated the second memory, the memory of the first buffer is smaller than the second memory, and the memory of the second buffer is smaller than the second memory, the electronic device allocates the second memory to the first process from the memory reclaimed by the system.

[0089] Exemplarily, if the memory of the first buffer is greater than or equal to the second memory, that is, the memory of the first buffer is sufficient for the first process, the electronic device allocates the second memory from the first buffer to the first process. If the memory of the first buffer is less than the second memory, it is determined whether the memory of the second buffer is less than the second memory. If not, the second memory is allocated from the second buffer to the first process; if so, the second memory is allocated from the memory recovered by the system to the first process.

[0090] It should be noted that the memory of the second buffer is all free memory, that is, memory that is not occupied or used.

[0091] For example, assuming that the process group to which the first process belongs is memCgroup1, and the private buffer corresponding to memCgroup1 is PRIVATE CACHE, and the corresponding public buffer is TOTALCACHE, then first determine whether the memory of PRIVATE CACHE is sufficient. If so, allocate the second memory to the first process from PRIVATE CACHE. If not, determine whether the memory of PRIVATE CACHE is sufficient. If so, allocate the second memory to the first process from TOTAL CACHE. If not, allocate the second memory to the first process from the memory recovered by the system.

[0092] In an embodiment of the present application, when allocating memory for a first process, if the memory of a private buffer corresponding to the process group to which the first process belongs is insufficient, the electronic device allocates memory for the first process from a public buffer corresponding to the process group to which the first process belongs, without triggering slow recycling, thereby improving memory allocation efficiency.

[0093] It should be noted that the above step 201 can be performed after step 102 or before step 101, and this embodiment of the present application does not limit this. Figure 3 The above step 201 is performed after step 102 as an example for illustrative description.

[0094] Optionally, in an embodiment of the present application, before the above step 101, the memory control method provided in the embodiment of the present application may further include the following steps 301 and 302.

[0095] Step 301: When a first process and a second process are associated with each other, the electronic device determines a main process and a sub-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.

[0096] In the embodiment of the present application, the association relationship between the first process and the second process may include: there is component interaction between the first process and the second process, or the first process and the second process share memory.

[0097] Optionally, in an embodiment of the present application, the above-mentioned importance level may include priority and creation time point, and the above-mentioned step 301 may be specifically implemented through the following step 3011 or step 3012.

[0098] Step 3011: When the priority of the first process is different from the priority of the second process, the electronic device determines a main process and a sub-process in the first process and the second process according to the priority of the first process and the priority of the second process.

[0099] Optionally, in the embodiment of the present application, the priority is used to indicate the importance of the process in the system, and can be represented by an Adj value. In addition, the electronic device can set a smaller Adj value to represent a higher priority, or set a larger Adj value to represent a higher priority, which is not limited in the embodiment of the present application.

[0100] It should be noted that the priority of a process can be determined according to the user visibility and perceptibility of the process. The priority of a process that is visible or perceptible to the user is higher than the priority of a process that is invisible or imperceptible to the user.

[0101] Exemplarily, since the process running in the foreground is visible to the user, the priority of the process running in the foreground is higher than the priority of the process running in the background. The priority of the process playing music in the background is higher than the priority of the process performing tasks in the background that the user cannot perceive.

[0102] Optionally, in an embodiment of the present application, when the priority of the first process is different from that of the second process, the electronic device may determine the process with a higher priority among the first process and the second process as the main process and determine the other process as the secondary process.

[0103] For example, assuming that 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 the priority of the second process. Then, the electronic device can determine the first process as the main process and the second process as the secondary process.

[0104] Step 3012: When the priority of the first process is the same as the priority of the second process, the electronic device determines a main process and a sub-process in the first process and the second process according to a creation time point of the first process and a creation time point of the second process.

[0105] Optionally, in an embodiment of the present application, when the priority of the first process is the same as the priority of the second process, the electronic device may, based on the creation time point of the first process and the creation time point of the second process, determine the process with an earlier creation time point among the first process and the second process as the main process, and determine the other process as the secondary process.

[0106] For example, assuming that the first process and the second process have the same priority, and the creation time of the first process is 10:00, and the creation time of the second process is 10:01, the creation time of the first process is earlier than the creation time of the second process, then the electronic device can determine the first process as the main process and the second process as the secondary process.

[0107] In this way, the electronic device determines the main process and the secondary process in the first process and the second process according to the priority and creation time of the first process and the second process, which facilitates the subsequent division of process groups and setting of memory allocation strategy and memory recovery strategy.

[0108] Step 302: The electronic device groups the main process and the sub-process according to the grouping state of the main process and the grouping state of the sub-process.

[0109] In the embodiment of the present application, the grouping status of a process can be used to indicate whether the process has been grouped, and the above grouping status can include grouped or not grouped.

[0110] Optionally, in an embodiment of the present application, the grouping state of a process can be determined by determining whether the process belongs to a certain process group. If it is determined that the process belongs to a certain process group, the grouping state of the process is determined to be grouped, and if it is determined that the process does not belong to a certain process group, the grouping state of the process is determined to be ungrouped.

[0111] 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 the process group.

[0112] Optionally, in an embodiment of the present application, the above step 302 can be specifically implemented through the following steps 3021 to 3023.

[0113] Step 3021: When the grouping state of the main process is grouped and the grouping state of the sub-process is ungrouped, the electronic device adds the sub-process to the process group where the main process is located.

[0114] Exemplarily, if the main process already belongs to the process group memCgroup1, and the secondary process has not yet been grouped, the electronic device may also add the secondary process to memCgroup1.

[0115] Step 3022: When the grouping state of the main process is ungrouped and the grouping state of the secondary process is grouped, the electronic device creates a process group for the main process.

[0116] In the embodiment of the present application, the above-mentioned main process and the above-mentioned sub-process are located in different process groups.

[0117] Exemplarily, if the main process does not belong to any process group, and the secondary process belongs to the process group memCgroup2, a process group memCgroup1 is created for the main process.

[0118] Step 3023: When the grouping status of the main process and the sub-process are both ungrouped, the electronic device creates a process group for the main process and adds the sub-process to the process group where the main process is located.

[0119] Exemplarily, if neither the main process nor the sub-process belongs to any process group, the electronic device creates a process group memCgroup1 for the main process, and also adds the sub-process to the memCgroup1.

[0120] In this way, after the main process and the secondary process are grouped according to their grouping status, the process groups associated with the main process and the secondary process can be determined according to the association between the main process and the secondary process, as well as the process group where the main process is located and the process group where the secondary process is located, thereby determining how to reclaim and allocate memory in the future.

[0121] Optionally, in the embodiment of the present application, after the above step 302, the memory control method provided in the embodiment of the present application may further include the following step 303.

[0122] Step 303: When the association between the first process and the second process is released, if the first process meets the removal condition, the electronic device removes the first process from the process group where the first process is located.

[0123] In the embodiment of the present application, the termination of the association between the first process and the second process may include: the component interaction between the first process and the second process ends, or the shared memory between the first process and the second process ends.

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

[0125] Exemplarily, taking the first process as process A and the second process as process B, the termination of the component interaction between the first process and the second process may include: unbinding the service component of process A from process B, termination of process A's access to the provider component of process B, shutdown of the provider component of process B, termination of the interaction between the Activity component of process A and the service component of process B, termination of the interaction between the Service component of process A and the service component of process B, and the like.

[0126] Exemplarily, taking the first process as a desktop process and the second process as a display process, the end of the shared memory between the first process and the second process may be: the desktop process switches from the foreground to the background, and the display process still runs in the foreground. In this case, the two use different memories.

[0127] In the embodiment of the present application, the above removal conditions may include: the first process is a secondary process, or the first process is a main process and the process group to which the first process belongs does not include other processes.

[0128] In an example of the present application, when the association relationship between the first process and the second process is released, if the first process is a sub-process of the first process and the second process, the electronic device removes the first process from the process group where the first process is located.

[0129] For example, it is assumed that process A is associated with process B, process A is the main process, process B is the secondary process, process A is in process group 1, and process B is in process group 2. Taking the first process as process B as an example, when the association between process A and process B is released, process B is removed from process group 2.

[0130] Optionally, in an embodiment of the present application, the group where the first process is located does not include other processes, which may include: the group where the first process is located only includes the first process before the association between the first process and the second process is released, or the group where the first process is located includes the first process and the sub-process before the association between the first process and the second process is released, and after the association between the first process and the second process is released, the sub-process has been removed.

[0131] In another example of the present application, when the association between the first process and the second process is released, if the first process is the main process of the first process and the second process, and there are no other processes in the process group where the first process is located, the electronic device removes the first process from the process group where the first process is located.

[0132] For example, it is assumed that process A is associated with process B, process A is the main process, process B is the secondary process, process A is in process group 1, and process B is in process group 2. For example, the first process is process A, and process group 1 only includes process A. When the association between process A and process B is released, process A is removed from process group 1.

[0133] For example, it is assumed that process A is associated with process B, process A is the main process, 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, when the association between process A and process B is released, the electronic device will remove both process B and process A from process group 1.

[0134] In another example of the present application, when the association between the first process and the second process is released, if the first process is the main process of the first process and the second process, and there are other processes in the process group where the first process is located, the first process is not removed.

[0135] For example, it is assumed that process A is associated with process B, process A is the main process, process B is the secondary process, process A is in process group 1, and process B is in process group 2. For example, if the first process is process A, and process group 1 also includes process C and process D, when the association between process A and process B is released, there is no need to remove process A from process group 1.

[0136] In this way, after the association between the first process and the second process is released, the first process that meets the removal conditions is removed, which can avoid the process that is not associated with the process group occupying the memory of the private buffer or public buffer corresponding to the process group, resulting in the process in the process group not being able to allocate memory, thereby improving the efficiency and success rate of memory allocation.

[0137] Optionally, in the embodiment of the present application, after the above step 102, the memory control method provided in the embodiment of the present application may further include the following steps 104 and 105.

[0138] Step 104: The electronic device obtains a recovery time length of the first memory in the first buffer or the second buffer.

[0139] Optionally, in an embodiment of the present application, the recycling time of the first memory in the first buffer can be understood as the time during which the first memory has been associated with the first buffer after being recycled to the first buffer. The recycling time of the first memory in the second buffer can be understood as the time during which the first memory has been associated with the second buffer after being recycled to the second buffer.

[0140] Optionally, in an embodiment of the present application, the electronic device may determine the recycling time of the first memory in the first buffer according to the difference between the time point when the first memory is recycled to the first buffer and the current time point. Similarly, the electronic device may determine the recycling time of the first memory in the second buffer according to the difference between the time point when the first memory is recycled to the second buffer and the current time point.

[0141] For example, assuming that the time point when the first memory is recycled to the first buffer is 10:00 and the current time point is 10:02, it can be determined that the recycling time of the first memory in the first buffer is 2 minutes, that is, the first memory has been associated with the first buffer for 2 minutes. Assuming that the time point when the first memory is recycled to the second buffer is 10:00 and the current time point is 10:03, it can be determined that the recycling time of the first memory in the second buffer is 3 minutes, that is, the first memory has been associated with the second buffer for 3 minutes.

[0142] Step 105: If the recycling time is greater than or equal to the time threshold, the electronic device recycles the first memory to the system buffer of the electronic device.

[0143] Optionally, in the embodiment of the present application, the duration threshold corresponds to the first process and can be set according to the type of the first process, wherein the type of the first process may include foreground, visible, perceptible, recently used, background service, and the like.

[0144] Optionally, in an embodiment of the present application, the electronic device can set different duration thresholds for different types of processes according to the type of process. For example, the electronic device can set the duration threshold of the foreground process to 3 minutes, set the duration threshold of the recently used process to 5 minutes, and so on.

[0145] It should be noted that the above-mentioned duration threshold can be understood as the duration during which the first memory can be allocated to the processes in the process group corresponding to the first buffer, or the duration during which the first memory can be allocated to the processes in at least two process groups corresponding to the second buffer.

[0146] For example, assuming that the duration threshold is 5 minutes, it means that the first memory can be allocated to the process in the process group corresponding to the first buffer within 5 minutes from the time it is recycled to the first buffer, and needs to be recycled by the Buddy system after 5 minutes. Or, it means that the first memory can be allocated to the process in the process group corresponding to the second buffer within 5 minutes from the time it is recycled to the second buffer, and needs to be recycled by the Buddy system after 5 minutes.

[0147] In the embodiment of the present application, the above-mentioned system buffer is a buffer for allocating memory to any process in the electronic device, that is, when any process in the electronic device needs to allocate memory, memory can be allocated to it from the system buffer.

[0148] It should be noted that the above-mentioned recycling of the first memory to the system buffer of the electronic device can be understood as recycling the first memory to the Buddy system.

[0149] In this way, when some memory in any buffer exceeds the recycling time, some memory in any buffer is released to the Buddy system for use by other processes, avoiding the situation where other processes need slow recycling to allocate the required memory.

[0150] The memory control method provided in the embodiment of the present application does not simply divide the processes created by a certain process or an application into a process group, but groups the processes according to the component interaction relationship of each process and the memory sharing relationship of the memory page, and after grouping, determines the memory allocation strategy and the memory recovery strategy according to the process group associated with the process, and creates a two-level cache of a private buffer and a public buffer to solve the problem of increased power consumption and reduced efficiency caused by slow recovery when reapplying for memory after releasing memory, which cannot be solved by the native cgroup in complex usage scenarios, thereby reducing the power consumption of electronic devices and improving memory allocation efficiency.

[0151] Figure 5 4 is a flow chart of a memory control method provided in an embodiment of the present application. The method may include the following steps 501 to 511.

[0152] Step 501: The electronic device determines that components of process A and process B interact or that process A and process B share memory.

[0153] Step 502: The electronic device obtains the priority of process A and the priority of process B, determines the process with a higher priority as the main process, and determines the process with a lower priority as the secondary process.

[0154] Step 503 , the electronic device determines whether the main process is in a certain process group, if so, executes step 504 , if not, executes step 505 .

[0155] Step 504 , the electronic device determines whether the secondary process is in a certain process group, if so, executes step 506 , if not, executes step 507 .

[0156] Step 505 : The electronic device creates a process group for the main process and returns to execute step 504 .

[0157] Step 506: If the sub-process is associated with two process groups, the electronic device associates the memory recovery strategy and the memory allocation strategy of the sub-process with the common buffers corresponding to the two process groups.

[0158] It should be noted that the above-mentioned association of the memory recovery strategy of the sub-process with the public buffer corresponding to the two process groups can be understood as when the electronic device releases the memory of the sub-process, the memory released by the sub-process is recovered to the public buffer corresponding to the two process groups associated with the sub-process. Similarly, the above-mentioned association of the memory allocation strategy of the sub-process with the public buffer corresponding to the two process groups can be understood as when the electronic device allocates memory to the sub-process, it can not only allocate from the private buffer corresponding to the process group where the sub-process is located, but also allocate from the public buffer corresponding to the two process groups associated with the sub-process.

[0159] Step 507: The electronic device adds the secondary process to the process group where the primary process is located.

[0160] Step 508: If the sub-process is associated with a process group, the electronic device associates the memory recovery strategy and memory allocation strategy of the sub-process with the private buffer corresponding to the process group to which the sub-process belongs.

[0161] It should be noted that the above-mentioned association of the memory recovery strategy of the secondary process with the private buffer corresponding to the process group where the secondary process is located can be understood as when the electronic device releases the memory of the secondary process, the memory released by the secondary process is recovered to the private buffer corresponding to the process group where the secondary process is located (that is, the process group where the main process is located). Similarly, the above-mentioned association of the memory allocation strategy of the secondary process with the private buffer corresponding to the process group where the secondary process is located can be understood as when the electronic device allocates memory to the secondary process, it can be allocated from the private buffer corresponding to the process group where the secondary process is located.

[0162] Step 509: The electronic device sets a first duration threshold and a second duration threshold of the recycling duration for the first process and the second process according to the types of the first process and the second process.

[0163] It should be noted that the above-mentioned step 509 can be implemented after step 508, can also be implemented after step 504, and can also be implemented after step 502. The embodiment of the present application only takes the implementation of step 509 after step 508 as an example for illustrative explanation.

[0164] Step 510: The electronic device determines that the association between the first process and the second process is released.

[0165] Step 511: if the recovery time of the memory released by the first process in the buffer is greater than the first time threshold, the electronic device recycles the memory released by the first process into the Buddy system; if the recovery time of the memory released by the second process in the buffer is greater than the second time threshold, the electronic device recycles the memory released by the second process into the Buddy system.

[0166] It should be noted that the specific implementation process of the above steps 501 to 511 can refer to the relevant description of the above embodiment. To avoid repetition, this embodiment will not be repeated here.

[0167] Next, we will give examples to illustrate memory grouping, memory recycling, and memory allocation strategies. Assume that process A first binds the service component of process B. At this time, process B is added to the process group memCgroup1 where process A is located. Then process C accesses the provider component of process B, and the process group where process C is located is memCgroup2. The memory released by process A will be placed in PRIVATE CACHE1 corresponding to memCgroup1; the 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, and the memory in TOTAL CACHE is only mapped to memCgroup1 and memCgroup2, and only processes in these two memCgroups can be allocated.

[0168] Next, combine Figure 6 The memory control method provided in the embodiment of the present application is further explained.

[0169] See also Figure 6When the electronic device runs application A, it creates process A, process B and process E. When running application B, it creates process C and process D. In addition, process A is bound to the service component of process B, process A accesses the provider component of process C, and process A shares memory pages with process C. The electronic device can group process A, process B, process C and process D according to the memory grouping strategy cMemCgroup. For example, the electronic device can divide these four processes into the same process group group1. Then, the electronic device associates the memory recovery / allocation strategy with the private buffer PRIVATE CACHE or the public buffer TOTAL CACHE, and PRIVATE CACHE can include PRIVATE CACHE1, PRIVATE CACHE2, PRIVATE CACHE3 and the like. After the recovery time of the memory in the private buffer PRIVATE CACHE or the public buffer TOTAL CACHE reaches the time threshold, the electronic device recycles the memory to the Buddy system.

[0170] It should be noted that the above-mentioned method embodiments, or various possible implementation methods in each method embodiment, can be executed separately, or any two or more can be executed in combination with each other. The specific implementation method can be determined according to actual usage requirements, and the embodiments of the present application do not impose any restrictions on this.

[0171] The memory control method provided in the embodiment of the present application can be executed by a memory control device. In the embodiment of the present application, the memory control device provided in the embodiment of the present application is described by taking the memory control method executed by the memory control device as an example.

[0172] Figure 7 701 is a schematic diagram of the structure of a memory control device provided in an embodiment of the present application. The memory control device includes: an acquisition module 701 and a recovery module 702.

[0173] The acquisition module 701 is used to acquire a process group associated with the first process when it is determined that the first process releases the first memory.

[0174] The recycling module 702 is configured to recycle the first memory to the first buffer and / or the second buffer if the first process is associated with at least two process groups.

[0175] Among them, 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 at least two process groups associated with the first process.

[0176] Optionally, in an embodiment of the present 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 where the first process is located; or, if the first process is associated with at least two groups and the first process is the sub-process of the process group where the first process is located, recycle the first memory to the second buffer.

[0177] Optionally, in the embodiment of the present application, the above-mentioned memory control device may further include an allocation module.

[0178] The allocation module is used 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.

[0179] Optionally, in an embodiment of the present application, the above-mentioned allocation module is specifically used to allocate the second memory to the first process from the first buffer 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 the second memory to the first process from the second buffer.

[0180] Optionally, in the embodiment of the present application, the above-mentioned memory control device may further include a determination module and a grouping module.

[0181] The above-mentioned determination module is used to determine the main process and the sub-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 it is determined that the first process releases the first memory, before obtaining the process group associated with the first process, when the first process and the second process have an association relationship.

[0182] The above 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.

[0183] The association relationship between the first process and the second process may include: there is component interaction between the first process and the second process, or the first process and the second process share memory.

[0184] Optionally, in an embodiment of the present application, the above-mentioned determination module is specifically used to determine the main process and the sub-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 is different from that of the second process; or, when the priority of the first process is the same as that of the second process, determine the main process and the sub-process in the first process and the second process according to the creation time point of the first process and the creation time point of the second process.

[0185] Optionally, in an embodiment of the present application, the above-mentioned 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 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.

[0186] Optionally, in the embodiment of the present application, the above-mentioned memory control device may further include a removal module.

[0187] The removal module is specifically used to remove the first process from the process group where the first process is located if the association relationship between the first process and the second process is released and the first process meets the removal condition.

[0188] The removal of the association between the first process and the second process may include: the component interaction between the first process and the second process ends, or the shared memory between the first process and the second process ends. The removal condition 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.

[0189] Optionally, in the embodiment of the present application, the above-mentioned memory control device may further include an acquisition module.

[0190] The acquisition module is specifically used to acquire the recycling time of the first memory in the first buffer or the second buffer.

[0191] The recycling module is further configured to recycle the first memory to a system buffer of the electronic device if the recycling time is greater than or equal to a time threshold, where the system buffer is a buffer for allocating memory to any process in the electronic device.

[0192] The memory control device provided in the embodiment of the present 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 to processes associated with the first process in other process groups, it can be allocated not only from the private buffers of other process groups but also from the public buffers. That is, if the amount of free memory available to the processes associated with the first process is relatively large, there is no need to trigger slow recovery to recycle the memory, which reduces the power consumption of the memory control device and improves the efficiency of memory management.

[0193] The memory control device in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or a device other than a terminal. For example, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a mobile Internet device, an augmented reality / virtual reality device, a robot, a wearable device, a super mobile personal computer, a netbook or a personal digital assistant, etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0194] The memory control device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0195] The memory control device provided in the embodiment of the present application can implement each process implemented by each embodiment of the above-mentioned memory control method, and will not be described again here to avoid repetition.

[0196] Alternatively, if Figure 8 As shown, an embodiment of the present application also provides an electronic device 900, including a processor 901 and a memory 902, wherein the memory 902 stores programs or instructions that can be executed on the processor 901, and when the program or instructions are executed by the processor 901, the various steps of the above-mentioned memory control method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not described here.

[0197] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.

[0198] Fig. 9 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.

[0199] The electronic device 1000 includes but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009, and a processor 1010 and other components.

[0200] Those skilled in the art will appreciate that the electronic device 1000 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1010 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Fig. 9 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.

[0201] The processor 1010 is configured to obtain a process group associated with the first process when it is determined that the first process releases the first memory.

[0202] The processor 1010 is further configured to recycle the first memory to the first buffer and / or the second buffer if the first process is associated with at least two process groups.

[0203] Among them, 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 at least two process groups associated with the first process.

[0204] Optionally, in an embodiment of the present application, the above-mentioned processor 1010 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 where the first process is located; or, if the first process is associated with at least two groups and the first process is the sub-process of the process group where the first process is located, recycle the first memory to the second buffer.

[0205] Optionally, in the embodiment of the present application, the processor 1010 is further 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.

[0206] Optionally, in an embodiment of the present application, the above-mentioned processor 1010 is specifically used to allocate the second memory to the first process from the first buffer 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 the second memory to the first process from the second buffer.

[0207] Optionally, in an embodiment of the present application, the processor 1010 is further used to, when it is determined that the first process releases the first memory, before obtaining the process group associated with the first process, determine the main process and the sub-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 the first process and the second process have an association relationship; and group the main process and the sub-process according to the grouping status of the main process and the grouping status of the sub-process.

[0208] The association relationship between the first process and the second process may include: there is component interaction between the first process and the second process, or the first process and the second process share memory.

[0209] Optionally, in an embodiment of the present application, the above-mentioned processor 1010 is specifically used to determine the main process and the sub-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 is different from that of the second process; or, when the priority of the first process is the same as that of the second process, determine the main process and the sub-process in the first process and the second process according to the creation time point of the first process and the creation time point of the second process.

[0210] Optionally, in an embodiment of the present application, the above-mentioned processor 1010 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 in different process groups; or, when the grouping status of the main process and the secondary process are both ungrouped, create a process group for the main process and add the secondary process to the process group where the main process is located.

[0211] Optionally, in an embodiment of the present application, the processor 1010 is specifically configured to remove the first process from the process group to which the first process belongs when the association between the first process and the second process is released and the first process meets a removal condition.

[0212] The removal of the association between the first process and the second process may include: the component interaction between the first process and the second process ends, or the shared memory between the first process and the second process ends. The removal condition 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.

[0213] Optionally, in an embodiment of the present application, the above-mentioned processor 1010 is specifically used to obtain the recovery time of the first memory in the first buffer or the second buffer; and if the recovery time is greater than or equal to the time threshold, the first memory is recovered to the system buffer of the electronic device, and the system buffer is a buffer that allocates memory to any process in the electronic device.

[0214] The electronic device provided by the embodiment of the present application, since when the first process is associated with at least two process groups, the first memory released by the first process is recovered 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. Therefore, when allocating memory to the process associated with the first process in other process groups, it can be allocated not only from the private buffer of the other process groups but also from the public buffer. That is, the amount of free memory available for the process associated with the first process is relatively large, and there is no need to trigger slow recovery to recycle the memory, thereby reducing the power consumption of the electronic device and improving the efficiency of memory management.

[0215] It should be understood that in the embodiment of the present application, the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042, and the graphics processor 10041 processes the image data of the static picture or video obtained by the image capture device (such as a camera) in the video capture mode or the image capture mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1007 includes a touch panel 10071 and at least one of other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include two parts: a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.

[0216] The memory 1009 can be used to store software programs and various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1009 may include a volatile memory or a non-volatile memory, or the memory 1009 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 109 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.

[0217] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1010.

[0218] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned memory control method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0219] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.

[0220] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned memory control method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0221] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0222] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned memory control method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0223] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0224] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0225] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A memory control method, characterized in that: The method comprises: When it is determined that the first process releases the first memory, obtaining a process group associated with the first process; If the first process is associated with at least two process groups, reclaiming the first memory to a first buffer and / or a second buffer; Among them, 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 at least two process groups associated with the first process.

2. The method according to claim 1, characterized in that The method further comprises: When 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 according to claim 1 or 2, characterized in that: In the case of determining that the first process releases the first memory, before obtaining the process group associated with the first process, the method further includes: In the case where the first process and the second process are associated with each other, determining a main process and a sub-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; Grouping the main process and the secondary process according to the grouping state of the main process and the grouping state of the secondary process; The association relationship between the first process and the second process includes: there is component interaction between the first process and the second process, or the first process and the second process share memory.

4. The method according to claim 3, characterized in that The determining a main process and a sub-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 includes: When the priority of the first process is different from the priority of the second process, determining a main process and a 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 is the same as the priority of the second process, a main process and a sub-process are determined in the first process and the second process according to a creation time point of the first process and a creation time point of the second process.

5. The method according to claim 3, characterized in that: The grouping the main process and the secondary process according to the grouping state of the main process and the grouping state of the secondary process includes: When the grouping state of the main process is grouped and the grouping state of the sub-process is ungrouped, adding the sub-process to the process group where the main process is located; When the grouping state of the main process is ungrouped and the grouping state of the secondary process is grouped, create a process group for the main process; wherein the main process and the secondary process are in different process groups; When the grouping states of the main process and the sub-process are both ungrouped, a process group is created for the main process, and the sub-process is added to the process group where the main process is located.

6. A memory control device, characterized in that: The device comprises: an acquisition module and a recovery module; The acquisition module is used to acquire a 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 recycle the first memory to a first buffer and / or a second buffer if the first process is associated with at least two process groups; Among them, 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 at least two process groups associated with the first process.

7. The device according to claim 6, characterized in that 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 device according to claim 6 or 7, characterized in that The device also includes a determination module and a grouping module; The determining module is configured to, when it is determined that the first process releases the first memory, determine a main process and a secondary process in the first process and the second process according to an importance level of the first process and an importance level of the second process, before obtaining a process group associated with the first process, if the first process and the second process are associated with each other; The grouping module is used to group the main process and the secondary process according to the grouping state of the main process and the grouping state of the secondary process; The association relationship between the first process and the second process includes: there is component interaction between the first process and the second process, or the first process and the second process share memory.

9. The device according to claim 8, characterized in that The determination module is specifically used for: When the priority of the first process is different from the priority of the second process, determining a main process and a 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 is the same as the priority of the second process, a main process and a sub-process are determined in the first process and the second process according to a creation time point of the first process and a creation time point of the second process.

10. The device according to claim 8, characterized in that The grouping module is specifically used for: When the grouping state of the main process is grouped and the grouping state of the sub-process is ungrouped, adding the sub-process to the process group where the main process is located; When the grouping state of the main process is ungrouped and the grouping state of the secondary process is grouped, create a process group for the main process; wherein the main process and the secondary process are in different process groups; When the grouping states of the main process and the sub-process are both ungrouped, a process group is created for the main process, and the sub-process is added to the process group where the main process is located.

11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the memory control method according to any one of claims 1 to 5 are implemented.

12. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the memory control method according to any one of claims 1 to 5 are implemented.

Citation Information

Cited By

  • Memory control method and apparatus, and electronic device and readable storage medium

    WO2026081905A1