WO2023236930A1 - 基于ion分配器的内存分配方法、装置、电子设备和可读存储介质 - Google Patents

基于ion分配器的内存分配方法、装置、电子设备和可读存储介质 Download PDF

Info

Publication number
WO2023236930A1
WO2023236930A1 PCT/CN2023/098499 CN2023098499W WO2023236930A1 WO 2023236930 A1 WO2023236930 A1 WO 2023236930A1 CN 2023098499 W CN2023098499 W CN 2023098499W WO 2023236930 A1 WO2023236930 A1 WO 2023236930A1
Authority
WO
WIPO (PCT)
Prior art keywords
memory
pool
terminal device
ion
allocator
Prior art date
Application number
PCT/CN2023/098499
Other languages
English (en)
French (fr)
Inventor
刘磊
荣乾锋
Original Assignee
维沃移动通信有限公司
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 维沃移动通信有限公司 filed Critical 维沃移动通信有限公司
Publication of WO2023236930A1 publication Critical patent/WO2023236930A1/zh

Links

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

Definitions

  • This application belongs to the field of memory management technology, and specifically relates to a memory allocation method, device, electronic device and readable storage medium based on an ION allocator.
  • the terminal device has problems such as slow camera startup, camera lag, video lag, and frame drops, which greatly affects the user experience.
  • the purpose of the embodiments of this application is to provide a memory allocation method, device, electronic device and readable storage medium based on an ION allocator, which can solve the existing problem of slow application speed for large amounts of memory.
  • embodiments of the present application provide a memory allocation method based on the ION allocator.
  • the method includes:
  • inventions of the present application provide a memory allocation device based on an ION allocator.
  • the device includes:
  • a determination module configured to determine the memory required by the target application in the user space of the terminal device when the terminal device starts the target application
  • a sending module configured to send a memory expansion request in the user space to the kernel space of the terminal device, where the memory expansion request includes the memory required by the target application;
  • An expansion module configured to expand the memory required by the target application from the system memory to the memory pool of the terminal device ION allocator based on the memory expansion request in the kernel space, and return it to the user space.
  • An application module is configured to apply memory to the memory pool for the target application in the user space after receiving the expansion completion command.
  • inventions of the present application provide an electronic device.
  • the electronic device includes a processor and a memory.
  • the memory stores programs or instructions that can be run on the processor.
  • the programs or instructions are processed by the processor.
  • the processor is executed, the steps of the method described in the first aspect are implemented.
  • embodiments of the present application provide a readable storage medium.
  • Programs or instructions are stored on the readable storage medium.
  • the steps of the method described in the first aspect are implemented. .
  • inventions of the present application provide a chip.
  • the chip includes a processor and a communication interface.
  • the communication interface is coupled to the processor.
  • the processor is used to run programs or instructions to implement the first aspect. the method described.
  • 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 method as described in the first aspect.
  • the memory required by the target application is determined in the user space of the terminal device; in the user space, the memory required by the target application is sent to the kernel space of the terminal device.
  • Memory expansion request the memory expansion request includes the memory required by the target application; in the kernel space, based on the memory expansion request, expand the memory required by the target application from the system memory to the terminal device ION in the memory pool of the allocator, and returns an expansion completion command to the user space; in the user space, after receiving the expansion completion command, it applies to the memory pool for memory for the target application, thereby It can establish communication between the underlying memory allocation and upper-layer applications, and support multimedia applications that apply for a large amount of memory. They can expand memory in advance to ensure the speed of memory application and avoid problems such as slow application startup and stuck operations.
  • Figure 1 is a schematic flowchart of a memory allocation method based on an ION allocator according to an embodiment of the present application.
  • Figure 2 is a schematic flowchart of the memory allocation method based on the ION allocator according to the first embodiment of the present application.
  • Figure 3 is a schematic flowchart of the memory allocation method based on the ION allocator according to the second embodiment of the present application.
  • Figure 4 is a schematic flowchart of a memory allocation method based on the ION allocator according to the third embodiment of the present application.
  • Figure 5 is a schematic flowchart of a memory allocation method based on the ION allocator according to the fourth embodiment of the present application.
  • Figure 6 is a schematic architectural diagram of the ION memory allocator according to the embodiment of the present application.
  • Figure 7 is a structural block diagram of a memory allocation device based on an ION allocator according to an embodiment of the present application.
  • Figure 8 is a structural block diagram of an electronic device according to an embodiment of the present application.
  • Figure 9 is a schematic diagram of the hardware structure of an electronic device that implements an embodiment of the present application.
  • first, second, etc. in the description and claims of this 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 figures so used are interchangeable under appropriate circumstances so that the embodiments of the present application can be practiced in orders other than those illustrated or described herein, and that "first,” “second,” etc. are distinguished Objects are usually of one type, and the number of objects is not limited. For example, the first object can be one or multiple.
  • “and/or” in the description and claims indicates at least one of the connected objects, and the character “/" generally indicates that the related objects are in an "or” relationship.
  • Figure 1 is a schematic flowchart of a memory allocation method based on an ION allocator according to an embodiment of the present application. As shown in Figure 1, the memory allocation method based on the ION allocator in the embodiment of the present application includes the following steps 102 to 108.
  • Step 102 When the terminal device starts the target application, determine the memory required by the target application in the user space of the terminal device.
  • the target applications are various applications installed on the terminal device, especially applications that require a large amount of memory to start and execute operations, such as multimedia applications such as cameras.
  • determining the memory required by the target application in the user space of the terminal device includes: In the case where the target application is an application of a preset type, the memory required by the target application is determined in the user space of the terminal device.
  • the target application is an application that requires a large amount of memory to start and execute operations.
  • the memory required by the application can be determined in advance in the user space of the terminal device.
  • the target application After the target application is started, if the target application has multiple operation scenarios, for example, the target application is a camera, and the camera includes multiple operation scenarios such as photo taking scenes, video recording scenes, or delayed photography scenes, etc., then in the upper user space based on the current selection of the application Scenario, determine the memory size required by the target application to perform the scenario operation.
  • the target application is a camera
  • the camera includes multiple operation scenarios such as photo taking scenes, video recording scenes, or delayed photography scenes, etc.
  • a 4K 60-frame video recording scene generally requires application for 16 megabytes (MB) of memory every 5 milliseconds, and the total amount of memory required is about 2 gigabytes (GB).
  • MB megabytes
  • GB gigabytes
  • the memory usage to be used by the application is directly calculated.
  • target applications with multiple operating scenarios first identify the different operating scenarios and then calculate the memory usage that the application will use.
  • Step 104 In the user space, send a memory expansion request to the kernel space of the terminal device, where the memory expansion request includes the memory required by the target application.
  • the upper user space of the terminal device can issue a memory expansion request to the underlying kernel space, so that the kernel space can prepare the memory required by the target application in advance.
  • Step 106 In the kernel space, based on the memory expansion request, expand the memory required by the target application from the system memory to the memory pool of the terminal device ION allocator, and return the expansion completion to the user space. Order.
  • the kernel space based on the memory expansion request, expand the memory required by the target application from the system memory to the memory pool of the terminal device ION allocator, including: responding to the memory expansion request , wake up the target thread in the kernel space; bind the target thread to the CPU large core of the terminal device; apply for memory expansion from the system memory through the CPU large core to expand the requirements of the target application memory to the memory pool.
  • the thread used for memory expansion is awakened, and this thread is bound to the CPU large core, and will apply for memory from the system memory (Buddy system) to expand the memory to ION allocation
  • the memory pool (Pool) of the ION allocator can be expanded to the usage requirements of the target application as quickly as possible. And after the memory expansion is completed, the corresponding command is returned to the user space.
  • Step 108 In the user space, after receiving the expansion completion command, apply for memory from the memory pool for the target application.
  • the upper user space starts to apply for memory after receiving the memory expansion completion command. At this time, it directly takes the memory from the memory pool of the ION allocator and uses it for the target application. This can meet the high speed and high performance of the target application in scenarios that require a large amount of memory. Amount of memory requirements.
  • the memory expanded into the memory pool is configured as exclusive memory for the target application, and the exclusive memory is non-recyclable memory.
  • FIG. 2 is a schematic flowchart of a memory allocation method based on an ION allocator according to the first embodiment of the present application.
  • This embodiment is a specific example of FIG. 1 , in which the target application takes a camera as an example.
  • Step 202 the upper user space opens the camera
  • Step 204 When the camera enters the corresponding scene mode, it identifies different operating scenarios, such as taking pictures or recording scenes;
  • Step 206 Calculate the memory usage required by the camera in this operating scenario
  • Step 208 The upper layer issues a charge (memory expansion) request carrying the required memory usage to the underlying kernel space;
  • Step 210 Notify the underlying kwork kernel thread to perform memory expansion based on the request
  • Step 212 the kwork kernel thread is bound to the central processing unit (Central Processing Unit, CPU) large core to speed up memory charge memory application from buddy;
  • CPU Central Processing Unit
  • Step 214 Set the memory not to be shrink (recycled) after memory expansion
  • Step 216 Set the expanded memory to allow only cameras to apply for use.
  • the method further includes:
  • the memory application stall time of the system memory is less than or equal to the first threshold and the CPU stall time is less than or equal to the second threshold, the memory in the memory pool of the ION allocator is released in a delayed manner.
  • the unit of memory application lag time is microseconds ( ⁇ s).
  • pressure stall information is used as an indicator to measure the pressure of hardware resources, such as CPU, memory and input/output (Input/Output, IO).
  • hardware resources such as CPU, memory and input/output (Input/Output, IO).
  • the CPU and The pressure value of the memory is used as a reference for the pressure level.
  • PSI quantifies task execution interruptions caused by tight hardware resources and counts the time tasks in the system wait for hardware resources. The longer the pause time during memory application, the greater the pressure on resources.
  • the first threshold is, for example, 60-70 milliseconds (ms)
  • the second threshold is, for example, 60-70 ms.
  • Step 302 the ION allocator frees the memory
  • Step 304 The release process always monitors the current system memory pressure and CPU usage of the terminal device
  • Step 306 If it is detected that the memory pressure is high, or the memory pressure is low and the CPU usage is high, enter step 308;
  • Step 308 will directly release the memory
  • Step 310 If the memory requested by the upper-layer application comes from the buddy system, release the memory and return it to the buddy system;
  • Step 312 if the memory requested by the upper-layer application comes from the memory pool of the ION allocator (ion pool), release the memory back to the memory pool;
  • Step 314 When it is detected that the system memory pressure is low and the CPU usage is low, enter step 316;
  • Step 316 At this time, the defer free process will be followed, and the memory release task will be added to a delayed release (defer free) linked list, so that the release thread will be awakened during the next memory application to delay the release of the memory.
  • the release speed of the ION allocator memory can be increased.
  • memory release can be considered Speed while reducing competition for CPU resources.
  • the method further includes:
  • the memory specifications include order 1, order 2, order 4 and order 9.
  • the order 4 and order 9 are configured with a memory application abandonment identifier.
  • the memory application abandonment identifier is used to inform the ION allocator that the request specification has not been applied for. In the case of memory, the memory application is given up.
  • order1, order2, order4 and order9 are memory specifications that express memory size.
  • the memory size order corresponding to the memory specifications is order9>order4>order2>order1.
  • the default order is order9 before order4, order4 before order2, order2 before order1, that is, priority is given to applying for large-sized memory. After the corresponding large-sized continuous memory cannot be applied for, small-sized memory is applied in sequence. Specifications of memory.
  • the target large-sized memory such as order9 and order4
  • the remaining system memory is a small amount of fragmented memory. If large-sized memory is still used to apply and fill, memory application failure will occur in most cases.
  • Using small-sized order2 and order1 to apply for fragmented memory in sequence can increase the probability of successful memory application and filling.
  • the method further includes:
  • the memory pool of the ION allocator includes two types of memory, cache memory (Cache) and uncache memory (Uncache).
  • the applied memory specification is the applied memory size.
  • the two types of memory pools in the memory pool of the ION allocator, the cache pool and the uncache pool, can communicate with each other. If the target memory specifications applied by the upper-layer application are within If the memory size exceeds the memory pool of the requested target memory type, the memory in the memory pool of another memory type in the memory pool can be migrated to the memory pool of the target memory type to meet the requirements of the upper-level memory application. required memory size.
  • Step 402 When starting the target application, apply for memory of the target memory type from the memory pool of the ION allocator, for example, buffer memory or non-buffer memory;
  • Step 404 when the target memory type is non-buffered memory, if the amount of memory corresponding to the applied memory specification is large, causing the memory of the Uncache pool to be quickly consumed, when the memory is insufficient, but there is still a lot of memory in the Cache pool, at this time
  • the memory migration in the Cache pool can be added to the Uncache pool to satisfy the Uncache pool application;
  • Step 406 conversely, when the memory in the Cache pool is insufficient, the memory in the Uncache pool can be migrated to the Cache pool.
  • the method further includes:
  • the terminal device When the terminal device is powered on, read the memory configuration file of the ION allocator, and the memory configuration file is used to configure the first reserved memory in the memory pool of the ION allocator;
  • the first reserved memory is filled from the system memory of the terminal device into the memory pool, wherein the first reserved memory is determined based on the available memory of the terminal device.
  • the reserved memory is locked and will not be released and recycled. Only when the system memory pressure is particularly high, some or all of the reserved memory will be released according to the level of system pressure. When the system memory pressure recovers, the reserved memory will be restored to the original value.
  • the reserved memory size can be determined based on the available memory size when the terminal device is turned on.
  • the initial reserved memory size is the available memory when the terminal device is turned on divided by a certain constant k.
  • the value of k is 8-10, which means that the initial Reserve about 10% of the available memory of the terminal device in advance.
  • the memory pressure used by different terminal devices may be different, and the available memory size may also be different. Therefore, the reserved memory size of the memory pool needs to be dynamically adjusted according to the specific use of the terminal device.
  • the method further includes: monitoring a first available memory of the terminal device; and updating the memory configuration file based on the first available memory.
  • the monitoring of the first available memory of the terminal device includes: counting the available memory of the terminal device within a preset time period after booting at a preset time interval; calculating the average available memory within the predetermined time period to obtain the The first available memory of the terminal device.
  • the updating of the memory configuration file based on the first available memory includes: obtaining the historical available memory of the terminal device corresponding to the reserved memory in the memory configuration file; and combining the first available memory and If the change value of the historical available memory is greater than the preset threshold, the first reserved memory in the memory configuration file is updated based on the first available memory.
  • the available memory status of the terminal device is counted every 10-30 minutes, and the average available memory is taken every 12 hours or 24 hours.
  • the average available memory calculated once every 24 hours a day calculate the absolute value of the change between the average available memory value of that day and the average available memory value of the previous day. Determine whether the absolute value of the change is within the set preset threshold. If it exceeds the preset threshold, use the current average available memory value to update the average available memory value of the previous day, that is, the available memory of the terminal device, so that based on the current terminal device of available memory, and update the corresponding reserved memory in the memory configuration file.
  • the next time the terminal device restarts it will read the latest memory configuration file and initialize the memory reserved by the memory pool.
  • it also includes:
  • the server in order to adjust the size of the memory pool conveniently and timely, can also reserve memory according to the model memory size of the terminal device and issue a memory configuration file that changes the memory pool.
  • the server configuration has a higher priority than the configuration based on monitoring the available memory of the terminal device in the above embodiment.
  • the method further includes:
  • the reserved memory reclaimed from the system memory is filled into the memory pool.
  • the reserved memory can release part or all of the reserved memory according to the system pressure level only when the system memory pressure is particularly high. When the system memory pressure recovers, the reserved memory can be restored to the original value.
  • Step 502 reserve memory (pool) in the configuration file
  • Step 504 The mobile phone is powered on and starts reading the configuration file
  • Step 506 obtain the size of the reserved pool
  • Step 508 Initialize the ION memory allocator pool memory size (pool size) according to the reserved size;
  • Step 510 The memory size of the locked pool is not recycled
  • Step 512 Large applications apply for a large amount of memory, causing memory pressure
  • Step 514 release part of the memory according to the pressure level
  • Step 516 The system releases all memory before launching OOM
  • Step 518 Release the memory and recycle it to the buddy system.
  • the configuration file can be updated based on the method from step 520 to step 532, or can be updated based on the method from step 534 to step 538, as follows:
  • Step 520 Establish a correspondence between the available memory of the terminal device and the reserved pool
  • Step 522 Dynamically adjust the size of the reserved pool according to user usage habits
  • Step 524 count the average available memory level of the user
  • Step 526 count every 10 minutes, and take the average value every day
  • Step 528 The difference between the average value of the current day and the average value of the previous day exceeds the set threshold
  • Step 530 Calculate pool size based on the corresponding relationship between pool size and available memory
  • Step 532 Update the pool size configuration file.
  • Step 534 The server issues the configuration command
  • Step 536 issue the size of the configuration pool
  • Step 538 Modify the pool size configuration file in the mobile phone according to the configuration command.
  • the startup speed of the target application can be improved, and the reserved memory can be recycled when the system memory pressure is high, and the size of the reserved memory can be adjusted according to Adaptive updates for different users and usage habits, and also supports the size configuration of reserved memory issued by the server.
  • Figure 6 is the architecture of the ION memory allocator corresponding to the memory allocation method based on the ION allocator in the embodiment of the present application. Schematic diagram.
  • the ION memory allocator can realize the following functions: function 1 memory expansion; function 2 memory release in different scenarios; function 3 multiple order application filling; function 4 different types of memory interoperability; function 5 memory reservation.
  • the memory required by the target application is determined in the user space of the terminal device; in the user space, the memory required by the target application is sent to the kernel space of the terminal device.
  • Memory expansion request the memory expansion request includes the memory required by the target application; in the kernel space, based on the memory expansion request, the system memory is expanded.
  • the memory required by the target application is added to the memory pool of the terminal device ION allocator, and an expansion completion command is returned to the user space; in the user space, after receiving the expansion completion command, the memory is returned to the memory pool.
  • the pool applies for memory for the target application, thereby establishing communication between the underlying memory allocation and the upper-layer application, supporting the target application to expand memory in advance, and ensuring the speed of memory application.
  • This can accelerate the startup speed of the target application, allowing the target application to apply for memory at the fastest speed, which can effectively reduce the lag and loss caused by slow memory application in scenarios where applications that need to use ION memory quickly and in large quantities apply for memory. Frame problem.
  • the execution subject may be a memory allocation device based on the ION allocator.
  • the memory allocation device based on the ION allocator performs the memory allocation method based on the ION allocator as an example to illustrate the memory allocation device based on the ION allocator provided by the embodiment of the present application.
  • the memory allocation device based on the ION allocator in the embodiment of the present application may be an electronic device or a component in the electronic device, such as an integrated circuit or a chip.
  • the electronic device may be a terminal or other devices other than the terminal.
  • the electronic device can be a mobile phone, a tablet computer, a notebook computer, a handheld computer, a vehicle-mounted electronic device, a mobile internet device (Mobile Internet Device, MID), or augmented reality (AR)/virtual reality (VR). ) equipment, robots, wearable devices, ultra-mobile personal computers (UMPC), netbooks or personal digital assistants (personal digital assistants, PDA), etc., and can also be personal computers (personal computers, PC), etc.,
  • the embodiments of this application are not specifically limited.
  • the memory allocation device based on the ION allocator in the embodiment of the present application may be a device with an operating system.
  • the operating system can be an Android operating system, an ios operating system, or other possible operating systems, which are not specifically limited in the embodiments of this application.
  • the memory allocation device based on the ION allocator provided by the embodiment of the present application can implement various processes implemented by the method embodiments of Figures 1 to 6. To avoid duplication, they will not be described again here.
  • FIG. 7 is a structural block diagram of a memory allocation device based on an ION allocator according to an embodiment of the present application.
  • the memory allocation device 800 based on an ION allocator according to an embodiment of the present application includes:
  • Determining module 820 configured to determine the memory required by the target application in the user space of the terminal device when the terminal device starts the target application
  • the sending module 840 is configured to send a memory expansion request in the user space to the kernel space of the terminal device, where the memory expansion request includes the memory required by the target application;
  • the expansion module 860 is configured to expand the memory required by the target application from the system memory to the memory pool of the terminal device ION allocator in the kernel space based on the memory expansion request, and provide the memory to the user space. Return to the expansion completion command;
  • the application module 880 is configured to apply to the user space after receiving the expansion completion command.
  • the memory pool requests memory for the target application.
  • the determining module 820 is specifically used to:
  • the memory required by the target application is determined in the user space of the terminal device.
  • the expansion module 860 is specifically used for:
  • the CPU large core applies for memory expansion from the system memory to expand the memory required by the target application into the memory pool.
  • the memory allocation device 800 also includes:
  • a dedicated memory configuration module is configured to configure the memory expanded into the memory pool as dedicated memory for the target application when the target application is started, and the dedicated memory is non-recyclable memory.
  • the memory required by the target application is determined in the user space of the terminal device; in the user space, the memory required by the target application is sent to the kernel space of the terminal device.
  • Memory expansion request the memory expansion request includes the memory required by the target application; in the kernel space, based on the memory expansion request, expand the memory required by the target application from the system memory to the terminal device ION in the memory pool of the allocator, and returns an expansion completion command to the user space; in the user space, after receiving the expansion completion command, it applies to the memory pool for memory for the target application, thereby Establish communication between the underlying memory allocation and the upper-layer application to support target applications to expand memory in advance and ensure the speed of memory application. This can accelerate the startup speed of the target application, allowing the target application to apply for memory at the fastest speed, which can effectively reduce the lag and loss caused by slow memory application in scenarios where applications that need to use ION memory quickly and in large quantities apply for memory. Frame problem.
  • the memory allocation device 800 also includes:
  • a time monitoring module used to monitor the CPU stuck time of the terminal device and the memory application stuck time of the system memory when there is memory release in the ION allocator;
  • the release module is used to directly release the memory in the memory pool of the ION allocator when the memory application lag time of the system memory is greater than the first threshold; when the memory application lag time of the system memory is less than Or equal to the first threshold and the CPU stall time is greater than the second threshold, directly release the memory in the memory pool of the ION allocator; when the memory application stall time of the system memory is less than or equal to the first If the CPU freeze time is less than or equal to the second threshold, the memory in the memory pool of the ION allocator is released in a delayed manner.
  • the release speed of the ION allocator memory can be increased.
  • memory release speed can be considered while Reduce competition for CPU resources.
  • the memory allocation device 800 also includes:
  • a memory monitoring module used to monitor the memory specifications in the memory pool of the ION allocator
  • a filling module configured to apply for the system memory in a preset order to fill memory in the memory pool according to the memory specifications in the memory pool of the ION allocator when the memory is lower than a preset threshold;
  • the memory specifications include order1, order2, order4 and order9.
  • the order4 and order9 are configured with a memory application abandonment identifier.
  • the memory application abandonment identifier is used to inform the ION allocator when the memory of the requested specification has not been applied for. , give up the memory application.
  • the memory filling speed of the ION allocator can be accelerated.
  • the memory allocation device 800 also includes:
  • a determining module configured to, after receiving the expansion completion command, apply for memory from the memory pool for the target application, and determine to apply to the memory pool for the memory type and memory specification for the target application,
  • the memory types of the memory pool include buffered memory and non-buffered memory
  • a migration module configured to migrate the target non-buffered memory from the non-buffered memory in the memory pool to the buffered memory when the applied memory type is buffered memory and the applied memory exceeds the buffered memory in the memory pool. in the buffer memory; when the memory type applied for is non-buffer memory and the applied memory exceeds the non-buffer memory in the memory pool, migrate the target buffer memory from the buffer memory in the memory pool to the buffer memory. in non-buffered memory.
  • the memory allocation device 800 also includes:
  • a reading module configured to read the memory configuration file of the ION allocator when the terminal device is powered on, and the memory configuration file is used to configure the first reserved memory in the memory pool of the ION allocator;
  • a filling module configured to fill the first reserved memory from the system memory of the terminal device into the memory pool based on the memory configuration file, wherein the first reserved memory is based on the system memory of the terminal device. Available memory determined.
  • the memory allocation device 800 also includes:
  • a memory monitoring module used to monitor the first available memory of the terminal device
  • a first update module configured to update the memory configuration file based on the first available memory.
  • the memory monitoring module is specifically used for:
  • the first update module is specifically used for:
  • the memory allocation device 800 also includes:
  • a receiving module configured to receive a configuration command sent by the server, where the configuration command carries the configured second reserved memory
  • the second update module is configured to update the first reserved memory in the configuration file based on the configured second reserved memory.
  • the memory allocation device 800 also includes:
  • a pressure monitoring module configured to monitor the memory pressure of the system memory after filling the first reserved memory from the system memory of the terminal device into the memory pool;
  • a recycling module configured to recycle the target reserved memory in the memory pool to the system memory based on the memory pressure level of the system memory
  • a filling module configured to fill the reserved memory recovered into the system memory into the memory pool when the memory pressure of the system memory is lower than a preset threshold.
  • the startup speed of the target application can be improved, and the reserved memory can be recycled when the system memory pressure is high.
  • the size of the reserved memory can be customized according to different users and usage habits. To adapt to updates, it also supports the server to issue reserved memory size configuration.
  • this embodiment of the present application also provides an electronic device 900, including a processor 940 and a memory 920.
  • the memory 920 stores programs or instructions that can be run on the processor 940.
  • the program or instruction is executed by the processor 940, each step of the above memory allocation method embodiment is implemented, and the same technical effect can be achieved. To avoid duplication, the details will not be described here.
  • the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
  • FIG. 9 is a schematic diagram of the hardware structure of an electronic device implementing an embodiment of the present application.
  • the electronic device 1000 includes but is not limited to: radio frequency unit 1001, network module 1002, audio output unit 1003, input unit 1004, sensor 1005, display unit 1006, user input unit 1007, interface unit 1008, memory 1009, processor 1010, etc. part.
  • the electronic device 1000 may also include a power supply (such as a battery) that supplies power to various components.
  • the power supply may be logically connected to the processor 1010 through a power management system, thereby managing charging, discharging, and function through the power management system. Consumption management and other functions. Shown in Figure x
  • the structure of the electronic device shown does not constitute a limitation on the electronic device.
  • the electronic device may include more or fewer components than shown in the figure, or may combine certain components, or arrange different components, which will not be described again here.
  • the processor 1010 is configured to determine the memory required by the target application in the user space of the terminal device when the terminal device starts the target application; and in the user space, send a message to the kernel space of the terminal device.
  • Memory expansion request the memory expansion request includes the memory required by the target application; in the kernel space, based on the memory expansion request, expand the memory required by the target application from the system memory to the terminal device ION
  • an expansion completion command is returned to the user space; in the user space, after receiving the expansion completion command, it applies to the memory pool for memory for the target application.
  • the processor 1010 is further configured to: when the target application is a preset type of application, determine the memory required by the target application in the user space of the terminal device.
  • the processor 1010 is also configured to: respond to the memory expansion request, wake up the target thread in the kernel space; bind the target thread to the CPU large core of the terminal device; The core applies for expanded memory from the system memory to expand the memory required by the target application into the memory pool.
  • the processor 1010 is also configured to: when the target application is started, configure the memory expanded into the memory pool as exclusive memory for the target application, and the exclusive memory is non-recyclable memory. .
  • the processor 1010 is also configured to: when there is memory release in the ION allocator, monitor the CPU stall time of the terminal device and the memory application stall time of the system memory; When the memory application lag time is greater than the first threshold, the memory in the memory pool of the ION allocator is directly released; when the memory application lag time of the system memory is less than or equal to the first threshold and the CPU card When the stall time is greater than the second threshold, the memory in the memory pool of the ION allocator is directly released; when the memory application stall time of the system memory is less than or equal to the first threshold and the CPU stall time is less than or When equal to the second threshold, the memory in the memory pool of the ION allocator is released in a delayed manner.
  • the processor 1010 is also configured to: monitor the memory specifications in the memory pool of the ION allocator; when the memory is lower than a preset threshold, adjust the memory size in the memory pool of the ION allocator according to specifications, apply for the system memory in a preset order to fill the memory pool; wherein, the memory specifications include order1, order2, order4 and order9, the order4 and order9 are configured to give up memory application flags, the said give up memory application The flag is used to inform the ION allocator to give up the memory application if the memory of the requested specifications is not applied for.
  • the processor 1010 is further configured to: after receiving the expansion completion command, apply for memory to the memory pool for the target application, and determine to apply to the memory pool for the target application.
  • memory type and memory specifications where the memory type of the memory pool includes buffer memory and non-buffered memory; when the applied memory type is buffered memory and the applied memory exceeds the buffered memory in the memory pool, migrate the target non-buffered memory from the non-buffered memory in the memory pool to the in the buffer memory; when the memory type applied for is non-buffer memory and the applied memory exceeds the non-buffer memory in the memory pool, migrate the target buffer memory from the buffer memory in the memory pool to the buffer memory. in non-buffered memory.
  • the processor 1010 is also configured to read the memory configuration file of the ION allocator when the terminal device is powered on, and the memory configuration file is used to configure the memory pool of the ION allocator.
  • First reserved memory based on the memory configuration file, fill the first reserved memory from the system memory of the terminal device into the memory pool, wherein the first reserved memory is based on the terminal device The available memory is determined.
  • the processor 1010 is further configured to: monitor the first available memory of the terminal device; and update the memory configuration file based on the first available memory.
  • the processor 1010 is also configured to: count the available memory of the terminal device within a preset time period after it is turned on at a preset time interval; calculate the average available memory within the predetermined time period to obtain the memory of the terminal device.
  • the first available memory obtaining the historical available memory of the terminal device corresponding to the reserved memory in the memory configuration file; when the change value between the first available memory and the historical available memory is greater than a preset threshold
  • the input unit 1004 is configured to receive a configuration command sent by the server, where the configuration command carries the configured second reserved memory.
  • the processor 1010 is also configured to update the first reserved memory in the configuration file based on the configured second reserved memory.
  • the processor 1010 is also configured to: after filling the first reserved memory from the system memory of the terminal device into the memory pool, monitor the memory pressure of the system memory; based on the system memory According to the memory pressure level, the target reserved memory in the memory pool will be recycled to the system memory; when the memory pressure of the system memory is lower than the preset threshold, the reserved memory will be recycled to the system memory. Populate the memory pool.
  • the memory required by the target application is determined in the user space of the terminal device; in the user space, the memory required by the target application is sent to the kernel space of the terminal device.
  • Memory expansion request the memory expansion request includes the memory required by the target application; in the kernel space, based on the memory expansion request, expand the memory required by the target application from the system memory to the terminal device ION in the memory pool of the allocator, and returns an expansion completion command to the user space; in the user space, after receiving the expansion completion command, it applies to the memory pool for memory for the target application, thereby Establish communication between the underlying memory allocation and the upper-layer application to support target applications to expand memory in advance and ensure the speed of memory application.
  • the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042, and the GPU 10041 is used for capturing images by an image capture device (such as a camera) in the video capture mode or the image capture mode.
  • the image data obtained from still pictures or videos is processed.
  • 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 .
  • Touch panel 10071 also known as 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 described again here.
  • 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.
  • memory 1009 may include volatile memory or nonvolatile memory, or memory 1009 may include both volatile and nonvolatile memory.
  • non-volatile memory can be read-only memory (Read-Only Memory, ROM), programmable read-only memory (Programmable ROM, PROM), erasable programmable read-only memory (Erasable PROM, EPROM), electrically removable 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 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).
  • RAM Random Access Memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • synchronous dynamic random access memory Synchronous DRAM, SDRAM
  • Double data rate synchronous dynamic random access memory Double Data Rate SDRAM, DDRSDRAM
  • enhanced SDRAM synchronous dynamic random access memory
  • Synch link DRAM synchronous link dynamic random access memory
  • SLDRAM direct memory bus random access memory
  • Direct Rambus RAM Direct Rambus RAM
  • the processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, where the application processor mainly handles operations related to the operating system, user interface, application programs, etc., Modem processors mainly process wireless communication signals, such as baseband processors. It can be understood that the above modem processor may not be integrated into the processor 1010.
  • Embodiments of the present application also provide a readable storage medium on which a program or instructions are stored.
  • the program or instructions are executed by a processor, the above memory allocation based on the ION allocator is implemented.
  • Each process of the preparation method embodiment can achieve the same technical effect. To avoid repetition, it will not be described again here.
  • the processor is the processor in the electronic device described in the above embodiment.
  • the readable storage medium includes computer readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disk, etc.
  • An embodiment of the present application further provides a chip.
  • the chip includes a processor and a communication interface.
  • the communication interface is coupled to the processor.
  • the processor is used to run programs or instructions to implement the above-mentioned ION allocator-based memory.
  • Each process of the allocation method embodiment can achieve the same technical effect. To avoid repetition, it will not be described again here.
  • chips mentioned in the embodiments of this application may also be called system-on-chip, system-on-a-chip, system-on-a-chip or system-on-chip, etc.
  • Embodiments of the present application provide a computer program product.
  • the program product is stored in a storage medium.
  • the program product is executed by at least one processor to implement the various processes of the above-mentioned ION allocator-based memory allocation method embodiment, and can To achieve the same technical effect, to avoid repetition, we will not repeat them here.
  • the methods of the above embodiments can be implemented by means of software plus the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better. implementation.
  • the technical solution of the present application can be embodied in the form of a computer software product that is essentially or contributes to the existing technology.
  • the computer software product is stored in a storage medium (such as ROM/RAM, disk , optical disk), including several instructions to cause a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of this application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

