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

By determining the free memory of the memory pool based on the process's scheduling priority and migrating to another memory pool if necessary, the problem of long-term memory application for important processes is solved, and the system fluency of electronic devices is improved.

CN119988034APending Publication Date: 2025-05-13VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510227007.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-27
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

In electronic devices, memory application for important processes takes a long time, resulting in frame dropouts, lags, etc. when displaying application interfaces of electronic devices, reducing system fluency.

Method used

By determining the amount of free memory in the memory pool corresponding to the scheduling priority of the process, if the free memory is sufficient, the memory will be allocated in the memory pool. If it is insufficient, it will be used to allocate another memory pool with a different migration type.

Benefits of technology

This reduces the time the process waits for memory allocation, improves the efficiency of memory allocation, and thus improves the system fluency of electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119988034A_ABST
    Figure CN119988034A_ABST
Patent Text Reader

Abstract

The invention discloses a memory allocation method and device, electronic equipment and a readable storage medium, and belongs to the technical field of electronics. The method comprises the steps that the number of idle memories of a first memory pool corresponding to the scheduling priority of a first process is determined; under the condition that the free memory quantity of the first memory pool is greater than or equal to the quantity of the memory blocks applied by the first process, executing memory allocation operation on the first process according to the first memory pool; under the condition that the free memory quantity of the first memory pool is smaller than the quantity of the memory blocks applied by the first process, performing memory allocation operation on the first process according to the second memory pool; wherein the migration types of the first memory pool and the second memory pool are different.
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 allocation method, device, electronic device and readable storage medium. Background Art

[0002] During the running of an application in an electronic device, the application needs to continuously apply for memory to store data and perform logical operations, so as to maintain the stable operation of the application. Generally, when an application needs to apply for a large amount of memory, the operating system of the electronic device can obtain the process information of the application to perform memory allocation.

[0003] However, in the above method, when the electronic device applies for memory, the memory application of an important process may take a long time, which may cause frame loss and freeze in the process of the electronic device displaying the application interface. As a result, the system fluency of the electronic device is low. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a memory allocation method, device, electronic device and readable storage medium, which can improve the system fluency of the electronic device.

[0005] In a first aspect, an embodiment of the present application provides a memory allocation method, which includes: determining the amount of free memory in a first memory pool corresponding to a scheduling priority of a first process; when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied for by the first process, performing a memory allocation operation on the first process according to the first memory pool; when the amount of free memory in the first memory pool is less than the number of memory blocks applied for by the first process, performing a memory allocation operation on the first process according to a second memory pool; wherein the migration types of the first memory pool and the second memory pool are different.

[0006] In a second aspect, an embodiment of the present application provides a memory allocation device, which includes: a determination module and an execution module; the determination module is used to determine the amount of free memory in a first memory pool corresponding to the scheduling priority of a first process; the execution module is used to perform a memory allocation operation on the first process according to the first memory pool when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied for by the first process; or, when the amount of free memory in the first memory pool is less than the number of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to a second memory pool; wherein the migration types of the first memory pool and the second memory pool are different.

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

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

[0009] In a fifth aspect, an embodiment of the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method described in the first aspect.

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

[0011] In an embodiment of the present application, the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process is determined; when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied by the first process, a memory allocation operation is performed on the first process according to the first memory pool; or, when the amount of free memory in the first memory pool is less than the number of memory blocks applied by the first process, a memory allocation operation is performed on the first process according to the second memory pool; wherein the migration types of the first memory pool and the second memory pool are different. In this scheme, since the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process can be determined first, and then when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied by the first process, memory is allocated to the first memory through the first memory pool, it can be shown that there is a corresponding relationship between the scheduling priority of the process and the memory pool, that is, the corresponding relationship determines the memory pool used by the electronic device for memory allocation for any process, so that when all processes in the electronic device apply for memory using only the same memory pool, the situation that the process that has not successfully applied for memory needs to wait for the memory pool to fill the free memory blocks due to insufficient free memory blocks in the memory pool can be reduced, thereby reducing the time required for the process to wait for memory allocation. Furthermore, in the process of allocating memory for the first process by the electronic device based on the scheduling priority, when the amount of free memory in the first memory pool is less than the number of memory blocks applied for by the first process, the first process can perform memory allocation through other memory pools, thereby reducing the time consumed by the first process waiting for memory allocation in the memory pool corresponding to its scheduling priority. In this way, the efficiency of memory allocation of the electronic device can be improved, thereby improving the system fluency of the electronic device. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 is a flow chart of a memory allocation method in the related art;

[0013] Figure 2 This is one of the flowcharts of a memory allocation method provided in an embodiment of the present application;

[0014] Figure 3 This is the second flowchart of a memory allocation method provided in an embodiment of the present application;

[0015] Figure 4 This is the third flowchart of a memory allocation method provided in an embodiment of the present application;

[0016] Figure 5 This is a fourth flowchart of a memory allocation method provided in an embodiment of the present application;

[0017] Figure 6 This is one of the flow charts of a memory pool filling method provided in an embodiment of the present application;

[0018] Figure 7 This is the second flowchart of a memory pool filling method provided in an embodiment of the present application;

[0019] Figure 8 This is the third flowchart of a memory pool filling method provided in an embodiment of the present application;

[0020] Fig. 9 is a flow chart of a memory pool recycling method provided by an embodiment of the present application;

[0021] Fig.10 It is a structural schematic diagram of a memory allocation device provided in an embodiment of the present application;

[0022] Fig.11 This is one of the hardware structure diagrams of an electronic device provided in an embodiment of the present application;

[0023] Fig.12 This is the second schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

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

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

[0026] The terms "at least one (item)", "at least one of" and the like in the specification of this application refer to any one, any two or a combination of more than two of the objects contained therein. For example, at least one (item) of a, b, and c can be represented by: "a", "b", "c", "a and b", "a and c", "b and c" and "a, b and c", where a, b, c can be single or multiple. Similarly, "at least two (items)" refers to two or more, and its meaning is similar to that of "at least one (item)". The logo in this application is text, symbol, image, etc. used to indicate information, and controls or other containers can be used as carriers for displaying information, including but not limited to text logos, symbol logos, and image logos.

[0027] The following is an explanation of the professional terms involved in the embodiments of the present application:

[0028] Process: A program's running activity on a certain data set in an electronic device. It is the basic unit for resource allocation in the system. It is the entity of program execution, enabling the program to run under the control of the operating system.

[0029] In the related art, when there are a large number of processes that need to apply for memory in an electronic device, the electronic device can determine the order in which the memory application is executed for the processes that need to apply for memory based on the scheduling priority of the processes. Figure 1 The general process of normal user-mode process application in the operating system kernel (Linux Is Not UniX, Linux) shown in the figure, after the user needs to trigger the electronic device to run a new program or perform a task, if the virtual address accessed by the process has not yet established a virtual address and physical address correspondence table, or the table exists but the physical address is not cached, the central processing unit (CPU) cannot work. At this time, Linux will trigger a page fault exception and interrupt the execution of the process. The system needs to read the corresponding data memory page (page) from a slow device (such as a disk) into the physical memory and establish a mapping relationship between the physical memory address and the virtual address space page. Then the process can access the memory of this part of the virtual address space.

[0030] At the same time, the buddy system can divide memory or resources into blocks of equal size (called buddies), each of which can be allocated to a process or thread for use. When a process or thread requests memory or resources, the system searches for an idle buddy to satisfy the request. If an idle buddy is found, the system assigns it to the requester and updates the buddy's status to allocated. If no idle buddy is found, the system splits a larger buddy into two smaller buddies until an idle buddy is found to satisfy the request. Among them, pages can be divided into movable and unmovable according to the migration type.

