Memory allocation method and apparatus

By forcibly allocating page table pages on NUMA nodes and combining this with an intelligent memory migration mechanism, the latency problem caused by remote access to page table pages in multi-core systems is solved, thereby improving system performance and resource utilization efficiency.

CN121092335BActive Publication Date: 2026-03-20ALIBABA CLOUD COMPUTING CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-12
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

In existing technologies, frequent access to remote node memory by threads in multi-core, multi-NUMA node systems leads to increased memory latency, and existing optimization schemes neglect NUMA locality optimization of page table pages, resulting in impacted system performance.

Method used

By acquiring the resource binding mechanism of the target process, the target memory node is determined, and page table pages are allocated on that node. If local memory is insufficient, local physical pages are migrated to remote memory nodes until allocation is successful, ensuring that page table pages are allocated on the local node.

Benefits of technology

It eliminates memory latency caused by remote access to page tables, improves system resource utilization efficiency and performance, and provides stable performance, especially in AI inference and high-frequency trading applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121092335B_ABST
    Figure CN121092335B_ABST
Patent Text Reader

Abstract

The embodiment of the present specification provides a memory allocation method and device, the method comprises: in the case of determining to perform page table page allocation for a target page table of a target process, acquiring a resource binding mechanism corresponding to the target process; according to a memory node binding constraint in the resource binding mechanism, determining a target memory node corresponding to the target process, and allocating a page table page for the target page table in the target memory node; in the case that local memory of the target memory node is insufficient to cause the page table page allocation to fail, migrating a target physical page in the local memory to a first remote memory node, and continuing to perform the step of allocating a page table page for the target page table in the target memory node until the page table page allocation succeeds. By such a forced allocation of a page table page in a target memory node and in combination with an intelligent memory migration mechanism, performance loss caused by remote access of a page table is fundamentally eliminated.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present specification relate to the technical field of computer technology, and particularly relate to a memory allocation method and device. BACKGROUND

[0002] With the rapid development of modern server hardware architecture, multi-core, multi-NUMA node systems have become the standard configuration of data centers. Especially in performance-sensitive application scenarios such as high-performance computing (HPC), large-scale concurrent services, AI inference, database systems, etc., the non-uniform memory access characteristics brought by the NUMA architecture have increasingly become an important factor affecting the overall performance of the system. The traditional uniform memory access assumption no longer holds in a multi-node environment, and the physical distance difference between threads and memory directly leads to significant fluctuations in access latency, which in turn affects instruction execution efficiency and task response time.

[0003] When threads frequently access remote node memory, memory latency will be significantly increased. However, existing optimization schemes mainly focus on user data layout, ignoring kernel critical metadata: NUMA locality optimization of page table pages.

[0004] Modern compilers and runtime systems support NUMA-aware optimization to some extent, but still lack the ability to optimize the allocation of page table pages. SUMMARY

[0005] Therefore, the embodiments of the present specification provide a memory allocation method, and one or more embodiments of the present specification also relate to a memory allocation device, a computing device, a computer-readable storage medium, and a computer program product to solve the technical defects in the prior art.

[0006] According to a first aspect of the embodiments of the present specification, a memory allocation method is provided, applied to a non-uniform memory access architecture, comprising:

[0007] In a case where it is determined to allocate a page table page for a target page table of a target process, a resource binding mechanism corresponding to the target process is obtained;

[0008] According to the memory node binding constraint in the resource binding mechanism, a target memory node corresponding to the target process is determined, and a page table page is allocated for the target page table in the target memory node;

[0009] In a case where local memory of the target memory node is insufficient to cause the page table page allocation to fail, a target physical page in the local memory is migrated to a first remote memory node, and the step of allocating a page table page for the target page table in the target memory node is continued to be executed until the page table page allocation is successful.

[0010] According to a second aspect of the embodiments of the present specification, a memory allocation apparatus applied to a non-uniform memory access architecture is provided, comprising:

[0011] a data acquisition module configured to acquire a resource binding mechanism corresponding to a target process in a case where a page table page is allocated for a target page table of the target process;

[0012] a memory node determination module configured to determine a target memory node corresponding to the target process according to a memory node binding constraint in the resource binding mechanism, and allocate a page table page for the target page table in the target memory node;

[0013] a page table page allocation module configured to, in a case where local memory of the target memory node is insufficient to cause the page table page allocation to fail, migrate a target physical page in the local memory to a first remote memory node, and continue to perform the step of allocating a page table page for the target page table in the target memory node until the page table page allocation succeeds.

[0014] According to a third aspect of the embodiments of the present specification, a page table page allocation method based on a NUMA architecture is provided, comprising:

[0015] acquiring a resource binding mechanism corresponding to a target process in a case where a page table page is allocated for a target page table of the target process;

[0016] determining a target NUMA node corresponding to the target process according to a memory node binding constraint in the resource binding mechanism, and allocating a page table page for the target page table in the target NUMA node;

[0017] in a case where local memory of the target NUMA node is insufficient to cause the page table page allocation to fail, migrating a target physical page in the local memory to a first remote NUMA node, and continuing to perform the step of allocating a page table page for the target page table in the target NUMA node until the page table page allocation succeeds.

[0018] According to a fourth aspect of the embodiments of the present specification, a computing device is provided, comprising:

[0019] a memory and a processor;

[0020] wherein the memory is configured to store computer programs / instructions, and the processor is configured to execute the computer programs / instructions, and the computer programs / instructions, when executed by the processor, implement the steps of the above memory allocation method or the page table page allocation method based on the NUMA architecture.

[0021] According to a fifth aspect of the embodiments of the present specification, a computer readable storage medium is provided, which stores computer programs / instructions, which, when executed by a processor, implement the steps of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0022] According to a sixth aspect of the embodiments of the present specification, a computer program product is provided, which includes computer programs / instructions, which, when executed by a processor, implement the steps of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0023] One or more embodiments of the present specification implement a memory allocation method, which comprises: in the case of determining to allocate a page table page for a target page table of a target process, obtaining a resource binding mechanism corresponding to the target process; determining a target memory node corresponding to the target process according to a memory node binding constraint in the resource binding mechanism, and allocating a page table page for the target page table in the target memory node; in the case of determining that the local memory of the target memory node is insufficient to cause the page table page allocation to fail, migrating a target physical page in the local memory to a first remote memory node, and continuing to execute the step of allocating a page table page for the target page table in the target memory node until the page table page allocation is successful.

[0024] Specifically, the memory allocation method, in the case of determining to allocate a page table page for a target page table of a target process, first obtains a resource binding mechanism (such as cpuset.mems configuration) corresponding to the target process, and according to the memory node binding constraint in the mechanism, the kernel determines a unique target memory node and strictly limits the allocation of a page table page for the target page table only in the target memory node. Secondly, if the local memory of the target memory node is insufficient at this time, causing the page table page allocation to fail, an intelligent memory consolidation process will be started, that is, a plurality of target physical pages (such as cold pages) in the local memory of the target memory node are migrated to a first remote memory node to release the local memory space of the target memory node, and the previous page table page allocation process is continued to be retried, and the process is repeated until the allocation is successful. By such forced allocation of a page table page in the target memory node and the combination of the intelligent memory migration mechanism, the performance loss caused by remote access of the page table, such as memory delay, is fundamentally eliminated. BRIEF DESCRIPTION OF DRAWINGS

[0025] Figure 1 is an application scenario diagram of a memory allocation method provided by one embodiment of the present specification;

[0026] Figure 2 is a flowchart of a memory allocation method provided by one embodiment of the present specification;

[0027] Figure 3is a structural schematic diagram of a memory allocation device provided by an embodiment of the present specification.

[0028] Figure 4 is a structural block diagram of a computing device provided by an embodiment of the present specification. DETAILED DESCRIPTION

[0029] In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present specification. However, the present specification can be practiced without the specific details, other than in the examples described herein. Those of ordinary skill in the art, and others, can readily ascertain combinations and sub-combinations of the elements of the present specification without departing from the scope of the present specification. Thus, the scope of the present specification is not to be limited by the specific details in the description.

[0030] The terminology used in one or more embodiments of the present specification is for the purpose of describing particular embodiments only and is not intended to be limiting of one or more embodiments of the present specification. As used in one or more embodiments of the present specification and the accompanying claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and / or "comprising," when used in one or more embodiments of the present specification, specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof.

[0031] It will be understood that, although the terms first, second, etc. can be used herein to describe various information, these terms are not intended to denote a temporal or chronological order. Rather, these terms are used solely to distinguish one from another only. For example, without departing from the scope of one or more embodiments of the present specification, first can be termed second, and similarly, second can be termed first. The term "if' as used herein, can be interpreted as meaning "when" or "in response to determining" depending on the context.

[0032] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in one or more embodiments of the present specification are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.

[0033] First, the terms involved in one or more embodiments of the present specification are explained.

[0034] NUMA: Non-Uniform Memory Access, a memory access architecture for multi-processor systems, its function is to realize more efficient memory access path by physically binding CPU (Central Processing Unit) and local memory, so as to improve the scalability and overall performance of the system in multi-core / multi-way environment.

