Memory optimization method and system based on memory hot spot migration monitoring

By monitoring cold-to-hot migration events of memory pages in the operating system kernel and identifying memory hotspots by utilizing the changing trends of native kernel events, the problem of high memory monitoring overhead in large memory scenarios is solved, achieving low-overhead and efficient memory hotspot monitoring and optimization.

CN122220261APending Publication Date: 2026-06-16联通云数据有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
联通云数据有限公司
Filing Date
2026-05-19
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

Existing memory hotspot monitoring technologies are costly in large memory scenarios and cannot be routinely used in production environments. Furthermore, sampling-based monitoring solutions reduce the accuracy of hotspot identification and cannot balance low system overhead with effective monitoring.

Method used

By capturing cold-to-hot migration events of memory pages in the operating system kernel, and using the changing trends of kernel native events to identify memory hotspot migration status, low-overhead memory optimization is achieved. This includes listening to the LRU list and storage media migration hooks to obtain events, statistically analyzing the changing trends of the number of events within a preset time window, determining the memory hotspot migration status, and executing optimization strategies.

Benefits of technology

It achieves accurate identification of memory hotspot migration behavior without increasing system overhead, reduces the system burden of memory management, and is suitable for long-term stable operation in production environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122220261A_ABST
    Figure CN122220261A_ABST
Patent Text Reader

Abstract

The application provides a memory optimization method and system based on memory hot spot migration monitoring, the method comprising: capturing a cold-to-hot migration event of a memory page in an operating system kernel, the cold-to-hot migration event comprising an event of the memory page being migrated from a data structure representing cold to a data structure representing hot and the memory page being migrated from a low-speed access storage medium to a high-speed access storage medium; counting the number of cold-to-hot migration events of the memory page within a preset time window; and determining a memory hot spot migration state according to the event number change trend within a continuous time window. The application can effectively identify the migration behavior of the memory hot spot based on the determination mode of the continuous event change trend, and achieve the balance between low overhead and effective monitoring.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of memory hotspot monitoring, and in particular relates to a memory optimization method and system based on memory hotspot migration monitoring. Background Technology

[0002] Existing memory hotspot monitoring technologies rely on memory page table scanning and access marker statistics to identify hotspots. The monitoring overhead is linearly related to the number of monitored memory pages. In large memory scenarios, this will consume system computing resources and cannot be routinely used in production environments. Some sampling monitoring solutions reduce overhead by reducing the scanning range, but they will lose access information of some memory pages, reducing the accuracy of hotspot identification. Existing technologies cannot achieve both low system overhead and effective monitoring of memory hotspot migration status, making it difficult to meet the actual needs of memory management in production environments. Summary of the Invention

[0003] This application provides a memory optimization method based on memory hotspot migration monitoring. Based on a continuous event change trend determination method, it can effectively identify memory hotspot migration behavior, achieving a balance between low overhead and effective monitoring. This application also provides a memory optimization system based on memory hotspot migration monitoring.

[0004] This application discloses a memory optimization method based on memory hotspot migration monitoring, including: Capture cold-to-hot migration events of memory pages in the operating system kernel. Cold-to-hot migration events include events where memory pages migrate from a data structure representing cold to a data structure representing hot, and events where memory pages migrate from a low-speed access storage medium to a high-speed access storage medium. The memory hotspot migration status is determined based on the event change trend of the cold-to-hot migration events of the memory pages; The memory optimization strategy corresponding to the memory page is determined and executed based on the memory hotspot migration status of the memory page.

[0005] Optionally, capturing cold-to-hot migration events of memory pages in the operating system kernel includes: Listen for cold and hot structure migration events by monitoring the kernel LRU list migration hook; Listen for kernel storage media migration hooks to obtain storage tier migration events; The cold-to-hot migration event of the memory page is determined based on the cold and hot structure migration event and the storage level migration event.

[0006] Optionally, the process of acquiring hot and cold structure migration events by monitoring the kernel LRU linked list migration hook includes: Listen for memory page migration events by monitoring the kernel LRU list migration hook; Identify, from the memory page linked list migration events, a first linked list migration event from the free linked list to the inactive LRU linked list and a second linked list migration event from the inactive LRU linked list to the active LRU linked list; The hot and cold structure migration events of the memory pages are determined based on the first linked list migration event and the second linked list migration event.

[0007] Optionally, the process of acquiring storage tier migration events via the kernel storage media migration hook includes: Listen for kernel storage media migration hooks to obtain memory page storage migration events; Identify, from the memory page storage migration events, a first storage migration event that migrates from persistent storage media to local memory and a second storage migration event that migrates from remote storage media to local memory; The storage hierarchy migration event of the memory page is determined based on the first storage migration event and the second storage migration event.

[0008] Optionally, determining the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page includes: Count the number of memory page cold-to-hot migration events within a preset time window; The memory hotspot migration status is determined based on the trend of changes in the number of events within a continuous time window.

[0009] Optionally, the number of memory page cold-to-hot migration events within the preset time window includes: Configure an event trigger flag for each memory page; Read the memory page to which the memory domain corresponding to the cold-to-hot migration event belongs, and add consecutive cold-to-hot migration events of memory pages into the counting unit based on the event trigger flag, and update the cumulative value of the counting unit; The number of events within a preset time window is obtained based on the time corresponding to the accumulated value of the counting unit.

