Memory management method and related equipment
By optimizing memory management through dynamic heat perception and hierarchical data migration, the problem of uneven resource utilization under high load in the traditional Swap mechanism is solved, realizing intelligent and efficient memory management and improving system stability and response speed.
Patent Information
- Application Number
- CN202511723293.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-03-20
- Estimated Expiration
- 2045-11-21
AI Technical Summary
Traditional swap mechanisms result in low intelligence in memory management, high system I/O load, and uneven resource utilization under high load or multi-process environments. Furthermore, they fail to fully consider the access characteristics and data hotness differences of different memory pages, leading to frequent disk I/O operations and low memory utilization efficiency.
By employing dynamic heat perception, hierarchical data migration, adaptive compression control, and cross-layer collaborative optimization, dynamic heat scores are calculated using memory page access information. Hierarchical data migration strategies are executed to migrate different types of data to the main Swap storage space or the auxiliary Swap storage space. The compression algorithm of the auxiliary Swap storage space is adjusted according to the CPU utilization. The status of each layer is detected and adjusted in real time to optimize resource allocation.
It improves memory utilization, swapping efficiency, and overall system stability, reduces disk I/O load, optimizes resource utilization, and ensures stable system operation under different loads.
Smart Images

Figure CN121704775A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage technology, and more specifically, to a memory management method and related equipment. Background Technology
[0002] With the increasing prevalence of applications such as mobile devices, cloud computing, and smart terminals, operating systems are becoming significantly more reliant on memory resources during multitasking and large-scale data processing. To ensure stable operation and responsiveness, operating systems typically use swap mechanisms to exchange data between physical memory and external storage, alleviating memory pressure. However, as application complexity increases, the traditional single swap mechanism is gradually revealing performance bottlenecks under high load or multi-process environments, making it difficult to meet the demands of modern operating systems for efficient and intelligent memory management.
[0003] In related technologies, mainstream swap mechanisms typically rely solely on disk swap space for data replacement. While this can expand available memory to some extent, frequent disk I / O operations under high system memory pressure can significantly increase swap latency, leading to slower system response or even system freezes. Furthermore, existing technologies fail to adequately consider the access characteristics and data frequency differences of different memory pages, resulting in frequent instances of frequently accessed data being mistakenly swapped and cold data occupying memory for extended periods, leading to low memory utilization efficiency. In other words, related technologies suffer from low levels of intelligent memory management, high system I / O load, and uneven resource utilization. Summary of the Invention
[0004] The summary section of this application introduces a series of simplified concepts, which will be further explained in detail in the detailed description section. The summary section of this application is not intended to limit the key features and essential technical features of the claimed technical solution, nor is it intended to determine the scope of protection of the claimed technical solution.
[0005] The memory management method and related devices provided in this application can achieve intelligent and efficient memory management through dynamic heat perception, hierarchical data migration, adaptive compression control and cross-layer collaborative optimization, thereby improving memory utilization, swapping efficiency and overall system stability under different system loads.
[0006] Firstly, this application provides a memory management method applied to a target operating system, the target operating system including a main Swap storage space and an auxiliary Swap storage space based on memory compression, comprising: determining a dynamic heat score for each memory page based on access information of memory pages in the target operating system; executing a corresponding hierarchical data migration strategy based on the current memory pressure level of the target operating system and the dynamic heat score to migrate different memory pages to the corresponding main Swap storage space or the auxiliary Swap storage space; adjusting the compression algorithm applied to the auxiliary Swap storage space based on the current CPU utilization of the target operating system; detecting the real-time status of the main Swap storage space, the auxiliary Swap storage space, and physical memory, and adjusting the hierarchical data migration strategy and the compression algorithm based on the detection results.
[0007] In some implementations, determining the dynamic popularity score of each memory page based on the access information of the memory pages of the target operating system includes: obtaining the first access frequency of each memory page within a preset first time window; determining the temporal locality factor of the corresponding memory page based on the access time distribution of each memory page within the preset first time window; and determining the dynamic popularity score of each memory page based on the first access frequency and the temporal locality factor.
[0008] In some implementations, determining the temporal locality factor of a corresponding memory page based on the access time distribution of each memory page within the preset first time window includes: dividing the preset first time window into multiple consecutive time sub-windows; obtaining the second access frequency of the corresponding memory page within each time sub-window; and determining the temporal locality factor based on the degree of dispersion of the distribution of the second access frequency in each time sub-window, wherein the degree of dispersion is negatively correlated with the temporal locality factor.
[0009] In some implementations, the step of executing a corresponding tiered data migration strategy based on the current memory pressure level of the target operating system and the dynamic heat score includes: comparing the dynamic heat score with a first scoring threshold and a second scoring threshold to classify memory pages into hot data type, warm data type, and cold data type, wherein the first scoring threshold is greater than the second scoring threshold; determining the current memory pressure level based on the proportion of free memory in the target operating system, and executing a corresponding tiered data migration strategy based on the current memory pressure level to migrate at least one type of memory page among the cold data type, the warm data type, and the hot data type to the auxiliary Swap storage space or the primary Swap storage space.
[0010] In some implementations, determining the current memory pressure level based on the proportion of free memory in the target operating system and executing a corresponding tiered data migration strategy based on the current memory pressure level includes: when the proportion of free memory is higher than a first proportion threshold, determining the current memory pressure level as a low memory pressure level, in which case the tiered data migration strategy is to migrate only the cold data type memory pages to the auxiliary Swap storage space; when the proportion of free memory is between a second proportion threshold and the first proportion threshold, determining the current memory pressure level as a medium memory pressure level, in which case the tiered data migration strategy is to migrate all the cold data type memory pages and a first proportion of the warm data type memory pages to the auxiliary Swap storage. Space; when the free memory ratio is between the third ratio threshold and the second ratio threshold, the current memory pressure level is determined to be a high memory pressure level. At this time, the hierarchical data migration strategy is to migrate all the cold data type and the warm data type memory pages to the auxiliary Swap storage space, and migrate the second ratio of the hot data type memory pages to the main Swap storage space; when the free memory ratio is lower than the third ratio threshold, the current memory pressure level is determined to be an emergency memory pressure level. At this time, the hierarchical data migration strategy is to migrate all the cold data type and the warm data type memory pages to the auxiliary Swap storage space, and migrate all the hot data type memory pages to the main Swap storage space.
[0011] In some implementations, adjusting the compression algorithm applied to the auxiliary Swap storage space based on the current CPU utilization of the target operating system includes: when the current CPU utilization is lower than a first preset load threshold, determining a first compression algorithm as the target compression algorithm; when the current CPU utilization is between the first preset load threshold and a second preset load threshold, determining a second compression algorithm as the target compression algorithm; when the current CPU utilization is higher than the second preset load threshold, determining a third compression algorithm as the target compression algorithm, wherein the compression ratio and processor overhead configured for the first compression algorithm, the second compression algorithm, and the third compression algorithm are all sequentially reduced; and switching or configuring the compression algorithm applied to the auxiliary Swap storage space to the target compression algorithm.
[0012] In some implementations, detecting the real-time status of the main Swap storage space, the auxiliary Swap storage space, and physical memory, and adjusting the hierarchical data migration strategy and the compression algorithm based on the detection results, includes: obtaining the free page ratio and allocation success rate of the physical memory, the compression efficiency and space utilization of the auxiliary Swap storage space, and the I / O load and migration frequency of the main Swap storage space; adjusting the heat rating threshold for data classification, the free memory ratio threshold for determining memory pressure level, and / or the load threshold for selecting the compression algorithm based on at least one of the free page ratio, the allocation success rate, the compression efficiency, the space utilization, the I / O load, and the migration frequency, wherein the heat rating threshold includes a first rating threshold and a second rating threshold, the free memory ratio threshold includes a first ratio threshold, a second ratio threshold, and a third ratio threshold, and the load threshold includes a first preset load threshold and a second preset load threshold.
[0013] Secondly, this application also provides a memory management device applied to a target operating system, the target operating system including a main Swap storage space and an auxiliary Swap storage space based on memory compression, comprising: a scoring determination unit, used to determine the dynamic heat score of each memory page based on the access information of the memory pages of the target operating system; a policy execution unit, used to execute a corresponding hierarchical data migration strategy based on the current memory pressure level of the target operating system and the dynamic heat score, so as to migrate different memory pages to the corresponding main Swap storage space or the auxiliary Swap storage space; an algorithm adjustment unit, used to adjust the compression algorithm applied to the auxiliary Swap storage space based on the current CPU utilization of the target operating system; and a detection adjustment unit, used to detect the real-time status of the main Swap storage space, the auxiliary Swap storage space and physical memory, and adjust the hierarchical data migration strategy and the compression algorithm based on the detection results.
[0014] Thirdly, this application also provides an electronic device, including: a memory and a processor, wherein the processor is configured to implement the steps of the memory management method described in the first aspect when executing a computer program stored in the memory.
[0015] Fourthly, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the memory management method described in the first aspect.
[0016] Fifthly, this application also provides a computer program product, including a computer program or computer executable instructions, which, when executed by a processor, implement the memory management method provided in the embodiments of this application.
[0017] In summary, this application analyzes memory page access information and calculates dynamic popularity scores for each page, thereby achieving accurate identification of data hotness and coldness. It can dynamically adjust based on actual access characteristics during system operation, making data migration more targeted and improving the intelligence and adaptability of memory management. Based on the current memory pressure level and page popularity scores, a layered data migration strategy is executed, migrating different types of data to either the main Swap storage space or a memory-compressed auxiliary Swap storage space. This allows for reasonable allocation of storage resources under different pressure conditions, prioritizing low-activity data and reducing disk I / O load, effectively improving memory swapping efficiency and system response speed. Based on the real-time utilization of the CPU, the compression algorithm applied to the auxiliary Swap space is dynamically adjusted, achieving a balance between compression performance and system performance, further optimizing system resource utilization. Furthermore, by continuously monitoring the real-time operating status of the main Swap, auxiliary Swap, and physical memory, and dynamically adjusting the layered migration strategy and compression algorithm based on the monitoring results, collaborative optimization between multiple memory spaces can be achieved, ensuring that resource allocation and data exchange at each layer remain in optimal condition, thereby improving the overall stability and memory utilization efficiency of the system. In summary, the memory management method provided in this application achieves intelligent and efficient memory management through dynamic heat perception, hierarchical data migration, adaptive compression control, and cross-layer collaborative optimization, thereby improving memory utilization, swapping efficiency, and overall system stability under different system loads. Attached Figure Description
[0018] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit this specification. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 A flowchart illustrating a memory management method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the composition structure of a memory management device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the composition structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0019] The terms used in the specification, claims, and drawings of this application, such as "first," "second," "third," "fourth," etc. (if any), are used to distinguish similar objects and not to describe a specific order or sequence. Therefore, it is to be understood that these terms can be used interchangeably where appropriate, allowing the described embodiments to be used in different orders, unless specifically required by the illustrations or description. Furthermore, the terms "is" and "has," and any variations thereof, are intended to cover, non-exclusively, all possible constituent elements. For example, a process, method, system, product, or apparatus comprising several steps or units is not necessarily limited to the steps or units explicitly listed, but may also include other steps or units not explicitly listed, or steps or units inherent to the process, method, product, or apparatus.
[0020] In this application, a "module" or "unit" refers to a computer program or part of a computer program that has a specific function and works in conjunction with other related parts to achieve a predetermined goal. These modules or units can be implemented by software, hardware (e.g., processing circuitry or memory), or a combination of both. One or more processors or memories can implement one or more modules or units. Furthermore, each module or unit can also be part of a larger module or unit.
[0021] The technical solutions of this application will be described in detail below with reference to the accompanying drawings of the embodiments. It should be noted that the described embodiments are only a part of this application, and not all embodiments. In the following description, the "some embodiments" mentioned are only a subset of all possible embodiments, which may be the same or different subsets, and different embodiments can be combined with each other without conflict.
[0022] The memory management method provided in this application is used in a target operating system, which includes a main swap storage space and an auxiliary swap storage space based on memory compression. The target operating system refers to the operating system used in this application, which needs to support the collaborative management of the main swap storage space (Main Swap Storage Space) and the auxiliary swap storage space based on memory compression (Auxiliary Swap Storage Space). It can be an operating system for resource-constrained scenarios. Supporting the main swap storage space, also known as supporting the main swap storage space, refers to a swap storage area based on a disk or solid-state drive (SSD), used to temporarily store memory pages when physical memory is insufficient. Its characteristics include a large capacity but slow read / write speed. The main swap storage space can be pre-allocated by the target operating system, usually existing in the form of a disk partition. For example, the operating system of a smart terminal allocates 8GB of space in a 128GB solid-state drive as the main swap storage space, with the path / dev / block / sda6, used to store memory pages with low long-term access frequency. Secondary swap space, also known as auxiliary exchange storage, refers to the swap storage area based on memory compression technology. It stores memory pages after compression using a compression algorithm. Essentially, it's a special area in physical memory, characterized by fast read / write speeds but limited capacity by physical memory. Secondary swap space can be dynamically allocated by the target operating system, for example, based on a memory compression block device (ZRAM). Its size can be dynamically calculated based on the total physical memory capacity (e.g., 50% of physical memory). For example, if a device has 6GB of physical memory, and the system dynamically allocates 3GB as secondary swap space, using the LZ4 algorithm to compress the migrated memory pages, the actual memory usage after compression is approximately 1.2GB.
[0023] Figure 1 This is a schematic flowchart illustrating a memory management method provided in an embodiment of this application. For example, see [link to example]. Figure 1 The memory management method provided in this application embodiment may include the following steps 101 to 104: Step 101: Determine the dynamic heat score of each memory page based on the access information of the memory pages of the target operating system.
[0024] In some examples, a memory page is the basic unit of memory management in the target operating system. It is a contiguous block of data of a fixed size in physical memory, the size of which is preset by the operating system. It is used to store application instructions, data, or cached information. Memory pages are obtained through the operating system's page table, which records the mapping relationship between the physical address and virtual address of each memory page. For example, the operating system of a mobile device divides memory into 4KB pages, one of which stores the browser's cached data. Access information refers to data generated when a memory page is accessed by the Central Processing Unit (CPU) or an application, including but not limited to access time (such as first access time, most recent access time), access frequency (the frequency of access per unit time), and access interval (the time difference between two consecutive accesses). Access information is obtained through the operating system's Memory Management Unit (MMU) or page monitoring module. For example, the MMU records the access events of each memory page in real time and stores the access time, frequency, and other data in the access log. Taking a database application as an example, its cached page was accessed 6 times in 5 minutes, with the first access time being 10:00:00 and the most recent access time being 10:04:30. These data all belong to the access information of that page. Dynamic popularity score is a quantitative indicator calculated based on the access information of memory pages. It reflects the frequency and time correlation of memory page access. Its value range is usually from 0 to 1 (the higher the value, the higher the page popularity). The dynamic popularity score is obtained by calculating it through a preset algorithm, such as combining the access frequency per unit time (the ratio of the number of accesses to the time window) and the temporal locality factor (the degree of clustering of access time distribution), and using a weighted formula (such as popularity score = 0.6 × access frequency + 0.4 × temporal locality factor). Taking the homepage data page of a social application as an example, it was accessed 12 times in 5 minutes, and the access time was concentrated in the first 2 minutes (temporal locality factor is 0.8). Its dynamic popularity score was calculated to be 0.75, which is a high popularity page.
[0025] By implementing step 101, a dynamic popularity score is calculated based on the access information of memory pages, which can reflect the access activity of each page in real time, thereby achieving accurate identification of the hotness or coldness of data; thus, the importance of pages can be dynamically judged according to the access characteristics in the actual operation process, providing an accurate basis for subsequent hierarchical data migration, and improving the accuracy and adaptability of memory management decisions.
[0026] Step 102: Based on the current memory pressure level and dynamic heat score of the target operating system, execute the corresponding hierarchical data migration strategy to migrate different memory pages to the corresponding primary Swap storage space or secondary Swap storage space.
[0027] In some examples, the current memory pressure level refers to the physical memory strain of the target operating system at a given moment, reflecting the urgency of the system's memory resource requirements. It is determined by calculating the ratio of free physical memory (the size of free memory to the total physical memory) and comparing it to a preset threshold. This is typically categorized as low, medium, high, and critical memory pressure levels. The corresponding tiered data migration strategy is a differentiated data migration rule based on the current memory pressure level and the dynamic popularity score of memory pages. Its core is to migrate memory pages with different popularity levels to either the primary or secondary swap space to balance system performance and resource utilization. The process of migrating different memory pages to their corresponding primary or secondary swap space involves copying memory pages with specific popularity from physical memory to the primary or secondary swap space according to the tiered data migration strategy, and updating the page tables to maintain address mappings.
[0028] By implementing step 102, and combining the current memory pressure level with the page popularity score to execute a hierarchical data migration strategy, data can be reasonably allocated to the main Swap or auxiliary Swap space according to different load states. Low-activity data can be migrated first, reducing disk I / O frequency and swap latency, thereby effectively improving memory swap efficiency and system response speed, and ensuring that the system can still run stably under high load scenarios.
[0029] Step 103: Adjust the compression algorithm applied to the auxiliary Swap storage space based on the current CPU utilization of the target operating system.
[0030] In some examples, the current CPU utilization rate is the level of activity of the CPU in the target operating system at a given moment, usually expressed as a percentage, reflecting the proportion of CPU time spent processing tasks out of the total available time. For example, if a smart terminal is running music playback and file browsing applications in the background, and the total CPU time is 100 time slices, with 30 time slices of idle time, then the current CPU utilization rate is 70%. Compression algorithms are rules and methods used to compress data. Their core is to reduce the storage space occupied by data through encoding techniques, while simultaneously recovering the original data through decoding. In this step, the compression algorithm specifically refers to algorithms applied to assist in swapping storage space, needing to consider both the compression ratio (the ratio of the compressed data to the original data) and the compression speed (the amount of data compressed per unit time). Common algorithms include LZ4 High Compression (LZ4 HC), Standard LZ4, and LZO (LZO Algorithm). The process of adjusting the compression algorithm applied to the auxiliary swap storage space based on the current CPU utilization of the target operating system involves dynamically selecting or switching the compression algorithm used by the auxiliary swap storage space according to the current CPU utilization level, in order to balance compression efficiency and CPU resource consumption. For example, when the CPU utilization is below 40% (low load), the LZ4HC algorithm is switched to improve the compression ratio; when the utilization is between 40% and 70% (medium load), the standard LZ4 algorithm is used to balance compression ratio and speed; when the utilization is above 70% (high load), the LZO algorithm is switched to reduce CPU overhead.
[0031] By implementing step 103, the compression algorithm of the auxiliary Swap space is dynamically adjusted according to the real-time utilization of the central processing unit, which can achieve a balance between performance and resource utilization under different system loads. When the CPU load is low, a high compression ratio algorithm is used to save memory space, and when the CPU load is high, a low-overhead algorithm is selected to reduce processing pressure, thereby improving the overall system operating efficiency and resource utilization flexibility.
[0032] Step 104: Detect the real-time status of the main Swap storage space, the auxiliary Swap storage space, and the physical memory, and adjust the hierarchical data migration strategy and compression algorithm based on the detection results.
[0033] In some examples, the real-time status of primary swap space, secondary swap space, and physical memory is used to reflect the load and efficiency of each storage tier. Specifically, the real-time status of primary swap space includes the percentage of used space, input / output load, and page migration frequency (the number of pages migrated in / out per unit time). The real-time status of secondary swap space includes compression efficiency (the ratio of compressed data to original data size), space utilization (the ratio of used compressed space to total compressed space), and average compression / decompression time. The real-time status of physical memory includes the proportion of free pages (the ratio of free pages to total pages), page allocation success rate (the proportion of successfully allocated page requests out of total requests), and the proportion of hot data pages (the proportion of pages with a dynamic popularity score > 0.7). The detection results are a dataset formed by summarizing and quantifying the real-time status of primary swap space, secondary swap space, and physical memory, used to intuitively reflect the operating status of each storage tier. The process of adjusting the hierarchical data migration strategy and compression algorithm based on the detection results involves dynamically adjusting the parameters of the hierarchical data migration strategy (such as the popularity score threshold and memory pressure level threshold) and the selection rules of the compression algorithm (such as the load threshold) according to the status indicators of each storage level in the detection results, in order to optimize the overall system performance. For example, if the detection results show that the I / O load of the main swap storage space reaches 85% (exceeding the warning threshold of 80%), the third ratio threshold of the high memory pressure level will be adjusted from 5% to 8% to reduce the migration of hot data to the main swap storage space. If the compression efficiency of the auxiliary swap storage space drops to 1.8:1 (below the warning threshold of 2.0:1) and the CPU utilization is 30% (low load), the compression algorithm will be switched from the standard LZ4 to the LZ4 high compression version.
[0034] By implementing step 104, the operating status of the main Swap, auxiliary Swap, and physical memory is monitored in real time, and the hierarchical migration strategy and compression algorithm are dynamically adjusted accordingly. This enables the collaborative optimization of multi-layer memory space, ensures the continuous optimality of data distribution and compression strategies, and allows the system to adaptively adjust according to actual operating conditions, thereby improving memory utilization, optimizing resource allocation, and enhancing the overall stability of the system.
[0035] In summary, this application's embodiments analyze memory page access information and calculate dynamic popularity scores for each page, thereby achieving accurate identification of data hotness / coldness. This allows for dynamic adjustments based on actual system access characteristics during operation, making data migration more targeted and improving the intelligence and adaptability of memory management. Based on the current memory pressure level and page popularity scores, a layered data migration strategy is executed, migrating different types of data to either the main Swap storage space or a memory-compressed auxiliary Swap storage space. This enables reasonable allocation of storage resources under different pressure conditions, prioritizing low-activity data and reducing disk I / O load, effectively improving memory swapping efficiency and system response speed. Dynamic adjustments to the compression algorithm applied to the auxiliary Swap space based on the real-time utilization of the CPU achieve a balance between compression performance and system performance, further optimizing system resource utilization. Furthermore, by continuously monitoring the real-time operating status of the main Swap, auxiliary Swap, and physical memory, and dynamically adjusting the layered migration strategy and compression algorithm based on the monitoring results, collaborative optimization between multiple memory spaces is achieved, ensuring that resource allocation and data exchange at each layer remain in optimal condition, thereby improving overall system stability and memory utilization efficiency. In summary, the memory management method provided in this application achieves intelligent and efficient memory management through dynamic heat perception, hierarchical data migration, adaptive compression control, and cross-layer collaborative optimization, thereby improving memory utilization, swapping efficiency, and overall system stability under different system loads.
[0036] In some embodiments, step 101 may include: obtaining the first access frequency of each memory page within a preset first time window; determining the temporal locality factor of the corresponding memory page based on the access time distribution of each memory page within the preset first time window; and determining the dynamic heat score of each memory page based on the first access frequency and the temporal locality factor.
[0037] In some examples, the preset first time window is a fixed time interval pre-defined for statistically analyzing memory page access information. Its purpose is to define the time range for calculating access frequency and time distribution, balancing real-time performance with statistical accuracy. Its duration can be adjusted according to the application scenario, typically ranging from 1 to 10 minutes. For example, in mobile device memory management, the preset first time window can be configured to 5 minutes, meaning only access data for memory pages within the most recent 5 minutes is counted. The first access frequency is the ratio of the total number of times a memory page is accessed within the preset first time window to the window duration. It quantifies the frequency of page access. This can be achieved by using the target operating system's memory access monitoring module to count the total number of accesses for each memory page within the preset first time window, then dividing by the window duration (in minutes or seconds). For example, if a memory page is accessed 15 times within a 5-minute (300-second) preset first time window, the first access frequency is 15 times / 5 minutes = 3 times / minute (or 0.05 times / second). Access time distribution refers to the time distribution of all access events of a memory page within a preset first time window. It reflects the time clustering characteristics of access behavior (such as being concentrated in a certain period of time within the window or being evenly distributed). The memory management unit can record the timestamp of each access and then map these timestamps to specific moments within the preset first time window to form a time distribution sequence. For example, if a memory page is accessed 10 times within a 5-minute (0-300 seconds) window, with timestamps of 20 seconds, 22 seconds, 25 seconds, 180 seconds, 182 seconds, 185 seconds, 290 seconds, 291 seconds, 293 seconds, and 295 seconds, its access time distribution shows that it occurs in three concentrated periods: 20-25 seconds, 180-185 seconds, and 290-295 seconds. The temporal locality factor is an indicator used to quantify the degree of clustering in the distribution of memory page access times. Its value typically ranges from 0 to 1. A higher value indicates a more concentrated access time (stronger locality), while a lower value indicates a more dispersed access time (weaker locality). It can be calculated based on the access time distribution. For example, a preset first time window can be divided into multiple equal-length sub-windows, and the number of accesses in each sub-window can be counted. By calculating the coefficient of variation (the ratio of the standard deviation to the mean) or variance of the access counts, the degree of dispersion can be converted into a locality factor (dispersion is negatively correlated with the locality factor). For instance, in the time distribution of the 10 accesses mentioned above, if the 5-minute window is divided into 10 30-second sub-windows, with 3 sub-windows having 3, 3, and 4 accesses respectively, and the remaining 7 sub-windows having 0 accesses, the calculated coefficient of variation is 0.3. Therefore, the temporal locality factor is 1 - 0.3 = 0.7 (the smaller the coefficient of variation, the higher the locality factor).The process of determining the dynamic popularity score of each memory page based on the first access frequency and the temporal locality factor is to integrate the first access frequency and the temporal locality factor into a comprehensive index through a preset weighted algorithm to fully reflect the popularity of the memory page (considering both the frequency of access and the temporal correlation of access). For example, if the first access frequency of a memory page is 3 times / minute (normalized value is 0.6) and the temporal locality factor is 0.7, if weight 1 = 0.5 and weight 2 = 0.5, then the dynamic popularity score is 0.6 × 0.5 + 0.7 × 0.5 = 0.65.
[0038] In practice, the target operating system's heat analysis module first reads the preset first time window configuration (e.g., 5 minutes) and collects the access timestamps of each memory page within the window through the memory management unit. Then, it calculates the first access frequency by counting the total number of accesses for each page (e.g., if a page is accessed 12 times in 300 seconds, the frequency is 0.04 times / second, and the normalized value is 0.8). At the same time, the 5-minute window is divided into 10 sub-windows of 30 seconds each, and the coefficient of variation of the access count for each sub-window is calculated (e.g., 0.2) and converted into a temporal locality factor (0.8). Finally, the page is weighted according to preset weights (e.g., 0.6 and 0.4) to obtain the dynamic heat score of the page as 0.8×0.6+0.8×0.4=0.8, and it is judged as a high-heat page.
[0039] By implementing the above embodiments, obtaining page access frequency within a preset time window and introducing a temporal locality factor can more accurately reflect the actual access patterns of each memory page, avoiding misjudgment of access characteristics by traditional static statistical methods. This allows hot data and cold data to be dynamically distinguished, providing a reliable basis for subsequent hierarchical migration. It can also improve the memory management's ability to perceive data characteristics, making data storage and exchange decisions more in line with access patterns, and fundamentally enhancing the system's intelligence level.
[0040] In some embodiments, determining the temporal locality factor of a corresponding memory page based on the access time distribution of each memory page within a preset first time window may include: dividing the preset first time window into multiple consecutive time sub-windows; obtaining the second access frequency of the corresponding memory page within each time sub-window; and determining the temporal locality factor based on the dispersion of the distribution of the second access frequencies of each time sub-window. The dispersion is negatively correlated with the temporal locality factor.
[0041] In some examples, a pre-defined fixed time interval (preset first time window) used for statistical access information can be divided into several smaller, continuous time segments of equal length to refine the analysis of memory page access time distribution. The target operating system can determine the number or duration of sub-windows through system configuration parameters, with the division rule being continuous and non-overlapping, and the total duration equal to the duration of the pre-defined first time window. For example, if the pre-defined first time window is 5 minutes (300 seconds), the system can divide it into 10 consecutive time sub-windows, each with a duration of 30 seconds (i.e., 0-30 seconds, 31-60 seconds...271-300 seconds). The total number of times memory pages are accessed within each time sub-window can be counted, and the ratio of this number to the sub-window duration can be calculated to reflect the frequency of page access in each subdivided time period. The acquisition method is to record the timestamp of each access event through the memory management unit, match the time sub-window to which the timestamp belongs, count the total number of accesses in each sub-window, and then divide by the sub-window duration (in seconds). For example, if a memory page is divided into 10 30-second sub-windows in a 5-minute window, the first sub-window (0-30 seconds) is accessed 4 times, the second sub-window (31-60 seconds) is accessed 0 times, and the third sub-window (61-90 seconds) is accessed 5 times, then the corresponding second access frequencies are 4 times / 30 seconds ≈ 0.13 times / second, 0 times / 30 seconds = 0 times / second, and 5 times / 30 seconds ≈ 0.17 times / second, respectively. The degree of difference (distribution dispersion) between the second access frequencies of multiple time sub-windows can be calculated and converted into a quantitative indicator reflecting the clustering of access time (temporal locality factor). The higher the distribution dispersion (i.e., the greater the difference in access frequencies among sub-windows), the lower the temporal locality factor, and vice versa. First, the statistical dispersion index (such as variance, standard deviation, or coefficient of variation) of the second access frequency of each time sub-window can be calculated. Then, the dispersion can be mapped to a factor value between 0 and 1 using a preset conversion formula (such as temporal locality factor = 1 - (coefficient of variation / maximum coefficient of variation)). The maximum coefficient of variation is the theoretical maximum value preset by the system. For example, if the second access frequencies of a memory page in 10 time sub-windows are 0.13, 0, 0.17, 0, 0, 0.2, 0, 0.15, 0, 0.15 times / second, the calculated coefficient of variation is 0.6 (assuming the maximum coefficient of variation is 1.0). Then, the temporal locality factor = 1 - 0.6 = 0.4, indicating that its access time distribution is relatively dispersed and its locality is weak.
[0042] By implementing the above embodiments, dividing the time window into multiple sub-windows and calculating the dispersion of access distribution, a fine quantification of the temporal locality factor can be achieved, thereby more accurately reflecting the concentration of data access. It can identify hot pages that are frequently accessed in a short period of time and cold pages that are accessed infrequently in a long period of time, avoiding unreasonable migration caused by the confusion of hot and cold data, effectively reducing invalid I / O operations, and further improving the accuracy of data exchange and the overall system response efficiency.
[0043] In some embodiments, the aforementioned implementation of a tiered data migration strategy based on the current memory pressure level and dynamic heat score of the target operating system may include: comparing the dynamic heat score with a first scoring threshold and a second scoring threshold to classify memory pages into hot data type, warm data type, and cold data type; wherein the first scoring threshold is greater than the second scoring threshold; determining the current memory pressure level based on the proportion of free memory in the target operating system, and implementing a corresponding tiered data migration strategy based on the current memory pressure level to migrate at least one type of memory page among cold data type, warm data type, and hot data type to the secondary Swap storage space or the primary Swap storage space.
[0044] In some examples, the first scoring threshold and the second scoring threshold are critical values used to classify memory page types, where the first scoring threshold is greater than the second scoring threshold, and the two together constitute the classification standard for dynamic popularity scoring; for example, in the memory management of smart terminals, the first scoring threshold can be set to 0.7 and the second scoring threshold can be set to 0.3 to distinguish between hot data type, warm data type and cold data type memory pages.
[0045] Hot data, warm data, and cold data are three page types categorized based on the comparison of the dynamic popularity score of memory pages with first and second score thresholds, reflecting the activity level of page access. Hot data pages are memory pages with a dynamic popularity score higher than the first score threshold, characterized by frequent access and strong temporal locality, and are sensitive to response speed. Warm data pages have a dynamic popularity score between the first and second score thresholds, characterized by moderate access frequency and are suitable for migration. Cold data pages have a dynamic popularity score lower than the second score threshold, characterized by very infrequent access and the lowest priority. The memory pressure level (e.g., low, medium, high, urgent) can be determined by calculating the proportion of unused space in physical memory to total physical memory (free memory ratio), matching it to a preset proportion threshold, and then selecting the corresponding rules based on the pressure level to migrate specific types of memory pages to secondary or primary swap space.
[0046] By implementing the above embodiments, page popularity is divided into three categories: hot, warm, and cold data. Combined with the system memory pressure level, a hierarchical migration is performed, enabling dynamic allocation of data between the main Swap and the auxiliary Swap. This allows for adaptive selection of the optimal data exchange path under different operating pressures, ensuring high access performance for active data while maximizing the use of compressed storage space. This achieves balanced resource utilization and dynamic optimization of system I / O load.
[0047] In some embodiments, the aforementioned determination of the current memory pressure level based on the free memory ratio of the target operating system and the execution of a corresponding tiered data migration strategy based on the current memory pressure level may include: when the free memory ratio is higher than a first ratio threshold, determining the current memory pressure level as a low memory pressure level, in which case the tiered data migration strategy is to migrate only cold data type memory pages to the auxiliary Swap storage space; when the free memory ratio is between a second ratio threshold and a first ratio threshold, determining the current memory pressure level as a medium memory pressure level, in which case the tiered data migration strategy is to migrate all cold data type memory pages and a first proportion of warm data type memory pages to the auxiliary Swap storage space. p storage space; when the proportion of free memory is between the third and second proportion thresholds, the current memory pressure level is determined to be high memory pressure level. At this time, the hierarchical data migration strategy is to migrate all cold and warm data memory pages to the auxiliary swap storage space, and migrate the second proportion of hot data memory pages to the main swap storage space; when the proportion of free memory is lower than the third proportion threshold, the current memory pressure level is determined to be critical memory pressure level. At this time, the hierarchical data migration strategy is to migrate all cold and warm data memory pages to the auxiliary swap storage space, and migrate all hot data memory pages to the main swap storage space.
[0048] In some examples, when the proportion of unused space in physical memory to the total physical memory (free memory ratio) exceeds a preset first proportion threshold, the memory pressure is determined to be at a low level. Only the cold data type pages with the lowest access frequency need to be migrated to the secondary swap space to free up physical memory. The first proportion threshold is a critical value used to define the low memory pressure level. It is obtained by the target operating system through a configuration file preset (usually 30%), which can be adjusted according to the device type (such as mobile phone, smartwatch). For example, a smartphone has a total physical memory of 6GB, and the first proportion threshold is set to 30% (i.e., 1.8GB). If the current free memory is 2GB (the free memory ratio is about 33.3%, which is higher than 30%), it is determined to be a low memory pressure level. At this time, the migration module only compresses the cold data type pages with a dynamic popularity score lower than the second score threshold (such as 0.3) and writes them to the secondary swap space. Hot data type and warm data type pages are still retained in physical memory. When the free memory ratio is between the second threshold (lower than the first threshold) and the first threshold, the memory pressure is considered moderate. The migration scope needs to be expanded to free up more physical memory. Specifically, all cold data pages and some warm data pages are migrated to the secondary swap space. The second threshold is the lower limit for defining the moderate memory pressure level (typically 15%), and the first threshold is the migration ratio for warm data pages (default 50%), both obtained from the system configuration file. When the free memory ratio is between the third threshold (lower than the second threshold) and the second threshold, the system considers the memory pressure to be high. The migration scope needs to be further expanded. In addition to migrating all cold and warm data pages to the secondary swap space, some hot data pages also need to be migrated to the primary swap space. The third threshold is the lower limit for defining the high memory pressure level (typically 5%), and the second threshold is the migration ratio for hot data pages (default 30%), both obtained from the system configuration file. When the proportion of free memory falls below the third threshold, the memory pressure is deemed to be in an emergency, and all migrateable memory pages must be released to prevent system crash. Specifically, all cold and warm data pages are migrated to the secondary swap space, and all hot data pages are migrated to the primary swap space. The third threshold is obtained in the same way as before (usually 5%).
[0049] By implementing the above embodiments, the system pressure is graded based on the proportion of free memory, and corresponding data migration strategies are configured for each pressure level. This enables gradual resource regulation at different stages of the system, from low load to high load and then to emergency state. It can avoid excessive swapping while ensuring system stability, effectively reduce disk I / O conflicts and latency, and ensure that the system still has sustainable operation capability under memory shortage scenarios, thereby improving overall operating efficiency and reliability.
[0050] In some embodiments, step 103 may include: when the current CPU utilization is lower than a first preset load threshold, determining a first compression algorithm as the target compression algorithm; when the current CPU utilization is between the first preset load threshold and a second preset load threshold, determining a second compression algorithm as the target compression algorithm; when the current CPU utilization is higher than the second preset load threshold, determining a third compression algorithm as the target compression algorithm; wherein the compression ratio and processor overhead configured for the first compression algorithm, the second compression algorithm, and the third compression algorithm decrease sequentially; and the compression algorithm applied to the auxiliary Swap storage space is switched or configured as the target compression algorithm.
[0051] In some examples, the first, second, and third compression algorithms in this section are three types of compression algorithms pre-integrated into the target operating system to assist in the utilization of swap space. Their core differences lie in the compression ratio (the ratio of the compressed data to the original data) and processor overhead (the CPU resources used during compression / decompression). The compression ratio and processor overhead decrease in the order of first compression algorithm > second compression algorithm > third compression algorithm. For example, the first compression algorithm uses a high-compression version of LZ4, the second uses standard LZ4, and the third uses the LZO algorithm. When the CPU load (current CPU utilization) is below a preset first threshold, the system determines that CPU resources are sufficient and prioritizes the first compression algorithm, which has the highest compression ratio and higher processor overhead, to maximize the utilization of the auxiliary swap space. The first preset load threshold is the threshold for defining low CPU load, and it is obtained by the target operating system through a configuration file preset (usually 40%). When CPU utilization is between the first preset load threshold (low load upper limit) and the second preset load threshold (high load lower limit), the CPU resources are considered moderate. A second compression algorithm, balancing compression ratio and processor overhead, is selected to balance capacity utilization and system response speed. The second preset load threshold is the critical value defining high CPU load, determined by system preset (usually 70%), and is greater than the first preset load threshold. When CPU utilization exceeds the second preset load threshold, the system determines CPU resources are strained and prioritizes a third compression algorithm with a lower compression ratio but minimal processor overhead to reduce CPU usage and ensure overall system response speed. The second preset load threshold is determined in the same way (usually 70%).
[0052] By implementing the above embodiments, the real-time CPU utilization is monitored and different compression algorithms are adaptively selected. The system prioritizes high compression ratio algorithms to improve space utilization under low load and low overhead algorithms to reduce processing burden under high load. This effectively balances compression efficiency and processing performance, avoids performance degradation caused by excessive CPU usage due to compression calculations, and achieves coordinated optimization of memory compression and system computing resources.
[0053] In some embodiments, step 104 may include: obtaining the free page ratio and allocation success rate of the physical memory, the compression efficiency and space utilization of the auxiliary Swap storage space, and the I / O load and migration frequency of the main Swap storage space; adjusting the heat rating threshold for data classification, the free memory ratio threshold for determining memory pressure level, and / or the load threshold for selecting compression algorithms based on at least one of the free page ratio, allocation success rate, compression efficiency, space utilization, I / O load, and migration frequency; wherein the heat rating threshold may include a first rating threshold and a second rating threshold, the free memory ratio threshold may include a first ratio threshold, a second ratio threshold, and a third ratio threshold, and the load threshold may include a first preset load threshold and a second preset load threshold.
[0054] In some examples, the free page ratio is the ratio of the number of free pages in physical memory to the total number of pages, reflecting the remaining available space in physical memory. It is obtained by using the target operating system's memory management unit to count the number of free pages in physical memory against the total number of pages and calculating the ratio; for example, if a device has 10,000 physical memory pages and currently has 3,000 free pages, then the free page ratio is 30%. The allocation success rate is the percentage of successful page allocation requests in physical memory, reflecting the allocation efficiency of physical memory. It is obtained by recording the total number of allocation requests and the number of successful allocations per unit time using a memory allocation monitoring module and calculating the ratio (successful allocations / total requests × 100%); for example, if 85 out of 100 page allocation requests are successful, the allocation success rate is 85%. Compression efficiency is the ratio of the compressed data size to the original data size in the auxiliary swap space, reflecting the space-saving effect of the compression algorithm. The data utilization rate is obtained by reading the total size of the original data and the total size of the compressed data through the statistics interface of the memory compression block device, and calculating the ratio. For example, if the total size of the original data is 100 megabytes and the compressed data is 40MB, then the compression efficiency is 100:40 = 2.5:1. Space utilization is the ratio of the used compressed space to the total compressed space in the secondary swap storage space, reflecting the load level of the secondary swap space. It can be calculated by reading the used compressed space and the total compressed space through the ZRAM statistics interface. For example, if the total size of the secondary swap storage space is 2GB and 1.2GB is used, then the space utilization rate is 60%. Input / output load is the percentage of time the primary swap storage space is used for read / write operations per unit of time, reflecting the I / O activity of the primary swap space. It can be calculated using disk monitoring tools by tracking the proportion of read / write time to total time for the primary swap partition. For example, if the primary swap space is in read / write state for 60 seconds out of 100 seconds, then the input / output load is 60%. Migration frequency is the total number of times memory pages are moved into or out of the main swap space per unit of time. It reflects the page swapping activity of the main swap space and can be calculated by using the operating system's page migration logs to count the total number of migrations per unit of time (e.g., 1 minute). For example, if there are 120 page migrations into the main swap space and 80 migrations out in 1 minute, the migration frequency is 200 times / minute. The heat rating threshold used for data classification is a critical value used to divide memory pages into hot, warm, and cold data types. It includes a first rating threshold (the boundary between hot and warm data) and a second rating threshold (the boundary between warm and cold data). For example, if physical memory is still tight after cold data migration, the second rating threshold can be increased from 0.3 to 0.4 to expand the range of cold data and increase the migration volume.The free memory ratio threshold used to determine memory pressure levels is a critical value used to divide memory pressure levels (low, medium, high, and urgent). It includes a first ratio threshold (the boundary between low and medium pressure), a second ratio threshold (the boundary between medium and high pressure), and a third ratio threshold (the boundary between high and urgent pressure), with the first ratio threshold > the second ratio threshold > the third ratio threshold. For example, if the main swap space I / O load is too high (e.g., 80%), the second ratio threshold can be increased from 15% to 20% to trigger the medium pressure strategy earlier and reduce migration to the main swap space. The load threshold used to select compression algorithms is a CPU utilization critical value used to switch compression algorithms. It includes a first preset load threshold (the boundary between low and medium load) and a second preset load threshold (the boundary between medium and high load), with the first preset load threshold < the second preset load threshold. For example, if the auxiliary swap space compression efficiency is too low (e.g., <2.0:1), the first preset load threshold can be decreased from 40% to 30% to enable the high compression ratio first compression algorithm earlier.
[0055] By implementing the above embodiments, the real-time status of the main Swap, auxiliary Swap, and physical memory is detected, and the heat threshold, memory pressure judgment threshold, and compression algorithm selection criteria are dynamically adjusted based on the detection results. This forms a closed-loop adaptive adjustment mechanism, which can realize the collaborative optimization of multi-layer storage space. The system can continuously correct parameter configurations according to the actual operating status, thereby maintaining the optimal data distribution state, significantly improving resource utilization, and reducing system I / O load.
[0056] Furthermore, as an implementation of the foregoing method embodiments, this application also provides a memory management device for implementing the foregoing method embodiments. This device embodiment corresponds to the foregoing method embodiments. For ease of reading, this memory management device embodiment will not repeat the details of the foregoing method embodiments one by one, but it should be understood that the device in this application embodiment can correspondingly implement all the contents of the foregoing method embodiments. For example... Figure 2As shown, the memory management device 20 includes: a scoring determination unit 201, a policy execution unit 202, an algorithm adjustment unit 203, and a detection and adjustment unit 204. The scoring determination unit 201 determines the dynamic heat score of each memory page based on the access information of the memory pages in the target operating system. The policy execution unit 202 executes a corresponding hierarchical data migration strategy based on the current memory pressure level and dynamic heat score of the target operating system to migrate different memory pages to the corresponding primary Swap storage space or secondary Swap storage space. The algorithm adjustment unit 203 adjusts the compression algorithm applied to the secondary Swap storage space based on the current CPU utilization of the target operating system. The detection and adjustment unit 204 detects the real-time status of the primary Swap storage space, secondary Swap storage space, and physical memory, and adjusts the hierarchical data migration strategy and compression algorithm based on the detection results.
[0057] In some embodiments, the scoring determination unit 201 is further configured to obtain the first access frequency of each memory page within a preset first time window; determine the temporal locality factor of the corresponding memory page based on the access time distribution of each memory page within the preset first time window; and determine the dynamic heat score of each memory page based on the first access frequency and the temporal locality factor.
[0058] In some embodiments, the scoring determination unit 201 is further configured to divide a preset first time window into multiple consecutive time sub-windows; obtain the second access frequency of the corresponding memory page in each time sub-window; and determine the temporal locality factor based on the distribution dispersion of the second access frequency of each time sub-window, wherein the distribution dispersion is negatively correlated with the temporal locality factor.
[0059] In some embodiments, the policy execution unit 202 is further configured to compare the dynamic heat score with a first score threshold and a second score threshold to classify the memory page type into hot data type, warm data type and cold data type, wherein the first score threshold is greater than the second score threshold; determine the current memory pressure level according to the free memory ratio of the target operating system, and execute the corresponding hierarchical data migration strategy based on the current memory pressure level to migrate at least one type of memory page of cold data type, warm data type and hot data type to the auxiliary Swap storage space or the main Swap storage space.
[0060] In some embodiments, the policy execution unit 202 is further configured to: determine that the current memory pressure level is low when the free memory ratio is higher than a first ratio threshold; in this case, the tiered data migration strategy is to migrate only cold data type memory pages to the auxiliary Swap storage space; determine that the current memory pressure level is medium when the free memory ratio is between a second ratio threshold and a first ratio threshold; in this case, the tiered data migration strategy is to migrate all cold data type memory pages and a first proportion of warm data type memory pages to the auxiliary Swap storage space; and determine that the current memory pressure level is medium when the free memory ratio is between a third ratio threshold and a second ratio threshold threshold. When the free memory ratio is between the two thresholds, the current memory pressure level is determined to be high memory pressure level. At this time, the tiered data migration strategy is to migrate all cold and warm data memory pages to the auxiliary swap storage space, and migrate the second proportion of hot data memory pages to the main swap storage space. When the free memory ratio is lower than the third threshold, the current memory pressure level is determined to be critical memory pressure level. At this time, the tiered data migration strategy is to migrate all cold and warm data memory pages to the auxiliary swap storage space, and migrate all hot data memory pages to the main swap storage space.
[0061] In some embodiments, the algorithm adjustment unit 203 is further configured to: determine the first compression algorithm as the target compression algorithm when the current CPU utilization is lower than the first preset load threshold; determine the second compression algorithm as the target compression algorithm when the current CPU utilization is between the first preset load threshold and the second preset load threshold; and determine the third compression algorithm as the target compression algorithm when the current CPU utilization is higher than the second preset load threshold, wherein the compression ratio and processor overhead configured for the first compression algorithm, the second compression algorithm, and the third compression algorithm are all decreased sequentially; and switch or configure the compression algorithm applied to the auxiliary Swap storage space as the target compression algorithm.
[0062] In some embodiments, the detection and adjustment unit 204 is further configured to acquire the free page ratio and allocation success rate of physical memory, the compression efficiency and space utilization of auxiliary Swap storage space, and the I / O load and migration frequency of main Swap storage space; and adjust the heat rating threshold for data classification, the free memory ratio threshold for determining memory pressure level, and / or the load threshold for selecting compression algorithm based on at least one of the free page ratio, allocation success rate, compression efficiency, space utilization, I / O load, and migration frequency, wherein the heat rating threshold includes a first rating threshold and a second rating threshold, the free memory ratio threshold includes a first ratio threshold, a second ratio threshold, and a third ratio threshold, and the load threshold includes a first preset load threshold and a second preset load threshold.
[0063] This application also provides a computer-readable storage medium storing computer-executable instructions or computer programs that, when executed by a processor, will cause the processor to perform any step of the memory management method provided in this application.
[0064] In some embodiments, the computer-readable storage medium may be a random access memory (RAM), a read-only memory (ROM), flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); or it may be a variety of devices that include one or any combination of the above-mentioned memories.
[0065] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.
[0066] In some embodiments, computer-executable instructions may, but do not necessarily, correspond to files in a file system, and may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).
[0067] In some embodiments, computer-executable instructions may be deployed to execute on an electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.
[0068] like Figure 3 As shown, this application also provides an electronic device 30, including a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor. When the processor 320 executes the computer program 311, it implements any step of the above-described memory management method.
[0069] This application also provides a computer program product comprising a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer program or computer-executable instructions from the computer-readable storage medium and executes the computer program or computer-executable instructions, causing the electronic device to perform any step of the memory management method described above.
[0070] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A memory management method, characterized in that, Applied to a target operating system, the target operating system includes a primary Swap storage space and a secondary Swap storage space based on memory compression, the memory management method includes: Based on the access information of the memory pages of the target operating system, determine the dynamic heat score of each memory page; Based on the current memory pressure level of the target operating system and the dynamic heat score, a corresponding hierarchical data migration strategy is executed to migrate different memory pages to the corresponding main Swap storage space or the auxiliary Swap storage space. Based on the current CPU utilization of the target operating system, adjust the compression algorithm applied to the auxiliary Swap storage space; The real-time status of the main Swap storage space, the auxiliary Swap storage space, and the physical memory is detected, and the hierarchical data migration strategy and the compression algorithm are adjusted based on the detection results.
2. The memory management method according to claim 1, characterized in that, The determination of dynamic popularity scores for each memory page based on access information of the target operating system's memory pages includes: Get the first access frequency of each memory page within a preset first time window; Based on the access time distribution of each memory page within the preset first time window, the temporal locality factor of the corresponding memory page is determined. Based on the first access frequency and the time locality factor, the dynamic heat score of each memory page is determined.
3. The memory management method according to claim 2, characterized in that, The step of determining the temporal locality factor of a corresponding memory page based on the access time distribution of each memory page within the preset first time window includes: The preset first time window is divided into multiple consecutive time sub-windows; Obtain the second access frequency of the corresponding memory page within each of the aforementioned time sub-windows; The temporal locality factor is determined based on the degree of dispersion of the second access frequency in each of the time sub-windows, wherein the degree of dispersion is negatively correlated with the temporal locality factor.
4. The memory management method according to claim 1, characterized in that, The step of executing a corresponding tiered data migration strategy based on the current memory pressure level of the target operating system and the dynamic popularity score includes: The dynamic heat score is compared with a first score threshold and a second score threshold to classify memory page types into hot data type, warm data type and cold data type, wherein the first score threshold is greater than the second score threshold; The current memory pressure level is determined based on the proportion of free memory in the target operating system, and a corresponding hierarchical data migration strategy is executed based on the current memory pressure level to migrate at least one type of memory page, namely, cold data, warm data, and hot data, to the auxiliary Swap storage space or the main Swap storage space.
5. The memory management method according to claim 4, characterized in that, The step of determining the current memory pressure level based on the proportion of free memory in the target operating system, and executing a corresponding tiered data migration strategy based on the current memory pressure level, includes: When the proportion of free memory is higher than the first proportion threshold, the current memory pressure level is determined to be a low memory pressure level. At this time, the hierarchical data migration strategy is to migrate only the cold data type memory pages to the auxiliary Swap storage space. When the proportion of free memory is between the second proportion threshold and the first proportion threshold, the current memory pressure level is determined to be medium memory pressure level. At this time, the hierarchical data migration strategy is to migrate all the cold data type memory pages and the first proportion of the warm data type memory pages to the auxiliary Swap storage space. When the proportion of free memory is between the third proportion threshold and the second proportion threshold, the current memory pressure level is determined to be a high memory pressure level. At this time, the hierarchical data migration strategy is to migrate all the cold data type and the warm data type memory pages to the auxiliary Swap storage space, and migrate the second proportion of the hot data type memory pages to the main Swap storage space. When the proportion of free memory is lower than the third proportion threshold, the current memory pressure level is determined to be an emergency memory pressure level. At this time, the hierarchical data migration strategy is to migrate all the cold data type and the warm data type memory pages to the auxiliary Swap storage space, and migrate all the hot data type memory pages to the main Swap storage space.
6. The memory management method according to claim 1, characterized in that, The adjustment of the compression algorithm applied to the auxiliary Swap storage space based on the current CPU utilization of the target operating system includes: When the current central processing unit utilization is lower than the first preset load threshold, the first compression algorithm is determined as the target compression algorithm; When the current central processing unit utilization is between the first preset load threshold and the second preset load threshold, the second compression algorithm is determined as the target compression algorithm; When the current central processing unit utilization is higher than the second preset load threshold, the third compression algorithm is determined as the target compression algorithm, wherein the compression ratio and processor overhead configured for the first compression algorithm, the second compression algorithm, and the third compression algorithm are all reduced sequentially. The compression algorithm applied to the auxiliary Swap storage space is switched or configured to the target compression algorithm.
7. The memory management method according to claim 1, characterized in that, The step of detecting the real-time status of the main Swap storage space, the auxiliary Swap storage space, and the physical memory, and adjusting the hierarchical data migration strategy and the compression algorithm based on the detection results, includes: The free page ratio and allocation success rate of the physical memory, the compression efficiency and space utilization of the auxiliary Swap storage space, and the I / O load and migration frequency of the main Swap storage space are obtained. Based on at least one of the free page ratio, the allocation success rate, the compression efficiency, the space utilization rate, the I / O load, and the migration frequency, adjust the popularity scoring threshold for data classification, the free memory ratio threshold for determining memory pressure level, and / or the load threshold for selecting compression algorithms, wherein the popularity scoring threshold includes a first scoring threshold and a second scoring threshold, the free memory ratio threshold includes a first ratio threshold, a second ratio threshold, and a third ratio threshold, and the load threshold includes a first preset load threshold and a second preset load threshold.
8. A memory management device, characterized in that, Applied to a target operating system, the target operating system including a main Swap storage space and an auxiliary Swap storage space based on memory compression, the memory management method apparatus includes: The scoring determination unit is used to determine the dynamic heat score of each memory page based on the access information of the memory pages of the target operating system. The strategy execution unit is used to execute a corresponding hierarchical data migration strategy based on the current memory pressure level of the target operating system and the dynamic heat score, so as to migrate different memory pages to the corresponding main Swap storage space or the auxiliary Swap storage space. An algorithm adjustment unit is used to adjust the compression algorithm applied to the auxiliary Swap storage space based on the current CPU utilization of the target operating system. The detection and adjustment unit is used to detect the real-time status of the main Swap storage space, the auxiliary Swap storage space, and the physical memory, and adjust the hierarchical data migration strategy and the compression algorithm based on the detection results.
9. An electronic device, comprising: A memory and a processor, characterized in that the processor, when executing a computer program stored in the memory, implements the steps of the memory management method as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the memory management method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Data processing method, readable medium, storage system and program product
CN120447822A
Memory management method and apparatus, device and storage medium
WO2022062524A1
Cited By
Cold and hot data layering method and system based on heterogeneous storage medium
CN121957508A
Memory optimization method and system based on memory hot spot migration monitoring
CN122220261A