[0035] NUMA node: a NUMA node is a processor-memory resource unit, containing a group of CPU cores and their directly connected local memory, its function is to provide low latency and high bandwidth memory access capability for threads running on it.

[0036] Page table: Page Table, which represents the mapping of virtual addresses to physical addresses, is a data structure used by the operating system to manage the mapping of virtual addresses to physical addresses, which is an array, each element is called a page table entry, which stores the mapping relationship of a virtual page to a physical page.

[0037] Page table page: Page Table Page, which is the physical carrier of the page table, a physical memory page (usually 4KB), used to store all table entries of a certain level page table. Specifically, a page table page is a page in physical memory, and a page table is a logical structure, whose content is stored in a page table page.

[0038] MMU: Memory Management Unit, responsible for handling virtual address to physical address conversion, and managing memory access permissions, cache behavior, etc.

[0039] Cold page: Cold Page, which refers to a page that has not been accessed for a long time. In the LRU (Least Recently Used) mechanism of Linux, pages are divided into: active page (Active List), which has been accessed recently; Inactive page (Inactive List), which has not been accessed, i.e. cold page.

[0040] PGD: Page Global Directory, which belongs to the highest level of multi-level page table; it is an array, each entry (PDE, Page Directory Entry) points to the physical address of a PUD page table, and CPU directly points to the physical address of the PGD of the current process through the CR3 register, which is the starting point of address translation.

[0041] PUD: Page Upper Directory, the second-level page table; an array, each entry (PDE) points to the physical address of a PMD page table, which is pointed to by the entry in PGD.

[0042] PMD: Page Middle Directory, the third-level page table; an array, each entry (PDE) points to the physical address of a PTE page table.

[0043] PTE: Page Table Entry, the bottom-level page table entry; a physical page, storing multiple PTE entries. PTE entry: an entry in the page table, which directly contains the physical page frame number (PFN, Page Frame Number): the address of the target physical memory page, permission bits: such as readable (R), writable (W), executable (X), user / kernel (U / S), etc., status bits: such as present (Present), accessed (Accessed), dirty (Dirty), etc. When the MMU finds the PTE entry, it can combine the offset of the virtual address with the physical page frame number to get the final physical address.

[0044] COW: Copy-On-Write, write-once copy, is an optimization strategy for delayed copy. Multiple processes or entities share the same data, and only when a process attempts to modify the data, the kernel will actually allocate a new copy for it and perform the copy. After that, the process operates its own copy.

[0045] HPC: High-Performance Computing, high-performance computing, refers to the use of supercomputers or computer clusters to solve complex problems that require huge computing power.

[0046] AI: Artificial Intelligence, artificial intelligence, refers to the technology that enables machines to simulate human intelligent behavior, such as learning, reasoning, recognition, etc.

[0047] Web: World Wide Web, the World Wide Web, is an information system based on hypertext on the Internet. Web engine is the core component of web browser that is responsible for rendering and parsing web page content.

[0048] QoS: Quality of Service, service quality, refers to the provision of different levels of priority protection and resource allocation for different types of traffic (such as voice, video, data, etc.) in network communication to ensure that critical applications obtain the required bandwidth, delay, jitter, and packet loss rate, etc. performance indicators.

[0049] NUMA-aware: Non-Uniform Memory Access-aware, refers to software (such as operating systems, applications, runtime systems) that can perceive and utilize the characteristics of underlying NUMA architecture for optimization design. For example, scheduling processes or threads to CPUs close to their required memory, preferentially allocating local memory, reducing cross-node memory access, optimizing data layout and thread binding (CPU affinity) to reduce latency and improve performance, etc.

[0050] cpuset: CPU set or CPU set, a control group (cgroup) subsystem provided by the Linux kernel, used to allocate a group of specified CPU cores and memory nodes (NUMA nodes) to specific processes or process groups, thereby achieving fine control and isolation of computing resources. Includes two core configuration parameters: cpuset.cpus and cpuset.mems, which work together to bind and isolate resources for processes. cpuset.cpus is used to limit processes to run only on specified CPU cores, and cpuset.mems is used to limit processes to allocate memory only from specified NUMA memory nodes.

[0051] malloc(): Memory allocation function, used to request a specified size of dynamic memory from the operating system, returning the starting address of the memory. The allocated memory is located in the process heap (heap) area. Returns a pointer on success or NULL (empty) on failure. alloc() indicates allocation.

[0052] brk(): Adjust the heap top pointer, brk() is a system call that directly sets the highest address (heap top) of the process heap area.

[0053] mmap(): Memory mapping system call, used to map a file or device to the process's virtual address space, or for anonymous mapping (not associated with a file), directly allocating a block of read-write memory (often used for large memory allocation).

[0054] fork(): A system call that creates a new process, this new process (child process) is almost identical to the calling process (parent process), including code, data, heap, stack, file descriptors, etc., but has an independent address space (write-optimized performance mechanism).

[0055] exec(): A set of system calls that replace the address space of the current process with a new program. After calling exec(), the code, data, heap, stack, etc. of the current process are overwritten by the contents of the new program. Usually after fork() creates a child process, the child process calls exec() to run another program (such as a shell command).

[0056] Page Fault: Page error or page exception or page interrupt. When a process accesses a virtual memory page that is not currently in physical memory, the CPU's memory management unit (MMU) will trigger an interrupt called Page Fault. Common triggering scenarios include: first access to memory allocated by the memory allocation function malloc(), access to mmap (memory mapping system call) mapped files but not yet loaded, process recovery from swap (swap, swap space or virtual memory swap) area when accessing swapped out pages, dereferencing a null pointer or wild pointer (causing a crash), etc.

[0057] CR3 register: Also known as Control Register 3, it is a key register used to store the physical address of the current process page directory table. It is one of the core components of virtual memory management and memory isolation between processes. The operating system switches different address spaces by modifying CR3.

[0058] CR2 register: Also known as Control Register 2, it is a register used to record the virtual address accessed when the last page error occurs. It is an important basis for the operating system to implement virtual memory management, on-demand paging and memory protection mechanisms. In simple terms, CR2 tells the operating system which virtual address caused the page fault.

[0059] In practical applications, the page table is the core data structure for the memory management unit (MMU) to perform virtual address to physical address conversion, with extremely high access frequency. Each time a memory access occurs, the MMU needs to traverse the page table. Therefore, the physical location of the page table page itself has a direct impact on performance. If a process running on NUMA node N has its page table page allocated on a remote node M, then each address translation will inevitably incur an expensive remote memory access, even if the final user data is located on the local node N. This overhead is amplified dramatically in loads that perform frequent memory accesses.

[0060] The current kernel page table page allocation mechanism has the following defects:

[0061] Lack of explicit NUMA-aware allocation strategy: When allocating page table pages, the kernel fails to always effectively pass the process's NUMA binding strategy (such as cpuset.mems) to the allocation layer. The failure to enforce the use of flags such as GFP_THISNODE allows the allocator to potentially allocate page table pages from arbitrary free nodes, violating NUMA locality.

[0062] Post-allocation immobility: Unlike user data pages, page table pages, as memory management metadata, have their physical addresses directly encoded in the parent page directory. This tight coupling makes them difficult to safely migrate once allocated. A page table page allocated on a remote node during initialization will continuously incur remote access overhead throughout its lifetime, creating a persistent performance defect.

[0063] Impact on overall system performance: The current kernel page table allocation mechanism has a significant impact on memory-intensive applications such as databases and AI inference. These applications typically optimize user data layout through binding and strategies, but remote allocation of page tables introduces a significant performance impact, injecting additional latency into every memory access. This severely affects the effectiveness of other NUMA optimization techniques and greatly reduces the overall system performance improvement.

[0064] To address the aforementioned technical problems, this specification provides a memory allocation method. One or more embodiments of this specification also relate to a memory allocation device, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.

[0065] See Figure 1 , Figure 1 A schematic diagram illustrating an application scenario of a memory allocation method provided according to an embodiment of this specification is shown.

[0066] according to Figure 1 It can be seen that, Figure 1 The NUMA architecture in the system includes two NUMA nodes, namely NUMA node 0 and NUMA node 1. Each NUMA node contains a set of CPUs and their directly connected local memory. NUMA node 0 and NUMA node 1 are interconnected through a QPI fast channel to enable remote access between them.

[0067] Assuming the memory allocation method provided in one or more embodiments of this specification is applied to this NUMA architecture, the specific implementation steps are as follows:

[0068] Step 102: If page table allocation is performed for the target page table of the target process, obtain the resource binding mechanism corresponding to the target process.

[0069] Step 104: According to the memory node binding constraint in the resource binding mechanism, a target memory node corresponding to the target process is determined, and a page table page is allocated for the target page table in the target memory node.

[0070] Step 106: In the case that the local memory of the target memory node is insufficient to cause the page table page allocation to fail, the target physical page in the local memory is migrated to a first remote memory node, and the step of allocating a page table page for the target page table in the target memory node is continued to be executed until the page table page allocation succeeds.

