CN114564315A - Memory allocation method and device, electronic equipment and medium - Google Patents

Memory allocation method and device, electronic equipment and medium Download PDF

Info

Publication number
CN114564315A
CN114564315A CN202210254377.4A CN202210254377A CN114564315A CN 114564315 A CN114564315 A CN 114564315A CN 202210254377 A CN202210254377 A CN 202210254377A CN 114564315 A CN114564315 A CN 114564315A
Authority
CN
China
Prior art keywords
memory
memory allocation
allocation
pool
application process
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210254377.4A
Other languages
Chinese (zh)
Inventor
张驰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Vivo Mobile Communication Co Ltd
Original Assignee
Vivo Mobile Communication Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Vivo Mobile Communication Co Ltd filed Critical Vivo Mobile Communication Co Ltd
Priority to CN202210254377.4A priority Critical patent/CN114564315A/en
Publication of CN114564315A publication Critical patent/CN114564315A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application discloses a memory allocation method, a memory allocation device, electronic equipment and a memory allocation medium, and belongs to the technical field of electronics. The specific scheme comprises the following steps: acquiring a memory allocation request; under the condition that continuous memories meeting the memory allocation requests are not allocated in a first allocation mode, allocating the memories in the reserved memory pool to meet the memory allocation requests; wherein the first formula comprises at least one of: a fast memory allocation path and a slow memory allocation path.

Description

内存分配方法、装置、电子设备及介质Memory allocation method, device, electronic device and medium

技术领域technical field

本申请属于电子技术领域,具体涉及一种内存分配方法、装置、电子设备及介质。The present application belongs to the field of electronic technology, and specifically relates to a memory allocation method, device, electronic device and medium.

背景技术Background technique

随着电子设备中应用程序的不断升级,应用程序的功能越来越丰富,当用户长时间使用电子设备后,启动的应用程序数量越来越多、系统的内存压力也越来越大。With the continuous upgrading of applications in electronic devices, the functions of the applications are becoming more and more abundant. When a user uses an electronic device for a long time, the number of applications that are started is increasing, and the memory pressure of the system is also increasing.

在相关技术中,当系统需要申请内存时,若剩余的连续内存不足以满足内存申请需求,就会触发系统执行内存规整(memory_compact),然而内存规整得以成功的前提是存在空闲内存,所以在内存压力大时,内存规整通常都是失败的。而一旦内存规整失败,就会触发系统的内存溢出(Out of Memory,OOM)机制,由于OOM机制能够结束运行除系统以外的绝大部分进程,因此会导致用户正在使用的前台应用被误杀,从而发生应用闪退的问题,影响用户的使用体验。In the related art, when the system needs to apply for memory, if the remaining contiguous memory is not enough to meet the memory application requirements, the system will be triggered to perform memory compaction (memory_compact). When stress is high, memory warping usually fails. Once the memory regularization fails, the system's Out of Memory (OOM) mechanism will be triggered. Since the OOM mechanism can end the operation of most processes other than the system, it will cause the foreground application being used by the user to be killed by mistake. The app crashes and crashes, affecting the user experience.

发明内容SUMMARY OF THE INVENTION

本申请实施例的目的是提供一种内存分配方法、装置、电子设备及介质,能够解决因内存不足导致应用闪退的问题。The purpose of the embodiments of the present application is to provide a memory allocation method, apparatus, electronic device, and medium, which can solve the problem of application flashback caused by insufficient memory.

第一方面,本申请实施例提供了一种内存分配方法,该方法包括:获取内存分配请求;在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。In a first aspect, an embodiment of the present application provides a memory allocation method, the method includes: acquiring a memory allocation request; and in the case that the first allocation method does not allocate contiguous memory that satisfies the memory allocation request, allocating a reserved memory The memory in the memory pool satisfies the memory allocation request; wherein, the first allocation manner includes at least one of the following: a fast memory allocation path and a slow memory allocation path.

第二方面,本申请实施例提供了一种内存分配装置,包括:获取模块和分配模块;所述获取模块,用于获取内存分配请求;所述分配模块,用于在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。In a second aspect, an embodiment of the present application provides a memory allocation device, including: an acquisition module and an allocation module; the acquisition module is used to acquire a memory allocation request; In the case of contiguous memory that satisfies the memory allocation request, allocate memory in the reserved memory pool to satisfy the memory allocation request; wherein, the first allocation method includes at least one of the following: a fast memory allocation path and a slow memory allocation path. Fast memory allocation path.

第三方面,本申请实施例提供了一种电子设备,该电子设备包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如第一方面所述的方法的步骤。In a third aspect, an embodiment of the present application provides an electronic device, the electronic device includes a processor and a memory, the memory stores a program or an instruction that can be executed on the processor, and the program or instruction is processed by the processor The steps of the method as described in the first aspect are implemented when the device is executed.

第四方面,本申请实施例提供了一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如第一方面所述的方法的步骤。In a fourth aspect, an embodiment of the present application provides a readable storage medium, where a program or an instruction is stored on the readable storage medium, and when the program or instruction is executed by a processor, the steps of the method according to the first aspect are implemented .

第五方面,本申请实施例提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如第一方面所述的方法。In a fifth aspect, an embodiment of the present application provides a chip, the chip includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is configured to run a program or an instruction, and implement the first aspect the method described.

第六方面,本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如第一方面所述的方法。In a sixth aspect, an embodiment of the present application provides a computer program product, where the program product is stored in a storage medium, and the program product is executed by at least one processor to implement the method according to the first aspect.

在本申请实施例中,可以获取内存分配请求;在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。通过该方案,由于在通过第一分配方式未分配到满足内存分配请求的连续内存的情况下,可以分配预留内存池中内存以满足所述内存分配请求,即可以使用预留内存池中的内存,因此可以缓解因申请不到内存导致前台应用进程被结束运行的问题,从而减少应用闪退情况的发生,进而提高系统在临界压力下稳定性。In this embodiment of the present application, a memory allocation request may be obtained; in the case that the first allocation method does not allocate continuous memory that satisfies the memory allocation request, allocate memory in the reserved memory pool to satisfy the memory allocation request; Wherein, the first allocation manner includes at least one of the following: a fast memory allocation path and a slow memory allocation path. With this solution, in the case where the contiguous memory that satisfies the memory allocation request is not allocated through the first allocation method, the memory in the reserved memory pool can be allocated to satisfy the memory allocation request, that is, the memory in the reserved memory pool can be used. Therefore, it can alleviate the problem that the foreground application process is terminated due to insufficient memory, thereby reducing the occurrence of application flashback and improving the stability of the system under critical pressure.

附图说明Description of drawings

图1是本申请实施例提供的内存分配方法的流程示意图之一;FIG. 1 is one of the schematic flowcharts of the memory allocation method provided by the embodiment of the present application;

图2是本申请实施例提供的内存分配方法的流程示意图之二;FIG. 2 is the second schematic flowchart of the memory allocation method provided by the embodiment of the present application;

图3是本申请实施例提供的内存分配方法的流程示意图之三;3 is a third schematic flowchart of a memory allocation method provided by an embodiment of the present application;

图4是本申请实施例提供的内存分配装置的结构示意图;4 is a schematic structural diagram of a memory allocation device provided by an embodiment of the present application;

图5是本申请实施例提供的电子设备的结构示意图;5 is a schematic structural diagram of an electronic device provided by an embodiment of the present application;

图6是本申请实施例提供的电子设备的硬件示意图。FIG. 6 is a schematic diagram of hardware of an electronic device provided by an embodiment of the present application.

具体实施方式Detailed ways

下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be clearly described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art fall within the protection scope of this application.