[0031] Movable: Indicates that the data stored in its page can be migrated. This type of migration contributes a lot to disk cache, process pages, etc. When the system needs to reclaim or reallocate memory, these pages can be moved to other locations to make room for new memory requests.

[0032] Unmovable: Indicates that the page cannot be migrated. These pages usually contain important system data or critical data that is being used, so they cannot be moved. If the system attempts to move these pages, data loss or system instability may occur.

[0033] Contiguous Memory Allocator (CMA) is used to allocate and manage Movable pages.

[0034] However, in the above process, it may happen that an important process needs to wait for the system memory to be released, that is, the memory application takes a long time, and the user-mode process may apply for memory in the slow allocation path (Slow Path). For example, the application time of an important process exceeds the reciprocal of the refresh rate. At this time, the electronic device will experience frame loss, freeze, etc. In this way, the efficiency of electronic devices in allocating memory to processes is poor, and further leads to low system fluency of electronic devices.

[0035] The memory allocation method provided in the embodiment of the present application is described in detail below through specific embodiments and their application scenarios in conjunction with the accompanying drawings.

[0036] The memory allocation method provided in the embodiment of the present application can be applied to the scenario where a process in the system requests memory.

[0037] The memory allocation method provided in the embodiments of the present application is exemplarily described below using some specific scenarios as examples.

[0038] Assume that the scheduling priorities of the processes of the electronic device include: the highest priority and the second highest priority; the system memory includes two memory pools, such as memory pool 1 and memory pool 2; wherein the highest priority corresponds to memory pool 1, and the second highest priority corresponds to memory pool 2.

[0039] Scenario 1: The scheduling priority of process 1 is the highest priority, and the number of memory blocks requested by process 1 is 4.

[0040] The electronic device can determine the amount of free memory in memory pool 1 corresponding to the highest priority; then, when the amount of free memory in memory pool 1 is greater than or equal to 4, such as when the amount of free memory in memory pool 1 is 5, perform a memory allocation operation on process 1 according to memory pool 1; when the amount of free memory in memory pool 1 is less than 4, such as when the amount of free memory in memory pool 1 is 3, perform a memory allocation operation on process 1 according to memory pool 2.

[0041] Scenario 2: The scheduling priority of process 2 is the second highest priority, and the number of memory blocks requested by process 2 is 5.

[0042] The electronic device can determine the amount of free memory in memory pool 2 corresponding to the second highest priority; then, when the amount of free memory in memory pool 2 is greater than or equal to 5, such as when the amount of free memory in memory pool 2 is 5, perform a memory allocation operation on process 2 according to memory pool 2; when the amount of free memory in memory pool 2 is less than 5, such as when the amount of free memory in memory pool 2 is 3, perform a memory allocation operation on process 2 according to memory pool 1.

[0043] It should be noted that the above-mentioned scenarios 1 and 2 are merely illustrative examples of some scenarios in which the embodiments of the present application may be applied. In actual implementation, the embodiments of the present application can also be applied to any possible scenarios in which more processes of different importance apply for memory, and the embodiments of the present application are not limited here.

[0044] Based on the above-mentioned scenario applied by the embodiments of the present application, the memory allocation method provided by the embodiments of the present application determines the amount of free memory of the first memory pool corresponding to the scheduling priority of the first process; when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied for by the first process, a memory allocation operation is performed on the first process according to the first memory pool; or, when the amount of free memory in the first memory pool is less than the number of memory blocks applied for by the first process, a memory allocation operation is performed on the first process according to the second memory pool; wherein the migration types of the first memory pool and the second memory pool are different. In this solution, since the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process can be determined first, and then when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied by the first process, memory is allocated to the first memory through the first memory pool, it can be shown that there is a corresponding relationship between the scheduling priority of the process and the memory pool, that is, the corresponding relationship determines the memory pool used by the electronic device for memory allocation for any process, so when all processes in the electronic device only use the same memory pool to apply for memory, the situation that the process that fails to apply for memory needs to wait for the memory pool to fill the free memory blocks due to insufficient free memory blocks in the memory pool can be reduced, thereby reducing the time required for the process to wait for memory allocation. In addition, in the process of allocating memory for the first process based on the scheduling priority of the electronic device, when the amount of free memory in the first memory pool is less than the number of memory blocks applied by the first process, the first process can perform memory allocation through other memory pools, thereby reducing the time consumed by the first process in the memory pool corresponding to its scheduling priority to wait for memory allocation, so that the efficiency of memory allocation of the electronic device can be improved, thereby improving the system fluency of the electronic device.

[0045] The execution subject of the memory allocation method provided in the embodiment of the present application is a memory allocation device, which can be an electronic device, or a functional module or entity in an electronic device, and the embodiment of the present application does not limit this. The following will take an electronic device as an example to exemplarily illustrate the memory allocation method provided in the embodiment of the present application.

[0046] The present application embodiment provides a memory allocation method. Figure 2 FIG. 1 is a flow chart of a memory allocation method provided by an embodiment of the present application. Figure 2 As shown, the memory allocation method provided in the embodiment of the present application may include the following steps 201 and 202.

[0047] Step 201: The electronic device determines the amount of free memory in a first memory pool corresponding to the scheduling priority of a first process.

[0048] In some embodiments of the present application, the first process may be any one of all processes included in the system of the electronic device, wherein all the processes may be processes corresponding to one application or processes corresponding to multiple applications.

[0049] In some embodiments of the present application, all processes included in the above system may include but are not limited to at least one of the following: a foreground process, a visible process, a service process, a background process (cache process), and an empty process.

[0050] It should be noted that the foreground process is the process that the user is interacting with through the electronic device;

[0051] The above visible processes are processes whose partial program interfaces can be seen by users but will not interact with users in the foreground;

[0052] The above service processes are started by calling the startService() method. Users cannot directly see the interface of these processes, and service processes are usually used to perform some important background operations, such as background downloads, data transmission, etc.

[0053] The above background processes (cache processes) do not include started services and processes that are invisible to users;

[0054] The above empty process is a process that does not contain any application components (Activity, Service, BroadcastReceiver, ContentProvider). Empty processes are usually used to cache data to improve the response speed when the application is started next time.

[0055] In some embodiments of the present application, each of all processes included in the above system corresponds to a scheduling priority.

[0056] In some embodiments of the present application, the above-mentioned scheduling priority may include at least two levels of priority, each level being used to indicate a degree of importance.

[0057] Exemplarily, the above scheduling priorities may include: highest priority, second highest priority and low priority. For example, the foreground process may be the highest priority, the visible process and the service process may be the second highest priority, and the background process and the empty process may be the low priority.

[0058] In some embodiments of the present application, the electronic device may determine the order of CPU resource allocation of at least one process based on the scheduling priority of the at least one process. For example, the process with the highest priority may obtain CPU resources first.

[0059] In some embodiments of the present application, the electronic device can obtain attribute information of each process in at least one process and assign a weight value to each attribute information obtained to obtain a numerical value that can represent the priority through weighted summation, thereby determining the scheduling priority of the at least one process based on the calculated numerical value.

[0060] In some embodiments of the present application, the above-mentioned attribute information may include but is not limited to at least one of the following: process type, process application time, process demand for system resources, and system default settings.

[0061] The process types mentioned above may include, but are not limited to, interactive processes, batch processes, and monitoring processes.

[0062] In some embodiments of the present application, the electronic device can display the process identifier (PID), command name, priority adjustment (Nice) value and priority (pri) of the specified process by executing the ps command. The priority can be a static priority or a dynamic priority in some form of expression.

