A code segment huge page allocation processing method and system

CN122173306APending Publication Date: 2026-06-09联通云数据有限公司 +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-13
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing code segment big page technology causes memory copying to block processor access when merging discrete physical pages to generate big pages, and leads to performance loss in cross-node memory access. At the same time, unused free memory cannot be flexibly allocated, resulting in big page memory fragmentation and low utilization.

Method used

When a page fault occurs in the code segment, pre-allocate contiguous physical memory to generate a preparatory large page, and establish a virtual address range through page table entries. Add the large page to the check queue to track free memory ranges. Preparatory large pages that exceed the threshold are added to the reuse waiting queue. When a subsequent page fault occurs, match and map the free memory range to realize the reuse and conversion of large pages.

Benefits of technology

It reduces fragmentation within large pages, decreases the invalidation of contiguous physical memory, alleviates system memory fragmentation, and improves the overall utilization of large page memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122173306A_ABST
    Figure CN122173306A_ABST
Patent Text Reader

Abstract

The application provides a code segment large page allocation processing method and system, the method comprises the following steps: in response to a page directory level page fault exception of a code segment, obtaining a virtual address interval corresponding to the page fault exception, pre-allocating a continuous physical memory block according to the virtual address interval, and establishing a corresponding page table item mapping to generate a preliminary large page; adding a mark to a virtual memory area corresponding to the preliminary large page and adding the virtual memory area to a preset check queue, tracking a free memory interval in the preliminary large page, and adding the preliminary large page with a free memory interval size exceeding a preset threshold to a reuse waiting queue; when a subsequent code segment triggers a page fault exception, matching a preliminary large page meeting a condition from the reuse waiting queue, and establishing a mapping between a free memory interval of the matched preliminary large page and a virtual address interval of the subsequent code segment. The application reduces memory fragmentation through large page allocation and reuse, thereby realizing copy-free large page conversion through a preliminary code segment large page to reduce memory access delay.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of code memory management technology, and in particular to a method and system for handling large page allocation of code segments. Background Technology

[0002] The code segment big page technique reduces address translation overhead and improves processor execution performance by increasing the granularity of memory mapping. Existing code segment big page techniques merge discrete physical pages to generate big pages at runtime. This merging process requires holding page table locks to perform memory copying, which can block processor memory access and easily lead to performance degradation when accessing memory across non-uniform memory access nodes. The pre-code segment big page scheme solves the lock blocking and cross-node access problems of big page merging by pre-allocating contiguous physical memory when a page fault occurs. However, after allocating smaller pages within the pre-code segment big page, unused free memory cannot be flexibly allocated due to the contiguous physical attribute of the big page, resulting in fragmentation within the big page. This leads to invalid use of contiguous physical memory, reduces the overall utilization of big page memory, and exacerbates system memory fragmentation. Summary of the Invention

[0003] This invention provides a method and system for processing code segment big page allocation. By allocating and reusing big pages, memory fragmentation is reduced, thereby achieving copyless big page conversion through the preparation of code segment big pages to reduce memory access latency.

[0004] To address at least one of the problems in the prior art, the present invention discloses a method for handling large page allocation of code segments, comprising: In response to a page fault at the middle directory level in the code segment, obtain the virtual address range corresponding to the page fault, pre-allocate contiguous physical memory blocks according to the virtual address range, and establish a corresponding page table entry mapping to generate a preparatory big page. Mark the virtual memory region corresponding to the preparatory large page and add it to the preset check queue. Track the free memory range within the preparatory large page and add the preparatory large page whose free memory range exceeds the preset threshold to the reuse waiting queue. When a page fault is triggered in a subsequent code segment, a matching pre-page is selected from the reuse wait queue, and a mapping is established between the free memory range of the matching pre-page and the virtual address range of the subsequent code segment.

[0005] Optionally, pre-allocating contiguous physical memory blocks based on the virtual address range and establishing corresponding page table entries to generate preparatory big pages includes: Determine the aligned virtual address range that matches the page intermediate directory mapping granularity based on the virtual address range; Allocate contiguous physical memory blocks based on aligned virtual address ranges; Create contiguous page table entries based on the aligned virtual address range and contiguous physical memory blocks, establish a mapping relationship between each page table entry and the corresponding page in the physical memory block, and generate a preparatory big page.

[0006] Optionally, creating contiguous page table entries based on the aligned virtual address range and contiguous physical memory blocks, and establishing the mapping relationship between each page table entry and the corresponding page in the physical memory block includes: The aligned virtual address range is split to obtain a continuous virtual page address; The contiguous physical memory blocks are split to obtain contiguous physical page addresses, and each physical page address corresponds to a unique physical page frame number; Create a corresponding page table entry for each virtual paging address, and establish a mapping relationship between each page table entry and the physical page frame number of the corresponding physical paging address.

[0007] Optionally, tracking free memory ranges within the prepared large pages and adding prepared large pages whose free memory range exceeds a preset threshold to the reuse waiting queue includes: Update the allocated and free memory regions within the prepared large page at the pagination level; Calculate the total free memory size and the maximum contiguous free memory size within the free memory interval of the prepared large page; When the total free memory size exceeds a preset threshold, the prepared large pages are added to the reuse waiting queue.

[0008] Optionally, updating the allocated and free memory regions within the prepared large page at the paging granularity includes: After completing the paging allocation within the preparatory large page, insert the corresponding allocated memory interval into the interval tree, and update the total number of free pages and the maximum number of consecutive free pages. After the paging is released within the preparatory large page, the corresponding interval is marked as free in the interval tree, adjacent free memory intervals are merged, and the total number of free pages and the maximum number of consecutive free pages are updated.

[0009] Optionally, matching eligible preparatory large pages from the multiplexing wait queue includes: Obtain the non-uniform memory access node number and data type corresponding to the page fault exception in the subsequent code segment; Filter the preparatory large pages in the reuse waiting queue that match the non-uniform memory access node number and data type; Among the filtered reserve large pages, select the reserve large page whose maximum contiguous free memory size meets the allocation requirements.

[0010] Optionally, establishing a mapping between the free memory region of the matching preparatory big page and the virtual address region of the subsequent code segment includes: Allocate an aligned virtual memory region in the virtual address space of the current process; Map the physical page frame number corresponding to the largest contiguous free memory range of the matched pre-page to the virtual address range of the virtual memory region; Update the interval tree of the prepared large page, marking the mapped memory interval as allocated.

[0011] Optionally, this also includes updating the range tree of the prepared large pages, marking the mapped memory range as allocated: Calculate the remaining free memory size for preparing large pages; When the remaining free memory exceeds a preset threshold, the prepared large page will be added back to the reuse wait queue. When the remaining free memory size does not exceed the preset threshold, the prepared large page is removed from the reuse waiting queue.

[0012] Optionally, this also includes marking the virtual memory region corresponding to the prepared large page and adding it to a preset check queue: Virtual memory regions are retrieved from the inspection queue according to a preset scheduling cycle; Perform multi-dimensional compliance checks on the corresponding preparatory main pages; When the prepared large page passes the multi-dimensional compliance check, the page table entry corresponding to the prepared large page is released, and a large page mapping matching the contiguous physical memory block is established in the corresponding page intermediate directory table entry.