[0071] Taking the target memory node NUMA node 0 as an example, the above steps are illustrated.

[0072] Specifically, when the kernel determines that a page table page needs to be allocated for the target page table of the target process, the kernel first acquires the resource binding mechanism (such as cpuset.mems configuration) corresponding to the target process, and according to the explicit memory node binding constraint in the mechanism, the kernel determines a unique target memory node: NUMA node 0, and strictly limits that the page table page for the target page table can only be allocated on the NUMA node 0. Secondly, if the local memory of the NUMA node 0 is insufficient at this time, causing the page table page allocation to fail, a smart memory arrangement process will be started, that is, a plurality of target physical pages (such as cold pages) in the local memory of the NUMA node 0 are migrated to the NUMA node 1 to release the local memory space of the NUMA node 0, and the previous page table page allocation process is continued to be retried, and the process is repeated until the allocation succeeds.

[0073] The memory allocation method provided by one or more embodiments of the present specification first guarantees that the page table page is always located in the same NUMA node as the process accessing it through the mandatory local allocation strategy and the local memory arrangement mechanism after failure, eliminates the remote delay introduced due to page table access across nodes, and provides stable performance for AI reasoning, high-frequency trading and other applications that are sensitive to delay. Secondly, the disadvantage of immobility of the page table page after allocation is avoided, and the local memory space is released for the page table page by migrating the movable user data page, which not only complies with the physical constraint of the page table page, but also achieves the purpose of fixing the page table page in an optimal position, avoiding the formation of persistent performance defects. Finally, under the premise of strictly complying with the cpuset isolation strategy, the memory layout in the node is optimized through intelligent migration, the "cold" data is migrated out, the memory space is released for the "hot" metadata (page table page), the frequent access (address translation) always occurs locally, the congestion of the interconnection bus is reduced, and thus the resource utilization efficiency and performance of the whole system are improved while ensuring the isolation between processes.

[0074] Referring to Figure 2 , Figure 2A flow chart of a memory allocation method according to one embodiment of the present specification is shown, which specifically includes the following steps.

[0075] Step 202: In the case of determining to perform page table page allocation for a target page table of a target process, obtaining a resource binding mechanism corresponding to the target process.

[0076] The memory allocation method provided by one or more embodiments of the present specification can be applied to any scenario requiring memory allocation for a page table page in a non-uniform memory access architecture, such as a process creation and address space initialization scenario: when a new process is created, the operating system needs to establish a page table structure (such as a four-level page table: PGD-PUD-PMD-PTE) for it, and then needs to allocate physical pages as page table pages for each level of the page table (such as allocating a page table page for PGD); a heap memory expansion scenario: when a process calls malloc() or brk() to expand the heap, the system needs to allocate new virtual pages for its virtual address space, and then update the page table. If the corresponding level of the page table does not exist, a new page table page needs to be allocated; a stack space growth scenario: the stack can usually grow automatically (triggered by a page fault exception), and when the stack expands to a new virtual page, if the page table entry does not exist, a page table page needs to be allocated to establish the mapping; a memory mapping file scenario: when using mmap() to map a file or anonymous memory, a page table entry is established for the specified virtual address range, and if the region crosses a new page table directory entry, a new page table page needs to be allocated; a page table optimization scenario in huge page (Huge Page) management: although huge pages (such as 2MB, 1GB) reduce the number of page table levels and page table pages, when switching between normal pages and huge pages, page table pages still need to be dynamically allocated / deallocated. Of course, in actual applications, there will be other scenarios that require memory allocation for page table pages, such as kernel self-page table management scenarios, address space switching scenarios, and the like, which will not be enumerated here. For any adaptable scenario that requires memory allocation for a page table page, the memory allocation method for the kernel provided by one or more embodiments of the present specification can be used to implement it.

[0077] The target process can be understood as a process that is currently running and needs to have a page table page allocated for it.

[0078] The target page table can be understood as a page table structure of the target process. For example, in Linux, each process has its own independent page table tree (from PGD-PUD-PMD-PTE), and the target page table can be understood as any part of the page table tree (such as PGD, PUD, PMD, and / or PTE).

[0079] The page table page can be understood as a physical memory page used to store page table entries, and page table page allocation can be understood as the kernel allocating a page frame of a predetermined size (such as 4KB) from physical memory and using it exclusively as a page table page for storing mapping relationships.

[0080] Resource binding mechanism, which can be understood as a kernel mechanism that limits the target page table to page table page allocation to use specific hardware resources, such as cpuset, which allows the target process to be bound to a specific CPU core and NUMA memory node for running, wherein the core parameter cpuset.mems of the cpuset defines which NUMA nodes the target process can apply for physical memory (i.e. the page table page of the target page table).

[0081] Obtaining the resource binding mechanism corresponding to the target process can be understood as the kernel reading the cpuset configuration by accessing the relevant fields in the process descriptor (task_struct), thereby determining which NUMA nodes the target process is allowed to use.

[0082] Specifically, the kernel determines that page table page allocation needs to be performed for the target page table of the target process, i.e. by accessing the relevant fields in the process descriptor, reading its cpuset configuration (resource binding mechanism), thereby determining which NUMA nodes the target process is allowed to use.

[0083] And for the scenario of page table page allocation for the target page table of the target process, there are at least two, such as the page table page allocation scenario at the initialization of exec(), and the page table page allocation scenario triggered by Page Fault.

[0084] Specifically, the page table page allocation at the initialization of exec() occurs when the child process calls exec() to start loading a new program after fork() creates a child process, and the page table structure needs to be established for the new address space. The specific implementation is as follows:

[0085] The determination of page table page allocation for the target page table of the target process comprises:

[0086] In a case where it is determined that the target process calls a process replacement function to load a new program, it is determined that page table page allocation is performed for the target page table of the target process, wherein the target process is a target child process created by a child process creation function for a target parent process, and the new program is a program running in the target process and different from a target program running in the target parent process.

[0087] The process replacement function can be understood as an exec() system call, which is used to replace the program currently running by the process with a new program. The PID (Process ID) of the process remains unchanged, but the code, data, stack, and the like are replaced by the contents of the new program. The target process calling the process replacement function to load the new program can be understood as follows: after the fork() creates a child process (i.e., the target process), the child process calls the exec() to start loading the new program. At this time, the new program can be understood as a program that runs in the child process and is different from the target program (original program) running in the target parent process, i.e., a new executable file different from the original program running in the target parent process.

[0088] The child process creation function can be understood as a fork() system call, which creates a new target child process (i.e., the target process) by copying the target parent process.

[0089] The page table page allocation for the target page table of the target process can be understood as the need to allocate new physical memory (physical pages) for the page table structure of the target process. In the page table page allocation scenario during the initialization of the exec(), since the address space needs to be completely replaced, a completely new page table tree needs to be constructed, and therefore the creation process of the page table tree needs to allocate page table pages of multiple levels of page directories (PGD, PUD, PMD, and PTE).

[0090] For example, assuming that a Shell process (command interpreter process) is a target parent process, the Shell process first calls fork() to create a Shell child process that is identical to the Shell process, i.e., a target child process (at this time, the target child process is also running the Shell program), and then the Shell child process calls exec() to start loading a new program " / bin / ls". At this time, the kernel can determine that the current task is to destroy the old address space and create a completely new address space for the Shell child process, and the construction of the completely new address space needs to establish a completely new mapping relationship for the code segment, data segment, heap, and stack of the new program. Therefore, the kernel determines to perform page table page allocation for the target page table of the Shell child process, and starts to allocate new page table pages of various levels for the Shell child process to construct the page table structure of the new program.

[0091] The memory allocation method provided by one or more embodiments of the present specification solves the problem that, in the traditional architecture, the page table page allocation of the exec() system call often ignores the NUMA locality when loading a new program for a process, which may place the page table page with high access frequency on a remote node, resulting in the process continuously suffering from remote access delay of address translation during its entire life cycle. However, the method optimizes the specific trigger scenario and forces the allocation of the new page table structure of the target process on the local NUMA node bound to the target process, thereby eliminating the performance risk from the beginning of program execution. Such targeted adjustment ensures that high-frequency operations such as the derivation of new processes by a web server, the start of function instances in a cloud computing environment, or the fast loading of tools by a Shell can obtain significant start-up speed and stable runtime performance. Due to the immovability of the page table page, the initial correct allocation avoids the performance problem that cannot be optimized later, thereby providing predictable low-delay protection for the system and significantly improving the resource utilization efficiency and overall throughput of data-intensive applications.

[0092] In addition, for the page table page allocation scenario triggered by a Page Fault, the occurrence timing is after the start of execution of a new program by a child process (target process), an unmapped virtual address (such as the first instruction, the first read / write data, stack growth, etc.) is accessed, a page fault exception is triggered, and page table page allocation is required. The specific implementation is described as follows.

[0093] The page table page allocation for the target page table of the target process includes the following steps.

[0094] In response to a page fault exception instruction for the target process, the page table page allocation for the target page table of the target process is determined, wherein the page fault exception instruction is triggered by the memory management unit in the case of failure in analyzing a target virtual address, and the target virtual address is a virtual address for memory writing or reading by the target process.

