Memory resource allocation method, device, electronic device, medium and product
By calling memory resources once in user-mode operations and adopting multi-level resource pools and page table management, the problem of high overhead caused by frequent kernel calls in memory resource allocation is solved, efficient and accurate memory resource allocation is achieved, and the needs of different business scenarios are adapted.
Patent Information
- Application Number
- CN202510897273.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-30
- Publication Date
- 2025-09-05
- Estimated Expiration
- 2045-06-30
AI Technical Summary
In the existing technology, the memory resource allocation process requires frequent calls to the system kernel, resulting in high overhead, especially throughput collapse in multi-threaded high-concurrency scenarios, and it is impossible to dynamically route memory resource requests according to the business characteristics of the module.
Transfer the allocation of memory resources to user-state operations, call memory resources at one time through the user-state sub-resource pool, reduce the involvement of the system kernel, and use multi-level resource pools and multi-level page tables to manage memory resources to adapt to the memory requirements of different business scenarios.
It reduces kernel overhead, improves the accuracy and efficiency of memory resource allocation, adapts to the needs of heterogeneous memory media, and improves system throughput and resource utilization.
Smart Images

Figure CN120407201B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory management technology, and in particular to methods, devices, electronic devices, media, and products for allocating memory resources. Background Art
[0002] With the rapid development of devices such as computers and servers, the scale of data has increased dramatically, which has put higher demands on memory. The modules of the device apply for memory resources according to actual usage needs. The system allocates corresponding memory resources to the modules based on the modules' requests and returns the memory resources after the modules have finished using the memory resources.
[0003] However, this approach requires the system kernel to frequently call memory resources, which results in high overhead. Summary of the Invention
[0004] The present application provides a method, device, electronic device, medium and product for allocating memory resources to at least solve the problem of high overhead in allocating memory resources in related technologies.
[0005] The present application provides a method for allocating memory resources, comprising: receiving a memory resource request sent by a target module, the memory resource request including a target memory capacity, a target memory attribute, and a target memory unit; determining, based on the memory resource request, a target memory management module corresponding to the target memory attribute; determining, through the target memory management module, a target memory resource corresponding to the target memory capacity from a user-state sub-resource pool corresponding to the target memory unit, wherein the memory resources in the user-state sub-resource pool are obtained by a one-time call during the initialization process of the user-state sub-resource pool; and allocating the target memory resource to the target module.
[0006] The present application also provides a memory resource allocation device, including: a receiving module, used to receive a memory resource request sent by a target module, the memory resource request including a target memory capacity, a target memory attribute, and a target memory unit; a determination module, used to determine a target memory management module corresponding to the target memory attribute based on the memory resource request; an acquisition module, used to determine, through the target memory management module, a target memory resource corresponding to the target memory capacity from a user-state sub-resource pool corresponding to the target memory unit, the memory resources in the user-state sub-resource pool being obtained by a one-time call during the initialization process of the user-state sub-resource pool; and an allocation module, used to allocate the target memory resource to the target module.
[0007] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned memory resource allocation methods when executing the computer program.
[0008] The present application also provides a non-volatile computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned memory resource allocation methods are implemented.
[0009] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned memory resource allocation methods when executed by a processor.
[0010] Through this application, sufficient memory resources are called at one time when the resource pool is initialized. When memory resources are allocated to modules, they are executed through user-mode operations without the participation of the kernel, thereby reducing kernel overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0012] Figure 1 A schematic diagram of an application scenario of a memory resource allocation method provided in an embodiment of the present application;
[0013] Figure 2 A flowchart of a method for allocating memory resources provided in an embodiment of the present application;
[0014] Figure 3 A flowchart of a method for allocating memory resources provided in an embodiment of the present application;
[0015] Figure 4 A schematic diagram of a memory management module provided in an embodiment of the present application;
[0016] Figure 5 A schematic diagram of a multi-level resource pool provided in an embodiment of the present application;
[0017] Figure 6 A schematic diagram of a multi-level page table provided in an embodiment of the present application;
[0018] Figure 7 A schematic diagram of the structure of a memory resource allocation device provided in an embodiment of the present application;
[0019] Figure 8 A schematic diagram of the structure of a memory resource allocation device provided in an embodiment of the present application;
[0020] Figure 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0021] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0022] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0023] In the field of memory management technology, how to efficiently manage memory resources is a current challenge. On the one hand, emerging interconnection technologies promote the expansion of memory resource pools, allowing the system to access memory capacity far beyond local physical limitations; on the other hand, the performance of storage devices continues to improve, and the gap between their input and output processing capabilities and memory management efficiency is becoming increasingly sharp. As temporary storage, memory has the characteristics of high-speed reading and writing, which can effectively improve the working efficiency of devices such as computers or servers. The module of the device applies for memory resources from the system according to the actual working system, and returns the memory resources to the system after use. The memory resources returned to the system can be applied by any device, thereby realizing a reasonable allocation and use mechanism of memory resources.
[0024] In related technologies, storage software requests memory through functions (such as malloc). This process passes through the operating system kernel, where memory resources are allocated. This presents the following problems: a lengthy path bottleneck. Each memory resource request from a user-mode module must cross the kernel protection boundary, triggering a context switch and privilege level check. In multi-threaded, high-concurrency scenarios, this switching loss amplifies exponentially, creating a throughput collapse zone. There is also a misalignment of abstraction levels. The kernel's byte-level allocation model, designed for processor paging requirements, suffers from a fundamental impedance mismatch with the physical block-based access model of storage devices. This mismatch forces storage systems to implement an additional adapter layer in user mode, resulting in redundant processing links. Furthermore, there are resource scheduling blind spots. The system lacks native awareness of heterogeneous memory media (such as high-speed, low-capacity memory or low-speed, high-capacity memory), making it impossible to dynamically route memory resource requests based on the module's business characteristics.
[0025] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0026] In conjunction with the specific application environment architecture or specific hardware architecture on which the execution of the memory resource allocation method depends, the specific application environment architecture or specific hardware architecture is described here. Figure 1 , Figure 1 This is a diagram of an application scenario for memory resource allocation. The target module initiates a memory resource request based on the memory resource requirements of the work process. Based on the memory resource request, the corresponding memory resources are requested from the resource pool and allocated to the target module.
[0027] Combined with the scenario example, during the operation of the target module, when the memory resources of the device where the target module is located are insufficient, the target module initiates a memory resource request, obtains the allocated memory resources through the memory resource request, and realizes the normal operation of the target module through its own memory resources and the allocated memory resources.
[0028] In related technologies, memory resources are allocated through the system's kernel. When multiple modules frequently request memory resources, the kernel needs to frequently allocate memory resources, resulting in a high kernel overhead.
[0029] Based on the above technical problems, the solution of this application is to transfer the allocation of memory resources to user-mode operations, reduce system memory operations, and thus reduce kernel overhead.
[0030] Figure 2 A flow chart of a method for allocating memory resources provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, an embodiment of the present application provides a method for allocating memory resources, which is described in detail as follows:
[0031] S201. Receive a memory resource request sent by a target module, where the memory resource request includes a target memory capacity, a target memory attribute, and a target memory unit.
[0032] Exemplarily, the target module is a module that requires memory resources, and the memory resource request is used to trigger the allocation of memory resources so that the target module has sufficient memory resources to store data.
[0033] Exemplarily, the target memory capacity is the size of the memory resources required by the target module, and the memory resources that meet the target memory capacity are sufficient for the target module to use.
[0034] Exemplarily, the target memory attribute is the target module's requirement for memory resource attributes, such as low latency, high bandwidth, stability, or large capacity, etc. The target memory attribute is determined according to the business scenario of the target module.
[0035] Exemplarily, the target memory unit is the smallest unit of memory resources required by the target module, such as a 4KB page or a 32KB input / output block, etc. Target memory units differ in granularity and are suitable for different business scenarios.
[0036] Combined with the scenario example, the memory resource request includes multiple types of requirements. The memory resources allocated to the target module through multiple types of requirements can effectively adapt to the business scenario of the target module, thereby improving the accuracy of memory resource allocation.
[0037] S202: Determine a target memory management module corresponding to the target memory attribute according to the memory resource request.
[0038] Exemplarily, the target memory management module is a user-mode management module configured to manage memory resources corresponding to the target memory attributes. The memory resources corresponding to the target memory attributes are memory resources that meet the requirements of the target module.
[0039] For example, different memory resources are managed by corresponding memory management modules according to their attributes. When allocating memory resources, the corresponding memory management modules allocate memory resources so that the actually allocated memory resources meet the requirements of the target module.
[0040] Based on the above implementation methods, grouping and managing memory resources can adapt the allocated resources to the business scenarios of the target modules, thereby improving the accuracy of memory resource allocation.
[0041] S203. Determine, through the target memory management module, target memory resources corresponding to the target memory capacity from the user-state sub-resource pool corresponding to the target memory unit. The memory resources in the user-state sub-resource pool are obtained by a one-time call during the initialization of the user-state sub-resource pool.
[0042] For example, during the initialization of the user-mode sub-resource pool, sufficient memory resources are allocated to the user-mode sub-resource pool at once. When a target module requests memory resources, memory resources are allocated to the target module from the user-mode sub-resource pool via user-mode operations without kernel involvement, thereby reducing kernel operations.
[0043] Exemplarily, the memory resources in the user-mode sub-resource pool corresponding to the target memory unit all use the target memory unit as the minimum unit. For example, if the target memory unit is a 4KB page, the minimum unit of the memory resources in the corresponding user-mode sub-resource pool is a 4KB page.
[0044] For example, the total size of memory resources required by the target module can be determined based on the target memory capacity, and memory resources are obtained from the user-mode sub-resource pool until the obtained memory resources reach the required total size, thereby obtaining the target memory resources. That is, the total size of the target memory resources is the target memory capacity.
[0045] Based on the above implementation, the kernel layer participates in the process of initializing the user-mode sub-resource pool, and the kernel does not need to participate in the process of allocating memory resources to the target module after initialization, thereby effectively reducing kernel overhead.
[0046] S204: Allocate target memory resources to the target module.
[0047] Exemplarily, the target memory resources obtained from the user-mode sub-resource pool through user-mode operations meet the needs of the target module, and the target memory resources are allocated to the target module so that the target module uses the target memory resources to complete the work of the target module.
[0048] The memory resource allocation method provided in the embodiment of the present application receives a memory resource request sent by a target module, the memory resource request includes a target memory capacity, a target memory attribute, and a target memory unit; according to the memory resource request, determines a target memory management module corresponding to the target memory attribute; through the target memory management module, determines the target memory resource corresponding to the target memory capacity from the user-state sub-resource pool corresponding to the target memory unit, the memory resource in the user-state sub-resource pool is obtained by a one-time call during the initialization process of the user-state sub-resource pool; and allocates the target memory resource to the target module. The above scheme calls enough memory resources at one time when initializing the resource pool, and when allocating memory resources to the module, it is executed through user-state operations without the participation of the kernel, thereby reducing the kernel's overhead.
[0049] Based on any of the above embodiments, Figure 3 , which explains the detailed process of memory resource allocation method.
[0050] Figure 3 A flow chart of a memory resource allocation method provided in an embodiment of the present application. Figure 3 As shown, the method includes:
[0051] S301: Receive a memory resource request sent by a target module, where the memory resource request includes a target memory capacity, a target memory attribute, and a target memory unit.
[0052] It should be noted that the execution process of S301 refers to S201 and will not be repeated here.
[0053] S302: Determine a corresponding target memory type according to a target memory attribute, where the target memory type is dynamic random access memory or computationally fast access memory.
[0054] For example, dynamic random access memory (DRAM) connects to processors (such as CPUs) through direct memory channels. Signals don't require protocol conversion, and current flows directly to the memory cells, resulting in low latency. Compute Express Link (CXL) memory decouples memory modules from the host's channels, allowing for independent hardware expansion without the host, resulting in high capacity.
[0055] Combined with the scenario example, the target memory attribute of the target module reflects the target module's requirements for memory attributes, and the memory resources of the target memory type can meet the requirements of the target module.
[0056] S303: Determine a target memory management module according to the target memory type, where the target memory management module is used to manage a resource pool of dynamic random access memory or a resource pool of computing fast connection memory.
[0057] Next, combine Figure 4 Describe the memory management module.
[0058] Figure 4 This is a schematic diagram of the memory management module provided in the embodiment of the present application. Figure 4 As shown, multiple memory management modules and multiple resource pools are pre-configured, each resource pool stores a dynamic random access memory or a computing fast connection memory, and each resource pool is managed by a corresponding memory management module.
[0059] In conjunction with the scenario example, if the target memory type is dynamic random access memory, the memory management module corresponding to the resource pool corresponding to the dynamic random access memory is determined as the target memory management module.
[0060] Based on the above implementation, different types of memory are decoupled and stored in different resource pools, respectively. When allocating memory resources, matching memory resources can be accurately allocated to the target module, thereby improving the accuracy of memory resource allocation.
[0061] S304: Determine the available resource amount of the user-mode sub-resource pool.
[0062] Optionally, the memory resources in the user-mode sub-resource pool can be allocated to one module or multiple modules. The available resource amount is used to ensure that the memory resources currently allocated to the target module meet the requirements of the target module.
[0063] For example, during the initialization process, initial memory resources are allocated to the user-state sub-resource pool. After memory resources are allocated to the target module or other modules, the amount of memory resources in the user-state sub-resource pool decreases accordingly. The available resource amount is the size of the remaining memory resources in the user-state sub-resource pool.
[0064] In a feasible implementation method, the memory resource allocation method may also include: determining the memory resource quota of the user-state sub-resource pool based on the total memory resource of the root resource pool; determining the initial memory resource from the upper-level resource pool based on the memory resource quota, and allocating the initial memory resource to the user-state sub-resource pool.
[0065] For example, the root resource pool is the master pool for managing memory resources. Before initializing sub-resource pools, all memory resources are stored in the root resource pool. The memory resource quota is the amount of memory allocated to each sub-resource pool. During initialization, the corresponding memory resources are allocated to the sub-resource pools based on the quota.
[0066] Optionally, the quota of each sub-resource pool is determined based on the memory resource requirements of the modules corresponding to each sub-resource pool. For example, if the module corresponding to any sub-resource pool has a greater memory resource requirement, the corresponding quota is larger.
[0067] In this feasible implementation, by allocating initial memory resources based on the device quota in advance, it is possible to avoid competition among multiple sub-resource pools for memory resources during initialization, thereby reducing initialization efficiency and improving initialization efficiency.
[0068] In a feasible implementation method, the memory resource allocation method may also include: determining the resource allocation record of the user-state sub-resource pool, the resource allocation record including the number of times the available resources of the user-state sub-resource pool are insufficient; if the number is greater than or equal to the first number threshold, adjusting the quota of the user-state sub-resource pool.
[0069] Exemplarily, the resource allocation record of the user-state sub-resource pool is the resource allocation record of the user-state sub-resource pool after historical initialization before the current initialization. The resource pool initialization can be re-executed according to the change of usage scenario. After each initialization, the resource allocation record of the user-state sub-resource pool is recorded.
[0070] Combined with the scenario example, if the number of times is greater than or equal to the first count threshold, it means that the quota of the user-state sub-resource pool is small, and the memory resources allocated according to the quota cannot meet the memory resource requirements of the module corresponding to the user-state sub-resource pool. In this case, the quota should be adaptively increased to allocate more memory resources to the user-state sub-resource pool during this initialization.
[0071] Optionally, if the historical initial memory resources of the user-state sub-resource pool are excessive, the quota of the user-state sub-resource pool is adaptively reduced.
[0072] In this feasible implementation, by dynamically adjusting quotas, appropriate initial memory resources can be accurately allocated to multiple sub-resource pools, thereby improving the accuracy of memory resource allocation.
[0073] S305: Determine whether the target memory capacity is less than or equal to the available resource amount.
[0074] Exemplarily, the target memory capacity is the memory capacity required by the target module, and the available resource amount is the remaining memory capacity in the user-state sub-resource pool. By comparison, it can be determined whether the size of the memory resources in the user-state sub-resource pool can meet the requirements of the target module.
[0075] S306: If yes, determine the target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool.
[0076] Exemplarily, when the target memory capacity is less than or equal to the available resource amount, it indicates that the size of the memory resources in the user-state sub-resource pool can meet the requirements of the target module, and the memory resources required by the target module are obtained from the user-state sub-resource pool as the target memory resources.
[0077] S307: If not, determine temporary memory resources from the upper-level resource pool of the user-state sub-resource pool, allocate the temporary memory resources to the user-state sub-resource pool, and determine target memory resources corresponding to the target memory capacity from the user-state sub-resource pool.
[0078] It should be noted that this application does not limit the execution order of S306 and S307.
[0079] For example, when the target memory capacity is greater than the available resources, it means that the size of the memory resources in the user-mode sub-resource pool cannot meet the needs of the target module. If allocation is still performed, insufficient memory resources will be allocated, affecting the normal operation of the target module.
[0080] For example, each resource pool has a different initial memory resource size, and the amount of available memory resources in each resource pool varies at different times. This may lead to an imbalance where some resource pools have too much available memory resources while others have insufficient available memory resources. By managing memory resources through multi-level resource pools, memory resources from multiple resource pools can be coordinated to balance the available memory resources in multiple resource pools, thereby avoiding idle or insufficient memory resources and improving the accuracy of memory resource allocation.
[0081] Next, combine Figure 5 Describe multi-level resource pools.
[0082] Figure 5 Schematic diagram of a multi-level resource pool provided in an embodiment of the present application. Figure 5 As shown, a multi-level resource pool consists of a root resource pool and multiple sub-resource pools. Memory resources in a sub-resource pool are allocated from the upper-level resource pool. A sub-resource pool can obtain temporary resources from the upper-level resource pool and return them to the upper-level resource pool after use.
[0083] In this feasible implementation, by managing memory resources through multi-level resource pools, the available resources in multiple resource pools can be balanced, thereby improving the accuracy of memory resource allocation.
[0084] In a feasible implementation, the memory resource allocation method further includes: determining the usage status of the temporary memory resource, which is either in use or completed; if the usage status is completed, sending the temporary memory resource to the upper-level resource pool.
[0085] Optionally, there can be multiple resource pools under the upper-level resource pool.
[0086] Exemplarily, a usage status of "in use" indicates that the temporary memory resource has been allocated to the module, and a usage status of "use completed" indicates that the temporary memory resource has not been allocated to the module.
[0087] In this scenario, temporary memory resources are borrowed by a user-level sub-resource pool from a higher-level resource pool. A higher-level resource pool can provide temporary memory resources to multiple lower-level resource pools. If a user-level sub-resource pool occupies temporary memory resources for a long time, other resource pools at the same level may be unable to obtain temporary memory resources from the higher-level resource pool.
[0088] Based on this, when the memory resource size of the user-state sub-resource pool is sufficient, the temporary memory resources are returned to the upper-level resource pool, which can effectively coordinate other resource pools without affecting the use of the user-state sub-resource pool.
[0089] In this feasible implementation, temporary memory resources are returned to the upper-level resource pool according to their usage status, realizing dynamic coordination of temporary memory resources and ensuring that multiple resource pools can effectively allocate resources to modules, thereby improving the reliability of memory resource management.
[0090] A feasible implementation method is that the memory resource request also includes a target page number, and the target memory unit is a memory page; the target memory resource corresponding to the target memory capacity can be determined from the user-state sub-resource pool corresponding to the target memory unit by the following method, including: determining a multi-level page table from the page table area of the user-state sub-resource pool, the multi-level page table is used to locate the memory page, and the multi-level page table includes a second-level page table; determining the starting address of the second-level page table; according to the target page number, determining the offset of the address of the target pointer corresponding to the target page number relative to the starting address; according to the offset, obtaining the target pointer in the second-level page table; determining the target memory page pointed to by the target pointer from the user-state sub-resource pool, and determining the target memory page as the target memory resource.
[0091] For example, let's take the scenario where the target memory unit is a memory page. The physical read and write unit of the solid-state drive is 4KB. Using a larger memory block will result in read and write amplification (for example, writing 32KB only requires modifying 4KB, and the entire block still needs to be written). When the storage system caches a 4KB solid-state drive data block, directly allocating 4KB memory pages can avoid redundant copies. Applicable operations: random small file reading and writing (such as database index updates), non-continuous memory access scenarios. Pages with a 4KB granularity provide more flexible memory allocation, avoiding fragmentation and waste caused by allocating large blocks of memory. Applicable scenarios: operations that require low-latency DRAM acceleration (such as metadata operations) and tasks with high real-time requirements (such as transaction log writing) can allocate 4KB memory pages for fast response and reduced waiting time.
[0092] Exemplarily, the target memory unit is a memory page, indicating that the minimum unit of memory resources required by the target module is a memory page, and the target page number is used to indicate the location of the memory page specified by the target module.
[0093] Exemplarily, the multi-level page table is used to manage multiple memory pages, including managing the storage location of each memory page, the properties of each memory page, or the idle state of each memory page.
[0094] Exemplarily, the second-level page table includes multiple secondary page table entries, each secondary page table entry points to a physical memory page, and the multiple secondary page table entries are arranged in sequence. The starting address of the second-level page table is the address of the first secondary page table entry among the multiple secondary page table entries.
[0095] Next, combine Figure 6 Describe the multi-level page table.
[0096] Figure 6 Schematic diagram of a multi-level page table provided in an embodiment of the present application. Figure 6As shown, different levels of the multi-level page table are pointed to by pd pointers, each of which is 8 bytes in size. The first-level page table contains 256 first-level page table entries, each of which contains 512 pds. The total size of each first-level page table entry is 512 × 8 bytes = 4KB. Each pd in the first-level page table points to a second-level page table entry in the second-level page table. The number of pds in the first-level page table is 256 × 512 = 128K, so the number of second-level page table entries is 128K. Each second-level page table entry contains 4K pds, so the total size of each second-level page table entry is 4K × 8 bytes = 32KB. Each pd in the second-level page table points to a memory page. The number of pds in the second-level page table is 128K × 4K = 512MB, so the number of memory pages is 512MB. Calculating the multi-level page tables separately, the total space occupied by the first-level page table is 128K×8Bytes=1MB, the total space occupied by the second-level page table is 128K×32KB=4GB, and the total space occupied by the memory page is 512MB×4KB=2TB. It should be noted that the values in this embodiment are only for example, and this application is not limited to specific values.
[0097] For example, in a second-level page table, multiple secondary page table entries are arranged sequentially. The pd pointers in each secondary page table entry are arranged consecutively. Each pointer has a fixed size. Therefore, the target page number corresponding to the target pointer can accurately determine the offset of the target pointer relative to the starting address. For example, the offset between the fifth pointer and the first pointer is (5-1) × 8 bytes = 32 bytes.
[0098] Exemplarily, each pointer uniquely points to a memory page. Once the target pointer is determined, the target memory resource pointed to by the target pointer can be determined.
[0099] In this feasible implementation, through the multi-level page table, the address of the memory page can be directly accessed by the user-mode process bypassing the kernel, thereby reducing the kernel overhead.
[0100] A feasible implementation method can obtain the target pointer according to the offset by the following method, including: determining the target address of the target pointer in the second-level page table according to the starting address and the offset; and obtaining the target pointer from the target address.
[0101] Exemplarily, after the starting address and the offset are determined, the sum of the starting address and the offset is determined as the target address.
[0102] Exemplarily, the target address addressing process is an operation performed in user mode and does not require the participation of the kernel, which can effectively reduce the kernel overhead.
[0103] In this feasible implementation, the offset of the target pointer relative to the initial address is accurately determined by the offset, so that the target pointer is accurately obtained from the user-mode process without using the kernel, thereby improving the accuracy of memory resource allocation.
[0104] In a feasible implementation, the memory resource allocation method may further include: removing the target memory page from the free page area of the user-mode sub-resource pool; and adding the target memory page to the general memory area of the user-mode sub-resource pool.
[0105] Exemplarily, the memory resources in the user-mode sub-resource pool are managed through different areas, wherein the memory pages in the free page area are unallocated memory pages, and the memory pages in the general memory area are allocated memory pages.
[0106] Combined with the scenario example, the free page area and the general memory area can be used to accurately distinguish whether the memory page has been allocated to the module, which can avoid conflicts when allocating memory pages.
[0107] In this feasible implementation, conflicts when allocating memory pages are avoided by using the free page area and the general memory area, thereby improving the accuracy of memory resource allocation.
[0108] A feasible implementation method is that the multi-level page table also includes a first-level page table, the first-level page table includes multiple first-level page table entries, each first-level page table entry includes multiple first-level pointers, each first-level pointer points to the corresponding second-level page table entry in the second-level page table, wherein each second-level page table entry includes multiple second-level pointers.
[0109] For example, the first-level page table pre-fixes the base address of the second-level page table (level2_memorytable). Subsequent accesses can quickly locate the memory page directly through the base address + offset (ptr + p). This eliminates the overhead of dynamically querying the first-level page table at runtime, reducing the address translation complexity from O(level depth) to O(1).
[0110] For example, during the initialization phase, the first-level page table is used to uniformly plan the layout of the second-level page table, ensuring that all second-level page table entries are stored contiguously and avoiding memory fragmentation. User mode can manage all memory using the level2_memorytable base address without having to worry about the underlying page table layout. This reduces code complexity and reduces the number of dynamic page table allocation and deallocation operations.
[0111] Optionally, the first-level page table can be used to restrict access rights to the second-level page table (e.g., read-only or non-executable) to prevent malicious code from tampering with memory mappings. This isolates user-mode and kernel-mode memory management logic to prevent cross-boundary access. Supports memory isolation in multi-tenant scenarios (e.g., allocating independent second-level page table areas to different modules).
[0112] Optionally, the first-level page table allocates independent second-level page table areas for different modules, combined with a tree-structured memory pool to implement quota isolation. This prevents a single module from exhausting global memory resources (for example, CXL resource pools and DRAM resource pools are managed independently). Multi-level resource pools enable flexible resource borrowing and improve resource utilization.
[0113] In this feasible implementation, the first-level page table manages the lower-level second-level page table, which can accurately locate the target memory page and directly access the address of the memory page through the user-mode process bypassing the kernel, thereby reducing kernel overhead.
[0114] A feasible implementation method is that the target memory unit is an input / output block. The target memory resource corresponding to the target memory capacity can be determined from the user-state sub-resource pool corresponding to the target memory unit by the following method, including: determining a free linked list from the input / output block area of the user-state sub-resource pool, and determining multiple candidate input / output blocks through the free linked list, each candidate input / output block including multiple memory pages; determining multiple status bitmaps from the multiple candidate input / output blocks determined from the input / output block area, each status bitmap representing the idle status of multiple memory pages in the corresponding candidate input / output block; determining a target input / output block from the multiple candidate input / output blocks based on the multiple status bitmaps, determining the target input / output block as the target memory resource, and the idle status in the status bitmap corresponding to the target input / output block are all idle.
[0115] As an example, let's take a look at scenarios using 32KB input / output blocks. 32KB input / output blocks are suitable for reading and writing large blocks of sequential data. Suitable operations include batch processing of sequential reads and writes (such as video streaming and scientific computing data) and appending to log files (such as Kafka message queues). A 32KB input / output block consists of eight consecutive 4KB memory pages. A single allocation reduces memory management overhead (i.e., the difference between one allocation and eight 4KB allocations), improving throughput. For example, when a storage system writes a 32KB log, directly allocating a 32KB input / output block can reduce seven system calls compared to allocating eight separate 4KB memory pages, thereby improving allocation efficiency.
[0116] Using 32KB input and output blocks can optimize performance by taking advantage of spatial locality. This is applicable for pre-reading adjacent data blocks and filling cache lines (e.g., CPU cache lines are typically 64B-256B).
[0117] Using 32KB I / O blocks better exploits spatial locality and reduces the probability of page faults on subsequent accesses. Using 32KB I / O blocks reduces management overhead and is suitable for scenarios such as long-term, large memory buffers (such as network transmission buffers) and memory pool preallocation (reserving a batch of I / O blocks at startup). The valid field of an I / O block uses a bitmap to manage eight internal 4KB memory pages. When releasing an I / O block, only the entire I / O block needs to be reclaimed, eliminating the need to traverse scattered small pages.
[0118] For example, the area in the user-mode sub-resource pool may also include an input / output block area, which is used to manage input / output blocks. The input / output block area is managed using a data structure, which may include a free list, a status bitmap, the total number of unallocated memory pages, or the total number of unallocated input / output blocks.
[0119] Each candidate I / O block includes multiple memory pages. Each candidate I / O block corresponds to a status bitmap. The status bitmap is used to determine the idle state of each memory page in the candidate I / O block. For example, "1" or "0" can be used to indicate idle or not idle. An idle memory page indicates an unallocated memory page.
[0120] For example, if an I / O block contains unfree memory pages, the entire I / O block cannot be allocated to the target module to avoid allocation conflicts. A target I / O block determined from multiple candidate I / O blocks is an I / O block in which every memory page is free. Allocating the target I / O block to the target module allows the target module to effectively use the memory resources corresponding to the target I / O block.
[0121] Optionally, the free linked list includes multiple numbers corresponding to multiple input and output blocks to be selected, and the corresponding input and output blocks to be selected can be quickly located through the numbers.
[0122] In this feasible implementation, the memory resources in the user-mode sub-resource pool are managed through the input and output block area, which can accurately determine the target memory resources and directly access the address of the memory page by bypassing the kernel, thereby reducing the kernel overhead.
[0123] In a feasible implementation method, the multiple input and output blocks to be selected do not include input and output blocks whose idle states in the status bitmap are all idle; the method also includes: allocating multiple free memory pages from the free page area of the user-state sub-resource pool; constructing a new input and output block through the multiple free memory pages, and adding the new input and output block to the free linked list; and determining the new input and output block as the target memory resource.
[0124] For example, if the multiple candidate I / O blocks do not include any I / O blocks whose idle status is shown in the status bitmap, this means that all memory pages in any candidate I / O block are non-idle, or partially non-idle. In this case, the target I / O block cannot be directly determined. Waiting for other modules to use the memory resources before returning to the user-mode sub-resource pool will result in inefficient memory resource allocation.
[0125] For example, in a scenario where multiple input and output blocks to be selected do not include input and output blocks whose idle states in the status bitmap are all idle, multiple free memory pages can be obtained and new input and output blocks can be constructed. It can be understood that since the new input and output blocks are constructed through free memory pages, the new input and output blocks meet the condition that the idle states in the status bitmap are all idle and can be allocated to the target module.
[0126] Exemplarily, the newly added input and output blocks are added to the free list so that they can be allocated later.
[0127] In this feasible implementation, by constructing new input and output blocks, complete input and output blocks can be allocated to the target module in scenarios where memory resources are tight, thereby improving the accuracy of memory resource allocation.
[0128] In a feasible implementation, the input / output block area further includes: a next input / output block identifier, a flag bit, a number of free pages, a number of free input / output blocks, and a memory page array.
[0129] Exemplarily, the next I / O block identifier is a link pointer in the user-mode free list, used to point to the next free I / O block. Using the next I / O block identifier avoids global scanning, thereby reducing the complexity of retrieving I / O blocks. A flag bit can be used to indicate the status of an I / O block (e.g., locked or persistent storage). The number of free pages can be a count of free memory pages. The number of free I / O blocks can be a count of free I / O blocks. A memory page array can be used to store the physical addresses corresponding to memory pages, allowing for rapid location of the physical addresses corresponding to memory pages.
[0130] In this feasible implementation, the input and output blocks can be managed from multiple dimensions through information of multiple fields, thereby improving the reliability of management.
[0131] In a feasible implementation, the user-state sub-resource pool further includes a metadata area, and the metadata area stores metadata of the user-state sub-resource pool.
[0132] Exemplarily, the metadata includes but is not limited to at least one of the following: the total number of available pages, the current number of free pages, the number of allocated input and output blocks, hardware and topology information, cluster configuration information (such as CXL switch addresses or CXL device lists), or resource pool health status.
[0133] For example, the user-mode sub-resource pool can be managed holistically from multiple dimensions through various metadata, so as to timely discover problems or parts that can be optimized.
[0134] In this feasible implementation, the memory resources of the user-mode sub-resource pool can be managed from multiple dimensions through the metadata area, thereby improving management reliability.
[0135] A feasible implementation method, the memory resource allocation method may also include: determining the total number of memory pages in the user-state sub-resource pool, and the correspondence between the number of physical pages and the number of management pages; determining the total number of memory pages as an intermediate variable; iteratively performing preset processing to obtain the number of physical pages and the number of management pages, the number of management pages including the number of pages in the second-level page table, the number of pages in the free page area, and the pages in the input and output block area; until the first condition or the second condition is met, the user-state sub-resource pool is allocated regions according to the number of physical pages and the number of management pages, the first condition being that the number of iterations is greater than the second number threshold and the intermediate variable is less than the number of physical pages, the second condition being that the intermediate variable is equal to the number of physical pages: wherein the preset processing includes: updating the number of iterations, determining the number of management pages according to the intermediate variable and the correspondence, and determining the difference between the total number of memory pages and the number of management pages as the number of physical pages.
[0136] Exemplarily, the user-state sub-resource pool includes memory pages, physical pages, and management pages. The memory pages, physical pages, and management pages all occupy space in the user-state sub-resource pool. A reasonable allocation method for the space is determined through iterative processing.
[0137] For example, the number of physical pages represents the total amount of physical memory that the user-mode sub-resource pool needs to manage. The correspondence between the number of physical pages and the number of management pages represents the mathematical relationship between the amount of management memory required per unit of service memory (for example, 8 pages of management overhead are required for every 512 service pages). The intermediate variable represents the number of service memory pages currently being calculated. The number of iterations is used to prevent infinite loops.
[0138] For example, the process terminates when the number of iterations is greater than a second threshold and the intermediate variable is less than the number of physical pages, thus avoiding an infinite loop that increases overhead. When the intermediate variable is equal to the number of physical pages, a balance point is found.
[0139] In this feasible implementation, through iterative operations, the areas of the user-state sub-resource pool can be effectively balanced, thereby effectively managing the user-state sub-resource pool.
[0140] A feasible implementation method is that the memory resource allocation method also includes: determining the module identifier of the target module; generating a reservation mark based on the module identifier; adding a reservation mark to the target memory resource to prohibit the target memory management module from allocating the target memory resource to other modules when the target memory resource is located in the user-state sub-resource pool.
[0141] Exemplarily, the reservation tag is used to pre-allocate target memory resources for the target module.
[0142] In this scenario example, for memory resources without the reservation flag, after they are returned to the user-state sub-resource pool, they can be allocated to any module. For target memory resources with the reservation flag, after the target module completes use and returns them to the user-state sub-resource pool, the target memory resources become locked and can only be allocated to the target module.
[0143] Combined with the scenario example, the reservation tag can be used to reserve memory resources for the module, so that when the module applies for memory resources, the user-mode sub-resource pool contains sufficient memory resources.
[0144] In this feasible implementation, the reservation mark can ensure that the user-state sub-resource pool can meet the target module's demand for memory resources, thereby improving the reliability of memory resource allocation.
[0145] In a feasible implementation, the memory resource allocation method may further include: if the target memory resource is in the user-mode sub-resource pool for a time period greater than or equal to a time period threshold, deleting a reservation mark in the target memory resource.
[0146] Exemplarily, if the duration is greater than or equal to the duration threshold, it indicates that the target memory resource is locked for too long. During this period, no module uses the target memory resource, resulting in unreasonable memory resource allocation.
[0147] Optionally, the duration threshold may be adaptively adjusted according to the amount of available resources in the user-mode sub-resource pool to reduce the impact of locking memory resources on module usage.
[0148] In this feasible implementation, by regularly clearing the reserved mark, memory resources are prevented from being locked for a long time and affecting allocation, thereby improving the reliability of memory management.
[0149] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0150] Figure 7This is a schematic diagram of the structure of the memory resource allocation device provided in the embodiment of the present application. Figure 7 As shown, the embodiment of the present application further provides a memory resource allocation device, the memory resource allocation device 70 may include: a receiving module 71, a determining module 72, an acquiring module 73, and an allocating module 74, wherein,
[0151] The receiving module 71 is configured to receive a memory resource request sent by a target module, where the memory resource request includes a target memory capacity, a target memory attribute, and a target memory unit.
[0152] The determination module 72 is configured to determine a target memory management module corresponding to a target memory attribute according to a memory resource request.
[0153] The acquisition module 73 is used to determine the target memory resources corresponding to the target memory capacity from the user state sub-resource pool corresponding to the target memory unit through the target memory management module. The memory resources in the user state sub-resource pool are obtained by a one-time call during the initialization process of the user state sub-resource pool.
[0154] The allocation module 74 is configured to allocate target memory resources to the target module.
[0155] Optionally, the receiving module 71 may execute Figure 2 S201 in the embodiment.
[0156] Optionally, the determination module 72 may execute Figure 2 S202 in the embodiment.
[0157] Optionally, the acquisition module 73 may execute Figure 2 S203 in the embodiment.
[0158] Optionally, the allocation module 74 may execute Figure 2 S204 in the embodiment.
[0159] It should be noted that the memory resource allocation device shown in the embodiment of the present application can execute the technical solution shown in the above method embodiment, and its implementation principle and beneficial effects are similar, which will not be repeated here.
[0160] In a possible implementation, the determination module 72 is specifically configured to:
[0161] Determine the corresponding target memory type according to the target memory attribute, the target memory type is dynamic random access memory or computing fast connection memory;
[0162] According to the target memory type, a target memory management module is determined. The target memory management module is used to manage a resource pool of dynamic random access memory or a resource pool of computing fast connection memory.
[0163] Figure 8 A schematic diagram of the structure of a memory resource allocation device provided in an embodiment of the present application. Figure 7 Based on the embodiment shown, Figure 8 As shown, the memory resource allocation device 70 further includes: a judgment module 75, a sending module 76, an initialization module 77, an adjustment module 78, a first execution module 79, an addition module 710, a second execution module 711, a construction module 712, a management module 713, a reservation module 714, and a removal module 715, wherein,
[0164] The judgment module 75 is used to determine the available resources of the user-mode sub-resource pool;
[0165] Determine whether the target memory capacity is less than or equal to the available resources;
[0166] If so, determine the target memory resource corresponding to the target memory capacity from the user-state sub-resource pool;
[0167] If not, a temporary memory resource is determined from the upper-level resource pool of the user-state sub-resource pool, and the temporary memory resource is allocated to the user-state sub-resource pool, and a target memory resource corresponding to the target memory capacity is determined from the user-state sub-resource pool.
[0168] The sending module 76 is used to: determine the usage status of the temporary memory resource, which is either in use or completed;
[0169] If the usage status is complete, temporary memory resources are sent to the upper-level resource pool.
[0170] Initialization module 77, used to: determine the memory resource quota of the user-mode sub-resource pool based on the total memory resource of the root resource pool;
[0171] Based on the memory resource quota, the initial memory resources are determined from the upper-level resource pool and allocated to the user-mode sub-resource pool.
[0172] The adjustment module 78 is configured to determine a resource allocation record of the user-mode sub-resource pool, where the resource allocation record includes a number of times the available resources of the user-mode sub-resource pool are insufficient;
[0173] If the number of times is greater than or equal to the first threshold, the quota of the user-state sub-resource pool is adjusted.
[0174] The memory resource request also includes a target page number, where the target memory unit is a memory page; a first execution module 79 is configured to: determine a multi-level page table from a page table area of the user-mode sub-resource pool, the multi-level page table being used to locate the memory page, the multi-level page table including a second-level page table;
[0175] Determine the starting address of the second-level page table;
[0176] According to the target page number, determine the offset of the address of the target pointer corresponding to the target page number relative to the starting address;
[0177] According to the offset, get the target pointer in the second-level page table;
[0178] A target memory page pointed to by a target pointer is determined from the user-state sub-resource pool, and the target memory page is determined as a target memory resource.
[0179] In a possible implementation, the first execution module 79 is specifically configured to: determine a target address of the target pointer in the second-level page table according to the start address and the offset;
[0180] Get the target pointer from the target address.
[0181] Adding module 710, used to: remove the target memory page from the free page area of the user-mode sub-resource pool;
[0182] Add the target memory page to the common memory area of the user-mode sub-resource pool.
[0183] In one possible embodiment, the multi-level page table also includes a first-level page table, the first-level page table includes multiple first-level page table entries, each first-level page table entry includes multiple first-level pointers, each first-level pointer points to a corresponding second-level page table entry in the second-level page table, wherein each second-level page table entry includes multiple second-level pointers.
[0184] The target memory unit is an input / output block; a second execution module 711 is configured to: determine a free list from the input / output block area of the user-mode sub-resource pool, and determine a plurality of candidate input / output blocks through the free list, each candidate input / output block including a plurality of memory pages;
[0185] Determine a plurality of state bitmaps from a plurality of candidate input and output blocks in the input and output block area, each state bitmap representing an idle state of a plurality of memory pages in a corresponding candidate input and output block;
[0186] According to multiple state bitmaps, a target input and output block is determined from multiple candidate input and output blocks, and the target input and output block is determined as a target memory resource. The idle states in the state bitmaps corresponding to the target input and output block are all idle.
[0187] The plurality of input and output blocks to be selected do not include all the input and output blocks in the idle state in the state bitmap; a construction module 712 is configured to: allocate a plurality of free memory pages from the free page area of the user state sub-resource pool;
[0188] Build new input and output blocks through multiple free memory pages, and add the new input and output blocks to the free list;
[0189] Identify the newly added input and output blocks as target memory resources.
[0190] In a possible implementation, the input / output block area further includes: a next input / output block identifier, a flag bit, a number of free pages, a number of free input / output blocks, and a memory page array.
[0191] In a possible implementation, the user-state sub-resource pool further includes a metadata area, and the metadata area stores metadata of the user-state sub-resource pool.
[0192] The management module 713 is used to determine the total number of memory pages in the user-mode sub-resource pool, and the corresponding relationship between the number of physical pages and the number of management pages;
[0193] Determine the total number of memory pages as an intermediate variable;
[0194] Iteratively executing a preset process to obtain the number of physical pages and the number of management pages, where the number of management pages includes the number of pages in the second-level page table, the number of pages in the free page area, and the number of pages in the input and output block area;
[0195] Until the first or second condition is met, the user-state sub-resource pool is allocated based on the number of physical pages and the number of management pages. The first condition is that the number of iterations is greater than the second threshold and the intermediate variable is less than the number of physical pages. The second condition is that the intermediate variable is equal to the number of physical pages:
[0196] The preset processing includes: updating the number of iterations, determining the number of management pages according to the intermediate variables and the corresponding relationship, and determining the difference between the total number of memory pages and the number of management pages as the number of physical pages.
[0197] The reservation module 714 is used to: determine the module identifier of the target module;
[0198] Generate a reserved tag based on the module identifier;
[0199] A reservation mark is added to the target memory resource to prohibit the target memory management module from allocating the target memory resource to other modules when the target memory resource is located in the user-mode sub-resource pool.
[0200] The removal module 715 is configured to delete the reservation mark in the target memory resource if the time period during which the target memory resource is in the user-mode sub-resource pool is greater than or equal to a time period threshold.
[0201] For the description of the features in the embodiment corresponding to the memory resource allocation device, reference can be made to the relevant description of the embodiment corresponding to the memory resource allocation method, which will not be repeated here.
[0202] Figure 9 This is a schematic diagram of the structure of the electronic device provided in this application. Figure 9As shown, the electronic device 90 provided in this embodiment includes: at least one processor 901 and a memory 902. Optionally, the electronic device 90 further includes a communication component 903. The processor 901, the memory 902 and the communication component 903 are connected via a bus.
[0203] During the specific implementation process, at least one processor 901 executes the computer-executable instructions stored in the memory 902, so that the at least one processor 901 executes the above-mentioned embodiment of the method for allocating memory resources.
[0204] The specific implementation process of the processor 901 can be found in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here in this embodiment.
[0205] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly executed by a hardware processor or by a combination of hardware and software modules within the processor.
[0206] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage.
[0207] A bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be categorized as address buses, data buses, and control buses. For ease of illustration, the buses in the drawings of this application are not limited to just one bus or just one type of bus.
[0208] An embodiment of the present application further provides a non-volatile computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned memory resource allocation method embodiments when running.
[0209] In an exemplary embodiment, the non-volatile computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0210] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the computer program implements the steps of any of the above-mentioned memory resource allocation method embodiments.
[0211] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above-mentioned memory resource allocation method embodiments are implemented.
[0212] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0213] The above is a detailed introduction to the memory resource allocation method, device, electronic device, medium and product provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A method for allocating memory resources, characterized in that: include: receiving a memory resource request sent by a target module, wherein the memory resource request includes a target memory capacity, a target memory attribute, and a target memory unit; Determining, according to the memory resource request, a target memory management module corresponding to the target memory attribute; Determining, by the target memory management module, target memory resources corresponding to the target memory capacity from the user-state sub-resource pool corresponding to the target memory unit, where the memory resources in the user-state sub-resource pool are obtained by a one-time call during the initialization process of the user-state sub-resource pool; Allocating the target memory resource to the target module; Wherein, the memory resource request also includes a target page number, and the target memory unit is a memory page; determining the target memory resource corresponding to the target memory capacity from the user-state sub-resource pool corresponding to the target memory unit, including: determining a multi-level page table from the page table area of the user-state sub-resource pool, the multi-level page table being used to locate memory pages, the multi-level page table including a second-level page table; determining the starting address of the second-level page table; determining, according to the target page number, an offset of an address of a target pointer corresponding to the target page number relative to the starting address; obtaining, according to the offset, the target pointer in the second-level page table; determining, from the user-state sub-resource pool, a target memory page pointed to by the target pointer, and determining the target memory page as the target memory resource; The user-state sub-resource pool further includes a metadata area, and the metadata area stores metadata of the user-state sub-resource pool; Among them, the method also includes: determining the total number of memory pages of the user-state sub-resource pool, and the correspondence between the number of physical pages and the number of management pages; determining the total number of memory pages as an intermediate variable; iteratively performing preset processing to obtain the number of physical pages and the number of management pages, the number of management pages including the number of pages in the second-level page table, the number of pages in the free page area, and the pages in the input and output block area; until the first condition or the second condition is met, the user-state sub-resource pool is allocated areas according to the number of physical pages and the number of management pages, the first condition being that the number of iterations is greater than the second number threshold and the intermediate variable is less than the number of physical pages, the second condition being that the intermediate variable is equal to the number of physical pages: wherein, the preset processing includes: updating the number of iterations, determining the number of management pages according to the intermediate variable and the correspondence, and determining the difference between the total number of memory pages and the number of management pages as the number of physical pages.
2. The memory resource allocation method according to claim 1, wherein: Determining a target memory management module corresponding to the target memory attribute includes: Determining a corresponding target memory type according to the target memory attribute, the target memory type being dynamic random access memory or computationally fast access memory; The target memory management module is determined according to the target memory type, and the target memory management module is used to manage a resource pool of dynamic random access memory or a resource pool of computing fast connection memory.
3. The memory resource allocation method according to claim 2, wherein: Determining a target memory resource corresponding to the target memory capacity from a user-mode sub-resource pool corresponding to the target memory unit includes: Determine the available resources of the user-mode sub-resource pool; Determining whether the target memory capacity is less than or equal to the available resource amount; If yes, determining the target memory resource corresponding to the target memory capacity from the user-state sub-resource pool; If not, a temporary memory resource is determined from the upper-level resource pool of the user-state sub-resource pool, and the temporary memory resource is allocated to the user-state sub-resource pool, and a target memory resource corresponding to the target memory capacity is determined from the user-state sub-resource pool.
4. The memory resource allocation method according to claim 3, wherein: The method further comprises: Determine the usage status of the temporary memory resource, where the usage status is in use or usage is complete; If the usage status is usage completed, the temporary memory resource is sent to the upper-level resource pool.
5. The memory resource allocation method according to claim 3, wherein: The method further comprises: Determine the memory resource quota of the user-mode sub-resource pool based on the total memory resource of the root resource pool; According to the memory resource quota, initial memory resources are determined from the upper-level resource pool, and the initial memory resources are allocated to the user-mode sub-resource pool.
6. The memory resource allocation method according to claim 5, characterized in that: The method further comprises: Determining a resource allocation record of the user-mode sub-resource pool, wherein the resource allocation record includes a number of times that the available resources of the user-mode sub-resource pool are insufficient; If the number of times is greater than or equal to the first number threshold, the quota of the user-mode sub-resource pool is adjusted.
7. The memory resource allocation method according to claim 3, wherein: Acquiring the target pointer in the second-level page table according to the offset includes: Determining a target address of the target pointer in the second-level page table according to the starting address and the offset; The target pointer is obtained from the target address.
8. The memory resource allocation method according to claim 7, wherein: The method further comprises: Remove the target memory page from the free page area of the user-mode sub-resource pool; The target memory page is added to the general memory area of the user-mode sub-resource pool.
9. The memory resource allocation method according to claim 8, characterized in that: The multi-level page table also includes a first-level page table, which includes multiple first-level page table entries, each first-level page table entry includes multiple first-level pointers, each first-level pointer points to a corresponding second-level page table entry in the second-level page table, wherein each second-level page table entry includes multiple second-level pointers.
10. The memory resource allocation method according to claim 3, wherein: The target memory unit is an input-output block; Determining a target memory resource corresponding to the target memory capacity from a user-mode sub-resource pool corresponding to the target memory unit includes: Determine a free linked list from the input and output block area of the user-mode sub-resource pool, and determine a plurality of candidate input and output blocks through the free linked list, each candidate input and output block including a plurality of memory pages; Determine a plurality of state bitmaps from the plurality of candidate input and output blocks in the input and output block area, each state bitmap representing idle states of a plurality of memory pages in a corresponding candidate input and output block; According to the multiple state bitmaps, a target input / output block is determined from the multiple candidate input / output blocks, and the target input / output block is determined as the target memory resource, and the idle states in the state bitmaps corresponding to the target input / output block are all idle.
11. The memory resource allocation method according to claim 10, wherein: The plurality of input and output blocks to be selected do not include input and output blocks whose idle states in the status bitmap are all idle; the method further includes: Allocate multiple free memory pages from the free page area of the user-mode sub-resource pool; Constructing a new input / output block using the plurality of free memory pages, and adding the new input / output block to the free linked list; The newly added input and output block is determined as the target memory resource.
12. The memory resource allocation method according to claim 11, wherein: The input / output block area further includes: a next input / output block identifier, a flag bit, a number of free pages, a number of free input / output blocks, and a memory page array.
13. The memory resource allocation method according to claim 1, wherein: The method further comprises: Determining a module identifier of the target module; generating a reserved mark according to the module identifier; The reservation mark is added to the target memory resource to prohibit the target memory management module from allocating the target memory resource to other modules when the target memory resource is located in the user-mode sub-resource pool.
14. The memory resource allocation method according to claim 13, wherein: The method further comprises: If the time duration for which the target memory resource is located in the user-mode sub-resource pool is greater than or equal to a time duration threshold, the reservation mark is deleted from the target memory resource.
15. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the method for allocating memory resources as claimed in any one of claims 1 to 14 when executing the computer program.
16. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method for allocating memory resources according to any one of claims 1 to 14.
17. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the memory resource allocation method according to any one of claims 1 to 14 are implemented.
Citation Information
Patent Citations
Memory mapping method and memory mapping module
CN103257936A
Subsystem memory management method and device
CN116049023A