[0010] Optionally, determining the memory hotspot migration status based on the trend of event quantity changes within a continuous time window includes: Get the number of events for a memory page across multiple consecutive time windows; Compare the changes in the number of events in adjacent time windows; The memory hotspot migration status of the memory page is determined based on the trend of event quantity changes over multiple consecutive time windows.

[0011] Optionally, determining the memory hotspot migration status of the memory page based on the event quantity change trend over multiple consecutive time windows includes: Identify the trend of event quantity changes within multiple consecutive time windows as a trend of continuous increase in the number of events; The memory page state corresponding to the continuously increasing trend is identified as the state of memory hotspot migration; The memory page state corresponding to a non-continuously increasing trend is identified as the stable state of the memory hotspot.

[0012] Optionally, determining the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page includes: When the memory hotspot migration state is in the memory hotspot migration state, a first optimization strategy is determined. The first optimization strategy includes at least one of the following: performing a reclamation operation on memory pages in a cold data structure, performing a memory resident protection operation on memory pages in a hot data structure, and pre-migrating memory pages in a low-speed access storage medium to a high-speed access storage medium. When the memory hotspot migration state is a stable memory hotspot state, a second optimization strategy is determined. The second optimization strategy includes migrating hot memory pages that have not been accessed within a preset access time from the data structure representing hot data to the data structure representing cold data. The hot memory pages are memory pages located in the data structure representing hot data.

[0013] This application also discloses a memory optimization system based on memory hotspot migration monitoring, the system comprising: The event capture module is used to capture cold-to-hot migration events of memory pages in the operating system kernel. Cold-to-hot migration events include events where memory pages migrate from a data structure representing cold to a data structure representing hot, and events where memory pages migrate from a low-speed access storage medium to a high-speed access storage medium. The status determination module is used to determine the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page; The memory optimization module is used to determine and execute the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page.

[0014] As can be seen from the above technical solution, the memory optimization method based on memory hotspot migration monitoring provided by the present invention obtains direct signals of changes in memory page access popularity by capturing cold-to-hot migration events of memory pages in the operating system kernel, then converts discrete events into comparable quantitative values ​​by counting the number of events through a preset time window, and finally determines the memory hotspot migration status by the trend of event number changes in a continuous time window. In the whole process, all data comes from events naturally generated by the kernel memory management process, without traversing the memory page table or performing additional memory scanning operations, and does not generate system overhead that is positively correlated with memory size. The event capture and statistics process is embedded in the kernel's native execution path and will not affect business operation. At the same time, based on the judgment method of continuous event change trend, the migration behavior of memory hotspots can be effectively identified, achieving a balance between low overhead and effective monitoring. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 This is a flowchart of a memory optimization method based on memory hotspot migration monitoring in an embodiment of this application; Figure 2 This is a flowchart illustrating the capture of cold-to-hot migration events of memory pages in the operating system kernel using a memory optimization method based on memory hotspot migration monitoring, as described in this application embodiment. Figure 3 This is a flowchart illustrating the acquisition of hot and cold structure migration events by monitoring the kernel LRU linked list migration hook in the memory optimization method based on memory hotspot migration monitoring in this application embodiment. Figure 4 This is a flowchart illustrating the process of acquiring storage-level migration events by monitoring the kernel storage medium migration hook in the memory optimization method based on memory hotspot migration monitoring in this application embodiment. Figure 5 This is a flowchart illustrating the process of determining the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page in the memory optimization method based on memory hotspot migration monitoring in the embodiments of this application. Figure 6 This is a flowchart showing the number of memory page cold-to-hot migration events within a preset time window in the memory optimization method based on memory hotspot migration monitoring in this application embodiment; Figure 7This is a flowchart illustrating how the memory optimization method based on memory hotspot migration monitoring in this application determines the memory hotspot migration status according to the trend of the number of events within a continuous time window. Figure 8 This is a flowchart illustrating how the memory optimization method based on memory hotspot migration monitoring in this application determines the memory hotspot migration status of the memory page according to the event quantity change trend of multiple consecutive time windows. Figure 9 This is a flowchart illustrating the process of determining the memory optimization strategy corresponding to a memory page based on the memory hotspot migration status of the memory page in the memory optimization method based on memory hotspot migration monitoring in this application embodiment. Figure 10 This is a structural diagram of the memory optimization system based on memory hotspot migration monitoring in the embodiments of this application. Detailed Implementation

[0017] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not limiting, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application can also be implemented in other embodiments without such specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of this application with unnecessary detail.

[0018] In this embodiment, existing memory hotspot monitoring technology uses CPU page table access marking to collect memory page hotspot information. First, the page table access markings of all memory pages in a specified memory segment are cleared. After a preset time, the page table of the memory segment is scanned again to confirm whether the memory page has been remarked by the CPU for access. This is used to count the number of memory page accesses. This process requires traversing all memory page tables of the specified memory segment twice. When the memory segment capacity is large, the traversal process will consume a lot of processor computing resources. At the same time, this technology needs to perform scanning operations periodically, which will generate continuous system overhead. In actual production environments, in order to ensure the stability of business operations, the hotspot monitoring function is usually turned off.

[0019] To address at least one of the problems existing in the prior art, this embodiment discloses a memory optimization method based on memory hotspot migration monitoring, such as... Figure 1 As shown, the method includes: S100: Captures cold-to-hot migration events of memory pages in the operating system kernel. Cold-to-hot migration events include events where memory pages migrate from a data structure representing cold to a data structure representing hot, and events where memory pages migrate from a low-speed access storage medium to a high-speed access storage medium.