[0095] The page fault exception instruction can be understood as an interrupt signal triggered automatically by the CPU hardware. When the memory management unit fails to successfully complete the conversion of the virtual address to the physical address, the CPU will fall into the kernel and execute the corresponding exception handling program. The triggering scenarios of the page fault exception instruction include, but are not limited to, the first access to the memory (after the process calls malloc() or mmap() to allocate memory, only the virtual address is allocated, and the physical page is not allocated. When the memory is accessed for the first time, the page fault exception is triggered, and the kernel allocates a physical page for it), copy-on-write (after fork(), the parent and child processes share the physical pages of the parent process (read-only). When any process attempts to write to these shared pages, a page fault exception is triggered. When the kernel handles the page fault exception, it allocates a new physical page frame (for storing data) for the writing process and allocates a new page table page as needed (if the page table page of the child process is still shared, a separate page table page needs to be copied first); then, the kernel copies the new data page to the new physical page and updates the page table entry to point to the new page and mark it as writable), automatic stack space expansion (the stack usually has an initial size limit. When the function call is too deep or the local variable is too large, and the stack page that has not been allocated is accessed, a page fault exception is triggered, and the kernel allocates a new stack page for it), and the like.

[0096] The memory management unit can be understood as a unit in the CPU responsible for virtual address conversion, which resolves the virtual address by querying the page table.

[0097] Failure to resolve the target virtual address can be understood as a failure of the memory management unit when traversing the page table, such as non-existent page table entries (the page table page at a certain level in the translation path or the final data page has not been allocated), permission errors (attempting to write to a page marked as read-only, such as the copy-on-write scenario), and the like.

[0098] The target virtual address can be understood as the memory address specified by a memory access instruction in the target process that needs to be read or written.

[0099] Specifically, in response to the page fault exception instruction for the target process, the kernel determines that page table page allocation is needed for the target page table (such as PTE) of the target process through its page fault exception handling program after diagnosis finds that the failure reason for the failure of the memory management unit to resolve the target virtual address is the lack of intermediate-level page table pages (for example, a PTE page table does not exist).

[0100] For example, suppose target process 1 executes an instruction attempting to write data to a variable (target virtual address 000000). The CPU's MMU starts working, attempting to translate the target virtual address 000000. While traversing the page table, it finds that an intermediate-level page table (e.g., the PTE table) required for translating the target virtual address 000000 does not exist (its Present bit is 0). The MMU resolution fails, immediately triggering a page fault exception instruction and transferring control to the operating system kernel. The operating system kernel's exception handler executes, analyzes the cause of the error, and determines that the exception is due to a missing page table page, not a data page. Therefore, the kernel determines to allocate a new page table page for target process 1's target page table (e.g., the PTE table) to repair the page table tree, enabling the MMU to successfully translate the target virtual address 000000 next time.

[0101] The memory allocation method provided in one or more embodiments of this specification applies a NUMA-aware page table allocation mechanism to page fault handling scenarios. This solves the problem in traditional architectures where page table allocation during page fault handling may be placed on arbitrary idle nodes, causing remote access latency in subsequent address translations via that page table. This method achieves NUMA optimization by forcibly allocating page table pages from the local node of the process that triggered the exception during exception handling. This ensures that when a process dynamically expands its memory space (e.g., heap growth, stack extension, or loading dynamic libraries), its new page table structure always maintains an optimal distance from the CPU accessing it. This method eliminates cross-node overhead, providing consistently stable memory access performance for memory-intensive applications, avoiding performance degradation caused by runtime memory expansion, and thus guaranteeing improved overall system performance.

[0102] Step 204: Based on the memory node binding constraints in the resource binding mechanism, determine the target memory node corresponding to the target process, and allocate page table pages for the target page table on the target memory node.

[0103] When the kernel determines that the target page table of the target process is to allocate page table pages, after obtaining the resource binding mechanism corresponding to the target process, the target memory node corresponding to the target process can be determined according to the memory node binding constraints in the resource binding mechanism, and the page table pages of the target page table can be allocated only on the target memory node.

[0104] The memory node binding constraint can be understood as a specific configuration parameter in the resource binding mechanism. For example, in the case of the resource binding mechanism being cpuset, the memory node binding constraint can be understood as cpuset.mems, which is used to define which NUMA nodes the target process is allowed to allocate physical memory from. For example, cpuset.mems=0-1 can indicate that the target process can only use the memory of NUMA node 0 and NUMA node 1 for page table page allocation of the target page table.

[0105] In the case of the target memory node allocating a page table page for the target page table, the kernel can be understood as calling the physical memory allocator to allocate a page table page for the target page table in the target memory node.

[0106] In addition, in order to ensure that the allocation of the page table page can only be performed in the target memory node corresponding to the target process, the kernel can carry a mandatory flag when calling the physical memory allocator to allocate a page table page for the target page table in the target memory node, instructing the memory allocator to find a free physical page frame only in the target memory node and allocate it to the target page table of the target process for use as a page table page. The specific implementation is as follows:

[0107] The target memory node allocating a page table page for the target page table includes:

[0108] generating a memory allocation parameter containing a node allocation restriction flag for the target memory node, and calling a memory allocation function to send the memory allocation parameter to the memory allocator to call the memory allocator to allocate a page table page for the target page table in the target memory node, wherein the memory allocator parses the memory allocation parameter, and in the case of determining that the memory allocation parameter includes the node allocation restriction flag, allocates a page table page for the target page table in the target memory node according to the node allocation restriction flag.

[0109] The memory allocation parameter can be understood as the parameter required to initiate a memory allocation. The memory allocation parameter includes the target memory node (which NUMA node to allocate), the allocation flag (a flag bit used to control the allocation behavior, such as the node allocation restriction flag), the order (the size of the memory requested to be allocated, such as order=0 indicating allocation of 1 page, 4KB), and the like.

[0110] The node allocation restriction flag can be understood as a flag passed to the memory allocation function, used to enforce constraints on memory allocation behavior. For example, the node allocation restriction flag is the GFP_THISNODE flag, which means that memory is only allocated within the current NUMA node, and is used to prevent memory migration or cross- NUMA node fallback, ensuring that memory is allocated from the local node associated with the current CPU. The GFP_THISNODE flag is generally explicitly set when the memory allocation function is called during kernel code execution, such as when a process context is running (the current process is running on a CPU, and its current->node or memory policy (mempolicy) specifies a preferred node, and the kernel wants to allocate memory in this node), interrupt or soft interrupt context (to avoid cross-node access delays on NUMA systems, use GFP_THISNODE to force local allocation), large page or page migration scenarios (to avoid lock contention or performance degradation when migrating pages or allocating large pages, use GFP_THISNODE to avoid cross-node lookup).

[0111] The memory allocation function can be understood as a function used by the kernel to request physical pages from the physical memory allocator. Calling the memory allocation function is an action performed by the kernel code actively, and the kernel requests physical pages from the memory allocator by calling a specific function.

[0112] The memory allocator can be understood as a subsystem in the kernel responsible for managing physical page allocation and recycling, maintaining a list of free memory for each NUMA node, and handling all requests for physical pages.

[0113] Analyzing memory allocation parameters can be understood as the memory allocator checking and interpreting the incoming memory allocation parameters after receiving the call. For example, the memory allocator will check each bit in gfp_mask (allocation flags) to determine the caller's requirements and constraints.

[0114] Specifically, the kernel determines the target memory node according to the cpuset.mems parameter in the cpuset policy corresponding to the target process, then constructs a gfp_mask containing the GFP_THISNODE flag, and then calls the memory allocation function to send the memory allocation parameter containing the target memory node and the gfp_mask flag containing the GFP_THISNODE flag to the memory allocator. After receiving the memory allocation parameter, the memory allocator parses the memory allocation parameter. In the case of identifying the GFP_THISNODE flag in the gfp_mask flag, it can be determined that the memory allocation is a mandatory instruction, and the target page table must and can only be allocated on the target memory node specified by the memory allocation request. Then the memory allocator strictly limits its search range to the free memory list of the target memory node, performs page table page allocation for the target page table, and returns the allocation result (such as a non-NULL return value: indicating success. The memory allocator has completed page table allocation, physical memory reservation, and established the necessary mapping, NULL return value: indicating failure. It may be out of memory, allocation flag limitation (such as _GFP_THISNODE resulting in no memory on the local node), etc.) to the kernel.

[0115] The memory allocation method provided by one or more embodiments of the present specification introduces a node allocation restriction flag as a parameter of a memory allocation request, realizes strict NUMA locality of page table page allocation, avoids any flexibility or fallback behavior of the memory allocator in the policy, and changes its behavior from "allocate on the preferred node as much as possible" to "allocate only on the specified node". First, it is ensured that the page table page must be allocated on the target memory node from the beginning of the allocation, thereby eliminating the performance fluctuations and uncertainties caused by remote access of the page table. Secondly, it is ensured that the upper resource binding policy (such as cpuset) can be executed unbiasedly at the bottom, avoiding accidental destruction of the resource isolation principle due to the automatic fallback behavior of the memory allocator, and enhancing the safety and predictability of the system. Finally, the forced allocation strategy also exposes the memory shortage problem on the target memory node (rather than being masked by cross-node allocation), so that the memory recovery or OOM termination management mechanism can be triggered faster, significantly improving the overall health and stability of the system.