[0013] Another aspect of the present invention discloses a code segment big page allocation processing system, comprising: The exception capture module is used to respond to page faults at the middle directory level of the code segment, obtain the virtual address range corresponding to the page fault, pre-allocate contiguous physical memory blocks according to the virtual address range, and establish corresponding page table entry mappings to generate preparatory big pages. The preparatory large page generation module is used to mark the virtual memory region corresponding to the preparatory large page and add it to a preset check queue, track the free memory range within the preparatory large page, and add preparatory large pages whose free memory range size exceeds a preset threshold to a reuse waiting queue. The mapping and reuse module is used to match a qualified preparatory large page from the reuse waiting queue when a page fault is triggered by a subsequent code segment, and to establish a mapping between the free memory range of the matched preparatory large page and the virtual address range of the subsequent code segment.

[0014] As can be seen from the above technical solution, this invention pre-allocates contiguous physical memory to generate a preparatory large page when a page fault is triggered in the code segment. The virtual memory region of the preparatory large page is marked and added to a check queue. Simultaneously, the allocated and free memory regions within the preparatory large page are tracked at the paging level. Preparatory large pages with free memory exceeding a preset threshold are added to a reuse waiting queue. When a subsequent page fault is triggered in the code segment, a matching preparatory large page is first selected from the reuse waiting queue. After establishing a mapping between the free memory region and the new virtual address region, small page allocation is performed. At the same time, compliance verification is performed on the preparatory large pages in the check queue. Once the verification passes, the large page is converted to a regular page. This achieves secondary reuse of the free memory in the preparatory large page, reduces fragmentation within the large page, reduces the invalid occupation of contiguous physical memory, alleviates system memory fragmentation, and improves the overall utilization rate of large page memory. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of the present invention 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 the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 This is a schematic diagram of the code segment memory allocation processing method in the prior art; Figure 2 This is a flowchart illustrating a code segment large page allocation processing method according to an embodiment of the present invention; Figure 3 This is a schematic diagram illustrating the addition of markers to the virtual memory region in a code segment large page allocation processing method according to an embodiment of the present invention; Figure 4 This is a flowchart illustrating a code segment large page allocation processing method S100 in an embodiment of the present invention; Figure 5 This is a flowchart illustrating a code segment large page allocation processing method S130 in an embodiment of the present invention; Figure 6 This is a flowchart illustrating a code segment large page allocation processing method S200 in an embodiment of the present invention; Figure 7 This is a schematic diagram illustrating the method for preparing large pages for addition to a reuse waiting queue in a code segment large page allocation processing method according to an embodiment of the present invention; Figure 8 This is a flowchart illustrating a code segment large page allocation processing method S210 in an embodiment of the present invention; Figure 9 This is a flowchart illustrating the process of multiplexing the waiting queue matching in a code segment large page allocation processing method S300 according to an embodiment of the present invention. Figure 10 This is a flowchart illustrating the mapping between free memory regions and virtual address regions in a code segment large page allocation processing method S300 according to an embodiment of the present invention. Figure 11 This is a flowchart illustrating a code segment large page allocation processing method S400 in an embodiment of the present invention; Figure 12 This is a flowchart illustrating a code segment large page allocation processing method S500 in an embodiment of the present invention; Figure 13 This is a schematic diagram of the structure of a code segment large page allocation processing system according to an embodiment of the present invention. Detailed Implementation

[0017] In the following description, specific details such as particular system structures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of the present invention. However, those skilled in the art will understand that the invention can be implemented in other embodiments without these 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 the invention with unnecessary detail.

[0018] In this application embodiment, the implementation process of the prior art will be described first by way of example. Figure 1 As shown, taking a 2MB granularity bigpage as an example, the processor's address translation unit uses a 4KB paging granularity, and a 2MB bigpage corresponds to 512 consecutive 4KB pages. Existing code segment bigpage technology, when a page fault occurs in a code segment, first allocates 512 discrete 4KB physical pages to the code segment, establishes page table entries, and a background thread periodically scans the virtual memory region, filters eligible code segments, requests 2MB of contiguous physical memory, holds a page table lock, copies the contents of the 512 discrete 4KB pages to the newly allocated contiguous physical memory, modifies the page intermediate directory table entries to establish a bigpage mapping, and releases the original discrete physical pages. During this process, memory copying blocks the processor's memory access, and the merged bigpage is fixed to a single non-uniform memory access node, easily triggering cross-node memory access. Furthermore, the pre-allocated contiguous physical memory pre-bigpage scheme generates unusable free memory after small page allocation, resulting in a waste of contiguous physical memory.

[0019] To address at least one of the aforementioned prior art issues, this invention discloses a method for handling large page allocation in code segments. For example... Figure 2 As shown, in this embodiment, the method includes: S100: In response to a page fault at the intermediate directory level in the code segment, obtain the virtual address range corresponding to the page fault, pre-allocate contiguous physical memory blocks according to the virtual address range, and establish a corresponding page table entry mapping to generate a preparatory big page.

[0020] S200: Mark the virtual memory region corresponding to the preparatory large page and add it to the preset check queue, track the free memory range within the preparatory large page, and add preparatory large pages whose free memory range size exceeds the preset threshold to the reuse waiting queue.

[0021] S300: When a page fault is triggered in a subsequent code segment, a matching preparatory large page is matched from the reuse wait queue, and a mapping is established between the free memory range of the matching preparatory large page and the virtual address range of the subsequent code segment.

[0022] This invention pre-allocates contiguous physical memory to generate a preparatory large page when a page fault occurs in the code segment. The virtual memory region of the preparatory large page is marked and added to a check queue. Simultaneously, allocated and free memory regions within the preparatory large page are tracked at the paging level. Preparatory large pages with free memory exceeding a preset threshold are added to a reuse waiting queue. When a subsequent page fault occurs in the code segment, a matching preparatory large page is first selected from the reuse waiting queue. After establishing a mapping between the free memory region and the new virtual address region, small page allocation is performed. At the same time, compliance checks are performed on the preparatory large pages in the check queue. Once the check passes, the large page is converted to a regular page. This achieves secondary reuse of the free memory in the preparatory large page, reduces fragmentation within the large page, reduces the invalid occupation of contiguous physical memory, alleviates system memory fragmentation, and improves the overall utilization of large page memory.

[0023] A page fault at the intermediate page directory level in a code segment occurs when a processor or other hardware device, while executing instructions in a code segment, encounters a page fault triggered by the absence of a valid mapping in the intermediate page directory entry corresponding to the virtual address accessed. The intermediate page directory is an intermediate level in the multi-level page table structure of the processor's memory management unit, corresponding to a memory mapping range of 2MB granularity. This embodiment uses a four-level page table structure as an example. The four-level page table structure includes a page global directory, a page fourth-level directory, a page parent directory, an intermediate page directory, and page table entries. The intermediate page directory entry can directly point to a contiguous physical memory block of 2MB, achieving large page mapping, or it can point to the base address of a page table entry, achieving small page mapping with a 4KB granularity through the page table entry.