本申请公开了一种基于ION分配器的内存分配方法、装置、电子设备和可读存储介质,属于内存管理技术领域。该方法包括:在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。

Description

基于ION分配器的内存分配方法、装置、电子设备和可读存储介质
交叉引用
本发明要求在2022年06月10日提交中国专利局、申请号为202210655016.0、发明名称为“基于ION分配器的内存分配方法、装置、电子设备和可读存储介质”的中国专利申请的优先权,该申请的全部内容通过引用结合在本发明中。
技术领域
本申请属于内存管理技术领域,具体涉及一种基于ION分配器的内存分配方法、装置、电子设备和可读存储介质。
背景技术
智能终端设备的发展和普及给人们的生活和工作带来了极大的便利,随着应用占用内存的不断扩大,终端设备可用内存变得越来越低。当终端设备中的目标应用需要申请大量内存时,例如相机启动、拍照、录像等场景,对内存申请的实时性要求特别高,会发生内存申请过慢的情况。
如此,导致终端设备出现相机启动慢,拍照卡顿,录像卡顿、掉帧等问题,极大影响了用户的使用体验。
发明内容
本申请实施例的目的是提供一种基于ION分配器的内存分配方法、装置、电子设备和可读存储介质,能够解决现有大量内存申请速度慢的问题。
第一方面,本申请实施例提供了一种基于ION分配器的内存分配方法,该方法包括:
在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;
在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;
在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;
在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。
第二方面,本申请实施例提供了一种基于ION分配器的内存分配装置,该装置包括:
确定模块,用于在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;
发送模块,用于在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;
扩充模块,用于在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;
申请模块,用于在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。
第三方面,本申请实施例提供了一种电子设备,该电子设备包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如第一方面所述的方法的步骤。
第四方面,本申请实施例提供了一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如第一方面所述的方法的步骤。
第五方面,本申请实施例提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如第一方面所述的方法。
第六方面,本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如第一方面所述的方法。
在本申请实施例中,通过在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用,由此可建立底层内存分配与上层应用的通讯,支持申请大量内存的多媒体应用能够提前扩充内存,保证内存的申请速度,避免应用启动慢、操作卡顿等问题。
附图说明
图1是本申请实施例的基于ION分配器的内存分配方法的流程示意图。
图2是本申请第一实施例的基于ION分配器的内存分配方法的流程示意图。
图3是本申请第二实施例的基于ION分配器的内存分配方法的流程示意图。
图4是本申请第三实施例的基于ION分配器的内存分配方法的流程示意图。
图5是本申请第四实施例的基于ION分配器的内存分配方法的流程示意图。
图6是本申请实施例的ION内存分配器的架构示意图。
图7是本申请实施例的基于ION分配器的内存分配装置的结构方框图。
图8是本申请实施例的电子设备的结构方框图。
图9是实现本申请实施例的一种电子设备的硬件结构示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员获得的所有其他实施例,都属于本申请保护的范围。
本申请的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。
下面结合附图,通过具体的实施例及其应用场景对本申请实施例提供的基于ION分配器的内存分配方法进行详细地说明。
图1是本申请实施例的基于ION分配器的内存分配方法的流程示意图。如图1所示,本申请实施例的基于ION分配器的内存分配方法包括以下步骤102至步骤108。
步骤102,在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存。
目标应用为终端设备上安装的各种应用,尤其是启动和执行操作需要申请大量内存的应用,例如相机等多媒体应用。
可选地,在所述终端设备的用户空间确定所述目标应用所需内存,包括: 在所述目标应用为预设类型的应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存。
不同类型的应用,所需的内存大小不同。本申请实施例中,目标应用为启动和执行操作需要申请大量内存的应用。也就是说,对于需要申请大量内存的应用,可预先在终端设备的用户空间确定应用所需内存。
在目标应用启动后,如果目标应用具有多种操作场景,例如目标应用为相机,相机包括拍照场景,或者录像场景,或者延迟摄影场景等等多种操作场景,则在上层用户空间基于应用当前选择的场景,确定目标应用执行该场景操作所需的内存大小。
例如,当相机启动进入录像预览前,此时用户空间会确定此场景下录像所需的内存。4K 60帧的录像场景,一般要求每5毫秒申请16兆字节(Mbyte,MB)内存,并且需要申请的内存总量约2千兆字节(Gigabyte,GB)。
同样地,对于拍照场景,可以在相机启动进入拍照预览前,确定相机所需的内存。
对于操作场景只有一种的目标应用,则在目标应用启动后,直接计算该应用将要使用的内存使用量。对于具有多种操作场景的目标应用,先识别不同的操作场景,再计算该应用将要使用的内存使用量。
步骤104,在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存。
在上述确定目标应用所需的内存步骤之后,终端设备的上层用户空间可以下发内存扩充请求到底层的内核空间,以让内核空间提前把目标应用所需的内存准备好。
步骤106,在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令。
可选地,在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,包括:响应所述内存扩充请求,唤醒所述内核空间的目标线程;将所述目标线程绑定至所述终端设备的CPU大核;通过所述CPU大核从所述系统内存申请扩充内存,以扩充所述目标应用所需内存至所述内存池中。
在该步骤中,内核空间收到内存扩充请求之后,用于内存扩充的线程被唤醒,并且此线程被绑定CPU大核,将会从系统内存(Buddy系统)申请内存以扩充内存到ION分配器的内存池(Pool),从而以最快速度将ION分配器的内存池中的内存扩充到目标应用的使用要求。并在内存扩充完成后,向用户空间返回对应命令。
步骤108,在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。
上层用户空间在接收到内存扩充完成命令后开始申请内存,此时直接从ION分配器的内存池中拿取内存,并用于目标应用,则能够满足目标应用在需要大量内存场景的高速度与高用量的内存要求。
在一个实施例中,可选地,在所述目标应用启动的情况下,将扩充至所述内存池中的内存配置为所述目标应用的专属内存,所述专属内存为不可回收内存。
由此,可保证扩充后的内存在目标应用打开期间不能够被其他应用申请并使用,保证只有该目标应用能够使用,并且此扩充内存不会被系统内存回收掉。
通过ION分配器内存扩充功能,建立底层内存分配与上层应用的通讯,支持目标应用能够提前扩充内存,保证内存的申请速度。从而能够加速目标应用的启动速度,使得目标应用能够在最快速度下申请到内存,可以有效的减少需要快速大量使用ION内存的应用申请内存的场景下,由于内存申请慢导致的卡顿和丢帧问题。
现在参考图2,图2是本申请第一实施例的基于ION分配器的内存分配方法的流程示意图,该实施例为图1的具体示例,其中目标应用以相机为例。
如图2所示,包括以下步骤:
步骤202,上层用户空间打开相机;
步骤204,当相机进入对应的场景模式,识别不同的操作场景,例如拍照或录像场景;
步骤206,计算相机在该操作场景下所需使用的内存用量;
步骤208,上层下发携带所需内存用量的charge(内存扩充)请求到底层的内核空间;
步骤210,基于该请求通知底层的kwork内核线程进行内存扩充;
步骤212,kwork内核线程被绑定中央处理器(Central Processing Unit,CPU)大核,以加速从buddy申请内存charge内存;
步骤214,内存扩充后设置内存不被shrink(回收);
步骤216,设置扩充内存只允许相机申请使用。
可选地,在一个实施例中,该方法还包括:
在所述ION分配器存在内存释放时,监测所述终端设备的CPU卡顿时间和所述系统内存的内存申请卡顿时间;
在所述系统内存的内存申请卡顿时间大于第一阈值的情况下,直接释放所述ION分配器的内存池中的内存;
在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间大于第二阈值的情况下,直接释放所述ION分配器的内存池中的内存;
在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间小于或等于第二阈值的情况下,延时释放所述ION分配器的内存池中的内存。
目标应用申请内存的时候,卡顿时间越长说明系统压力越大,内存申请卡顿时间单位是微秒(μs)。
在该实施例中,使用压力停顿信息(Pressure Stall Information,PSI)作为指标来衡量硬件资源,例如CPU、内存和输入/输出(Input/Output,IO)的压力情况,根据系统的PSI监测CPU和内存的压力值作为压力大小的参考。
PSI量化了由于硬件资源紧张造成的任务执行中断,统计了系统中任务等待硬件资源的时间。内存申请时停顿的时间越长,说明资源面临的压力越大。
在一个实施例中,第一阈值例如为60-70毫秒(ms),第二阈值例如为60-70ms。
下面结合图3,对本申请的内存释放实施例进行示例说明。
如图3所示,包括以下步骤:
步骤302,ION分配器释放(free)内存;
步骤304,释放过程总会监测终端设备当前的系统内存压力和CPU占用情况;
步骤306,在监测到内存压力大,或者内存压力小并且CPU占用高的情况下,进入步骤308;
步骤308,会直接释放内存;
步骤310,若上层应用申请的内存来源于buddy系统,则释放内存回到buddy系统;
步骤312,若上层应用申请的内存来源于ION分配器的内存池(ion pool),则释放内存回到内存池;
步骤314,在监测到系统内存压力小,并且CPU占用低的情况下,进入步骤316;
步骤316,此时将走defer free的流程,将内存释放任务加入一个延迟释放(defer free)链表,从而在下次内存申请时去唤醒释放线程以延时释放该内存。
由此,通过采用上述实施例的不同场景的内存释放方式,可以增加对ION分配器内存的释放速度。通过识别不同的内存压力场景,可在兼顾内存释放 速度的同时减少CPU资源竞争。
可选地,在一个实施例中,该方法还包括:
监测所述ION分配器的内存池中的内存规格;
在所述内存低于预设阈值的情况下,根据所述ION分配器的内存池中内存规格,按照预设顺序申请所述系统内存向所述内存池填充内存;
其中,所述内存规格包括顺序(order)1、order2、order4及order9,所述order4和order9配置放弃内存申请标识,所述放弃内存申请标识用于告知所述ION分配器在未申请到请求规格内存的情况下,放弃内存申请。
order1、order2、order4及order9为表述内存大小的内存规格,其中内存规格对应的内存大小排序为order9>order4>order2>order1。在该实施例中,预设顺序为order9先于order4,order4先于order2,order2先于order1,也即优先申请大规格的内存,在申请不到对应的大规格连续内存后,再依次申请小规格的内存。
目标大规格内存,例如order9、order4依次申请后,剩余的系统内存为碎片化的少量内存,如果仍使用大规格内存进行申请并填充,则大部分情况下会存在内存申请失败。使用小规格的order2、order1依次申请碎片化内存,可以增加内存申请和填充成功的概率。
另外,通过为order4、order9的内存申请配置放弃内存申请标识GFP_NORETRY,则可以在大规格内存申请失败的情况下,及时切换为使用小规格内存进行申请,如此可以避免大规格内存在申请失败后仍多次去尝试申请,提高内存申请及填充的效率。
可选地,在一个实施例中,所述在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用之后,还包括:
确定向所述内存池申请用于所述目标应用的内存类型和内存规格,其中,所述内存池的内存类型包括缓冲内存和非缓冲内存;
在申请的所述内存类型为缓冲内存且所述申请的内存超出所述内存池中缓冲内存的情况下,从所述内存池中的非缓冲内存迁移目标非缓冲内存至所述缓冲内存中;
在申请的所述内存类型为非缓冲内存且所述申请的内存超出所述内存池中非缓冲内存的情况下,从所述内存池中的缓冲内存迁移目标缓冲内存至所述非缓冲内存中。
该实施例中,ION分配器的内存池中包括两种类型的内存,缓冲内存(Cache)和非缓冲内存(Uncache),申请的内存规格即申请的内存大小。
ION分配器的内存池中两种类型的内存池,缓冲内存(Cache pool)和非缓冲内存(Uncache pool)可以互通,如果上层应用申请的目标内存规格的内 存大小,超出申请的目标内存类型的内存池中的内存存量,则可以将内存池中另一内存类型的内存池中的内存迁移至目标内存类型的内存池中,以满足上层的内存申请所需的内存大小。
下面结合图4,对本申请的内存迁移实施例进行示例说明。
如图4所示,包括以下步骤:
步骤402,启动目标应用时,向ION分配器的内存池申请目标内存类型的内存,例如,缓冲内存或非缓冲内存;
步骤404,在目标内存类型为非缓冲内存时,若申请的内存规格对应的内存量很大,导致Uncache pool的内存被迅速被消耗,内存不足时,但是Cache pool中还有很多内存,此时可以将Cache pool中内存迁移加入到Uncache pool中,满足Uncache pool的申请;
步骤406,反之当Cache pool中的内存不足时,可以将Uncache pool中的内存迁移到Cache pool中。
由此,通过打通Cache pool和Uncache pool的互通,达到ION分配器内存使用的最大化,增加系统的可用内存。
可选地,在一个实施例中,该方法还包括:
在所述终端设备开机时,读取所述ION分配器的内存配置文件,所述内存配置文件用于在所述ION分配器的内存池中配置第一预留内存;
基于所述内存配置文件,从所述终端设备的系统内存填充所述第一预留内存至所述内存池中,其中,所述第一预留内存基于所述终端设备的可用内存确定。
预留内存被锁定不被释放回收,只有当系统内存压力特别大时才根据系统压力的等级释放部分或全部预留内存,当系统内存压力恢复时,将预留内存恢复到原始值。
预留内存大小可用基于终端设备开机的可用内存大小确定,例如,初始化的预留内存大小为终端设备开机的可用内存除以某个常数k,k的取值为8-10,也就是初始可以将终端设备开机的可用内存的10%左右提前预留出来。
随着终端设备的使用,不同终端设备使用的内存压力可能也不一样,可用内存大小也会不一样,所以内存池的预留内存大小需要跟据终端设备使用的具体情况做出动态的调整。
可选地,该方法还包括:监测所述终端设备的第一可用内存;基于所述第一可用内存,更新所述内存配置文件。
所述监测所述终端设备的第一可用内存,包括:以预设时间间隔统计所述终端设备在开机后预设时长内的可用内存;计算所述预定时长内的平均可用内存,得到所述终端设备的第一可用内存。
所述基于所述第一可用内存,更新所述内存配置文件,包括:获取所述内存配置文件中所述预留内存对应的所述终端设备的历史可用内存;在所述第一可用内存与所述历史可用内存的变化值大于预设阈值的情况下,基于所述第一可用内存更新所述内存配置文件中的第一预留内存。
例如,以每10-30分钟统计一次终端设备的可用内存的状态,每12小时或24小时的时长内取一次可用内存均值。以一天24小时计算一次平均可用内存为例,计算当天的平均可用内存值与前一天的平均可用内存值的变化绝对值。判断变化绝对值是否在设置的预设阈值内,如果超过预设阈值,则用当前的平均可用内存值去更新前一天的平均可用内存值,也即终端设备的可用内存,从而基于当前终端设备的可用内存,更新内存配置文件中对应的预留内存。
下次终端设备重启时则去读取最新的内存配置文件,初始化内存池预留的内存。
在另一个实施例中,还包括:
接收服务器发送的配置命令,所述配置命令携带配置的第二预留内存;
基于所述配置的第二预留内存,更新所述配置文件中的第一预留内存。
在该实施例中,为了方便及时地对内存池的大小做出调整,也可以通过服务器根据终端设备的机型内存大小等配置预留内存,下发更改内存池的内存配置文件。服务器配置的优先级要高于上述实施例基于监测终端设备的可用内存的配置,当二者的预留内存值同时存在时,先取服务器配置的预留内存大小。
可选地,所述从所述终端设备的系统内存填充所述第一预留内存至所述内存池中之后,还包括:
监测所述系统内存的内存压力;
基于所述系统内存的内存压力等级,将所述内存池中目标预留内存回收至所述系统内存;
在所述系统内存的内存压力低于预设阈值的情况下,将回收至所述系统内存的预留内存填充至所述内存池。
该实施例中,预留内存可在系统内存压力特别大时才根据系统压力的等级释放部分或全部预留内存,当系统内存压力恢复时,将预留内存恢复到原始值。
系统压力的等级越大,释放的预留内存越多,在系统出现内存用完了(Out Of Memory,OOM)之前,则释放全部预留内存,防止系统崩溃。
下面结合图5,对本申请的预留内存配置及释放的实施例进行示例说明。
如图5所示,包括以下步骤:
步骤502,在配置文件中预留内存(pool);
步骤504,手机开机启动读取配置文件;
步骤506,获取预留pool的大小;
步骤508,根据预留大小初始化ION内存分配器池内存大小(pool size);
步骤510,锁定pool的内存大小不被回收;
步骤512,大应用申请大量内存产生内存压力;
步骤514,根据压力等级释放部分内存;
步骤516,系统发射OOM前释放全部内存;
步骤518,释放内存回收到buddy系统。
步骤504中配置文件可以基于步骤520至步骤532的方式进行更新,也可以基于步骤534至步骤538的方式进行更新,具体如下:
步骤520,建立终端设备可用内存与预留pool的对应关系;
步骤522,根据用户使用习惯动态调整预留pool的大小;
步骤524,统计用户的平均可用内存水平;
步骤526,每10分钟统计一次,每天取平均值;
步骤528,当天均值与上一天均值的差值超过设定阈值;
步骤530,根据pool大小与可用内存对应关系计算pool size;
步骤532,更新pool大小的配置文件。
步骤534,服务器下发配置命令;
步骤536,下发配置pool的大小;
步骤538,根据配置命令修改手机中的pool大小的配置文件。
由此,在该实施例中,通过为ION分配器增加预留内存,可以提高目标应用的起启动速度,并且预留内存在系统内存压力大的时候能够被回收,预留内存的大小能够根据不同用户及使用习惯自适应更新,还支持服务器下发预留内存的大小配置。
在ION分配器同时具有上述各功能的情况下,对应的ION分配器的架构如图6所示,图6是本申请实施例的基于ION分配器的内存分配方法对应的ION内存分配器的架构示意图。
如图6所示,ION内存分配器可以实现以下功能:功能①内存扩充;功能②不同场景内存释放;功能③多个order申请填充;功能④不同类型内存互通;功能⑤内存预留。
在本申请实施例中,通过在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;在所述内核空间,基于所述内存扩充请求从所述系统内存扩充 所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用,由此建立底层内存分配与上层应用的通讯,支持目标应用能够提前扩充内存,保证内存的申请速度。从而能够加速目标应用的启动速度,使得目标应用能够在最快速度下申请到内存,可以有效的减少需要快速大量使用ION内存的应用申请内存的场景下,由于内存申请慢导致的卡顿和丢帧问题。
本申请实施例提供的基于ION分配器的内存分配方法,执行主体可以为基于ION分配器的内存分配装置。本申请实施例中以基于ION分配器的内存分配装置执行基于ION分配器的内存分配方法为例,说明本申请实施例提供的基于ION分配器的内存分配装置。
本申请实施例中的基于ION分配器的内存分配装置可以是电子设备,也可以是电子设备中的部件,例如集成电路、或芯片。该电子设备可以是终端,也可以为除终端之外的其他设备。示例性的,电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备、移动上网装置(Mobile Internet Device,MID)、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、机器人、可穿戴设备、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本或者个人数字助理(personal digital assistant,PDA)等,还可以为个人计算机(personal computer,PC)等,本申请实施例不作具体限定。
本申请实施例中的基于ION分配器的内存分配装置可以为具有操作系统的装置。该操作系统可以为安卓(Android)操作系统,可以为ios操作系统,还可以为其他可能的操作系统,本申请实施例不作具体限定。
本申请实施例提供的基于ION分配器的内存分配装置能够实现图1至图6的方法实施例实现的各个过程,为避免重复,这里不再赘述。
图7是本申请实施例的基于ION分配器的内存分配装置的结构方框图,参考图7,本申请实施例的基于ION分配器的内存分配装置800包括:
确定模块820,用于在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;
发送模块840,用于在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;
扩充模块860,用于在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;
申请模块880,用于在所述用户空间,在接收到所述扩充完成命令后向 所述内存池申请内存以用于所述目标应用。
可选地,确定模块820具体用于:
在所述目标应用为预设类型的应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存。
可选地,扩充模块860具体用于:
响应所述内存扩充请求,唤醒所述内核空间的目标线程;
将所述目标线程绑定至所述终端设备的CPU大核;
通过所述CPU大核从所述系统内存申请扩充内存,以扩充所述目标应用所需内存至所述内存池中。
可选地,内存分配装置800还包括:
专属内存配置模块,用于在所述目标应用启动的情况下,将扩充至所述内存池中的内存配置为所述目标应用的专属内存,所述专属内存为不可回收内存。
在本申请实施例中,通过在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用,由此建立底层内存分配与上层应用的通讯,支持目标应用能够提前扩充内存,保证内存的申请速度。从而能够加速目标应用的启动速度,使得目标应用能够在最快速度下申请到内存,可以有效的减少需要快速大量使用ION内存的应用申请内存的场景下,由于内存申请慢导致的卡顿和丢帧问题。
可选地,内存分配装置800还包括:
时间监测模块,用于在所述ION分配器存在内存释放时,监测所述终端设备的CPU卡顿时间和所述系统内存的内存申请卡顿时间;
释放模块,用于在所述系统内存的内存申请卡顿时间大于第一阈值的情况下,直接释放所述ION分配器的内存池中的内存;在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间大于第二阈值的情况下,直接释放所述ION分配器的内存池中的内存;在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间小于或等于第二阈值的情况下,延时释放所述ION分配器的内存池中的内存。
由此,通过采用上述实施例的内存释放方式,可以增加对ION分配器内存的释放速度。通过识别不同的内存压力场景,可在兼顾内存释放速度的同 时减少CPU资源竞争。
可选地,内存分配装置800还包括:
内存监测模块,用于监测所述ION分配器的内存池中的内存规格;
填充模块,用于在所述内存低于预设阈值的情况下,根据所述ION分配器的内存池中内存规格,按照预设顺序申请所述系统内存向所述内存池填充内存;
其中,所述内存规格包括order1、order2、order4及order9,所述order4和order9配置放弃内存申请标识,所述放弃内存申请标识用于告知所述ION分配器在未申请到请求规格内存的情况下,放弃内存申请。
由此,通过增加多个不同内存规格的order的填充,可以加速ION分配器的内存填充速度。
可选地,内存分配装置800还包括:
确定模块,用于在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用之后,确定向所述内存池申请用于所述目标应用的内存类型和内存规格,其中,所述内存池的内存类型包括缓冲内存和非缓冲内存;
迁移模块,用于在申请的所述内存类型为缓冲内存且所述申请的内存超出所述内存池中缓冲内存的情况下,从所述内存池中的非缓冲内存迁移目标非缓冲内存至所述缓冲内存中;在申请的所述内存类型为非缓冲内存且所述申请的内存超出所述内存池中非缓冲内存的情况下,从所述内存池中的缓冲内存迁移目标缓冲内存至所述非缓冲内存中。
由此,通过打通Cache pool和Uncache pool的互通,达到ION分配器内存使用的最大化,增加系统的可用内存。
可选地,内存分配装置800还包括:
读取模块,用于在所述终端设备开机时,读取所述ION分配器的内存配置文件,所述内存配置文件用于在所述ION分配器的内存池中配置第一预留内存;
填充模块,用于基于所述内存配置文件,从所述终端设备的系统内存填充所述第一预留内存至所述内存池中,其中,所述第一预留内存基于所述终端设备的可用内存确定。
可选地,内存分配装置800还包括:
内存监测模块,用于监测所述终端设备的第一可用内存;
第一更新模块,用于基于所述第一可用内存,更新所述内存配置文件。
可选地,所述内存监测模块,具体用于:
以预设时间间隔统计所述终端设备在开机后预设时长内的可用内存;
计算所述预定时长内的平均可用内存,得到所述终端设备的第一可用内 存;
所述第一更新模块,具体用于:
获取所述内存配置文件中所述预留内存对应的所述终端设备的历史可用内存;
在所述第一可用内存与所述历史可用内存的变化值大于预设阈值的情况下,基于所述第一可用内存更新所述内存配置文件中的第一预留内存。
可选地,内存分配装置800还包括:
接收模块,用于接收服务器发送的配置命令,所述配置命令携带配置的第二预留内存;
第二更新模块,用于基于所述配置的第二预留内存,更新所述配置文件中的第一预留内存。
可选地,内存分配装置800还包括:
压力监测模块,用于从所述终端设备的系统内存填充所述第一预留内存至所述内存池中之后,监测所述系统内存的内存压力;
回收模块,用于基于所述系统内存的内存压力等级,将所述内存池中目标预留内存回收至所述系统内存;
填充模块,用于在所述系统内存的内存压力低于预设阈值的情况下,将回收至所述系统内存的预留内存填充至所述内存池。
由此,通过为ION分配器增加预留内存,可以提高目标应用的起启动速度,并且预留内存在系统内存压力大的时候能够被回收,预留内存的大小能够根据不同用户及使用习惯自适应更新,还支持服务器下发预留内存的大小配置。
可选地,如图8所示,本申请实施例还提供一种电子设备900,包括处理器940和存储器920,存储器920上存储有可在所述处理器940上运行的程序或指令,该程序或指令被处理器940执行时实现上述内存分配方法实施例的各个步骤,且能达到相同的技术效果,为避免重复,这里不再赘述。
需要说明的是,本申请实施例中的电子设备包括上述的移动电子设备和非移动电子设备。
图9为实现本申请实施例的一种电子设备的硬件结构示意图。
该电子设备1000包括但不限于:射频单元1001、网络模块1002、音频输出单元1003、输入单元1004、传感器1005、显示单元1006、用户输入单元1007、接口单元1008、存储器1009、以及处理器1010等部件。
本领域技术人员可以理解,电子设备1000还可以包括给各个部件供电的电源(比如电池),电源可以通过电源管理系统与处理器1010逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。图x中示 出的电子设备结构并不构成对电子设备的限定,电子设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置,在此不再赘述。
其中,处理器1010,用于在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。
可选地,处理器1010,还用于:在所述目标应用为预设类型的应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存。
可选地,处理器1010,还用于:响应所述内存扩充请求,唤醒所述内核空间的目标线程;将所述目标线程绑定至所述终端设备的CPU大核;通过所述CPU大核从所述系统内存申请扩充内存,以扩充所述目标应用所需内存至所述内存池中。
可选地,处理器1010,还用于:在所述目标应用启动的情况下,将扩充至所述内存池中的内存配置为所述目标应用的专属内存,所述专属内存为不可回收内存。
可选地,处理器1010,还用于:在所述ION分配器存在内存释放时,监测所述终端设备的CPU卡顿时间和所述系统内存的内存申请卡顿时间;在所述系统内存的内存申请卡顿时间大于第一阈值的情况下,直接释放所述ION分配器的内存池中的内存;在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间大于第二阈值的情况下,直接释放所述ION分配器的内存池中的内存;在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间小于或等于第二阈值的情况下,延时释放所述ION分配器的内存池中的内存。
可选地,处理器1010,还用于:监测所述ION分配器的内存池中的内存规格;在所述内存低于预设阈值的情况下,根据所述ION分配器的内存池中内存规格,按照预设顺序申请所述系统内存向所述内存池填充内存;其中,所述内存规格包括order1、order2、order4及order9,所述order4和order9配置放弃内存申请标识,所述放弃内存申请标识用于告知所述ION分配器在未申请到请求规格内存的情况下,放弃内存申请。
可选地,处理器1010,还用于:在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用之后,确定向所述内存池申请用于所述目标应用的内存类型和内存规格,其中,所述内存池的内存类型包括缓冲内存 和非缓冲内存;在申请的所述内存类型为缓冲内存且所述申请的内存超出所述内存池中缓冲内存的情况下,从所述内存池中的非缓冲内存迁移目标非缓冲内存至所述缓冲内存中;在申请的所述内存类型为非缓冲内存且所述申请的内存超出所述内存池中非缓冲内存的情况下,从所述内存池中的缓冲内存迁移目标缓冲内存至所述非缓冲内存中。
可选地,处理器1010,还用于:在所述终端设备开机时,读取所述ION分配器的内存配置文件,所述内存配置文件用于在所述ION分配器的内存池中配置第一预留内存;基于所述内存配置文件,从所述终端设备的系统内存填充所述第一预留内存至所述内存池中,其中,所述第一预留内存基于所述终端设备的可用内存确定。
可选地,处理器1010,还用于:监测所述终端设备的第一可用内存;基于所述第一可用内存,更新所述内存配置文件。
可选地,处理器1010,还用于:以预设时间间隔统计所述终端设备在开机后预设时长内的可用内存;计算所述预定时长内的平均可用内存,得到所述终端设备的第一可用内存;获取所述内存配置文件中所述预留内存对应的所述终端设备的历史可用内存;在所述第一可用内存与所述历史可用内存的变化值大于预设阈值的情况下,基于所述第一可用内存更新所述内存配置文件中的第一预留内存。
可选地,输入单元1004用于:接收服务器发送的配置命令,所述配置命令携带配置的第二预留内存。
处理器1010,还用于:基于所述配置的第二预留内存,更新所述配置文件中的第一预留内存。
可选地,处理器1010,还用于:从所述终端设备的系统内存填充所述第一预留内存至所述内存池中之后,监测所述系统内存的内存压力;基于所述系统内存的内存压力等级,将所述内存池中目标预留内存回收至所述系统内存;在所述系统内存的内存压力低于预设阈值的情况下,将回收至所述系统内存的预留内存填充至所述内存池。
在本申请实施例中,通过在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用,由此建立底层内存分配与上层应用的通讯,支持目标应用能够提前扩充内存,保证内存的申请速度。从而 能够加速目标应用的启动速度,使得目标应用能够在最快速度下申请到内存,可以有效的减少需要快速大量使用ION内存的应用申请内存的场景下,由于内存申请慢导致的卡顿和丢帧问题。
应理解的是,本申请实施例中,输入单元1004可以包括图形处理器(Graphics Processing Unit,GPU)10041和麦克风10042,GPU10041对在视频捕获模式或图像捕获模式中由图像捕获装置(如摄像头)获得的静态图片或视频的图像数据进行处理。显示单元1006可包括显示面板10061,可以采用液晶显示器、有机发光二极管等形式来配置显示面板10061。用户输入单元1007包括触控面板10071以及其他输入设备10072中的至少一种。触控面板10071,也称为触摸屏。触控面板10071可包括触摸检测装置和触摸控制器两个部分。其他输入设备10072可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆,在此不再赘述。
存储器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包括但不限于这些和任意其它适合类型的存储器。
处理器1010可包括一个或多个处理单元;可选的,处理器1010集成应用处理器和调制解调处理器,其中,应用处理器主要处理涉及操作系统、用户界面和应用程序等的操作,调制解调处理器主要处理无线通信信号,如基带处理器。可以理解的是,上述调制解调处理器也可以不集成到处理器1010中。
本申请实施例还提供一种可读存储介质,所述可读存储介质上存储有程序或指令,该程序或指令被处理器执行时实现上述基于ION分配器的内存分 配方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
其中,所述处理器为上述实施例中所述的电子设备中的处理器。所述可读存储介质,包括计算机可读存储介质,如计算机只读存储器ROM、随机存取存储器RAM、磁碟或者光盘等。
本申请实施例另提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现上述基于ION分配器的内存分配方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
应理解,本申请实施例提到的芯片还可以称为系统级芯片、系统芯片、芯片系统或片上系统芯片等。
本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如上述基于ION分配器的内存分配方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。此外,需要指出的是,本申请实施方式中的方法和装置的范围不限按示出或讨论的顺序来执行功能,还可包括根据所涉及的功能按基本同时的方式或按相反的顺序来执行功能,例如,可以按不同于所描述的次序来执行所描述的方法,并且还可以添加、省去、或组合各种步骤。另外,参照某些示例所描述的特征可在其他示例中被组合。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以计算机软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求 所保护的范围情况下,还可做出很多形式,均属于本申请的保护之内。