[0020] Specifically, when managing physical memory, the operating system kernel categorizes memory pages based on their access frequency. Memory pages with lower access frequency are stored in data structures representing "cold" access, while those with higher access frequency are stored in data structures representing "hot" access. When the access frequency of a memory page changes, the kernel automatically migrates the page between cold and hot data structures. This migration process directly reflects an increase in the page's access frequency. Low-speed access storage media are those with higher data access latency than local physical memory, while high-speed access storage media are local physical memory. A memory page migrating from a low-speed access storage media to a high-speed access storage media indicates that cold data is being accessed by a process, and the page's access frequency increases from "cold" to "hot."

[0021] In specific examples, memory pages are migrated from data structures representing cold access to data structures representing hot access. This includes migrating memory pages that are being allocated and accessed for the first time from the free list to the inactive LRU list, and migrating memory pages whose access frequency increases from the inactive LRU list to the active LRU list. Memory pages are also migrated from low-speed access storage media to high-speed access storage media. This includes migrating locally cold data loaded from persistent storage media to local memory, and migrating remotely cold data loaded from remote storage media to local memory.

[0022] S200: Determine the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page.

[0023] S300: Determine and execute the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page.

[0024] Specifically, by analyzing the changing direction of the number of cold-to-hot migration events over multiple consecutive time periods, the changes in memory page access popularity are identified, distinguishing between the stable and migrating states of memory hotspots and avoiding misjudgments caused by event fluctuations within a single time period. The memory optimization strategy is a memory management approach tailored to different memory hotspot migration states. The system's memory requirements differ under different states, and the corresponding optimization operations also vary.

[0025] Those skilled in the art will understand that in the entire method flow, all events come from the kernel's native memory management process, without the need to perform any scanning operations on the memory page table, and will not generate system overhead that is positively correlated with memory capacity. The event capture, status determination and optimization execution processes are all embedded in the kernel's native execution path, without adding any additional kernel threads or periodic tasks, and will not affect the operation of business processes, and can run stably in a production environment for a long time.

[0026] In this embodiment, when memory pages migrate between hot and cold data structures, the change in the access frequency of allocated memory by a process can be captured. When memory pages migrate between storage media with different access speeds, the first access scenario of cold data by a process can be captured. Cold-to-hot migration events do not affect the original kernel memory management execution flow. The event acquisition logic only performs event recording operations and immediately returns to the original kernel execution flow after execution, without increasing the execution latency of kernel memory management operations or affecting the normal operation of memory management. In a specific example, when the kernel needs to migrate a memory page from an inactive LRU list to an active LRU list, it first performs the LRU list migration operation, and then calls the hook function to trigger the event acquisition logic. The event acquisition logic only records basic event information and does not affect the total latency of the migration operation.

[0027] It should be noted that the information recorded by the event acquisition logic only includes the event trigger time and the memory domain number to which the memory page belongs. There is no need to record additional information such as the specific address of the memory page and the process to which it belongs. The amount of data recorded is extremely small and will not occupy a large amount of memory storage resources. At the same time, the small amount of recorded content also ensures the execution efficiency of the acquisition logic and will not generate additional system overhead.

[0028] In alternative implementations, such as Figure 2 As shown, the capture of cold-to-hot migration events of memory pages in the operating system kernel includes: S110: Listen for kernel LRU list migration hooks to obtain hot and cold structure migration events.

[0029] S120: Listen for kernel storage media migration hooks to acquire storage tier migration events.

[0030] S130: Determine the cold-to-hot migration event of the memory page based on the cold-to-hot structure migration event and the storage level migration event.

[0031] In this embodiment, the kernel LRU list is a data structure used by the kernel to manage the access frequency of memory pages. The LRU list migration hook is a callback interface reserved by the kernel. When memory pages migrate between LRU list nodes, the kernel automatically calls this hook function. No modification to the kernel's LRU list management logic is required; only the event listening logic needs to be attached to the hook function to achieve event capture. The kernel storage medium migration hook is a callback interface reserved by the kernel for memory page migration across storage media. When memory pages migrate between storage media with different access speeds, the kernel automatically calls this hook function, and the corresponding storage level migration event is obtained by listening to this hook function.

[0032] Specifically, the kernel LRU list migration hook monitoring mechanism attaches custom event collection logic to the kernel's reserved LRU list migration hook. When a memory page migrates between cold and hot data structures, the hook function automatically triggers the event collection logic, recording the event trigger time and the corresponding memory page information. Similarly, the kernel storage medium migration hook monitoring mechanism attaches event collection logic to the corresponding hook function. When a memory page migrates across storage media, the event collection logic is automatically triggered, recording the corresponding event information. Determining cold-to-hot migration events of memory pages based on cold and hot structure migration events and storage tier migration events involves aggregating cold and hot structure migration events and storage tier migration events collected within the same time period, and statistically analyzing the overall trigger count. It should be noted that in this embodiment, the collection logic for both types of events adopts a lock-free design, completing event recording through native kernel atomic operations. This avoids lock contention in a multi-processor environment, does not affect the kernel's parallel execution efficiency, and even in high-load multi-server environments, the event collection process does not generate observable system overhead. Meanwhile, the collection processes for the two types of events are independent of each other and do not interfere with each other. Even if one type of hook function cannot be triggered due to kernel configuration differences, the collection of the other type of event can still proceed normally.