[0116] In addition, different page table page allocation scenarios correspond to different target page tables. In the page table page allocation scenario during exec() initialization, the kernel allocates a brand-new page table structure for a new address space. Initially, only high-level page directories (e.g., PGD) are allocated, and the underlying page table pages are allocated on demand, that is, the kernel does not immediately allocate all page table pages, but waits until the program actually accesses the memory, triggers a page fault exception, and in the page fault exception processing, the kernel allocates specific page table pages and physical memory pages and establishes a mapping. Therefore, in the page table page allocation scenario during exec() initialization, the kernel allocates page table pages for the PGD of the target process. The specific implementation is as follows:

[0117] The target page table is a page global directory;

[0118] The target memory node is allocated a page table page for the target page table, including:

[0119] The target memory node is allocated a page table page for the page global directory.

[0120] The page global directory can be understood as the PGD in the above embodiments, that is, a high-level page table in a page table structure, and each process has a unique PGD, the physical address of which is stored in the CR3 register of the CPU and is the starting point of address translation by the memory management unit.

[0121] Allocating a page table page for the page global directory can be understood as when a new process is created or the address space needs to be expanded, the kernel allocates a page frame of a preset size from the physical memory for storing the table entries of the page global directory.

[0122] The memory allocation method provided by one or more embodiments of the present specification ensures the NUMA locality of the process page table tree root node by forcibly allocating the page global directory (PGD) locally on the target memory node, eliminating cross-node access delays from the very beginning of address translation. The MMU does not need to read remotely when accessing the PGD, significantly reducing the overhead of virtual address conversion, which can significantly improve the overall performance of the system, especially in high-frequency context switching and memory access-intensive scenarios. Due to the immovability of the PGD, the initial allocation is localized, avoiding subsequent uncorrectable performance defects, providing stable and predictable low-delay protection for the system, which is particularly beneficial to the workload efficiency of applications such as databases, virtualization, and high-performance computing.

[0123] In the page table page allocation scenario triggered by the Page Fault, the kernel can obtain the page fault exception parameters in response to the page fault exception instruction for the target process, and determine the target page table for which the page table page needs to be allocated by analyzing the page fault exception parameters. The specific implementation is as follows:

[0124] The method further comprises:

[0125] Obtaining a page fault exception parameter, wherein the page fault exception parameter comprises the target virtual address and an exception error code generated by the memory management unit.

[0126] According to the target virtual address and the exception error code, determining the target page table by a step-by-step page table traversal method, wherein the target page table comprises a page upper directory, a page intermediate directory and / or a page table entry.

[0127] The page fault exception parameter can be understood as a set of information automatically generated by hardware and passed to the operating system kernel when the memory management unit fails to complete virtual address translation and triggers a page fault exception, including but not limited to a target virtual address (the memory address that triggered the page fault exception and that the target process attempted to access, which is stored in a special CR2 register by hardware), an exception error code (an encoding value generated by hardware, used to explain the specific reason for the page fault, such as whether the page does not exist (Present bit is 0) or the read-write permission is violated).

[0128] The step-by-step page table traversal method can be understood as a method in which the operating system kernel simulates the working mode of the hardware memory management unit, starting from the page global directory PGD of the target process page table, and sequentially querying each level of page table structure. The purpose is to resolve each level of page table entry: page upper directory (PUD), page intermediate directory (PMD), and page table entry (PTE) according to the virtual address. Specifically, the implementation steps of the kernel for page fault exception processing according to the step-by-step page table traversal method are as follows:

[0129] The kernel first obtains the faulty virtual address to find the PGD; then finds the PUD according to the PGD, if the PUD does not exist, calls pud_alloc() to allocate the PUD page table page, if the PUD exists, continues to find the PMD; if the PMD does not exist, calls pmd_alloc() to allocate the PMD page table page, if the PMD exists, continues to find the PTE; if the PTE does not exist, calls pte_alloc() to allocate the PTE page table page and allocates a physical page. The target page table is determined to be the page upper directory, the page intermediate directory and / or the page table entry by this step-by-step page table establishment method.

[0130] The memory allocation method provided by one or more embodiments of the present specification can accurately diagnose the specific location and root cause of the page fault in the page table tree by accurately obtaining and analyzing the page fault exception parameters and using the method of traversing the page table level by level, thereby laying a solid foundation for implementing efficient NUMA-aware page table page allocation. And ensure that the kernel can distinguish whether the exception is caused by the missing intermediate page table pages (such as PUD, PMD) or the final data page, so as to make accurate allocation decisions. This accuracy not only significantly improves the efficiency of handling page faults and reduces unnecessary overhead, but also provides important context information for subsequent forced allocation of required page table pages on the correct NUMA node, thereby avoiding performance loss caused by remote allocation of page table pages and ensuring overall performance optimization and stable low-latency operation of the system under the NUMA architecture.

[0131] After determining that the target page table is a page upper directory, a page intermediate directory, and / or a page table entry, the corresponding page table page can be allocated for the page upper directory, the page intermediate directory, and / or the page table entry in the target memory node. The specific implementation is as follows:

[0132] The step of allocating the page table page for the target page table in the target memory node includes:

[0133] The page table page is allocated for the page upper directory, the page intermediate directory, and / or the page table entry in the target memory node.

[0134] The page upper directory, the page intermediate directory, and the page table entry allocated with the page table page can be understood as different levels in the page table tree structure, which collectively complete the conversion of the virtual address to the physical address.

[0135] The allocation of the page table page for the page upper directory, the page intermediate directory, and / or the page table entry in the target node can be understood as that when the page table tree needs to be expanded, the kernel forces to allocate physical page frames from the target memory node bound to the target process to act on these intermediate directories or page tables.

[0136] The memory allocation method provided by one or more embodiments of the present specification ensures that all levels of the page table tree are located in the local NUMA node, realizes local displacement of the whole address conversion process, eliminates the remote access delay that may occur when the MMU traverses the page table, and ensures the stability of the virtual memory access performance.

[0137] Step 206: In the case where the local memory of the target memory node is insufficient to cause the page table page allocation to fail, the target physical page in the local memory is migrated to a first remote memory node, and the step of allocating the page table page for the target page table in the target memory node is continued to be executed until the page table page allocation is successful.

[0138] The local memory of the target memory node is insufficient, which means that when the kernel allocates a physical page on the specified target memory node, the physical memory allocator of the target memory node finds that there is no enough immediately available physical page that meets the requirements (such as continuity) in its free list. It belongs to an immediate state, and NULL is returned by the memory allocation function to indicate this.

[0139] The page table page allocation fails, which means that the target page table fails to allocate physical memory due to the above-mentioned local memory insufficiency.

[0140] The target physical page can be understood as a user data page on the target memory node that is selected and prepared for migration, including but not limited to a page that is accessed less than a first preset number of times within a first preset time period (i.e., a cold page) and a page that is accessed more than a second preset number of times by the second remote memory node within a second preset time period. The first preset time period, the second preset time period, the first preset number of times, and the second preset number of times can be set according to actual application, and the first preset time period and the second preset time period can be the same or different. For example, the first preset time period can be set to 1 day, the second preset time period can be set to 1 day or 2 days, etc., the first preset number of times can be set to 1, and the second preset number of times can be set to 10, etc. By migrating the cold page or the page frequently accessed by the second remote memory node as the target physical page, the system performance can be significantly improved. First, by migrating the cold page that is not frequently used on the local node, memory space can be released at a small performance cost, thereby creating memory space for the page table page allocation of the target page table and ensuring the efficiency of address translation. Second, pages frequently accessed by the remote node can also be identified and migrated, which pushes these pages closer to their real access nodes, reduces the number of subsequent remote accesses, and reduces the pressure and access delay of the interconnection bus.

[0141] Migration to the first remote memory node means that the kernel migrates the content of the target physical page to a physical page of another remote memory node different from the target memory node, updates the page table entry of all processes that map the virtual address to point to the new physical location, and then releases the old page frame, thereby creating memory space for the target memory node. The first remote memory node can be understood as another NUMA node other than the target memory node, which can be the same as the second remote memory node or different.

[0142] The step of allocating a page table page for the target page table at the target memory node is continuously executed until the page table page allocation succeeds, which can be understood as a loop retry logic, that is, after successfully migrating one or more target physical pages, there is new free memory on the target memory node. At this time, the kernel will again initiate the previously failed memory allocation instruction and continue to attempt to allocate a page table page for the target page table at the target memory node. If the page table page allocation still fails due to insufficient local memory of the target memory node, one or more target physical pages are selected in the local memory, migrated to the first remote memory node, and the retry logic is continuously executed until the page table page allocation for the target page table succeeds, and the entire loop process ends.