Claims (17)

  1. 一种基于ION分配器的内存分配方法,其中,包括:
    在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;
    在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;
    在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;
    在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。
  2. 根据权利要求1所述的方法,其中,在所述终端设备的用户空间确定所述目标应用所需内存,包括:
    在所述目标应用为预设类型的应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存。
  3. 根据权利要求1所述的方法,其中,在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,包括:
    响应所述内存扩充请求,唤醒所述内核空间的目标线程;
    将所述目标线程绑定至所述终端设备的CPU大核;
    通过所述CPU大核从所述系统内存申请扩充内存,以扩充所述目标应用所需内存至所述内存池中。
  4. 根据权利要求1所述的方法,其中,还包括:
    在所述目标应用启动的情况下,将扩充至所述内存池中的内存配置为所述目标应用的专属内存,所述专属内存为不可回收内存。
  5. 根据权利要求1所述的方法,其中,还包括:
    在所述ION分配器存在内存释放时,监测所述终端设备的CPU卡顿时间和所述系统内存的内存申请卡顿时间;
    在所述系统内存的内存申请卡顿时间大于第一阈值的情况下,直接释放所述ION分配器的内存池中的内存;
    在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU卡顿时间大于第二阈值的情况下,直接释放所述ION分配器的内存池中的内存;
    在所述系统内存的内存申请卡顿时间小于或等于第一阈值且所述CPU 卡顿时间小于或等于第二阈值的情况下,延时释放所述ION分配器的内存池中的内存。
  6. 根据权利要求1所述的方法,其中,还包括:
    监测所述ION分配器的内存池中的内存规格;
    在所述内存低于预设阈值的情况下,根据所述ION分配器的内存池中内存规格,按照预设顺序申请所述系统内存向所述内存池填充内存;
    其中,所述内存规格包括order1、order2、order4及order9,所述order4和order9配置放弃内存申请标识,所述放弃内存申请标识用于告知所述ION分配器在未申请到请求规格内存的情况下,放弃内存申请。
  7. 根据权利要求1所述的方法,其中,所述在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用之后,还包括:
    确定向所述内存池申请用于所述目标应用的内存类型和内存规格,其中,所述内存池的内存类型包括缓冲内存和非缓冲内存;
    在申请的所述内存类型为缓冲内存且所述申请的内存超出所述内存池中缓冲内存的情况下,从所述内存池中的非缓冲内存迁移目标非缓冲内存至所述缓冲内存中;
    在申请的所述内存类型为非缓冲内存且所述申请的内存超出所述内存池中非缓冲内存的情况下,从所述内存池中的缓冲内存迁移目标缓冲内存至所述非缓冲内存中。
  8. 根据权利要求1所述的方法,其中,还包括:
    在所述终端设备开机时,读取所述ION分配器的内存配置文件,所述内存配置文件用于在所述ION分配器的内存池中配置第一预留内存;
    基于所述内存配置文件,从所述终端设备的系统内存填充所述第一预留内存至所述内存池中,其中,所述第一预留内存基于所述终端设备的可用内存确定。
  9. 根据权利要求8所述的方法,其中,还包括:
    监测所述终端设备的第一可用内存;
    基于所述第一可用内存,更新所述内存配置文件。
  10. 根据权利要求9所述的方法,其中,所述监测所述终端设备的第一可用内存,包括:
    以预设时间间隔统计所述终端设备在开机后预设时长内的可用内存;
    计算所述预定时长内的平均可用内存,得到所述终端设备的第一可用内存;
    所述基于所述第一可用内存,更新所述内存配置文件,包括:
    获取所述内存配置文件中所述预留内存对应的所述终端设备的历史可用 内存;
    在所述第一可用内存与所述历史可用内存的变化值大于预设阈值的情况下,基于所述第一可用内存更新所述内存配置文件中的第一预留内存。
  11. 根据权利要求8所述的方法,其中,还包括:
    接收服务器发送的配置命令,所述配置命令携带配置的第二预留内存;
    基于所述配置的第二预留内存,更新所述配置文件中的第一预留内存。
  12. 根据权利要求8所述的方法,其中,所述从所述终端设备的系统内存填充所述第一预留内存至所述内存池中之后,还包括:
    监测所述系统内存的内存压力;
    基于所述系统内存的内存压力等级,将所述内存池中目标预留内存回收至所述系统内存;
    在所述系统内存的内存压力低于预设阈值的情况下,将回收至所述系统内存的预留内存填充至所述内存池。
  13. 一种基于ION分配器的内存分配装置,其中,包括:
    确定模块,用于在终端设备启动目标应用的情况下,在所述终端设备的用户空间确定所述目标应用所需内存;
    发送模块,用于在所述用户空间,向所述终端设备的内核空间发送内存扩充请求,所述内存扩充请求中包括所述目标应用所需内存;
    扩充模块,用于在所述内核空间,基于所述内存扩充请求从所述系统内存扩充所述目标应用所需内存至所述终端设备ION分配器的内存池中,并向所述用户空间返回扩充完成命令;
    申请模块,用于在所述用户空间,在接收到所述扩充完成命令后向所述内存池申请内存以用于所述目标应用。
  14. 一种电子设备,其中,包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如权利要求1-12中任一项所述的内存分配方法的步骤。
  15. 一种可读存储介质,其中,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如权利要求1-12中任一项所述的内存分配方法的步骤。
  16. 一种芯片,其中,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如权利要求1-12中任一项所述的内存分配方法。
  17. 一种计算机程序产品,其中,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如权利要求1-12中任一项所述的内存分配方法。