[0033] Furthermore, the loading and unloading process of event acquisition logic can be implemented through the loading and unloading of kernel modules, without recompiling the kernel or restarting the server. This allows deployment in an already running production environment. When a kernel module is loaded, it automatically loads the event acquisition logic to the corresponding hook function; when the kernel module is unloaded, it automatically removes the acquisition logic from the hook function, restoring the hook function to its original state. Those skilled in the art will understand that hook function loading and unloading are native kernel features. This deployment method can flexibly adapt to different business needs. When memory hotspot migration monitoring and optimization are required, the corresponding kernel module can be loaded; when monitoring and optimization are not required, the module can be unloaded.

[0034] In alternative implementations, such as Figure 3 As shown, the process of acquiring hot and cold structure migration events by monitoring the kernel LRU linked list migration hook includes: S111: Listen for memory page list migration events by monitoring the kernel LRU list migration hook.

[0035] S112: Identify from the memory page linked list migration events a first linked list migration event from the free linked list to the inactive LRU linked list and a second linked list migration event from the inactive LRU linked list to the active LRU linked list.

[0036] In this embodiment, the free list stores unallocated physical memory pages. These pages are not accessed by any process and represent the least frequently accessed memory pages. The inactive LRU list stores allocated memory pages with low access frequency, while the active LRU list stores allocated memory pages with high access frequency. In a specific example, the migration of a memory page from the free list to the inactive LRU list indicates that the page has been allocated to a process and accessed for the first time. The page's access frequency increases from the lowest to the second highest, representing the initial stage of a cold-to-hot transition. When the kernel performs this migration operation, it triggers the corresponding LRU list migration hook. By listening to this hook and identifying the state of the memory page before and after the migration, the first list migration event is captured. By migrating a memory page from an inactive LRU list to an active LRU list, we can see that the access frequency of the memory page is continuously increasing. The kernel determines that it is a high-access-hot memory page. The access hotness of the memory page increases from a secondary hot state to a hot state, which is an advanced stage of cold to hot. When the kernel performs this migration operation, it will also trigger the corresponding LRU list migration hook, and capture the second list migration event by identifying the state before and after the migration.

[0037] S113: Determine the hot and cold structure migration events of the memory page based on the first linked list migration event and the second linked list migration event.

[0038] Specifically, the first and second linked list migration events collected within the same time period are merged. Based on these events, the hot and cold migration events of memory pages are determined, reflecting changes in memory page access frequency. Those skilled in the art will understand that the identification of both types of events relies on the kernel's native memory page state flags. These flags are automatically updated by the kernel during the migration process, requiring no additional computation or storage operations. The identification process only needs to read the current and previous states of the memory pages, resulting in high execution efficiency and no additional system overhead.

[0039] In this embodiment, when the workload of a service changes, a new memory region is requested and accessed, triggering a large number of first linked list migration events. When the service's access hotspot shifts from the original memory region to a new memory region, the access frequency of memory pages in the new region continuously increases, triggering a large number of second linked list migration events. In a specific example, when a service process switches from a compute-intensive load to a data processing load, a large amount of new memory is requested to store data to be processed. These newly requested memory pages are migrated from the free linked list to the inactive LRU linked list, triggering a large number of first linked list migration events. These events are captured and included in the statistics. In this embodiment, the first and second linked list migration events can be identified according to different LRU linked list management configurations. Even if the kernel has enabled the hierarchical management function of the LRU linked list, the corresponding hot and cold structure migration events can be captured by identifying the linked list type before and after the memory page migration, without needing to modify the identification logic for different kernel configurations.

[0040] In alternative implementations, such as Figure 4 As shown, the kernel storage media migration hook for acquiring storage tier migration events includes: S121: Listen for kernel storage media migration hooks to obtain memory page storage migration events.

[0041] S122: Identify from the memory page storage migration events a first storage migration event that migrates from persistent storage medium to local memory and a second storage migration event that migrates from remote storage medium to local memory.

[0042] Specifically, migrating a memory page from persistent storage to local memory occurs when cold data stored in persistent storage is read by a process and loaded into local memory. The access frequency of this memory page increases from cold to hot. When the kernel performs this data loading operation, it triggers the corresponding storage media migration hook. By listening to this hook and identifying the source and target media of the memory page migration, the first storage migration event is obtained. Similarly, migrating a memory page from remote storage to local memory occurs when cold data stored remotely is read by a process and synchronized to local memory. The access frequency of this memory page also increases from cold to hot. When the kernel performs this data synchronization operation, it triggers the corresponding storage media migration hook. By identifying the source and target media of the migration, the second storage migration event is obtained. It should be noted that persistent storage media is used for long-term data storage, and its data access latency is much higher than that of local physical memory. Remote storage media is a non-local storage medium connected through a network, which needs to be accessed through network transmission, and its latency is also much higher than that of local physical memory. Persistent storage media and remote storage media are low-speed access storage media, while local memory is the physical memory of the local server and is a high-speed access storage medium.

[0043] S123: Determine the storage level migration event of the memory page based on the first storage migration event and the second storage migration event.

[0044] Specifically, the first and second storage migration events collected within the same time period are merged. Both the first and second storage migration events involve the migration of memory pages from low-speed access storage media to high-speed access storage media. It should be noted that in both the first and second storage migration events, the source and target media information is automatically recorded by the kernel during the migration process, without the need for additional querying or calculation operations.