本申请的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。The terms "first", "second" and the like in the description and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It is to be understood that the data so used are interchangeable under appropriate circumstances so that the embodiments of the present application can be practiced in sequences other than those illustrated or described herein, and distinguish between "first", "second", etc. The objects are usually of one type, and the number of objects is not limited. For example, the first object may be one or more than one. In addition, "and/or" in the description and claims indicates at least one of the connected objects, and the character "/" generally indicates that the associated objects are in an "or" relationship.

下面结合附图,通过具体的实施例及其应用场景对本申请实施例提供的内存分配方法进行详细地说明。The memory allocation method provided by the embodiments of the present application will be described in detail below with reference to the accompanying drawings through specific embodiments and application scenarios thereof.

本申请实施例提供的内存分配方法,该内存分配方法的执行主体可以为电子设备或者电子设备中能够实现该内存分配方法的功能模块或功能实体,本申请实施例提及的电子设备包括但不限于手机、平板电脑、电脑、相机、可穿戴设备等,下面以电子设备作为执行主体为例对本申请实施例提供的内存分配方法进行说明。In the memory allocation method provided by the embodiment of the present application, the execution body of the memory allocation method may be an electronic device or a functional module or functional entity in the electronic device that can implement the memory allocation method. The electronic device mentioned in the embodiment of the present application includes but does not Limited to a mobile phone, a tablet computer, a computer, a camera, a wearable device, etc., the following describes the memory allocation method provided by the embodiment of the present application by taking an electronic device as an execution subject as an example.

如图1所示,本申请实施例提供了一种内存分配方法,该方法可以包括步骤101-步骤102:As shown in FIG. 1 , an embodiment of the present application provides a memory allocation method, and the method may include steps 101 to 102:

步骤101、电子设备获取内存分配请求。Step 101, the electronic device obtains a memory allocation request.

当电子设备想要正常运行一个应用程序时,就必须成功申请可以维持该应用程序运行的内存,具体地,如图2所示,电子设备可以获取该应用程序的内存分配请求,之后,电子设备可以先通过第一分配方式响应该内存分配请求,该第一分配方式可以包括以下至少一项:快速内存分配路径和慢速内存分配路径。也就是说,在系统的剩余连续内存足够满足该内存分配请求时,电子设备可以直接通过快速内存分配路径将剩余连续内存分配给该应用程序;在系统的剩余连续内存不足以满足该内存分配请求时,电子设备可以通过慢速内存分配路径分配内存,即触发系统的内存回收和内存规整操作,将回收到的、碎片化的内存块规整为连续内存,然后,将规整后的连续内存分配给该应用程序。When an electronic device wants to run an application program normally, it must successfully apply for the memory that can maintain the running of the application program. Specifically, as shown in Figure 2, the electronic device can obtain the memory allocation request of the application program. After that, the electronic device The memory allocation request may be responded to first through a first allocation manner, and the first allocation manner may include at least one of the following: a fast memory allocation path and a slow memory allocation path. That is to say, when the remaining contiguous memory of the system is sufficient to satisfy the memory allocation request, the electronic device can directly allocate the remaining contiguous memory to the application through the fast memory allocation path; when the remaining contiguous memory of the system is insufficient to satisfy the memory allocation request , the electronic device can allocate memory through the slow memory allocation path, that is, trigger the system's memory reclamation and memory reorganization operations, reorganize the recovered and fragmented memory blocks into contiguous memory, and then allocate the reorganized contiguous memory to the app.

可选地,上述内存分配请求的内存需求可以为非碎片化的连续内存需求,例如,至少可以为order3内存,即大于或等于32K的连续内存。Optionally, the memory requirement of the above memory allocation request may be a non-fragmented contiguous memory requirement, for example, at least order3 memory, that is, a contiguous memory greater than or equal to 32K.

步骤102、在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,电子设备分配预留内存池中内存以满足所述内存分配请求。Step 102: In the case that the contiguous memory that satisfies the memory allocation request is not allocated by the first allocation method, the electronic device allocates the memory in the reserved memory pool to satisfy the memory allocation request.

继续参考图2,若通过快速内存分配路径和慢速内存分配路径都未能分配到满足所述内存分配请求的连续内存,即规整后的连续内存仍不足以满足该内存分配请求的内存需求,则电子设备可以将预留内存池中的内存分配给该应用程序。Continuing to refer to FIG. 2, if both the fast memory allocation path and the slow memory allocation path fail to allocate contiguous memory that satisfies the memory allocation request, that is, the regularized contiguous memory is still insufficient to meet the memory requirement of the memory allocation request, Then the electronic device can allocate the memory in the reserved memory pool to the application.

在本申请实施例中,由于在通过第一分配方式未分配到满足内存分配请求的连续内存的情况下,可以分配预留内存池中内存以满足所述内存分配请求,即可以使用预留内存池中的内存,因此可以缓解因申请不到内存导致前台应用进程被结束运行的问题,从而减少应用闪退情况的发生,进而提高系统在临界压力下稳定性。In the embodiment of the present application, since the first allocation method does not allocate contiguous memory that satisfies the memory allocation request, the memory in the reserved memory pool can be allocated to satisfy the memory allocation request, that is, the reserved memory can be used Therefore, it can alleviate the problem that the foreground application process is terminated due to insufficient memory, thereby reducing the occurrence of application flashback and improving the stability of the system under critical pressure.

可选地,为了满足电子设备中应用程序的运行需求,上述预留内存池的内存大小可以通过以下两种方式确定:Optionally, in order to meet the running requirements of the application in the electronic device, the memory size of the above-mentioned reserved memory pool can be determined in the following two ways:

方式1,在电子设备的系统处于启动状态的情况下,电子设备可以获取预留内存池的第一配置文件;并通过读取该第一配置文件确定预留内存池的初始内存;然后,基于该初始内存对预留内存池进行初始化处理,该第一配置文件为服务器向电子设备下发的配置文件。也就是说,服务器可以通过下发第一配置文件的方式修改预留内存池的内存大小,当电子设备重新启动时,新下发的第一配置文件即可生效。Mode 1, when the system of the electronic device is in the startup state, the electronic device can obtain the first configuration file of the reserved memory pool; and determine the initial memory of the reserved memory pool by reading the first configuration file; then, based on The initial memory initializes the reserved memory pool, and the first configuration file is a configuration file issued by the server to the electronic device. That is, the server can modify the memory size of the reserved memory pool by issuing the first configuration file, and when the electronic device is restarted, the newly issued first configuration file can take effect.

基于上述方案,由于可以根据第一配置文件确定预留内存池的初始内存,因此,后台开发人员可以通过服务器对预留内存池的初始内存的大小进行灵活控制,从而使预留内存池可以满足不同场景的内存需求。Based on the above solution, since the initial memory of the reserved memory pool can be determined according to the first configuration file, the background developer can flexibly control the size of the initial memory of the reserved memory pool through the server, so that the reserved memory pool can meet the Memory requirements for different scenarios.