[0024] It should be noted that the virtual address range corresponding to a page fault refers to the continuous virtual address range that matches the granularity of the page's intermediate directory mapping, where the virtual address that triggered the page fault is located. Taking a 2MB big page as an example, this virtual address range is a continuous virtual address range aligned to 2MB, and the ending address is the starting address plus 2MB.

[0025] Specifically, pre-allocating contiguous physical memory blocks based on virtual address ranges means that during the page fault handling process, a contiguous physical memory block matching the granularity of the page intermediate directory mapping is directly allocated, rather than allocating multiple discrete 4KB physical pages. Taking a 2MB big page as an example, this contiguous physical memory block is a contiguous 2MB of physical memory, corresponding to 512 contiguous 4KB physical pages. Each physical page corresponds to a unique physical page frame number, and the physical page frame numbers are a continuously increasing numerical sequence.

[0026] For example, establishing a corresponding page table entry mapping to generate a pre-built big page refers to creating consecutive page table entries for a pre-allocated contiguous block of physical memory. Each page table entry corresponds to a 4KB physical page within the contiguous physical memory block, establishing a mapping from virtual address to physical address. At this point, the translation from virtual address to physical address is still done through page table entries, and big page mapping at the intermediate page directory level is not enabled. Therefore, no address translation optimization effect of big pages is achieved. However, the pre-allocated contiguous physical memory block is locked, satisfying real-time memory usage requirements through small physical pages while also providing the physical memory foundation for subsequent big page mapping.

[0027] It should be noted that a preparatory big page refers to a memory page that has been pre-allocated as a contiguous block of physical memory, mapped through page table entries, but without an intermediate directory-level big page mapping. Only after the big page mapping is established can the contiguous physical memory blocks of the preparatory big page be formally merged into a big page, completing the conversion from a preparatory big page to a formal big page.

[0028] Specifically, a flag is added to the virtual memory region corresponding to the pre-defined big page, and it is then added to a pre-defined check queue. Virtual memory regions are structures in the kernel used to manage the virtual address space of a process. Each virtual memory region corresponds to a contiguous range of virtual addresses, containing information such as memory attributes, mapping relationships, and permission configurations for that address range. Adding a flag to a virtual memory region means adding a unique identifier to the flag field of the virtual memory region to distinguish it from ordinary virtual memory regions and the virtual memory region corresponding to the pre-defined big page. The kernel can quickly identify the virtual memory region corresponding to the pre-defined big page that needs to be processed through this identifier. For example, ... Figure 3 As shown, after marking the virtual memory regions, they are added to the queue. That is, virtual memory region 0, virtual memory region 1, virtual memory region 2 and virtual memory region 3 are put into the preparatory big page queue in turn. Each virtual memory region is marked with virtual memory region mark 0, virtual memory region mark 1, virtual memory region mark 2 and virtual memory region mark 3 respectively.

[0029] The preset check queue can be a linked list structure pre-initialized in the kernel to store the corresponding virtual memory regions for preparing large pages. The virtual memory regions added to the check queue will be scanned by the kernel's periodic processing thread to perform subsequent compliance verification operations.

[0030] For example, tracking the allocated and free memory regions within a preparatory large page means recording, with 4KB pages as the smallest granularity, which pages in the contiguous physical memory block corresponding to the preparatory large page have been allocated to processes and which pages are in a free and unused state, while also recording information such as the start address, end address, and usage status of each allocated and free memory region.

[0031] In this embodiment, a range tree structure is used to store information about allocated and free memory ranges. A range tree is an ordered data structure based on a red-black tree for storing range data, which can quickly perform range lookup, insertion, deletion, and merging operations, ensuring efficient memory range tracking. Of course, in other feasible implementations, linked lists and graphs can also be used instead of range trees. Those skilled in the art can choose a feasible storage structure according to the actual application scenario, and this application does not limit this choice.

[0032] Specifically, large pages with free memory exceeding a preset threshold are added to a reuse waiting queue. The preset threshold is a pre-configured free memory threshold used to determine whether a large page can enter the reuse waiting queue. In this embodiment, the preset threshold can be configured to 8KB, corresponding to two consecutive 4KB pages, or it can be configured to other values ​​according to actual memory usage requirements. Of course, in other embodiments, a memory size such as 16KB can also be selected as the preset threshold. Those skilled in the art can set it according to actual needs, and this application does not limit this.

[0033] The free memory size refers to the total size of all free pages within the contiguous physical memory block corresponding to the planned large page. When this total size exceeds a preset threshold, it indicates that there is reusable free memory within the planned large page, and it can be added to the reuse waiting queue. The reuse waiting queue is a pre-initialized linked list structure in the kernel used to store planned large pages with reusable free memory. It can also be accompanied by an ordered tree structure sorted by free memory size for quickly matching planned large pages that meet allocation requirements.

[0034] For example, in a subsequent code segment—that is, a new code segment before a page fault is triggered—when a page fault occurs, a suitable pre-emptive page is first matched from the reuse wait queue. A suitable pre-emptive page can be one that matches the allocation requirements of the new page fault. Matching conditions include matching non-uniform memory access nodes, data types, and free memory sizes, ensuring that the matched pre-emptive page can meet the allocation requirements of the new page fault without incurring additional performance overhead.

[0035] Specifically, after establishing the mapping between the free memory range of the matching preparatory large page and the new virtual address range of the subsequent code segment, the small page allocation operation is performed. The new virtual address range refers to the virtual address range corresponding to the code segment of the new page fault. The contiguous physical memory range in the preparatory large page that is in a free state is mapped to the new virtual address range, and a page table mapping from virtual address to physical address is established.

[0036] Once the mapping is established, page allocation operations can be performed on the physical memory corresponding to the new virtual address range to allocate the corresponding physical page for the new page fault, thus completing the page fault handling. It should be noted that this mapping process only modifies the page table mapping relationship from virtual address to physical address; it does not move or copy data in physical memory and has no impact on the memory range already allocated in the original prepared big page, ensuring the stability of access to the original memory range.

[0037] In alternative implementations, such as Figure 4 As shown, S100 pre-allocates contiguous physical memory blocks based on the virtual address range and establishes corresponding page table entries to generate preparatory big pages, including: S110: Determine the aligned virtual address range that matches the page intermediate directory mapping granularity based on the virtual address range.

[0038] S120: Allocate contiguous physical memory blocks based on aligned virtual address ranges.

[0039] S130: Create contiguous page table entries based on the aligned virtual address range and contiguous physical memory blocks, establish the mapping relationship between each page table entry and the corresponding page in the physical memory block, and generate a preparatory big page.

[0040] In this embodiment, an aligned virtual address range matching the page intermediate directory mapping granularity is determined based on the virtual address range. The page intermediate directory mapping granularity refers to the memory size that a single page intermediate directory entry can map; in this embodiment, it is 2MB. The corresponding alignment requirement is that the lower 21 bits of the virtual address are 0, i.e., 2MB alignment. The virtual address range is the address range where the virtual address that triggered the page fault is located. When determining the aligned virtual address range, the lower 21 bits of the virtual address that triggered the page fault are first cleared to obtain the aligned starting virtual address. Then, 2MB is added to the starting virtual address to obtain the aligned ending virtual address. The continuous range between the starting virtual address and the ending virtual address is the aligned virtual address range matching the page intermediate directory mapping granularity.

