Memory Allocation Method, Device and Electronic Device Based on ION Allocator
By using the ION allocator-based memory allocation method in smart terminal devices, memory is expanded in advance to solve the problem of slow memory application speed, and the effect of improving application startup speed and reducing lag is achieved.
Patent Information
- Application Number
- CN202210655016.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-10
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2042-06-10
AI Technical Summary
When a smart terminal device needs to apply for a large amount of memory when the target application requires a slow memory application, resulting in slow device startup, lag in photography, lag in recording, and frame drops, affecting the user experience.
The memory allocation method based on the ION allocator is adopted. By determining the memory required by the target application in the user space of the terminal device, and expanding memory from the system memory to the memory pool of the ION allocator in the kernel space, the target application is supported to expand memory in advance to ensure the speed of memory application.
By expanding memory in advance, the problem of slow memory application speed is solved, the startup speed of the target application is improved, the lag and frame loss problems caused by slow memory application is reduced, and the user experience is improved.
Smart Images

Figure CN114996014B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of memory management, and particularly relates to a memory allocation method, device, electronic device, and readable storage medium based on an ION allocator. Background Art
[0002] The development and popularization of intelligent terminal devices have brought great convenience to people's lives and work. As the memory occupied by applications continues to expand, the available memory of terminal devices becomes lower and lower. When a target application in a terminal device needs to apply for a large amount of memory, such as in scenarios like camera startup, taking pictures, and recording videos, the real-time requirement for memory application is particularly high, and the situation of slow memory application may occur.
[0003] As a result, problems such as slow camera startup, stuttering during picture taking, stuttering and frame dropping during video recording occur in the terminal device, greatly affecting the user experience. Summary of the Invention
[0004] 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 problem of slow speed of a large amount of existing memory applications.
[0005] In a first aspect, the embodiments of this application provide a memory allocation method based on an ION allocator, and the method includes:
[0006] When starting a target application on a terminal device, determine the memory required by the target application in the user space of the terminal device;
[0007] 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;
[0008] 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 ION allocator of the terminal device, and return an expansion completion command to the user space;
[0009] In the user space, after receiving the expansion completion command, apply for memory from the memory pool for the target application.
[0010] In a second aspect, the embodiments of this application provide a memory allocation device based on an ION allocator, and the device includes:
[0011] A determination module, configured to determine the memory required by the target application in the user space of the terminal device when starting a target application on the terminal device;
[0012] A sending module, configured to send a memory expansion request including the memory required by the target application to the kernel space of the terminal device in the user space;
[0013] An expansion module, configured to expand the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device in the kernel space based on the memory expansion request, and return an expansion completion command to the user space;
[0014] An application module, configured to apply for memory from the memory pool for the target application in the user space after receiving the expansion completion command.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory. The memory stores a program or instruction that can run on the processor. When the program or instruction is executed by the processor, the steps of the method described in the first aspect are implemented.
[0016] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.
[0017] In a fifth aspect, an embodiment of the present application provides a chip, which 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 instruction to implement the method described in the first aspect.
[0018] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the method described in the first aspect.
[0019] In the embodiment of the present application, when starting a target application on a terminal device, the memory required by the target application is determined in the user space of the terminal device; in the user space, a memory expansion request including the memory required by the target application is sent to the kernel space of the terminal device; in the kernel space, the memory required by the target application is expanded from the system memory to the memory pool of the ION allocator of the terminal device based on the memory expansion request, and an expansion completion command is returned to the user space; in the user space, after receiving the expansion completion command, memory is applied for from the memory pool for the target application. Thus, communication between underlying memory allocation and upper-layer applications can be established, enabling multimedia applications that require a large amount of memory to expand memory in advance, ensuring the memory application speed, and avoiding problems such as slow application startup and operation lag. Description of the Drawings
[0020] Figure 1 It is a schematic flowchart of the memory allocation method based on the ION allocator according to an embodiment of the present application.
[0021] Figure 2 It is a schematic flowchart of the memory allocation method based on the ION allocator according to the first embodiment of the present application.
[0022] Figure 3 It is a schematic flowchart of the memory allocation method based on the ION allocator according to the second embodiment of the present application.
[0023] Figure 4 It is a schematic flowchart of the memory allocation method based on the ION allocator according to the third embodiment of the present application.
[0024] Figure 5 It is a schematic flowchart of the memory allocation method based on the ION allocator according to the fourth embodiment of the present application.
[0025] Figure 6 It is a schematic architecture diagram of the ION memory allocator according to an embodiment of the present application.
[0026] Figure 7 It is a structural block diagram of the memory allocation device based on the ION allocator according to an embodiment of the present application.
[0027] Figure 8 It is a structural block diagram of the electronic device according to an embodiment of the present application.
[0028] Figure 9 It is a schematic hardware structure diagram of an electronic device for implementing an embodiment of the present application. Detailed implementation manners
[0029] Next, the technical solutions in the embodiments of the present application will be clearly described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some, but not all, of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art belong to the scope of protection of the present application.
[0030] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are usually of the same category, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / " generally represents an "or" relationship between the associated objects before and after.
[0031] The following will combine the accompanying drawings and, through specific embodiments and their application scenarios, elaborate in detail on the memory allocation method based on the ION allocator provided by the embodiments of the present application.
[0032] Figure 1 It is a schematic flowchart of the memory allocation method based on the ION allocator according to the embodiments of the present application. As Figure 1 shown, the memory allocation method based on the ION allocator according to the embodiments of the present application includes the following steps 102 to 108.
[0033] Step 102, when the target application is started on the terminal device, determine the memory required by the target application in the user space of the terminal device.
[0034] The target application is various applications installed on the terminal device, especially applications that require a large amount of memory for startup and execution operations, such as multimedia applications like cameras.
[0035] Optionally, determining the memory required by the target application in the user space of the terminal device includes: when the target application is an application of a preset type, determine the memory required by the target application in the user space of the terminal device.
[0036] Applications of different types require different amounts of memory. In the embodiments of the present application, the target application is an application that requires a large amount of memory for startup and execution operations. That is to say, for applications that require a large amount of memory, the memory required by the application can be determined in advance in the user space of the terminal device.
[0037] 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 a photo-taking scenario, a video-recording scenario, or a time-lapse photography scenario, etc., then in the upper-layer user space, based on the scenario currently selected by the application, determine the memory size required for the target application to execute the operation of this scenario.
[0038] For example, when the camera starts and enters the video recording preview, at this time, the user space will determine the memory required for video recording in this scenario. For a 4K 60-frame video recording scenario, generally, 16MB of memory needs to be applied every 5 milliseconds, and the total amount of memory required is about 2GB.
[0039] Similarly, for the photo-taking scenario, the memory required by the camera can be determined before the camera starts and enters the photo-taking preview.
[0040] For a target application with only one operation scenario, after the target application is started, directly calculate the memory usage amount that the application will use. For a target application with multiple operation scenarios, first identify different operation scenarios, and then calculate the memory usage amount that the application will use.
[0041] Step 104: In the user space, send a memory expansion request to the kernel space of the terminal device. The memory expansion request includes the memory required by the target application.
[0042] After the step of determining the memory required by the target application, the upper-layer user space of the terminal device can send 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.
[0043] Step 106: In the kernel space, expand the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device based on the memory expansion request, and return an expansion completion command to the user space.
[0044] Optionally, in the kernel space, expanding the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device includes: in response to the memory expansion request, wake up the target thread in the kernel space; bind the target thread to the large CPU core of the terminal device; apply for expanded memory from the system memory through the large CPU core to expand the memory required by the target application to the memory pool.
[0045] In this step, after the kernel space receives the memory expansion request, the thread for memory expansion is awakened, and this thread is bound to the large CPU core. It will apply for memory from the system memory (Buddy system) to expand the memory to the memory pool of the ION allocator (Pool), so as to expand the memory in the memory pool of the ION allocator to meet the usage requirements of the target application at the fastest speed. After the memory expansion is completed, a corresponding command is returned to the user space.
[0046] Step 108: In the user space, apply for memory from the memory pool after receiving the expansion completion command for the target application.
[0047] After the upper-layer user space receives the memory expansion completion command, it starts to apply for memory. At this time, it directly takes the memory from the memory pool of the ION allocator and uses it for the target application, which can meet the high-speed and high-usage memory requirements of the target application in scenarios where a large amount of memory is needed.
[0048] In one embodiment, optionally, when the target application is started, the memory expanded to the memory pool is configured as the exclusive memory of the target application, and the exclusive memory is non-reclaimable memory.
[0049] Thus, it can be ensured that the expanded memory cannot be applied for and used by other applications during the opening of the target application, ensuring that only the target application can use it, and this expanded memory will not be reclaimed by the system memory.
[0050] Through the ION allocator memory expansion function, communication between the underlying memory allocation and the upper-layer application is established, enabling the target application to expand memory in advance and ensuring the memory application speed. This can accelerate the startup speed of the target application, allowing the target application to apply for memory at the fastest speed, and effectively reducing the lag and frame drop problems caused by slow memory application in scenarios where applications that require rapid and large-scale use of ION memory apply for memory.
[0051] Now refer to Figure 2 , Figure 2 which is a schematic flowchart of the memory allocation method based on the ION allocator in the first embodiment of this application. This embodiment is Figure 1 a specific example of
[0052] As Figure 2 shown, it includes the following steps:
[0053] Step 202, the upper-layer user space opens the camera;
[0054] Step 204, when the camera enters the corresponding scene mode, different operation scenarios are recognized, such as the photo-taking or video-recording scenario;
[0055] Step 206, calculate the amount of memory required for the camera to use in this operation scenario;
[0056] Step 208, the upper layer sends a charge (memory expansion) request carrying the required amount of memory to the underlying kernel space;
[0057] Step 210, based on this request, notify the underlying kwork kernel thread to expand memory;
[0058] Step 212, the kwork kernel thread is bound to the CPU big core to accelerate the application for memory charge from the buddy;
[0059] Step 214, after memory expansion, set the memory not to be shrunk (reclaimed);
[0060] Step 216, set the expanded memory to be only available for the camera to apply for use.
[0061] Optionally, in one embodiment, the method further includes:
[0062] When there is memory release in the ION allocator, monitor the CPU lag time of the terminal device and the memory application lag time of the system memory;
[0063] When the memory application lag time of the system memory is greater than the first threshold, directly release the memory in the memory pool of the ION allocator;
[0064] When the memory application stuttering time of the system memory is less than or equal to the first threshold and the CPU stuttering time is greater than the second threshold, directly release the memory in the memory pool of the ION allocator;
[0065] When the memory application stuttering time of the system memory is less than or equal to the first threshold and the CPU stuttering time is less than or equal to the second threshold, delay the release of the memory in the memory pool of the ION allocator.
[0066] When the target application applies for memory, the longer the stuttering time, the greater the system pressure. The unit of the memory application stuttering time is μs.
[0067] In this embodiment, Pressure Stall Information (PSI) is used as an indicator to measure the pressure of hardware resources such as CPU, memory, and IO, and the pressure values of the CPU and memory are monitored according to the PSI of the system as a reference for the pressure level.
[0068] PSI quantifies the interruption of task execution caused by hardware resource tension and counts the time that tasks in the system wait for hardware resources. The longer the pause time during memory application, the greater the pressure on the resources.
[0069] In one embodiment, the first threshold is, for example, 60 - 70 ms, and the second threshold is, for example, 60 - 70 ms.
[0070] Next, in combination with Figure 3 , an example of the memory release embodiment of this application will be described.
[0071] As Figure 3 shown, it includes the following steps:
[0072] Step 302, the ION allocator releases the memory;
[0073] Step 304, the release process always monitors the current system memory pressure and CPU occupancy of the terminal device;
[0074] Step 306, when it is detected that the memory pressure is high, or the memory pressure is low and the CPU occupancy is high, enter step 308;
[0075] Step 308, directly release the memory;
[0076] Step 310, if the memory applied for by the upper-layer application comes from the buddy system, release the memory back to the buddy system;
[0077] Step 312: If the memory applied for by the upper-layer application is from the memory pool (ion pool) of the ION allocator, release the memory back to the memory pool.
[0078] Step 314: When it is detected that the system memory pressure is low and the CPU occupancy is low, proceed to Step 316.
[0079] Step 316: At this time, the defer free process will be followed, adding the memory release task to a defer free linked list, so as to wake up the release thread during the next memory application to defer the release of the memory.
[0080] Thus, by adopting the memory release methods in different scenarios of the above embodiments, the release speed of the memory of the ION allocator can be increased. By identifying different memory pressure scenarios, CPU resource competition can be reduced while taking into account the memory release speed.
[0081] Optionally, in one embodiment, the method further includes:
[0082] Monitoring the memory specifications in the memory pool of the ION allocator;
[0083] When the memory is lower than a preset threshold, according to the memory specifications in the memory pool of the ION allocator, apply for the system memory to fill the memory pool in a preset order;
[0084] Wherein, the memory specifications include order1, order2, order4, and order9, and the order4 and order9 are configured with a memory application abandonment flag, and the memory application abandonment flag is used to inform the ION allocator to abandon the memory application when the requested specification memory cannot be applied for.
[0085] order1, order2, order4, and order9 are memory specifications representing the memory size, and the memory sizes corresponding to the memory specifications are sorted as order9 > order4 > order2 > order1. In this embodiment, the preset order is that order9 is prior to order4, order4 is prior to order2, and order2 is prior to order1, that is, large-specification memory is preferentially applied for. After the corresponding large-specification continuous memory cannot be applied for, small-specification memory is sequentially applied for.
[0086] After the target large-specification memory, such as order9 and order4, are sequentially applied for, the remaining system memory is a small amount of fragmented memory. If large-specification memory is still used for application and filling, memory application failure will occur in most cases. Applying for fragmented memory sequentially with small-specification order2 and order1 can increase the probability of successful memory application and filling.
[0087] In addition, by configuring the memory application abandonment flag GFP_NORETRY for the memory applications of order4 and order9, it is possible to promptly switch to using small-sized memory for application in case of failure in large-sized memory application, thus avoiding multiple attempts to apply for large-sized memory after application failure and improving the efficiency of memory application and filling.
[0088] Optionally, in one embodiment, after applying for memory from the memory pool for the target application after receiving the expansion completion command, the following is further included:
[0089] Determine the memory type and memory specification for the target application to be applied for from the memory pool, where the memory types in the memory pool include buffered memory and unbuffered memory;
[0090] When the applied memory type is buffered memory and the applied memory exceeds the buffered memory in the memory pool, migrate the target unbuffered memory from the unbuffered memory in the memory pool to the buffered memory;
[0091] When the applied memory type is unbuffered memory and the applied memory exceeds the unbuffered memory in the memory pool, migrate the target buffered memory from the buffered memory in the memory pool to the unbuffered memory.
[0092] In this embodiment, the memory pool of the ION allocator includes two types of memory, buffered memory (Cache) and unbuffered memory (Uncache), and the applied memory specification is the size of the applied memory.
[0093] The two types of memory pools in the memory pool of the ION allocator, the buffered memory pool (Cache pool) and the unbuffered memory pool (Uncache pool), can communicate with each other. If the size of the memory of the target memory specification applied by the upper-layer application exceeds the memory stock in the memory pool of the applied target memory type, the memory in the memory pool of the other memory type in the memory pool can be migrated to the memory pool of the target memory type to meet the memory size required for the upper-layer memory application.
[0094] The following combines Figure 4 , and gives an example illustration of the memory migration embodiment of the present application.
[0095] As Figure 4 shown, it includes the following steps:
[0096] 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, buffered memory or unbuffered memory;
[0097] Step 404, when the target memory type is non-buffered memory, if the memory amount corresponding to the applied memory specification is very large, causing the memory in the Uncache pool to be quickly consumed and memory shortage occurs, but there is still a lot of memory in the Cache pool, at this time, the memory in the Cache pool can be migrated and added to the Uncache pool to meet the application of the Uncache pool;
[0098] 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.
[0099] Thus, by opening up the interconnection between the Cache pool and the Uncache pool, the maximum utilization of the ION allocator's memory is achieved, increasing the available memory of the system.
[0100] Optionally, in one embodiment, the method further includes:
[0101] When the terminal device is powered on, read the memory configuration file of the ION allocator, where the memory configuration file is used to configure the first reserved memory in the memory pool of the ION allocator;
[0102] Based on the memory configuration file, fill the first reserved memory from the system memory of the terminal device into the memory pool, where the first reserved memory is determined based on the available memory of the terminal device.
[0103] The reserved memory is locked and not released or recycled. Only when the system memory pressure is extremely high, some or all of the reserved memory is released according to the level of the system pressure. When the system memory pressure recovers, the reserved memory is restored to its original value.
[0104] The size of the reserved memory can be determined based on the available memory size when the terminal device is powered on. For example, the initialized size of the reserved memory is the available memory when the terminal device is powered on divided by a constant k, and the value of k is 8 - 10, that is, initially about 10% of the available memory when the terminal device is powered on can be reserved in advance.
[0105] As the terminal device is used, the memory pressure of different terminal devices may be different, and the available memory size will also be different. Therefore, the size of the reserved memory in the memory pool needs to be dynamically adjusted according to the specific situation of the terminal device's use.
[0106] Optionally, the method further includes: monitoring the first available memory of the terminal device; based on the first available memory, updating the memory configuration file.
[0107] Monitoring the first available memory of the terminal device includes: counting the available memory of the terminal device within a preset duration after startup at a preset time interval; calculating the average available memory within the preset duration to obtain the first available memory of the terminal device.
[0108] Updating 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; when the change value between the first available memory and the historical available memory is greater than a preset threshold, updating the first reserved memory in the memory configuration file based on the first available memory.
[0109] For example, the status of the available memory of the terminal device is counted every 10 - 30 minutes, and the average value of the available memory is taken within a duration of every 12 hours or 24 hours. Taking the calculation of the average available memory once every 24 hours in a day as an example, calculate the absolute value of the change between the average available memory value of the current 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 as to update the corresponding reserved memory in the memory configuration file based on the current available memory of the terminal device.
[0110] When the terminal device is restarted next time, it reads the latest memory configuration file and initializes the memory reserved in the memory pool.
[0111] In another embodiment, it further includes:
[0112] Receiving a configuration command sent by the server, the configuration command carrying the configured second reserved memory;
[0113] Updating the first reserved memory in the configuration file based on the configured second reserved memory.
[0114] In this embodiment, in order to facilitate timely adjustment of the size of the memory pool, the server can also configure the reserved memory according to the memory size of the terminal device model, etc., and issue a memory configuration file for changing the memory pool. The priority of the server configuration is higher than the configuration based on monitoring the available memory of the terminal device in the above embodiment. When the reserved memory values of both exist, the size of the reserved memory configured by the server is taken first.
[0115] Optionally, after filling the first reserved memory from the system memory of the terminal device into the memory pool, it further includes:
[0116] Monitoring the memory pressure of the system memory;
[0117] Recover the target reserved memory in the memory pool to the system memory based on the memory pressure level of the system memory;
[0118] When the memory pressure of the system memory is lower than a preset threshold, fill the reserved memory recovered to the system memory into the memory pool.
[0119] In this embodiment, the reserved memory can release part or all of the reserved memory according to the level of system pressure only when the system memory pressure is extremely high. When the system memory pressure is restored, the reserved memory is restored to the original value.
[0120] The greater the level of system pressure, the more reserved memory is released. Before the system runs out of memory (Out Of Memory, OOM), all reserved memory is released to prevent the system from crashing.
[0121] The following combines Figure 5 , and gives an example of the embodiment of the reserved memory configuration and release of this application.
[0122] As Figure 5 shown, it includes the following steps:
[0123] Step 502, reserve memory (pool) in the configuration file;
[0124] Step 504, when the mobile phone is powered on and starts up, read the configuration file;
[0125] Step 506, obtain the size of the reserved pool;
[0126] Step 508, initialize the ION memory allocator pool memory size (pool size) according to the reserved size;
[0127] Step 510, lock the memory size of the pool so that it cannot be recycled;
[0128] Step 512, a large application applies for a large amount of memory, generating memory pressure;
[0129] Step 514, release part of the memory according to the pressure level;
[0130] Step 516, release all memory before the system emits an OOM;
[0131] Step 518, recycle the released memory to the buddy system.
[0132] In step 504, the configuration file can be updated based on the methods from step 520 to step 532, or can be updated based on the methods from step 534 to step 538, specifically as follows:
[0133] Step 520, establish the correspondence between the available memory of the terminal device and the reserved pool;
[0134] Step 522: Dynamically adjust the size of the reserved pool according to the user's usage habits;
[0135] Step 524: Statistically calculate the average available memory level of the user;
[0136] Step 526: Statistically calculate once every 10 minutes and take the average value every day;
[0137] Step 528: The difference between the average value of the current day and the average value of the previous day exceeds the set threshold;
[0138] Step 530: Calculate the pool size according to the corresponding relationship between the pool size and the available memory;
[0139] Step 532: Update the configuration file of the pool size.
[0140] Step 534: The server issues a configuration command;
[0141] Step 536: Issue the configured size of the pool;
[0142] Step 538: Modify the configuration file of the pool size in the mobile phone according to the configuration command.
[0143] Thus, in this embodiment, by adding reserved memory for the ION allocator, 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 adaptively updated according to different users and usage habits, and the server is also supported to issue the size configuration of the reserved memory.
[0144] When the ION allocator has the above functions at the same time, the corresponding architecture of the ION allocator is as Figure 6 shown, Figure 6 It is a schematic diagram of 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.
[0145] As Figure 6 shown, the ION memory allocator can implement the following functions: Function ① Memory expansion; Function ② Memory release in different scenarios; Function ③ Filling of multiple order applications; Function ④ Intercommunication of different types of memory; Function ⑤ Memory reservation.
[0146] In an embodiment of the present application, when the target application is started in the terminal device, the memory required by the target application is determined in the user space of the terminal device; in the user space, a memory expansion request is sent to the kernel space of the terminal device, and the memory expansion request includes the memory required by the target application; in the kernel space, the memory required by the target application is expanded from the system memory to the memory pool of the ION allocator of the terminal device based on the memory expansion request, and an expansion completion command is returned to the user space; in the user space, after receiving the expansion completion command, memory is applied to the memory pool for the target application, thereby establishing communication between the underlying memory allocation and the upper-level application, supporting the target application to expand the memory in advance, and ensuring the memory application speed. Thereby, the startup speed of the target application can be accelerated, so that the target application can apply for memory at the fastest speed, which can effectively reduce the jamming and frame loss problems caused by slow memory application in the scenario where the application needs to use ION memory quickly and in large quantities to apply for memory.
[0147] The memory allocation method based on ION allocator provided in the embodiment of the present application can be executed by a memory allocation device based on ION allocator. In the embodiment of the present application, the memory allocation method based on ION allocator is executed by a memory allocation device based on ION allocator as an example to illustrate the memory allocation device based on ION allocator provided in the embodiment of the present application.
[0148] The memory allocation device based on the ION allocator in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than the terminal. Exemplary, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a personal computer (personal computer, PC), etc., which is not specifically limited in the embodiment of the present application.
[0149] The memory allocation device based on the ION allocator in the embodiment of the present application can 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 embodiment of the present application.
[0150] The memory allocation device based on the ION allocator provided by the embodiments of the present application can implement Figures 1 to 6 each process implemented by the method embodiments. To avoid repetition, details are not described herein again.
[0151] Figure 7 is a structural block diagram of the memory allocation device based on the ION allocator in the embodiments of the present application. Referring to Figure 7 , the memory allocation device 800 based on the ION allocator in the embodiments of the present application includes:
[0152] A determination 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;
[0153] A sending module 840, configured to send a memory expansion request to the kernel space of the terminal device in the user space, where the memory expansion request includes the memory required by the target application;
[0154] An expansion module 860, configured to expand the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device in the kernel space based on the memory expansion request, and return an expansion completion command to the user space;
[0155] An application module 880, configured to apply for memory from the memory pool in the user space to be used for the target application after receiving the expansion completion command.
[0156] Optionally, the determination module 820 is specifically configured to:
[0157] 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.
[0158] Optionally, the expansion module 860 is specifically configured to:
[0159] In response to the memory expansion request, wake up the target thread in the kernel space;
[0160] Bind the target thread to the CPU big core of the terminal device;
[0161] Apply for expanded memory from the system memory through the CPU big core to expand the memory required by the target application to the memory pool.
[0162] Optionally, the memory allocation device 800 further includes:
[0163] The dedicated memory configuration module is used to configure the memory expanded into the memory pool as the dedicated memory of the target application when the target application is started, and the dedicated memory is non-reclaimable memory.
[0164] In an embodiment of the present application, when the target application is started in the terminal device, the memory required by the target application is determined in the user space of the terminal device; in the user space, a memory expansion request is sent to the kernel space of the terminal device, and the memory expansion request includes the memory required by the target application; in the kernel space, the memory required by the target application is expanded from the system memory to the memory pool of the ION allocator of the terminal device based on the memory expansion request, and an expansion completion command is returned to the user space; in the user space, after receiving the expansion completion command, memory is applied to the memory pool for the target application, thereby establishing communication between the underlying memory allocation and the upper-level application, supporting the target application to expand the memory in advance, and ensuring the memory application speed. Thereby, the startup speed of the target application can be accelerated, so that the target application can apply for memory at the fastest speed, which can effectively reduce the jamming and frame loss problems caused by slow memory application in the scenario where the application needs to use ION memory quickly and in large quantities to apply for memory.
[0165] Optionally, the memory allocation device 800 further includes:
[0166] A time monitoring module, used for monitoring the CPU stall time of the terminal device and the memory application stall time of the system memory when there is memory release in the ION allocator;
[0167] A release module is used to directly release the memory in the memory pool of the ION allocator when the memory application jam time of the system memory is greater than a first threshold; directly release the memory in the memory pool of the ION allocator when the memory application jam time of the system memory is less than or equal to the first threshold and the CPU jam time is greater than a second threshold; and delay the release of the memory in the memory pool of the ION allocator when the memory application jam time of the system memory is less than or equal to the first threshold and the CPU jam time is less than or equal to the second threshold.
[0168] Therefore, by adopting the memory release method of the above embodiment, the release speed of the ION allocator memory can be increased. By identifying different memory pressure scenarios, the CPU resource competition can be reduced while taking into account the memory release speed.
[0169] Optionally, the memory allocation device 800 further includes:
[0170] A memory monitoring module, used to monitor the memory specifications in the memory pool of the ION allocator;
[0171] A filling module, configured to, when the memory is lower than a preset threshold, apply for system memory to fill the memory pool according to the memory specifications in the memory pool of the ION allocator in a preset order;
[0172] Wherein, the memory specifications include order1, order2, order4, and order9, and order4 and order9 are configured with a memory application abandonment flag, and the memory application abandonment flag is used to inform the ION allocator to abandon the memory application when the requested specification memory cannot be applied for.
[0173] Thus, by increasing the filling of orders with multiple different memory specifications, the memory filling speed of the ION allocator can be accelerated.
[0174] Optionally, the memory allocation device 800 further includes:
[0175] A determination module, configured to, after receiving the expansion completion command and applying for memory from the memory pool for the target application, determine the memory type and memory specifications for applying for memory from the memory pool for the target application, wherein the memory types in the memory pool include buffered memory and unbuffered memory;
[0176] A migration module, configured to, when the applied memory type is buffered memory and the applied memory exceeds the buffered memory in the memory pool, migrate the target unbuffered memory from the unbuffered memory in the memory pool to the buffered memory; when the applied memory type is unbuffered memory and the applied memory exceeds the unbuffered memory in the memory pool, migrate the target buffered memory from the buffered memory in the memory pool to the unbuffered memory.
[0177] Thus, by opening up the intercommunication between the Cache pool and the Uncache pool, the maximum utilization of the ION allocator memory is achieved, and the available memory of the system is increased.
[0178] Optionally, the memory allocation device 800 further includes:
[0179] 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;
[0180] 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 determined based on the available memory of the terminal device.
[0181] Optionally, the memory allocation device 800 further includes:
[0182] A memory monitoring module for monitoring the first available memory of the terminal device;
[0183] A first update module for updating the memory configuration file based on the first available memory.
[0184] Optionally, the memory monitoring module is specifically configured to:
[0185] Statistically calculate the available memory of the terminal device within a preset duration after startup at a preset time interval;
[0186] Calculate the average available memory within the preset duration to obtain the first available memory of the terminal device;
[0187] The first update module is specifically configured to:
[0188] Obtain the historical available memory of the terminal device corresponding to the reserved memory in the memory configuration file;
[0189] When the change value between the first available memory and the historical available memory is greater than a preset threshold, update the first reserved memory in the memory configuration file based on the first available memory.
[0190] Optionally, the memory allocation device 800 further includes:
[0191] A receiving module for receiving a configuration command sent by a server, where the configuration command carries a configured second reserved memory;
[0192] A second update module for updating the first reserved memory in the configuration file based on the configured second reserved memory.
[0193] Optionally, the memory allocation device 800 further includes:
[0194] A pressure monitoring module for monitoring 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;
[0195] A recycling module for recycling the target reserved memory in the memory pool to the system memory based on the memory pressure level of the system memory;
[0196] A filling module for filling the reserved memory recycled to the system memory into the memory pool when the memory pressure of the system memory is lower than a preset threshold.
[0197] Thus, by adding reserved memory to the ION allocator, the startup speed of the target application can be improved, and the reserved memory can be reclaimed when the system memory is under heavy pressure. The size of the reserved memory can be adaptively updated according to different users and usage habits, and it also supports the server to send the size configuration of the reserved memory.
[0198] Optionally, as Figure 8 shown, an embodiment of the present application further provides an electronic device 900, including a processor 940 and a memory 920. A program or instruction that can run on the processor 940 is stored on the memory 920. When the program or instruction is executed by the processor 940, it implements each step of the above-mentioned memory allocation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0199] It should be noted that the electronic device in the embodiment of the present application includes the above-mentioned mobile electronic device and non-mobile electronic device.
[0200] Figure 9 A schematic diagram of the hardware structure of an electronic device for implementing an embodiment of the present application.
[0201] The electronic device 1000 includes, but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009, and a processor 1010 and other components.
[0202] Those skilled in the art can understand that the electronic device 1000 may further include a power supply (such as a battery) for supplying power to each component. The power supply can be logically connected to the processor 1010 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. The structure of the electronic device shown in Figure x does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0203] Among them, the processor 1010 is used to determine the memory required by the target application in the user space of the terminal device when the target application is started in the terminal device; in the user space, send a memory expansion request to the kernel space of the terminal device, and the memory expansion request includes the memory required by the target application; in the kernel space, expand the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device based on the memory expansion request, and return an expansion completion command to the user space; in the user space, apply for memory from the memory pool for the target application after receiving the expansion completion command
[0204] Optionally, the processor 1010 is further configured to: when the target application is an application of a preset type, determine the memory required by the target application in the user space of the terminal device.
[0205] Optionally, the processor 1010 is further configured to: in response to the memory expansion request, wake up the target thread in the kernel space; bind the target thread to the large core of the CPU of the terminal device; apply for expanded memory from the system memory through the large core of the CPU to expand the memory required by the target application into the memory pool.
[0206] Optionally, the processor 1010 is further configured to: when the target application is started, configure the memory expanded into the memory pool as the exclusive memory of the target application, and the exclusive memory is non-recyclable memory.
[0207] Optionally, the processor 1010 is further configured to: when there is memory release in the ION allocator, monitor the CPU lag time of the terminal device and the memory application lag time of the system memory; when the memory application lag time of the system memory is greater than the first threshold, directly release the memory in the memory pool of the ION allocator; when the memory application lag time of the system memory is less than or equal to the first threshold and the CPU lag time is greater than the second threshold, directly release the memory in the memory pool of the ION allocator; when the memory application lag time of the system memory is less than or equal to the first threshold and the CPU lag time is less than or equal to the second threshold, delay the release of the memory in the memory pool of the ION allocator.
[0208] Optionally, the processor 1010 is further configured to: monitor the memory specification in the memory pool of the ION allocator; when the memory is lower than the preset threshold, apply for the system memory to fill the memory pool according to the memory specification in the memory pool of the ION allocator in a preset order; wherein, the memory specification includes order1, order2, order4, and order9, and order4 and order9 are configured with a memory application abandonment flag, and the memory application abandonment flag is used to inform the ION allocator to abandon the memory application when the requested specification memory cannot be applied for.
[0209] Optionally, the processor 1010 is further configured to: after receiving the expansion completion command and applying for memory from the memory pool for the target application, determine the memory type and memory specification for applying for memory from the memory pool for the target application, where the memory types of the memory pool include buffered 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 buffered memory; when the applied memory type is non-buffered memory and the applied memory exceeds the non-buffered memory in the memory pool, migrate the target buffered memory from the buffered memory in the memory pool to the non-buffered memory.
[0210] Optionally, the processor 1010 is further configured to: when the terminal device is powered on, read the memory configuration file of the ION allocator, where the memory configuration file is used to configure the first reserved memory in the memory pool of the ION allocator; based on the memory configuration file, fill the first reserved memory from the system memory of the terminal device into the memory pool, where the first reserved memory is determined based on the available memory of the terminal device.
[0211] Optionally, the processor 1010 is further configured to: monitor the first available memory of the terminal device; based on the first available memory, update the memory configuration file.
[0212] Optionally, the processor 1010 is further configured to: count the available memory of the terminal device at preset time intervals within a preset duration after the terminal device is powered on; calculate the average available memory within the preset duration to obtain the first available memory of the terminal device; obtain 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, update the first reserved memory in the memory configuration file based on the first available memory.
[0213] Optionally, 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.
[0214] The processor 1010 is further configured to: update the first reserved memory in the configuration file based on the configured second reserved memory.
[0215] Optionally, the processor 1010 is further 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 memory pressure level of the system memory, recycle the target reserved memory in the memory pool to the system memory; and when the memory pressure of the system memory is lower than a preset threshold, fill the reserved memory recycled to the system memory into the memory pool.
[0216] In the embodiment of the present application, when starting a target application on a terminal device, the required memory of the target application is determined in the user space of the terminal device; in the user space, a memory expansion request is sent to the kernel space of the terminal device, and the memory expansion request includes the required memory of the target application; in the kernel space, based on the memory expansion request, the required memory of the target application is expanded from the system memory to the memory pool of the ION allocator of the terminal device, and an expansion completion command is returned to the user space; in the user space, after receiving the expansion completion command, memory is applied from the memory pool for the target application, thereby establishing communication between the underlying memory allocation and the upper-layer application, supporting the target application to be able to expand memory in advance, and ensuring the memory application speed. Thereby, the startup speed of the target application can be accelerated, enabling the target application to apply for memory at the fastest speed, and effectively reducing the problems of lag and frame drops caused by slow memory application in scenarios where applications that require rapid and large-scale use of ION memory apply for memory.
[0217] It should be understood that in the embodiment of the present application, the input unit 1004 may include a graphics processing unit (GPU) 10041 and a microphone 10042. The graphics processing unit 10041 processes the image data of static pictures or videos obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light-emitting diode, etc. The user input unit 1007 includes at least one of a touch panel 10071 and other input devices 10072. The touch panel 10071 is also referred to as a touch screen. The touch panel 10071 may include two parts: a touch detection device and a touch controller. The other input devices 10072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, power-on keys, etc.), a trackball, a mouse, a joystick, which will not be elaborated here.
[0218] The memory 1009 can be used to store software programs and various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data. Among them, the first storage area may store an operating system, application programs or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 1009 may include a volatile memory or a non-volatile memory, or the memory 1009 may include both a volatile memory and a non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synch link dynamic random access memory (SLDRAM), and a direct rambus random access memory (DRRAM). The memory 1009 in the embodiments of the present application includes but is not limited to these and any other suitable types of memories.
[0219] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor. Among them, the application processor mainly processes operations related to the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication signals, such as a baseband processor. It can be understood that the above modem processor may not be integrated into the processor 1010.
[0220] The embodiments of the present application also provide a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, it implements each process of the above embodiments of the memory allocation method based on the ION allocator, and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0221] Among them, the processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disks, or optical discs, etc.
[0222] Another embodiment of the present application provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement each process of the above embodiment of the memory allocation method based on the ION allocator, and can achieve the same technical effects. To avoid repetition, it will not be elaborated here.
[0223] 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, system chip, chip system, or system-on-chip, etc.
[0224] The embodiments of the present application provide a computer program product. The program product is stored in a storage medium and is executed by at least one processor to implement each process of the above embodiment of the memory allocation method based on the ION allocator, and can achieve the same technical effects. To avoid repetition, it will not be elaborated here.
[0225] It should be noted that in this article, the term "including", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in a reverse order according to the functions involved. For example, the described methods may be performed in an order different from that described, and various steps may be added, omitted, or combined. Additionally, the features described with reference to certain examples may be combined in other examples.
[0226] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases, the former is a better implementation method. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present application.
[0227] The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above specific implementation manners. The above specific implementation manners are merely illustrative and not restrictive. Under the inspiration of the present application, those of ordinary skill in the art can also make many forms without departing from the purpose of the present application and the scope protected by the claims, and all of them belong to the protection scope of the present application.
Claims
1. A memory allocation method based on an ION allocator, characterized in that, Including: When the target application with multiple operation scenarios is started on the terminal device, identify the operation scenario to be executed by the target application and determine the memory required by the target application based on the identified operation scenario of the target application in the user space of the terminal device; the memory required by the target application is the memory required for the target application to execute the operation scenario. 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, so that the kernel space can prepare the memory required by the target application in advance. In the kernel space, expand the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device based on the memory expansion request, and return an expansion completion command to the user space. In the user space, after receiving the expansion completion command, apply for memory from the memory pool to directly obtain memory from the memory pool and use it for the target application.
2. The method according to claim 1, characterized in that Determining the memory required by the target application based on the identified operation scenario of the target application in the user space of the terminal device includes: When the target application is a preset type of application, determine the memory required by the target application based on the identified operation scenario of the target application in the user space of the terminal device.
3. The method according to claim 1, characterized in that, Expanding the memory required by the target application from the system memory to the memory pool of the ION allocator of the terminal device in the kernel space includes: Respond to the memory expansion request and wake up the target thread in the kernel space. Bind the target thread to the large CPU core of the terminal device. Apply for expanded memory from the system memory through the large CPU core to expand the memory required by the target application into the memory pool.
4. The method according to claim 1, wherein Also including: When the target application is started, configure the memory expanded into the memory pool as the exclusive memory of the target application, and the exclusive memory is non-recyclable memory.
5. The method according to claim 1, characterized in that, Also including: When there is memory release in the ION allocator, monitor the CPU lag time of the terminal device and the memory application lag time of the system memory. When the memory application lag time of the system memory is greater than the first threshold, directly release the memory in the memory pool of the ION allocator. When the memory application lag time of the system memory is less than or equal to the first threshold and the CPU lag time is greater than the second threshold, directly release the memory in the memory pool of the ION allocator. When the memory application lag time of the system memory is less than or equal to the first threshold and the CPU lag time is less than or equal to the second threshold, delay the release of the memory in the memory pool of the ION allocator.
6. The method according to claim 1, characterized in that, Also including: Monitor the memory specification in the memory pool of the ION allocator. When the memory is lower than the preset threshold, apply for the system memory to fill the memory pool in the preset order according to the memory specification in the memory pool of the ION allocator. Among them, the memory specifications include order1, order2, order4, and order9. The order4 and order9 are configured with a memory application abandonment flag, which is used to inform the ION allocator to abandon the memory application when the requested specification memory cannot be applied for.
7. The method according to claim 1, characterized in that, After receiving the expansion completion command and applying for memory from the memory pool to directly obtain memory from the memory pool and use it for the target application, it further includes: Determine the memory type and memory specification for the target application to be applied for from the memory pool. Among them, the memory types in the memory pool include buffered memory and unbuffered memory; When the applied memory type is buffered memory and the applied memory exceeds the buffered memory in the memory pool, migrate the target unbuffered memory from the unbuffered memory in the memory pool to the buffered memory; When the applied memory type is unbuffered memory and the applied memory exceeds the unbuffered memory in the memory pool, migrate the target buffered memory from the buffered memory in the memory pool to the unbuffered memory.
8. The method according to claim 1, wherein It further includes: 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; Based on the memory configuration file, fill the first reserved memory from the system memory of the terminal device into the memory pool, where the first reserved memory is determined based on the available memory of the terminal device.
9. The method according to claim 8, wherein It further includes: Monitor the first available memory of the terminal device; Based on the first available memory, update the memory configuration file.
10. The method according to claim 9, characterized in that, The monitoring of the first available memory of the terminal device includes: Statistically calculate the available memory of the terminal device within a preset duration after startup at a preset time interval; Calculate the average available memory within the preset duration to obtain the first available memory of the terminal device; The updating of the memory configuration file based on the first available memory includes: Obtain 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, update the first reserved memory in the memory configuration file based on the first available memory.
11. The method according to claim 8, wherein It further includes: Receive a configuration command sent by the server, and the configuration command carries the configured second reserved memory; Based on the configured second reserved memory, update the first reserved memory in the configuration file.
12. The method according to claim 8, wherein After filling the first reserved memory from the system memory of the terminal device into the memory pool, it further includes: Monitor the memory pressure of the system memory; Based on the memory pressure level of the system memory, recycle the target reserved memory in the memory pool to the system memory; When the memory pressure of the system memory is lower than a preset threshold, fill the reserved memory recycled to the system memory into the memory pool.
13. A memory allocation device based on an ION allocator, characterized in that, It includes: A determination module, configured to, when a target application with multiple operation scenarios is launched on a terminal device, identify an operation scenario to be executed by the target application and determine, in a user space of the terminal device, memory required by the target application based on the identified operation scenario of the target application; the memory required by the target application is the memory required for the target application to execute the operation scenario. A sending module, configured to send, in the user space, a memory expansion request to a kernel space of the terminal device, where the memory expansion request includes the memory required by the target application, so that the kernel space prepares the memory required by the target application in advance. An expansion module, configured to, in the kernel space, expand the memory required by the target application from a system memory to a memory pool of an ION allocator of the terminal device based on the memory expansion request, and return an expansion completion command to the user space. An application module, configured to, in the user space, apply for memory from the memory pool after receiving the expansion completion command to directly obtain memory from the memory pool and use it for the target application.
14. An electronic device, characterized in that, It includes a processor and a memory, and the memory stores a program or instruction that can run on the processor. When the program or instruction is executed by the processor, the steps of the memory allocation method according to any one of claims 1-12 are implemented.
15. A readable storage medium, characterized in that, The readable storage medium stores a program or instruction. When the program or instruction is executed by a processor, the steps of the memory allocation method according to any one of claims 1-12 are implemented.
Citation Information
Patent Citations
A method and apparatus for allocating terminal memory
CN109213596A
User mode program memory allocation method and system and related components
CN111143072A