方式2,由于每个用户的电子设备中安装的应用程序不同,应用场景也不同,因此,为了满足用户的个性化内存需求,不同电子设备中预留内存池的内存大小可以动态调整。具体地,在电子设备的系统处于运行状态的情况下,当电子设备根据内存分配请求的内存需求向预留内存池申请内存之后,在预留内存池不满足该内存需求的情况下,电子设备可以调整第一配置文件对应的初始内存,得到第二配置文件;然后,将第一配置文件更新为第二配置文件;其中,所述第二配置文件对应的初始内存小于或等于第四阈值,所述第四阈值与系统物理内存具有关联关系。也就是说,第四阈值的大小可以根据系统物理内存确定,系统物理内存越大,第四阈值越大,系统物理内存越小,第四阈值越小。Mode 2, since each user's electronic device has different application programs and different application scenarios, in order to meet the user's personalized memory requirements, the memory size of the reserved memory pools in different electronic devices can be dynamically adjusted. Specifically, when the system of the electronic device is in the running state, after the electronic device applies for memory from the reserved memory pool according to the memory requirement of the memory allocation request, if the reserved memory pool does not meet the memory requirement, the electronic device The initial memory corresponding to the first configuration file can be adjusted to obtain the second configuration file; then, the first configuration file is updated to the second configuration file; wherein, the initial memory corresponding to the second configuration file is less than or equal to the fourth threshold, The fourth threshold is associated with the system physical memory. That is, the size of the fourth threshold can be determined according to the system physical memory, the larger the system physical memory, the larger the fourth threshold, and the smaller the system physical memory, and the smaller the fourth threshold.

需要说明的是,上述第二配置文件可以在电子设备重新启动后生效。It should be noted that the above-mentioned second configuration file may take effect after the electronic device is restarted.

可选地,在预留内存池不满足该内存需求的情况下,电子设备可以按照预设倍数调整第一配置文件对应的初始内存,得到第二配置文件。Optionally, when the reserved memory pool does not meet the memory requirement, the electronic device may adjust the initial memory corresponding to the first configuration file according to a preset multiple to obtain the second configuration file.

示例性地,如图3所示,以预设倍数为2为例。电子设备在第一次启动时,可以先完成系统的初始化,然后读取电子设备中的配置文件,此时,该配置文件为服务器下发的第一配置文件,从而确定预留内存池当前的初始内存为X,当电子设备运行一段时间后,若预留内存池中的剩余内存无法满足当前的内存需求,则电子设备可以自适应生成第二配置文件,该第二配置文件用于指示预留内存池的初始内存为2X。之后,电子设备可以将配置文件更新为第二配置文件,然后当电子设备第二次启动时,可以直接读取该第二配置文件,从而确定预留内存池当前的初始内存为2X。Exemplarily, as shown in FIG. 3 , the preset multiple is 2 as an example. When the electronic device is started for the first time, the initialization of the system can be completed first, and then the configuration file in the electronic device can be read. At this time, the configuration file is the first configuration file issued by the server, so as to determine the current value of the reserved memory pool. The initial memory is X. After the electronic device runs for a period of time, if the remaining memory in the reserved memory pool cannot meet the current memory requirements, the electronic device can adaptively generate a second configuration file, which is used to indicate the preset memory. The initial memory of the reserved memory pool is 2X. After that, the electronic device can update the configuration file to the second configuration file, and then when the electronic device is started for the second time, it can directly read the second configuration file, thereby determining that the current initial memory of the reserved memory pool is 2X.

需要说明的是,电子设备需要根据系统物理内存调整预留内存池的初始内存,调整后的预留内存池的初始内存必须小于第四阈值,该第四阈值与系统物理内存正相关。例如,以电子设备的最小内存单位为4G为例,第四阈值

Figure BDA0003547960100000061
其中,memtotal为电子设备的物理内存,单位为G,第四阈值poollimit的单位为M,计算结果可以向下取整。It should be noted that the electronic device needs to adjust the initial memory of the reserved memory pool according to the system physical memory, and the adjusted initial memory of the reserved memory pool must be less than a fourth threshold, which is positively related to the system physical memory. For example, taking the minimum memory unit of an electronic device as 4G, the fourth threshold
Figure BDA0003547960100000061
Among them, memtotal is the physical memory of the electronic device, the unit is G, and the unit of the fourth threshold pool limit is M, and the calculation result can be rounded down.

基于上述方案,由于在预留内存池中的剩余内存不满足内存需求的情况下,电子设备可以按照调整第一配置文件对应的初始内存,得到第二配置文件,因此,预留内存池的初始内存可以根据用户的使用场景需求进行灵活的调整,如此,不仅可以避免内存浪费,还可以提高内存管理的优化效果。Based on the above solution, since the remaining memory in the reserved memory pool does not meet the memory requirement, the electronic device can obtain the second configuration file by adjusting the initial memory corresponding to the first configuration file. Therefore, the initial The memory can be flexibly adjusted according to the needs of the user's usage scenarios. In this way, it can not only avoid memory waste, but also improve the optimization effect of memory management.

可选地,电子设备分配预留内存池中内存以满足所述内存分配请求,具体可以包括:电子设备根据该述内存分配请求的内存需求向预留内存池申请内存;在所述预留内存池中的剩余内存可以满足该内存需求的情况下,电子设备可以分配预留内存池中内存以满足所述内存分配请求。也就是说,当预留内存池中的剩余内存大于或等于内存分配请求对应的内存需求时,电子设备就可以通过预留内存池成功分配内存。Optionally, the electronic device allocates memory in the reserved memory pool to meet the memory allocation request, which may specifically include: the electronic device applies for memory from the reserved memory pool according to the memory requirement of the memory allocation request; When the remaining memory in the pool can meet the memory requirement, the electronic device can allocate the memory in the reserved memory pool to meet the memory allocation request. That is, when the remaining memory in the reserved memory pool is greater than or equal to the memory requirement corresponding to the memory allocation request, the electronic device can successfully allocate memory through the reserved memory pool.

基于上述方案,由于电子设备可以在预留内存池中的剩余内存可以满足内存需求的情况下,分配预留内存池中内存以满足所述内存分配请求,因此可以通过预留内存池中的内存缓解系统的内存压力,从而减少应用闪退情况的发生。Based on the above solution, since the electronic device can allocate the memory in the reserved memory pool to meet the memory allocation request under the condition that the remaining memory in the reserved memory pool can meet the memory requirement, the memory in the reserved memory pool can be allocated by the electronic device. Relieve the memory pressure of the system, thereby reducing the occurrence of application flashbacks.

可选地,在分配预留内存池中内存以满足所述内存分配请求之后,电子设备还可以监测所述预留内存池的内存消耗速度;并在所述内存消耗速度大于第一阈值的情况下,确定目标应用进程,并结束运行所述目标应用进程,所述目标应用进程为用户感知度小于第二阈值的应用进程,所述用户感知度为结束运行应用进程后被用户感知的概率;最后,对结束运行所述目标应用进程释放的内存进行规整处理,得到连续内存。Optionally, after allocating memory in the reserved memory pool to satisfy the memory allocation request, the electronic device may also monitor the memory consumption speed of the reserved memory pool; and when the memory consumption speed is greater than the first threshold Next, determine a target application process, and end running the target application process, where the target application process is an application process with a user perception degree less than a second threshold, and the user perception degree is the probability of being perceived by the user after finishing running the application process; Finally, regular processing is performed on the memory released by the end of running the target application process to obtain continuous memory.

当预留内存池的内存消耗速度大于第一阈值时,表示预留内存池的内存消耗速度较快,如果预留内存池的剩余内存越来越紧张,新的内存得不到释放,剩余内存又不足以满足下次内存需求,那么仍然可能触发OOM机制,因此,为了避免这种情况的发生,电子设备可以在监测到预留内存池的内存消耗速度大于第一阈值时,筛选出用户感知度小于第二阈值的目标应用进程,并结束运行目标应用进程,从而释放目标应用进程占用的内存。When the memory consumption rate of the reserved memory pool is greater than the first threshold, it means that the memory consumption rate of the reserved memory pool is relatively fast. If it is not enough to meet the next memory demand, the OOM mechanism may still be triggered. Therefore, in order to avoid this situation, the electronic device can filter out the user perception when monitoring that the memory consumption rate of the reserved memory pool is greater than the first threshold. The target application process whose degree is less than the second threshold is terminated, and the running of the target application process is terminated, thereby releasing the memory occupied by the target application process.