PCT/CN2023/098499 2022-06-10 2023-06-06 基于ion分配器的内存分配方法、装置、电子设备和可读存储介质 WO2023236930A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210655016.0A CN114996014A (zh) 2022-06-10 2022-06-10 基于ion分配器的内存分配方法、装置和电子设备
CN202210655016.0 2022-06-10

Publications (1)

Publication Number Publication Date
WO2023236930A1 true WO2023236930A1 (zh) 2023-12-14

Family

ID=83033988

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/098499 WO2023236930A1 (zh) 2022-06-10 2023-06-06 基于ion分配器的内存分配方法、装置、电子设备和可读存储介质

Country Status (2)

Country Link
CN (1) CN114996014A (zh)
WO (1) WO2023236930A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114996014A (zh) * 2022-06-10 2022-09-02 维沃移动通信有限公司 基于ion分配器的内存分配方法、装置和电子设备

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105427236A (zh) * 2015-12-18 2016-03-23 魅族科技(中国)有限公司 一种图像渲染方法及装置
CN109213596A (zh) * 2018-08-01 2019-01-15 青岛海信移动通信技术股份有限公司 一种分配终端内存的方法和设备
CN111143072A (zh) * 2019-12-29 2020-05-12 浪潮(北京)电子信息产业有限公司 用户态程序内存分配方法、系统及相关组件
CN114116215A (zh) * 2021-11-19 2022-03-01 北京小米移动软件有限公司 内存管理方法、装置、电子设备及存储介质
CN114518962A (zh) * 2022-04-15 2022-05-20 北京奥星贝斯科技有限公司 内存的管理方法及装置
CN114996014A (zh) * 2022-06-10 2022-09-02 维沃移动通信有限公司 基于ion分配器的内存分配方法、装置和电子设备

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105427236A (zh) * 2015-12-18 2016-03-23 魅族科技(中国)有限公司 一种图像渲染方法及装置
CN109213596A (zh) * 2018-08-01 2019-01-15 青岛海信移动通信技术股份有限公司 一种分配终端内存的方法和设备
CN111143072A (zh) * 2019-12-29 2020-05-12 浪潮(北京)电子信息产业有限公司 用户态程序内存分配方法、系统及相关组件
CN114116215A (zh) * 2021-11-19 2022-03-01 北京小米移动软件有限公司 内存管理方法、装置、电子设备及存储介质
CN114518962A (zh) * 2022-04-15 2022-05-20 北京奥星贝斯科技有限公司 内存的管理方法及装置
CN114996014A (zh) * 2022-06-10 2022-09-02 维沃移动通信有限公司 基于ion分配器的内存分配方法、装置和电子设备