[0063] It should be noted that the above PID is used to represent the identity of the process, and one process can correspond to one PID. After the process is terminated, the PID corresponding to the process can be recycled by the system and may be assigned to a newly running program later;

[0064] The above command name refers to the command or program name used to start the process;

[0065] The Nice value can be used to describe the priority of a process relative to other processes. The lower the Nice value, the higher the priority. The higher the Nice value, the lower the priority. The Nice value can range from -20 to 19, and the default value is 0.

[0066] Exemplarily, the ps command may be psax-onice, pid, comm, so that the electronic device can display the nice values, process IDs, and command names of all processes in the system.

[0067] In some embodiments of the present application, the memory pools corresponding to processes with different scheduling priorities may be the same or different.

[0068] In some embodiments of the present application, the above-mentioned memory pool may include memory pools corresponding to at least two migration types.

[0069] Exemplarily, the above-mentioned memory pool may include but is not limited to: a memory pool corresponding to a migration type preset in the system compilation process, similar to the Movable type memory pool used in the existing memory application process.

[0070] It should be noted that, during the system compilation process, the electronic device may construct a framework of a preset memory pool, and may not fill the preset memory pool with free memory blocks.

[0071] It should be noted that in the embodiment of the present application, the above-mentioned preset memory pool is used as a VIP type memory pool. The specific description of filling the free memory blocks in the VIP type memory pool can be referred to the description of the following embodiment, and the present application will not repeat it here.

[0072] For example, Figure 3 As shown, it is assumed that the scheduling priorities include: highest priority, second highest priority, and low priority. When the scheduling priority of a process is the highest priority, the electronic device can perform memory allocation for the highest priority process through a memory pool of the first migration type, such as the above-mentioned VIP type memory pool; when the scheduling priority of a process is the second highest priority or low priority, the electronic device can perform memory allocation for the process through a memory pool of the second migration type, such as a Movable type memory pool.

[0073] In some embodiments of the present application, the amount of free memory in the above-mentioned memory pool can be described by the number of memory blocks, such as the memory pool contains 100 free memory blocks; it can also be described by the size of the memory block, such as the free memory capacity of the memory pool is 1MB.

[0074] When describing by capacity, the units that can be used include but are not limited to any of the following: byte (B), kilobyte (KB), megabyte (MB).

[0075] It should be noted that the number of memory blocks is an integer.

[0076] Step 202: When the amount of free memory in the first memory pool is greater than or equal to the amount of memory blocks requested by the first process, the electronic device performs a memory allocation operation on the first process according to the first memory pool.

[0077] The memory allocation method provided in the embodiment of the present application may also include step 201 and step 203.

[0078] Step 203: When the amount of free memory in the first memory pool is less than the amount of memory blocks requested by the first process, the electronic device performs a memory allocation operation on the first process according to the second memory pool.

[0079] In some embodiments of the present application, the above-mentioned "the amount of free memory in the first memory pool is less than the number of memory blocks applied for by the first process" can be understood as: the electronic device is currently unable to continue to allocate memory for the first process through the first memory pool.

[0080] In the embodiment of the present application, the migration types of the first memory pool and the second memory pool are different.

[0081] Exemplarily, when the scheduling priority of the first process is the highest priority, the first memory pool may be a VIP type memory pool, and the second memory pool may be a Movable type memory pool. When the scheduling priority of the first process is the second highest priority, the first memory pool may be a Movable type memory pool, and the second memory pool may be a VIP type memory pool.

[0082] For example, in combination Figure 3 ,like Figure 4 As shown, assuming that the first process is process 1, and the scheduling priority of process 1 is the highest priority, the number of memory blocks applied for by process 1 is 4MB. The electronic device can determine the amount of free memory of the VIP type memory pool, so that when the amount of free memory of the VIP type memory pool is greater than or equal to 4MB, memory allocation is performed for process 1 through the VIP type memory pool; when the amount of free memory of the VIP type memory pool is less than 4MB, memory allocation is performed for process 1 through the Movable type memory pool, thereby reducing the time required for process 1 to wait for the application of the process through the VIP type memory pool.

[0083] Again illustratively, in combination Figure 4 , assuming that the first process is process 2, and the scheduling priority of process 2 is the second highest priority, and the number of memory blocks applied for by process 2 is 5MB, the electronic device can determine the amount of free memory of the Movable type memory pool, so that when the amount of free memory of the Movable type memory pool is greater than or equal to 5MB, memory allocation is performed for process 2 through the Movable type memory pool; when the amount of free memory of the Movable type memory pool is less than 5MB, memory is performed for process 2 through the VIP type memory pool, thereby reducing the time required for process 2 to wait for the application of the process through the Movable type memory pool.

[0084] In the memory allocation method provided in the embodiment of the present application, since the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process can be determined first, and then when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied by the first process, memory is allocated to the first memory through the first memory pool, it can be shown that there is a corresponding relationship between the scheduling priority of the process and the memory pool, that is, the corresponding relationship determines the memory pool used by the electronic device for memory allocation for any process, so that when all processes in the electronic device only use the same memory pool to apply for memory, the situation that the process that fails to apply for memory needs to wait for the memory pool to fill the free memory blocks due to insufficient free memory blocks in the memory pool can be reduced, thereby reducing the time required for the process to wait for memory allocation. In addition, in the process of allocating memory for the first process based on the scheduling priority of the electronic device, if the amount of free memory in the first memory pool is less than the number of memory blocks applied by the first process, the first process can perform memory allocation through other memory pools, thereby reducing the time consumed by the first process in the memory pool corresponding to its scheduling priority to wait for memory allocation, so that the efficiency of memory allocation of the electronic device can be improved, thereby improving the system fluency of the electronic device.

[0085] In some embodiments of the present application, the scheduling priority of the first process is the first priority. Before the "electronic device performs a memory allocation operation on the first process according to the second memory pool" in the above step 203, the memory allocation method provided in the embodiment of the present application may also include the following step 301, and the "electronic device performs a memory allocation operation on the first process according to the second memory pool" in the above step 203 can be specifically implemented by the following step 203a.

[0086] Step 301: The electronic device determines the amount of free memory in the second memory pool.

[0087] In some embodiments of the present application, when the scheduling priority of the process includes the highest priority and the second highest priority, the first priority may be the second highest priority. Therefore, the second memory pool may be the memory pool corresponding to the highest priority, that is, the VIP type memory pool.

[0088] In some embodiments of the present application, the migration type of the second memory pool is the first migration type.

[0089] In some embodiments of the present application, the above-mentioned free memory quantity may be the quantity of free memory blocks that are not currently allocated to any process or task. These free memory blocks may be used by the system or memory manager to satisfy subsequent memory allocation requests.

[0090] In some embodiments of the present application, the method for the electronic device to determine the amount of free memory may include but is not limited to any of the following:

[0091] The electronic device may maintain a data structure through a memory pool management algorithm to track all memory blocks contained in the memory pool, thereby determining the amount of free memory in the memory pool, wherein the data structure may include but is not limited to a linked list and an array;

[0092] The electronic device can maintain a free memory block counter through a memory pool management algorithm to determine the amount of free memory in the memory pool through the value recorded by the counter.

[0093] In some embodiments of the present application, if the amount of free memory in the first memory pool corresponding to the first process is less than the number of memory blocks applied for by the first process, the electronic device may start to obtain the amount of free memory contained in the second memory pool when the memory application waiting time of the first process reaches a preset duration.

[0094] It should be noted that the above-mentioned preset duration may be determined based on the response time of the electronic device displaying a new interface.

[0095] In some embodiments of the present application, the setting of the above-mentioned preset duration can be dynamically changed according to the real-time requirements of the system at different times.