[0041] For example, a physical memory block of contiguous size matching the aligned virtual address range is allocated from the kernel's physical memory management system. Taking a 2MB aligned virtual address range as an example, the allocated contiguous physical memory block is 2MB in size, corresponding to 512 consecutive 4KB physical pages. The physical page frame number corresponding to each physical page is a continuously increasing value without any gaps.

[0042] It should be noted that the allocation process of contiguous physical memory blocks is performed in the context of page fault handling. During allocation, priority is given to allocating from the local memory of the non-uniform memory access node to which the processor that triggered the page fault belongs, ensuring that subsequent memory accesses are local node accesses and will not cause performance loss due to cross-node accesses.

[0043] Specifically, based on the aligned virtual address range and contiguous physical memory blocks, contiguous page table entries are created, establishing a mapping relationship between each page table entry and the corresponding page in the physical memory block, thus generating a preparatory big page. A contiguous page table entry refers to a contiguous array of page table entries corresponding to the aligned virtual address range. Each page table entry corresponds to a 4KB virtual page within the aligned virtual address range and simultaneously to a 4KB physical page within the contiguous physical memory block. When creating page table entries, first, the corresponding page table memory space is allocated for the aligned virtual address range. Then, a corresponding page table entry is created for each virtual page, and the physical page frame number and memory permission configuration of the corresponding physical page are filled into the page table entry, establishing a one-to-one mapping from virtual address to physical address. After all page table entry mapping configurations are completed, the corresponding preparatory big page is generated. At this point, the translation from virtual address to physical address is completed through page table entries. Big page mapping at the intermediate directory level is not enabled, and the physical memory block is a contiguous 2MB of memory, providing a foundation for subsequent big page mapping and free memory reuse.

[0044] In alternative implementations, such as Figure 5As shown, S130 creates contiguous page table entries based on the aligned virtual address range and contiguous physical memory blocks, establishing the mapping relationship between each page table entry and the corresponding page in the physical memory block, including: S131: Split the aligned virtual address range to obtain a continuous virtual page address.

[0045] S132: Obtain consecutive physical page addresses by splitting consecutive physical memory blocks, with each physical page address corresponding to a unique physical page frame number.

[0046] S133: Create a corresponding page table entry for each virtual paging address, and establish a mapping relationship between each page table entry and the physical page frame number of the corresponding physical paging address.

[0047] In this embodiment, consecutive virtual paging addresses are obtained by splitting the aligned virtual address range. The aligned virtual address range is a 2MB aligned consecutive virtual address range, and with a paging granularity of 4KB, it can be split into 512 consecutive virtual paging addresses. During splitting, the starting address of the aligned virtual address range is taken as the starting address of the first virtual paging address. The size of each virtual paging address is 4KB. The starting address of the next virtual paging address is the starting address of the previous virtual paging address plus 4KB. This process is repeated to obtain 512 consecutive virtual paging addresses, with each virtual paging address corresponding to a 4KB virtual page within the aligned virtual address range.

[0048] For example, contiguous physical memory blocks are split to obtain contiguous physical page addresses, each corresponding to a unique physical page frame number. A contiguous physical memory block of 2MB in size, with a paging granularity of 4KB, can be split into 512 contiguous physical page addresses. During splitting, the starting physical address of the contiguous physical memory block is used as the starting address of the first physical page address. Each physical page address is 4KB in size. The starting address of the next physical page address is the starting address of the previous physical page address plus 4KB, and so on, resulting in 512 contiguous physical page addresses. Each physical page address corresponds to a unique physical page frame number, which is the high-order part of the physical address. Taking 4KB paging as an example, the physical page frame number is the value obtained by right-shifting the physical address by 12 bits. The physical page frame numbers corresponding to consecutive physical page addresses are a continuously increasing sequence of values.

[0049] Specifically, a corresponding page table entry is created for each virtual paging address. Each page table entry is then mapped one-to-one with the physical page frame number of its corresponding physical paging address. After configuring the mapping for all page table entries, a preparatory big page is generated. When creating page table entries, one entry is allocated sequentially for each virtual paging address, following the order of the virtual paging addresses. Each page table entry contains a physical page frame number field, a memory permission field, and a status field. The physical page frame number of the corresponding physical paging address is filled into the physical page frame number field of the page table entry. Simultaneously, the memory permissions of the page table entry are configured to be readable and executable, consistent with the memory attributes of the code segment. The valid bit of the page table entry is then configured to be valid, completing the mapping configuration for a single page table entry. After configuring the mapping for 512 page table entries, a stable mapping relationship is established between all virtual paging addresses and their corresponding physical paging addresses, thus completing the generation of the preparatory big page. It should be noted that after all page table entries are mapped and configured, the processor can access any virtual address within the aligned virtual address range by translating the virtual address to a physical address through the corresponding page table entry, thus accessing the corresponding physical memory without triggering a page fault again, ensuring the stability of code execution.

[0050] In alternative implementations, such as Figure 6 As shown, S200 tracks the free memory range within the prepared large page and adds prepared large pages whose free memory range exceeds a preset threshold to the reuse waiting queue, including: S210: Update the allocated and free memory regions within the prepared large page at the paging level; S220: Calculate the total free memory size and the maximum contiguous free memory size within the free memory interval of the prepared large page; S230: When the total free memory size exceeds the preset threshold, the prepared large page is added to the reuse waiting queue.

[0051] In this embodiment, the allocated memory range and free memory range within the preparatory large page are updated at the paging level. The smallest memory management granularity is 4KB. All memory allocation and deallocation operations are performed on a paging basis; therefore, the updates to the allocated memory range and free memory range are also performed at the paging level. An allocated memory range refers to the contiguous address range within the contiguous physical memory block corresponding to the preparatory large page, consisting of pages that have been allocated to the process. A free memory range refers to the contiguous address range consisting of unallocated pages that are in a free and available state.

[0052] Update operations include updates during allocation and updates during release. During allocation, the corresponding page is marked as allocated, the corresponding free memory range is split, and a new allocated memory range is inserted. During release, the corresponding page is marked as free, the corresponding allocated memory range is marked as free, and adjacent free memory ranges are merged.

[0053] For example, the total free memory size and the maximum contiguous free memory size within the prepared large page are calculated. The total free memory size refers to the total size of all free pages within the prepared large page. This is calculated by counting the lengths of all free memory intervals, summing their lengths to obtain the total number of free pages, and then multiplying this total number of free pages by the size of a single page (4KB) to obtain the total free memory size. The maximum contiguous free memory size refers to the size of the longest single contiguous free memory interval among all free memory intervals within the prepared large page. This is calculated by traversing all free memory intervals, comparing the length of each interval, selecting the longest free memory interval, and multiplying its length by the size of a single page (4KB) to obtain the maximum contiguous free memory size. It should be noted that the maximum contiguous free memory size determines whether the prepared large page can satisfy the maximum contiguous memory allocation requirement, and is used to match new allocation requests.