可选地,应用进程的用户感知度可以根据以下至少一项确定:是否在后台运行、距离前台运行的时间、用户使用该应用进程的频率和时间等。Optionally, the user perception of the application process may be determined according to at least one of the following: whether it is running in the background, the time from running in the foreground, the frequency and time at which the user uses the application process, and the like.

基于上述方案,在预留内存池的内存消耗速度大于第一阈值时,可以通过结束运行目标应用进程来释放内存,并通过规整处理得到连续内存,由于目标应用进程的用户感知度小于第二阈值,因此,可以在兼顾用户使用体验的前提下,扩大连续内存,从而提高下次内存申请的内存分配速度。Based on the above solution, when the memory consumption rate of the reserved memory pool is greater than the first threshold, the memory can be released by ending the running of the target application process, and continuous memory can be obtained through regular processing. Since the user perception of the target application process is less than the second threshold , therefore, the continuous memory can be expanded under the premise of taking into account the user experience, thereby improving the memory allocation speed of the next memory application.

可选地,电子设备可以根据多个内存分配请求的平均时间间隔确定预留内存池的内存消耗速度。例如,电子设备可以获取10次内存分配请求的总耗时,然后计算该10次内存分配请求的平均时间间隔,最后,将得到的平均时间间隔与第一阈值进行比较,从而掌握预留内存池的内存消耗速度,进而减轻电子设备的监测压力。Optionally, the electronic device may determine the memory consumption speed of the reserved memory pool according to the average time interval of multiple memory allocation requests. For example, the electronic device can obtain the total time-consuming of 10 memory allocation requests, then calculate the average time interval of the 10 memory allocation requests, and finally, compare the obtained average time interval with the first threshold, so as to grasp the reserved memory pool The speed of memory consumption is reduced, thereby reducing the monitoring pressure of electronic devices.

可选地,在结束运行目标应用进程之前,电子设备可以先确定系统内存的碎片化程度;若所述碎片化程度大于第三阈值,则结束运行目标应用进程。Optionally, before ending the running of the target application process, the electronic device may first determine the degree of fragmentation of the system memory; if the degree of fragmentation is greater than the third threshold, the electronic device ends the running of the target application process.

具体地,电子设备可以监测预留内存池的内存消耗速度,并在内存消耗速度大于第一阈值时向上层lmkd线程上报异常,当lmkd线程接收到底层发送的异常上报后,可以先计算当前系统的内存状态,如果碎片化程度大于第三阈值,则通过进程排分机制确定用户感知度小于第二阈值的目标应用进程,结束运行目标应用进程之后,lmkd线程可以向内核中的kcompact线程发送杀进程成功信号,从而触发kcompact线程对结束运行目标应用进程释放的内存进行规整处理。Specifically, the electronic device can monitor the memory consumption rate of the reserved memory pool, and report an exception to the upper-layer lmkd thread when the memory consumption rate is greater than the first threshold. When the lmkd thread receives the exception report sent by the lower layer, it can first calculate the current system If the fragmentation degree is greater than the third threshold, the target application process whose user perception is less than the second threshold is determined by the process ranking mechanism. After the target application process ends, the lmkd thread can send a kill to the kcompact thread in the kernel. The process success signal, which triggers the kcompact thread to perform regular processing on the memory released by the end running the target application process.

基于上述方案,由于可以在结束运行目标应用进程之前,先进行内存碎片化程度的判断,因此,可以提高后续内存规整处理的成功率。Based on the above solution, since the degree of memory fragmentation can be judged before ending the running of the target application process, the success rate of subsequent memory regularization processing can be improved.

本申请实施例提供的内存分配方法,执行主体可以为内存分配装置。本申请实施例中以内存分配装置执行内存分配方法为例,说明本申请实施例提供的内存分配装置。In the memory allocation method provided by the embodiment of the present application, the execution body may be a memory allocation device. In the embodiments of the present application, the memory allocation method provided by the embodiments of the present application is described by taking the memory allocation method performed by the memory allocation device as an example.

如图4所示,本申请实施例还提供一种内存分配装置400,包括:获取模块401和分配模402。所述获取模块401,可以用于获取内存分配请求;所述分配模块402,可以用于在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。As shown in FIG. 4 , an embodiment of the present application further provides a memory allocation device 400 , including: an acquisition module 401 and an allocation module 402 . The acquisition module 401 can be used to acquire a memory allocation request; the allocation module 402 can be used to allocate a reserved memory pool under the condition that the contiguous memory that satisfies the memory allocation request is not allocated through the first allocation method medium memory to satisfy the memory allocation request; wherein, the first allocation manner includes at least one of the following: a fast memory allocation path and a slow memory allocation path.

可选地,继续参考图4,上述装置400还可以包括处理模块403。所述处理模块403,可以用于在所述内存消耗速度大于第一阈值的情况下,确定目标应用进程,并结束运行所述目标应用进程,所述目标应用进程为用户感知度小于第二阈值的应用进程,所述用户感知度为结束运行应用进程后被用户感知的概率;对结束运行所述目标应用进程释放的内存进行规整处理,得到连续内存。Optionally, continuing to refer to FIG. 4 , the above-mentioned apparatus 400 may further include a processing module 403 . The processing module 403 can be configured to determine a target application process when the memory consumption speed is greater than the first threshold, and end running the target application process, where the user perception is less than the second threshold. The user perception degree is the probability of being perceived by the user after ending the running of the application process; regular processing is performed on the memory released by the ending running of the target application process to obtain continuous memory.

可选地,所述处理模块403,还可以用于确定系统内存的碎片化程度;所述处理模块403,具体可以用于在所述碎片化程度大于第三阈值的情况下,结束运行所述目标应用进程。Optionally, the processing module 403 can also be used to determine the degree of fragmentation of the system memory; the processing module 403 can be specifically configured to end running the system when the degree of fragmentation is greater than a third threshold target application process.

可选地,所述获取模块401,还可以用于在系统处于启动状态的情况下,获取所述预留内存池的第一配置文件;所述处理模块403,可以用于根据所述第一配置文件确定所述预留内存池的初始内存;基于所述初始内存对所述预留内存池进行初始化处理;其中,所述第一配置文件为服务器下发的配置文件。Optionally, the obtaining module 401 may also be configured to obtain the first configuration file of the reserved memory pool when the system is in a startup state; the processing module 403 may be configured to obtain the first configuration file of the reserved memory pool according to the first configuration file. The configuration file determines the initial memory of the reserved memory pool; initializes the reserved memory pool based on the initial memory; wherein, the first configuration file is a configuration file issued by the server.

可选地,所述分配模块402,具体可以用于根据所述内存分配请求的内存需求向所述预留内存池申请内存;在所述预留内存池中的剩余内存满足所述内存需求的情况下,分配预留内存池中内存以满足所述内存分配请求。Optionally, the allocation module 402 can be specifically configured to apply for memory from the reserved memory pool according to the memory requirement of the memory allocation request; the remaining memory in the reserved memory pool meets the memory requirement. In this case, allocate the memory in the reserved memory pool to satisfy the memory allocation request.

可选地,所述处理模块403,还可以用于在所述预留内存池中的剩余内存不满足所述内存需求的情况下,调整所述第一配置文件对应的初始内存,得到第二配置文件;将所述第一配置文件更新为所述第二配置文件;其中,所述第二配置文件对应的初始内存小于或等于第四阈值,所述第四阈值与系统物理内存具有关联关系。Optionally, the processing module 403 can be further configured to adjust the initial memory corresponding to the first configuration file to obtain the second memory in the case that the remaining memory in the reserved memory pool does not meet the memory requirement. configuration file; update the first configuration file to the second configuration file; wherein, the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold is associated with the system physical memory .