[0045] In this embodiment, when a service needs to access a local file that has not been accessed before, the file data is loaded from persistent storage medium to local memory, triggering a large number of first storage migration events. These first storage migration events represent the activation of cold data and an increase in memory access activity. When a distributed service needs to access data stored in a remote storage cluster, the data is synchronized to local memory via the network, triggering a large number of second storage migration events. By capturing these second storage migration events, changes in memory hotspots of the distributed service can be obtained. In a specific example, when a database service performs a cold data query operation, cold data stored in local persistent storage medium is loaded into memory, triggering a large number of first storage migration events. It should be noted that the identification process for the first and second storage migration events is adaptable to different storage medium types. Whether it is block storage medium or file storage medium, whether it is local storage or network storage, as long as the access latency of the medium is higher than that of local physical memory, the corresponding migration events can be identified without modifying the identification logic for different storage media, demonstrating good versatility.

[0046] In alternative implementations, such as Figure 5 As shown, determining the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page includes: S210: Count the number of memory page cold-to-hot migration events within a preset time window.

[0047] Specifically, the preset time window is a fixed-length window driven by the kernel clock interrupt. The window's duration matches the kernel's regular memory management statistical cycle, requiring no adjustment based on business scenarios. The process of counting the number of cold-to-hot migration events within the preset time window involves counting all captured cold-to-hot migration events within each time window to obtain the current window's event count. This process only operates on memory pages that have triggered events; memory pages without triggered events are not accessed or processed, eliminating the need to traverse all memory pages in the system. In this specific example, the preset time window's duration is matched to the kernel's memory reclamation cycle, ensuring the timeliness of statistical data while preventing incomplete event statistics due to an excessively short window and delayed status determination due to an excessively long window.

[0048] S220: Determine the memory hotspot migration status based on the trend of the number of events within a continuous time window.

[0049] In this embodiment, the event counts of multiple consecutive windows are arranged in chronological order, and the changes in the event counts of adjacent windows are compared to identify the overall trend of event count changes, thereby determining the migration status of memory hotspots. This process only requires comparing the stored window values. Time windows are used to collect the event counts within a fixed period, converting discrete event trigger signals into comparable quantifiable values. Continuous time windows are multiple windows of equal length arranged in chronological order. By comparing the changes in the event counts within multiple consecutive windows, the overall trend of memory page access heat can be identified, thereby determining the migration status of memory hotspots. In a specific example, three consecutive time windows are set. Three consecutive windows effectively balance the sensitivity and anti-interference capability of the judgment, avoiding both insufficient anti-interference capability due to too few windows and delayed status judgment due to too many windows.

[0050] Those skilled in the art will understand that determining the status based on the changing trend of a continuous time window can effectively filter out instantaneous fluctuations in events within a single time window, avoid misjudgments caused by sudden event triggers, and improve the accuracy of status determination. Furthermore, the entire determination process is highly efficient and does not impose additional burden on the system. In the embodiments of this application, the event count can be performed by memory domain. Each memory domain corresponds to an independent time window and event count. The statistical processes for different memory domains are independent and do not interfere with each other. This allows for the determination of memory hotspot migration status in different memory domains, enabling refined monitoring and optimization by memory domain.

[0051] It should be noted that the preset time window duration can be adapted to the kernel clock frequency without manual adjustment. The window duration setting matches the kernel memory management statistical cycle, ensuring the timeliness of statistical data. This prevents incomplete event statistics due to an excessively short window, and avoids delayed status determination due to an excessively long window. The event count for consecutive time windows is stored using a circular array with a fixed length. When new window data is written, it automatically overwrites the oldest window data, eliminating the need for frequent allocation and release of memory storage resources. In a specific example, when the kernel clock frequency is 100Hz, the preset time window duration can be set to 1 second. This duration is consistent with the kernel's regular statistical cycle, ensuring the accuracy and timeliness of statistical data without incurring additional clock interrupt overhead on the system.

[0052] In alternative implementations, such as Figure 6 As shown, the number of memory page cold-to-hot migration events within the preset time window includes: S221: Configure an event trigger flag for each memory page.

[0053] Specifically, configuring an event trigger flag for each memory page involves reserving a bit in the kernel management structure corresponding to the memory page as the event trigger flag. When a memory page triggers a cold-to-hot migration event within the current time window, this flag is set; otherwise, it remains reset. This flag is automatically reset at the end of each time window, awaiting event statistics for the next time window. It should be noted that the event trigger flag is used to identify whether a memory page has triggered a cold-to-hot migration event within the current time window. The event trigger flag is a native kernel Boolean variable and consumes very little memory resources.

[0054] S222: Read the memory page to which the memory domain corresponding to the cold-to-hot migration event belongs, and add the consecutive cold-to-hot migration events of memory pages into the counting unit based on the event trigger flag, and update the cumulative value of the counting unit.

[0055] Specifically, when a cold-to-hot migration event is triggered, the kernel management structure corresponding to the memory page reads the memory domain number to which the memory page belongs. Each memory domain has a unique number, which determines the memory domain to which the memory page belongs. This reading process only requires accessing the kernel management structure of the memory page and does not require traversing the memory page table or performing other additional operations. When a memory page triggers a cold-to-hot migration event, the event trigger flag corresponding to the memory page is first read. If the flag is not set, an increment operation is performed on the counter unit of the corresponding memory domain, and the event trigger flag is set at the same time. If the flag is already set, the counter unit value is not updated. This process can avoid duplicate counting caused by the same memory page triggering the event multiple times within the same time window, ensuring the accuracy of the statistical results.

[0056] It should be noted that the counting unit is a kernel-native atomic counting variable. Updating atomic counting variables does not require locking, which can ensure the accuracy of counting in a multi-processor environment, while avoiding the system overhead caused by lock contention.