Also Published As

Publication number Publication date
CN114996014A (zh) 2022-09-02

Similar Documents

Publication Publication Date Title
US11531625B2 (en) Memory management method and apparatus
WO2022089452A1 (zh) 内存管理方法、装置、电子设备以及计算机可读存储介质
WO2018059027A1 (zh) 一种内存回收方法及终端
US20070101325A1 (en) System and method for utilizing a remote memory to perform an interface save/restore procedure
WO2023236930A1 (zh) 基于ion分配器的内存分配方法、装置、电子设备和可读存储介质
WO2019137252A1 (zh) 内存处理方法、电子设备、计算机可读存储介质
US20140149984A1 (en) Information processing apparatus, information processing method, and computer readable medium
WO2022156600A1 (zh) 缓冲区容量的调整方法、装置、电子设备及可读存储介质
CN113590501A (zh) 一种数据存储方法及相关设备
EP4328705A1 (en) Storage space arrangement method and electronic device
US20190227918A1 (en) Method for allocating memory resources, chip and non-transitory readable medium
CN115509953A (zh) 内存回收方法及其装置
CN112231238A (zh) 使用存储器压缩来减少存储器提交开销
WO2021047398A1 (zh) 存储块回收方法、装置、存储介质及电子设备
EP4044015A1 (en) Data processing method and apparatus
WO2023246638A1 (zh) 信息处理方法、装置、可穿戴设备和电子设备
CN107209738B (zh) 储存存储器直接访问
CA2848683C (en) Working set adjustment in a managed environment
CN111103960B (zh) 一种Nvme SSD及其复位方法和系统
CN114564315A (zh) 内存分配方法、装置、电子设备及介质
CN111078405B (zh) 内存分配方法、装置、存储介质及电子设备
WO2019071616A1 (zh) 一种处理方法及装置
CN112162704A (zh) 存储空间释放方法及其装置
CN113268437A (zh) 一种主动触发内存整理的方法与设备
CN113485642A (zh) 数据缓存方法及装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23819095

Country of ref document: EP

Kind code of ref document: A1