[0096] Step 203a: When the amount of free memory in the second memory pool is greater than or equal to the first amount, the electronic device performs a memory allocation operation on the first process according to the second memory pool.

[0097] In some embodiments of the present application, the first number may be a value determined based on a memory block accommodation threshold of the second memory pool.

[0098] In some embodiments of the present application, since the scheduling priority of the above-mentioned first process is the second highest priority, and the above-mentioned second memory pool is the memory pool corresponding to the highest priority, when the second memory pool is used for the second highest priority, it is necessary to make a judgment based on the first quantity so that sufficient free memory blocks can be reserved in the second memory pool for the highest priority process, so that the highest priority process that needs to apply for memory subsequently can directly execute the memory application through the free memory blocks in the above-mentioned second memory pool.

[0099] It should be noted that if the amount of free memory in the second memory pool is less than the first amount, the electronic device still performs memory allocation for the first process through the first memory pool.

[0100] Exemplarily, the first quantity may be half of the memory block accommodation threshold of the second memory pool. Thus, when the second highest priority process 2 needs to perform memory allocation, if the amount of free memory in the Movable type memory pool is less than the amount of memory blocks required by process 2, the electronic device may obtain the amount of free memory in the VIP type memory pool. If the VIP type memory pool may contain 40MB of memory blocks, the electronic device may apply for memory for the second highest priority process 2 through the VIP type memory pool when the amount of free memory contained in the VIP type memory pool is greater than the first quantity, such as when the amount of free memory is 25MB. At the same time, if the amount of free memory contained in the VIP type memory pool is less than the first quantity, such as when the amount of free memory is 15MB, the electronic device may not be able to apply for memory for the second highest priority process 2 through the VIP type memory pool, so the process 2 needs to wait through the Movable type memory pool to continue to allocate memory through the Movable type memory pool after the Movable type memory pool is filled with enough free memory blocks.

[0101] For example, in combination Figure 4 ,like Figure 5 As shown, assuming that the user requires the electronic device to display the content corresponding to the input within 3ms after receiving the user's input, the above preset duration can be set to a value less than 3ms, such as 1ms. That is, when the amount of free memory in the Movable type memory pool is less than the number of memory blocks applied for by process 2, that is, process 2 cannot directly apply for memory through the Movable type memory pool, process 2 can wait for 1ms. Within the 1ms of waiting, if the amount of free memory in the Movable type memory pool is greater than the number of memory blocks applied for by process 2, the electronic device still allocates memory to process 2 through the Movable type memory pool; if the amount of free memory in the Movable type memory pool continues to be less than the number of memory blocks applied for by process 2, that is, process 2 still cannot apply for memory through the Movable type memory pool, the electronic device can obtain the amount of free memory in the VIP type memory pool, so that when certain conditions are met, such as the amount of free memory is greater than 1 / 2 of the memory block capacity threshold of the VIP type memory pool, the electronic device can allocate memory to process 2 through the VIP type memory pool; or, when the amount of free memory is less than 1 / 2 of the memory block capacity threshold of the VIP type memory pool, the electronic device still allocates memory to process 2 through the Movable type memory pool.

[0102] In some embodiments of the present application, the first number may also be a value obtained by adding half of the memory block accommodation threshold of the second memory pool and the number of memory blocks applied for by the first process. Thus, after the second memory pool performs a memory allocation operation for the first process, the amount of free memory in the second memory pool may still be greater than or equal to half of the memory block accommodation threshold of the second memory pool, thereby reserving sufficient free memory blocks for the highest priority process.

[0103] In an embodiment of the present application, when the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process is insufficient, the first process can continue to apply for memory through other memory pools. In this way, the time required for the first process to wait for sufficient memory to be filled in the first memory pool can be reduced, thereby improving the efficiency of memory allocation in the electronic device and improving the system fluency of the electronic device.

[0104] In some embodiments of the present application, the memory allocation method provided in the embodiments of the present application may further include the following step 401.

[0105] Step 401: When the system memory meets a memory filling condition, the electronic device fills free memory blocks for a third memory pool based on a second quantity.

[0106] In the embodiment of the present application, the second number is the memory block accommodation threshold of the third memory pool, that is, the maximum number of memory blocks that the third memory pool can accommodate.

[0107] In some embodiments of the present application, the second number may be a fixed value set by default, or a value obtained through dynamic training.

[0108] In the embodiment of the present application, the system memory may include a first memory pool and a second memory pool, and the third memory pool may be the first memory pool or the second memory pool.

[0109] In the embodiment of the present application, the above-mentioned memory filling condition may include but is not limited to one of the following: the amount of free memory of the system memory is greater than or equal to the third amount, and the system memory meets the filling trigger condition.

[0110] In some embodiments of the present application, the third number may represent that the amount of free memory in the system memory has reached a high watermark (WMARK_HIGH).

[0111] It should be noted that if the amount of free memory in the system memory reaches the high watermark, it means that the system memory watermark is sufficient, and the system can directly fill the memory for the third memory pool without performing a memory recycling operation.

[0112] In some embodiments of the present application, when the third memory pool is a memory pool of the first migration type, the second number may be a number determined by the electronic device based on device information.

[0113] For example, the third memory pool is a VIP type memory pool. The electronic device can be based on the formula The default memory block accommodation threshold corresponding to the third memory pool is calculated, that is, the second quantity mentioned above. Wherein, RAM_SIZE is the physical memory size of the electronic device, and its unit is GB.

[0114] Among them, when the electronic device is a mobile phone, the above RAM_SIZE may include but is not limited to any of the following: 4GB, 6GB, 8GB, 12GB, 16GB.

[0115] For example, if the electronic device is a mobile phone, and the memory configuration of the mobile phone is 12GB+512GB, the second number corresponding to the VIP type memory pool in the mobile phone is

[0116] In some embodiments of the present application, the electronic device may first fill a memory pool of the first migration type to a second quantity corresponding to the memory pool of the first migration type; at this time, if the system still contains free memory blocks, the memory pool of the second migration type may continue to be filled.

[0117] For example, Figure 6 As shown, since the VIP type memory pool is not filled with free memory blocks during the system initialization phase, after the application releases the memory in the electronic device, if the amount of free memory in the system memory is greater than the high watermark, the electronic device can try to fill the VIP type memory pool. At this time, the electronic device can first detect whether the number of memory blocks contained in the VIP type memory pool has reached the memory block accommodation threshold, that is, the second number mentioned above, and then, if the number of memory blocks contained in the VIP type memory is less than the second number, the electronic device can fill the free memory blocks for the VIP type memory pool based on the second number; if the number of memory blocks contained in the VIP type memory reaches the second number, the electronic device can fill the free memory blocks for other memory pools migrated in the Buddy system, such as the Movable type memory pool.

[0118] In some embodiments of the present application, the above-mentioned system memory satisfies the fill trigger condition, which can be understood as: the electronic device actively sets the fill trigger condition in the system compilation stage to reserve an active fill interface, so that during the use stage of the electronic device, the electronic device can actively write a value to the active fill interface, triggering the electronic device to perform memory filling for the third memory pool.

[0119] In some embodiments of the present application, the above filling trigger condition may be: the electronic device recognizes that the electronic device is currently in a certain special scenario, such as the amount of free memory in a memory pool is less than a preset amount.

[0120] It should be noted that, in the above filling process based on the filling trigger condition, it is not necessary to consider whether the amount of free memory in the system memory is greater than or equal to the above third amount.

[0121] In an embodiment of the present application, the electronic device can fill the third memory pool with free memory blocks, so that the third memory pool can contain sufficient free memory blocks, which can facilitate the process to apply for memory through the third memory pool, and can further appropriately reduce the waiting time required for the process to apply for memory. In this way, the convenience of allocating memory for the electronic device can be improved.