[0057] S223: Obtain the number of events within the preset time window based on the time corresponding to the accumulated value of the counting unit.

[0058] Specifically, at the end of the preset time window, the current cumulative value of the counting unit is read. This value represents the number of cold-to-hot migration events of memory pages within the current time window. After reading, the counting unit is reset to its initial state, awaiting statistics for the next time window. Those skilled in the art will understand that this statistical process only operates on memory pages that have triggered cold-to-hot migration events; memory pages that have not triggered events are not accessed or processed. It does not require traversing all memory pages in the system, and therefore does not incur statistical overhead directly related to memory capacity. The execution efficiency of the statistical process is related to the number of events triggered, but not to the total system memory capacity, thus adapting to the usage requirements of large memory scenarios.

[0059] In this embodiment, the lifecycle of the event trigger marker is completely synchronized with the preset time window. At the end of each time window, the event trigger markers of all memory pages are uniformly reset. The reset process only needs to traverse the memory pages that have triggered the event, without traversing all memory pages in the system. In a specific example, if 1000 memory pages trigger the cold-to-hot migration event within the current time window, at the end of the time window, it is only necessary to traverse these 1000 memory pages and reset their event trigger markers. It is not necessary to traverse millions or even tens of millions of memory pages in the system. The execution time of the reset process is extremely short and will not affect the system.

[0060] Specifically, each memory domain corresponds to an independent event trigger flag management and counting unit. The statistical processes of different memory domains are independent of each other. Even if the number of events in one memory domain is large, it will not affect the statistical processes of other memory domains. The reset process of the counting unit is executed synchronously with the reset process of the event trigger flag. After the flag is reset, the value of the counting unit is reset to zero, ensuring that the statistics of the next time window start from zero, preventing the confusion of counting data from different windows, and ensuring the accuracy of the statistical results.

[0061] In alternative implementations, such as Figure 7 As shown, determining the memory hotspot migration status based on the trend of event quantity changes within a continuous time window includes: S310: Get the number of events in a memory page across multiple consecutive time windows.

[0062] In this embodiment, at the end of each time window, the number of events in that window is stored in a temporary storage area of ​​the kernel. This storage area is a fixed-length array, the length of which is the same as the number of consecutive time windows. When a new time window ends, the new number of events is stored in the array, while the oldest window data is removed, ensuring that the array always stores the latest number of events from multiple consecutive time windows. The multiple consecutive time windows are equal-length windows arranged in chronological order.

[0063] S320: Compare the changes in the number of events in adjacent time windows.

[0064] Specifically, the number of events in the array is arranged in chronological order, and the number of events in two adjacent windows is compared one by one. The change in the value between the next window and the previous window is calculated. By comparing adjacent windows multiple times, the direction of the change in the number of events in multiple consecutive windows can be obtained.

[0065] S330: Determine the memory hotspot migration status of the memory page based on the trend of event quantity changes over multiple consecutive time windows.

[0066] Specifically, the overall status of memory hotspots is determined based on the direction of change in the number of events within multiple consecutive windows. When the number of events shows a continuous increasing trend, it indicates that the number of cold-to-hot memory page events in the system is continuously increasing, and memory hotspots are migrating. When the number of events does not show a continuous increasing trend, it indicates that the memory page access heat in the system is stable, and memory hotspots have not migrated. Judging based on the changing trends of multiple consecutive time windows can effectively filter out instantaneous fluctuations in events within a single time window, avoiding misjudgments caused by sudden event triggers and improving the accuracy of status determination. In this embodiment, the number of consecutive time windows is set to three. This avoids insufficient anti-interference capability due to too few windows, and delays in status determination due to too many windows, adapting to the usage needs of most production environments. For example, the three consecutive time windows are the first window, the second window, and the third window, with the first window ending earliest and the third window ending latest. By comparing the changes in the number of events in the first and second windows, and the changes in the number of events in the second and third windows, two continuous changing directions can be obtained.

[0067] Specifically, when the change direction of two adjacent window pairs is both increasing, it can be determined that the number of events is showing a continuous increasing trend. When the change direction of any adjacent window pair is non-increasing, it can be determined that the number of events is not showing a continuous increasing trend. It should be noted that the event count of consecutive time windows is stored using a circular array with a fixed length. When new window data is written, it automatically overwrites the oldest window data.

[0068] In alternative implementations, such as Figure 8 As shown, determining the memory hotspot migration status of the memory page based on the event quantity change trend across multiple consecutive time windows includes: S321: Identify the trend of event quantity changes within multiple consecutive time windows as a trend of continuous increase in the number of events.

[0069] In this embodiment, the trend of continuously increasing event counts within multiple consecutive time windows is characterized by positive differences between all adjacent window pairs, meaning the number of events in each subsequent window is greater than that in the previous window. This continuously increasing trend indicates that the number of cold-to-hot memory page events in the system is continuously increasing over multiple consecutive periods, and the overall access frequency of memory pages is continuously improving. For example, if there are three consecutive time windows, and the difference between the first and second windows is positive, as is the difference between the second and third windows, and the number of events in all three windows is continuously increasing, this can be identified as a continuously increasing trend. If the difference between any pair of adjacent windows is negative or zero, then a continuously increasing trend cannot be identified.

[0070] S322: The memory page state corresponding to the continuously increasing trend is identified as the memory hotspot migration state.

[0071] Specifically, when the number of events within a continuous time window is detected to be increasing, it is determined that a memory hotspot in the system is migrating, and the corresponding memory hotspot migration status is output.