[0143] In a specific implementation, the specific implementation logic of the target memory node for allocating a page table page for the target page table is as follows:

[0144] First, in _alloc_pages_nodemask(), the alloc_control structure is first initialized, and then get_pages_from_freelist() is used to traverse the allowed zonelist to apply for memory. At this time, cpusets_enabled&&alloc_flags&ALLOC_CPUSET&&cpu_mems_allowed_nodemask() is used to filter a part of zones that are not expected to be allocated in the zonelist. After the fastpath fails to allocate successfully and enters the slowpath, the nodemask is assigned NULL to broaden the fallback interval.

[0145] _alloc_pages_nodemask() is the core entry function of kernel memory allocation. The alloc_control structure is used to encapsulate all control parameters (such as allocation flags, target node, cpuset limit, recycling state, etc.) of this allocation. The memory allocator selects a zonelist (usually NODE_DATA(nid)->node_zonelists[gfp_mask&GFP_ZONEMASK]) according to gfp_mask and the target node (preferred_nid). Then get_pages_from_freelist() is called to attempt to allocate memory from this zonelist.

[0146] Specifically, in the _alloc_pages_nodemask function, memory allocation follows a hierarchical strategy. The function first prepares allocation parameters by initializing the alloc_control structure, and then enters the fast path, calling the get_pages_from_freelist function to traverse the preset zonelist to attempt to immediately obtain memory. In this process, if the system enables cpuset control and the allocation flag requires to follow this constraint, the kernel will call cpu_mems_allowed_nodemask to filter the zonelist, ensuring that memory allocation is strictly limited to the CPU and memory node set allowed by the process, thus meeting the resource binding requirement. If this fast allocation fails, the function will enter the slow path. At this time, a key measure is to set the nodemask parameter to empty, the purpose of which is to remove the node restriction under the cpuset constraint before, to broaden the fallback interval of memory allocation, allowing the kernel to search for free memory in a wider NUMA node, so as to significantly improve the probability of successful allocation under complex memory pressure.

[0147] In addition, the semantics of __GFP_THISNODE is to force memory allocation in the current numa_node by limiting the allowed zonelist to ZONELIST_NOFALLBACK. At this time, there is no fallback to other numanodes. When the current numanode cannot allocate memory, memory recycling operations are performed, kswapd is awakened and enters __alloc_pages_direct_reclaim() to recycle memory, until __alloc_pages_may_oom() triggers the OOMkiller to terminate the process and reattempt memory allocation.

[0148] Among them, __GFP_THISNODE is a mandatory memory allocation policy flag, and its semantics is "force memory allocation in the current NUMA node".

[0149] With this restriction, the kernel will limit the allowed memory region list (zonelist) to ZONELIST_NOFALLBACK. This means that the search range of the memory allocator is strictly limited within the local NUMA node where the request is initiated, and the memory allocator will no longer perform any form of fallback, i.e. it will not try to allocate memory on other NUMA nodes.

[0150] When the current NUMA node is out of memory, it cannot solve the problem by allocating from other nodes, but will immediately start a series of aggressive operations aimed at releasing memory from the local node:

[0151] Perform memory reclaim: The kernel will wake up the background reclaim thread kswapd and directly enter __alloc_pages_direct_reclaim() to synchronize memory reclaim, trying to clean up enough local memory pages.

[0152] Trigger OOM Killer: If memory reclaim still cannot meet this forced local allocation request, the system will enter the __alloc_pages_may_oom() process and eventually trigger the OOM Killer. The OOM Killer will select a process to terminate, thereby releasing the memory occupied by it (hopefully including the memory of the local node), and then the memory allocator will reattempt to allocate.

[0153] Therefore, in order to achieve the ability of binding cores when allocating page tables, it is necessary to set __GFP_THISNODE when applying for a page table page to ensure the ability of strong binding. In addition, in most scenarios, SWAP space is not configured, which can lead to the situation that the entire machine memory still has remaining while OOM (unable to reclaim more file pages). In the case of setting __GFP_THISNODE and no SWAP space (i.e., swap space), the inactivelist of the current numanode can be migrated to other remaining numanodes to avoid OOM.

[0154] Specifically, in order to fix the physical memory of the page table to the local NUMA node where the CPU core is located, the strong flag __GFP_THISNODE must be used when applying for a page table page. This flag can ensure that the memory allocator only allocates in the current node, thereby achieving the ability of strong binding. Even if the entire server has other NUMA nodes with sufficient free memory, the current bound node can trigger the OOM (out of memory) mechanism due to local memory exhaustion. This is because, in the absence of SWAP, when the node runs out of memory, the kernel's ability to reclaim memory to release space is very limited - especially for many file cache pages that cannot be released. To solve this problem, when the page table page allocation with __GFP_THISNODE fails in the current node and the system has no SWAP space, the inactive cold memory pages (inactive list) on the current node are actively migrated to other remote NUMA nodes with remaining memory. Through this strategy, local memory space is freed on the current node, thereby meeting the mandatory local allocation requirements of the page table page, and ultimately achieving the purpose of avoiding triggering OOM.

[0155] The selection of the first remote memory node can be determined based on the number of node accesses to the target physical page, the water level of other remote memory nodes belonging to the same non-consistent memory access architecture as the target memory node, or a combination of the node's access count and water level. The specific implementation is as follows:

[0156] Before migrating the target physical page in the local memory to the first remote memory node, the method further includes:

[0157] The first remote memory node is determined based on the number of node accesses to the target physical page;

[0158] or

[0159] The first remote memory node is determined based on the number of node accesses to the target physical page and the remaining memory resources of each remote memory node in the non-consistent memory access architecture.

[0160] or

[0161] The first remote memory node is determined based on the remaining memory resources of each remote memory node in the non-consistent memory access architecture.

[0162] The node access count of the target physical page can be understood as the number of times the target physical page is accessed by other NUMA nodes besides the target memory node. Based on this node access count, the primary access NUMA node of the target physical page can be determined, and then this primary access NUMA node can be designated as the first remote memory node. In practice, the kernel samples the access information of the target physical page. After a period of sampling (e.g., 2 or 3 days), the kernel will count which NUMA node's CPU accesses the target physical page most frequently. This NUMA node is then identified as the primary access NUMA node for the target physical page. The target physical page is then migrated to the primary access NUMA node. In this way, subsequent accesses to the target physical page by the primary access NUMA node become local accesses, greatly improving performance. Unlike the method described above, which uses the criterion of "the number of times the target physical page is accessed by the second remote memory node within a second preset time period is greater than a second preset threshold" to determine the target physical page, here the node access count for the target physical page is the node access count with the highest number of node accesses among multiple second remote memory nodes accessing the target physical page; while the method described above uses the sum of the node access counts of multiple second remote memory nodes accessing the target physical page. In other words, the first remote memory node determined using the node access count of the target physical page can be understood as any one of the second remote memory nodes.

[0163] The non-uniform memory access architecture can be understood as the NUMA architecture described above, and the first remote memory node can be understood as any one of the plurality of NUMA nodes, and the second remote memory node can be understood as any one or more of the plurality of NUMA nodes, that is, the target memory node, the first remote memory node, and the second remote memory node all belong to the non-uniform memory access architecture.

[0164] Each remote memory node can be understood as a memory node other than the target memory node in the non-uniform memory access architecture, and the remaining memory resources of each remote memory node can be understood as the free memory of each remote memory node. In actual application, after the main access NUMA node is determined, the memory state of the main access NUMA node needs to be evaluated to determine a more optimal first remote memory node. Specifically, the kernel checks whether the free memory of the main access NUMA node is sufficient (i.e., whether it is higher than the low watermark). If the main access NUMA node is only one and its memory is also very tight, migrating new pages will exacerbate its pressure, and it may trigger recycling immediately. Therefore, if there are multiple main access NUMA nodes, the main access NUMA node with sufficient free memory can be selected as the first remote memory node, and if there is only one main access NUMA node and the memory pressure is too great, the kernel can select a node with less pressure and closer distance / lower delay to the main access NUMA node as the first remote memory node.

[0165] In another scenario, the target physical page can not be frequently accessed by any remote memory node, so in order to ensure that a suitable first remote memory node can be obtained, the kernel can directly determine the first remote memory node according to the free memory of the other remote memory nodes. Specifically, if the target physical page is not frequently accessed by other remote memory nodes or the system lacks access statistics information when starting, at this time, the kernel will degenerate into a global memory balancer, which will check the free memory of all remote NUMA nodes other than the target memory node in the non-uniform memory access architecture, and then migrate the target physical page to the NUMA node with the most free memory, that is, to find a NUMA node with a lower memory level that will not exceed its carrying capacity after receiving migration, as the first remote memory node, which helps to balance the memory usage of the entire system.