[0054] Specifically, when the total free memory size exceeds a preset threshold, a pre-configured large page is added to the reuse waiting queue. The preset threshold is a pre-configured critical value; in this embodiment, it is 8KB, corresponding to two 4KB pages. When the total free memory size is greater than 8KB, it indicates that there is reusable free memory within the pre-configured large page, and it can be added to the reuse waiting queue. When adding to the reuse waiting queue, it is first checked whether the pre-configured large page already exists in the queue. If it already exists, it is not added again; if it does not exist, the structure node corresponding to the pre-configured large page is added to the linked list of the reuse waiting queue, and the relevant information of the pre-configured large page is inserted into an ordered tree structure sorted by the largest contiguous free memory size for easy subsequent matching. It should be noted that the original mapping relationship and memory usage status of a pre-configured large page added to the reuse waiting queue remain unchanged; the allocated memory range can still be accessed normally and will not affect the execution of the process code. For example, as... Figure 7 As shown, for the three preparatory large pages 0, 1, and 2, there are free memory intervals 0, 1, and 2, respectively. The total free memory size of free memory intervals 0 and 2 exceeds a preset threshold, so preparatory large pages 0 and 2 are added to the reuse waiting queue. The total free memory size of free memory interval 1 does not exceed the preset threshold, so it is not added to the reuse waiting queue.

[0055] It should be noted that, when a page fault occurs at the directory level in the middle of each current code segment page, this invention first matches a qualified reserve large page from the reuse waiting queue based on conditions such as the total memory size required. It then determines whether multiple contiguous free physical memory blocks within the existing reserve large page can be used. If a match is successful, the current code segment is mapped to the free memory range of the matched reserve large page, making the free memory of the reserve large page available for the current code segment. If no match is successful, a new reserve large page composed of contiguous physical memory blocks is generated for the current code segment. Therefore, this application forcibly allocates a large address range of reserve large pages each time a page fault occurs. Within the range of the reserve large page, the contiguous physical memory blocks within the reserve large page are used by one or more code segments. This not only ensures that code segments can be allocated physical memory blocks at the physical page level in real time, guaranteeing code stability, but also allows for the pre-setting of contiguous physical memory blocks for code segments to facilitate the subsequent preparation work from the reserve large page to the formal large page, avoiding the problem of blocking processor memory access and causing cross-node memory access during the transition to the formal large page. Furthermore, pre-allocating and planning based on the pre-sized large pages can avoid the problem of high fragmentation caused by allocating scattered small physical memory blocks to code segments, thereby improving the success rate of pre-sized large page allocation and improving memory utilization.

[0056] In alternative implementations, such as Figure 8 As shown, S210 updates the allocated memory range and free memory range within the prepared large page at the paging granularity, including: S211: After completing the paging allocation within the preparatory large page, insert the corresponding allocated memory interval into the interval tree, and update the total number of free pages and the maximum number of consecutive free pages. S212: After completing the paging release within the preparatory large page, mark the corresponding interval as free in the interval tree, merge adjacent free memory intervals, and update the total number of free pages and the maximum number of consecutive free pages.

[0057] In this embodiment, after paging allocation is completed within the pre-allocated large page, the corresponding allocated memory interval is inserted into the interval tree, and the total number of free pages and the maximum number of consecutive free pages are updated. The paging allocation operation within the pre-allocated large page refers to allocating 4KB physical pages within the pre-allocated large page to the process's code segment, establishing a mapping from virtual address to physical address. This operation includes paging allocation within the virtual address interval corresponding to the original pre-allocated large page, as well as paging allocation within the new virtual address interval when reusing free memory. After paging allocation is completed, the starting and ending physical page frame numbers corresponding to the allocated pages are first obtained, the starting and ending addresses of the corresponding allocated memory interval are determined, and then a free memory interval overlapping with the allocated memory interval is searched in the interval tree.

[0058] For example, after finding overlapping free memory intervals, these intervals are removed from the interval tree. If the starting address of the free memory interval is less than the starting address of the allocated memory interval, the first half of the free memory interval is split off and re-inserted into the interval tree. If the ending address of the free memory interval is greater than the ending address of the allocated memory interval, the second half of the free memory interval is split off and re-inserted into the interval tree. After splitting, the new allocated memory interval is inserted into the interval tree, completing the interval tree update. After the update, the total number of free pages is recalculated. The total number of free pages equals the original total number of free pages minus the number of pages allocated this time. Simultaneously, all free memory intervals in the interval tree are traversed, and the maximum number of consecutive free pages is recalculated, completing the update of relevant parameters.

[0059] Specifically, after paging is released within the preparatory large page, the corresponding interval is marked as free in the interval tree, adjacent free memory intervals are merged, and the total number of free pages and the maximum number of consecutive free pages are updated. The paging release operation within the preparatory large page refers to the process releasing the allocated 4KB physical pages, unmapping the virtual address to physical address, and reclaiming the corresponding physical pages. After paging release, the starting and ending physical page frame numbers corresponding to the released pages are first obtained to determine the start and end addresses of the corresponding interval to be released. Then, the corresponding allocated memory interval is searched in the interval tree, removed from the interval tree, and marked as a free memory interval.

[0060] For example, after marking a free memory interval, the preceding and subsequent free memory intervals adjacent to it are searched in the interval tree. If adjacent free memory intervals exist, they are merged with the current free memory interval into a single contiguous free memory interval. The adjacent free memory intervals before merging are removed from the interval tree, and the merged contiguous free memory interval is then inserted into the interval tree. After merging, the total number of free pages is recalculated. The total number of free pages equals the original total number of free pages plus the number of pages released this time. Simultaneously, all free memory intervals in the interval tree are traversed, and the maximum number of contiguous free pages is recalculated, completing the update of relevant parameters. It should be noted that all update operations of the interval tree are protected by spinlocks to ensure that data races and data inconsistencies do not occur when multiple processors operate on the interval tree simultaneously, thus guaranteeing the accuracy of memory interval tracking.

[0061] In alternative implementations, such as Figure 9 As shown, S300 matches eligible preparatory large pages from the multiplexing wait queue, including: S310: Obtain the non-uniform memory access node number and data type corresponding to the page fault in the subsequent code segment; S320: Filter the preparatory large pages in the multiplexing wait queue that match the non-uniform memory access node number and data type; S330: Select the largest contiguous free memory page from the filtered preparatory large pages that meets the allocation requirements.

[0062] In this embodiment, the non-uniform memory access node number and data type corresponding to the subsequent page fault are obtained. The non-uniform memory access architecture divides the system's physical memory into multiple nodes, each node corresponding to a set of processors and local physical memory. The latency of a processor accessing the memory of its local node is much lower than the latency of accessing the memory of a remote node. The non-uniform memory access node number refers to the number of the memory node to which the processor that triggered the new page fault belongs. Obtaining this number ensures that the matched preparatory big page is located on the local node of that processor, avoiding the performance loss of cross-node memory access.

[0063] Data type refers to the type of memory region corresponding to the page fault. In this application embodiment, it includes anonymous pages, file mapping pages, code segment pages, etc. The memory attributes, access modes, and permission configurations of memory regions with different data types are different. Matching a preparatory large page of the same data type can ensure that the memory access permissions and attributes meet the usage requirements of the code segment.