[0072] S323: Determine the memory page state corresponding to a non-continuously increasing trend as a stable memory hotspot state.

[0073] Specifically, when no continuously increasing trend is detected, it is determined that the overall memory page access heat in the system has not changed and the memory hotspot is in a stable state. The corresponding memory hotspot stable state is output, and the corresponding memory optimization operation is executed.

[0074] Those skilled in the art will understand that the state determination logic is simple and clear, requiring only a judgment on the difference between adjacent windows, without the need for complex calculations, resulting in high execution efficiency. At the same time, the continuously increasing judgment conditions can effectively filter out instantaneous event fluctuations, ensuring the accuracy of state determination and avoiding accidental triggering of subsequent memory optimization operations.

[0075] In this embodiment, the output of the memory hotspot migration status includes only two states: memory hotspot migration in progress and memory hotspot stable state. In a specific example, when the memory hotspot migration in progress state is output, corresponding memory optimization operations can be performed to adapt to the upcoming memory demands of the business. When the memory hotspot stable state is output, conventional memory optimization operations can be performed to improve memory resource utilization. Specifically, the status determination process and the event statistics process are executed synchronously. At the end of each time window, after completing the event count, the difference calculation and trend identification of adjacent windows are immediately performed, and the corresponding memory hotspot migration status is output. The latency of the status output does not exceed the duration of one time window. It should be noted that the status determination processes for different memory domains are independent of each other, and the memory hotspot migration status of different memory domains can be output separately. When a memory domain outputs the memory hotspot migration in progress state, other memory domains can still output the memory hotspot stable state.

[0076] In alternative implementations, such as Figure 9 As shown, the method for determining the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page includes: S331: When the memory hotspot migration state is in the memory hotspot migration state, a first optimization strategy is determined. The first optimization strategy includes at least one of the following: performing a reclamation operation on memory pages in a cold data structure, performing a memory resident protection operation on memory pages in a hot data structure, and pre-migrating memory pages in a low-speed access storage medium to a high-speed access storage medium.

[0077] Specifically, memory pages in cold data structures are reclaimed by reclaiming pages from the free list and inactive LRU list, freeing up more free memory space to meet new memory allocation needs and avoid business anomalies caused by memory allocation failures. Memory pages in hot data structures are protected by memory residency, marking pages in the active LRU list as non-reclaimable. This prevents the kernel from mistakenly reclaiming frequently accessed hot memory pages during memory reclamation, reducing page faults and improving business performance.

[0078] In this embodiment, the operation of pre-migrating memory pages in low-speed access storage media to high-speed access storage media refers to predicting the cold data that will be accessed soon based on the trend of cold-to-hot migration events, and migrating it from the low-speed access storage media to local memory in advance, reducing the waiting time when the business accesses cold data and improving the business response speed. Migrating hot memory pages that have not been accessed within a preset access time from the data structure representing hot data to the data structure representing cold data refers to migrating memory pages that have not been accessed for a long time in the active LRU list to the inactive LRU list, freeing up space in the active LRU list. The state during memory hotspot migration indicates that the business's memory access set is changing, with a large number of new memory pages being accessed. The system needs more free memory to meet the business's memory demands, while simultaneously protecting the hot memory pages that are being accessed from being reclaimed to avoid business performance fluctuations. The stable state of memory hotspot migration indicates that the business's memory access set is in a stable state, with no large number of new memory pages being accessed. At this time, hot memory pages that have not been accessed for a long time can be reclaimed, improving memory resource utilization.

[0079] In this embodiment, the cold memory page refers to a memory page located in a data structure representing cold data. When the system has limited free memory, cold memory page reclamation can be prioritized. When the service has high performance requirements, hot memory page resident protection can be prioritized. The cold data refers to data stored in memory pages located in low-speed access storage media. When there is a large demand for accessing cold data, cold data pre-migration can be prioritized. In a specific example, when a service switches from a compute-intensive load to a data processing load, there will be a large number of new memory demands. At this time, cold memory page reclamation can be performed to release sufficient free memory, while hot memory page resident protection can be performed to prevent the hot memory pages that are being accessed from being reclaimed.

[0080] S332: When the memory hotspot migration state is a stable memory hotspot state, a second optimization strategy is determined. The second optimization strategy includes migrating hot memory pages that have not been accessed within a preset access time from the data structure representing hot data to the data structure representing cold data, wherein the hot memory page is a memory page located in the data structure representing hot data.

[0081] Specifically, the preset access time in the second optimization strategy matches the kernel's memory reclamation cycle, which ensures that the reclaimed memory pages are indeed cold memory pages that have not been accessed for a long time, and will not mistakenly reclaim hot memory pages that are being accessed. At the same time, this operation can be performed when the system is idle, so it will not affect the operation of business.

[0082] It should be noted that the first optimization strategy and the second optimization strategy are adapted to different memory hotspot migration states. The first optimization strategy focuses on ensuring the memory requirements and operating performance of the business, while the second optimization strategy focuses on improving the utilization of memory resources. By dynamically matching the optimization strategy with the hotspot migration state, memory management operations can be made more in line with the actual needs of the business, thereby improving the utilization of memory resources while ensuring business performance.

[0083] This application also provides a memory optimization system based on memory hotspot migration monitoring, such as... Figure 10 As shown, the system includes: Event capture module 11 is used to capture cold-to-hot migration events of memory pages in the operating system kernel. Cold-to-hot migration events include events in which memory pages migrate from a data structure representing cold to a data structure representing hot, and events in which memory pages migrate from a low-speed access storage medium to a high-speed access storage medium.