在本申请实施例中,由于在通过第一分配方式未分配到满足内存分配请求的连续内存的情况下,可以分配预留内存池中内存以满足所述内存分配请求,即可以使用预留内存池中的内存,因此可以缓解因申请不到内存导致前台应用进程被结束运行的问题,从而减少应用闪退情况的发生,进而提高系统在临界压力下稳定性。In the embodiment of the present application, since the first allocation method does not allocate contiguous memory that satisfies the memory allocation request, the memory in the reserved memory pool can be allocated to satisfy the memory allocation request, that is, the reserved memory can be used Therefore, it can alleviate the problem that the foreground application process is terminated due to insufficient memory, thereby reducing the occurrence of application flashback and improving the stability of the system under critical pressure.

本申请实施例中的内存分配装置可以是电子设备,也可以是电子设备中的部件,例如集成电路或芯片。该电子设备可以是终端,也可以为除终端之外的其他设备。示例性的,电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备、移动上网装置(Mobile Internet Device,MID)、增强现实(augmented reality,AR)/虚拟现实(virtualreality,VR)设备、机器人、可穿戴设备、超级移动个人计算机(ultra-mobile personalcomputer,UMPC)、上网本或者个人数字助理(personal digital assistant,PDA)等,还可以为服务器、网络附属存储器(Network Attached Storage,NAS)、个人计算机(personalcomputer,PC)、电视机(television,TV)、柜员机或者自助机等,本申请实施例不作具体限定。The memory allocation apparatus in this embodiment of the present application may be an electronic device, or may be a component in the electronic device, such as an integrated circuit or a chip. The electronic device may be a terminal, or may be other devices other than the terminal. Exemplarily, the electronic device may be a mobile phone, a tablet computer, a notebook computer, a palmtop computer, a vehicle-mounted electronic device, a Mobile Internet Device (MID), an augmented reality (AR)/virtual reality (VR) Devices, robots, wearable devices, ultra-mobile personal computers (UMPCs), netbooks or personal digital assistants (PDAs), etc., and can also be servers, network attached storages (NAS) , a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which are not specifically limited in the embodiments of the present application.

本申请实施例中的内存分配装置可以为具有操作系统的装置。该操作系统可以为安卓(Android)操作系统,可以为iOS操作系统,还可以为其他可能的操作系统,本申请实施例不作具体限定。The memory allocation device in this embodiment of the present application may be a device with an operating system. The operating system may be an Android (Android) operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiments of the present application.

本申请实施例提供的内存分配装置能够实现图1至图3的方法实施例实现的各个过程,为避免重复,这里不再赘述。The memory allocation device provided in the embodiment of the present application can implement each process implemented by the method embodiments in FIG. 1 to FIG. 3 , and to avoid repetition, details are not described here.

可选地,如图5所示,本申请实施例还提供一种电子设备500,包括处理器501和存储器502,存储器502上存储有可在所述处理器501上运行的程序或指令,该程序或指令被处理器501执行时实现上述内存分配方法实施例的各个步骤,且能达到相同的技术效果,为避免重复,这里不再赘述。Optionally, as shown in FIG. 5 , an embodiment of the present application further provides an electronic device 500 , including a processor 501 and a memory 502 . The memory 502 stores programs or instructions that can run on the processor 501 . When the program or the instruction is executed by the processor 501, each step of the above-mentioned embodiment of the memory allocation method is implemented, and the same technical effect can be achieved. In order to avoid repetition, details are not repeated here.

需要说明的是,本申请实施例中的电子设备包括上述所述的移动电子设备和非移动电子设备。It should be noted that the electronic devices in the embodiments of the present application include the aforementioned mobile electronic devices and non-mobile electronic devices.

图6为实现本申请实施例的一种电子设备的硬件结构示意图。FIG. 6 is a schematic diagram of a hardware structure of an electronic device implementing an embodiment of the present application.

该电子设备1000包括但不限于:射频单元1001、网络模块1002、音频输出单元1003、输入单元1004、传感器1005、显示单元1006、用户输入单元1007、接口单元1008、存储器1009、以及处理器1010等部件。The electronic device 1000 includes but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009, and a processor 1010, etc. part.

本领域技术人员可以理解,电子设备1000还可以包括给各个部件供电的电源(比如电池),电源可以通过电源管理系统与处理器1010逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。图6中示出的电子设备结构并不构成对电子设备的限定,电子设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置,在此不再赘述。Those skilled in the art can understand that the electronic device 1000 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 1010 through a power management system, so that the power management system can manage charging, discharging, and power functions. consumption management and other functions. The structure of the electronic device shown in FIG. 6 does not constitute a limitation on the electronic device, and the electronic device may include more or less components than those shown in the figure, or combine some components, or arrange different components, which will not be repeated here. .

其中,接口单元1008,可以用于获取内存分配请求;处理器1010,可以用于在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。Wherein, the interface unit 1008 can be used to obtain a memory allocation request; the processor 1010 can be used to allocate the memory in the reserved memory pool under the condition that the contiguous memory that satisfies the memory allocation request is not allocated through the first allocation method to satisfy the memory allocation request; wherein, the first allocation manner includes at least one of the following: a fast memory allocation path and a slow memory allocation path.

在本申请实施例中,由于在通过第一分配方式未分配到满足内存分配请求的连续内存的情况下,可以分配预留内存池中内存以满足所述内存分配请求,即可以使用预留内存池中的内存,因此可以缓解因申请不到内存导致前台应用进程被结束运行的问题,从而减少应用闪退情况的发生,进而提高系统在临界压力下稳定性。In the embodiment of the present application, since the first allocation method does not allocate contiguous memory that satisfies the memory allocation request, the memory in the reserved memory pool can be allocated to satisfy the memory allocation request, that is, the reserved memory can be used Therefore, it can alleviate the problem that the foreground application process is terminated due to insufficient memory, thereby reducing the occurrence of application flashback and improving the stability of the system under critical pressure.

可选地,处理器1010,可以用于在所述内存消耗速度大于第一阈值的情况下,确定目标应用进程,并结束运行所述目标应用进程,所述目标应用进程为用户感知度小于第二阈值的应用进程,所述用户感知度为结束运行应用进程后被用户感知的概率;对结束运行所述目标应用进程释放的内存进行规整处理,得到连续内存。Optionally, the processor 1010 can be configured to determine a target application process when the memory consumption speed is greater than the first threshold, and end running the target application process, where the user perception degree is less than the first threshold. For an application process with two thresholds, the user perception degree is the probability of being perceived by the user after finishing running the application process; regular processing is performed on the memory released by the ending running of the target application process to obtain continuous memory.

在本申请实施例中,在预留内存池的内存消耗速度大于第一阈值时,可以通过结束运行目标应用进程来释放内存,并通过规整处理得到连续内存,由于目标应用进程的用户感知度小于第二阈值,因此,可以在兼顾用户使用体验的前提下,扩大连续内存,从而提高下次内存申请的内存分配速度。In the embodiment of the present application, when the memory consumption speed of the reserved memory pool is greater than the first threshold, the memory can be released by ending the running of the target application process, and the continuous memory can be obtained by regular processing. Since the user perception of the target application process is less than The second threshold, therefore, can expand the continuous memory under the premise of taking into account the user experience, thereby improving the memory allocation speed of the next memory application.

可选地,处理器1010,还可以用于确定系统内存的碎片化程度;处理器1010,具体可以用于在所述碎片化程度大于第三阈值的情况下,结束运行所述目标应用进程。Optionally, the processor 1010 may be further configured to determine the fragmentation degree of the system memory; the processor 1010 may be specifically configured to end running the target application process when the fragmentation degree is greater than a third threshold.