[0122] In some embodiments of the present application, the type of the third memory pool is the first migration type. The memory method provided in the embodiment of the present application may also include the following step 501 or step 502. It should be noted that by executing the following step 501 or step 502, the "second quantity" in the above step 401 can be obtained, that is, the following step 501 or step 502 can be executed before the above step 401.

[0123] Step 501: The electronic device determines a second quantity based on test data.

[0124] In the embodiment of the present application, the test data may be used to characterize the relationship between the amount of free memory in the third memory pool and the fourth amount when at least two applications have completed their memory application.

[0125] In some embodiments of the present application, the fourth number may be the initial capacity of the third memory pool for free memory blocks. For example, the fourth number may be the default memory block capacity threshold calculated based on the formula in step 401.

[0126] In some embodiments of the present application, the above-mentioned test data may include but is not limited to at least one of the following: the above-mentioned fourth quantity, and an increased value.

[0127] In some embodiments of the present application, the test data may be numerical values ​​set based on experience.

[0128] In some embodiments of the present application, the electronic device can perform stress detection on the system memory based on the initial capacity of the free memory blocks in the third memory pool, such as automatically starting and browsing multiple applications contained in the electronic device normally to detect the usage of the free memory blocks contained in the third memory pool during the operation of the multiple applications by the electronic device. Then, if the usage meets the preset conditions, based on the increase value in the test data, the initial capacity set for the third memory pool is increased, and the above-mentioned stress detection is further performed until the usage of the third memory pool does not meet the preset conditions, the training is stopped and the above-mentioned second quantity is determined.

[0129] In some embodiments of the present application, the preset condition may be: after running multiple applications, the remaining memory blocks in the third memory pool are less than or equal to a sixth number, and the sixth number is the product of the initial capacity of the free memory blocks in the third memory pool and a preset ratio. For example, the preset ratio may be 5%.

[0130] In some embodiments of the present application, in order to avoid detection errors in the usage of the third memory pool, when the usage of the third memory pool of the electronic device does not meet the above-mentioned preset conditions, the electronic device may continue to stress test the system memory, so as to stop training and determine the above-mentioned second number if the usage of the third memory pool fails to meet the preset conditions for multiple consecutive times.

[0131] In some embodiments of the present application, the electronic device may set an upper limit value for the second quantity. For example, the electronic device may set the upper limit value of the second quantity to three times the initial capacity contained in the test data.

[0132] For example, Figure 7 As shown, it is assumed that the initial capacity of the VIP type memory pool for free memory blocks is 20MB, and the increase value is 10MB. The electronic device can perform pressure detection on the system memory, such as automatically starting and browsing the 20 applications contained in the electronic device normally, so as to detect the use of the free memory blocks contained in the VIP type memory pool by the electronic device during the operation of the 20 applications. Then, when the remaining number of free memory blocks contained in the VIP type memory pool is less than or equal to 5%, that is, the remaining free memory blocks are less than or equal to 1MB, the electronic device can increase the capacity of the VIP type memory pool for free memory blocks by 10MB, that is, 30MB, and perform pressure detection on the system memory again, and determine whether the remaining free memory blocks contained in the updated VIP type memory pool are less than or equal to 5%, that is, 1.5MB.

[0133] Furthermore, if the remaining free memory blocks in the VIP type memory pool are greater than 1.5MB, the electronic device can perform three more stress tests to determine whether the remaining amounts of the 30MB VIP type memory pool are all greater than 1.5MB. If they are all greater than 1.5MB, the stress test is stopped and the second amount is determined to be 30MB.

[0134] Alternatively, if the remaining free memory blocks in the VIP type memory pool are less than or equal to 1.5MB, the capacity of the free memory blocks in the VIP type memory pool is increased by 10MB, i.e., 40MB. If the capacity of the free memory blocks in the VIP type memory pool is increased for multiple times but the preset condition is not met, and the capacity of the free memory blocks in the VIP type memory pool reaches 3 times the initial value, i.e., 60MB, the electronic device can stop performing pressure detection on the system memory and determine that the second amount is 60MB.

[0135] Step 502: The electronic device determines a second quantity based on the first usage information and the second usage information.

[0136] In the embodiment of the present application, the first usage information represents the number of times the amount of free memory in the third memory pool is less than the fifth amount when at least two applications are in operation.

[0137] The above “the amount of free memory in the third memory pool is less than the fifth amount” may be understood as a situation where memory blocks in the third memory pool are used up.

[0138] In the embodiment of the present application, the second usage information represents the number of times that the amount of free memory in the third memory pool is greater than or equal to the fifth amount when at least two applications are in a running state.

[0139] The above “the amount of free memory in the third memory pool is greater than or equal to the fifth amount” may be understood as a situation where memory blocks in the third memory pool are not fully used.

[0140] In some embodiments of the present application, the electronic device can collect the usage of the third memory pool by the process in a first time period, and update and report it to the server. Then, the electronic device can determine the probability of the third memory pool being used up in the first time period based on the first usage information and the second usage information in the first time period, and determine whether it is necessary to adjust the amount of free memory that the third memory pool can accommodate based on the probability, thereby determining the second amount.

[0141] In some embodiments of the present application, a method for adjusting the amount of free memory that can be accommodated by the third memory pool may include but is not limited to any of the following: increasing a fixed value based on an initial value, increasing proportionally based on the initial value.

[0142] In some embodiments of the present application, the electronic device may set an upper limit value for the second quantity. For example, the electronic device may set the upper limit value of the second quantity to three times the initial capacity contained in the test data.

[0143] In some embodiments of the present application, the first time period may be a time period of a preset duration, for example, 3 hours, 5 hours, 10 hours, 12 hours, or 24 hours.

[0144] In some embodiments of the present application, the reporting interval in the above-mentioned first time period may be a time period of fixed length, such as 1 hour; or may be a time period of dynamically adjustable length.

[0145] For example, Figure 8 As shown, the electronic device can collect the usage of the VIP type memory pool by the processes in the system when the user uses the electronic device, and upload the usage to the server once every hour. Then, the electronic device can count the number of times the VIP type memory pool is used and the number of times it is not used every 10 hours, that is, the first usage information and the second usage information mentioned above.

[0146] Furthermore, if the VIP type memory pool is used up once and not used up four times within the 10 hours, that is, the probability of being used up is 20%, which is less than the preset 80%, then the electronic device does not need to adjust the amount of free memory that the VIP type memory pool can accommodate, that is, directly outputs the above second amount. If the VIP type memory pool is used up nine times within the 10 hours and not used up once, that is, the probability of being used up is 90%, which is greater than the preset 80%, then the electronic device can increase the amount of free memory in the VIP type memory pool by 20% based on the initial value, that is, calculate the updated second amount.

[0147] In some embodiments of the present application, the reporting interval in the first time period may be determined based on the user's usage information of the electronic device.

[0148] For example, assuming that the electronic device determines based on the user's historical usage information of the electronic device that the user uses the electronic device frequently or for a long time between 8:00 and 23:00, the electronic device can upload the usage of the third memory pool by the process applying for memory once every hour between 8:00 and 23:00; if 21:00-23:00 is a time period when the user uses the electronic device intensively, the above-mentioned reporting interval can be shortened within this time period, such as uploading the usage of the third memory pool by the process once every 20 or 30 minutes.