[0166] The memory allocation method provided in one or more embodiments of this specification selects the first remote memory node through diversified strategies. It can intelligently select a better migration target based on the real-time system status, thereby significantly improving system performance and resource utilization efficiency. First, it can migrate the target physical page to the primary access NUMA node based on the number of node accesses, reducing subsequent remote access operations, significantly reducing access latency, and alleviating interconnect bus pressure. Second, it can also combine the decision of remaining memory resources to avoid simply migrating the target physical page to a node that is frequently accessed but has low memory, thus preventing the creation of new resource problems while solving a performance problem, ensuring the effectiveness of the migration operation. For cold pages without obvious access preferences, it can provide an efficient and fair migration strategy based on the decision of remaining resources, effectively achieving load balancing of memory resources among different NUMA nodes.

[0167] Furthermore, to avoid resource waste caused by infinite loops, a counter is used to accumulate the number of loop iterations during the loop step of allocating page table pages for the target page table in the target memory node. When the number of iterations becomes too large, the target process can be terminated directly. The specific implementation is as follows:

[0168] After the step of continuing to execute the step of allocating page table pages for the target page table at the target memory node, the method further includes:

[0169] If the number of iterations is greater than or equal to a preset iteration threshold, the target process is terminated.

[0170] That is, the cumulative number of iterations is used to terminate the target process when the number of iterations is greater than or equal to a preset iteration threshold.

[0171] The cumulative iteration count can be understood as the number of times the same "migration-retry" loop is executed, which is recorded and accumulated by the kernel. Each time a migration is triggered due to page table allocation failure and an allocation attempt is made again, it is counted as one iteration.

[0172] The preset iteration threshold can be understood as a pre-defined upper limit on the number of iterations. It limits the maximum allowed number of "migration-retry" loops. If this preset threshold is exceeded, it can be determined that continuing to try will not solve the problem. Specifically, this preset iteration threshold can be set according to the actual application, and no restrictions are imposed here. For example, the preset iteration threshold can be set to 12 or 15 times, etc.

[0173] Terminating the target process can be understood as the kernel calling the OOM Killer (Out of Memory Killer) mechanism to forcibly terminate the target process that triggered this process because the page allocation of its target page table could not be satisfied, in order to release all the resources it occupied.

[0174] Specifically, the kernel accumulates the number of iterations. If the number of iterations is greater than or equal to a preset threshold, it can be determined that continuing to try will not solve the problem. Then, the target process that triggered this process because its target page table's page allocation could not be satisfied is forcibly terminated. By introducing this iteration counting and forced termination mechanism, the system effectively avoids getting stuck in an infinite loop under extreme memory pressure.

[0175] The memory allocation method provided in one or more embodiments of this specification clearly defines the failure boundary by setting a preset iteration threshold, ensuring that system resources are not infinitely consumed by a single unfulfillable request, thereby protecting the normal operation of other unrelated processes and the availability of the entire system. This introduction of iteration counting and forced termination mechanisms can promptly transform insufficient memory signals into explicit error handling actions. On the one hand, by terminating the target process and reclaiming all its occupied memory resources, memory pressure can be alleviated; on the other hand, it facilitates the rapid detection and intervention of resource-related anomalies. Under the premise of strictly adhering to the strong constraints of `cpuset`, the predictability and stability of the system are maintained, preventing large-scale service interruptions that may be caused by local resource shortages.

[0176] The memory allocation method provided in one or more embodiments of this specification first ensures that the page table page is always located on the same NUMA node as the target process accessing it through a mandatory local allocation strategy and a local memory migration mechanism after failure. This eliminates the unpredictable remote latency introduced by page table access across nodes, providing a stable and high-performance foundation for applications that are extremely sensitive to latency, such as AI inference and high-frequency trading. Secondly, it avoids the defect that page table pages cannot be moved after allocation by migrating movable user data pages (target physical pages) to make room for page table pages. This both adheres to the physical constraints of page table pages and achieves the goal of fixing them to the target memory node, avoiding the generation of permanent performance defects. Finally, under the premise of strictly adhering to the cpuset isolation strategy, this method optimizes the local memory within the target memory node through intelligent migration, realizing the migration of "cold" data to make room for "hot" metadata (the page table pages of the target page table). This ensures that frequent access (address translation) always occurs locally, which not only reduces congestion on the interconnect bus but also leaves remote memory bandwidth for data exchange between other projects. Thus, while ensuring inter-process isolation, it improves the overall resource utilization efficiency and performance of the system.

[0177] Corresponding to the above method embodiments, this specification also provides embodiments of a memory allocation device. Figure 3 A schematic diagram of a memory allocation device according to one embodiment of this specification is shown. Figure 3 As shown, this device is applied to a non-uniform memory access architecture and includes:

[0178] The data obtaining module 302 is configured to obtain a resource binding mechanism corresponding to the target process in a case where it is determined to allocate a page table page for a target page table of the target process.

[0179] The memory node determining module 304 is configured to determine a target memory node corresponding to the target process according to a memory node binding constraint in the resource binding mechanism, and allocate a page table page for the target page table in the target memory node.

[0180] The page table page allocating module 306 is configured to, in a case where it is determined that local memory of the target memory node is insufficient to cause the page table page allocation to fail, migrate a target physical page in the local memory to a first remote memory node, and continue to perform the step of allocating a page table page for the target page table in the target memory node until the page table page allocation succeeds.

[0181] Optionally, the memory node determining module 304 is further configured to:

[0182] generate a memory allocation parameter containing a node allocation limit flag for the target memory node, and call a memory allocation function to send the memory allocation parameter to a memory allocator to call the memory allocator to allocate a page table page for the target page table in the target memory node, wherein the memory allocator parses the memory allocation parameter, and in a case where it is determined that the memory allocation parameter contains the node allocation limit flag, allocates a page table page for the target page table in the target memory node according to the node allocation limit flag.

[0183] Optionally, the data obtaining module 302 is further configured to:

[0184] In a case where it is determined that the target process calls a process replacement function to load a new program, allocate a page table page for a target page table of the target process, wherein the target process is a target child process created by a child process creating function for a target parent process, and the new program is a program running in the target process and different from a target program running in the target parent process.

[0185] Optionally, the target page table is a page global directory.

[0186] The memory node determining module 304 is further configured to:

[0187] allocate a page table page for the page global directory in the target memory node.

[0188] Optionally, the data obtaining module 302 is further configured to:

[0189] In response to a page fault exception instruction for the target process, a page table page is allocated for a target page table of the target process, wherein the page fault exception instruction is triggered by a memory management unit in a case that a target virtual address is failed to be resolved, and the target virtual address is a virtual address for memory writing or reading of the target process.

[0190] Optionally, the apparatus further comprises:

[0191] The exception parameter obtaining module is configured to:

[0192] Obtain a page fault exception parameter, wherein the page fault exception parameter comprises the target virtual address and an exception error code generated by the memory management unit.

[0193] According to the target virtual address and the exception error code, the target page table is determined by a step-by-step page table traversal method, wherein the target page table comprises a page upper directory, a page intermediate directory and / or a page table item.

[0194] Optionally, the memory node determining module 304 is further configured to:

[0195] Allocate a page table page for the page upper directory, the page intermediate directory and / or the page table item in the target memory node.

[0196] Optionally, the apparatus further comprises:

[0197] The remote memory node determining module is configured to:

[0198] According to the node access times of the target physical page, the first remote memory node is determined.

[0199] Or

[0200] According to the node access times of the target physical page and the remaining memory resources of each remote memory node in the non-uniform memory access architecture, the first remote memory node is determined.

[0201] Or

[0202] According to the remaining memory resources of each remote memory node in the non-uniform memory access architecture, the first remote memory node is determined.

[0203] Optionally, the apparatus further comprises:

[0204] The process termination module is configured to terminate the target process in a case that the iteration number is greater than or equal to a preset iteration number threshold.

[0205] Optionally, the target physical page includes a page whose access frequency in a first preset time period is less than a first preset frequency threshold, or a page whose access frequency in a second preset time period accessed by the second remote memory node is greater than a second preset frequency threshold.

[0206] Optionally, the target memory node, the first remote memory node, and the second remote memory node all belong to the non-uniform memory access architecture.

[0207] The above is a schematic scheme of the memory allocation apparatus of the embodiment. It should be noted that the technical scheme of the memory allocation apparatus and the technical scheme of the memory allocation method described above belong to the same concept, and the details of the technical scheme of the memory allocation apparatus not described in detail can be referred to the description of the technical scheme of the memory allocation method.

[0208] Corresponding to the memory allocation method embodiment described above, the specification also provides a page table page allocation method embodiment based on the NUMA architecture, which is implemented as follows:

[0209] In a case where page table page allocation is determined for a target page table of a target process, a resource binding mechanism corresponding to the target process is acquired;

[0210] According to a memory node binding constraint in the resource binding mechanism, a target NUMA node corresponding to the target process is determined, and a page table page is allocated to the target page table in the target NUMA node;

[0211] In a case where local memory of the target NUMA node is insufficient to cause the page table page allocation to fail, target physical pages in the local memory are migrated to a first remote NUMA node, and the step of allocating a page table page to the target page table in the target NUMA node is continued to be executed until the page table page allocation succeeds.