在本申请实施例中,由于可以在结束运行目标应用进程之前,先进行内存碎片化程度的判断,因此,可以提高后续内存规整处理的成功率。In the embodiment of the present application, since the degree of memory fragmentation can be judged before ending the running of the target application process, the success rate of subsequent memory regularization processing can be improved.

可选地,接口单元1008,还可以用于在系统处于启动状态的情况下,获取所述预留内存池的第一配置文件;处理器1010,可以用于根据所述第一配置文件确定所述预留内存池的初始内存;基于所述初始内存对所述预留内存池进行初始化处理;其中,所述第一配置文件为服务器下发的配置文件。Optionally, the interface unit 1008 may be further configured to acquire the first configuration file of the reserved memory pool when the system is in the startup state; the processor 1010 may be configured to determine the first configuration file according to the first configuration file. initial memory of the reserved memory pool; initializing the reserved memory pool based on the initial memory; wherein the first configuration file is a configuration file delivered by the server.

在本申请实施例中,由于可以根据第一配置文件确定预留内存池的初始内存,因此,后台开发人员可以通过服务器对预留内存池的初始内存的大小进行灵活控制,从而使预留内存池可以满足不同场景的内存需求。In this embodiment of the present application, since the initial memory of the reserved memory pool can be determined according to the first configuration file, the background developer can flexibly control the size of the initial memory of the reserved memory pool through the server, so that the reserved memory Pools can meet the memory requirements of different scenarios.

可选地,处理器1010,具体可以用于根据所述内存分配请求的内存需求向所述预留内存池申请内存;在所述预留内存池中的剩余内存满足所述内存需求的情况下,通过所述预留内存池中内存响应所述内存分配请求。Optionally, the processor 1010 may be specifically configured to apply for memory from the reserved memory pool according to the memory requirement of the memory allocation request; if the remaining memory in the reserved memory pool meets the memory requirement , responding to the memory allocation request through the memory in the reserved memory pool.

在本申请实施例中,由于电子设备可以在预留内存池中的剩余内存可以满足内存需求的情况下,分配预留内存池中内存以满足所述内存分配请求,因此可以通过预留内存池中的内存缓解系统的内存压力,从而减少应用闪退情况的发生。In the embodiment of the present application, since the electronic device can allocate memory in the reserved memory pool to meet the memory allocation request under the condition that the remaining memory in the reserved memory pool can meet the memory requirement, the reserved memory pool can The memory in the system relieves the memory pressure of the system, thereby reducing the occurrence of application flashbacks.

可选地,处理器1010,还可以用于在所述预留内存池中的剩余内存不满足所述内存需求的情况下,调整所述第一配置文件对应的初始内存,得到第二配置文件;将所述第一配置文件更新为所述第二配置文件;其中,所述第二配置文件对应的初始内存小于或等于第四阈值,所述第四阈值与系统物理内存具有关联关系。Optionally, the processor 1010 may also be configured to adjust the initial memory corresponding to the first configuration file to obtain a second configuration file when the remaining memory in the reserved memory pool does not meet the memory requirement. ; Update the first configuration file to the second configuration file; wherein, the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold is associated with the system physical memory.

在本申请实施例中,由于在预留内存池中的剩余内存不满足内存需求的情况下,电子设备可以调整第一配置文件对应的初始内存,得到第二配置文件,因此,预留内存池的初始内存可以根据用户的使用场景需求进行灵活的调整,如此,不仅可以避免内存浪费,还可以提高内存管理的优化效果。In the embodiment of the present application, since the remaining memory in the reserved memory pool does not meet the memory requirements, the electronic device can adjust the initial memory corresponding to the first configuration file to obtain the second configuration file. Therefore, the reserved memory pool The initial memory can be flexibly adjusted according to the user's usage scenario requirements, so that not only can avoid memory waste, but also improve the optimization effect of memory management.

应理解的是,本申请实施例中,输入单元1004可以包括图形处理器(GraphicsProcessing Unit,GPU)10041和麦克风10042,图形处理器10041对在视频捕获模式或图像捕获模式中由图像捕获装置(如摄像头)获得的静态图片或视频的图像数据进行处理。显示单元1006可包括显示面板10061,可以采用液晶显示器、有机发光二极管等形式来配置显示面板10061。用户输入单元1007包括触控面板10071以及其他输入设备10072中的至少一种。触控面板10071,也称为触摸屏。触控面板10071可包括触摸检测装置和触摸控制器两个部分。其他输入设备10072可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆,在此不再赘述。It should be understood that, in this embodiment of the present application, the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042. camera) to process the image data of still pictures or videos. The display unit 1006 may include a display panel 10061, which may be configured in the form of a liquid crystal display, an organic light emitting diode, or the like. The user input unit 1007 includes at least one of a touch panel 10071 and other input devices 10072 . The touch panel 10071 is also called a touch screen. The touch panel 10071 may include two parts, a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, physical keyboards, function keys (such as volume control keys, switch keys, etc.), trackballs, mice, and joysticks, which will not be repeated here.

存储器1009可用于存储软件程序以及各种数据。存储器1009可主要包括存储程序或指令的第一存储区和存储数据的第二存储区,其中,第一存储区可存储操作系统、至少一个功能所需的应用程序或指令(比如声音播放功能、图像播放功能等)等。此外,存储器1009可以包括易失性存储器或非易失性存储器,或者,存储器1009可以包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(Read-Only Memory,ROM)、可编程只读存储器(Programmable ROM,PROM)、可擦除可编程只读存储器(Erasable PROM,EPROM)、电可擦除可编程只读存储器(Electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(Random Access Memory,RAM),静态随机存取存储器(Static RAM,SRAM)、动态随机存取存储器(Dynamic RAM,DRAM)、同步动态随机存取存储器(Synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(Double Data Rate SDRAM,DDRSDRAM)、增强型同步动态随机存取存储器(Enhanced SDRAM,ESDRAM)、同步连接动态随机存取存储器(Synch link DRAM,SLDRAM)和直接内存总线随机存取存储器(Direct Rambus RAM,DRRAM)。本申请实施例中的存储器1009包括但不限于这些和任意其它适合类型的存储器。The memory 1009 may be used to store software programs as well as various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, image playback function, etc.), etc. Further, memory 1009 may include volatile memory or non-volatile memory, or memory 1009 may include both volatile and non-volatile memory. Wherein, the non-volatile memory may be Read-Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (Erasable PROM, EPROM), Erase programmable read-only memory (Electrically EPROM, EEPROM) or flash memory. Volatile memory can be random access memory (Random Access Memory, RAM), static random access memory (Static RAM, SRAM), dynamic random access memory (Dynamic RAM, DRAM), synchronous dynamic random access memory (Synchronous random access memory) DRAM, SDRAM), double data rate synchronous dynamic random access memory (Double Data Rate SDRAM, DDRSDRAM), enhanced synchronous dynamic random access memory (Enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (Synch link DRAM) , SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DRRAM). The memory 1009 in this embodiment of the present application includes, but is not limited to, these and any other suitable types of memory.

处理器1010可包括一个或多个处理单元;可选的,处理器1010集成应用处理器和调制解调处理器,其中,应用处理器主要处理涉及操作系统、用户界面和应用程序等的操作,调制解调处理器主要处理无线通信信号,如基带处理器。可以理解的是,上述调制解调处理器也可以不集成到处理器1010中。The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly processes operations involving an operating system, a user interface, and an application program, etc. Modem processors mainly deal with wireless communication signals, such as baseband processors. It can be understood that, the above-mentioned modulation and demodulation processor may not be integrated into the processor 1010.