[0149] As another example, assuming that the electronic device determines based on the user's historical usage information of the electronic device that the user uses the electronic device less frequently between 23:00 and 6:00, or determines that this time period is the user's sleep time, the electronic device may increase the above-mentioned reporting interval, such as uploading the usage of the third memory pool by the process applying for memory every two hours between 23:00 and 6:00; or, the electronic device may stop uploading the usage of the third memory pool between 23:00 and 6:00.

[0150] In the embodiment of the present application, since the electronic device can adaptively adjust the amount of free memory that can be accommodated in the memory pool of the first migration type based on the hardware configuration of the electronic device or the user's usage habits, the system fluency of the electronic device can be improved.

[0151] In some embodiments of the present application, if a system abnormality occurs during the process of an electronic device allocating memory to a process based on a memory pool of a first migration type, the electronic device may stop using the memory pool of the first migration type and allocate memory to the process through a memory allocation method included in related technologies.

[0152] In some embodiments of the present application, the memory method provided in the embodiments of the present application may also include the following step 601.

[0153] Step 601: When the usage information of the system memory meets the memory release condition, the electronic device releases the free memory blocks of the fourth memory pool, and fills the released free memory blocks into the fifth memory pool.

[0154] In the embodiment of the present application, the type of the fourth memory pool is the first migration type, and the type of the fifth memory pool is the second migration type.

[0155] In the embodiment of the present application, the system memory may include a first memory pool and a second memory pool.

[0156] In the embodiment of the present application, the fourth memory pool is the first memory pool or the second memory pool, the fifth memory pool is the first memory pool or the second memory pool, and the fourth memory pool is different from the fifth memory pool.

[0157] In some embodiments of the present application, the above memory release condition may indicate that the pressure on the system memory is relatively high.

[0158] It should be noted that the above-mentioned “high system memory pressure” can be understood as: within a certain period of time, the amount of tasks processed by the system exceeds the actual memory capacity of the system, resulting in a state of tight system memory resources.

[0159] In some embodiments of the present application, the above-mentioned usage information may include but is not limited to at least one of the following: memory usage rate, memory swap speed, and number of memory application failures.

[0160] In some embodiments of the present application, the above-mentioned usage information satisfies the memory release conditions and may include but is not limited to at least one of the following: the memory usage rate of the system memory is greater than or equal to a preset ratio, such as 80%; the memory swap speed in the system memory is lower than the physical memory access speed; multiple consecutive new process memory applications fail.

[0161] In some embodiments of the present application, the electronic device may determine the recovery ratio of the free memory blocks of the fourth memory pool based on the pressure level of the system memory.

[0162] In some embodiments of the present application, the reclaiming strategy for the free memory blocks may be: lmkd (full name: low memory killer daemon) strategy.

[0163] It should be noted that the above lmkd policy is a daemon process used to detect low memory usage in the system. When the system memory is tight, lmkd will be responsible for monitoring the memory status and reclaiming memory by terminating unnecessary processes to ensure stable operation of the system.

[0164] In some embodiments of the present application, in the process of reclaiming memory, the electronic device can reclaim it in sequence based on the scheduling priority of the process from low to high.

[0165] It should be noted that each process can correspond to a different priority for determining whether the process is killed, namely, the oom_adj value. The adj value is a key parameter used by the system to evaluate the priority and importance of a process. The smaller the value, the more important the process is and the less likely it is to be killed; the larger the value, the less important the process is and the easier it is to be killed to free up memory.

[0166] In the embodiment of the present application, the above-mentioned memory release condition may include that the fourth memory pool satisfies the recycling trigger condition.

[0167] In some embodiments of the present application, the above-mentioned recycling trigger conditions can be understood as: the electronic device actively sets the filling trigger conditions in the system compilation stage to reserve an active filling interface, so that during the use stage of the electronic device, the electronic device can actively write values ​​to the active filling interface, triggering the electronic device to recycle based on the fourth memory pool.

[0168] In some embodiments of the present application, the above release trigger condition may be: the electronic device recognizes that the electronic device is currently in a certain special scenario, such as the amount of free memory in the system memory is less than a preset value.

[0169] For example, Fig. 9 As shown, when the pressure of the electronic device is at the first level, the electronic device can recycle 80% of the free memory blocks of the VIP type memory pool through the lmkd policy and provide them to the Movable type memory pool; when the pressure of the electronic device is at the second level, the electronic device can recycle 100% of the free memory blocks of the VIP type memory pool through the lmkd policy, that is, release them to adj0, and provide them to the Movable type memory pool. Alternatively, when the electronic device detects that the recycling trigger condition is met, the electronic device can recycle the free memory blocks of the VIP type memory pool based on the setting of the recycling trigger condition and provide them to the Movable type memory pool.

[0170] In some embodiments of the present application, the above-mentioned memory release condition may be a condition set based on the number of memory overflows (Out off Memory, OOM) occurring in the system memory.

[0171] Exemplarily, if OOM occurs frequently in the system memory, such as the number of OOM occurrences within 1 second is greater than or equal to 10 times, the electronic device can release all free memory blocks contained in the VIP type memory pool to the Movable type memory pool to ensure the stability of the system.

[0172] In an embodiment of the present application, the electronic device can release the free memory pool included in the memory pool of the first migration type to provide an executable memory block for the second migration type to ensure the stability of the system and avoid system crashes, thereby improving the robustness of the system.

[0173] For various scenarios to which the embodiments of the present application can be applied, combined with the various implementation schemes of the embodiments of the present application described above, specific examples are given below to illustrate the implementation process in various scenarios of the embodiments of the present application.

[0174] Assume that the memory pool corresponding to the highest scheduling priority is a VIP type memory pool, and the memory block data of the VIP type memory pool is 40MB;

[0175] The memory pool corresponding to the second highest scheduling priority is memory pool 2, and memory pool 2 is a Movable type memory pool.

[0176] Scenario 1: The scheduling priority of process 1 is the highest priority, and the number of memory blocks requested by process 1 is 4MB.

[0177] The electronic device can first determine the amount of free memory in the VIP type memory pool corresponding to the highest priority; then, when the amount of free memory in the VIP type memory pool is greater than or equal to 4MB, such as when the amount of free memory in the VIP type memory pool is 10MB, perform a memory allocation operation on process 1 according to the VIP type memory pool.

[0178] Alternatively, when the amount of free memory in the VIP type memory pool is less than 4MB, such as the amount of free memory in the VIP type memory pool is 3MB, the electronic device can obtain the amount of free memory in the Movable type memory pool, so that when the amount of free memory in the Movable type memory pool is greater than or equal to the number of memory blocks applied for by process 1, such as the amount of memory in the Movable type memory pool is 5MB, which is greater than 4MB, the electronic device can perform memory allocation operations on process 1 according to the Movable type memory pool.

[0179] If the amount of free memory in the Movable type memory pool is less than the number of memory blocks applied for by process 1, such as the amount of memory in the Movable type memory pool is 2MB and less than 4MB, the electronic device cannot perform memory allocation operations on process 1 according to the Movable type memory pool. Therefore, process 1 needs to wait for the VIP type memory pool to perform memory filling operations until the amount of free memory is greater than or equal to 4MB, and then continue to perform memory allocation operations through the VIP type memory pool.

[0180] Scenario 2: The scheduling priority of process 2 is the second highest priority, and the number of memory blocks requested by process 2 is 5MB.

[0181] The electronic device can determine the amount of free memory of the Movable type memory pool corresponding to the second highest priority; then when the amount of free memory in the Movable type memory pool is greater than or equal to 5MB, such as when the amount of free memory in the Movable type memory pool is 5MB, perform a memory allocation operation on process 2 according to the Movable type memory pool.

