Active page replacement method and system based on regional reuse pattern recognition
By adopting an active paging method based on regional reuse pattern recognition, the memory region boundaries are adaptively adjusted, and eviction and prefetching are actively triggered. This solves the problems of memory thrashing and redundant swapping traffic in existing technologies, and improves prefetching performance and memory expansion efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAZHONG UNIV OF SCI & TECH
- Filing Date
- 2025-09-18
- Publication Date
- 2026-07-24
AI Technical Summary
Existing eviction strategies struggle to capture long-term data reuse patterns in applications, leading to memory thrashing and redundant swapping traffic. The passive prefetch coverage triggered by page faults has an upper limit, resulting in poor prefetch performance.
The proactive paging method based on regional reuse pattern recognition identifies the working set by sampling and clustering memory accesses within the monitoring window, adaptively adjusting memory region boundaries, proactively triggering eviction and prefetching, and combining access instruction counts and the number of monitoring windows for timing determination, thereby achieving stability judgment of hot and cold states and proactive page management.
It improves prefetch coverage, reduces page faults and invalid swapping traffic, fully leverages the memory expansion benefits of the page swapping mechanism, reduces system overhead, and improves application execution efficiency.
Smart Images

Figure CN121233498B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer memory management technology, and more specifically, relates to an active paging method and system based on regional reuse pattern recognition. Background Technology
[0002] Modern applications are rapidly increasing their demand for memory capacity, a trend that DRAM capacity growth is struggling to keep pace with. Emerging data-intensive workloads, exemplified by large language models, have seen their memory footprint expand from the GB level to the TB level and continue to grow. This trend is particularly pronounced in resource-constrained edge servers, exacerbating the shortage of available DRAM.
[0003] To address memory shortages, operating systems provide page swapping, a transparent memory expansion mechanism for applications. Page swapping tracks the access frequency of each memory page, swapping out "cold" pages to slower swap devices and keeping "hot" pages resident in memory as much as possible, thus expanding available memory space while minimizing performance loss. Advances in solid-state drives (SSDs) and network interconnect memory have provided higher-performance swap devices, promoting the widespread adoption of page swapping in industry. However, when application memory access patterns change dynamically and swapped-out pages are accessed again, the operating system needs to swap them back into memory, causing costly page faults with latency typically ranging from 10 to 30 μs, far exceeding memory hit latency (approximately 100 to 300 ns). Therefore, reducing page fault overhead is crucial for the effectiveness of swapping, which largely depends on the operating system's swapping strategy, including eviction policies for selecting pages to be evicted and prefetch policies for pre-swapping pages that are about to be accessed. An effective swapping strategy is a prerequisite for reducing page faults and maximizing the advantages of page swapping.
[0004] However, existing eviction strategies mostly rely on short-term recency heuristics, making it difficult to capture long-term data reuse patterns in applications, often leading to memory thrashing and redundant swapping traffic. Furthermore, the existing prefetching mechanism in operating systems is passively triggered by page faults, meaning that page faults used to trigger prefetching cannot be overridden, and prefetch coverage decreases as memory access locality deteriorates. Summary of the Invention
[0005] To address the aforementioned deficiencies or improvement needs of existing technologies, this invention provides an active paging method and system based on regional reuse pattern recognition. Its purpose is to solve the problem of the upper limit of coverage of passive prefetching triggered by page fault interruption, improve the prefetching coverage, and shorten the execution time.
[0006] To achieve the above objectives, the present invention provides an active page-switching method based on regional reuse pattern recognition, comprising: S1. Sample the memory access instructions of the application process within the current monitoring window to obtain memory access samples; cluster the memory access samples according to address proximity, and use several virtual address intervals defined by the minimum and maximum virtual addresses of the memory access samples in each cluster as the working set within the current monitoring window. S2, based on the i-th memory region R i Update memory region R based on the overlap ratio with the virtual address range in the working set. i So that memory region R i Aligned with the boundaries of the virtual address ranges in the working set, i=1,2,…,N; initially, the N memory regions are N non-overlapping memory regions that are pre-divided based on the continuity of virtual addresses in the application's virtual address space; S3. When the current monitoring window ends, update the memory region R. i It switches between hot and cold states and identifies the memory region R after the state switch. i Does it have a stable reuse pattern? If the memory region R after the state switch... i If the state is cold and has a stable reuse pattern, then jump to S4; otherwise, let i = i + 1 and jump to S2. S4, Predict memory region R i The next reuse time; in memory region R i Duration of cold state T C More than α·T R At that time, all memory pages within it are swapped out to the swap space, and its state is switched to an unresident state. T R For memory region R i The reuse interval is such that the difference between the adjustable parameter α and 0 is less than a preset threshold; and before the predicted next reuse time, memory pages in the swap space are swapped into memory region R. i In the middle, switch its state to cold state; let i=i+1, and jump to S2. When i=N, take the next monitoring window as the current monitoring window and return to S1 until the application ends.
[0007] Furthermore, in S4, the predicted next reuse time is: t + (T R - T C ); where t is the end time of the current monitoring window; In memory region R i Duration T of non-resident state S More than β·T R At that time, memory pages in the swap space are swapped into memory region R. iIn order to achieve the swapping of memory pages in the swap space into memory region R before the predicted next reuse time. i In the middle; where the difference between the adjustable parameter β and 1 is less than the preset threshold.
[0008] Furthermore, in S2, according to the i-th memory region R i Update memory region R based on the overlap ratio with the virtual address range in the working set. i So that memory region R i Alignment with the boundaries of the virtual address ranges in the working set includes: Overlap ratio ρ i,k When the value is 0, the memory region R is... i The User Agent (UA) is marked as not being accessed within the current monitoring window, and memory region R... i The start and end addresses remain unchanged; k indicates that the current monitoring window is the kth monitoring window; Overlap ratio ρ i,k Greater than 0 and less than the low threshold ρ L When updating memory region R i Address boundaries, so that the memory region R after boundary alignment i The updated memory region R does not overlap with the virtual address range in the working set at all. i Mark the User Agent (UA) as not being accessed within the current monitoring window; Overlap ratio ρ i,k Greater than the high threshold ρ H At that time, memory region R i The AC is marked as having been accessed within the current monitoring window, and memory region R i The start and end addresses remain unchanged; Overlap ratio ρ i,k In ρ L and ρ H In between, the working set and memory region R i The starting address and / or ending address of overlapping virtual address ranges are used as boundaries for memory region R. i The memory region is split, and the memory region completely covered by the working set after the split is marked as the accessed AC within the current monitoring window. The memory region that does not overlap with the working set after the split is marked as the unaccessed UA within the current monitoring window. The boundaries of the split memory regions are aligned with the boundaries of the virtual address ranges in the working set. The memory region with the smallest starting address among the split memory regions is taken as the updated memory region R. i ; Also includes: memory region R i With R i-1 The states are the same, and the duration of both states is the same as that of memory region R.i Reuse interval T R When the difference is less than a preset threshold, memory region R is... i With R i-1 Perform the merge, and use the merged memory region as the updated memory region R. i .
[0009] Furthermore, the overlap ratio ρ i,k for: ρ i,k =|R i ∩W k | / |R i | Where | represents the absolute value operation, used to calculate the size of an interval, ∩ represents the intersection operation, and W k This is the work set within the k-th monitoring window.
[0010] Furthermore, in S3, the updated memory region R... i Switching between hot and cold states includes: Memory region R i When in a cold state, if it is marked as UA, its state remains unchanged, and its state duration is increased; if it is marked as AC, its state is switched to a hot state, and its state duration is updated to the reuse interval T. R ; Memory region R i When in a hot state, if it is marked as AC, its state remains unchanged and its state duration is increased; if it is marked as UA, its state is switched to a cold state and its state duration is reset to 0. Among them, memory region R i The state duration is the memory region R i The duration of maintaining the current state, including absolute and relative time, is represented by memory region R. i The absolute time is represented by the number of monitoring windows experienced during the current state, denoted by memory region R. i The number of memory access instructions executed by the application process while maintaining the current state represents relative time; the reuse interval T R For memory region R i The duration of the cold state; the increase of its state duration includes: increasing the absolute time by a monitoring window number, and increasing the relative time by the number of memory access instructions generated within the current monitoring window.
[0011] Furthermore, in S3, the memory region R after the identification state switch... i Does it have a stable reuse pattern, including: If the memory region R after the state switch iIf the relative difference between the number of memory access instructions executed by the application process during its cold state and the number of memory access instructions executed by the application process during its previous cold state does not exceed a preset stability threshold ε, then the memory region R after the state switch is considered to be... i It has a stable reuse pattern; otherwise, the memory region R after the state switch is considered to be... i There is no stable reuse pattern.
[0012] Furthermore, in S1, memory access instructions of the application process are sampled based on hardware performance events within the current monitoring window; wherein, the hardware performance events are triggered by a counting threshold of memory access instructions, and sampling is triggered when the counting threshold is exceeded. The memory access sample includes a process identifier and a virtual address; the memory access sample is stored in a circular buffer corresponding to the operating system kernel address space according to the process identifier; Clustering the memory access samples based on address proximity includes: At the end of the current monitoring window, collect all memory access samples in the circular buffer and sort them in ascending order according to the size of the virtual address of the memory access sample; cluster them according to the distance between the virtual addresses of adjacent memory access samples, and memory access samples whose virtual address distance is less than the specified address distance threshold D are assigned to the same cluster. In S2, initially, the starting addresses and sizes of the N memory regions are determined by the application's memory allocation behavior. The starting addresses of the N memory regions are arranged in ascending order, and the N memory regions constitute the application's virtual address space.
[0013] The present invention also provides an active page-switching system based on regional reuse pattern recognition, comprising: The sampling and clustering module is used to sample the memory access instructions of the application process within the current monitoring window to obtain memory access samples; the memory access samples are clustered according to address proximity, and several virtual address intervals defined by the minimum and maximum virtual addresses of the memory access samples in each cluster are used as the working set within the current monitoring window. The memory region management module is used to manage memory regions based on the i-th memory region R. i Update memory region R based on the overlap ratio with the virtual address range in the working set. i So that memory region R i Aligned with the boundaries of the virtual address ranges in the work set, i=1,2,…,N; initially, the N memory regions are N non-overlapping memory regions of the application's virtual address space after pre-division; The pattern recognition module is reused for updating the memory region R. i It switches between hot and cold states and identifies the memory region R after the state switch. iDoes it have a stable reuse pattern? If the memory region R after the state switch... i If the system is in a cold state and has a stable reuse mode, then jump to the active switching strategy execution module; otherwise, set i=i+1 and jump to the memory region management module. The proactive swapping strategy execution module is used to predict memory region R. i The next reuse time; in memory region R i Duration of cold state T C More than α·T R At that time, all memory pages within it are swapped out to the swap space, and its state is switched to an unresident state. T R For memory region R i The reuse interval is such that the difference between α and 0 is less than a preset threshold; and before the predicted next reuse time, memory pages in the swap space are swapped into memory region R. i In the middle, switch its state to cold state; let i=i+1, and jump to the memory region management module. When i=N, take the next monitoring window as the current monitoring window and return to the sampling clustering module until the application ends.
[0014] The present invention also provides an active paging device based on regional reuse pattern recognition, including a computer-readable storage medium and a processor; The computer-readable storage medium is used to store executable instructions; The processor is used to read executable instructions stored in the computer-readable storage medium and execute the active paging method based on regional reuse pattern recognition described above.
[0015] The present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the active paging method based on regional reuse pattern recognition as described in any of the preceding claims.
[0016] In summary, the above-described technical solutions conceived in this invention can achieve the following beneficial effects: (1) After each monitoring window ends and the cold / hot state transition is completed, the present invention enters the page swapping judgment when the memory area is in a cold state and has a stable reuse mode, and actively swaps out pages at the end of the cooling phase (cold state duration T). C More than α·T RWhen the cooling-off period is deemed sufficiently long, the replacement of this memory region is actively triggered. Pages are proactively prefetched before the predicted next reuse time, avoiding the coverage limit issue of passive prefetching triggered by page faults. Compared to existing passive page fault triggering methods, this invention significantly improves prefetch coverage through proactive prefetching, effectively reducing the number of high-latency page faults on the critical path, thereby shortening execution time. Combined with proactive replacement, it avoids the problem of prefetching being blocked by replacement operations due to insufficient memory space, significantly reducing application execution time. When prefetching requires space, it works in conjunction with proactive replacement to prevent memory pages from being swapped out just before use, reducing erroneous replacements, avoiding cache thrashing, and thus reducing invalid page swapping traffic. This invention fully leverages the advantages of page swapping mechanisms in memory space expansion.
[0017] (2) Further, when the duration of the non-resident state of the memory region is T S More than β·T R Active prefetching begins at a specific time to ensure sufficient time is allocated for the memory region so that memory pages are read into memory before the predicted next reuse time; in this invention, during the reuse interval T... R The text introduces a cooling phase and a warm-up phase to trigger page replacement and prefetching, from 0 to α·T. R As a cooling phase (the current state is cold), β·T R As the trigger point for entering the preheating phase, the adjustable parameters α and β limit the length of the cooling phase and the preheating phase, respectively. This ensures that the memory region that was previously in a hot state enters the cold state completely during the cooling phase, and that the preheating phase allows enough time to ensure that the memory region is read into memory before the predicted next reuse time.
[0018] (3) Furthermore, the present invention employs a memory region granularity management and coordination strategy to reduce system overhead. Specifically, based on the overlap ratio between the memory region and the virtual address range in the working set, the memory region is adaptively adjusted. Based on the region boundary alignment, splitting and merging mechanism of the working set integration, each memory region can be quickly converged to the actual memory access unit of the application (data used as a whole in the application process), maintaining the attribute of each memory region being accessed as a coordination unit, and adapting to changes in access mode in real time. This allows subsequent paging to be performed using "memory region" as the coordination unit, and batch selection of eviction and prefetching pages at the memory region granularity. There is no need to maintain the state of each memory page, reducing the metadata maintenance overhead of page-by-page selection and address demapping.
[0019] (4) Furthermore, this invention combines two indicators, memory access instruction count and monitoring window count, to improve the reliability of timing determination. This invention uses the state duration of each memory region and the number of memory access instructions in the reuse interval as a unified time scale to predict the reuse time, avoiding clock drift and misjudgment caused by the difference of two orders of magnitude between page fault and hit latency. Especially in scenarios with large memory load and significant page fault rate fluctuations, it can effectively avoid premature replacement or missing the warm-up opportunity.
[0020] (5) Furthermore, by accurately sampling hardware performance events and clustering based on address proximity, the present invention can directly locate the working set within each monitoring window. Compared with scanning methods that rely on multi-window merging / splitting and random sampling, the present invention can track the working set more promptly and maintain stable memory usage.
[0021] Overall, this invention reduces page faults caused by page swapping, reduces swap-in / swap-out traffic, and improves application execution efficiency and system throughput by tracking and analyzing data reuse patterns during application memory access, and by proactively performing page replacement and prefetching. It can fully leverage the advantages of page swapping in memory expansion. Attached Figure Description
[0022] Figure 1 A schematic diagram of an active page-switching system based on regional reuse pattern recognition provided in an embodiment of the present invention; Figure 2 A flowchart of a working set identification method based on memory access sample clustering provided in an embodiment of the present invention; Figure 3 An example diagram of adaptive region partitioning based on working set integration provided in an embodiment of the present invention; Figure 4 This is a state transition diagram used in the reuse pattern recognition process provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of an active page swapping and prefetching method based on a reuse pattern provided in an embodiment of the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0024] Example 1 To address the technical challenges of high page fault overhead, memory thrashing, and redundant swapping traffic caused by operating system page swapping relying on proximity heuristics and limited passive prefetch coverage in DRAM-scarce scenarios, this invention provides an active paging method based on regional reuse pattern recognition. The overall approach involves: sampling memory accesses using hardware performance events within a monitoring window and identifying the working set by address proximity clustering; dividing "memory regions" based on virtual address continuity and aligning them with the working set, adaptively splitting and merging to maintain the attribute of each memory region as an access unit; statistically analyzing reuse intervals and determining stability through state transitions of memory regions between cold / hot / non-resident states to form predictable reuse patterns; proactively triggering eviction during the cooling phase and proactively triggering prefetching during the warm-up phase to ensure that the prefetching of this region is completed before the predicted next reuse time, avoiding potential page faults; and employing a dual-scale time metric of "access instruction count + monitoring window count" to ensure reliable timing determination. This approach improves prefetch coverage and space utilization without changing the application, significantly reduces the number of page faults, suppresses thrashing, and reduces invalid swapping traffic, fully releasing the memory expansion benefits of page swapping.
[0025] like Figure 1 As shown, this embodiment of the invention provides an active page-switching method based on regional reuse pattern recognition, including: S1. Working set identification based on memory access sample clustering. Within a preset monitoring window, memory access instructions of the target application process are sampled based on hardware performance events to obtain memory access samples containing process identifiers and virtual addresses. The virtual address is the virtual address of the instruction accessed memory within the process address space. The memory access samples are clustered according to address proximity to obtain the working set within the current monitoring window.
[0026] S2. (For each memory region) Adaptive memory region partitioning based on working set integration. The target application's virtual address space (process address space) is pre-divided into N non-overlapping memory regions based on virtual address contiguousness, and then partitioned according to the i-th memory region R... i Update memory region R based on the overlap ratio with the working set within the current monitoring window. i So that memory region R i The boundary of the memory region R is aligned with the address boundary of the virtual address range within the working set to obtain the updated memory region R. i .
[0027] S3. Reuse pattern recognition based on state transition. At the end of the current monitoring window, the updated memory region R... i Perform a state update (transfer) based on the updated memory region R. i The state of the memory region R is identified.i Does it have a stable reuse pattern? If the updated memory region R i If the state is cold and has a stable reuse pattern, jump to S4 to check for paging; otherwise, set i = i + 1 and jump to S2 to update the next memory region.
[0028] S4. Active page swapping and prefetching method based on reuse pattern. In memory region R i Duration of cold state T C More than α·T R At that time, memory region R i All contained memory pages are swapped out to the swap space and their state is changed to non-resident; in the predicted memory region R i Before the next reuse time, the page in the swap space is swapped into the current memory and its state is changed to cold; let i=i+1, and jump to S2 to update the next memory region, until i=N, the next monitoring window is used as the current monitoring window, and return to S1, until the page swapping and prefetching of each memory region in all monitoring windows (when the target application ends) is completed.
[0029] In this embodiment of the invention, S1 is mounted on the sampling and clustering module and implemented as a set of library functions. These functions include initializing and enabling processor hardware performance events, and collecting, sorting, and clustering memory access samples from the circular buffers corresponding to all cores at the end of each monitoring window. At the start of the application, the initialization function sets the hardware performance events on each processor core to sample only memory access instructions, using a specified sampling count threshold. For example... Figure 2 As shown, the clustering function takes all memory access samples as input, and then performs clustering by scanning once, using whether the distance between adjacent addresses exceeds a specified threshold. This results in several sample clusters. The minimum and maximum sample addresses of each cluster define an address range. All address ranges constitute the working set of the current monitoring window, which is the output of the clustering function. The address distance threshold D depends on the minimum memory allocation size of the application. In data-intensive applications, tests show that a typical value is 18~20 MiB, and the closest power of 2, i.e., 16 MiB, can be taken.
[0030] As a specific implementation, in S1, the hardware performance events used in the working set identification process are used to accurately sample the memory read / write instructions (memory access instructions) corresponding to the target application on each processor core. Sampling is triggered by a count threshold for memory read / write instructions; if the count threshold is exceeded, sampling is triggered, excluding all memory read / write instructions that hit the processor's internal cache. The monitoring window slides at fixed time intervals.
[0031] In this embodiment of the invention, memory access samples are stored in a circular buffer in the operating system kernel address space. Each processor core uses a different circular buffer, and each circular buffer contains a process identifier (the process identifier is used to distinguish the application to which it belongs). Based on the process identifier of the memory access sample, it is stored in the corresponding circular buffer.
[0032] The clustering of memory access samples involves: at the end of the current monitoring window, collecting all memory access samples within the circular buffer and sorting them in ascending order according to the size of their virtual addresses. Then, clustering is performed based on the distance between the virtual addresses of adjacent memory access samples; memory access samples whose virtual address distance is less than a specified address distance threshold D are grouped into the same cluster. Several virtual address intervals defined by the minimum and maximum virtual addresses of the memory access samples in each cluster are defined as the working set within the current monitoring window. That is, for the current cluster, the starting address of the virtual address interval of the current cluster is the virtual address of the memory access sample with the smallest virtual address in the current cluster, and the ending address is the virtual address of the memory access sample with the largest virtual address in the current cluster. Thus, the set consisting of the virtual address intervals of each cluster within the current monitoring window is obtained, and this set is used as the working set within the current monitoring window.
[0033] In this embodiment of the invention, S2 is mounted on the memory region management module and is used to maintain a region list and perform adaptive splitting and merging. The method implemented by the memory region management module is adaptive memory region partitioning based on working set integration. The memory region management module mainly includes a region initialization function and an address boundary update function interface. The region initialization function tracks the application's mmap() system call to allocate virtual address space for the program, and determines the initial address boundary of a region based on the starting address and interval size returned by mmap(). In this embodiment of the invention, the application's mmap() system call is used to allocate virtual address space for the program, and the initial address boundary of a memory region is determined based on the starting address and interval size returned by mmap().
[0034] The address boundary update function takes the current window's working set and a list of regions as input. During execution, it iterates through each memory region in the region list, and the output is the updated list of regions. Figure 3 As shown, considering that the sampling clustering module ensures that the memory address ranges of the working set are arranged in ascending order, the address boundary update function can therefore simultaneously traverse each range within the current working set and each memory region in the region list. The memory region address boundary is updated by calculating the overlap ratio.
[0035] As a specific implementation, in S2, the initial partitioning of memory regions is determined by the application's memory allocation behavior. The virtual address (the starting address of a usable memory region) and the size of the interval returned by the operating system for the application's memory allocation request determine the initial (pre-partitioned) start and end addresses of a memory region. Through N memory allocation actions, N pre-partitioned memory regions are obtained; N is a variable that changes with different applications and with subsequent updates to memory regions, and is constrained by the operating system's physical memory capacity. All memory regions are maintained by a region list. The region list is an ordered doubly linked list, arranged in ascending order of the starting addresses of the memory regions, and adjacent memory regions do not overlap. All memory regions contained in the region list together constitute the effective virtual address space of an application. The region attributes within the region list change dynamically, but the entire lifecycle of the region list spans the entire execution process of the application. Memory regions have the following attributes: start address, end address, state, state duration, and reuse interval; the start address and end address are determined by the memory allocation behavior. Among them: (1) The state of a memory region at a certain moment includes cold, hot and unresident. The cold state means that the current memory region has not been accessed in the current monitoring window but is still resident in memory. The hot state means that the current memory region has been accessed in the current monitoring window and is resident in memory. The unresident state means that the current memory region has not been accessed in the current monitoring window and is not resident in memory.
[0036] (2) The state duration represents the length of time a memory region remains in its current state. In this embodiment of the invention, the state duration is characterized by two dimensions: absolute time and relative time. The absolute time is the number of monitoring windows that the current memory region goes through while it remains in its current state, and the relative time is the number of memory access instructions executed by the application while the current region remains in its current state. If the current monitoring window is the kth monitoring window, the attributes of each memory region are maintained in the first k-1 monitoring windows and are used to update the attributes of the memory region in the kth monitoring window.
[0037] (3) The reuse interval represents the duration of a memory region in a cold state, which is measured by two dimensions: the number of monitoring windows that the memory region goes through during the period of the cold state, and the number of memory access instructions executed during the period of the cold state.
[0038] In this embodiment of the invention, a single memory region has the attribute of being accessed as a cooperative unit. The monitoring window slides at fixed time intervals, and the memory regions are adaptively updated (adjusted) according to the overlap (proportion) between the working set and each memory region within each monitoring window, maintaining the attribute of each memory region being accessed as a cooperative unit.
[0039] Specifically, the principle of adaptive memory region partitioning based on working set integration is the overlap ratio of each memory region relative to the working set. Let there be an i-th memory region R. i The working set W in the kth monitoring window k The overlap ratio is ρ i,k =|R i ∩W k | / |R i | represents the absolute value operation, used to calculate the size of an interval, and ∩ represents the intersection operation; the specific principle of memory region splitting and merging based on overlap ratio is as follows: for a memory region R i , (1) Overlap ratio ρ i,k If the value is 0, then the current region R i Not part of working set W k (Current region and working set W) k (None of the virtual address ranges in the current region R overlaps) i This memory region is marked as unaccessed (UA) within the current monitoring window (the k-th monitoring window). The start and end addresses of this memory region remain unchanged.
[0040] (2) Overlap ratio ρ i,k Greater than 0 and less than the low threshold ρ L This indicates that a small portion of the current memory region belongs to the working set W. k (Current region and working set W) k If a certain virtual address range overlaps, but the overlap is small, then modify the shared address boundary between the current memory region and its neighbors (the memory region preceding or following the current memory region) to make it consistent with the working set W. k The corresponding clusters (overlapping virtual address ranges) are aligned, ensuring that the current memory region and the corresponding virtual address range do not overlap at all, and the updated current memory region is marked as UA. When the header of a memory region overlaps with a virtual address range in the working set, the shared address boundary is the starting address of the current region (see [link to documentation]). Figure 3 In step ②), what is being modified at this point is the address of the current region; conversely, the address of the current region is the end address.
[0041] (3) Overlap ratio ρ i,k Greater than the high threshold ρ H This indicates that most or all of the current memory region belongs to the working set W. k (Most or all of the current memory region is connected to the working set W) k If at least one virtual address range overlaps within the range, it is marked as Accessed (AC). Its start and end addresses remain unchanged.
[0042] (4) Overlap ratio ρ i,k Located at ρ L and ρ H If the boundary is between two points, it indicates that the memory access mode on the current memory region has changed. The current region is split into at least two memory regions, using the address (start address and / or end address) of the virtual address range overlapping the current memory region within the working set as the boundary (if the end address of the current memory region is within the overlapping virtual address range, then this boundary is the start address of the overlapping virtual address range; if the start address of the current memory region is within the overlapping virtual address range, then this boundary is the end address of the overlapping virtual address range). (See [link to relevant documentation]). Figure 3 In step ①), the memory region completely contained within the overlapping virtual address range after splitting is marked as AC, and the memory region that does not overlap with the virtual address range in the working set after splitting is marked as UA. The memory region with the smallest starting address among the split memory regions is taken as the updated current memory region.
[0043] (5) If the current memory region has the same state as the previous memory region, and the duration of the state is close to the reuse interval, then the two memory regions are considered to have the same memory access pattern. The two memory regions are then merged and used as the current updated memory region (see [link]). Figure 3 (③ in the text) to reduce maintenance costs.
[0044] Low threshold ρ L and high threshold ρ H The setting principle is to be able to distinguish the differences in memory access behavior between memory regions. In this embodiment of the invention, the typical values are set to 20% and 80%, respectively. The principle of memory region boundary update is: to align with the address boundaries of the sample clusters (virtual address ranges) within the working set of the current monitoring window, so that the updated memory region belongs entirely to at least one virtual address range within the working set, or does not overlap with any virtual address range.
[0045] In this embodiment of the invention, the current memory region is adaptively adjusted by the overlap ratio between the current memory region and the working set within the current monitoring window, maintaining the attribute that each memory region is accessed as a cooperative unit. This facilitates subsequent paging of the memory region as a whole. At this time, it is only necessary to maintain the same state for all pages of the memory region, without the need to maintain the state for each page, thus reducing maintenance overhead.
[0046] In this embodiment of the invention, S3 is mounted on the reuse pattern recognition module and is used to calculate the reuse interval of the memory region and determine its stability.
[0047] As a specific implementation, in S3, the reuse of the pattern recognition process relies on state transitions in memory regions. These state transitions include state machines with two state transitions, such as... Figure 4 As shown. Specifically, when a memory region is marked as UA (Unaccessed) or AC (Accessed), a state transition occurs, including: (1) When a memory region in a cold state is marked as UA, its state duration is increased, that is, the absolute time and relative time are increased. In this embodiment of the invention, the number of monitoring windows experienced during the current state of the current memory region is increased by 1, and the relative time is added to the number of memory access instructions generated in the current window. The cold state remains unchanged. When it is marked as AC, its state duration is recorded as the reuse interval (reuse pattern recognition), and its state becomes hot. (2) When a memory region in a hot state is marked as AC, its state duration increases while the hot state remains unchanged; when it is marked as UA, its state becomes cold and its state duration is reset to 0. This can be used to determine the start time of the cold state, and thus determine the reuse interval. In this embodiment of the invention, the determination of a stable reuse mode includes: The effectiveness of memory region reuse intervals depends on numerical stability. The stability criterion is that the relative difference between two consecutive reuse intervals does not exceed a stability threshold ε; in this embodiment, the stability threshold ε is a small empirical value, such as a relative difference of less than 5%, which indicates that the reuse interval remains stable. The numerical value used for the stability criterion of the reuse interval is the memory region R. i The number of instructions generated during the current and previous cold state durations.
[0048] In this embodiment of the invention, S3 is mounted on the active switching strategy execution module and implemented as a strategy execution library function. For example... Figure 5 As shown, as a specific implementation method, the active page swapping and prefetching method based on the reuse pattern in S4 includes: Based on memory region R i Duration T of the cold state C Reuse interval T R The current time t (the end time of the current monitoring window) predicts the next reuse time, i.e., the memory region R. i The next time it becomes hot; in this embodiment of the invention, the predicted memory region R i The next reuse time (time) is t + (T) R - T C ).
[0049] In this embodiment of the invention, the active page swapping and prefetching method based on reuse patterns introduces a cooling phase and a warm-up phase during the reuse interval to trigger page replacement and prefetching. The cooling phase ensures that a memory region previously in a hot state completely enters a cold state, while the warm-up phase allows sufficient time to ensure that a memory region is read into memory before the predicted next reuse time. Two adjustable parameters, α and β, limit the length of the cooling phase and the warm-up phase, respectively. Specifically: (1) Current memory region R i Duration of cold state T C More than α·T R If the cooling-off period is deemed long enough, the memory region is actively evicted. All memory pages within this region are swapped out to the swap space, and their state is changed to non-resident. The non-resident state inherits the duration of the cold state and continues to increase; that is, the duration of the non-resident state is increased by both absolute and relative time. In this embodiment, the number of monitoring windows experienced by the current memory region while it remains in its current state is incremented by 1, and the relative time is added to the number of memory access instructions generated within the current window. Otherwise, all memory pages in the current region are not swapped out.
[0050] (2) Further, the current memory region R i Duration T of non-resident state S More than β·T R When it is determined that a warm-up phase should be initiated, prefetching of this region is actively triggered, and pages contained in this region and located in the swap space are swapped into the current memory to avoid potential page faults later (this can be achieved within the predicted memory region R). i The page is switched in before the next reuse time. Its state is changed to "cold," inheriting the duration of the non-resident state and continuously increasing it. That is, the duration of the "cold" state is increased by both absolute and relative time compared to the original non-resident state duration. α and β take values from 0 to 1, with α close to 0 and β close to 1. Specifically, the difference between α and 0 is less than a preset threshold, and the difference between β and 1 is less than a preset threshold. In this embodiment, the preset threshold can be 5%.
[0051] In the above embodiments of the present invention, a hardware platform using DRAM as memory and SSD as swap space is described. In other embodiments, equivalent substitutions can be made based on different hardware platforms.
[0052] Example 2 This invention provides an active paging system based on regional reuse pattern recognition, comprising: a sampling clustering module for sampling memory access hardware events within a monitoring window and clustering the samples according to address proximity to obtain a working set; a memory region management module for maintaining a region list and performing adaptive splitting and merging; a reuse pattern recognition module for calculating the reuse interval of memory regions and determining stability; and an active swapping strategy execution module for proactively initiating page prefetching and page replacement in a timely manner and coordinating the two.
[0053] Each module is used to execute the corresponding steps described above. The specific implementation methods are the same as above and will not be repeated here.
[0054] Example 3 This invention provides an active paging device based on regional reuse pattern recognition, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of the active paging method based on regional reuse pattern recognition in Embodiment 1 above.
[0055] The relevant technical solutions are the same as above, and will not be repeated here.
[0056] Example 4 This invention provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the steps of the active page-switching method based on regional reuse pattern recognition in Embodiment 1 above.
[0057] Specifically, the memory may include high-speed random access memory, as well as non-volatile memory, such as hard disks, RAM, plug-in hard disks, smart media cards (SMC), secure digital (SD) cards, flash cards, at least one disk storage device, flash memory device, or other volatile solid-state storage devices.
[0058] The relevant technical solutions are the same as above, and will not be repeated here.
[0059] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. An active page-switching method based on regional reuse pattern recognition, characterized in that, include: S1. Sample the memory access instructions of the application process within the current monitoring window to obtain memory access samples; The memory access samples are clustered based on address proximity, and several virtual address intervals defined by the minimum and maximum virtual addresses of the memory access samples in each cluster are used as the working set within the current monitoring window. S2, based on the i-th memory region R i Update memory region R based on the overlap ratio with the virtual address range in the working set. i So that memory region R i Aligned with the boundaries of the virtual address ranges in the work set, i=1,2,…,N; initially, the N memory regions are N non-overlapping memory regions that are pre-divided based on the continuity of virtual addresses of the applied virtual address space; S3. When the current monitoring window ends, update the memory region R. i It switches between hot and cold states and identifies the memory region R after the state switch. i Does it have a stable reuse pattern? If the memory region R after the state switch... i If the system is in a cold state and has a stable reuse pattern, then proceed to S4; otherwise... Let i = i + 1, and jump to S2; S4, Predict memory region R i The next reuse time; in memory region R i Duration of cold state T C More than α·T R At that time, all memory pages within it are swapped out to the swap space, and its state is switched to an unresident state. T R For memory region R i The reuse interval is such that the difference between the adjustable parameter α and 0 is less than a preset threshold; and before the predicted next reuse time, memory pages in the swap space are swapped into memory region R. i In the middle, switch its state to cold state; let i=i+1, and jump to S2. When i=N, take the next monitoring window as the current monitoring window and return to S1 until the application ends.
2. The active page-switching method based on regional reuse pattern recognition according to claim 1, characterized in that, In S4, the predicted next reuse time is: t + (T R - T C ); where t is the end time of the current monitoring window; In memory region R i Duration T of non-resident state S More than β·T R At that time, memory pages in the swap space are swapped into memory region R. i In order to achieve the swapping of memory pages in the swap space into memory region R before the predicted next reuse time. i In the middle; where the difference between the adjustable parameter β and 1 is less than the preset threshold.
3. The active page-switching method based on regional reuse pattern recognition according to claim 1 or 2, characterized in that, In S2, based on the i-th memory region R i Update memory region R based on the overlap ratio with the virtual address range in the working set. i So that memory region R i Alignment with the boundaries of the virtual address ranges in the working set includes: Overlap ratio ρ i,k When the value is 0, the memory region R is... i The User Agent (UA) is marked as not being accessed within the current monitoring window, and memory region R... i The start and end addresses remain unchanged; k indicates that the current monitoring window is the kth monitoring window; Overlap ratio ρ i,k Greater than 0 and less than the low threshold ρ L When updating memory region R i Address boundaries, so that the memory region R after boundary alignment i The updated memory region R does not overlap with the virtual address range in the working set at all. i Mark the User Agent (UA) as not being accessed within the current monitoring window; Overlap ratio ρ i,k Greater than the high threshold ρ H At that time, memory region R i The AC is marked as having been accessed within the current monitoring window, and memory region R i The start and end addresses remain unchanged; Overlap ratio ρ i,k In ρ L and ρ H In between, the working set and memory region R i The starting address and / or ending address of overlapping virtual address ranges are used as boundaries for memory region R. i The memory region is split, and the memory region completely covered by the working set after the split is marked as the accessed AC within the current monitoring window. The memory region that does not overlap with the working set after the split is marked as the unaccessed UA within the current monitoring window. The boundaries of the split memory regions are aligned with the boundaries of the virtual address ranges in the working set. The memory region with the smallest starting address among the split memory regions is taken as the updated memory region R. i ; Also includes: memory region R i With R i-1 The states are the same, and the duration of both states is the same as that of memory region R. i Reuse interval T R When the difference is less than a preset threshold, memory region R is... i With R i-1 Perform the merge, and use the merged memory region as the updated memory region R. i .
4. The active page-switching method based on regional reuse pattern recognition according to claim 3, characterized in that, The overlap ratio ρ i,k for: r i,k =|R i ∩W k | / |R i | Where | represents the absolute value operation, used to calculate the size of an interval, ∩ represents the intersection operation, and W k This is the work set within the k-th monitoring window.
5. The active page-switching method based on regional reuse pattern recognition according to claim 3, characterized in that, In S3, the updated memory region R i Switching between hot and cold states includes: Memory region R i When in a cold state, if it is marked as UA, its state remains unchanged, and its state duration is increased; if it is marked as AC, its state is switched to a hot state, and its state duration is updated to the reuse interval T. R ; Memory region R i When in a hot state, if it is marked as AC, its state remains unchanged and its state duration is increased; if it is marked as UA, its state is switched to a cold state and its state duration is reset to 0. Among them, memory region R i The state duration is the memory region R i The duration of maintaining the current state, including absolute and relative time, is represented by memory region R. i The absolute time is represented by the number of monitoring windows experienced during the current state, denoted by memory region R. i The number of memory access instructions executed by the application process while maintaining the current state represents relative time; the reuse interval T R For memory region R i The duration of the cold state; the increase of its state duration includes: increasing the absolute time by a monitoring window number, and increasing the relative time by the number of memory access instructions generated within the current monitoring window.
6. The active page-switching method based on regional reuse pattern recognition according to claim 5, characterized in that, In S3, the memory area R after the recognition state switch i Does it have a stable reuse pattern, including: If the memory region R after the state switch i If the relative difference between the number of memory access instructions executed by the application process during its cold state and the number of memory access instructions executed by the application process during its previous cold state does not exceed a preset stability threshold ε, then the memory region R after the state switch is considered to be... i It has a stable reuse pattern; otherwise, the memory region R after the state switch is considered to be... i There is no stable reuse pattern.
7. The active page-switching method based on regional reuse pattern recognition according to claim 1, characterized in that, In S1, memory access instructions of the application process are sampled based on hardware performance events within the current monitoring window; wherein, the hardware performance events are triggered by a counting threshold of memory access instructions, and sampling is triggered when the counting threshold is exceeded. The memory access sample includes a process identifier and a virtual address; the memory access sample is stored in a circular buffer corresponding to the operating system kernel address space according to the process identifier; Clustering the memory access samples based on address proximity includes: At the end of the current monitoring window, collect all memory access samples in the circular buffer and sort them in ascending order according to the size of the virtual address of the memory access sample; cluster them according to the distance between the virtual addresses of adjacent memory access samples, and memory access samples whose virtual address distance is less than the specified address distance threshold D are assigned to the same cluster. In S2, initially, the starting addresses and sizes of the N memory regions are determined by the application's memory allocation behavior. The starting addresses of the N memory regions are arranged in ascending order, and the N memory regions constitute the application's virtual address space.
8. An active page-changing system based on regional reuse pattern recognition, characterized in that, include: The sampling and clustering module is used to sample the memory access instructions of the application process within the current monitoring window to obtain memory access samples; The memory access samples are clustered based on address proximity, and several virtual address intervals defined by the minimum and maximum virtual addresses of the memory access samples in each cluster are used as the working set within the current monitoring window. The memory region management module is used to manage memory regions based on the i-th memory region R. i Update memory region R based on the overlap ratio with the virtual address range in the working set. i So that memory region R i Aligned with the boundaries of the virtual address ranges in the work set, i=1,2,…,N; initially, the N memory regions are N non-overlapping memory regions of the application's virtual address space after pre-division; The pattern recognition module is reused for updating the memory region R. i It switches between hot and cold states and identifies the memory region R after the state switch. i Does it have a stable reuse pattern? If the memory region R after the state switch... i If the system is in a cold state and has a stable reuse mode, then the process jumps to the active switching strategy execution module. Otherwise, set i = i + 1 and jump to the memory region management module; The proactive swapping strategy execution module is used to predict memory region R. i The next reuse time; in memory region R i Duration of cold state T C More than α·T R At that time, all memory pages within it are swapped out to the swap space, and its state is switched to an unresident state. T R For memory region R i The reuse interval is such that the difference between α and 0 is less than a preset threshold; and before the predicted next reuse time, memory pages in the swap space are swapped into memory region R. i In the middle, and switch its state to cold state; Set i = i + 1 and jump to the memory region management module. When i = N, set the next monitoring window as the current monitoring window and return to the sampling clustering module until the application ends.
9. An active page-switching device based on regional reuse pattern recognition, characterized in that, Includes computer-readable storage media and processors; The computer-readable storage medium is used to store executable instructions; The processor is configured to read executable instructions stored in the computer-readable storage medium and execute the active paging method based on regional reuse pattern recognition as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the active paging method based on regional reuse pattern recognition as described in any one of claims 1-7.