Efficient memory allocation and recovery method for Android device
By calculating memory state entropy and building a multi-dimensional allocation priority matrix, dynamically adjusting memory allocation and page recycling priority, the problem of insufficient memory management of Android devices in high-load and multi-task environments is solved, and efficient memory resource utilization and performance optimization are achieved.
Patent Information
- Application Number
- CN202411708779.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-11-27
AI Technical Summary
The memory management technology of existing Android devices is difficult to dynamically adapt to system state changes in high-load and multi-task environments, resulting in performance degradation and system crashes.
By calculating memory state entropy and building a multi-dimensional allocation priority matrix, dynamically adjusting memory allocation thresholds and page recycling priority, realizing adaptive memory compression and defragmentation.
It significantly improves memory resource utilization efficiency, ensures the execution performance of high-priority tasks, and optimizes resource allocation for low-priority tasks, extends the service life of equipment.
Smart Images

Figure CN119645634A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory processing technology, and in particular to an efficient memory allocation and recycling method for Android devices. Background Art
[0002] With the rapid popularization of smart devices, especially mobile smart terminals represented by Android devices, memory management technology has become a key factor affecting device performance, user experience and energy consumption. Android devices usually need to handle multi-task concurrency, complex resource scheduling and real-time response to user needs, which places extremely high demands on the allocation and management of memory resources. However, existing memory management technologies still have obvious shortcomings in dealing with complex and changing operating scenarios, especially in high-load, multi-tasking environments. The traditional static processing method of memory allocation and recycling cannot meet the dynamic needs of the system, resulting in performance degradation or even system crashes.
[0003] At present, the memory management technology of Android devices mainly includes the following core aspects: memory allocation strategy, page recycling mechanism, defragmentation and memory compression technology. In the prior art, the memory allocation of Android devices usually relies on fixed thresholds or simple priority rules. For example, the memory management method based on the least recently used algorithm is a widely used strategy. This algorithm is simple and efficient by giving priority to releasing recently unused memory pages. However, this method fails to fully consider the global state of memory allocation, such as memory fragmentation, the dynamics of task load and the overall pressure of the system, which often leads to low memory utilization or unmet memory requirements of key tasks. In addition, the static nature of the least recently used algorithm is difficult to adapt to dynamic changes in a multi-task concurrent environment, especially when running high-load applications, its performance bottleneck becomes more and more obvious. Page recycling is a key operation of memory management. In the prior art, hierarchical recycling strategies are mostly adopted, such as giving priority to cleaning pages of background tasks, or releasing cache and dirty pages. However, this method is often based only on task priority or page type, and lacks a comprehensive evaluation of the global system state. Specifically, when the system load is high and fragmentation is severe, the traditional recycling mechanism may not be able to release enough continuous memory, resulting in a decline in the performance of the foreground task or even application crashes. In addition, the calculation of recycling priority by existing page recycling algorithms usually only considers single-dimensional indicators, such as page access frequency, but fails to integrate multi-dimensional factors such as memory distribution, task load and system pressure, which significantly limits recycling efficiency and accuracy. Memory fragmentation is a chronic disease of memory management in Android devices, especially after long-term operation, a large number of discontinuous small memory blocks will seriously affect the memory allocation requirements of large tasks. In the prior art, memory defragmentation operations are usually periodic or triggered when the degree of fragmentation exceeds a fixed threshold. However, this static trigger mechanism lacks dynamic perception of memory status, which may cause the defragmentation operation to be triggered too late, thereby affecting system performance. In addition, the defragmentation operation itself is a time-consuming process that has a great impact on system performance. The prior art lacks intelligent optimization of its triggering conditions and execution scope. Summary of the invention
[0004] In view of this, the main purpose of the present invention is to provide an efficient memory allocation and recovery method for Android devices. This multi-dimensional dynamically optimized memory management method can not only significantly improve the utilization efficiency of memory resources, but also dynamically adapt to changes in system status in complex operating scenarios, ensure the execution performance of high-priority tasks, and optimize the resource allocation of low-priority tasks. This efficient memory management technology is of great significance in improving user experience, optimizing device performance, and extending device service life, especially in the environment of processing complex tasks, high-load operation, and multi-tasking concurrency, showing great application value and technical advantages.
[0005] To achieve the above object, the technical solution of the present invention is achieved as follows:
[0006] An efficient memory allocation and recycling method for Android devices, the method comprising:
[0007] Step 1: Obtain the running data of the Android device, and calculate the memory state entropy based on the running data; construct a multi-dimensional allocation priority matrix based on the memory state entropy; and calculate the memory fragmentation risk by combining the priority matrix and the running data;
[0008] Step 2: Calculate the dynamic threshold of memory allocation based on the memory fragmentation risk; calculate the page recovery priority based on the priority matrix and memory state entropy; calculate the adaptive memory compression rate based on the page recovery priority and memory fragmentation risk;
[0009] Step 3: Use the adaptive memory compression rate to compress the currently unused memory data of the Android device; determine whether the memory usage of a certain active process exceeds the dynamic threshold of memory allocation, and if so, further determine whether the page recycling priority exceeds the set recycling threshold, and if so, recycle the pages of the active process in the order of page generation time until the number of pages of the active process is lower than the set minimum page threshold;
[0010] Step 4: If the memory fragmentation risk exceeds the set defragmentation threshold, the Android device performs memory defragmentation; calculates the memory allocation Boolean value according to the memory allocation dynamic threshold, the adaptive memory compression rate and the page recycling priority; if the memory allocation Boolean value is true, recycles all memory, and subtracts the memory allocation dynamic threshold from the total memory capacity, and then distributes the remaining memory capacity evenly to all active processes.
[0011] Furthermore, the operation data of the Android device obtained in step 1 includes: the size of each memory block, the total memory capacity, the number of pages of each active process, the CPU usage corresponding to each active process, the process real-time response time, the maximum allowed process response time, the current number of dirty pages, the page miss count, the IO wait time, the maximum IO wait time, the current number of memory pages, the maximum number of memory pages, the active memory load, the maximum memory load, the number of page table entries, and the maximum number of page table entries.
[0012] Furthermore, in step 1, the following formula is used to calculate the memory state entropy H mem :
[0013]
[0014] Where n is the total number of memory blocks; b i is the size of the i-th memory block; B total is the total memory capacity; is the proportion of the i-th memory block to the total memory; p j is the number of pages of the jth active process; c j is the CPU usage of the jth active process; m is the number of active processes; P total The total number of pages.
[0015] Furthermore, in step 1, the following formula is used to construct a multidimensional allocation priority matrix M based on the memory state entropy: priority :
[0016]
[0017] Where, t is time; R p is the real-time response time of the process; R max is the maximum allowed process response time; D c is the current number of dirty pages; F c F is the page fault count; max is the page fault count threshold; I o I is the IO waiting time; max is the maximum IO waiting time; N p is the current number of memory pages; N total is the maximum number of memory pages; L m is the active memory load; L total is the maximum memory load; T p is the number of page table entries; T max is the maximum number of page table entries.
[0018] Furthermore, in step 1, the following formula is used to calculate the memory fragmentation risk R by combining the priority matrix and the running data: frag :
[0019]
[0020] Among them, det(M priority ) indicates M priority The determinant value; q is the number of memory segments; s k is the size of the kth memory segment; g k is the memory growth rate of the kth segment; G max is the maximum allowed memory growth rate; f l is the number of fragments of the first type; F total is the total fragment capacity; v is the number of fragment types.
[0021] Furthermore, in step 2, the following formula is used to calculate the dynamic threshold T of memory allocation according to the memory fragmentation risk: alloc :
[0022]
[0023] Among them, B base is the basic memory block size, which is the smallest memory allocation unit of Android devices; C is the memory state closed path; represents the line integral of the priority change rate along the closed path of the memory state; α is the preset weight factor; m x is the size of the xth memory mapping unit; w is the number of memory mapping units; M ref is the reference memory size, which is used to normalize the size impact of the memory mapping unit; β is the preset historical entropy change rate correction factor; t′ is the time integral variable, ranging from 0 to t; σ(H mem ) represents the standard deviation of memory state entropy.
[0024] Furthermore, in step 2, the following formula is used to calculate the page recycling priority P by combining the priority matrix and memory state entropy: reclaim :
[0025]
[0026] in, is the gradient of memory state entropy; The gradient of the multidimensional allocation priority matrix; ||·|| is the modulus operator; a j is the active time of the jth active process; e j is the memory usage of the jth active process.
[0027] Furthermore, in step 2, the following formula is used to calculate the adaptive memory compression rate C according to the page recycling priority and memory fragmentation risk: ratio :
[0028]
[0029] Among them, Ω y is the yth memory area; is the normal gradient of the memory state entropy; l c is the memory usage of layer c; L max is the maximum memory usage of all levels; z is the number of memory regions; r is the number of memory levels; × is the cross product operator.
[0030] Furthermore, in step 4, the following formula is used to calculate the memory allocation Boolean value B alloc :
[0031]
[0032] By adopting the above technical scheme, the present invention has the following intentional effects: compared with the traditional memory management method that solely relies on the static parameters of memory occupancy or task priority, the present invention comprehensively reflects the distribution and utilization efficiency of memory resources by combining the dynamic weights of memory block size, task page number and system load through memory state entropy. For example, in a scenario where memory blocks are unevenly distributed and load fluctuations are large, the dynamic change of entropy value can effectively prompt the system to adjust the allocation strategy to avoid performance bottlenecks caused by fragmentation or uneven load. This innovative method of quantifying memory state not only improves the accuracy of resource allocation, but also provides a scientific basis for subsequent optimization strategies. By introducing a dynamic evaluation mechanism of memory fragmentation risk, the present invention can monitor the distribution of system memory fragments in real time and decide whether to trigger the defragmentation operation according to the level of risk. Compared with the traditional defragmentation method triggered by periodic or static thresholds, the dynamic fragmentation risk assessment of the present invention can handle the fragmentation problem more timely and effectively, avoiding the lag of the defragmentation operation and reducing unnecessary performance overhead, thereby providing a more stable operating environment for Android devices. The present invention proposes an adaptive memory compression strategy, which dynamically adjusts the memory compression rate by combining multi-dimensional factors such as memory fragmentation risk, page recycling efficiency and system load. This method not only improves the efficiency of memory compression, but also significantly reduces the negative impact of compression operation on system performance. In practical applications, the adaptive compression strategy of the present invention can quickly respond to changes in the system memory state. For example, in high-load operation scenarios, it preferentially makes room by compressing unused data, while reducing the compression frequency in low-load scenarios, thereby finding the best balance between performance and resource utilization. This dynamic adjustment mechanism significantly improves the memory management efficiency of Android devices and provides strong technical support for high-performance demand scenarios. The present invention optimizes the target selection process of page recycling by introducing a dynamic calculation method of page recycling priority. Traditional page recycling strategies are usually based on a single indicator, such as the access frequency of a page or the priority of a task, while ignoring the complexity of the overall memory state of the system and the task load. The page recycling priority method of the present invention comprehensively considers the value of the page, the importance of the task and the current load of the system through multi-dimensional analysis, thereby accurately identifying the pages that need to be recycled. This method maximizes the release of resources of low-priority tasks while ensuring the memory requirements of critical tasks, providing a more stable memory guarantee for system operation. The present invention also introduces a memory allocation Boolean value calculation mechanism in the final decision-making process of memory allocation. This mechanism dynamically determines whether to allow new memory allocation operations through dual evaluation of memory allocation conditions and system status. By comprehensively considering the impact of allocation dynamic thresholds, page recycling priorities, and memory fragmentation distribution, the Boolean value decision-making mechanism of the present invention can avoid unnecessary resource allocation requests, thereby reducing the risk of memory allocation failure or system performance degradation.This mechanism is particularly suitable for memory management requirements in high-concurrency, multi-tasking environments, and can effectively improve system stability and task execution efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0034] Figure 1 A method flow chart of an efficient memory allocation and recovery method for Android devices provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The method of the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments of the present invention.
[0036] Example 1, reference Figure 1 :An efficient memory allocation and recycling method for Android devices, the method comprising:
[0037] Step 1: Obtain the running data of the Android device, and calculate the memory state entropy based on the running data; construct a multi-dimensional allocation priority matrix based on the memory state entropy; and calculate the memory fragmentation risk by combining the priority matrix and the running data;
[0038] In Android devices, the size and distribution of each memory block will directly affect the overall operating state of the system. If the size distribution of the memory block is too discrete (i.e., the memory fragmentation phenomenon is significant), the system may fall into a state of resource scheduling difficulties due to the inability to allocate continuous memory for large tasks; when the memory block distribution is relatively uniform, the system has a higher allocation efficiency and runs more smoothly. Therefore, the memory state entropy is designed as a quantitative indicator to describe the distribution characteristics of the memory block size in the total memory capacity. Specifically, the present invention collects the current memory allocation data of the device, regards the size ratio of the memory block as a probability distribution, and calculates the memory state entropy based on this. The high or low entropy value directly reflects the degree of chaos in the system memory allocation. In the calculation of the entropy value, the present invention particularly considers the multi-tasking characteristics of Android devices and corrects the entropy value by introducing dynamic weights. In Android devices, different processes have different requirements for memory resources during operation, and these requirements are usually associated with their number of pages and CPU occupancy. For example, if a high-priority process occupies a large amount of memory and has a large number of pages, it will have a greater impact on the system load. In order to more accurately evaluate the memory state, the present invention designs a weighted entropy model combined with the system load, taking the number of pages and CPU occupancy of each process as weighted factors, and acting together with the memory block distribution in the entropy value calculation. Specifically, by calculating the weighted average of the number of pages and CPU occupancy of all active processes, the present invention constructs a factor reflecting the system load intensity, and combines the factor with the traditional entropy model, so that the calculation of the entropy value can not only reflect the spatial characteristics of memory allocation, but also reflect the dynamic changes of the system load. For example, when an Android device runs multiple background tasks, low-priority tasks usually occupy less memory and have less impact, while the memory demand of high-priority tasks fluctuates greatly. At this time, the traditional entropy value calculation may only reflect the uniformity of the memory block distribution, while ignoring the impact of these memory blocks on the actual system performance. The present invention makes the entropy value more practical by combining the system load factor, and can better guide the subsequent memory optimization strategy. In this process, the calculation of the memory state entropy also fully considers the changes in the time dimension, that is, the dynamic nature of the memory distribution. By analyzing the changing trend of entropy value over time, we can further determine whether the system is in an efficient state of memory usage, thereby providing a decision-making basis for operations such as memory defragmentation or page recycling.
[0039] Based on the calculation results of memory state entropy, the present invention further constructs a multi-dimensional allocation priority matrix for comprehensively evaluating the urgency and rationality of memory resource allocation. The design of the priority matrix is based on multiple key parameters, including the rate of change of memory entropy, page miss rate, IO waiting time, system response delay, etc. These parameters jointly reflect the demand for memory resources of Android devices under different operating states. Each element of the priority matrix is a quantitative description of a certain memory management dimension. For example, the rate of change of memory entropy represents the dynamic adjustment trend of system memory distribution, while the page miss rate directly reflects the efficiency of current memory allocation. By constructing this matrix, the present invention realizes a comprehensive quantification of the urgency of memory allocation and provides accurate priority sorting for memory compression and page recycling in subsequent steps. Traditional memory management schemes often use fixed rules to allocate resources, lack sensitivity to real-time changes, and are prone to instability in high load or emergency situations. The present invention enables the memory management strategy to quickly adapt to changes in system status by updating the priority matrix in real time. For example, when a large number of page misses occur in the system, the priority matrix will automatically increase the weight of the page miss rate, thereby giving priority to allocating memory resources to alleviate this problem. At the same time, other dimensions in the matrix (such as response delay and IO waiting time) will also be adjusted accordingly according to the current system load to ensure the global optimization of memory management decisions. In practical applications, memory state entropy and priority matrix together constitute the decision-making core of Android device memory management. The entropy value provides a global quantitative description of the memory distribution state, while the priority matrix refines this global information into a specific allocation strategy through multi-dimensional weight analysis. The combination of the two enables the present invention to quickly respond to memory allocation requirements in a complex operating environment, while ensuring efficient use of memory resources by dynamically adjusting weights and parameters. For example, in a high-load operating environment, the changing trend of the entropy value can indicate whether the system needs to perform memory defragmentation, and the priority matrix can further determine which tasks should be given priority in allocating resources. This multi-dimensional, multi-level decision-making framework provides powerful technical support for the memory management of Android devices, significantly improving the operating efficiency and stability of the system.
[0040] Step 2: Calculate the dynamic threshold of memory allocation based on the memory fragmentation risk; calculate the page recovery priority based on the priority matrix and memory state entropy; calculate the adaptive memory compression rate based on the page recovery priority and memory fragmentation risk;
[0041] One of the main problems faced by memory allocation in Android devices is memory fragmentation, that is, due to the distribution of discontinuous small memory blocks in the entire memory space, it is impossible to allocate enough continuous space for large tasks. The risk of fragmentation is not only manifested in the reduction of memory utilization, but also significantly affects the system response performance in high-load scenarios. The present invention calculates the key indicator of fragmentation risk by analyzing the distribution characteristics, growth trend and number of fragments of memory blocks. The memory fragmentation risk directly affects the dynamic threshold calculation of subsequent memory allocation. It has a nonlinear relationship with system performance, that is, the higher the risk, the more likely the stability of system operation is threatened. By adjusting the dynamic threshold, the negative impact of fragmentation on the system can be effectively reduced. The calculation of the dynamic threshold of memory allocation is the core step of memory optimization. It is a dynamic adjustment parameter that comprehensively considers the current state of the system, historical trends and fragmentation risks. In Android devices, different application tasks have variable memory requirements. For example, the foreground application may suddenly increase the memory demand during user interaction, while the background task usually has a lower priority and a relatively stable memory demand. The present invention introduces a dynamic threshold to distinguish the competitiveness of high-priority and low-priority tasks in memory allocation. In this process, the memory state entropy is used as a key reference to characterize the degree of disorder in the current memory allocation; the dimensions of the priority matrix further refine the urgency of the needs of different tasks and the distribution of system pressure. Through the combination of these data, the dynamic threshold is designed as a real-time adjustment indicator. When the risk of fragmentation is high, the dynamic threshold will be lowered to limit new memory allocation and give priority to defragmentation and memory compression; when the system load is low and the degree of fragmentation is low, the dynamic threshold will be increased accordingly to support more flexible memory allocation operations.
[0042] At the same time, the page recovery priority calculation method proposed in the present invention provides a scientific decision-making basis for memory recovery operations by further analyzing the memory state and priority matrix. In Android devices, memory recovery is often to make room to meet more urgent task requirements, so the recovery operation needs to take into account both timeliness and rationality. The calculation of page recovery priority is based on the gradient of memory state entropy, combined with the dynamic changes of the priority matrix, to evaluate the retention value of each memory page. For tasks that occupy more memory but have lower activity, their page recovery priority will be relatively high, and the key pages of high-priority tasks will be retained first. In addition, the present invention further optimizes the calculation of recovery priority by analyzing the second-order derivative of memory entropy, that is, the acceleration of memory state change. In the case of large memory fluctuations or rapid changes in system load, the introduction of the second-order derivative can more accurately determine which pages should be recycled first, thereby improving the efficiency and rationality of memory recovery. In step 2, the adaptive memory compression rate dynamically adjusts the memory compression strategy through a comprehensive evaluation of memory fragmentation risk and page recovery priority. In Android devices, the main purpose of memory compression technology is to release more available space by compressing infrequently used or unused memory data, while avoiding the performance overhead caused by frequently writing data to disk. The adaptive compression rate model of the present invention fully considers the current memory pressure and task priority of the system, and the dynamic adjustment of the compression rate can find the best balance between performance and memory utilization. For example, when the risk of fragmentation is high and the recycling priority is not enough to effectively release memory, the adaptive compression rate will increase, thereby preferentially releasing space by compressing unused data; and when the system load is low, the compression rate will automatically decrease to reduce the impact of compression operations on system performance. This flexible compression strategy can not only significantly improve the effective utilization of memory, but also reduce the frequency of memory recycling operations, thereby improving the overall performance and stability of the system.
[0043] Step 3: Use the adaptive memory compression rate to compress the currently unused memory data of the Android device; determine whether the memory usage of a certain active process exceeds the dynamic threshold of memory allocation, and if so, further determine whether the page recycling priority exceeds the set recycling threshold, and if so, recycle the pages of the active process in the order of page generation time until the number of pages of the active process is lower than the set minimum page threshold;
[0044] Memory compression is a commonly used optimization method in modern Android devices. By compressing and storing unused or low-frequency data, more available memory space can be released. However, static compression strategies often cannot adapt to real-time changes in system load, resulting in low compression efficiency or resource waste. The present invention proposes a dynamic adaptive compression strategy by analyzing the memory fragmentation risk and page recycling priority. Specifically, when the memory is severely fragmented and the recycling priority is low, the system will appropriately increase the memory compression rate to give priority to compressing low-priority or unused page data, thereby avoiding frequent triggering of defragmentation or recycling operations; conversely, when the system load is low or the recycling priority is high, the compression rate will be reduced accordingly to reduce the impact of compression operations on performance. Through this dynamic adjustment mechanism, Android devices can find the best balance between performance and resource utilization and achieve efficient allocation of memory resources. After completing the adaptive compression of memory data, step 3 further determines whether it is necessary to recycle the pages of a specific active process through the joint judgment of the dynamic allocation threshold and the page recycling priority. The dynamic allocation threshold is the core parameter for the system to determine whether the memory allocation is overloaded, and is dynamically calculated by combining the memory fragmentation risk and the real-time system status. When the memory usage of an active process exceeds the dynamic allocation threshold, the system will further analyze the page recovery priority of the process to decide whether to trigger the page recovery operation. The calculation of the page recovery priority is based on the model in step 2, and the retention value of the page is sorted in combination with the chronological order of page generation. This sorting method embodies the principle of "prioritizing the recovery of low-frequency access pages", thereby ensuring that the key data of high-priority tasks will not be mistakenly recovered. In specific operations, the present invention recycles low-priority pages in chronological order by analyzing the page generation time one by one until the number of pages of the active process is lower than the set minimum page threshold. This design fully considers the characteristics of frequent task switching and changeable data access patterns in Android devices, and avoids excessive interference with system performance while recovering memory.
[0045] In addition, the present invention also introduces a dynamic minimum page threshold in the page recycling operation to ensure the accuracy and stability of page recycling. The minimum page threshold is a parameter that the system dynamically adjusts according to the real-time status and is used to limit the scope of the recycling operation. When the number of pages of an active process is close to the minimum page threshold, the recycling operation will be suspended to avoid negative impact on the operation of the process. For example, for a foreground application that is performing important calculations, even if its memory usage is large, the system will give priority to protecting its key data by increasing the minimum page threshold. For background tasks or processes that have not been accessed for a long time, the minimum page threshold can be appropriately lowered to free up more memory space for high-priority tasks. This priority-based dynamic threshold adjustment mechanism not only improves the efficiency of memory recycling, but also ensures the stability of high-priority tasks in a memory-constrained environment. Another important function of step 3 is to monitor and intervene in memory fragmentation. After completing the page recycling operation, the system will determine whether it is necessary to perform a defragmentation operation based on the memory fragmentation risk. If the fragmentation risk exceeds the preset defragmentation threshold, the system will trigger the memory defragmentation mechanism to further optimize the memory distribution. In Android devices, defragmentation is usually a time-consuming operation, so it needs to be triggered with caution. The present invention introduces a dynamic defragmentation threshold, combines the memory allocation dynamic threshold and the page recycling priority, and designs a delayed triggering strategy, that is, the defragmentation operation will be started only when the impact of memory fragmentation on system performance reaches a certain level. This strategy effectively avoids excessive interference of defragmentation on system performance, and at the same time ensures the efficient use of memory resources. Finally, the present invention determines whether it is necessary to uniformly recycle all memories and reallocate resources by calculating the memory allocation Boolean value. The memory allocation Boolean value is a logical judgment parameter, which is calculated by comprehensively considering the adaptive compression rate, the dynamic allocation threshold and the page recycling priority. When the memory allocation Boolean value is true, the system will give priority to releasing all memories, and according to the calculation result of the dynamic allocation threshold, the remaining memory capacity will be evenly distributed to all active processes. This global recovery and reallocation mechanism is suitable for scenarios where system memory resources are extremely tight, and can restore the stable state of the system in a short time. Compared with the traditional step-by-step recovery strategy, the global recovery mechanism of the present invention can significantly improve the efficiency of resource allocation, especially in high-load or long-term operation environments, and has important practical application value.
[0046] Step 4: If the memory fragmentation risk exceeds the set defragmentation threshold, the Android device performs memory defragmentation; calculates the memory allocation Boolean value according to the memory allocation dynamic threshold, the adaptive memory compression rate and the page recycling priority; if the memory allocation Boolean value is true, recycles all memory, and subtracts the memory allocation dynamic threshold from the total memory capacity, and then distributes the remaining memory capacity evenly to all active processes.
[0047] Memory fragmentation is a long-standing problem in the memory management of Android devices. Especially in high-load operation scenarios, memory fragmentation can lead to a shortage of continuous memory blocks, thereby limiting the allocation requirements of large tasks. The defragmentation trigger mechanism of the present invention is based on a dynamic assessment of the risk of fragmentation, which is calculated by the model in step 1 and step 2, combining the multi-dimensional analysis of the memory state entropy and the allocation priority matrix. When the memory fragmentation risk exceeds the set defragmentation threshold, the system triggers the memory defragmentation operation. It is worth noting that the defragmentation operation itself may cause a short-term fluctuation in system performance. Therefore, the present invention designs a dynamic defragmentation threshold, which intelligently determines the timing of the defragmentation operation by combining memory pressure, task priority and fragmentation distribution characteristics. For example, when the system detects that a high-priority task is about to request a large memory, if the degree of fragmentation is serious, the defragmentation threshold will be dynamically reduced, thereby giving priority to triggering the defragmentation operation to ensure the smooth execution of the task. After triggering the defragmentation, the present invention further guides the reallocation of system memory by calculating the memory allocation Boolean value. The memory allocation Boolean value is a logical judgment parameter that combines the comprehensive information of adaptive memory compression rate, dynamic allocation threshold and page recycling priority to decide whether to uniformly recycle and reallocate all memory. In the high-load scenario of Android devices, the traditional step-by-step optimization strategy often fails to meet the system's demand for rapid resource response, while the introduction of the memory allocation Boolean value enables the system to perform global optimization under specific conditions. Specifically, when the memory allocation Boolean value is true, the system will release all allocated memory resources and reallocate the remaining memory capacity to all active processes according to the currently calculated dynamic allocation threshold. This operation can not only quickly restore the system to a stable state, but also significantly improve the efficiency of resource allocation. For example, in an Android device with a memory usage rate close to saturation, if it is detected that multiple background tasks occupy a large amount of low-priority memory, and the foreground task has degraded performance due to lack of resources, at this time, through global recycling and reallocation, the resources of the low-priority tasks can be immediately released and allocated to higher-priority tasks, thereby improving the user experience.
[0048] Embodiment 2: The operation data of the Android device obtained in step 1 includes: the size of each memory block, the total memory capacity, the number of pages of each active process, the CPU usage corresponding to each active process, the real-time response time of the process, the maximum allowed process response time, the current number of dirty pages, the page miss count, the IO wait time, the maximum IO wait time, the current number of memory pages, the maximum number of memory pages, the active memory load, the maximum memory load, the number of page table entries and the maximum number of page table entries.
[0049] Specifically, first, in the acquired operation data, the size of each memory block and the total memory capacity are used to describe the spatial distribution of system memory allocation. These two sets of data are the core inputs for the calculation of memory state entropy, reflecting the uniformity and degree of disorder of memory block distribution. When the memory block size distribution is relatively discrete, for example, when there are a large number of small blocks of memory, the system entropy value will be higher, indicating that the memory allocation is not efficient enough and there may be a risk of fragmentation; and when the memory block distribution is relatively uniform, the entropy value is lower, indicating that the memory resource allocation is reasonable. In addition, by combining the number of pages and CPU usage of each active process, the load of the system can be further evaluated, which provides a dynamic adjustment capability for the entropy model. In a high-load scenario, some processes may occupy a large number of pages, significantly affecting the overall memory allocation efficiency of the system. To this end, the present invention adds the number of pages and CPU usage to the entropy calculation in the form of weights, so that the entropy value can not only describe the static characteristics of the memory distribution, but also dynamically reflect the changing trend of the system operation load. In addition, the operation data obtained in Example 2 also includes the real-time response time of the process and the maximum allowed response time. These two sets of data are used to measure the urgency of the task for memory resources. Process response time is one of the key indicators of system performance. When the actual response time of a process is close to or even exceeds the maximum allowed response time, it may indicate that the memory resources of the process are insufficient or the priority has not been reasonably allocated. The present invention integrates these data into the calculation of the priority matrix, and dynamically adjusts the allocation priority of memory resources by comparing the ratio of the real-time response time of the process to the maximum allowed response time. For example, for a process with a long response time, its priority will be increased accordingly, so that memory resources will be allocated to it first to avoid further performance degradation. The acquired operation data also includes the current number of dirty pages and page miss counts, which are important measurement indicators of memory status. Dirty pages refer to memory pages that need to be written back to storage. When the number of dirty pages is too large, it may cause frequent system write operations, thereby increasing IO waiting time and reducing system performance. The present invention monitors the number of dirty pages in real time, incorporates it into the priority matrix calculation, and is used to guide the adjustment of memory allocation strategy. For example, when the number of dirty pages is high, the priority matrix will reduce the allocation priority of new tasks, thereby leaving enough resource space for the write-back operation of dirty pages. The page miss count reflects the access frequency and scheduling efficiency of the memory page. When the number of page misses is large, it may indicate that the system memory allocation strategy needs to be optimized. By combining the page miss count with other operating data, the present invention can dynamically adjust the memory allocation strategy to give priority to reducing the occurrence of page misses. IO wait time and maximum IO wait time are another important performance indicator during the operation of Android devices, reflecting the IO bottleneck of the system during the memory scheduling process. The present invention determines whether memory scheduling has a significant impact on system performance by comparing the current IO wait time with the maximum IO wait time.If the IO waiting time is close to the maximum allowed value, it means that there may be a problem with the current memory scheduling, and the resource allocation strategy needs to be adjusted first. The relevant dimensions in the priority matrix will change accordingly. For example, to reduce IO pressure, the memory pages of low-priority tasks may be cleared first, or more available space may be released through memory compression. The current number of memory pages and the maximum number of memory pages are important data to describe the system memory allocation capacity. By calculating the ratio of the two, the intensity of memory usage can be quantified. When the number of pages is close to the maximum allowed value, the memory state entropy value will increase accordingly, indicating that the system resources are close to saturation and the memory allocation strategy needs to be optimized. The active memory load and the maximum memory load further describe the overall situation of the system load. These two sets of data are the core inputs of the load dimension in the priority matrix, and can dynamically adjust the urgency of memory resource allocation. For example, when the active memory load is close to the maximum memory load, the priority matrix will increase the allocation weight of high-priority tasks, and at the same time determine whether page recycling or defragmentation operations need to be triggered based on the change trend of the memory state entropy. Finally, the number of page table entries and the maximum number of page table entries are used to measure the efficiency of the memory management unit. These two sets of data reflect the complexity of memory mapping and scheduling pressure. When the number of page table entries approaches the maximum allowed value, it may indicate that the memory allocation strategy needs to be adjusted to reduce new mapping operations. The present invention dynamically adjusts the relevant weights of the priority matrix by combining these data, thereby optimizing memory allocation efficiency and reducing the impact of page table operations on system performance.
[0050] Example 3: In step 1, the following formula is used to calculate the memory state entropy H mem :
[0051]
[0052] Where n is the total number of memory blocks; b i is the size of the i-th memory block; B total is the total memory capacity; is the proportion of the i-th memory block to the total memory; p j is the number of pages of the jth active process; c j is the CPU usage of the jth active process; m is the number of active processes; P total The total number of pages.
[0053] Specifically, the first part of the formula is based on the concept of information entropy, which is used to describe the uniformity of memory block distribution. i The size of the total memory B total The proportion is considered as a probability distribution, through Its information entropy is calculated in the form of . Information entropy here reflects the degree of disorder of memory allocation. The higher the entropy value, the more evenly the memory blocks are distributed, and the system can use memory resources more efficiently. The lower the entropy value, the more significant the difference in memory block size. There may be a large number of fragmented small blocks of memory, resulting in reduced memory allocation efficiency. This is particularly critical for Android devices, because applications usually need to allocate larger and continuous memory blocks. Once the memory blocks are too scattered, the system will face performance bottlenecks. However, it is not enough to describe memory distribution only by information entropy, because the utilization efficiency of memory resources is also affected by the system task load. To this end, the present invention further introduces a load correction factor, expressed as where p j is the number of pages of the jth active process, c j is the corresponding CPU usage, P total is the total number of system pages. This factor reflects the dynamic changes in system load by weighting the memory page occupancy and computing resource requirements of each active process. When the number of tasks increases or the CPU usage of some processes increases significantly, the correction factor will amplify the impact of the entropy value, indicating that the current memory allocation of the system may face higher pressure; when the load is low, the correction factor will weaken the effect of the entropy value, indicating that the system is running relatively smoothly. Because the memory state of Android devices depends not only on the static distribution of memory blocks, but also on the dynamic fluctuations of task load. By combining information entropy and load correction factors, the formula achieves dual adaptation of memory status: it can accurately capture the static characteristics of memory fragmentation, and reflect the dynamic changes of system load in real time. For example, in a high-load scenario, even if the memory blocks are distributed more evenly, the correction factor will increase H due to the increase in task pressure. mem The calculated value of H indicates that the system needs to prioritize optimizing the memory allocation strategy; in low-load scenarios, even if the memory block distribution is fragmented to a certain extent, the system can temporarily suspend the optimization operation due to the reduction of the correction factor, thereby avoiding unnecessary resource consumption. mem The value not only provides a comprehensive evaluation of the current system memory status, but also provides a clear direction for the selection of subsequent memory management strategies. mem When the value is high, it indicates that the system memory allocation uniformity is poor or the task load is high. At this time, the system may need to take measures such as memory compression, page recycling or defragmentation as a priority; memWhen the value is low, it indicates that the system memory state is relatively healthy and the current allocation strategy can continue to be maintained. This dynamism and real-time performance greatly improves the memory management efficiency of Android devices in complex operating environments, especially in high-load, multi-tasking scenarios, and can significantly reduce the risk of imbalanced memory resource allocation or performance degradation. In addition, this formula is also highly adaptable. By adjusting the parameter weights in the formula, such as the entropy weight of the memory block distribution or the weight of the task load correction factor, different types of Android devices and application requirements can be adapted. For example, for devices that need to process large data sets or run complex models, the weight of the memory block distribution can be increased to give priority to reducing fragmentation; and for devices that focus on real-time and multi-task switching, the influence of the task load correction factor can be strengthened, so that memory management focuses more on the efficiency of dynamic allocation. This flexible parameter adjustment capability enables the memory state model of the present invention to be widely applicable to various Android devices and has extremely high practical value.
[0054] Example 4: In step 1, the following formula is used to construct a multidimensional allocation priority matrix M based on memory state entropy: priprity :
[0055]
[0056] Where, t is time; R p is the real-time response time of the process; R max is the maximum allowed process response time; D c is the current number of dirty pages; F c F is the page fault count; max is the page fault count threshold; I o I is the IO waiting time; max is the maximum IO waiting time; N p is the current number of memory pages; N total is the maximum number of memory pages; L m is the active memory load; L total is the maximum memory load; T p is the number of page table entries; T max is the maximum number of page table entries.
[0057] Specifically, the first dimension of the matrix introduces the time rate of change of the memory state entropy, that is, Memory state entropy H memIt describes the uniformity and stability of the system memory distribution, while its time derivative further reveals the dynamic change trend of the memory state. If the rate of change of entropy is large, it indicates that the system memory state is experiencing drastic fluctuations. For example, memory blocks are frequently allocated or released, which may lead to memory fragmentation or load imbalance. In this case, the priority matrix will assign higher weights to tasks that require stable memory states to ensure that the system can quickly resume smooth operation. In contrast, if the rate of change of entropy is low, it indicates that the memory allocation is relatively stable. At this time, the system can allow more low-priority tasks to allocate resources to improve memory utilization. At the same time, the relationship between task response time and system performance is also incorporated into the matrix, through the parameter Describes the ratio between the real-time response time of a process and its maximum allowed response time. This parameter directly reflects the urgency of the task: when the real-time response time is close to the allowed threshold, the system needs to prioritize memory resources to ensure the timeliness of the task; when the response time is far below the threshold, the system can more flexibly adjust the resource allocation priority. This design is particularly suitable for multi-tasking scenarios of Android devices, achieving a dynamic balance between user interaction, background tasks, and system processes. For example, when the foreground application needs to respond quickly to user operations, the matrix will automatically increase its priority, thereby providing users with a smooth operating experience.
[0058] The priority matrix is also passed through the parameter The distribution of dirty pages is taken into account. Dirty pages are data that the system needs to write back to storage. When the number of dirty pages increases, the IO pressure of the system will increase significantly. By incorporating the proportion of dirty pages into the matrix, the system can prioritize freeing up memory resources for write-back operations when the number of dirty pages is high, so as to avoid the impact of IO bottlenecks on system performance. This design is particularly suitable for scenarios where storage is frequently read and written, such as video stream caching or large file operations. In these cases, the priority matrix can dynamically adjust the allocation strategy to ensure that the system remains stable under high IO load. When considering the dimension of page missing, the priority matrix is adjusted through the parameter Measures the frequency of page misses. Page misses are a key issue in memory management. When the page miss count is close to the threshold, system performance may be seriously affected by frequent page scheduling operations. The matrix dynamically evaluates the pressure of page scheduling through this parameter, and prioritizes allocating more resources to related tasks when the page miss frequency is high, thereby alleviating the burden of page scheduling. At the same time, the matrix also introduces Parameter used to describe the urgency of IO waiting time. When the IO waiting time is close to the maximum value allowed by the system, the matrix will significantly increase the priority of related tasks to reduce the impact of IO delay on system response. This dynamic adjustment strategy can effectively improve the storage operation efficiency of Android devices under high load environments.
[0059] The design of the matrix also takes into full consideration the balance between the number of memory pages and the system load. The matrix evaluates the ratio of the current number of memory pages to the total number of pages, which is used to measure the tightness of memory resources. When the number of pages is close to the total capacity, the system memory load tends to be saturated. At this time, the matrix will prioritize reserving resources for critical tasks and free up memory space by recycling pages of low-priority tasks. In addition, the parameter Describes the proportion of active memory load to total load, which reflects the overall load level of the system. When the memory load approaches the limit, the matrix will dynamically adjust the resource allocation priority to prevent the system from crashing due to excessive load. Finally, the matrix contains and e -H mem Two key parameters are used to describe the global impact of memory mapping complexity and memory distribution state. The ratio of the number of page table entries to the maximum allowed number It measures the complexity of memory management. As the number of page table entries increases, the matrix will reduce the memory allocation priority of new tasks to reduce the complexity and management cost of memory mapping. The exponential decay factor As a weight correction for the overall memory state, the higher the entropy value, the more evenly distributed the memory is. However, due to the exponential decay characteristic, the value will be closer to zero, thus preventing over-reliance on the influence of a single entropy indicator.
[0060] Example 5: In step 1, the following formula is used to calculate the memory fragmentation risk R by combining the priority matrix and the running data: frag :
[0061]
[0062] Among them, det(M priority ) indicates M priority The determinant value; q is the number of memory segments; s k is the size of the kth memory segment; g k is the memory growth rate of the kth segment; G max is the maximum allowed memory growth rate; f l is the number of fragments of the first type; F total is the total fragment capacity; v is the number of fragment types.
[0063] Specifically, the core of the design of this formula is to transform the priority matrix M priorityThe determinant value is combined with the size and growth rate of the memory segment, the number and type of fragments to dynamically reflect the risk level of memory fragmentation. The determinant value of the priority matrix is the first part of the formula. By calculating the determinant of the priority matrix, the present invention integrates the multi-dimensional information of memory allocation into a scalar to describe the urgency of the system's current memory resources. The priority matrix itself has integrated multiple parameters such as the rate of change of memory state entropy, task response time, page miss, IO wait time, etc. The information of these dimensions together constitutes a comprehensive assessment of the system's demand for memory resources. When the determinant value is large, it indicates that the current system load is high and the task's demand for memory resources is more urgent. In this case, the impact of fragmentation on system performance will be further amplified. By taking the cube root of the determinant value The formula maintains the determinant's weight on the impact of fragmentation risk while avoiding nonlinear fluctuations caused by excessive values. The second part of the formula is Describes the contribution of the distribution characteristics of memory segments to the fragmentation risk. In Android devices, the size of the memory segment s k and the growth rate g k It is an important factor affecting fragmentation. Larger memory segments may cause greater obstacles to task scheduling when they are distributed discontinuously, so the formula directly weights the memory segment size. In addition, the memory segment growth rate g k Reflects the dynamic trend of memory allocation. In the form of, when the growth rate is low, the contribution of the memory segment to the fragmentation risk increases, while the growth rate is close to the maximum value allowed G max By summing the contribution of each memory segment and introducing 2 k The denominator of is used to adjust the weight of the memory segment sequence number. The formula realizes the gradual decrease of the influence on the memory segment position, which is highly consistent with the characteristics of actual memory distribution: the latter memory segments usually have less direct impact on the system performance.
[0064] The complexity of the number and types of fragments is the third important dimension of the formula, which is expressed by The impact of different types of fragmentation on the overall fragmentation risk is accumulated. In Android devices, different tasks or allocation strategies may generate different types of fragmentation, and the impact of each type of fragmentation on performance is also different. The formula accumulates the impact factor of each type of fragmentation and calculates it through The ratio of the number of normalized fragments to the total fragmentation capacity of the system dynamically quantifies the impact of fragmentation complexity on system performance. For example, when the number of a certain type of fragment is large, its contribution to the fragmentation risk increases significantly, while the impact is relatively weak when the number of fragments is small. This design enables the formula to adapt to different fragmentation distributions, especially in a multi-tasking concurrent operating environment, and can accurately describe the threat of complex fragmentation scenarios to system performance. The overall design of the formula reflects a high degree of dynamics and adaptability. It not only integrates the priority matrix, memory segment distribution characteristics and fragmentation complexity, but also reflects the overall characteristics of the system memory state through the interactive coupling between parameters. For example, in a high-load scenario, the determinant value of the priority matrix may be large, reflecting the urgency of memory resources; at the same time, if the system has multiple large memory segments with a low growth rate, the contribution of these memory segments will further increase the fragmentation risk. In addition, if the fragmentation type is complex and the number of certain fragments is large, the cumulative factor of the formula will amplify its impact, thereby increasing the overall risk R frag . This risk value can be used as a direct basis for memory optimization decisions. For example, when the risk exceeds a certain threshold, the system can prioritize defragmentation or memory compression operations. Traditional methods often only focus on static analysis of the number or size of fragments, while this formula dynamically reflects the comprehensive impact of fragmentation on system performance by combining the priority matrix and operating data. The multi-dimensional parameter design in the formula enables it to adapt to different operating states in real time, and can provide accurate fragmentation risk assessment regardless of high load or low load scenarios. At the same time, the weight adjustment and cumulative calculation in the formula also reflect a deep understanding of the actual operating characteristics of the system, making the risk calculation results more valuable for reference.
[0065] Example 6: In step 2, the following formula is used to calculate the dynamic threshold T of memory allocation according to the memory fragmentation risk: alloc :
[0066]
[0067] Among them, B base is the basic memory block size, which is the smallest memory allocation unit of Android devices; C is the memory state closed path; represents the line integral of the priority change rate along the closed path of the memory state; α is the preset weight factor; m x is the size of the xth memory mapping unit; w is the number of memory mapping units; M ref is the reference memory size, which is used to normalize the size impact of the memory mapping unit; β is the preset historical entropy change rate correction factor; t′ is the time integral variable, ranging from 0 to t; σ(H mem ) represents the standard deviation of memory state entropy.
[0068] Specifically, the first part of the formula is based on the basic memory block size B base The basic range of the allocation threshold is initially set based on the index adjustment of the memory fragmentation risk. base It is the smallest unit of memory allocation in Android devices, usually related to the hardware architecture, and is the basic parameter of memory management. The addition of memory fragmentation risk directly reflects the current fragmentation status of the system. When the fragmentation risk is high, the exponential function The formula dynamically lowers the allocation threshold and limits new memory allocation requests, thereby giving priority to alleviating the fragmentation problem; when the risk is low, the allocation threshold can be increased to allow more flexible memory allocation operations. This mechanism ensures that the system can dynamically adapt the allocation priority of memory resources according to the degree of fragmentation. The second part uses the closed path integral of the memory state Extract the changing relationship between the memory state and the priority matrix. The closed path integral describes the changing trajectory of the memory state within a specific time range, especially the impact of the priority change rate on the overall entropy of the system. When the priority matrix changes drastically, the path integral value is large, indicating that the memory state is unstable and the system may face high-frequency allocation and recycling operations. In this case, the formula adjusts this change by introducing a weight factor α, thereby dynamically lowering the allocation threshold to reduce the impact of frequent memory operations on system performance. When the path integral value is small, the system state is relatively stable, and the allocation threshold can be appropriately increased to improve memory utilization. The third part of the formula combines the size of the memory mapping unit m x and the total number w, by weighted mean The allocation threshold is adjusted in detail. The memory mapping unit is an important part of the memory management of Android devices. Its size and number directly affect the complexity and efficiency of system memory allocation. The formula increases the weight of large memory blocks on the overall allocation threshold in the form of square sum, ensuring that the system can give priority to supporting the memory requirements of large tasks; while the reference memory size M ref The introduction of normalizes the impact of the memory mapping unit, making the formula adaptable to devices with different memory sizes. The fourth part introduces the historical entropy change rate correction factor Used to adjust the allocation threshold to adapt to the long-term change trend of the system memory state. By integrating the entropy value over time, this part captures the overall fluctuation characteristics of the memory state in history. If the entropy value of the system changes dramatically over a long period of time, the correction factor value is higher and the allocation threshold is reduced accordingly, thereby avoiding the instability of memory allocation; when the entropy value changes more smoothly, the correction factor value is lower and the allocation threshold can be appropriately increased. This design is particularly suitable for Android devices with variable memory usage patterns. For example, in a multi-tasking environment with frequent switching, the correction factor can help the system predict the changing trend of the memory state and adjust the allocation strategy in advance.
[0069] Example 7: In step 2, the following formula is used to calculate the page recycling priority P by combining the priority matrix and the memory state entropy: reclaim :
[0070]
[0071] in, is the gradient of memory state entropy; The gradient of the multidimensional allocation priority matrix; ||·|| is the modulus operator; a j is the active time of the jth active process; e j is the memory usage of the jth active process.
[0072] Specifically, the first part of the formula is The directional relationship between the memory state entropy and the priority matrix is quantified in the form of describes the direction of change of the memory state, and the gradient of the priority matrix It reflects the direction of change in system resource allocation. The dot product of the two quantifies the correlation between memory state changes and priority changes through directional weights. When the dot product value is high, it indicates that the trend of memory state changes is consistent with the demand direction of resource allocation, and the recycling operation will be more efficient at this time; when the dot product value is close to zero or negative, it may indicate that the recycling operation will conflict with the resource allocation of high-priority tasks, and the recycling priority will be reduced accordingly. Through modulus length normalization, the formula avoids the influence of different gradient scales and ensures that the calculation of directional weights is unified and dynamically adaptable. The second part of the formula introduces a correction factor for historical entropy changes. By integrating the historical changes in memory state entropy, the impact of memory state fluctuations on the recycling strategy is quantified. This part is particularly suitable for scenarios where the memory state changes drastically. For example, during high-frequency task switching or large data stream processing, the memory state may experience significant fluctuations in a short period of time. These fluctuations are captured by the integral value of historical entropy and combined with the standard deviation of entropy σ(H mem ) is normalized, and this correction factor can dynamically increase or decrease the recycling priority. For example, when the historical changes in memory state entropy are large and fluctuate violently, the recycling priority will increase, prompting the system to prioritize memory recycling operations to stabilize the overall state; when the historical entropy changes are small and stable, the recycling priority will decrease, allowing the system to maintain the current memory allocation strategy. The third part of the formula is The acceleration effect of task load and entropy change is combined to dynamically evaluate the contribution of each active process to page recycling. Here, a j represents the active time of the jth active process, reflecting the running status of the task; e jis the memory usage of the process, describing the intensity of the task's demand for memory resources. The two are weighted and normalized to the total memory capacity of the system E. total , the formula derives the relative resource importance of each task. When a task is active for a long time and occupies a high memory, its relative importance increases, and the system will give priority to retaining the task's pages during the recycling operation. At the same time, the second-order time derivative of entropy It further captures the acceleration characteristics of memory state changes. If the acceleration of entropy change is large, it indicates that the system is in a period of drastic fluctuations, and the recycling operation needs to be more cautious to avoid further aggravating the instability of the memory state. Finally, the formula is passed The impact of fragmentation on page recycling is taken into account. Here, f l is the number of fragments of type l, F total is the total fragmentation capacity of the system. This part quantifies the weakening effect of the type and amount of fragments on the recycling priority in a cumulative form. When the number of a certain type of fragment is large, its impact on the recycling operation is more significant, thereby reducing the recycling priority. This design avoids the performance overhead that may be caused by frequent page recycling in the case of severe fragmentation, while ensuring that the recycling operation can alleviate the fragmentation problem of the system. Through the above multi-dimensional comprehensive calculation, the formula dynamically adjusts the page recycling priority P reclaim , enabling Android devices to make efficient memory recycling decisions in complex and changing operating environments. For example, in a high-load environment, if a task occupies a large amount of memory and has a high priority, and the system memory state changes dramatically, the recycling priority will be significantly increased, and the system will give priority to recycling pages of low-priority tasks to release resources for critical tasks; in a low-load scenario, if the historical entropy changes little and fragmentation is severe, the recycling priority will be reduced, and the system can delay the recycling operation to avoid performance interference.
[0073] Example 8: In step 2, the following formula is used to calculate the adaptive memory compression rate C according to the page recycling priority and the memory fragmentation risk: ratio :
[0074]
[0075] Among them, Ω y is the yth memory area; is the normal gradient of the memory state entropy; l c is the memory usage of layer c; L max is the maximum memory usage of all levels; z is the number of memory regions; r is the number of memory levels; × is the cross product operator.
[0076] Specifically, the core of the formula design is to dynamically balance the memory fragmentation risk R frag and page recycling priority Preclaim , these two key indicators reflect the current memory fragmentation level of the system and the efficiency of memory page recycling. In the first part of the formula, Provides a basic proportional relationship for the compression rate. When the fragmentation risk is high, it means that the memory distribution is more discontinuous. At this time, it is necessary to free up more continuous memory space by increasing the compression rate to alleviate the fragmentation problem. When the page recovery priority is high, it means that the system has taken more page recovery operations to release memory resources, and the demand for compression is reduced accordingly. Therefore, through the calculation of the logarithmic ratio, the formula can dynamically adapt to the balance between fragmentation and page recovery. When fragmentation is severe but recovery operations are insufficient, the compression rate is significantly improved; and when page recovery has played a greater role, the compression rate will be appropriately reduced to reduce the additional consumption of compression operations on system performance. At the level of memory state space distribution, the formula introduces the spatial variation of the memory state entropy gradient through regional integration. This part aims to capture the spatial unevenness of memory distribution and adjust the compression strategy accordingly. Each memory region Ω y It is a logical unit of system memory, and its entropy gradient describes the magnitude of the change in the memory state in the area. If the entropy gradient of a certain area is large, it indicates that the memory distribution in the area is more uneven, and there may be significant fragmentation problems. Through regional integration, the formula can fully quantify the contribution of each area to the overall memory compression demand. In practical applications, this design makes the compression operation more precise. For example, when the memory in a certain area is severely fragmented and other areas are relatively uniform, the system will give priority to compression operations on this area, rather than uniformly compressing all memory in a one-size-fits-all manner, thereby improving the pertinence and efficiency of compression.
[0077] The usage of the memory level is also an important factor affecting the compression strategy. The third part of the formula The compression ratio is modified by multiplying the usage of different layers to dynamically adapt to the resource load of different layers. c Close to the maximum value L maxWhen , the correction factor tends to zero, indicating that the resources of this layer are already in a tight state. At this time, the compression operation will cause great interference to the performance. The formula protects the performance of this layer by reducing the overall compression rate. When the layer usage rate is low, the correction factor is large, allowing more aggressive compression operations on the low-load layer. This design is particularly suitable for Android devices with multi-level storage architecture. For example, compression at the low-speed storage layer can free up more space for the high-speed storage layer, thereby improving the overall performance of the system. The overall structure of the formula not only reflects the multi-dimensional integration of memory status and system load, but also achieves adaptive optimization for different operating scenarios by dynamically adjusting the weights of each part. For example, in a high-load scenario, the risk of memory fragmentation is usually high, and the usage rate of the memory layer also tends to be saturated. At this time, the formula will prioritize releasing more memory resources by increasing the compression rate to provide support for high-priority tasks. In a low-load scenario, when the page recovery priority is high and the risk of fragmentation is low, the formula will reduce the compression rate, thereby reducing the impact of compression operations on system performance. This dynamic balancing mechanism ensures the flexibility of the memory compression strategy, allowing the system to maintain efficient operation under different load conditions. Traditional memory compression strategies are usually adjusted based on only a single dimension of fragmentation or memory utilization, which makes it difficult to cope with complex multi-tasking environments. This formula not only improves the intelligence level of the compression strategy, but also significantly enhances the positive impact of compression operations on system performance by incorporating multiple dimensions such as fragmentation risk, page recovery efficiency, spatial distribution characteristics, and hierarchical load into a unified model. In practical applications, such as in high-load scenarios such as large-scale game running or video editing, memory allocation requirements fluctuate greatly and fragmentation is common. This formula can quickly respond to changes in the system's memory status and dynamically adjust the compression rate to ensure the smooth execution of tasks. At the same time, when there are many background tasks, the formula can balance the relationship between page recovery and memory compression to prioritize the release of memory resources for low-priority tasks, thereby avoiding interference with foreground tasks.
[0078] Example 9: In step 4, use the following formula to calculate the memory allocation Boolean value B alloc :
[0079]
[0080] Specifically, the first part of the formula By setting the memory allocation dynamic threshold T alloc The feasibility of current memory allocation is quantified by comparing the value of s with the memory fragmentation distribution factor. Here, the memory fragmentation distribution factor is composed of the size of each memory segment s k and the growth rate g k Decide jointly and in descending order of weight Different memory segments are weighted. This design reflects the correlation between the actual contribution of memory segments and the degree of fragmentation: larger memory segments are more supportive of memory allocation when they are evenly distributed, while smaller and discretely distributed memory segments have a greater negative impact on system memory management. alloc When the value is high and the denominator is small, it means that the current memory allocation conditions of the system are relatively loose and new memory allocation operations can be accepted; on the contrary, when the denominator is large, fragmentation may significantly limit new allocation requirements, and the Boolean value tends to return "0" to prohibit further allocation. The second part of the formula is The change rate of page recycling priority and the spatial gradient of memory state entropy are cumulatively analyzed to further measure the potential impact of memory resource allocation on the overall stability of the system. reclaim Rate of change It is a key indicator used to reflect the memory compression rate C of the page recycling operation. ratio When the page recovery efficiency is low and the compression rate adjustment has limited effect, the priority change rate approaches zero, indicating that memory allocation may increase system load, so the Boolean value result is more likely to be "0". When the page recovery efficiency is high, the priority change rate will increase significantly, which signals the system to make new memory allocation operations more flexibly.
[0081] Spatial gradient integral of memory state entropy From the perspective of the spatial distribution of memory states, the uniformity and stability of the current memory resource allocation are evaluated. By performing regional integration on the gradient of the memory state entropy, the formula captures the unevenness of memory distribution, especially in different memory regions Ω y When the entropy gradient of some memory areas is large, it indicates that the memory distribution is uneven and resource allocation may lead to further fragmentation. At this time, the Boolean value is more likely to return "0" to avoid causing new allocation risks. When the entropy gradient is small, it indicates that the system memory is evenly distributed and the conditions for supporting further allocation are ideal. Through the comprehensive comparison of the above two parts, the formula returns a Boolean value B alloc, as the final decision basis for system memory allocation. When the value of the first part of the formula (allocation condition) is greater than the value of the second part (recycling and space impact assessment), the system believes that the current memory state can support new allocation operations, and the Boolean value returns "1"; otherwise, the Boolean value returns "0", and the system suspends new allocation requests to prioritize solving current memory problems. Traditional memory allocation strategies are often based on a single threshold or fixed rules, which cannot reflect the complex state of the system in real time. This formula can not only dynamically adapt to different operating scenarios, but also balance the relationship between memory allocation requirements and system stability by introducing multi-dimensional factors such as memory fragmentation distribution, page recycling efficiency, and entropy gradient distribution. For example, in a multi-task high-load scenario, if memory fragmentation is severe and page recycling efficiency is low, the formula can effectively prevent unnecessary memory allocation operations, thereby avoiding further degradation of system performance. In the case of low load and uniform memory distribution, the formula will flexibly relax the allocation conditions to maximize the utilization of memory resources. This formula is of great significance in practical applications, especially in the complex operating environment of Android devices. For example, when running large games or multimedia editing tasks, memory allocation requirements fluctuate greatly and task priorities vary significantly. The formula can accurately evaluate the current state of the system and quickly make allocation decisions as needed, thereby ensuring the stability of key tasks. At the same time, for scenarios with many background tasks, the formula dynamically adjusts the Boolean value to avoid low-priority tasks occupying too much memory resources, thereby ensuring the response speed of foreground tasks.
[0082] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
Claims
1. An efficient memory allocation and recovery method for Android devices, characterized in that: The method comprises: Step 1: Obtain the running data of the Android device, and calculate the memory state entropy based on the running data; construct a multi-dimensional allocation priority matrix based on the memory state entropy; and calculate the memory fragmentation risk by combining the priority matrix and the running data; Step 2: Calculate the dynamic threshold of memory allocation based on the memory fragmentation risk; calculate the page recovery priority based on the priority matrix and memory state entropy; calculate the adaptive memory compression rate based on the page recovery priority and memory fragmentation risk; Step 3: Use the adaptive memory compression rate to compress the currently unused memory data of the Android device; determine whether the memory usage of a certain active process exceeds the dynamic threshold of memory allocation, and if so, further determine whether the page recycling priority exceeds the set recycling threshold, and if so, recycle the pages of the active process in the order of page generation time until the number of pages of the active process is lower than the set minimum page threshold; Step 4: If the memory fragmentation risk exceeds the set defragmentation threshold, the Android device performs memory defragmentation; calculates the memory allocation Boolean value according to the memory allocation dynamic threshold, the adaptive memory compression rate and the page recycling priority; if the memory allocation Boolean value is true, recycles all memory, and subtracts the memory allocation dynamic threshold from the total memory capacity, and then distributes the remaining memory capacity evenly to all active processes.
2. The efficient memory allocation and recovery method for Android devices as claimed in claim 1, characterized in that: The operation data of the Android device obtained in step 1 includes: the size of each memory block, the total memory capacity, the number of pages of each active process, the CPU usage corresponding to each active process, the process real-time response time, the maximum allowed process response time, the current number of dirty pages, the page miss count, the IO wait time, the maximum IO wait time, the current number of memory pages, the maximum number of memory pages, the active memory load, the maximum memory load, the number of page table entries, and the maximum number of page table entries.
3. The efficient memory allocation and recovery method for Android devices as described in claim 2, characterized in that: In step 1, use the following formula to calculate the memory state entropy H mem : Where n is the total number of memory blocks; b i is the size of the i-th memory block; B total is the total memory capacity; is the proportion of the i-th memory block to the total memory; p j is the number of pages of the jth active process; c j is the CPU usage of the jth active process; m is the number of active processes; P total The total number of pages.
4. The efficient memory allocation and recovery method for Android devices as described in claim 3, characterized in that: In step 1, the following formula is used to construct a multidimensional allocation priority matrix M based on memory state entropy: priority : Where, t is time; R p is the real-time response time of the process; R max is the maximum allowed process response time; D c is the current number of dirty pages; F c F is the page fault count; max is the page fault count threshold; I o I is the IO waiting time; max is the maximum IO waiting time; N p is the current number of memory pages; N total is the maximum number of memory pages; L m is the active memory load; L total is the maximum memory load; T p is the number of page table entries; T max is the maximum number of page table entries.
5. The efficient memory allocation and recovery method for Android devices as described in claim 4, characterized in that: In step 1, use the following formula to calculate the memory fragmentation risk R by combining the priority matrix and the running data: frag : Among them, det(M priority ) indicates M priority The determinant value; q is the number of memory segments; s k is the size of the kth memory segment; g k is the memory growth rate of the kth segment; G max is the maximum allowed memory growth rate; f l is the number of fragments of the first type; F total is the total fragment capacity; v is the number of fragment types.
6. The efficient memory allocation and recovery method for Android devices as claimed in claim 5, characterized in that: In step 2, use the following formula to calculate the dynamic threshold T of memory allocation based on the memory fragmentation risk: alloc : Among them, B base is the basic memory block size, which is the smallest memory allocation unit of Android devices; C is the memory state closed path; represents the line integral of the priority change rate along the closed path of the memory state; α is the preset weight factor; m x is the size of the xth memory mapping unit; w is the number of memory mapping units; M ref is the reference memory size, which is used to normalize the size impact of the memory mapping unit; β is the preset historical entropy change rate correction factor; t′ is the time integral variable, ranging from 0 to t; σ(H mem ) represents the standard deviation of memory state entropy.
7. The efficient memory allocation and recovery method for Android devices as claimed in claim 6, characterized in that: In step 2, the following formula is used to combine the priority matrix and memory state entropy to calculate the page recycling priority P reclaim : in, is the gradient of memory state entropy; The gradient of the multidimensional allocation priority matrix; ||·|| is the modulus operator; a j is the active time of the jth active process; e j is the memory usage of the jth active process.
8. The efficient memory allocation and recovery method for Android devices as claimed in claim 7, characterized in that: In step 2, the following formula is used to calculate the adaptive memory compression rate C based on the page recycling priority and memory fragmentation risk: ratio : Among them, Ω y is the yth memory area; is the normal gradient of the memory state entropy; l c is the memory usage of layer c; L max is the maximum memory usage of all levels; z is the number of memory regions; r is the number of memory levels; × is the cross product operator.
9. The efficient memory allocation and recovery method for Android devices as claimed in claim 8, characterized in that: In step 4, use the following formula to calculate the memory allocation Boolean value B alloc :
Citation Information
Patent Citations
Memory management method and device, storage medium and electronic device
CN110888746A
Equipment control method and device, storage medium and electronic device
CN110895492A
Dynamic memory allocation method and system
CN111858064A
Self-Adaptive Continuous Flushing of Pages to Disk
US20180307570A1
Memory management method, computer device and storage medium
WO2024109076A1
Cited By
Streaming data storage method combined with adaptive compression
CN120295582A
Multi-level storage space dynamic recovery method and electronic equipment
CN120743206A
A multi-level storage space dynamic recycling method and an electronic device
CN120743206B