[0182] Alternatively, when the amount of free memory in the Movable type memory pool is less than 5MB, such as 3MB, the process 1 can wait for a preset time, such as 1ms, based on the Movable type memory pool. Within the 1ms, if the amount of free memory in the Movable type memory pool is greater than 5MB, the electronic device still allocates memory to the process 2 through the Movable type memory pool.

[0183] If the amount of free memory in the Movable type memory pool continues to be less than 5MB, that is, process 2 is still unable to apply for memory through the Movable type memory pool, the electronic device can obtain the amount of free memory in the VIP type memory pool, so that when the amount of free memory in the VIP type memory pool is greater than or equal to the sum of 1 / 2 of the memory block capacity threshold of the VIP type memory pool and the number of memory blocks applied for by process 2, that is, the amount of free memory in the VIP type memory pool is greater than or equal to 25MB, the electronic device can allocate memory to process 2 through the VIP type memory pool; however, if the amount of free memory in the VIP type memory pool is less than 25MB, process 2 needs to wait for the Movable type memory pool to perform a memory filling operation until the amount of free memory is greater than or equal to 5MB before continuing to perform memory allocation operations through the Movable type memory pool.

[0184] It should be noted that the above-mentioned method embodiments, or various possible implementation methods in each method embodiment, can be executed separately, or, under the premise that there is no contradiction, can also be executed in combination with each other. The specific implementation can be determined according to actual usage requirements, and the embodiments of the present application do not limit this.

[0185] It should be noted that the memory allocation method provided in the embodiment of the present application can be executed by a memory allocation device. In the embodiment of the present application, the memory allocation device provided in the embodiment of the present application is described by taking the memory allocation method executed by the memory allocation device as an example.

[0186] Fig.10 FIG. 1 shows a possible structural diagram of a memory allocation device involved in an embodiment of the present application. Fig.10 As shown, the memory allocation device 70 may include: a determination module 71 and an execution module 72;

[0187] The determination module 71 is used to determine the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process;

[0188] An execution module 72 is configured to, when the amount of free memory in the first memory pool is greater than or equal to the amount of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to the first memory pool; or, when the amount of free memory in the first memory pool is less than the amount of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to the second memory pool;

[0189] The migration types of the first memory pool and the second memory pool are different.

[0190] In a possible implementation, the scheduling priority of the first process is the first priority; the determination module 71 is also used to determine the amount of free memory in the second memory pool before performing a memory allocation operation on the first process according to the second memory pool; the execution module 72 is specifically used to perform a memory allocation operation on the first process according to the second memory pool when the amount of free memory in the second memory pool is greater than or equal to the first amount.

[0191] In one possible implementation, the memory allocation device 70 provided in the embodiment of the present application also includes: a filling module; a filling module, which is used to fill free memory blocks for the third memory pool based on a second number when the system memory meets the memory filling condition, and the second number is the memory block accommodation threshold of the third memory pool; wherein the system memory includes a first memory pool and a second memory pool, and the third memory pool is the first memory pool or the second memory pool.

[0192] In a possible implementation, the memory filling condition is one of the following: the amount of free memory in the system memory is greater than or equal to a third amount, and the system memory meets a filling trigger condition.

[0193] In one possible implementation, the type of the third memory pool is the first migration type; the determination module 71 is also used to determine the second quantity based on test data; the test data characterizes the relationship between the amount of free memory in the third memory pool and the fourth quantity when at least two applications complete the memory application.

[0194] In one possible implementation, the type of the third memory pool is a first migration type; the determination module 71 is further used to determine the second quantity based on the first usage information and the second usage information; the first usage information represents the number of times when at least two applications are in a running state, the amount of free memory in the third memory pool is less than the fifth quantity, and the second usage information represents the number of times when at least two applications are in a running state, the amount of free memory in the third memory pool is greater than or equal to the fifth quantity.

[0195] In a possible implementation, the memory allocation device 70 provided in the embodiment of the present application also includes: a release module and a filling module; the release module is used to release the free memory blocks of the fourth memory pool when the usage information of the system memory meets the memory release condition; the filling module is used to fill the free memory blocks released by the release module into the fifth memory pool, the type of the fourth memory pool is the first migration type, and the type of the fifth memory pool is the second migration type; wherein the system memory includes the first memory pool and the second memory pool; the fourth memory pool is the first memory pool or the second memory pool, the fifth memory pool is the first memory pool or the second memory pool, and the fourth memory pool is different from the fifth memory pool.

[0196] In an embodiment of the present application, a memory allocation device is provided. Since the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process can be determined first, and then when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied by the first process, memory is allocated to the first memory through the first memory pool, it can be shown that there is a corresponding relationship between the scheduling priority of the process and the memory pool, that is, the corresponding relationship determines the memory pool used by the memory allocation device for any process to allocate memory, so that when all processes in the memory allocation device only use the same memory pool to apply for memory, the situation that the process that has not successfully applied for memory needs to wait for the memory pool to fill the free memory blocks due to insufficient free memory blocks in the memory pool can be reduced, thereby reducing the time required for the process to wait for memory allocation. Moreover, in the process of allocating memory for the first process based on the scheduling priority by the memory allocation device, if the amount of free memory in the first memory pool is less than the number of memory blocks applied by the first process, the first process can perform memory allocation through other memory pools, thereby reducing the time consumed by the first process in the memory pool corresponding to its scheduling priority to wait for memory allocation, so that the efficiency of memory allocation of the memory allocation device can be improved, thereby improving the system fluency of the memory allocation device.

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

[0198] The memory allocation 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.

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

[0200] Alternatively, if Fig.11 As shown, an embodiment of the present application also provides an electronic device 90, including a processor 91 and a memory 92, wherein the memory 92 stores programs or instructions that can be executed on the processor 91, and when the program or instructions are executed by the processor 91, the various steps of the above-mentioned memory allocation method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not described here.

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

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

[0203] The electronic device 100 includes but is not limited to components such as a radio frequency unit 101, a network module 102, an audio output unit 103, an input unit 104, a sensor 105, a display unit 106, a user input unit 107, an interface unit 108, a memory 109, and a processor 110.

[0204] Those skilled in the art will appreciate that the electronic device 100 may also include a power source (such as a battery) for supplying power to various components, and the power source may be logically connected to the processor 110 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Fig.12 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.

[0205] The processor 110 is used to determine the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process; and when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to the first memory pool; or, when the amount of free memory in the first memory pool is less than the number of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to the second memory pool; wherein the migration types of the first memory pool and the second memory pool are different.

[0206] Optionally, the scheduling priority of the above-mentioned first process is the first priority; the processor 110 is also used to determine the amount of free memory in the second memory pool before performing a memory allocation operation on the first process according to the second memory pool; the processor 110 is specifically used to perform a memory allocation operation on the first process according to the second memory pool when the amount of free memory in the second memory pool is greater than or equal to the first amount.

[0207] Optionally, the processor 110 is further used to fill free memory blocks for the third memory pool based on a second quantity when the system memory meets the memory filling condition, and the second quantity is a memory block accommodation threshold of the third memory pool; wherein the system memory includes a first memory pool and a second memory pool, and the third memory pool is the first memory pool or the second memory pool.

[0208] Optionally, the memory filling condition is one of the following: the amount of free memory in the system memory is greater than or equal to a third amount; the system memory meets a filling trigger condition.

[0209] Optionally, the type of the third memory pool is the first migration type; the processor 110 is further used to determine the second quantity based on test data; the test data characterizes the relationship between the amount of free memory in the third memory pool and the fourth quantity when at least two applications complete the memory application.

