A memory allocation and recycling method for an Android device
By calculating memory state entropy and a multi-dimensional allocation priority matrix, and combining memory fragmentation risk and page reclamation priority, the memory allocation and reclamation strategies are dynamically adjusted, solving the memory management problem of Android devices under high load and multi-tasking environments, and achieving efficient and stable memory resource utilization.
Patent Information
- Application Number
- CN202411708779.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2044-11-27
AI Technical Summary
Existing Android device memory management technologies cannot meet dynamic demands under high load and multitasking environments, leading to performance degradation or even system crashes. In particular, they cannot effectively release contiguous memory when memory fragmentation is severe, and traditional memory allocation and reclamation strategies lack a comprehensive assessment of the overall system state.
By calculating memory state entropy and a multidimensional allocation priority matrix, combined with memory fragmentation risk and page reclamation priority, the memory allocation threshold and adaptive memory compression rate are dynamically adjusted to optimize the memory defragmentation strategy and achieve adaptive memory management.
It significantly improves memory resource utilization efficiency, dynamically adapts to changes in system state, ensures the performance of high-priority tasks, optimizes resource allocation for low-priority tasks, and improves system stability and task execution efficiency.
Smart Images

Figure CN119645634B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of memory processing, and particularly relates to an efficient memory allocation and recovery method for an Android device. BACKGROUND
[0002] With the rapid popularization of smart devices, especially mobile smart terminals represented by Android devices, the memory management technology becomes a key factor affecting the performance of the device, user experience and energy consumption. Android devices usually need to handle multitasking concurrency, complex resource scheduling and real-time response to user needs, which puts high requirements on the allocation and management of memory resources. However, the existing memory management technology still has obvious shortcomings in dealing with complex and changeable running scenes, especially in a high-load, multi-task environment. The static processing method of traditional methods for memory allocation and recovery cannot meet the dynamic needs of the system, resulting in performance degradation or even system crash.
[0003] Currently, memory management technologies for Android devices mainly include the following core aspects: memory allocation strategies, page reclamation mechanisms, defragmentation, and memory compression techniques. In existing technologies, memory allocation in Android devices typically relies on fixed thresholds or simple priority rules. For example, the Least Recently Used (LRU) algorithm is a widely used strategy, which is simple and efficient by prioritizing the release of recently unused memory pages. However, this method fails to fully consider the global state of memory allocation, such as memory fragmentation, dynamic task load, and overall system pressure, often resulting in low memory utilization or unmet memory requirements for critical tasks. Furthermore, the static nature of the LRU algorithm makes it difficult to adapt to dynamic changes in multi-task concurrent environments, especially when running high-load applications, where its performance bottleneck becomes increasingly apparent. Page reclamation is a critical operation in memory management. Existing technologies often employ tiered reclamation strategies, such as prioritizing the cleanup of background task pages or releasing cached and dirty pages. However, this method often only considers task priority or page type, lacking a comprehensive assessment of the global system state. Specifically, when the system load is high and fragmentation is severe, traditional reclamation mechanisms may fail to release enough contiguous memory, leading to performance degradation of foreground tasks or even application crashes. Furthermore, existing page reclamation algorithms typically consider only a single-dimensional metric, such as page access frequency, when calculating reclamation priority, failing to integrate multi-dimensional factors such as memory distribution, task load, and system pressure. This significantly limits reclamation efficiency and accuracy. Memory fragmentation is a persistent problem in Android device memory management, especially after long-term operation, where numerous discontinuous small memory blocks severely impact the memory allocation requirements of large tasks. In existing technologies, memory defragmentation operations are usually periodic or triggered when fragmentation exceeds a fixed threshold. However, this static triggering mechanism lacks dynamic awareness of memory status, potentially leading to delayed defragmentation operations and impacting system performance. Moreover, defragmentation itself is a time-consuming process with a significant impact on system performance, and existing technologies lack intelligent optimization of its triggering conditions and execution scope. Summary of the Invention
[0004] In view of this, the main objective of this invention is to provide an efficient memory allocation and reclamation method for Android devices. This multi-dimensional, dynamically optimized memory management method not only significantly improves the utilization efficiency of memory resources but also dynamically adapts to changes in system state in complex operating scenarios, ensuring the execution performance of high-priority tasks while optimizing resource allocation for low-priority tasks. This efficient memory management technology is of great significance in improving user experience, optimizing device performance, and extending device lifespan, especially in environments involving complex tasks, high load operation, and multi-task concurrency, demonstrating significant application value and technical advantages.
[0005] To achieve the above objectives, the technical solution of the present invention is implemented as follows:
[0006] An efficient memory allocation and reclamation method for Android devices, the method comprising:
[0007] Step 1: Obtain the running data of the Android device, calculate the memory state entropy based on the running data; construct a multi-dimensional allocation priority matrix based on the memory state entropy; combine the priority matrix and the running data to calculate the memory fragmentation risk.
[0008] Step 2: Calculate the dynamic threshold for memory allocation based on the memory fragmentation risk level; calculate the page reclamation priority by combining the priority matrix and memory state entropy; calculate the adaptive memory compression rate based on the page reclamation priority and the memory fragmentation risk level.
[0009] Step 3: Compress the currently unused memory data of the Android device using an adaptive memory compression ratio; determine whether the memory usage of an active process exceeds the dynamic threshold of memory allocation. If so, further determine whether the page recycling priority exceeds the set recycling threshold. If so, recycle the pages of the active process in the order of their 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 based on the dynamic memory allocation threshold, adaptive memory compression ratio, and page reclamation priority. If the memory allocation boolean value is true, all memory is reclaimed, and the remaining memory capacity is evenly distributed among all active processes after subtracting the dynamic memory allocation threshold from the total memory capacity.
[0011] Furthermore, the Android device's operational data obtained in step 1 includes: the size of each memory block, total memory capacity, number of pages per active process, CPU utilization for each active process, real-time process response time, maximum allowed process response time, current number of dirty pages, page miss count, IO wait time, maximum IO wait time, current number of memory pages, maximum number of memory pages, active memory load, maximum memory load, number of page table entries, and maximum number of page table entries.
[0012] Furthermore, in step 1, the memory state entropy is calculated using the following formula. :
[0013] ;
[0014] in, This represents the total number of memory blocks. For the first The size of each memory block; This represents the total memory capacity. For the first The percentage of total memory occupied by each memory block; For the first Number of pages per active process; For the first CPU utilization of each active process; Number of activity processes; This represents the total number of pages.
[0015] Furthermore, in step 1, a multidimensional allocation priority matrix is constructed based on memory state entropy using the following formula. :
[0016] ;
[0017] in, For time; This refers to the real-time response time of the process. This is the maximum allowed process response time; This represents the current number of dirty pages. Count the number of missing pages; This is the threshold for counting missing pages; For I / O wait time; Maximum I / O wait time; This represents the current number of memory pages. This represents the maximum number of memory pages. For active memory load; Maximum memory load; This refers to the number of page table entries; This represents the maximum number of page table entries.
[0018] Furthermore, in step 1, the memory fragmentation risk is calculated using the following formula, combining the priority matrix and runtime data. :
[0019] ;
[0020] in, express The determinant value; This refers to the number of memory segments. For the first The size of each memory segment; For the first The memory growth rate of the segment; This represents the maximum allowed memory growth rate. For the first Number of fragments; Total fragment capacity; Number of fragment types;
[0021] Furthermore, in step 2, the dynamic threshold for memory allocation is calculated based on the memory fragmentation risk using the following formula. :
[0022] ;
[0023] in, The base memory block size is the smallest unit of memory allocation in an Android device. For closed paths of memory states; The line integral representing the rate of change of priority along a closed path of memory states; These are preset weighting factors; For the first The size of a memory-mapped unit; This refers to the number of memory-mapped units; The reference memory size is used to normalize the impact of the size of the memory-mapped unit; This is a preset correction factor for the rate of change of historical entropy; is a time integral variable, with a value range from 0 to t; The standard deviation of memory state entropy.
[0024] Furthermore, the page reclamation priority is calculated using the following formula, combining the priority matrix and memory state entropy. :
[0025] ;
[0026] in, The gradient of the memory state entropy; The gradient of the multidimensional priority assignment matrix; Modulo length operator; For the first The active time of each activity process; For the first Memory usage of each active process.
[0027] Furthermore, in step 2, the adaptive memory compression ratio is calculated using the following formula, based on page reclamation priority and memory fragmentation risk. :
[0028] ;
[0029] in, For the first One memory region; The normal gradient of the memory state entropy; For the first Layer memory usage; This represents the maximum memory usage across all levels. This represents the number of memory regions. This refers to the number of memory levels. This is the cross product operator.
[0030] Furthermore, in step 4, the Boolean value for memory allocation is calculated using the following formula. :
[0031] .
[0032] By adopting the above technical solution, this invention has the following beneficial effects: Compared with traditional memory management methods that rely solely on static parameters such as memory occupancy or task priority, this invention comprehensively reflects the distribution and utilization efficiency of memory resources by combining memory state entropy with dynamic weights of memory block size, task page count, and system load. For example, in scenarios with uneven memory block distribution and large load fluctuations, the dynamic change in entropy can effectively prompt the system to adjust its 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 assessment mechanism for memory fragmentation risk, this invention can monitor the distribution of system memory fragmentation in real time and determine whether to trigger defragmentation operations based on the level of risk. Compared with traditional defragmentation methods triggered by periodic or static thresholds, the dynamic fragmentation risk assessment of this invention can handle fragmentation problems more promptly and effectively, avoiding the lag of defragmentation operations and reducing unnecessary performance overhead, thereby providing a more stable operating environment for Android devices. This invention proposes an adaptive memory compression strategy that dynamically adjusts the memory compression rate by combining multiple factors such as memory fragmentation risk, page reclamation efficiency, and system load. This method not only improves memory compression efficiency but also significantly reduces the negative impact of compression operations on system performance. In practical applications, the adaptive compression strategy of this invention can quickly respond to changes in system memory status. For example, in high-load scenarios, it prioritizes compressing unused data to free up space, while in low-load scenarios, it reduces the compression frequency, thus finding the optimal 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 scenarios. This invention optimizes the target selection process for page reclamation by introducing a dynamic calculation method for page reclamation priority. Traditional page reclamation strategies are usually based on a single indicator, such as page access frequency or task priority, while ignoring the complexity of the overall system memory status and task load. The page reclamation priority method of this invention uses multi-dimensional analysis to comprehensively consider the value of the page, the importance of the task, and the current system load, thereby accurately identifying the pages that need to be reclaimed. This method ensures the memory requirements of critical tasks while maximizing the release of resources for low-priority tasks, providing a more stable memory guarantee for system operation. This invention also introduces a Boolean value calculation mechanism for memory allocation in the final decision-making process. This mechanism dynamically determines whether to allow a new memory allocation operation by dually evaluating the impact of memory allocation conditions and system state. By comprehensively considering the impact of dynamic allocation thresholds, page reclamation priority, and memory fragmentation distribution, the Boolean value decision mechanism of this 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 needs in high-concurrency, multi-tasking environments, and can effectively improve system stability and task execution efficiency. Attached Figure Description
[0033] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0034] Figure 1 This is a schematic diagram of the method flow for an efficient memory allocation and reclamation method for Android devices provided in an embodiment of the present invention. Detailed Implementation
[0035] The method of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0036] Example 1, Reference Figure 1 A method for efficient memory allocation and reclamation for Android devices, the method comprising:
[0037] Step 1: Obtain the running data of the Android device, calculate the memory state entropy based on the running data; construct a multi-dimensional allocation priority matrix based on the memory state entropy; combine the priority matrix and the running data to calculate the memory fragmentation risk.
[0038] In Android devices, the size and distribution of each memory block directly affect the overall operating state of the system. If the size distribution of memory blocks is too discrete (i.e., significant memory fragmentation), the system may encounter resource scheduling difficulties due to the inability to allocate contiguous memory for large tasks. Conversely, when the memory block distribution is relatively uniform, the system's allocation efficiency is higher and its operation is more stable. Therefore, memory state entropy is designed as a quantitative indicator to describe the distribution characteristics of memory block sizes within the total memory capacity. Specifically, this invention collects current memory allocation data of the device, treats the proportion of memory block sizes as a probability distribution, and calculates memory state entropy based on this distribution. The level of entropy directly reflects the degree of disorder in the system's memory allocation. In the calculation of entropy, this invention specifically considers the multi-tasking characteristics of Android devices, introducing dynamic weights to correct the entropy value. In Android devices, different processes have different memory resource requirements during runtime, and these requirements are usually related to their page count and CPU utilization. For example, a high-priority process that consumes a large amount of memory and has a large number of pages will have a greater impact on the system load. To more accurately assess memory status, this invention designs a weighted entropy model that incorporates system load. The number of pages and CPU utilization of each process are used as weighting factors, working in conjunction with memory block distribution to calculate the entropy value. Specifically, by calculating the weighted average of the number of pages and CPU utilization of all active processes, this invention constructs a factor reflecting the intensity of system load. This factor is then combined with the traditional entropy model, allowing the entropy calculation to reflect not only the spatial characteristics of memory allocation but also the dynamic changes in system load. For example, when an Android device runs multiple background tasks, low-priority tasks typically consume less memory and have a smaller impact, while high-priority tasks have fluctuating memory requirements. In this case, traditional entropy calculations might only reflect the uniformity of memory block distribution, ignoring the impact of these memory blocks on actual system performance. This invention, by incorporating the system load factor, makes the entropy value more meaningful and better guides subsequent memory optimization strategies. In this process, the calculation of memory state entropy also fully considers changes over time, i.e., the dynamic nature of memory distribution. By analyzing the trend of entropy over time, we can further determine whether the system is in a state of efficient memory usage, thus providing a basis for decision-making for operations such as memory defragmentation or page reclamation.
[0039] Based on the calculation results of memory state entropy, this invention further constructs a multi-dimensional allocation priority matrix to comprehensively evaluate the urgency and rationality of memory resource allocation. The priority matrix is designed based on several key parameters, including the rate of change of memory entropy, page miss rate, IO wait time, and system response latency. These parameters collectively reflect the memory resource requirements of Android devices under different operating states. Each element of the priority matrix is a quantitative description of a specific 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, this invention achieves a comprehensive quantification of the urgency of memory allocation and provides precise priority ranking for memory compression and page reclamation in subsequent steps. Traditional memory management schemes often use fixed rules to allocate resources, lacking sensitivity to real-time changes and prone to instability under high load or sudden situations. This invention, by updating the priority matrix in real time, enables the memory management strategy to quickly adapt to changes in system state. For example, when a large number of page misses occur in the system, the priority matrix automatically increases the weight of the page miss rate, thereby prioritizing the allocation of memory resources to alleviate this problem. Meanwhile, other dimensions in the matrix (such as response latency and I / O wait time) are also adjusted according to the current system load to ensure global optimization of memory management decisions. In practical applications, memory state entropy and the priority matrix together constitute the core of Android device memory management decisions. Entropy provides a global quantitative description of the memory distribution state, while the priority matrix refines this global information into specific allocation strategies through multi-dimensional weight analysis. The combination of the two enables this invention to quickly respond to memory allocation needs in complex operating environments, while ensuring efficient utilization of memory resources by dynamically adjusting weights and parameters. For example, in high-load operating environments, the trend of entropy changes can indicate whether the system needs to perform memory defragmentation, while the priority matrix can further determine which tasks should be prioritized for resource allocation. This multi-dimensional, multi-level decision-making framework provides strong technical support for Android device memory management, significantly improving system operating efficiency and stability.
[0040] Step 2: Calculate the dynamic threshold for memory allocation based on the memory fragmentation risk level; calculate the page reclamation priority by combining the priority matrix and memory state entropy; calculate the adaptive memory compression rate based on the page reclamation priority and the memory fragmentation risk level.
[0041] One of the main problems facing memory allocation in Android devices is memory fragmentation, where discontinuous small memory blocks distributed throughout the memory space prevent sufficient contiguous space from being allocated for large tasks. The risks of fragmentation extend beyond reduced memory utilization; they significantly impact system response performance under high load. This invention calculates a key indicator—fragmentation risk—by analyzing the distribution characteristics, growth trends, and number of fragments in memory blocks. The fragmentation risk directly affects the calculation of the dynamic threshold for subsequent memory allocation. Its relationship with system performance is non-linear; the higher the risk, the more vulnerable the system's stability. Adjusting the dynamic threshold effectively reduces the negative impact of fragmentation. Calculating the dynamic threshold for memory allocation is a core step in memory optimization; it's a dynamically adjusted parameter that comprehensively considers the current system state, historical trends, and fragmentation risk. In Android devices, different application tasks have varying memory requirements. For example, foreground applications may suddenly increase memory demands during user interaction, while background tasks typically have lower priority and relatively stable memory needs. This invention introduces a dynamic threshold to differentiate the competitive capabilities of high-priority and low-priority tasks in memory allocation. In this process, memory state entropy serves as a key reference, characterizing the current level of disorder in memory allocation; the dimensions of the priority matrix further refine the distribution of the urgency of different tasks and system pressure. By combining these data, a dynamic threshold is designed as a real-time adjustable indicator. When the fragmentation risk is high, the dynamic threshold decreases, thereby limiting new memory allocations and prioritizing defragmentation and memory compression; conversely, when the system load is low and the fragmentation level is low, the dynamic threshold increases accordingly to support more flexible memory allocation operations.
[0042] Meanwhile, the page reclamation priority calculation method proposed in this invention provides a scientific basis for memory reclamation operations through further analysis of memory state and priority matrix. In Android devices, memory reclamation is often used to free up space to meet more urgent task requirements; therefore, reclamation operations need to balance timeliness and rationality. The calculation of page reclamation 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 reclamation priority will be relatively high, while critical pages of high-priority tasks will be retained first. In addition, this invention further optimizes the calculation of reclamation priority by analyzing the second derivative of memory entropy, i.e., the acceleration of memory state changes. In cases of large memory fluctuations or rapid changes in system load, the introduction of the second derivative can more accurately determine which pages should be reclaimed first, thereby improving the efficiency and rationality of memory reclamation. In step 2, the adaptive memory compression rate dynamically adjusts the memory compression strategy through a comprehensive evaluation of memory fragmentation risk and page reclamation priority. In Android devices, the main purpose of memory compression technology is to free up more available space by compressing infrequently used or unused memory data, while avoiding the performance overhead caused by frequent data writes to disk. The adaptive compression ratio model of this invention fully considers the current memory pressure and task priorities of the system. The dynamic adjustment of the compression ratio can find the optimal balance between performance and memory utilization. For example, when the fragmentation risk is high and the reclamation priority is insufficient to effectively release memory, the adaptive compression ratio increases, thus prioritizing the release of space by compressing unused data; while when the system load is low, the compression ratio automatically decreases to reduce the impact of compression operations on system performance. This flexible compression strategy not only significantly improves the effective utilization of memory but also reduces the frequency of memory reclamation operations, thereby improving the overall performance and stability of the system.
[0043] Step 3: Compress the currently unused memory data of the Android device using an adaptive memory compression ratio; determine whether the memory usage of an active process exceeds the dynamic threshold of memory allocation. If so, further determine whether the page recycling priority exceeds the set recycling threshold. If so, recycle the pages of the active process in the order of their generation time until the number of pages of the active process is lower than the set minimum page threshold.
[0044] Memory compression is a common optimization technique in modern Android devices. By compressing and storing unused or infrequently used data, more available memory space can be freed up. However, static compression strategies often cannot adapt to real-time changes in system load, leading to low compression efficiency or resource waste. This invention proposes a dynamic adaptive compression strategy by analyzing memory fragmentation risk and page reclamation priority. Specifically, when memory fragmentation is severe and reclamation priority is low, the system will appropriately increase the memory compression ratio to prioritize compressing low-priority or unused page data, thereby avoiding frequent triggering of defragmentation or reclamation operations. Conversely, when system load is low or reclamation priority is high, the compression ratio will decrease accordingly to reduce the impact of compression operations on performance. Through this dynamic adjustment mechanism, Android devices can find the optimal balance between performance and resource utilization, achieving efficient allocation of memory resources. After completing the adaptive compression of memory data, step 3 further determines whether pages of specific active processes need to be reclaimed through a joint judgment of dynamic allocation threshold and page reclamation priority. The dynamic allocation threshold is the core parameter for the system to determine whether memory allocation is overloaded, and it is dynamically calculated by combining memory fragmentation risk and real-time system status. When the memory usage of an active process exceeds the dynamic allocation threshold, the system further analyzes the page reclamation priority of that process to determine whether to trigger a page reclamation operation. The calculation of page reclamation priority is based on the model in step 2, ranking the retention value of pages according to their creation time. This ranking method reflects the principle of "prioritizing the reclamation of low-frequency accessed pages," thus ensuring that critical data from high-priority tasks is not mistakenly reclaimed. In specific operation, this invention analyzes the page creation time one by one, reclamating low-priority pages in chronological order until the number of pages for the active process falls below the set minimum page threshold. This design fully considers the characteristics of frequent task switching and varied data access patterns in Android devices, avoiding excessive interference with system performance while reclamating memory.
[0045] Furthermore, this invention introduces a dynamic minimum page threshold in the page reclamation operation to ensure the accuracy and stability of page reclamation. The minimum page threshold is a parameter dynamically adjusted by the system based on real-time status, used to limit the scope of the reclamation operation. When the number of pages of an active process approaches the minimum page threshold, the reclamation operation will be paused to avoid negatively impacting the process's operation. For example, for a foreground application performing important calculations, even if its memory usage is large, the system will prioritize protecting its critical 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 reclamation but also ensures the stability of high-priority tasks in memory-constrained environments. Another important function of step 3 is the monitoring and intervention of memory fragmentation. After completing the page reclamation operation, the system will determine whether to perform a defragmentation operation based on the memory fragmentation risk level. If the fragmentation risk level exceeds the preset defragmentation threshold, the system will trigger the memory defragmentation mechanism to further optimize memory distribution. In Android devices, defragmentation is usually a time-consuming operation, so it needs to be triggered with caution. This invention introduces a dynamic defragmentation threshold, combined with a dynamic memory allocation threshold and page reclamation priority, to design a delayed-triggered strategy. Defragmentation is only initiated when the impact of memory fragmentation on system performance reaches a certain level. This strategy effectively avoids excessive interference from defragmentation on system performance while ensuring efficient utilization of memory resources. Finally, this invention determines whether all memory needs to be uniformly reclaimed and resources reallocated through the calculation of a memory allocation Boolean value. The memory allocation Boolean value is a logical judgment parameter calculated by comprehensively considering adaptive compression ratio, dynamic allocation threshold, and page reclamation priority. When the memory allocation Boolean value is true, the system will prioritize releasing all memory and, according to the calculation result of the dynamic allocation threshold, evenly distribute the remaining memory capacity to all active processes. This global reclamation and reallocation mechanism is suitable for scenarios with extremely scarce system memory resources and can restore the system to a stable state in a short time. Compared with traditional gradual reclamation strategies, the global reclamation mechanism of this invention can significantly improve the efficiency of resource allocation, especially in high-load or long-term operating environments, and has significant 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 based on the dynamic memory allocation threshold, adaptive memory compression ratio, and page reclamation priority. If the memory allocation boolean value is true, all memory is reclaimed, and the remaining memory capacity is evenly distributed among all active processes after subtracting the dynamic memory allocation threshold from the total memory capacity.
[0047] Memory fragmentation is a long-standing problem in Android device memory management, especially under high-load scenarios. Memory fragmentation leads to a scarcity of contiguous memory blocks, thus limiting the allocation requirements of large tasks. The defragmentation triggering mechanism of this invention is based on a dynamic assessment of fragmentation risk, calculated by the model in steps 1 and 2, combining multi-dimensional analysis of memory state entropy and allocation priority matrix. When the memory fragmentation risk exceeds a set defragmentation threshold, the system triggers a memory defragmentation operation. It is worth noting that the defragmentation operation itself may cause temporary fluctuations in system performance. Therefore, this invention designs a dynamic defragmentation threshold, intelligently determining 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 amount of memory, if the fragmentation level is severe, the defragmentation threshold will be dynamically lowered, thus triggering the defragmentation operation first to ensure the smooth execution of the task. After triggering defragmentation, this invention further guides the reallocation of system memory through the calculation of memory allocation Boolean values. The memory allocation boolean value is a logical judgment parameter that combines information from adaptive memory compression ratio, dynamic allocation threshold, and page reclamation priority to determine whether to uniformly reclaim and reallocate all memory. In high-load scenarios on Android devices, traditional incremental optimization strategies often fail to meet the system's need for rapid resource response. The introduction of the memory allocation boolean value allows the system to perform global optimization under specific conditions. Specifically, when the memory allocation boolean value is true, the system releases all allocated memory resources and, based on the currently calculated dynamic allocation threshold, reallocates the remaining memory capacity to all active processes. This operation not only quickly restores the system to a stable state but also significantly improves resource allocation efficiency. For example, in an Android device with near-saturated memory usage, if multiple background tasks are detected consuming a large amount of low-priority memory while foreground tasks experience performance degradation due to resource shortages, global reclamation and reallocation can immediately release the resources of low-priority tasks and allocate them to higher-priority tasks, thereby improving the user experience.
[0048] Example 2: The Android device running data obtained in step 1 includes: the size of each memory block, total memory capacity, number of pages for each active process, CPU utilization for each active process, real-time process response time, maximum allowed process response time, current number of dirty pages, page miss count, IO wait time, maximum IO wait time, current number of memory pages, maximum number of memory pages, active memory load, maximum memory load, number of page table entries, and maximum number of page table entries.
[0049] Specifically, firstly, the size of each memory block and the total memory capacity in the acquired runtime data are used to describe the spatial distribution of system memory allocation. These two sets of data are the core inputs for memory state entropy calculation, reflecting the uniformity and disorder of memory block distribution. When the memory block size distribution is relatively discrete, such as when there are a large number of small memory blocks, the system entropy value will be high, indicating that memory allocation is not efficient and there may be a risk of fragmentation; while when the memory block distribution is relatively uniform, the entropy value is low, indicating that memory resource allocation is reasonable. In addition, by combining the number of pages and CPU utilization of each active process, the system load can be further evaluated, which provides dynamic adjustment capability for the entropy model. In high-load scenarios, some processes may occupy a large number of pages, significantly affecting the overall memory allocation efficiency of the system. To this end, this invention incorporates the number of pages and CPU utilization into the entropy calculation in the form of weights, so that the entropy value can not only describe the static characteristics of memory distribution, but also dynamically reflect the changing trend of system runtime load. In addition, the runtime data acquired in Example 2 also includes the process real-time response time and the maximum allowed response time, which are used to measure the urgency of tasks for memory resources. Process response time is a key indicator of system performance. When a process's actual response time approaches or exceeds the maximum allowed response time, it may indicate insufficient memory resources or improper priority allocation. This invention integrates this data into the calculation of the priority matrix, dynamically adjusting the allocation priority of memory resources by comparing the ratio of a process's real-time response time to its maximum allowed response time. For example, processes with longer response times will have their priority increased, thus allocating memory resources to them first and preventing further performance degradation. The acquired runtime data also includes the current number of dirty pages and the page miss count, both important metrics for memory status. Dirty pages refer to memory pages that need to be written back to storage. When the number of dirty pages is too high, it may lead to frequent system write operations, increasing I / O wait time and reducing system performance. This invention monitors the number of dirty pages in real time and incorporates it into the priority matrix calculation to guide adjustments to the memory allocation strategy. For example, when the number of dirty pages is high, the priority matrix will lower the allocation priority for new tasks, thus reserving sufficient resource space for the write-back operations of dirty pages. Page miss count reflects the frequency of memory page access and scheduling efficiency. A high number of page misses may indicate that the system's memory allocation strategy needs optimization. By combining page miss count with other runtime data, this invention can dynamically adjust the memory allocation strategy, prioritizing the reduction of page misses. I / O wait time and maximum I / O wait time are another important performance indicator during Android device operation, reflecting the I / O bottleneck in the system's memory scheduling process. This invention compares the current I / O wait time with the maximum I / O wait time to determine whether memory scheduling has a significant impact on system performance.If the I / O wait time approaches the maximum allowable value, it indicates a potential problem with the current memory scheduling, requiring a priority adjustment to the resource allocation strategy. The relevant dimensions in the priority matrix will change accordingly. For example, to reduce I / O pressure, the memory pages of low-priority tasks might be prioritized for cleanup, or more available space might be freed up through memory compaction. The current number of memory pages and the maximum number of memory pages are crucial data describing the system's memory allocation capacity; calculating their ratio quantifies the level of memory usage pressure. When the number of pages approaches the maximum allowable value, the memory state entropy value increases accordingly, indicating that system resources are nearing saturation and the memory allocation strategy needs optimization. Active memory load and maximum memory load further describe the overall system load. These two sets of data are core inputs to the load dimension of the priority matrix, dynamically adjusting the urgency of memory resource allocation. For example, when the active memory load approaches the maximum memory load, the priority matrix will increase the allocation weight for high-priority tasks, while the trend of memory state entropy changes will determine whether page reclamation or defragmentation operations need to be triggered. 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. This invention optimizes memory allocation efficiency and reduces the impact of page table operations on system performance by dynamically adjusting the relevant weights of the priority matrix based on this data.
[0050] Example 3: In step 1, the memory state entropy is calculated using the following formula. :
[0051] ;
[0052] in, This represents the total number of memory blocks. For the first The size of each memory block; This represents the total memory capacity. For the first The percentage of total memory occupied by each memory block; For the first Number of pages per active process; For the first CPU utilization of each active process; Number of activity processes; This represents the total number of pages.
[0053] Specifically, the first part of the formula is based on the concept of information entropy, used to describe the uniformity of memory block distribution. (Memory block) Size of total memory The proportion is considered a probability distribution, through... The information entropy is calculated in the form of [formula missing]. Information entropy reflects the degree of disorder in memory allocation. A higher entropy value indicates a more uniform distribution of memory blocks, allowing the system to utilize memory resources more efficiently. A lower entropy value indicates significant differences in memory block sizes, potentially leading to a large number of fragmented small memory blocks and reduced memory allocation efficiency. This is particularly critical for Android devices, as applications typically require the allocation of large and contiguous memory blocks; if these blocks are too scattered, the system will face performance bottlenecks. However, describing memory distribution solely through information entropy is insufficient, as memory resource utilization efficiency is also affected by system task load. Therefore, this invention further introduces a load correction factor, expressed as [formula missing]. ,in It is the first The number of pages per active process. It corresponds to the CPU utilization rate. This is the total number of system pages. This factor reflects the dynamic changes in system load by weighting the memory page usage and computing resource requirements of each active process. When the number of tasks increases or the CPU utilization of certain processes increases significantly, the correction factor amplifies the impact of entropy, indicating that the current memory allocation of the system may be facing higher pressure; while at low loads, the correction factor weakens the effect of entropy, indicating that the system is running relatively smoothly. This is because the memory state of an Android device depends not only on the static distribution of memory blocks but also on the dynamic fluctuations of task load. By combining information entropy and the load correction factor, the formula achieves a dual adaptation to the memory state: it can accurately capture the static characteristics of memory fragmentation and reflect the dynamic changes in system load in real time. For example, in high-load scenarios, even if the memory block distribution is relatively uniform, the correction factor will increase due to the increased task pressure. The calculated value indicates that the system needs to prioritize optimizing the memory allocation strategy; however, in low-load scenarios, even if there is some fragmentation in the memory block distribution, the system can postpone optimization operations due to the reduction in the correction factor, thereby avoiding unnecessary resource consumption. The value calculated using this formula... The value not only provides a comprehensive assessment of the current system memory state, but also offers clear direction for the selection of subsequent memory management strategies. When A high value indicates poor uniformity in system memory allocation or high task load. In this case, the system may need to prioritize measures such as memory compression, page reclamation, or defragmentation. Conversely, when... A lower value indicates a healthier system memory state, and the current allocation strategy can be maintained. This dynamism and real-time nature greatly improves the memory management efficiency of Android devices in complex operating environments, especially in high-load, multi-tasking scenarios, significantly reducing the risk of memory resource allocation imbalance or performance degradation. Furthermore, this formula is highly adaptable. By adjusting the parameter weights in the formula, such as the entropy weight of memory block distribution or the weight of the task load correction factor, it can be adapted to different types of Android devices and application needs. For example, for devices that need to process large datasets or run complex models, the weight of memory block distribution can be increased to prioritize reducing fragmentation; while for devices that emphasize real-time performance and multi-tasking switching, the influence of the task load correction factor can be strengthened, making memory management more focused on the efficiency of dynamic allocation. This flexible parameter adjustment capability makes the memory state model of this invention widely applicable to various Android devices, possessing extremely high practical value.
[0054] Example 4: In step 1, a multidimensional allocation priority matrix is constructed based on memory state entropy using the following formula. :
[0055] ;
[0056] in, For time; This refers to the real-time response time of the process. This is the maximum allowed process response time; This represents the current number of dirty pages. Count the number of missing pages; This is the threshold for counting missing pages; For I / O wait time; Maximum I / O wait time; This represents the current number of memory pages. This represents the maximum number of memory pages. For active memory load; Maximum memory load; This refers to the number of page table entries; This represents 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, i.e. Memory state entropy The matrix describes the uniformity and stability of the system's memory distribution, while its time derivative further reveals the dynamic trends of memory state changes. A large rate of change in entropy indicates that the system's memory state is experiencing drastic fluctuations, such as frequent allocation or release of memory blocks, potentially leading to memory fragmentation or load imbalance. In this case, the priority matrix allocates higher weights to tasks requiring stable memory states, ensuring the system can quickly recover and operate smoothly. Conversely, a low rate of change in entropy indicates relatively stable memory allocation, allowing the system to allocate more resources to lower-priority tasks, thus improving memory utilization. The matrix also incorporates the relationship between task response time and system performance through parameters... This parameter describes the ratio between a process's real-time response time and its maximum allowed response time. It directly reflects the urgency of the task: when the real-time response time is close to the allowed threshold, the system prioritizes allocating memory resources to ensure task timeliness; conversely, when the response time is significantly below the threshold, the system can more flexibly adjust resource allocation priorities. This design is particularly suitable for multitasking scenarios on Android devices, achieving a dynamic balance between user interaction, background tasks, and system processes. For example, when a background application needs to respond quickly to user actions, the matrix automatically increases its priority, thus providing a smooth user experience.
[0058] The priority matrix is also passed through parameters The distribution of dirty pages is considered. Dirty pages are data that the system needs to write back to storage. An increase in the number of dirty pages significantly increases the system's I / O pressure. 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, thus avoiding the impact of I / O bottlenecks on system performance. This design is particularly suitable for scenarios with frequent storage read / write operations, such as video stream caching or large file operations. In these cases, the priority matrix can dynamically adjust the allocation strategy to ensure system stability under high I / O loads. When considering the dimension of missing pages, the priority matrix uses parameters... This measure assesses the frequency of page misses. Page misses are a critical issue in memory management; when the page miss count approaches a threshold, system performance can be severely impacted by frequent page scheduling operations. The matrix dynamically evaluates the page scheduling pressure using this parameter, prioritizing the allocation of more resources to related tasks when page misses are frequent, thereby alleviating the burden of page scheduling. Simultaneously, the matrix also introduces... The parameters describe the urgency of I / O latency. When the I / O latency approaches the system's maximum allowable value, the matrix significantly increases the priority of related tasks to reduce the impact of I / O latency on system responsiveness. This dynamic adjustment strategy can effectively improve the storage operation efficiency of Android devices under high load environments.
[0059] The matrix design also fully considers the balance between memory page count and system load. Through parameters... The matrix assesses the ratio of the current number of memory pages to the total number of pages, measuring the level of memory resource strain. When the number of pages approaches the total capacity, the system memory load tends to be saturated. At this point, the matrix will prioritize reserving resources for critical tasks and free up memory space by reclaiming pages from low-priority tasks. Furthermore, parameters... This describes the proportion of active memory load to total load, a metric reflecting the overall system load level. When memory load approaches its limit, the matrix dynamically adjusts resource allocation priorities to prevent system crashes due to excessive load. Finally, the matrix includes... and Two key parameters describe the global impact of memory mapping complexity and memory distribution state: the proportion of page table entries to the maximum allowed number. This measures the complexity of memory management. As the number of page table entries increases, the matrix lowers the memory allocation priority for new tasks to reduce the complexity and management cost of memory mapping. The exponential decay factor... As a weighted correction for the overall memory state, a higher entropy value indicates a more uniform memory allocation. However, due to the exponential decay characteristic, this value will be closer to zero, thus preventing over-reliance on the single indicator of entropy.
[0060] Example 5: In step 1, the memory fragmentation risk level is calculated using the following formula, combining the priority matrix and runtime data. :
[0061] ;
[0062] in, express The determinant value; This refers to the number of memory segments. For the first The size of each memory segment; For the first The memory growth rate of the segment; This represents the maximum allowed memory growth rate.
[0063] For the first Number of fragments; Total fragment capacity; This represents the number of fragment types.
[0064] Specifically, the core design of this formula lies in the priority matrix. The determinant value is combined with the size and growth rate of memory segments, 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, this invention integrates multi-dimensional information on memory allocation into a scalar to describe the urgency of the system's current memory resources. The priority matrix itself already incorporates multiple parameters such as the rate of change of memory state entropy, task response time, page misses, and I / O wait time. These dimensions of information together constitute a comprehensive assessment of the system's memory resource requirements. When the determinant value is large, it indicates that the system's current 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 weight of the determinant's impact on fragmentation risk while avoiding nonlinear fluctuations caused by excessively large values. The second part of the formula... This describes the contribution of memory segment distribution characteristics to fragmentation risk. In Android devices, the size of memory segments... and growth rate This is a significant factor influencing fragmentation. Larger memory segments, when discontinuously distributed, can pose a greater obstacle to task scheduling; therefore, the formula directly weights memory segment sizes. Furthermore, the memory segment growth rate... It reflects the dynamic trend of memory allocation, through When the growth rate is low, the contribution of memory segments to fragmentation risk increases, while the growth rate approaches the maximum allowable value. At that time, the contribution decreases significantly. This is achieved by summing the contributions of each memory segment and introducing... The denominator of the formula is adjusted with weights for the memory segment numbers. The formula achieves a gradual decrease in the impact of the memory segment position, which is highly consistent with the characteristics of actual memory distribution: later memory segments usually have a smaller direct impact on system performance.
[0065] The complexity of the number and type of fragments is the third important dimension of the formula, which is achieved through... The impact of accumulating different types of fragmentation on overall fragmentation risk. In Android devices, different tasks or allocation strategies may generate different types of fragmentation, and each type of fragmentation has a different impact on performance. The formula accumulates the impact factor of each fragment type and then... The ratio of standardized fragment quantity to total system fragment capacity dynamically quantifies the impact of fragment complexity on system performance. For example, when the quantity of a certain fragment type is large, its contribution to fragmentation risk increases significantly, while the impact is relatively weak when the quantity of fragments is small. This design allows the formula to adapt to different fragment distributions, especially in multi-task concurrent operating environments, accurately describing the threat of complex fragmentation scenarios to system performance. The overall design of the formula reflects a high degree of dynamism 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, under high load scenarios, 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 low growth rates, the contribution of these memory segments will further increase the fragmentation risk. In addition, if the fragment types are complex and the quantity of some fragments is large, the cumulative factor of the formula will amplify their impact, thereby increasing the overall risk. This risk level can serve as a direct basis for memory optimization decisions. For example, when the risk level exceeds a certain threshold, the system can prioritize triggering defragmentation or memory compression operations. Traditional methods often focus only 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 a priority matrix and operational data. The multi-dimensional parameter design in the formula allows it to adapt to different operating states in real time, providing accurate fragmentation risk assessments in both high-load and low-load scenarios. Furthermore, the weight adjustment and cumulative calculation in the formula reflect a deep understanding of the actual operating characteristics of the system, making the risk level calculation results more valuable.
[0066] Example 6: In step 2, the dynamic threshold for memory allocation is calculated based on the memory fragmentation risk using the following formula. :
[0067] ;
[0068] in, The base memory block size is the smallest unit of memory allocation in an Android device. For closed paths of memory states; The line integral representing the rate of change of priority along a closed path of memory states; These are preset weighting factors; For the first The size of a memory-mapped unit; This refers to the number of memory-mapped units; The reference memory size is used to normalize the impact of the size of the memory-mapped unit; This is a preset correction factor for the rate of change of historical entropy; is a time integral variable, with a value range from 0 to t; The standard deviation of memory state entropy.
[0069] Specifically, the first part of the formula is determined by the base memory block size. The initial range of allocation thresholds is set by adjusting the index of memory fragmentation risk. It is the smallest unit of memory allocation in Android devices, usually related to hardware architecture, and is a fundamental parameter for memory management. The inclusion of memory fragmentation risk directly reflects the current fragmentation status of the system. When the fragmentation risk is high, an exponential function is used to... The formula dynamically lowers the allocation threshold, limiting new memory allocation requests and thus prioritizing the mitigation of fragmentation. When the risk level is low, the allocation threshold can be increased, allowing for 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 involves the integration of closed paths in the memory state. Extract the relationship between memory state and priority matrix changes. The closed-loop path integral describes the trajectory of memory state changes over a specific time range, especially the impact of the priority change rate on the overall system entropy. When the priority matrix changes drastically, the path integral value is large, indicating memory instability and the system may face frequent allocation and reclamation operations. In this case, the formula introduces a weighting factor. This change is adjusted to dynamically lower the allocation threshold, reducing the impact of frequent memory operations on system performance. Conversely, when the path integral is small, the system is more stable, and the allocation threshold can be appropriately increased to improve memory utilization. The third part of the formula incorporates the size of the memory-mapped unit. and total quantity Through weighted average The allocation threshold has been refined. Memory-mapped units are a crucial component of Android device memory management, and their size and number directly impact the complexity and efficiency of system memory allocation. The formula uses a sum-of-squares approach to increase the weight of large memory blocks on the overall allocation threshold, ensuring the system prioritizes supporting the memory demands of large tasks; while referencing memory size... The introduction of this factor normalizes the impact of memory-mapped units, allowing the formula to adapt to devices with different memory sizes. Part Four introduces a historical entropy change rate correction factor. This adjustment factor is used to adjust the allocation threshold to adapt to long-term changes in the system's memory state. By integrating the entropy value over time, this part captures the overall fluctuation characteristics of the memory state historically. If the system's entropy value changes drastically over a long period, the adjustment factor value is higher, and the allocation threshold is lowered accordingly, thus avoiding instability in memory allocation; conversely, when the entropy value changes relatively steadily, the adjustment 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, such as in multitasking environments with frequent switching. This adjustment factor can help the system predict changes in memory state and adjust the allocation strategy in advance.
[0070] Example 7: In step 2, the page reclamation priority is calculated using the following formula, combining the priority matrix and memory state entropy. :
[0071] ;
[0072] in, The gradient of the memory state entropy; The gradient of the dimensional assignment priority matrix; Modulo length operator; For the first The active time of each activity process; For the first Memory usage of each active process.
[0073] Specifically, the first part of the formula is obtained through... The gradient of memory state entropy quantifies the directional relationship between memory state entropy and priority matrix. The direction of memory state changes is described, and the gradient of the multidimensional allocation priority matrix is discussed. This reflects the direction of changes in system resource allocation. The dot product of the two values quantifies the correlation between changes in memory state and priority through directional weights. When the dot product value is high, it indicates that the trend of memory state changes is consistent with the direction of resource allocation needs, making reclamation operations more efficient. Conversely, when the dot product value is close to zero or negative, it may indicate that reclamation operations will conflict with resource allocation for high-priority tasks, thus reducing reclamation priority accordingly. Through modulus normalization, the formula avoids the influence of different gradient scales, ensuring the uniformity and dynamic adaptability of the directional weight calculation. The second part of the formula introduces a correction factor for historical entropy changes. This study quantifies the impact of memory state fluctuations on reclamation strategies by integrating historical changes in memory state entropy. This approach is particularly useful in scenarios with drastic memory state changes, such as during high-frequency task switching or large data stream processing, where memory states may experience significant fluctuations in a short period. These fluctuations are captured by integrating historical entropy values and combining them with the standard deviation of entropy. After normalization, this correction factor can dynamically increase or decrease the reclamation priority. For example, when the historical entropy changes significantly and fluctuates wildly, the reclamation priority will increase, prompting the system to prioritize memory reclamation operations to stabilize the overall state; conversely, when the historical entropy changes are small and stable, the reclamation priority will decrease, allowing the system to maintain its current memory allocation strategy. The third part of the formula... It combines the acceleration effect of task load and entropy change to dynamically evaluate the contribution of each active process to page recycling. Indicates the first The active time of each activity process reflects the running status of the task; This represents the memory usage of the process, describing the intensity of the task's memory resource requirements. It is calculated by weighting both factors and normalizing them to the total system memory capacity. The formula derives the relative resource importance of each task. When a task has a longer active time and higher memory usage, its relative importance increases, and the system will prioritize reserving pages for that task during garbage collection. Simultaneously, the second time derivative of entropy... The acceleration characteristics of memory state changes were further captured. A large acceleration in entropy change indicates that the system is in a period of severe fluctuation, requiring more cautious reclamation operations to avoid further exacerbating memory instability. Finally, the formula... The impact of fragmentation on page recycling has been considered. Here, It is the first The number of fragments, This represents the total fragmentation capacity of the system. Through a cumulative multiplication, this part quantifies the weakening effect of fragment type and quantity on recycling priority. When the quantity of a certain type of fragment is large, its impact on the recycling operation is more significant, thus reducing its recycling priority. This design avoids the performance overhead that frequent page recycling may cause under severe fragmentation conditions, while ensuring that the recycling operation can alleviate the system's fragmentation problem. Through the above multi-dimensional comprehensive calculation, the formula dynamically adjusts the page recycling priority. This enables Android devices to make efficient memory reclamation decisions in complex and ever-changing operating environments. For example, in a high-load environment, if a task has a large memory footprint and high priority, and the system memory state changes drastically, the reclamation priority will be significantly increased. The system will prioritize reclamating pages of low-priority tasks to free up resources for critical tasks. In a low-load scenario, if historical entropy changes are small and fragmentation is severe, the reclamation priority will be reduced, and the system can delay reclamation operations to avoid performance interference.
[0074] Example 8: In step 2, the adaptive memory compression ratio is calculated using the following formula based on page reclamation priority and memory fragmentation risk. :
[0075] ;
[0076] in, For the first One memory region; The normal gradient of the memory state entropy; For the first Layer memory usage; This represents the maximum memory usage across all levels. This represents the number of memory regions. This refers to the number of memory levels. This is the cross product operator.
[0077] Specifically, the core of the formula's design lies in dynamically balancing the risk of memory fragmentation. and page recycling priority These two key metrics reflect the current level of memory fragmentation and the efficiency of memory page reclamation, respectively. In the first part of the formula, It provides a basic proportional relationship for compression ratios. A high fragmentation risk indicates a more discontinuous memory distribution, requiring an increased compression ratio to free up more contiguous memory space and alleviate fragmentation. Conversely, a high page reclamation priority indicates that the system has already performed numerous page reclamation operations to release memory resources, reducing the need for compression. Therefore, by calculating the logarithmic ratio, the formula dynamically adapts to the balance between fragmentation and page reclamation. When fragmentation is severe but reclamation operations are insufficient, the compression ratio is significantly increased; conversely, when page reclamation has played a significant role, the compression ratio is appropriately reduced to minimize the additional performance overhead of compression operations. At the level of memory state space distribution, the formula introduces the spatial variation of the memory state entropy gradient through region integration. This section aims to capture the spatial non-uniformity of memory distribution and adjust the compression strategy accordingly. Each memory region... A memory region is a logical unit of system memory, and its entropy gradient describes the magnitude of changes in memory state within that region. A large entropy gradient in a region indicates a more uneven distribution of memory within that region, potentially suggesting significant fragmentation. Through region integration, the formula comprehensively quantifies the contribution of each region to the overall memory compression requirement. In practical applications, this design makes compression operations more precise. For example, when a region exhibits severe memory fragmentation while other regions are more uniform, the system prioritizes compressing that region rather than uniformly compressing all memory, thus improving the targeting and efficiency of the compression.
[0078] Memory usage patterns are also a significant factor influencing compression strategies. (The third part of the formula...) The compression ratio is adjusted by multiplying the utilization rates of different levels to dynamically adapt to the resource load at different levels. When the memory utilization rate at a certain level... Close to the maximum value When the compression factor approaches zero, it indicates that the resources at that level are under strain. Compression operations at this point would significantly disrupt performance. The formula protects the performance of this level by reducing the overall compression ratio. Conversely, when the level utilization is low, the compression factor is larger, allowing for more aggressive compression operations on low-load levels. This design is particularly suitable for Android devices with multi-tiered storage architectures. For example, compression at low-speed storage levels can free up more space for high-speed storage levels, thereby improving overall system performance. The formula's overall structure not only reflects a multi-dimensional integration of memory state and system load but also achieves adaptive optimization for different operating scenarios by dynamically adjusting the weights of each component. For instance, in high-load scenarios, the risk of memory fragmentation is typically high, and the utilization of memory levels tends to be saturated. In this case, the formula prioritizes releasing more memory resources by increasing the compression ratio to support high-priority tasks. In low-load scenarios, when page recycling has a high priority and the risk of fragmentation is low, the formula reduces the compression ratio, thereby minimizing the impact of compression operations on system performance. This dynamic balancing mechanism ensures the flexibility of the memory compression strategy, enabling the system to maintain efficient operation under different load conditions. Traditional memory compression strategies typically adjust based on only one dimension: fragmentation or memory utilization, making them ill-suited for complex multi-tasking environments. This formula, however, incorporates multiple dimensions such as fragmentation risk, page reclamation efficiency, spatial distribution characteristics, and hierarchical load into a unified model. This not only enhances the intelligence of the compression strategy but also significantly strengthens the positive impact of compression operations on system performance. In practical applications, such as high-load scenarios like running large games or video editing, memory allocation demands fluctuate greatly, and fragmentation is prevalent. This formula can quickly respond to changes in system memory status and dynamically adjust the compression ratio to ensure smooth task execution. Furthermore, when there are many background tasks, the formula can balance page reclamation and memory compression, prioritizing the release of memory resources for low-priority tasks to avoid interfering with foreground tasks.
[0079] Example 9: In step 4, the Boolean value for memory allocation is calculated using the following formula. :
[0080] .
[0081] Specifically, the first part of the formula By using dynamic thresholds for memory allocation The ratio of this ratio to the memory fragmentation distribution factor quantifies the feasibility of the current memory allocation. Here, the memory fragmentation distribution factor is determined by the size of each memory segment. and growth rate The decision is made jointly, with weights decreasing in stages. Different memory segments are weighted. This design reflects the correlation between the actual contribution of memory segments and their fragmentation level: larger memory segments, when evenly distributed, provide stronger support for memory allocation, while smaller and more dispersed memory segments have a greater negative impact on system memory management. When the dynamic threshold of the numerator... A high denominator and a small denominator indicate that the system's current memory allocation conditions are relatively lenient, and new memory allocation operations can be accepted. Conversely, when the denominator is large, fragmentation may significantly limit new allocation demands, and the Boolean value tends to return "0" to prohibit further allocation. The second part of the formula is... Cumulative analysis of the rate of change in page reclamation priority and the spatial gradient of memory state entropy is performed to further measure the potential impact of memory resource allocation on the overall system stability. Page reclamation priority rate of change It is a key metric used to reflect the memory compression rate of page reclamation operations. The sensitivity of priority is as follows: When page reclamation efficiency is low and the effect of compression ratio adjustment is limited, the priority change rate approaches zero, indicating that memory allocation may exacerbate system load, so the Boolean value is more likely to be "0". Conversely, when page reclamation efficiency is high, the priority change rate will significantly increase, a signal that the system can more flexibly perform new memory allocation operations.
[0082] 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 integrating the gradient of the memory state entropy over different regions, the formula captures the non-uniformity of memory distribution, especially in different memory regions. The entropy gradient within the memory indicates uneven memory distribution and the potential for further fragmentation in resource allocation. In this case, the Boolean value is more likely to return "0" to avoid triggering new allocation risks. Conversely, a smaller entropy gradient indicates a more uniform memory distribution and more ideal conditions for further allocation. Through a comprehensive comparison of these two parts, the formula returns a Boolean value. This formula serves as the final decision-making 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 (reclamation and space impact assessment), the system considers the current memory state to be able to 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 resolving the current memory problem. 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, by introducing multi-dimensional factors such as memory fragmentation distribution, page reclamation efficiency, and entropy gradient distribution, can not only dynamically adapt to different operating scenarios but also balance the relationship between memory allocation needs and system stability. For example, in multi-tasking, high-load scenarios, if memory fragmentation is severe and page reclamation efficiency is low, the formula can effectively prevent unnecessary memory allocation operations, thereby avoiding further degradation of system performance. Under 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 significantly and task priorities differ markedly. The formula can accurately assess the current system state and quickly make allocation decisions as needed, thereby ensuring the stability of critical tasks. Meanwhile, for scenarios with many background tasks, the formula dynamically adjusts Boolean values to prevent low-priority tasks from consuming excessive memory resources, thus ensuring the responsiveness of foreground tasks.
[0083] It will be apparent 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 invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in the apparatus claims may also be implemented by a single unit or device in software or hardware. The terms "first," "second," etc., are used to indicate names and do not indicate any particular order.
Claims
1. A method for memory allocation and reclamation in Android devices, characterized in that, The method includes: Step 1: Obtain the running data of the Android device, calculate the memory state entropy based on the running data; construct a multi-dimensional allocation priority matrix based on the memory state entropy; combine the multi-dimensional allocation priority matrix and the running data to calculate the memory fragmentation risk. Step 2: Calculate the dynamic threshold for memory allocation based on the memory fragmentation risk level; calculate the page reclamation priority by combining the multi-dimensional allocation priority matrix and memory state entropy; calculate the adaptive memory compression rate based on the page reclamation priority and the memory fragmentation risk level. Step 3: Compress the currently unused memory data of the Android device using an adaptive memory compression ratio; determine whether the memory usage of an active process exceeds the dynamic threshold of memory allocation. If so, further determine whether the page recycling priority exceeds the set recycling threshold. If so, recycle the pages of the active process in the order of their 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 based on the dynamic memory allocation threshold, adaptive memory compression rate and page reclamation priority. If the memory allocation boolean value is true, all memory is reclaimed, and the total memory capacity is reduced by the dynamic memory allocation threshold before the remaining memory capacity is evenly distributed to all active processes. In step 1, the memory state entropy is calculated using the following formula. : ; in, This represents the total number of memory blocks. For the first The size of each memory block; This represents the total memory capacity. For the first The percentage of total memory occupied by each memory block; For the first Number of pages per active process; For the first CPU utilization of each active process; The number of activity processes; Total number of pages; In step 1, a multidimensional allocation priority matrix is constructed based on memory state entropy using the following formula. ; in, For time; This refers to the real-time response time of the process. This is the maximum allowed process response time; This represents the current number of dirty pages. Count the number of missing pages; This is the threshold for counting missing pages; For I / O wait time; Maximum I / O wait time; This represents the current number of memory pages. This represents the maximum number of memory pages. For active memory load; Maximum memory load; This refers to the number of page table entries; This represents the maximum number of page table entries. In step 1, the memory fragmentation risk is calculated using the following formula, combining the multidimensional allocation priority matrix and runtime data. : ; in, express The determinant value; This refers to the number of memory segments. For the first The size of each memory segment; For the first The memory growth rate of the segment; This represents the maximum allowed memory growth rate. For the first Number of fragments; Total fragment capacity; Number of fragment types; In step 2, the dynamic threshold for memory allocation is calculated based on the memory fragmentation risk using the following formula. : ; in, The base memory block size is the smallest unit of memory allocation in an Android device. For closed paths of memory states; The line integral representing the rate of change of priority along a closed path of memory states; These are preset weighting factors; For the first The size of a memory-mapped unit; This refers to the number of memory-mapped units; The reference memory size is used to normalize the impact of the size of the memory-mapped unit; This is a preset correction factor for the rate of change of historical entropy; The variable is a time integral variable, and its range is... arrive ; The standard deviation represents the entropy of memory states; In step 2, the page reclamation priority is calculated using the following formula, combining the multidimensional allocation priority matrix and memory state entropy. : ; in, The gradient of the memory state entropy; The gradient of the multidimensional priority assignment matrix; Modulo length operator; For the first The active time of each activity process; For the first Memory usage of each active process.
2. The memory allocation and reclamation method for Android devices as described in claim 1, characterized in that, The Android device's runtime data obtained in Step 1 includes: the size of each memory block, total memory capacity, number of pages per active process, CPU utilization for each active process, real-time process response time, maximum allowed process response time, current number of dirty pages, page miss count, IO wait time, maximum IO wait time, current number of memory pages, maximum number of memory pages, active memory load, maximum memory load, number of page table entries, and maximum number of page table entries.
3. The memory allocation and reclamation method for Android devices as described in claim 1, characterized in that, In step 2, the adaptive memory compression ratio is calculated using the following formula, based on page reclamation priority and memory fragmentation risk. : ; in, For the first One memory region; The normal gradient of the memory state entropy; For the first Layer memory usage; This represents the maximum memory usage across all levels. This represents the number of memory regions. This refers to the number of memory levels. This is the cross product operator.
4. The memory allocation and reclamation method for Android devices as described in claim 1, characterized in that, In step 4, the Boolean value for memory allocation is calculated using the following formula. : 。
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