[0084] The status determination module 12 is used to determine the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page.

[0085] The memory optimization module 13 is used to determine and execute the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page.

[0086] The technical effects of the memory optimization system based on memory hotspot migration monitoring provided in this application are the same as the corresponding methods, and will not be elaborated here.

[0087] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to interchangeably. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0088] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A memory optimization method based on memory hotspot migration monitoring, characterized in that, include: Capture cold-to-hot migration events of memory pages in the operating system kernel. Cold-to-hot migration events include events where memory pages migrate from a data structure representing cold to a data structure representing hot, and events where memory pages migrate from a low-speed access storage medium to a high-speed access storage medium. The memory hotspot migration status is determined based on the event change trend of the cold-to-hot migration events of the memory pages; The memory optimization strategy corresponding to the memory page is determined and executed based on the memory hotspot migration status of the memory page.

2. The memory optimization method based on memory hotspot migration monitoring according to claim 1, characterized in that, The capture of cold-to-hot migration events of memory pages in the operating system kernel includes: Listen for cold and hot structure migration events by monitoring the kernel LRU list migration hook; Listen for kernel storage media migration hooks to obtain storage tier migration events; The cold-to-hot migration event of the memory page is determined based on the cold and hot structure migration event and the storage level migration event.

3. The memory optimization method based on memory hotspot migration monitoring according to claim 2, characterized in that, The monitoring kernel LRU linked list migration hook for acquiring hot and cold structure migration events includes: Listen for memory page migration events by monitoring the kernel LRU list migration hook; Identify, from the memory page linked list migration events, a first linked list migration event from the free linked list to the inactive LRU linked list and a second linked list migration event from the inactive LRU linked list to the active LRU linked list; The hot and cold structure migration events of the memory pages are determined based on the first linked list migration event and the second linked list migration event.

4. The memory optimization method based on memory hotspot migration monitoring according to claim 2, characterized in that, The kernel storage media migration hook for acquiring storage tier migration events includes: Listen for kernel storage media migration hooks to obtain memory page storage migration events; Identify, from the memory page storage migration events, a first storage migration event that migrates from persistent storage media to local memory and a second storage migration event that migrates from remote storage media to local memory; The storage hierarchy migration event of the memory page is determined based on the first storage migration event and the second storage migration event.

5. The memory optimization method based on memory hotspot migration monitoring according to claim 1, characterized in that, The process of determining the memory hotspot migration status based on the event change trend of the cold-to-hot migration events of the memory pages includes: Count the number of memory page cold-to-hot migration events within a preset time window; The memory hotspot migration status is determined based on the trend of changes in the number of events within a continuous time window.

6. The memory optimization method based on memory hotspot migration monitoring according to claim 5, characterized in that, The number of memory page cold-to-hot migration events within the preset time window includes: Configure an event trigger flag for each memory page; Read the memory page to which the memory domain corresponding to the cold-to-hot migration event belongs, and add consecutive cold-to-hot migration events of memory pages into the counting unit based on the event trigger flag, and update the cumulative value of the counting unit; The number of events within a preset time window is obtained based on the time corresponding to the accumulated value of the counting unit.

7. The memory optimization method based on memory hotspot migration monitoring according to claim 5, characterized in that, The process of determining the memory hotspot migration status based on the trend of changes in the number of events within a continuous time window includes: Get the number of events for a memory page across multiple consecutive time windows; Compare the changes in the number of events in adjacent time windows; The memory hotspot migration status of the memory page is determined based on the trend of event quantity changes over multiple consecutive time windows.

8. The memory optimization method based on memory hotspot migration monitoring according to claim 7, characterized in that, The step of determining the memory hotspot migration status of the memory page based on the trend of event quantity changes over multiple consecutive time windows includes: Identify the trend of event quantity changes within multiple consecutive time windows as a trend of continuous increase in the number of events; The memory page state corresponding to the continuously increasing trend is identified as the state of memory hotspot migration; The memory page state corresponding to a non-continuously increasing trend is identified as the stable state of the memory hotspot.

9. The memory optimization method based on memory hotspot migration monitoring according to claim 1, characterized in that, The process of determining the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page includes: When the memory hotspot migration state is in the memory hotspot migration state, a first optimization strategy is determined. The first optimization strategy includes at least one of the following: performing a reclamation operation on memory pages in a cold data structure, performing a memory resident protection operation on memory pages in a hot data structure, and pre-migrating memory pages in a low-speed access storage medium to a high-speed access storage medium. When the memory hotspot migration state is a stable memory hotspot state, a second optimization strategy is determined. The second optimization strategy includes migrating hot memory pages that have not been accessed within a preset access time from the data structure representing hot data to the data structure representing cold data. The hot memory pages are memory pages located in the data structure representing hot data.

10. A memory optimization system based on memory hotspot migration monitoring, characterized in that, The system includes: The event capture module is used to capture cold-to-hot migration events of memory pages in the operating system kernel. Cold-to-hot migration events include events where memory pages migrate from a data structure representing cold to a data structure representing hot, and events where memory pages migrate from a low-speed access storage medium to a high-speed access storage medium. The status determination module is used to determine the memory hotspot migration status based on the event change trend of the cold-to-hot migration event of the memory page; The memory optimization module is used to determine and execute the memory optimization strategy corresponding to the memory page based on the memory hotspot migration status of the memory page.