[0210] Optionally, the type of the third memory pool is a first migration type; the processor 110 is further used to determine a second quantity based on the first usage information and the second usage information; the first usage information represents the number of times when at least two applications are in a running state, the amount of free memory in the third memory pool is less than the fifth quantity, and the second usage information represents the number of times when at least two applications are in a running state, the amount of free memory in the third memory pool is greater than or equal to the fifth quantity.

[0211] Optionally, the processor 110 is further used to release the free memory blocks of the fourth memory pool and fill the released free memory blocks into the fifth memory pool when the usage information of the system memory meets the memory release condition. The type of the fourth memory pool is the first migration type, and the type of the fifth memory pool is the second migration type; wherein the system memory includes the first memory pool and the second memory pool; the fourth memory pool is the first memory pool or the second memory pool, the fifth memory pool is the first memory pool or the second memory pool, and the fourth memory pool is different from the fifth memory pool.

[0212] In the electronic device provided in the embodiment of the present application, since the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process can be determined first, and then when the amount of free memory in the first memory pool is greater than or equal to the number of memory blocks applied by the first process, memory is allocated to the first memory through the first memory pool, it can be shown that there is a corresponding relationship between the scheduling priority of the process and the memory pool, that is, the corresponding relationship determines the memory pool used by the electronic device for memory allocation for any process, so that when all processes in the electronic device only use the same memory pool to apply for memory, the situation that the process that fails to apply for memory needs to wait for the memory pool to fill the free memory blocks due to insufficient free memory blocks in the memory pool can be reduced, thereby reducing the time required for the process to wait for memory allocation. In addition, in the process of allocating memory for the first process based on the scheduling priority of the electronic device, when the amount of free memory in the first memory pool is less than the number of memory blocks applied by the first process, the first process can perform memory allocation through other memory pools, thereby reducing the time consumed by the first process in the memory pool corresponding to its scheduling priority to wait for memory allocation, so that the efficiency of memory allocation of the electronic device can be improved, thereby improving the system fluency of the electronic device.

[0213] The electronic device provided in the embodiment of the present application can implement each process implemented in the above method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described here.

[0214] The beneficial effects of various implementations in this embodiment can be specifically referred to the beneficial effects of the corresponding implementations in the above method embodiment. To avoid repetition, they will not be described again here.

[0215] It should be understood that in the embodiment of the present application, the input unit 104 may include a graphics processor (Graphics Processing Unit, GPU) 1041 and a microphone 1042, and the graphics processor 1041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 106 may include a display panel 1061, and the display panel 1061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 107 includes a touch panel 1071 and at least one of other input devices 1072. The touch panel 1071 is also called a touch screen. The touch panel 1071 may include two parts: a touch detection device and a touch controller. Other input devices 1072 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 109 can be used to store software programs and various data. The memory 109 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 109 may include a volatile memory or a non-volatile memory, or the memory 109 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 110 may include one or more processing units; optionally, the processor 110 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 110.

[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 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 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] The 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 various processes of the above method embodiment and can achieve the same technical effect.

[0223] To avoid repetition, the results will not be described here.

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

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

[0226] 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 specific implementations.

[0227] It is only illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

Claims

1. A memory allocation method, characterized in that: The method comprises: Determine the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process; When the amount of free memory in the first memory pool is greater than or equal to the amount of memory blocks applied for by the first process, performing a memory allocation operation on the first process according to the first memory pool; When the amount of free memory in the first memory pool is less than the amount of memory blocks applied for by the first process, performing a memory allocation operation on the first process according to the second memory pool; The migration types of the first memory pool and the second memory pool are different.

2. The method according to claim 1, characterized in that The scheduling priority of the first process is the first priority; Before performing the memory allocation operation on the first process according to the second memory pool, the method further includes: Determine the amount of free memory in the second memory pool; The performing a memory allocation operation on the first process according to the second memory pool includes: When the amount of free memory in the second memory pool is greater than or equal to the first amount, a memory allocation operation is performed on the first process according to the second memory pool.

3. The method according to claim 1, characterized in that The method further comprises: In the case where the system memory meets the memory filling condition, filling the free memory blocks for the third memory pool based on the second number, where the second number is the memory block accommodation threshold of the third memory pool; The system memory includes the first memory pool and the second memory pool, and the third memory pool is the first memory pool or the second memory pool.

4. The method according to claim 3, characterized in that The memory filling condition is one of the following: The amount of free memory of the system memory is greater than or equal to a third amount; The system memory meets a fill trigger condition.

5. The method according to claim 3, characterized in that: The type of the third memory pool is a first migration type; and the method further includes: The second quantity is determined based on test data; the test data represents the relationship between the free memory quantity of the third memory pool and the fourth quantity when at least two applications have applied for memory.

6. The method according to claim 3, characterized in that: The type of the third memory pool is a first migration type; and the method further includes: The second quantity is determined based on first usage information and second usage information; the first usage information represents the number of times when at least two applications are running, the amount of free memory in the third memory pool is less than the fifth quantity, and the second usage information represents the number of times when at least two applications are running, the amount of free memory in the third memory pool is greater than or equal to the fifth quantity.

7. The method according to claim 1, characterized in that The method further comprises: When the usage information of the system memory meets the memory release condition, free memory blocks of the fourth memory pool are released, and the free memory blocks after release are filled into the fifth memory pool, the type of the fourth memory pool is the first migration type, and the type of the fifth memory pool is the second migration type; The system memory includes the first memory pool and the second memory pool; the fourth memory pool is the first memory pool or the second memory pool; the fifth memory pool is the first memory pool or the second memory pool; and the fourth memory pool is different from the fifth memory pool.

8. A memory allocation device, characterized in that: The memory allocation device comprises: a determination module and an execution module; The determination module is used to determine the amount of free memory in the first memory pool corresponding to the scheduling priority of the first process; The execution module is configured to, when the amount of free memory in the first memory pool is greater than or equal to the amount of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to the first memory pool; or, when the amount of free memory in the first memory pool is less than the amount of memory blocks applied for by the first process, perform a memory allocation operation on the first process according to the second memory pool; The migration types of the first memory pool and the second memory pool are different.

9. The device according to claim 8, characterized in that The scheduling priority of the first process is the first priority; The determining module is further configured to determine the amount of free memory in the second memory pool before performing a memory allocation operation on the first process according to the second memory pool; The execution module is specifically configured to execute a memory allocation operation on the first process according to the second memory pool when the amount of free memory in the second memory pool is greater than or equal to the first amount.

10. The device according to claim 8, characterized in that The memory allocation device further comprises: a filling module; The filling module is configured to fill the free memory blocks for the third memory pool based on a second quantity when the system memory satisfies the memory filling condition, where the second quantity is a memory block accommodation threshold of the third memory pool; The system memory includes the first memory pool and the second memory pool, and the third memory pool is the first memory pool or the second memory pool.

11. The device according to claim 10, characterized in that The memory filling condition is one of the following: The amount of free memory of the system memory is greater than or equal to a third amount; The system memory meets a fill trigger condition.

12. The device according to claim 10, characterized in that The type of the third memory pool is the first migration type; the determination module is also used to determine the second quantity based on test data; the test data characterizes the relationship between the amount of free memory in the third memory pool and the fourth quantity when at least two applications complete the memory application.

13. The device according to claim 10, characterized in that The type of the third memory pool is the first migration type; the determination module is also used to determine the second quantity based on the first usage information and the second usage information; the first usage information represents the number of times when at least two applications are in a running state, the amount of free memory in the third memory pool is less than the fifth quantity, and the second usage information represents the number of times when at least two applications are in a running state, the amount of free memory in the third memory pool is greater than or equal to the fifth quantity.

14. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the memory allocation method as described in any one of claims 1 to 7 are implemented.

15. 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 allocation method according to any one of claims 1 to 7 are implemented.