[0064] For example, in the reuse wait queue, prepared large pages that match the non-uniform memory access node number and data type are filtered. During filtering, all prepared large pages in the reuse wait queue are first traversed. First, it is checked whether the non-uniform memory access node number to which the prepared large page belongs matches the node number corresponding to the new page fault, filtering out prepared large pages with matching node numbers. Then, among the prepared large pages with matching node numbers, it is checked whether the data type corresponding to the prepared large page matches the data type corresponding to the new page fault, filtering out prepared large pages with matching data types. It should be noted that the filtering process can prioritize matching non-uniform memory access node numbers, and then ensure matching data types, to ensure that the matched prepared large pages do not cause performance overhead from cross-node memory access.

[0065] Specifically, among the filtered candidate large pages, those with the largest contiguous free memory size that meets the allocation requirements are selected. The allocation requirements refer to the minimum contiguous memory allocation size corresponding to the new page fault. In this embodiment, the minimum allocation size is 4KB, corresponding to one page, but it can be configured to other values ​​according to actual needs. Meeting the allocation requirements with the largest contiguous free memory size means that the largest contiguous free memory size of the candidate large page is greater than or equal to the minimum allocation requirement, ensuring that the free memory of the candidate large page can meet the new allocation requirements. During selection, the candidate large page with the largest contiguous free memory size closest to the allocation requirements is prioritized. This selection method reduces the fragmentation of remaining free memory within the large page and improves the probability of subsequent reuse. It should be noted that if none of the candidate large pages among the filtered candidate large pages meet the allocation requirements with the largest contiguous free memory size, the matching process is terminated, and a new contiguous physical memory block is allocated for the new page fault according to the original pre-allocation process, generating a new candidate large page to ensure that the page fault processing is not interrupted.

[0066] In alternative implementations, such as Figure 10 As shown, the mapping between the free memory range of the matching preparatory big page and the virtual address range of the subsequent code segment established by S300 includes: S340: Allocate an aligned virtual memory region in the virtual address space of the current process.

[0067] S350: Maps the physical page frame number corresponding to the largest contiguous free memory range of the matched pre-page to the virtual address range of the virtual memory region.

[0068] S360: Update the interval tree of the prepared big page, marking the mapped memory interval as allocated.

[0069] In this embodiment, an aligned virtual memory region is allocated in the virtual address space of the current process. The current process refers to the process that triggered the subsequent page fault. The virtual address space is the total range of virtual addresses accessible to the process; each process has its own independent virtual address space, and the virtual address spaces of different processes are isolated from each other. The aligned virtual memory region refers to a 2MB aligned virtual memory region that matches the granularity of the page intermediate directory mapping. During allocation, an unused, 2MB aligned contiguous virtual address range is searched within the virtual address space of the current process. A corresponding virtual memory region structure is created for this virtual address range, and the memory attributes of the virtual memory region are configured as readable and executable, consistent with the memory attributes of the code segment. Simultaneously, the relevant flag bits of the virtual memory region are configured, completing the allocation of the virtual memory region.

[0070] For example, the physical page frame number corresponding to the largest contiguous free memory range of the matched pre-existing big page is mapped to the virtual address range of the virtual memory region. The largest contiguous free memory range refers to the longest contiguous free physical page range within the pre-existing big page, and the physical page frame numbers corresponding to this range are a continuously increasing numerical sequence. The mapping operation is implemented through the kernel's memory remapping function, establishing a one-to-one mapping relationship between the contiguous physical page frame numbers and the virtual address range of the virtual memory region. The corresponding physical page frame number and memory permission configuration are filled into the page table entry corresponding to the virtual memory region, establishing a stable mapping from virtual address to physical address. It should be noted that this mapping operation only establishes a new mapping relationship from virtual address to existing physical memory; it does not allocate new physical memory, nor does it modify or move existing data in physical memory. It does not affect the memory range already allocated in the original pre-existing big page, ensuring the stability of the original memory access.

[0071] Specifically, the interval tree of the pre-allocated large page is updated, marking the mapped memory intervals as allocated. After mapping, the start and end physical page frame numbers corresponding to the mapped memory intervals are obtained, and the start and end addresses of the corresponding allocated memory intervals are determined. In the interval tree of the pre-allocated large page, a free memory interval overlapping with the allocated memory interval is found, and this free memory interval is removed from the interval tree. The unmapped free memory intervals before and after the new interval are split off, and the split free memory intervals are re-inserted into the interval tree. Then, the new allocated memory interval is inserted into the interval tree, completing the interval tree update. After the update, the total number of free pages and the maximum number of consecutive free pages of the pre-allocated large page are recalculated, and the relevant parameters are updated. It should be noted that the interval tree update operation is protected by a spinlock to ensure that no data races occur during the update process, guaranteeing the accuracy of the interval data.

[0072] In alternative implementations, such as Figure 11 As shown, the method further includes step S400 after updating the interval tree of the prepared large page and marking the mapped memory interval as allocated: S410: Calculate the remaining free memory size for preparing large pages.

[0073] S420: When the remaining free memory exceeds a preset threshold, the prepared large page is added back to the reuse wait queue.

[0074] S430: When the remaining free memory size does not exceed the preset threshold, the prepared large page is removed from the reuse waiting queue.

[0075] In this embodiment, the implementation process of the multiplexed prepared large page queue is described in detail. First, the interval tree of the prepared large page is updated. After marking the mapped memory interval as allocated, the remaining free memory size of the prepared large page is calculated. The remaining free memory size refers to the total size of all pages in the prepared large page that are in a free state after this mapping allocation is completed. In the calculation, the lengths of all free memory intervals in the interval tree are added together to obtain the total number of free pages. Then, the total number of free pages is multiplied by the size of a single page, 4KB, to obtain the remaining free memory size.

[0076] For example, when the remaining free memory exceeds a preset threshold, the prepared large page is re-added to the reuse waiting queue. The preset threshold is the same as the initial threshold for adding to the reuse waiting queue; in this embodiment, it is 8KB. If the remaining free memory is greater than 8KB, it means that there is still reusable free memory in the prepared large page, and it can continue to be kept in the reuse waiting queue, waiting for subsequent allocation requests to match. When re-adding to the reuse waiting queue, it is first checked whether the prepared large page already exists in the reuse waiting queue. If it already exists, the position of the prepared large page in the ordered tree sorted by free size is updated; if it does not exist, the prepared large page is added to the linked list of the reuse waiting queue and simultaneously inserted into the ordered tree structure.

[0077] Specifically, when the remaining free memory size does not exceed a preset threshold, the prepared large page is removed from the reuse waiting queue. If the remaining free memory size is less than or equal to 8KB, it means that there is not enough reusable free memory in the prepared large page. Continuing to keep it in the reuse waiting queue will increase the overhead of the matching operation, so it is removed from the reuse waiting queue. During removal, the node corresponding to the prepared large page is removed from the linked list of the reuse waiting queue, and the corresponding node is also removed from the ordered tree sorted by free size. The total count of the reuse waiting queue is updated, and the removal operation is completed. It should be noted that after the prepared large page is removed from the reuse waiting queue, its original mapping relationship, memory usage status, and interval tree structure will not change. It will only no longer participate in the subsequent reuse matching process. If a page is released within the prepared large page later, and the remaining free memory size exceeds the preset threshold again, it can be added back to the reuse waiting queue to continue participating in reuse matching.

