Memory management methods, devices, electronic devices and storage media
By determining the amount of memory occupied by ION pools after they are used up and actively releasing it to the operating system, the problems of memory fragmentation and delayed reclamation caused by excessive ION pool usage are solved, thus improving the efficiency and stability of system memory management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-19
- Publication Date
- 2026-04-03
AI Technical Summary
The amount of memory occupied by the ION pool cannot be quantitatively determined by the operating system, leading to memory fragmentation and delayed system memory reclamation. In severe cases, this can cause memory allocation failures and process killing.
After the ION memory is used up, it is determined whether the total amount occupied is greater than or equal to the memory release threshold. If it exceeds the threshold, the ION memory is directly released to the operating system. The release of ION pool memory is actively managed by dynamically adjusting the threshold adjustment coefficient and the memory release flag.
It effectively prevents system memory shortages caused by excessive memory consumption of the ION pool, reduces memory fragmentation, avoids memory reclamation delays, improves system stability, and prevents processes from being killed.
Smart Images

Figure CN114116215B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of memory management technology, and in particular to a memory management method, apparatus, electronic device and storage medium. Background Technology
[0002] ION, a mechanism for managing bulk memory allocation in Linux, is a general-purpose memory manager introduced to address memory fragmentation. The Android operating system, building upon the Linux kernel's memory management mechanism, introduced the ION memory manager. ION is designed to avoid memory fragmentation or to reserve memory pools for applications with specific memory requirements, such as cameras and video players, during system startup. These pools, called ION pools, are managed by ION.
[0003] However, the amount of memory occupied by the ION pool cannot be quantitatively determined by the operating system. Generally, memory reclamation is only triggered when the system memory is severely insufficient, at which point the memory resources occupied by the ION pool are released to the operating system. The problem with this is that it does not consider the impact of an excessively large ION pool on the operating system, and system memory reclamation is delayed. Summary of the Invention
[0004] To overcome the problems existing in related technologies, this disclosure provides a memory management method, apparatus, electronic device, and storage medium.
[0005] According to a first aspect of the present disclosure, a memory management method is provided, comprising:
[0006] After the data cached in the current ION memory has been used up, determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold.
[0007] If the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, then the current ION memory is released to the operating system, wherein the ION memory occupied by the ION pool is storage space allocated from the operating system for caching data.
[0008] In an optional implementation, the method further includes:
[0009] Calculate the total amount of currently operable memory in the operating system;
[0010] The current pressure parameters of the operating system are obtained, and a threshold adjustment coefficient is determined based on the current pressure parameters; wherein the threshold adjustment coefficient is negatively correlated with the current pressure parameters.
[0011] The memory release threshold is calculated based on the total current operable memory and the threshold adjustment coefficient.
[0012] In one optional implementation, calculating the total current operable memory of the operating system includes:
[0013] Obtain the total amount of currently available memory and the amount of currently unrecoverable memory in the operating system;
[0014] The total amount of currently available memory is obtained by calculating the difference between the current total amount of available memory and the current amount of unrecoverable memory.
[0015] In one optional implementation, determining the threshold adjustment coefficient based on the current pressure parameter includes:
[0016] When the current pressure parameter is less than the first threshold, the threshold adjustment coefficient is determined to be the first percentage.
[0017] When the current pressure parameter is greater than or equal to the first threshold and less than or equal to the second threshold, the threshold adjustment coefficient is determined to be the second percentage.
[0018] If the current pressure parameter is greater than the second threshold, the threshold adjustment coefficient is determined to be the third percentage.
[0019] Wherein, the first threshold is less than the second threshold, and the first percentage, the second percentage, and the third percentage decrease sequentially.
[0020] In an optional implementation, the method further includes:
[0021] After the data cached in the current ION memory has been used up, if the current ION memory has been given a memory release flag, then the current ION memory is released to the operating system.
[0022] In an optional implementation, the method further includes:
[0023] If the total amount of ION memory occupied by the ION pool is less than the memory release threshold, and the current ION memory has not been assigned the memory release flag, then the current ION memory is stored in the ION pool.
[0024] In one alternative implementation, the current ION memory is allocated to the application process from the ION heap in the following manner:
[0025] When an application process requests the allocation of a specified size of memory from the ION heap, it is determined whether there is an allocatable ION memory of that size in the ION heap;
[0026] If there is no allocatable ION memory of the specified size in the ION heap, determine whether there is allocatable ION memory of the specified size in the ION pool;
[0027] If the ION pool has allocatable ION memory of the specified size, then request ION memory of the specified size from the ION pool and allocate it to the ION heap, and then allocate ION memory of the specified size from the ION heap for use by the application process.
[0028] In an optional implementation, the method further includes:
[0029] If there is no allocatable ION memory of the specified size in the ION pool, then an ION memory of the specified size is requested from the operating system and allocated to the ION heap, and then an ION memory of the specified size is allocated from the ION heap for use by the application process.
[0030] In an optional implementation, the method further includes:
[0031] If the creation of an ION heap fails during the process of specifying multiple ION memory locations, a memory release flag is assigned to each of the specified ION memory locations.
[0032] According to a second aspect of the present disclosure, a memory management apparatus is provided, comprising:
[0033] The threshold judgment module is used to determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold after the data cached in the current ION memory has been used.
[0034] The memory release module is used to release the current ION memory to the operating system when the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. The ION memory occupied by the ION pool is storage space allocated from the operating system for caching data.
[0035] According to a third aspect of the present disclosure, an electronic device is provided, characterized in that it includes:
[0036] A storage device on which computer programs are stored;
[0037] A processing device for executing the computer program in the storage device to implement the steps of the method described in the first aspect.
[0038] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided that stores computer program instructions thereon, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0039] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:
[0040] When an application process (such as a camera, video player, or multimedia application process) finishes using the current ION memory, it will determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. If the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, it means that the memory in the ION pool is excessive. In this case, there is no need to put the current ION memory into the ION pool, but to release it directly to the operating system. This is to prevent a series of problems caused by excessive memory occupied by the ION pool, alleviate the pressure of system memory shortage, and actively release memory to the operating system, thus avoiding the delay caused by waiting for memory reclamation.
[0041] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0042] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0043] Figure 1 This is a flowchart illustrating a memory management method according to an exemplary embodiment;
[0044] Figure 2 This is a flowchart illustrating the ION memory allocation process according to an exemplary embodiment;
[0045] Figure 3 It is based on Figure 2 The flowchart in the image shows a schematic diagram of the ION memory allocation process;
[0046] Figure 4 This is a flowchart illustrating the calculation of a memory release threshold according to an exemplary embodiment;
[0047] Figure 5 This is a schematic diagram illustrating a memory management device according to an exemplary embodiment;
[0048] Figure 6 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation
[0049] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0050] As described in the background section, the amount of memory occupied by the ION pool cannot be quantitatively determined by the operating system. Only after the data cached in the ION memory has been used can a qualitative decision be made: whether the used memory should be added back to the pool or directly released to the operating system. Typically, the memory resources occupied by the ION pool can only be released when the system memory is severely insufficient and the operating system reclaims memory. On the one hand, system memory reclamation is delayed; on the other hand, excessive memory usage by the ION pool can lead to memory shortages and fragmentation. If a memory-intensive operation occurs at this time, memory allocation will fail. For example, when the ION pool occupies too much memory, causing operating system memory pressure, the operating system will take actions such as killing processes to close memory-intensive processes (such as game processes, benchmarking software processes, etc.), resulting in a black screen when the user is playing games, or benchmarking software malfunctioning and unable to continue benchmarking tests, or even causing the benchmarking software to directly return a score of 0.
[0051] Therefore, this disclosure provides a memory management method that can proactively release used ION memory to the operating system. Figure 1 This is a flowchart illustrating a memory management method according to an exemplary embodiment, such as... Figure 1 As shown, this memory management method is used for ION memory management and includes the following steps:
[0052] Step S110: After the data cached in the current ION memory has been used, determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold.
[0053] Step S120: If the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, then the current ION memory is released to the operating system. The ION memory occupied by the ION pool is storage space allocated from the operating system for caching data.
[0054] During the above process, when an application process (such as a camera, video player, multimedia application process, etc.) finishes using the current ION memory, it will determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. If the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, it means that the memory in the ION pool is excessive. In this case, there is no need to put the current ION memory into the ION pool, but to release it directly to the operating system to prevent a series of problems caused by excessive memory occupied by the ION pool, alleviate the pressure of system memory shortage, and actively release memory to the operating system to avoid the delay caused by waiting for memory reclamation.
[0055] In a specific embodiment, the current ION memory is through Figure 2 The flowchart shown illustrates the allocation of resources to the application process. For example... Figure 2 As shown, the ION memory allocation process includes:
[0056] Step S210: When an application process requests to allocate memory of a specified size from the ION heap, determine whether there is an allocatable ION memory of that size in the ION heap. If there is an allocatable ION memory of that size in the ION heap, proceed to step S220; if there is no allocatable ION memory of that size in the ION heap, proceed to step S230.
[0057] Step S220: Allocate ION memory of this size from the ION heap for use by the application process.
[0058] Step S230: Determine whether there is an allocatable ION memory of that size in the ION pool. If there is an allocatable ION memory of that size in the ION pool, proceed to step S240; if there is no allocatable ION memory of that size in the ION pool, proceed to step S250.
[0059] Step S240: Request ION memory of the specified size from the ION pool and allocate it to the ION heap. Then allocate ION memory of the specified size from the ION heap for use by the application process.
[0060] Understandably, if there is no available ION memory of that size in the ION heap, and there is available ION memory of that size in the ION pool, then the ION memory of that size is first requested from the ION pool and allocated to the ION heap, and then the ION memory of that size is allocated from the ION heap for the application process to use.
[0061] Step S250: Request ION memory of the specified size from the operating system and allocate it to the ION heap, then allocate ION memory of the specified size from the ION heap for use by the application process.
[0062] Understandably, if there is no available ION memory of that size in the ION heap and no available ION memory of that size in the ION pool, the only option is to request ION memory of that size from the operating system, allocate it to the ION heap, and then allocate ION memory of that size from the ION heap for the application process to use.
[0063] Figure 3 A schematic diagram of the above ION memory allocation process is shown, as follows: Figure 3 As shown, the application process requests memory allocation from the ION heap. Here, the application process refers to the process that registered the ION. First, the application process requests N memory pages from the ION heap to cache process data. Then, it checks if the ION heap has N memory pages available for allocation. If it does, N memory pages are directly allocated from the ION heap to the application process. If not, it checks if the ION pool has N memory pages available. Since the ION pool is a memory pool reserved by the operating system for applications with specific memory requirements to facilitate rapid memory allocation, it prioritizes requesting memory allocation from the ION pool when the ION heap cannot meet the allocation needs. If the ION pool has N memory pages available, it requests N memory pages from the ION pool, allocates them to the ION heap, and then allocates N memory pages from the ION heap to the application process. If the ION pool also lacks available N memory pages, it requests N memory pages from the operating system, allocates them to the ION heap, and then allocates N memory pages from the ION heap to the application process.
[0064] Understandably, when in the initial state or after the ION pool's memory resources have been reclaimed by the system, the ION pool occupies zero ION memory. When an application process requests a specified size of ION memory from the ION heap, and the ION heap does not have that size of ION memory, since the ION pool occupies zero ION memory, it can only request that size of ION memory from the operating system, allocate it to the ION heap, and then allocate it to the application process from the ION heap. When the application process finishes using the ION memory allocated to it, the total amount of ION memory occupied by the ION pool is obviously not greater than or equal to the memory release threshold, so the ION memory will be stored in the ION pool. As more and more ION memory is requested from the operating system, and this ION memory is not returned to the system after use but is stored in the ION pool, so that it can be directly requested from the ION pool and quickly allocated when memory is requested next time, the ION memory in the ION pool gradually increases until the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. Once the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, the ION memory that is used up will no longer be stored in the ION pool, but will be directly returned to the operating system. When the operating system triggers memory reclamation again, the memory resources of the ION pool will be cleared again.
[0065] In an optional implementation, the memory management method further includes: after the data cached in the current ION memory has been used up, if the current ION memory has been given a memory release flag, then the current ION memory is released to the operating system.
[0066] For example, the memory release flag can have the highest priority. After the data cached in the current ION memory has been used up, if the current ION memory has the memory release flag, it is not necessary to perform the step of judging whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. Regardless of whether the total amount of ION memory occupied by the ION pool is greater than, equal to or less than the memory release threshold, once the current ION memory has the memory release flag, the current ION memory can be directly released to the operating system without being stored in the ION pool.
[0067] For example, after the data cached in the current ION memory has been used up, if the current ION memory does not have a memory release flag, the step of determining whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold is executed. If the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, the current ION memory is released to the operating system. If the total amount of ION memory occupied by the ION pool is less than the memory release threshold, the current ION memory is stored in the ION pool.
[0068] In an optional implementation, if the creation of an ION heap fails during the process of creating an ION heap by specifying multiple ION memories, a memory release flag is assigned to each of the specified ION memories.
[0069] It is understood that the above implementation is only one scenario for assigning a memory release flag to ION memory. In other implementations, the memory release flag can be generated in other ways, which will not be described one by one in this disclosure.
[0070] It should be noted that the memory release threshold in this embodiment can be a pre-set fixed value or a dynamically adjusted value based on the operating system's memory pressure. For example, the memory release threshold can be calculated each time the data cached in the current ION memory is used, or it can be calculated at a certain frequency.
[0071] Figure 4 A flowchart illustrating the calculation of the memory release threshold in an embodiment of this disclosure is shown, as follows: Figure 4 As shown, the memory release threshold is calculated through the following steps:
[0072] Step S310: Calculate the total amount of currently operable memory in the operating system.
[0073] The total amount of currently operable memory in the operating system can be calculated as follows: Obtain the total amount of currently available memory and the amount of currently unrecoverable memory in the operating system; calculate the difference between the two; and use this difference to obtain the total amount of currently operable memory in the operating system. The currently available memory includes currently unrecoverable memory, currently recoverable memory, and currently allocatable memory. The currently operable memory includes both currently recoverable and currently allocatable memory. Therefore, the total amount of currently operable memory in the operating system can be obtained by calculating the difference between the total amount of currently available memory and the amount of currently unrecoverable memory.
[0074] The total available memory and the current unrecoverable memory are counted in terms of memory page count. If the current available memory and the current unrecoverable memory are in KB, they need to be divided by the size of the memory page (in Linux, each page is usually 4KB) to convert them into the total available memory and the current unrecoverable memory in terms of memory page count.
[0075] Step S320: Obtain the current pressure parameters of the operating system and determine the threshold adjustment coefficient based on the current pressure parameters; wherein, the threshold adjustment coefficient is negatively correlated with the current pressure parameters.
[0076] The current pressure parameter is an indicator of the operating system's memory pressure. Specifically, it can be the system memory pressure value calculated based on the PSI (Pressure Stall Information) mechanism. In a specific embodiment, the current pressure parameter is represented as a value in the range of 0 to 100.
[0077] It should be noted that the higher the current stress parameter value, the greater the current memory pressure on the operating system. In this case, it is more necessary to conserve memory and not allow the ION pool to occupy too much ION memory. Therefore, the memory release threshold should be set smaller. On the other hand, the lower the current stress parameter value, the less the current memory pressure on the operating system. In this case, it is not necessary to conserve memory too much. The ION pool can occupy more ION memory to quickly allocate memory for memory-intensive application processes such as cameras and video players. Therefore, the memory release threshold can be set larger.
[0078] As the current pressure parameters increase, the memory release threshold should decrease. Therefore, a threshold adjustment coefficient is set to adjust the size of the memory release threshold. The threshold adjustment coefficient is negatively correlated with the current pressure parameters.
[0079] In an optional implementation, the step of determining the threshold adjustment coefficient based on the current pressure parameter includes the following cases:
[0080] 1) If the current pressure parameter is less than the first threshold, then the threshold adjustment coefficient is set to the first percentage;
[0081] 2) If the current pressure parameter is greater than or equal to the first threshold and less than or equal to the second threshold, then the threshold adjustment coefficient is determined to be the second percentage.
[0082] 3) If the current pressure parameter is greater than the second threshold, then the threshold adjustment coefficient is set to the third percentage;
[0083] Among them, the first threshold is less than the second threshold, and the first percentage, the second percentage, and the third percentage decrease in sequence.
[0084] Optionally, the first threshold is set to 50, the second threshold is set to 80, and the first percentage, second percentage, and third percentage are set to 150%, 100%, and 50% respectively. Then:
[0085] If the current pressure parameter is less than 50, the threshold adjustment coefficient is 150%.
[0086] If the current pressure parameter ∈ [50, 80], then the threshold adjustment coefficient is 100%.
[0087] If the current pressure parameter is greater than 80, the threshold adjustment coefficient is 50%.
[0088] Step S330: Calculate the memory release threshold based on the current total amount of operable memory and the threshold adjustment coefficient.
[0089] The memory release threshold is obtained by multiplying the current total operable memory by the threshold adjustment factor and the base factor. Considering that the maximum memory required by ION is typically around 10% of the total memory, the base factor can be set at around 10%. Using 10% of the total operable memory as the adjustment base, the threshold adjustment factor is used to adjust the threshold, thus obtaining the memory release threshold. This memory release threshold is dynamically determined based on the current operating system memory pressure and the total current operable memory. It changes dynamically with system memory pressure and the total operable memory, reflecting the reasonable range of ION memory occupied by the ION pool. When the total ION memory occupied by the ION pool exceeds this reasonable range, the used ION memory will be released to the operating system. It can be seen that when the system memory pressure increases, the threshold adjustment factor decreases accordingly, causing the memory release threshold to decrease as well. This ensures that used ION memory is returned to the operating system in a timely manner, thereby alleviating system memory pressure.
[0090] It should be noted that a target node is set in the sys file system. This node serves as the access path for the memory release threshold. Before executing the step of determining whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, the memory release threshold stored in the target node is read. After a new memory release threshold is calculated based on the system's stress parameters, the memory release threshold is updated through this node.
[0091] It should be noted that the embodiments of this disclosure limit the amount of memory occupied by the ION pool by setting a memory release threshold, which can significantly improve the system memory situation and reduce the failure of some memory-intensive operations in electronic devices such as mobile phones, TVs, and in-vehicle devices equipped with the Android operating system and ION memory manager under conditions of memory shortage and severe fragmentation. For example, operations such as screen recording with a camera or playing high-definition videos can cause a large amount of memory to be occupied in the ION pool, and it can only be released when the system reclaims memory. Therefore, memory shortages at this time can cause black screens or even process termination. The technical solution provided by the embodiments of this disclosure can effectively solve this technical problem.
[0092] Figure 5 This is a schematic diagram illustrating a memory management device according to an exemplary embodiment, such as... Figure 5 As shown, the memory management device 400 includes a threshold judgment module 410 and a memory release module 420.
[0093] The threshold judgment module 410 is used to determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold after the data cached in the current ION memory has been used.
[0094] The memory release module 420 is used to release the current ION memory to the operating system when the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. The ION memory occupied by the ION pool is storage space allocated from the operating system for caching data.
[0095] In an optional embodiment, the device 400 further includes:
[0096] An operable memory calculation module is used to calculate the total amount of currently operable memory in the operating system;
[0097] The adjustment coefficient calculation module is used to obtain the current pressure parameters of the operating system and determine the threshold adjustment coefficient based on the current pressure parameters; wherein, the threshold adjustment coefficient is negatively correlated with the current pressure parameters;
[0098] The memory release threshold calculation module is used to calculate the memory release threshold based on the total number of currently operable memory units and the threshold adjustment coefficient.
[0099] In an optional implementation, the operable in-memory computing module is used for:
[0100] Obtain the total amount of currently available memory and the amount of currently unrecoverable memory in the operating system;
[0101] The total amount of currently available memory is obtained by calculating the difference between the current total amount of available memory and the current amount of unrecoverable memory.
[0102] In an optional implementation, the adjustment coefficient calculation module is used for:
[0103] When the current pressure parameter is less than the first threshold, the threshold adjustment coefficient is determined to be the first percentage.
[0104] When the current pressure parameter is greater than or equal to the first threshold and less than or equal to the second threshold, the threshold adjustment coefficient is determined to be the second percentage.
[0105] When the current pressure parameter is greater than the second threshold, the threshold adjustment coefficient is determined to be the third percentage.
[0106] Wherein, the first threshold is less than the second threshold, and the first percentage, the second percentage, and the third percentage decrease sequentially.
[0107] In an optional implementation, the memory release module 420 is used for:
[0108] After the data cached in the current ION memory has been used up, and the current ION memory has been given a memory release flag, the current ION memory is released to the operating system.
[0109] In an optional implementation, the device 400 further includes a memory pooling module, used to store the current ION memory into the ION pool when the total amount of ION memory occupied by the ION pool is less than the memory release threshold and the current ION memory has not been assigned the memory release flag.
[0110] In an optional implementation, the apparatus 400 further includes an ION memory allocation module for requesting and allocating ION memory from the ION heap to the application process in the following manner:
[0111] When an application process requests the allocation of a specified size of memory from the ION heap, it is determined whether there is an allocatable ION memory of that size in the ION heap;
[0112] If there is no allocatable ION memory of the specified size in the ION heap, determine whether there is allocatable ION memory of the specified size in the ION pool.
[0113] If there is an allocatable ION memory of the specified size in the ION pool, request the specified size of ION memory from the ION pool and allocate it to the ION heap, and then allocate the specified size of ION memory from the ION heap for use by the application process.
[0114] In an optional implementation, the ION memory allocation module is used for:
[0115] If there is no available ION memory of the specified size in the ION pool, request ION memory of the specified size from the operating system and allocate it to the ION heap, and then allocate ION memory of the specified size from the ION heap for use by the application process.
[0116] In an optional implementation, the apparatus 400 further includes a flag adding module, which, if the creation of an ION heap fails during the creation of a specified plurality of ION memory, assigns a memory release flag to each of the specified plurality of ION memory.
[0117] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0118] This disclosure also provides a computer-readable storage medium having stored thereon computer program instructions that, when executed by a processor, implement the steps of the memory management method provided in this disclosure.
[0119] This disclosure also provides an electronic device, including: a storage device and a processing device, wherein the storage device stores a computer program, and the processing device is used to execute the computer program in the storage device to implement the steps of the memory management method provided in this disclosure.
[0120] Figure 6 This is a block diagram illustrating an electronic device 500 according to an exemplary embodiment. For example, the electronic device 500 may be a mobile phone, television, in-vehicle device, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness device, personal digital assistant, etc. The electronic device 500 is equipped with the Android operating system and ION memory manager.
[0121] Reference Figure 6 The electronic device 500 may include one or more of the following components: processing component 502, memory 504, power component 506, multimedia component 508, audio component 510, input / output (I / O) interface 512, sensor component 514, and communication component 516.
[0122] Processing component 502 typically controls the overall operation of electronic device 500, such as operations associated with display, telephone calls, data communication, camera operation, and recording operations. Processing component 502 may include one or more processors 520 to execute instructions to complete all or part of the steps of the memory management method described above. Furthermore, processing component 502 may include one or more modules to facilitate interaction between processing component 502 and other components. For example, processing component 502 may include a multimedia module to facilitate interaction between multimedia component 508 and processing component 502.
[0123] Memory 504 is used to store various types of data to support the operation of electronic device 500. Examples of this data include instructions for any application or method operating on electronic device 500, contact data, phonebook data, messages, pictures, videos, etc. Memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0124] Power component 506 provides power to various components of electronic device 500. Power component 506 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 500.
[0125] Multimedia component 508 includes a screen that provides an output interface between the electronic device 500 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 508 includes a front-facing camera and / or a rear-facing camera. When the electronic device 500 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0126] Audio component 510 is used to output and / or input audio signals. For example, audio component 510 includes a microphone (MIC) used to receive external audio signals when electronic device 500 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 504 or transmitted via communication component 516. In some embodiments, audio component 510 also includes a speaker for outputting audio signals.
[0127] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0128] Sensor assembly 514 includes one or more sensors for providing state assessments of various aspects of electronic device 500. For example, sensor assembly 514 may detect the on / off state of electronic device 500, the relative positioning of components such as the display and keypad of electronic device 500, changes in position of electronic device 500 or a component of electronic device 500, the presence or absence of user contact with electronic device 500, orientation or acceleration / deceleration of electronic device 500, and temperature changes of electronic device 500. Sensor assembly 514 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 514 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 514 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.
[0129] Communication component 516 facilitates wired or wireless communication between electronic device 500 and other devices. Electronic device 500 can access wireless networks based on communication standards, such as WiFi, 4G, or 5G, or combinations thereof. In one exemplary embodiment, communication component 516 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 516 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0130] In an exemplary embodiment, the electronic device 500 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the memory management method described above.
[0131] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 504 including instructions, which can be executed by a processor 520 of an electronic device 500 to complete the memory management method described above. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0132] In another exemplary embodiment, a computer program product is also provided, the computer program product comprising a computer program executable by a programmable device, the computer program having a code portion for performing the memory management method described above when executed by the programmable device.
[0133] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of this disclosure. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0134] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A memory management method, characterized in that, include: After the data cached in the current ION memory has been used up, determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold. If the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, then the current ION memory is released to the operating system, wherein the ION memory occupied by the ION pool is storage space allocated from the operating system for caching data; The method further includes: Calculate the total amount of currently operable memory in the operating system; The current pressure parameters of the operating system are obtained and a threshold adjustment coefficient is determined based on the current pressure parameters; wherein, different ranges of the pressure parameters correspond to different threshold adjustment coefficients, and the threshold adjustment coefficient is negatively correlated with the range in which the current pressure parameters are located; The memory release threshold is calculated based on the total current operable memory and the threshold adjustment coefficient.
2. The method according to claim 1, characterized in that, The calculation of the total current operable memory of the operating system includes: Obtain the total amount of currently available memory and the amount of currently unrecoverable memory in the operating system; The total amount of currently available memory is obtained by calculating the difference between the current total amount of available memory and the current amount of unrecoverable memory.
3. The method according to claim 1, characterized in that, Determining the threshold adjustment coefficient based on the current pressure parameter includes: When the current pressure parameter is less than the first threshold, the threshold adjustment coefficient is determined to be the first percentage. When the current pressure parameter is greater than or equal to the first threshold and less than or equal to the second threshold, the threshold adjustment coefficient is determined to be the second percentage. If the current pressure parameter is greater than the second threshold, the threshold adjustment coefficient is determined to be the third percentage. Wherein, the first threshold is less than the second threshold, and the first percentage, the second percentage, and the third percentage decrease sequentially.
4. The method according to claim 1, characterized in that, The method further includes: After the data cached in the current ION memory has been used up, if the current ION memory has been given a memory release flag, then the current ION memory is released to the operating system.
5. The method according to claim 4, characterized in that, The method further includes: If the total amount of ION memory occupied by the ION pool is less than the memory release threshold, and the current ION memory has not been assigned the memory release flag, then the current ION memory is stored in the ION pool.
6. The method according to any one of claims 1-5, characterized in that, The current ION memory is allocated to the application process from the ION heap in the following manner: When an application process requests the allocation of a specified size of memory from the ION heap, it is determined whether there is an allocatable ION memory of that size in the ION heap; If there is no allocatable ION memory of the specified size in the ION heap, determine whether there is allocatable ION memory of the specified size in the ION pool; If the ION pool has allocatable ION memory of the specified size, then request ION memory of the specified size from the ION pool and allocate it to the ION heap, and then allocate ION memory of the specified size from the ION heap for use by the application process.
7. The method according to claim 6, characterized in that, The method further includes: If there is no allocatable ION memory of the specified size in the ION pool, then an ION memory of the specified size is requested from the operating system and allocated to the ION heap, and then an ION memory of the specified size is allocated from the ION heap for use by the application process.
8. The method according to claim 6, characterized in that, The method further includes: If the creation of an ION heap fails during the process of specifying multiple ION memory locations, a memory release flag is assigned to each of the specified ION memory locations.
9. A memory management device, characterized in that, include: The threshold judgment module is used to determine whether the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold after the data cached in the current ION memory has been used. The memory release module is used to release the current ION memory to the operating system when the total amount of ION memory occupied by the ION pool is greater than or equal to the memory release threshold, wherein the ION memory occupied by the ION pool is storage space allocated from the operating system for caching data; An operable memory calculation module is used to calculate the total amount of currently operable memory in the operating system; The adjustment coefficient calculation module is used to obtain the current pressure parameters of the operating system and determine the threshold adjustment coefficient based on the current pressure parameters; wherein, different ranges of pressure parameters correspond to different threshold adjustment coefficients, and the threshold adjustment coefficient is negatively correlated with the range in which the current pressure parameter is located; The memory release threshold calculation module is used to calculate the memory release threshold based on the total number of currently operable memory units and the threshold adjustment coefficient.
10. An electronic device, characterized in that, include: A storage device on which computer programs are stored; A processing device for executing the computer program in the storage device to implement the steps of the method according to any one of claims 1-8.
11. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When executed by a processor, the program instructions implement the steps of the method described in any one of claims 1-8.
Citation Information
Patent Citations
Memory recovery processing method and device, electronic equipment and storage medium
CN110737606A
Memory recovery method and device, terminal equipment and storage medium
CN111782560A