本申请实施例还提供一种可读存储介质,所述可读存储介质上存储有程序或指令,该程序或指令被处理器执行时实现上述内存分配方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。Embodiments of the present application further provide a readable storage medium, where a program or an instruction is stored on the readable storage medium. When the program or instruction is executed by a processor, each process of the foregoing memory allocation method embodiment can be achieved, and the same can be achieved. In order to avoid repetition, the technical effect will not be repeated here.

其中,所述处理器为上述实施例中所述的电子设备中的处理器。所述可读存储介质,包括计算机可读存储介质,如计算机只读存储器ROM、随机存取存储器RAM、磁碟或者光盘等。Wherein, the processor is the processor in the electronic device described in the foregoing embodiments. The readable storage medium includes a computer-readable storage medium, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disk, and the like.

本申请实施例另提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现上述内存分配方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。An embodiment of the present application further provides a chip, where the chip includes a processor and a communication interface, the communication interface is coupled to the processor, and the processor is used to run a program or an instruction to implement the memory allocation method embodiments described above. Each process can achieve the same technical effect. In order to avoid repetition, it will not be repeated here.

应理解,本申请实施例提到的芯片还可以称为系统级芯片、系统芯片、芯片系统或片上系统芯片等。It should be understood that the chip mentioned in the embodiments of the present application may also be referred to as a system-on-chip, a system-on-chip, a system-on-a-chip, or a system-on-a-chip, or the like.

本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如上述内存分配方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。The embodiments of the present application provide a computer program product, the program product is stored in a storage medium, and the program product is executed by at least one processor to implement the various processes in the foregoing memory allocation method embodiments, and can achieve the same technical effect , in order to avoid repetition, it will not be repeated here.

需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。此外,需要指出的是,本申请实施方式中的方法和装置的范围不限按示出或讨论的顺序来执行功能,还可包括根据所涉及的功能按基本同时的方式或按相反的顺序来执行功能,例如,可以按不同于所描述的次序来执行所描述的方法,并且还可以添加、省去、或组合各种步骤。另外,参照某些示例所描述的特征可在其他示例中被组合。It should be noted that, herein, the terms "comprising", "comprising" or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements, It also includes other elements not expressly listed or inherent to such a process, method, article or apparatus. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in a process, method, article or apparatus that includes the element. Furthermore, it should be noted that the scope of the methods and apparatus in the embodiments of the present application is not limited to performing the functions in the order shown or discussed, but may also include performing the functions in a substantially simultaneous manner or in the reverse order depending on the functions involved. To perform functions, for example, the described methods may be performed in an order different from that described, and various steps may also be added, omitted, or combined. Additionally, features described with reference to some examples may be combined in other examples.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对相关技术做出贡献的部分可以以计算机软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is better implementation. Based on this understanding, the technical solutions of the present application can be embodied in the form of computer software products that are essentially or contribute to related technologies, and the computer software products are stored in a storage medium (such as ROM/RAM, magnetic disk, CD-ROM), including several instructions to make a terminal (which may be a mobile phone, a computer, a server, or a network device, etc.) execute the methods described in the various embodiments of this application.

上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本申请的保护之内。The embodiments of the present application have been described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific embodiments, which are merely illustrative rather than restrictive. Under the inspiration of this application, without departing from the scope of protection of the purpose of this application and the claims, many forms can be made, which all fall within the protection of this application.

Claims (10)

1.一种内存分配方法,其特征在于,包括:1. a memory allocation method, is characterized in that, comprises: 获取内存分配请求;Get memory allocation request; 在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;In the case that the contiguous memory that satisfies the memory allocation request is not allocated by the first allocation method, allocate memory in the reserved memory pool to satisfy the memory allocation request; 其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。Wherein, the first allocation manner includes at least one of the following: a fast memory allocation path and a slow memory allocation path. 2.根据权利要求1所述的内存分配方法,其特征在于,所述分配预留内存池中内存以满足所述内存分配请求之后,所述方法还包括:2. The memory allocation method according to claim 1, wherein after allocating the memory in the reserved memory pool to meet the memory allocation request, the method further comprises: 在所述预留内存池的内存消耗速度大于第一阈值的情况下,确定目标应用进程,并结束运行所述目标应用进程,所述目标应用进程为用户感知度小于第二阈值的应用进程,所述用户感知度为结束运行应用进程后被用户感知的概率;In the case where the memory consumption speed of the reserved memory pool is greater than the first threshold, determine a target application process, and end running the target application process, where the target application process is an application process whose user perception is less than the second threshold, The user perception degree is the probability of being perceived by the user after the running application process is terminated; 对结束运行所述目标应用进程释放的内存进行规整处理,得到连续内存。Perform regular processing on the memory released by the end of running the target application process to obtain continuous memory. 3.根据权利要求2所述的内存分配方法,其特征在于,所述结束运行所述目标应用进程之前,所述方法还包括:3. The memory allocation method according to claim 2, wherein, before the end of running the target application process, the method further comprises: 确定系统内存的碎片化程度;Determine the degree of fragmentation of system memory; 所述结束运行所述目标应用进程,包括:The ending of running the target application process includes: 在所述碎片化程度大于第三阈值的情况下,结束运行所述目标应用进程。In the case that the fragmentation degree is greater than the third threshold, the target application process is terminated. 4.根据权利要求1所述的内存分配方法,其特征在于,所述获取内存分配请求之前,所述方法还包括:4. The memory allocation method according to claim 1, wherein, before the acquiring the memory allocation request, the method further comprises: 在系统处于启动状态的情况下,获取所述预留内存池的第一配置文件;When the system is in the startup state, obtain the first configuration file of the reserved memory pool; 根据所述第一配置文件确定所述预留内存池的初始内存;Determine the initial memory of the reserved memory pool according to the first configuration file; 基于所述初始内存对所述预留内存池进行初始化处理;performing initialization processing on the reserved memory pool based on the initial memory; 其中,所述第一配置文件为服务器下发的配置文件。Wherein, the first configuration file is a configuration file delivered by the server. 5.根据权利要求1-4中任一项所述的内存分配方法,其特征在于,所述分配预留内存池中内存以满足所述内存分配请求,包括:5. The memory allocation method according to any one of claims 1-4, wherein the allocating memory in the reserved memory pool to satisfy the memory allocation request comprises: 根据所述内存分配请求的内存需求向所述预留内存池申请内存;Apply for memory from the reserved memory pool according to the memory requirement of the memory allocation request; 在所述预留内存池满足所述内存需求的情况下,分配预留内存池中内存以满足所述内存分配请求。In the case that the reserved memory pool satisfies the memory requirement, allocate memory in the reserved memory pool to satisfy the memory allocation request. 6.根据权利要求5所述的内存分配方法,其特征在于,所述根据所述内存分配请求的内存需求向所述预留内存池申请内存之后,所述方法还包括:6. The memory allocation method according to claim 5, wherein after applying for memory from the reserved memory pool according to the memory requirement of the memory allocation request, the method further comprises: 在所述预留内存池不满足所述内存需求的情况下,调整第一配置文件对应的初始内存,得到第二配置文件;In the case that the reserved memory pool does not meet the memory requirement, adjusting the initial memory corresponding to the first configuration file to obtain a second configuration file; 将所述第一配置文件更新为所述第二配置文件;updating the first configuration file to the second configuration file; 其中,所述第二配置文件对应的初始内存小于或等于第四阈值,所述第四阈值与系统物理内存具有关联关系。Wherein, the initial memory corresponding to the second configuration file is less than or equal to a fourth threshold, and the fourth threshold is associated with the system physical memory. 7.一种内存分配装置,其特征在于,包括:获取模块和分配模块;7. A memory allocation device, comprising: an acquisition module and an allocation module; 所述获取模块,用于获取内存分配请求;The obtaining module is used to obtain a memory allocation request; 所述分配模块,用于在通过第一分配方式未分配到满足所述内存分配请求的连续内存的情况下,分配预留内存池中内存以满足所述内存分配请求;The allocating module is configured to allocate memory in the reserved memory pool to satisfy the memory allocation request under the condition that the contiguous memory that satisfies the memory allocation request is not allocated by the first allocation method; 其中,所述第一分配方式包括以下至少一项:快速内存分配路径和慢速内存分配路径。Wherein, the first allocation manner includes at least one of the following: a fast memory allocation path and a slow memory allocation path. 8.根据权利要求7所述的内存分配装置,其特征在于,所述装置还包括处理模块;8. The memory allocation device according to claim 7, wherein the device further comprises a processing module; 所述处理模块,用于在所述内存消耗速度大于第一阈值的情况下,确定目标应用进程,并结束运行所述目标应用进程,所述目标应用进程为用户感知度小于第二阈值的应用进程,所述用户感知度为结束运行应用进程后被用户感知的概率;The processing module is configured to determine a target application process when the memory consumption speed is greater than a first threshold, and end running the target application process, where the target application process is an application whose user perception is less than the second threshold process, the user perception is the probability of being perceived by the user after the running application process is terminated; 对结束运行所述目标应用进程释放的内存进行规整处理,得到连续内存。Perform regular processing on the memory released by the end of running the target application process to obtain continuous memory. 9.一种电子设备,其特征在于,包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如权利要求1-6任一项所述的内存分配方法。9. An electronic device, characterized in that it comprises a processor and a memory, wherein the memory stores a program or an instruction that can be run on the processor, and when the program or instruction is executed by the processor, the implementation as claimed in the claims The memory allocation method described in any one of 1-6. 10.一种可读存储介质,其特征在于,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如权利要求1-6任一项所述的内存分配方法。10. A readable storage medium, wherein a program or an instruction is stored on the readable storage medium, and when the program or instruction is executed by a processor, the memory allocation according to any one of claims 1-6 is realized method.
CN202210254377.4A 2022-03-15 2022-03-15 Memory allocation method and device, electronic equipment and medium Pending CN114564315A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210254377.4A CN114564315A (en) 2022-03-15 2022-03-15 Memory allocation method and device, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210254377.4A CN114564315A (en) 2022-03-15 2022-03-15 Memory allocation method and device, electronic equipment and medium