[0078] In alternative implementations, such as Figure 12 As shown, it also includes S500 after marking the virtual memory region corresponding to the prepared large page and adding it to a preset check queue: S510: Retrieves virtual memory regions from the check queue according to a preset scheduling cycle.

[0079] S520: Perform multi-dimensional compliance checks on the corresponding preparatory main page.

[0080] S530: When the prepared large page passes the multi-dimensional compliance check, release the page table entry corresponding to the prepared large page, and establish a large page mapping that matches the contiguous physical memory block in the corresponding page intermediate directory table entry.

[0081] In this embodiment, after marking the virtual memory region corresponding to the pre-defined large page and adding it to a preset check queue, the virtual memory region is retrieved from the check queue according to a preset scheduling cycle, and multi-dimensional compliance verification is performed on the corresponding pre-defined large page. The preset scheduling cycle refers to the scheduling interval of the kernel's periodic processing threads, which can be configured to 100 milliseconds in this embodiment, or adjusted to other values ​​according to the system load. The periodic processing threads run according to the preset scheduling cycle, and each time they run, they sequentially retrieve virtual memory regions from the check queue and perform multi-dimensional compliance verification on the pre-defined large page corresponding to each virtual memory region.

[0082] For example, multi-dimensional compliance verification includes physical page frame number continuity verification and code hotspot verification. Physical page frame number continuity verification involves traversing all page table entries corresponding to the preparatory big page, extracting the physical page frame number from each page table entry, and checking whether all physical page frame numbers are a continuously increasing numerical sequence. If all physical page frame numbers are a continuously increasing numerical sequence, the physical page frame number continuity verification passes; if there are cases where physical page frame numbers are not continuous, the verification fails. Code hotspot verification involves collecting the memory access count and instruction translation detection buffer missing count within the virtual address range corresponding to the preparatory big page, calculating the instruction translation detection buffer missing rate, and if the memory access count exceeds a preset access count threshold and the instruction translation detection buffer missing rate exceeds a preset missing rate threshold, the code hotspot verification passes; otherwise, the verification fails.

[0083] Specifically, when a pre-existing large page passes multi-dimensional compliance checks, the corresponding page table entry is released, and a large page mapping matching the contiguous physical memory block is established in the corresponding page intermediate directory table entry. Passing multi-dimensional compliance checks indicates that the physical memory of the pre-existing large page remains contiguous, will not trigger cross-node memory access, and the code segment is hotspot code; establishing a large page mapping can provide a clear performance improvement. When establishing a large page mapping, all page table entries corresponding to the pre-existing large page are first released, and the memory space occupied by the page table entries is reclaimed. Then, in the page intermediate directory table entry of the corresponding virtual address range, the starting physical page frame number of the contiguous physical memory block is filled in, and the relevant flag bits and permission configurations for the large page mapping are configured, establishing a 2MB large page mapping at the page intermediate directory level. After the mapping is established, the processor's address translation cache is refreshed to ensure the new page table mapping takes effect. At this point, when the processor accesses this virtual address range, it directly completes the address translation through the page intermediate directory table entry, without needing to access the page table entry, reducing the overhead of address translation, lowering the probability of missing instruction translation detection buffers, and improving code execution performance. It should be noted that during the process of establishing a large page mapping, no new physical memory needs to be allocated, nor does any memory data need to be copied. Only the contents of the page intermediate directory table need to be modified. The operation takes very little time, will not cause long-term lock blocking, and will not affect the real-time performance of the business.

[0084] Based on the same principle, this application also discloses a code segment big page allocation processing system. For example... Figure 13 As shown, the system includes an exception capture module 11, a pre-large page generation module 12, and a mapping reuse module 13.

[0085] The exception capture module 11 is used to respond to a page fault at the middle directory level of the code segment, obtain the virtual address range corresponding to the page fault, pre-allocate contiguous physical memory blocks according to the virtual address range, and establish a corresponding page table entry mapping to generate a preparatory big page. The preparatory large page generation module 12 is used to add a mark to the virtual memory region corresponding to the preparatory large page and add it to a preset check queue, track the free memory range within the preparatory large page, and add preparatory large pages whose free memory range size exceeds a preset threshold to a reuse waiting queue. The mapping and reuse module 13 is used to match a qualified preparatory large page from the reuse wait queue when a page fault is triggered by a subsequent code segment, and to establish a mapping between the free memory range of the matched preparatory large page and the virtual address range of the subsequent code segment.

[0086] For example, the complete implementation process of this application embodiment can be illustrated through the following specific scenario. The system adopts a four-level page table structure, with a large page granularity of 2MB and a basic paging granularity of 4KB. The non-uniform memory access architecture is divided into two nodes, node 0 and node 1. Each node corresponds to a set of processors and local physical memory. The preset threshold for large page reuse is 8KB.

[0087] First, the processor of node 0 executes a code segment of a process. The accessed virtual address corresponds to a page intermediate directory table entry that has no valid mapping, triggering a page intermediate directory level page fault. The exception capture module 11 receives this page fault, obtains the virtual address that triggered the exception as 0x400000, determines the corresponding 2MB aligned virtual address range to be from 0x400000 to 0x600000, and passes the relevant information to the preparatory big page generation module 12.

[0088] After receiving the virtual address range, the preparatory big page generation module 12 allocates a 2MB contiguous physical memory block from the local memory of node 0, corresponding to 512 consecutive physical page frame numbers from 0x10000 to 0x101ff. It then creates 512 consecutive page table entries for the virtual address range from 0x400000 to 0x600000, with each page table entry corresponding to a virtual page and a physical page, establishing a one-to-one mapping to generate the preparatory big page. Finally, it adds a unique marker to the virtual memory region corresponding to this preparatory big page and adds it to a preset check queue.

[0089] The preparatory large page generation module 12 creates a range tree structure for the preparatory large page. In the initial state, the entire 2MB physical memory is a free memory range, with a total of 512 free pages and a maximum number of consecutive free pages of 512.

[0090] Subsequently, the process allocated 510 4KB pages within the preparatory large page for loading the code segment. Two pages remained, resulting in a total free memory size of 8KB, which did not exceed the preset threshold and therefore was not added to the reuse waiting queue. The preparatory large page generation module 12 updated the interval tree, inserting the allocated memory interval of 510 pages and the remaining 2 pages of free memory, resulting in a total of 2 free pages and a maximum of 2 consecutive free pages.

[0091] After a period of time, the process released 256 pages, bringing the total number of free pages to 258 and the total free memory size to 1032KB, exceeding the preset threshold of 8KB. The pre-released large page generation module 12 updated the interval tree, marking the 256 released pages as free, merging adjacent free memory intervals, updating the total number of free pages to 258, and the maximum number of consecutive free pages to 256. The pre-released large page generation module 12 added this pre-released large page to the reuse waiting queue, recording that the node to which the pre-released large page belongs is node 0, the data type is a code segment page, and the maximum consecutive free memory size is 1024KB.

[0092] Subsequently, the processor of node 0 executes another code segment of the same process, triggering a new page intermediate directory level page fault. The exception capture module 11 obtains a new virtual address range with the corresponding node number 0, the data type being code segment page, and the allocation requirement being 256 consecutive pages.