[0212] The above is a schematic scheme of the page table page allocation method based on the NUMA architecture of the embodiment. It should be noted that the technical scheme of the page table page allocation method based on the NUMA architecture and the technical scheme of the memory allocation method described above belong to the same concept, and the details of the technical scheme of the page table page allocation method based on the NUMA architecture not described in detail can be referred to the description of the technical scheme of the memory allocation method.

[0213] Figure 4 A structural block diagram of a computing device according to an embodiment of the specification is shown. The components of the computing device 400 include but are not limited to a memory 410 and a processor 420. The processor 420 is connected with the memory 410 through a bus 430, and a database 450 is used to save data.

[0214] The computing device 400 also includes an access device 440 that enables the computing device 400 to communicate via one or more networks 460. Examples of such networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or combinations of such networks, such as the Internet. The access device 440 can include one or more of any type of network interface (for example, a network interface card (NIC)) such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC).

[0215] In one embodiment of the present specification, the above-mentioned components of the computing device 400 and other components not shown in the Figure 4 may be connected to each other, for example, through a bus. It should be understood that Figure 4 The computing device structure diagram shown is only for the purpose of example, and is not a limitation on the scope of the present specification. Those skilled in the art can add or replace other components as needed.

[0216] The computing device 400 can be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (for example, a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, and the like), a mobile phone (for example, a smartphone), a wearable computing device (for example, a smart watch, smart glasses, and the like), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 400 can also be a mobile or stationary server.

[0217] The processor 420 is configured to execute computer-executable instructions, which, when executed by the processor, implement the steps of the above-mentioned memory allocation method or the page table page allocation method based on the NUMA architecture.

[0218] The above is a schematic scheme of the computing device of the embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the memory allocation method or the page table page allocation method based on the NUMA architecture belong to the same concept, and details of the technical scheme of the computing device that are not described in detail can be referred to the description of the technical scheme of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0219] An embodiment of the present specification further provides a computer readable storage medium storing computer programs / instructions, which, when executed by a processor, implement the steps of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0220] The above is a schematic scheme of the computer readable storage medium of the embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the memory allocation method or the page table page allocation method based on the NUMA architecture belong to the same concept, and details of the technical scheme of the storage medium that are not described in detail can be referred to the description of the technical scheme of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0221] An embodiment of the present specification further provides a computer program product comprising computer programs / instructions, which, when executed by a processor, implement the steps of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0222] The above is a schematic scheme of the computer program product of the embodiment. It should be noted that the technical scheme of the computer program product and the technical scheme of the memory allocation method or the page table page allocation method based on the NUMA architecture belong to the same concept, and details of the technical scheme of the computer program product that are not described in detail can be referred to the description of the technical scheme of the memory allocation method or the page table page allocation method based on the NUMA architecture.

[0223] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the acts or steps recited in the claims can be performed in a different order than the order in which they are recited and still achieve desirable results. In addition, the processes depicted in the figures do not necessarily require the particular order shown, or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.

[0224] The computer program / instructions can include a computer program code, which can be in a form of source code, object code, executable file, or some intermediate form etc. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier signal, telecommunication signal, software distribution medium, etc. It should be noted that the computer readable medium can include appropriate contents according to the requirements of patent practice, for example, according to the patent practice in some regions, the computer readable medium does not include electrical carrier signals and telecommunication signals.

[0225] It should be noted that, for the foregoing method embodiments, in order to facilitate description, they are all described as a combination of a series of actions, but those skilled in the art should know that the embodiments of the present specification are not limited by the order of the described actions, because according to the embodiments of the present specification, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments of the present specification.

[0226] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.

[0227] The preferred embodiments of the present specification disclosed above are only used to help explain the present specification. The alternative embodiments do not describe all the details and limit the invention to the specific embodiments described. Obviously, according to the content of the embodiments of the present specification, many modifications and changes can be made. The present specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of the present specification, so that those skilled in the art can well understand and use the present specification. The present specification is limited by the claims and their entire scope and equivalents.

Claims

1. A memory allocation method applied to a non-consistent memory access architecture, comprising: If page table allocation is performed for the target page table of the target process, the resource binding mechanism corresponding to the target process is obtained; Based on the memory node binding constraints in the resource binding mechanism, the target memory node corresponding to the target process is determined, and by setting a node allocation restriction flag, page table pages are forced to be allocated for the target page table from the target memory node. The target memory node is uniquely determined according to the memory node binding constraints in the resource binding mechanism, and the node allocation restriction flag is used to prohibit the memory allocator from allocating page table pages for the target page table from memory nodes other than the target memory node. If it is determined that the page table allocation fails due to insufficient local memory of the target memory node, the target physical page in the local memory is migrated to the first remote memory node, and the step of allocating page table pages for the target page table on the target memory node continues until the page table allocation is successful, wherein the target physical page is a movable user data page.

2. The memory allocation method according to claim 1, wherein the step of forcing the allocation of page table pages for the target page table in the target memory node by setting a node allocation restriction flag includes: A memory allocation parameter containing a node allocation restriction flag for the target memory node is generated, and a memory allocation function is called to send the memory allocation parameter to the memory allocator, so as to call the memory allocator to force the allocation of page table pages for the target page table on the target memory node. The memory allocator parses the memory allocation parameter, and if it determines that the memory allocation parameter includes the node allocation restriction flag, it forces the allocation of page table pages for the target page table on the target memory node according to the node allocation restriction flag.

3. The memory allocation method according to claim 1, wherein determining the target page table of the target process and performing page table allocation includes: If it is determined that the target process calls the process replacement function to load a new program, page table allocation is performed for the target page table of the target process. The target process is a target child process created for the target parent process through the child process creation function, and the new program is a program running in the target process that is different from the target program running in the target parent process.

4. The memory allocation method according to claim 3, wherein the target page table is a page global directory; The step of allocating page table pages for the target page table in the target memory node includes: Page table pages are allocated for the page global directory in the target memory node.

5. The memory allocation method according to claim 1, wherein determining the target page table of the target process and performing page table allocation includes: In response to a page fault instruction for the target process, page table allocation is performed for the target page table of the target process, wherein the page fault instruction is triggered by the memory management unit when it fails to resolve the target virtual address, and the target virtual address is the virtual address for which the target process performs memory write or read.

6. The memory allocation method according to claim 5 further includes: Obtain page fault parameters, wherein the page fault parameters include the target virtual address and the exception error code generated by the memory management unit; Based on the target virtual address and the error code, the target page table is determined by a step-by-step page table traversal method, wherein the target page table includes the page parent directory, the page intermediate directory, and / or page table entries.

7. The memory allocation method according to claim 6, wherein allocating page table pages for the target page table in the target memory node comprises: Page table pages are allocated for the page parent directory, page intermediate directory, and / or page table entries in the target memory node.

8. The memory allocation method according to any one of claims 1-7, further comprising, before migrating the target physical page in the local memory to the first remote memory node: The first remote memory node is determined based on the number of node accesses to the target physical page; or The first remote memory node is determined based on the number of node accesses to the target physical page and the remaining memory resources of each remote memory node in the non-consistent memory access architecture. or The first remote memory node is determined based on the remaining memory resources of each remote memory node in the non-consistent memory access architecture.

9. The memory allocation method according to any one of claims 1-7, further comprising, after the step of continuing to perform the step of allocating page table pages for the target page table at the target memory node: If the number of iterations is greater than or equal to a preset iteration threshold, the target process is terminated.

10. The memory allocation method according to any one of claims 1-7, wherein the target physical page includes a page whose access count is less than a first preset threshold within a first preset time period, and a page whose access count by a second remote memory node is greater than a second preset threshold within a second preset time period.

11. The memory allocation method according to claim 10, wherein the target memory node, the first remote memory node, and the second remote memory node all belong to the non-consistent memory access architecture.

12. A memory allocation device applied to a non-uniform memory access architecture, comprising: The data acquisition module is configured to acquire the resource binding mechanism corresponding to the target process when page table allocation is performed on the target page table of the target process. The memory node determination module is configured to determine the target memory node corresponding to the target process according to the memory node binding constraints in the resource binding mechanism, and to force the allocation of page table pages for the target page table from the target memory node by setting a node allocation restriction flag. The target memory node is uniquely determined according to the memory node binding constraints in the resource binding mechanism, and the node allocation restriction flag is used to prohibit the memory allocator from allocating page table pages for the target page table from memory nodes other than the target memory node. The page table allocation module is configured to, when it is determined that the local memory of the target memory node is insufficient, causing the page table allocation to fail, migrate the target physical page in the local memory to a first remote memory node, and continue to execute the step of allocating page table pages for the target page table on the target memory node until the page table allocation is successful, wherein the target physical page is a movable user data page.

13. A computing device, comprising: A memory and a processor, the memory and the processor being connected via a bus; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions, which, when executed by the processor, implement the steps of the memory allocation method according to any one of claims 1 to 11.

14. A computer-readable storage medium storing a computer program / instructions that, when executed by a processor, implement the steps of the memory allocation method according to any one of claims 1 to 11.

15. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the memory allocation method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Page placement method and device, electronic equipment, storage medium and program product

    CN119336506A

  • Layered memory page allocation method based on process virtual address space segmentation

    CN120029935A