Publications (1)

Publication Number Publication Date
CN114564315A true CN114564315A (en) 2022-05-31

Family

ID=81719401

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210254377.4A Pending CN114564315A (en) 2022-03-15 2022-03-15 Memory allocation method and device, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN114564315A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116361012A (en) * 2023-06-01 2023-06-30 荣耀终端有限公司 Memory page allocation method and electronic equipment
CN117724826A (en) * 2023-06-13 2024-03-19 荣耀终端有限公司 Memory allocation method for interprocess communication, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101937398A (en) * 2010-09-14 2011-01-05 中兴通讯股份有限公司 Embedded system memory pool configuration method and device
CN105302738A (en) * 2015-12-09 2016-02-03 北京东土科技股份有限公司 Method and device for distributing memory
CN106155699A (en) * 2016-07-29 2016-11-23 维沃移动通信有限公司 The management method of a kind of background process and mobile terminal
CN108255941A (en) * 2017-12-08 2018-07-06 佛吉亚好帮手电子科技有限公司 A kind of method of the raising picture loading velocity of low EMS memory occupation
CN108334440A (en) * 2017-01-19 2018-07-27 阿里巴巴集团控股有限公司 A kind of processing method and processing device, client obtaining application performance test result
CN111078587A (en) * 2019-12-10 2020-04-28 Oppo(重庆)智能科技有限公司 Memory allocation method and device, storage medium and electronic equipment
CN112631773A (en) * 2020-12-23 2021-04-09 苏州三六零智能安全科技有限公司 Data dynamic release method, device, equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101937398A (en) * 2010-09-14 2011-01-05 中兴通讯股份有限公司 Embedded system memory pool configuration method and device
CN105302738A (en) * 2015-12-09 2016-02-03 北京东土科技股份有限公司 Method and device for distributing memory
CN106155699A (en) * 2016-07-29 2016-11-23 维沃移动通信有限公司 The management method of a kind of background process and mobile terminal
CN108334440A (en) * 2017-01-19 2018-07-27 阿里巴巴集团控股有限公司 A kind of processing method and processing device, client obtaining application performance test result
CN108255941A (en) * 2017-12-08 2018-07-06 佛吉亚好帮手电子科技有限公司 A kind of method of the raising picture loading velocity of low EMS memory occupation
CN111078587A (en) * 2019-12-10 2020-04-28 Oppo(重庆)智能科技有限公司 Memory allocation method and device, storage medium and electronic equipment
CN112631773A (en) * 2020-12-23 2021-04-09 苏州三六零智能安全科技有限公司 Data dynamic release method, device, equipment and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116361012A (en) * 2023-06-01 2023-06-30 荣耀终端有限公司 Memory page allocation method and electronic equipment
CN116361012B (en) * 2023-06-01 2023-10-24 荣耀终端有限公司 Memory page allocation method and electronic equipment
CN117724826A (en) * 2023-06-13 2024-03-19 荣耀终端有限公司 Memory allocation method for interprocess communication, electronic equipment and storage medium
CN117724826B (en) * 2023-06-13 2024-12-10 荣耀终端有限公司 Memory allocation method, electronic device and storage medium for inter-process communication

Similar Documents

Publication Publication Date Title
CN111158910B (en) Memory management method and device, storage medium and electronic equipment
CN111078147B (en) Processing method, device and equipment for cache data and storage medium
US9229651B2 (en) Method and apparatus for managing memory in virtual machine environment
US8838930B2 (en) Methods, systems, and devices for management of a memory system
CN107209683B (en) Backup image restore
CN111475299B (en) Memory allocation method and device, storage medium and electronic equipment
CN114564315A (en) Memory allocation method and device, electronic equipment and medium
CN105677483B (en) Data caching method and device
CN115509953A (en) Memory recovery method and device
CN107408073B (en) Reducing memory commit overhead using memory compression
CN111078407B (en) Memory management method and device, storage medium and electronic equipment
US8751724B2 (en) Dynamic memory reconfiguration to delay performance overhead
CN115357389A (en) Memory management method and device and electronic equipment
US7243041B2 (en) GUID, PnPID, isochronous bandwidth based mechanism for achieving memory controller thermal throttling
CN111444117B (en) Method and device for realizing fragmentation of storage space, storage medium and electronic equipment
WO2024245175A1 (en) Memory reclamation method and apparatus, electronic device, and storage medium
KR20220051546A (en) Electronic apparatus and control method thereof
WO2024222606A1 (en) Cache resource adjustment method and apparatus, and electronic device and readable storage medium
CN117170872A (en) Memory management method, device, equipment and storage medium
WO2023236930A1 (en) Memory allocation method and apparatus based on ion allocator, electronic device, and readable storage medium
CN114924995A (en) Storage space fragmentation and arrangement method and device and electronic equipment
CN113032290A (en) Flash memory configuration method and device, electronic equipment and storage medium
US9798479B2 (en) Relocatable and resizable tables in a computing device
CN113806238A (en) Memory allocation method, device, storage medium and electronic device
CN117311967A (en) Memory processing method and device and electronic equipment

Legal Events

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