[0093] The mapping multiplexing module 13 filters the preparatory large pages of node 0 and code segment page type from the multiplexing waiting queue. The preparatory large page is found, and its maximum number of consecutive free pages of 256 meets the allocation requirements. Therefore, the preparatory large page is selected.

[0094] The mapping multiplexing module 13 allocates a new 2MB aligned virtual memory region in the virtual address space of the current process, maps the physical page frame numbers corresponding to the 256 consecutive free pages in the prepared big page to the new virtual memory region, and establishes page table mapping.

[0095] The preparatory large page generation module 12 updates the interval tree of the preparatory large page, marks the 256 mapped pages as allocated, splits the corresponding free memory intervals, updates the total number of free pages to 2, and the maximum number of consecutive free pages to 2.

[0096] The mapping multiplexing module 13 checks that the remaining free memory size of the prepared large page is 8KB, which does not exceed the preset threshold, so it removes the prepared large page from the multiplexing wait queue.

[0097] Meanwhile, the kernel's periodic processing thread retrieves the virtual memory region corresponding to the preparatory large page from the inspection queue according to a preset scheduling cycle and performs multi-dimensional compliance checks. First, it checks the continuity of physical page frame numbers; all physical page frame numbers of the preparatory large page are still in a continuously increasing sequence, so the physical page frame number continuity check passes. Then, it collects the access count of the code segment and the instruction translation detection buffer missing rate; both exceed the preset threshold, so the code hotspot check passes.

[0098] After the preparatory big page passes the multi-dimensional compliance verification, the corresponding 512 page table entries are released. The starting physical page frame number 0x10000 of the contiguous physical memory block is filled into the page intermediate directory table entry to establish a 2MB big page mapping. The address translation cache is refreshed, and the big page mapping officially takes effect.

[0099] Those skilled in the art will understand that the above embodiments are merely exemplary implementation methods. In actual implementation, the relevant parameter configurations, the order of implementation steps, and the implementation methods of modules can be adjusted according to the system's hardware architecture, memory management requirements, and business scenarios. As long as the implementation principle is consistent with the embodiments of this application, they all fall within the scope of this application.

Claims

1. A method for handling large page allocation of code segments, characterized in that, include: In response to a page fault at the middle directory level in the code segment, obtain the virtual address range corresponding to the page fault, pre-allocate contiguous physical memory blocks according to the virtual address range, and establish a corresponding page table entry mapping to generate a preparatory big page. Mark the virtual memory region corresponding to the preparatory large page and add it to the preset check queue. Track the free memory range within the preparatory large page and add the preparatory large page whose free memory range exceeds the preset threshold to the reuse waiting queue. When a page fault is triggered in a subsequent code segment, a matching pre-page is selected from the reuse wait queue, and a mapping is established between the free memory range of the matching pre-page and the virtual address range of the subsequent code segment.

2. The method according to claim 1, characterized in that, Based on the virtual address range, pre-allocate contiguous physical memory blocks, establish corresponding page table entries to map and generate preparatory big pages, including: Determine the aligned virtual address range that matches the page intermediate directory mapping granularity based on the virtual address range; Allocate contiguous physical memory blocks based on aligned virtual address ranges; Create contiguous page table entries based on the aligned virtual address range and contiguous physical memory blocks, establish a mapping relationship between each page table entry and the corresponding page in the physical memory block, and generate a preparatory big page.

3. The method according to claim 2, characterized in that, Based on the alignment of virtual address ranges with contiguous physical memory blocks, contiguous page table entries are created. The mapping relationship between each page table entry and the corresponding page in the physical memory block is established, including: The aligned virtual address range is split to obtain a continuous virtual page address; The contiguous physical memory blocks are split to obtain contiguous physical page addresses, and each physical page address corresponds to a unique physical page frame number; Create a corresponding page table entry for each virtual paging address, and establish a mapping relationship between each page table entry and the physical page frame number of the corresponding physical paging address.

4. The method according to claim 1, characterized in that, Tracking free memory ranges within the prepared large pages and adding prepared large pages with free memory ranges exceeding a preset threshold to the reuse waiting queue includes: Update the allocated and free memory regions within the prepared large page at the pagination level; Calculate the total free memory size and the maximum contiguous free memory size within the free memory interval of the prepared large page; When the total free memory size exceeds a preset threshold, the prepared large pages are added to the reuse waiting queue.

5. The method according to claim 4, characterized in that, Updating the allocated and free memory regions within a prepared large page at the paging granularity includes: After completing the paging allocation within the preparatory large page, insert the corresponding allocated memory interval into the interval tree, and update the total number of free pages and the maximum number of consecutive free pages. After the paging is released within the preparatory large page, the corresponding interval is marked as free in the interval tree, adjacent free memory intervals are merged, and the total number of free pages and the maximum number of consecutive free pages are updated.

6. The method according to claim 1, characterized in that, Matching eligible preparatory large pages from the reuse waiting queue includes: Obtain the non-uniform memory access node number and data type corresponding to the page fault exception in the subsequent code segment; Filter the preparatory large pages in the reuse waiting queue that match the non-uniform memory access node number and data type; Among the filtered reserve large pages, select the reserve large page whose maximum contiguous free memory size meets the allocation requirements.

7. The method according to claim 1, characterized in that, Establishing the mapping between the free memory range of the matching preparatory big page and the virtual address range of the subsequent code segment includes: Allocate an aligned virtual memory region in the virtual address space of the current process; Map the physical page frame number corresponding to the largest contiguous free memory range of the matched pre-page to the virtual address range of the virtual memory region; Update the interval tree of the prepared large page, marking the mapped memory interval as allocated.

8. The method according to claim 7, characterized in that, This also includes updating the range tree of the prepared large pages, marking the mapped memory range as allocated: Calculate the remaining free memory size for preparing large pages; When the remaining free memory exceeds a preset threshold, the prepared large page will be added back to the reuse wait queue. When the remaining free memory size does not exceed the preset threshold, the prepared large page is removed from the reuse waiting queue.

9. The method according to claim 1, characterized in that, This also includes marking the virtual memory region corresponding to the prepared big page and adding it to a pre-defined check queue: Virtual memory regions are retrieved from the inspection queue according to a preset scheduling cycle; Perform multi-dimensional compliance checks on the corresponding preparatory main pages; When the prepared large page passes the multi-dimensional compliance check, the page table entry corresponding to the prepared large page is released, and a large page mapping matching the contiguous physical memory block is established in the corresponding page intermediate directory table entry.

10. A code segment large page allocation processing system, characterized in that, include: The exception capture module is used to respond to page faults at the middle directory level of the code segment, obtain the virtual address range corresponding to the page fault, pre-allocate contiguous physical memory blocks according to the virtual address range, and establish corresponding page table entry mappings to generate preparatory big pages. The preparatory large page generation module is used to mark the virtual memory region corresponding to the preparatory large page and add it to a preset check queue, track the free memory range within the preparatory large page, and add preparatory large pages whose free memory range size exceeds a preset threshold to a reuse waiting queue. The mapping and reuse module is used to match a qualified preparatory large page from the reuse waiting queue when a page fault is triggered by a subsequent code segment, and to establish a mapping between the free memory range of the matched preparatory large page and the virtual address range of the subsequent code segment.