Memory resource allocation method and device, electronic equipment, medium and product

By calling memory resources at one time in user-mode operations and adopting multi-level resource pools and page table management, the problem of large kernel overhead in memory resource allocation is solved, and efficient and accurate memory resource allocation is achieved to adapt to different business needs.

CN120407201AActive Publication Date: 2025-08-01INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202510897273.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-08-01
Estimated Expiration
2045-06-30

AI Technical Summary

Technical Problem

In the prior art, the memory resource allocation process requires frequent participation of the system kernel, resulting in high overhead, especially inefficient in high concurrency scenarios of multi-threading.

Method used

Transfer the allocation of memory resources to user-state operations, call memory resources at one time through user-state sub-resource pools, reduce kernel participation, and use multi-level resource pools and multi-level page tables to manage memory resources to achieve efficient allocation of memory resources.

Benefits of technology

It reduces the overhead of the kernel, improves the efficiency and accuracy of memory resource allocation, adapts to memory requirements in different business scenarios, and improves the system's throughput and resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407201A_ABST
    Figure CN120407201A_ABST
Patent Text Reader

Abstract

The invention discloses a memory resource allocation method and device, electronic equipment, a medium and a product, relates to the technical field of memory management, and aims at calling enough memory resources at one time when a resource pool is initialized and executing the memory resource allocation to a module through user mode operation without the participation of a kernel so as to reduce the overhead of the kernel.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of memory management, and particularly to a method, device, electronic device, medium and product for allocating memory resources. Background Art

[0002] With the rapid development of devices such as computers or servers, the data scale has increased sharply, posing high requirements for memory. The modules of the device apply for memory resources according to actual usage needs, and the system allocates corresponding memory resources to the modules according to the applications of the modules. After the modules finish using the memory resources, the memory resources are returned.

[0003] However, this method requires the system kernel to frequently execute memory resource calls, resulting in a large overhead problem. Summary of the Invention

[0004] This application provides a method, device, electronic device, medium and product for allocating memory resources to at least solve the problem of large overhead in allocating memory resources in related technologies.

[0005] This application provides a method for allocating memory resources, including: receiving 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; determining a target memory management module corresponding to the target memory attribute according to the memory resource request; through the target memory management module, determining a target memory resource corresponding to the target memory capacity from the user-state sub-resource pool corresponding to the target memory unit, and 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.

[0006] This application also provides a device for allocating memory resources, including: a receiving module, 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; a determining module, configured to determine a target memory management module corresponding to the target memory attribute according to the memory resource request; an obtaining module, configured to determine a target memory resource 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, and 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; an allocating module, configured to allocate the target memory resource to the target module.

[0007] This application also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any one of the above methods for allocating memory resources when executing the computer program.

[0008] The present application also provides a non-volatile computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the above-mentioned memory resource allocation methods.

[0009] The present application also provides a computer program product including a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned memory resource allocation methods.

[0010] Through the present application, when initializing the resource pool, sufficient memory resources are called at one time. When allocating memory resources to modules, it is executed through user-mode operations without the participation of the kernel, thereby reducing the overhead of the kernel. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] To more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0012] Figure 1 Schematic diagram of an application scenario of a memory resource allocation method provided by an embodiment of the present application;

[0013] Figure 2 Schematic diagram of a flowchart of a memory resource allocation method provided by an embodiment of the present application;

[0014] Figure 3 Schematic diagram of a flowchart of a memory resource allocation method provided by an embodiment of the present application;

[0015] Figure 4 Schematic diagram of a memory management module provided by an embodiment of the present application;

[0016] Figure 5 Schematic diagram of a multi-level resource pool provided by an embodiment of the present application;

[0017] Figure 6 Schematic diagram of a multi-level page table provided by an embodiment of the present application;

[0018] Figure 7 Schematic diagram of a structure of a memory resource allocation device provided by an embodiment of the present application;

[0019] Figure 8 Schematic diagram of a structure of a memory resource allocation device provided by an embodiment of the present application;

[0020] Figure 9 Schematic diagram of a structure of an electronic device provided by an embodiment of the present application. Detailed implementation manners

[0021] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.

[0022] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, rather than to describe a specific 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 Internet technologies drive the pooling and expansion of memory resources, enabling the system to access memory capacities far beyond local physical limitations; on the other hand, the performance of storage devices continues to improve, and the gap between its input / output processing capabilities and memory management efficiency is becoming increasingly acute. Memory, as a temporary storage, has the characteristics of high-speed reading and writing, which can effectively improve the working efficiency of devices such as computers or servers. Modules of the device apply for memory resources from the system according to the actual working system, and return the memory resources to the system after use. The memory resources returned to the system can be applied for by any device, thus realizing a reasonable allocation and use mechanism of memory resources.

[0024] In the related art, storage software applies for memory through functions (such as malloc). This process passes through the kernel of the operating system, and memory resources are allocated through the kernel of the system operating system. There are the following problems: long path bottleneck, each memory resource request of the user-mode module needs to cross the kernel protection boundary, triggering context switching and privilege-level verification. In a multi-threaded high-concurrency scenario, this switching loss is amplified exponentially, forming a throughput collapse area; misalignment of abstraction levels, the byte-level allocation model designed by the kernel according to the processor paging management requirements has a fundamental impedance mismatch with the physical block-based access mode of the storage device. This mismatch forces the storage system to additionally encapsulate an adaptation layer in the user mode, resulting in redundant processing links; resource scheduling blind area, lacking native awareness of heterogeneous memory media (such as high-speed low-capacity / low-speed high-capacity memory), and unable to dynamically route memory resource requests according to the business characteristics of the module.

[0025] To enable those skilled in the art of the present technology to better understand the solution of this application, the following further detailed description of this application will be given in conjunction with the accompanying drawings and specific embodiments.

[0026] In combination 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 herein. Refer to Figure 1 , Figure 1 FIG. is a schematic diagram of the application scenario for the allocation of memory resources. The target module initiates a memory resource request according to the demand for memory resources in the working process, applies for the corresponding memory resources from the resource pool according to the memory resource request, and allocates the corresponding memory resources to the target module.

[0027] Combined with the scenario example, during the working process 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 the related art, the system kernel is used to execute the allocation of memory resources. When multiple modules frequently apply for memory resources, the kernel needs to frequently execute the memory resource allocation, resulting in the problem of high kernel overhead.

[0029] Based on the above technical problems, the solution of this application is to transfer the allocation of memory resources to the user state operation, reduce the operation of the system memory, and thus reduce the kernel overhead.

[0030] Figure 2 FIG. is a schematic flowchart of the memory resource allocation method provided by the embodiment of this application. As Figure 2 shown, the embodiment of this application provides a memory resource allocation method, and a detailed description of the method is as follows:

[0031] S201. Receive a memory resource request sent by the target module. The memory resource request includes the target memory capacity, the target memory attribute, and the target memory unit.

[0032] Exemplarily, the target module is a module that demands memory resources, and the memory resource request is used to trigger the execution of the memory resource allocation 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 demanded 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 demand of the target module for the attributes of the memory resources. For example, it can be 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 of the type that is the smallest unit of the memory resources required by the target module. For example, it can be a 4KB page or a 32KB input / output block, etc. The difference of the target memory units lies in different granularity sizes, which are adapted to different business scenarios.

[0036] Combined with the scenario example, the memory resource request includes various types of requirements. By allocating memory resources to the target module through various types of requirements, the business scenario of the target module can be effectively adapted, thereby improving the accuracy of memory resource allocation.

[0037] S202. Determine the 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 management module in the user state, which is used to manage the memory resources corresponding to the target memory attribute. The memory resources corresponding to the target memory attribute are the memory resources that meet the requirements of the target module.

[0039] Exemplarily, according to the attributes of different memory resources, they are respectively managed by the corresponding memory management modules. When allocating memory resources, the corresponding memory management module allocates the memory resources, which can make the actually allocated memory resources meet the requirements of the target module.

[0040] Based on the above embodiments, grouping and managing the memory resources can make the allocated resources adapt to the business scenario of the target module, thereby improving the accuracy of memory resource allocation.

[0041] S203. Through the target memory management module, determine the 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 process of the user-state sub-resource pool.

[0042] Exemplarily, during the initialization process of the user-state sub-resource pool, a sufficient amount of memory resources are called at one time and allocated to the user-state sub-resource pool. When the target module applies for memory resources, it does not require the participation of the kernel, and the memory resources are allocated from the user-state sub-resource pool to the target module through user-state operations, thereby reducing the operations of the kernel.

[0043] Exemplarily, the memory resources in the user-state sub-resource pool corresponding to the target memory unit all use the target memory unit as the smallest unit. For example, if the target memory unit is a 4KB page, then the smallest unit of the memory resources in the corresponding user-state sub-resource pool is all 4KB pages.

[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 , describes 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 the corresponding target memory type according to the target memory attribute, where the target memory type is dynamic random access memory or compute express link memory.

[0054] Exemplarily, dynamic random access memory (DRAM) is interconnected with a processor (such as a CPU) through a direct memory channel. The signal does not require protocol conversion, and the current directly reaches the storage unit, having the property of low latency. Compute express link (CXL) memory decouples the memory module from the host channel and can expand the capacity independently through separate hardware, having the property of large capacity.

[0055] Combined with a scenario example, the target memory attribute of the target module reflects the memory attribute requirements of the target module, and the memory resources of the target memory type can meet the requirements of the target module.

[0056] S303. Determine the target memory management module according to the target memory type. The target memory management module is used to manage the resource pool of dynamic random access memory or the resource pool of compute express link memory.

[0057] Next, Figure 4 describe the memory management module.

[0058] Figure 4 is a schematic diagram of the memory management module provided by an embodiment of the present application. As Figure 4 shown, multiple memory management modules and multiple resource pools are pre-configured. Each resource pool stores one type of memory, either dynamic random access memory or compute express link memory, and each resource pool is managed by a corresponding memory management module.

[0059] Combined with a scenario example, if the target memory type is dynamic random access memory, then determine the memory management module corresponding to the resource pool of dynamic random access memory as the target memory management module.

[0060] Based on the above implementation, decouple different types of memory and store them in different resource pools, which can accurately allocate matching memory resources to the target module when allocating memory resources, thereby improving the allocation accuracy of memory resources.

[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] Exemplarily, during the initialization process, initial memory resources are allocated to the user-mode sub-resource pool. When memory resources are allocated to the target module or other modules, the quantity of memory resources in the user-mode sub-resource pool decreases accordingly. The available resource quantity is the size of the remaining memory resources in the user-mode sub-resource pool.

[0064] A feasible implementation manner, the memory resource allocation method may further include: determining the memory resource quota of the user-mode sub-resource pool according to the total amount of memory resources in the root resource pool; determining the initial memory resources from the upper-level resource pool according to the memory resource quota, and allocating the initial memory resources to the user-mode sub-resource pool.

[0065] Exemplarily, the root resource pool is the total pool for managing memory resources. Before initializing the sub-resource pool, all memory resources are stored in the root resource pool. The memory resource quota is the quota for the memory size allocated to each sub-resource pool. During initialization, the corresponding memory resources are allocated to the sub-resource pool according to the quota.

[0066] Optionally, determine the quota of each sub-resource pool according to the memory resource requirements of the module corresponding to each sub-resource pool. For example, if the memory resource requirements of the module corresponding to any sub-resource pool are relatively large, the corresponding quota is relatively large.

[0067] In this feasible implementation manner, by allocating the initial memory resources through the pre-set quota, it is possible to avoid multiple sub-resource pools competing for memory resources during initialization and reducing the initialization efficiency, thereby improving the initialization efficiency.

[0068] A feasible implementation manner, the memory resource allocation method may further include: determining the resource allocation record of the user-mode sub-resource pool, where the resource allocation record includes the number of times when the available resource quantity of the user-mode sub-resource pool is insufficient; if the number of times is greater than or equal to the first number threshold, adjust the quota of the user-mode sub-resource pool.

[0069] Exemplarily, the resource allocation record of the user-mode sub-resource pool is the resource allocation record of the user-mode sub-resource pool after historical initialization before this initialization. The initialization of the resource pool can be re-executed according to the change of the usage scenario. After each execution of the initialization, record the resource allocation record of the user-mode sub-resource pool.

[0070] Combined with the scenario example, if the number of times is greater than or equal to the first number threshold, it indicates that the quota of the user-mode sub-resource pool is relatively small, and the memory resources allocated according to the quota cannot meet the memory resource requirements of the module corresponding to the user-mode sub-resource pool. Then, the quota should be adaptively increased to allocate more memory resources to the user-mode sub-resource pool during this execution of the initialization.

[0071] Optionally, if the initial memory resources of the user-mode sub-resource pool history are excessive, the quota of the user-mode sub-resource pool is adaptively reduced.

[0072] In this feasible implementation, by dynamically adjusting the quota, 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-mode sub-resource pool. By comparison, it can be determined whether the size of the memory resources in the user-mode sub-resource pool can meet the requirements of the target module.

[0075] S306. If so, determine the target memory resources 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-mode sub-resource pool can meet the requirements of the target module. Then, the memory resources required by the target module are obtained from the user-mode sub-resource pool as the target memory resources.

[0077] S307. If not, determine the temporary memory resources from the upper-level resource pool of the user-mode sub-resource pool, allocate the temporary memory resources to the user-mode sub-resource pool, and determine the target memory resources corresponding to the target memory capacity from the user-mode sub-resource pool.

[0078] It should be noted that the execution order of S306 and S307 in this application is not limited.

[0079] Exemplarily, when the target memory capacity is greater than the available resource amount, it indicates that the size of the memory resources in the user-mode sub-resource pool cannot meet the requirements of the target module. If the allocation is still performed, it will cause insufficient allocated memory resources and affect the normal operation of the target module.

[0080] Exemplarily, the initial memory resource sizes of each resource pool are different, and the available memory resource amounts of each resource pool at different times are different. There may be an imbalance problem where the available memory resources in some resource pools are excessive and the available memory resources in some resource pools are insufficient at a certain moment. By managing memory resources through a multi-level resource pool, the memory resources in multiple resource pools can be coordinated and called to balance the available memory resources in multiple resource pools, thereby avoiding the problems of idle memory resources or insufficient memory resources and improving the accuracy of memory resource allocation.

[0081] Next, a multi-level resource pool will be described in conjunction with Figure 5 Describe the multi-level resource pool.

[0082] Figure 5 This is a schematic diagram of the multi - level resource pool provided by the embodiments of the present application. As Figure 5 shown, the multi - level resource pool includes a root resource pool and multiple sub - resource pools. The memory resources in the sub - resource pools are obtained by allocation from the resource pool of the previous level. The sub - resource pool can obtain temporary resources from the previous - level resource pool and return the temporary resources to the previous - level resource pool after use.

[0083] In this feasible implementation manner, by managing memory resources through a multi - level resource pool, the available resource amounts in multiple resource pools can be balanced, thereby improving the accuracy of memory resource allocation.

[0084] A feasible implementation manner, the method for allocating memory resources further includes: determining the usage status of the temporary memory resources, where the usage status is in - use or used - up; if the usage status is used - up, sending the temporary memory resources to the previous - level resource pool.

[0085] Optionally, there can be multiple resource pools at the lower level of the previous - level resource pool.

[0086] Exemplarily, the usage status being in - use means that the temporary memory resources have been allocated to a module, and the usage status being used - up means that the temporary memory resources have not been allocated to a module.

[0087] Combined with the scenario example, the temporary memory resources are the memory resources "borrowed" by the user - mode sub - resource pool from the previous - level resource pool, and the previous - level resource pool can send the temporary memory resources to multiple lower - level resource pools. If the user - mode sub - resource pool occupies the temporary memory resources for a long time, it may cause other peer resource pools to be unable to obtain temporary memory resources from the previous - level resource pool.

[0088] Based on this, when the size of the memory resources in the user - mode sub - resource pool is sufficient, returning the temporary memory resources to the previous - level resource pool can effectively coordinate other resource pools without affecting the use of the user - mode sub - resource pool.

[0089] In this feasible implementation manner, returning the temporary memory resources to the previous - level resource pool according to the usage status of the temporary memory resources realizes the dynamic coordination of the temporary memory resources, ensures that multiple resource pools can effectively allocate resources to the module, thereby improving the reliability of memory resource management.

[0090] A feasible implementation manner, the memory resource request further includes a target page number, and the target memory unit is a memory page; the following method can be used to determine the target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool corresponding to the target memory unit, including: determining a multi-level page table from the page table area of the user-mode 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; determining the offset of the address of the target pointer corresponding to the target page number relative to the starting address according to the target page number; obtaining the target pointer in the second-level page table according to the offset; determining the target memory page pointed to by the target pointer from the user-mode sub-resource pool, and determining the target memory page as the target memory resource.

[0091] Exemplarily, for the scenario where the target memory unit is a memory page, the physical read / write unit of the solid-state drive is 4KB. If a larger memory block is used, it will cause read / write amplification (for example, when writing 32KB, only 4KB needs to be modified, but the whole block still needs to be written). When the storage system caches a 4KB solid-state drive data block, directly allocating a 4KB memory page can avoid redundant copying. Applicable operations: Random small file read / write (such as database index update), non-continuous memory access scenario. The 4KB granularity page provides more flexible memory allocation and avoids fragmentation waste caused by allocating large memory blocks. Applicable scenarios: Operations that require low-latency DRAM acceleration (such as metadata operations), tasks with high real-time requirements (such as transaction log writing). Allocating 4KB memory pages can respond quickly and reduce waiting time.

[0092] Exemplarily, the target memory unit being a memory page means that the minimum unit of the memory resource required by the target module is a memory page, and the target page number is used to represent the position 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 nature of each memory page, or the free state of each memory page, etc.

[0094] Exemplarily, the second-level page table includes multiple second-level page table entries, each second-level page table entry points to a physical memory page, the multiple second-level page table entries are arranged in sequence, and the starting address of the second-level page table is the address of the first second-level page table entry among the multiple second-level page table entries.

[0095] Next, in combination with Figure 6 the multi-level page table will be described.

[0096] Figure 6 This is a schematic diagram of the multi-level page table provided by the embodiment of the present application. As Figure 6As shown, different levels of the multi-level page table are pointed to by pd pointers. The size of the pd pointer is 8 Bytes. The first-level page table includes 256 first-level page table entries. Each first-level page table entry includes 512 pds. The total size of each first-level page table entry is 512×8 Bytes = 4KB. Each pd of the first-level page table points to a second-level page table entry of the second-level page table. The number of pds in the first-level page table is 256×512 = 128K. Therefore, the number of second-level page table entries is 128K. Each second-level page table entry includes 4K pds. The total size of each second-level page table entry is 4K×8 Bytes = 32KB. Each pd of the second-level page table points to a memory page. The number of pds in the second-level page table is 128K×4K = 512MB. Therefore, the number of memory pages is 512M. Calculate the multi-level page table separately. The total occupied space of the first-level page table is 128K×8 Bytes = 1MB. The total occupied space of the second-level page table is 128K×32KB = 4GB. The total occupied space of the memory pages is 512MB×4KB = 2TB. It should be noted that the numerical values in this embodiment are only examples, and the present application does not limit the specific numerical values.

[0097] Exemplarily, in the second-level page table, multiple second-level page table entries are arranged in sequence. The pd pointers in each second-level page table entry are arranged continuously in sequence. The size of each pointer is fixed. Therefore, the offset of the address of the target pointer relative to the starting address can be accurately determined through the target page number corresponding to the target pointer. For example, the offset between the 5th pointer and the 1st pointer is (5 - 1)×8 Bytes = 32 Bytes.

[0098] Exemplarily, each pointer uniquely points to a memory page. After determining the target pointer, 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 user-mode process can directly access the address of the memory page bypassing the kernel, thereby reducing the overhead of the kernel.

[0100] A feasible implementation can obtain the target pointer according to the offset through 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; obtaining the target pointer from the target address.

[0101] Exemplarily, after determining the starting address and the offset, the sum of the starting address and the offset is determined as the target address.

[0102] Exemplarily, the addressing process of the target address is an operation executed in the user mode and does not require the participation of the kernel, which can effectively reduce the overhead of the kernel.

[0103] In this feasible implementation, the offset of the target pointer relative to the initial address is accurately determined through the offset, so that without using the kernel, the target pointer can be accurately obtained from the user-mode process, improving the accuracy of memory resource allocation.

[0104] In a feasible implementation, the method for allocating memory resources may further include: removing the target memory page from the free page area of the user-mode sub-resource pool; adding the target memory page to the general memory area of the user-mode sub-resource pool.

[0105] Exemplarily, memory resources are managed in different areas in the user-mode sub-resource pool. Among them, 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, it can be accurately distinguished whether the memory page has been allocated to the module through the free page area and the general memory area, and conflicts during memory page allocation can be avoided.

[0107] In this feasible implementation, conflicts during memory page allocation are avoided through the free page area and the general memory area, thereby improving the accuracy of memory resource allocation.

[0108] In a feasible implementation, the multi-level page table further 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. Among them, each second-level page table entry includes multiple second-level pointers.

[0109] Exemplarily, the first-level page table pre-fixes the base address (level2_memorytable) of the second-level page table. During subsequent access, the memory page can be quickly located directly through the base address + offset (ptr + p). The overhead of dynamically querying the first-level page table during runtime can be saved, and the address translation complexity is reduced from O(hierarchy depth) to O(1).

[0110] Exemplarily, during the initialization phase, the layout of the second-level page table is uniformly planned through the first-level page table to ensure that all second-level page table entries are continuously stored, avoiding the problem of memory fragmentation. In the user mode, all memory can be managed through the level2_memorytable base address without caring about the underlying page table distribution. The code complexity is reduced, and the operations of dynamically allocating / releasing page tables are reduced.

[0111] Optionally, the access permissions of the second-level page table are restricted through the first-level page table (such as read-only or non-executable, etc.) to prevent malicious code from tampering with the memory mapping relationship. Isolate the memory management logic between the user mode and the kernel mode to avoid out-of-bounds access. Support memory isolation in a multi-tenant scenario (such as allocating independent second-level page table areas for different modules).

[0112] Optionally, the first-level page table allocates independent second-level page table regions for different modules, and combines with a tree-shaped memory pool to achieve quota isolation, preventing a single module from exhausting global memory resources (for example, the CXL resource pool and the DRAM resource pool are managed independently), and realizing elastic resource borrowing through a multi-level resource pool to improve resource utilization.

[0113] In this feasible implementation, the first-level page table manages the underlying second-level page tables, which can accurately locate the target memory page. The user-mode process can directly access the address of the memory page bypassing the kernel, thereby reducing the kernel overhead.

[0114] In a feasible implementation, the target memory unit is an input / output block. The following method can be used to determine the target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool corresponding to the target memory unit, including: determining the free list from the input / output block region of the user-mode sub-resource pool, and determining multiple candidate input / output blocks through the free list. Each candidate input / output block includes multiple memory pages; determining multiple status bitmaps from the multiple candidate input / output blocks in the input / output block region, and each status bitmap represents the free status of multiple memory pages in the corresponding candidate input / output block; according to the multiple status bitmaps, determining the target input / output block from the multiple candidate input / output blocks, and determining the target input / output block as the target memory resource, where the free status in the status bitmap corresponding to the target input / output block is all free.

[0115] Exemplarily, the scenario of using a 32KB input / output block is exemplified. The scenario of using a 32KB input / output block can be for large-block continuous data reading and writing, and the applicable operations include: batch processing sequential reading and writing (such as video streams, scientific computing data), and appending writes to log files (such as Kafka message queues). The 32KB input / output block consists of 8 consecutive 4KB memory pages. Single allocation reduces the memory management overhead (that is, the difference between 1 allocation and 8 allocations of 4KB), and improves the throughput. For example, when the storage system writes a 32KB log, directly allocating a 32KB input / output block can reduce 7 system calls compared to allocating 8 independent 4KB memory pages, thereby improving the allocation efficiency.

[0116] Using a 32KB input / output block can optimize performance by taking advantage of spatial locality, and the applicable scenarios include: prefetching adjacent data blocks, cache line filling (such as the CPU cache line is usually 64B - 256B).

[0117] Using 32KB input / output blocks can better utilize spatial locality and reduce the page fault probability of subsequent accesses. Using 32KB input / output blocks can reduce management overhead. Applicable scenarios include large memory buffers held for a long time (such as network transfer Buffers) and memory pool pre-allocation (reserving a batch of input / output blocks at startup). The valid field of the input / output block manages 8 internal 4KB memory pages through a bitmap. When releasing, only the entire input / output block needs to be recycled, without traversing scattered small pages.

[0118] Exemplarily, the area in the user-mode sub-resource pool may further include an input / output block area for managing input / output blocks. The input / output block area is managed through a data structure, and the data structure may include a free list, a status bitmap, the total number of unallocated memory pages, or the total number of unallocated input / output blocks, etc.

[0119] Among them, each candidate input / output block includes multiple memory pages, and each candidate input / output block corresponds to a status bitmap. The free status of each memory page in the candidate input / output block is determined through the status bitmap. For example, it can be represented by "1" or "0" for free or not free. The free memory pages represent unallocated memory pages.

[0120] Exemplarily, if there are non-free memory pages in the input / output block, the input / output block cannot be allocated to the target module as a whole to avoid allocation conflicts. The target input / output block determined from multiple candidate input / output blocks is an input / output block with all memory pages free. Allocating the target input / output block to the target module can enable the target module to effectively use the memory resources corresponding to the target input / output block.

[0121] Optionally, the free list includes multiple numbers corresponding to multiple candidate input / output blocks, and the corresponding candidate input / output block 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 / output block area, which can accurately determine the target memory resources and directly access the memory page address bypassing the kernel, thereby reducing the kernel overhead.

[0123] A feasible implementation, where among multiple candidate input / output blocks, there is no input / output block with all free statuses in the status bitmap; then the method further includes: allocating multiple free memory pages from the free page area of the user-mode sub-resource pool; constructing a new input / output block through the multiple free memory pages, and adding the new input / output block to the free list; determining the new input / output block as the target memory resource.

[0124] Exemplarily, among multiple candidate input / output blocks, there is no input / output block in which the idle states in the status bitmap are all idle, indicating that the memory pages in any one of the candidate input / output blocks are all non-idle or partially non-idle. At this time, the target input / output block cannot be directly determined. If waiting for other modules to finish using the memory resources and then returning to the user-state sub-resource pool, it will lead to the problem of low memory resource allocation efficiency.

[0125] Exemplarily, for the scenario where among multiple candidate input / output blocks, there is no input / output block in which the idle states in the status bitmap are all idle, multiple free memory pages can be obtained and a new added input / output block can be constructed. It can be understood that since the added input / output block is constructed by free memory pages, the added input / output block meets the condition that the idle states in the status bitmap are all idle and can be allocated to the target module.

[0126] Exemplarily, by adding the added input / output block to the free list, it can be allocated subsequently.

[0127] In this feasible implementation manner, by constructing the added input / output block, a complete input / output block can be allocated to the target module in the scenario of tight memory resources, thereby improving the allocation accuracy of memory resources.

[0128] A feasible implementation manner is that the input / output block area further includes: the next input / output block identifier, the flag bit, the number of free pages, the number of free input / output blocks, and the memory page array.

[0129] Exemplarily, the next input / output block identifier is a link pointer of the user-state free list, used to point to the next free input / output block. By using the next input / output block identifier, global scanning can be avoided, thereby reducing the complexity of obtaining the input / output block. The flag bit can be used to represent the status of the input / output block (such as locked or persistent storage, etc.). The number of free pages can be the count value of free memory pages. The number of free input / output blocks can be the count value of free input / output blocks. The memory page array can be used to store the physical addresses corresponding to the memory pages for quickly locating the physical addresses corresponding to the memory pages.

[0130] In this feasible implementation manner, through the information of multiple fields, the input / output blocks can be managed from multiple dimensions, thereby improving the reliability of management.

[0131] A feasible implementation manner is that the user-state sub-resource pool further includes a metadata area, and the metadata area stores the 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 / output blocks, hardware and topology information, cluster configuration information (such as CXL switch addresses, or a list of CXL devices, etc.), or the health status of the resource pool, etc.

[0133] Exemplarily, through various metadata, the user-mode sub-resource pool can be managed holistically from multiple dimensions to promptly 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 enhancing the reliability of management.

[0135] A feasible implementation, the memory resource allocation method may further include: determining 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; determining the total number of memory pages as an intermediate variable; 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 pages in the input / output block area; until the first condition or the second condition is met, then perform area allocation for the user-mode sub-resource pool according to 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 number 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: where the preset process includes: updating the number of iterations, determining the number of management pages according to the intermediate variable and the corresponding relationship, and determining the number of physical pages as the difference between the total number of memory pages and the number of management pages.

[0136] Exemplarily, the user-mode sub-resource pool includes memory pages, physical pages, and management pages. The memory pages, physical pages, and management pages all occupy the space of the user-mode sub-resource pool, and a reasonable allocation method for the space is determined through iterative processing.

[0137] Exemplarily, the number of physical pages is the total amount of physical memory that the user-mode sub-resource pool needs to manage. The corresponding relationship between the number of physical pages and the number of management pages represents the mathematical relationship of how much management memory is required per unit of business memory (for example: 8 pages of management overhead are required for every 512 business pages). The intermediate variable is the current trial number of business memory pages. The number of iterations is used to prevent infinite loops.

[0138] Exemplarily, it terminates when the number of iterations is greater than the second number threshold and the intermediate variable is less than the number of physical pages, to avoid increased overhead due to infinite loops. When the intermediate variable is equal to the number of physical pages, it means that a balance point has been found.

[0139] In this feasible implementation, through iterative operations, the area of the user-mode sub-resource pool can be effectively balanced, thereby effectively managing the user-mode sub-resource pool.

[0140] A feasible implementation manner, the method for allocating memory resources further includes: determining the module identifier of the target module; generating a reservation mark according to the module identifier; adding the reservation mark to the target memory resources to prohibit the target memory management module from allocating the target memory resources to other modules when the target memory resources are in the user-state sub-resource pool.

[0141] Exemplarily, the reservation mark is used to pre-allocate the target memory resources for the target module.

[0142] Combined with a scenario example for illustration, for the memory resources without the reservation mark, after the memory resources return to the user-state sub-resource pool, the memory resources can be allocated to any module. For the target memory resources with the reservation mark, after the target module finishes using and returns the target memory resources to the user-state sub-resource pool, the target memory resources are in a locked state and can only be allocated to the target module.

[0143] Combined with a scenario example for illustration, through the reservation mark, memory resources can be reserved for the module, so that when the module applies for memory resources, the user-state sub-resource pool contains sufficient memory resources.

[0144] In this feasible implementation manner, through the reservation mark, it can be ensured that the user-state sub-resource pool can meet the memory resource requirements of the target module, thereby improving the reliability of memory resource allocation.

[0145] A feasible implementation manner, the method for allocating memory resources may further include: if the duration of the target memory resources in the user-state sub-resource pool is greater than or equal to the duration threshold, then delete the reservation mark from the target memory resources.

[0146] Exemplarily, the duration is greater than or equal to the duration threshold, indicating that the target memory resources are locked for too long. During this period, no module has used the target memory resources, resulting in an unreasonable memory resource allocation problem.

[0147] Optionally, the duration threshold can be adaptively adjusted according to the amount of available resources in the user-state sub-resource pool to reduce the impact of locked memory resources on module usage.

[0148] In this feasible implementation manner, by periodically clearing the reservation mark, it is avoided that the memory resources are locked for a long time and affect the allocation, thereby improving the reliability of memory management.

[0149] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation manner.

[0150] Figure 7The structural schematic diagram of the memory resource allocation device provided by the embodiment of the present application. As Figure 7 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 obtaining module 73, and an allocating module 74, where

[0151] The receiving module 71 is configured to receive 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.

[0152] The determining module 72 is configured to determine a target memory management module corresponding to the target memory attribute according to the memory resource request.

[0153] The obtaining module 73 is configured to determine, through the target memory management module, a target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool corresponding to the target memory unit. The memory resources in the user-mode sub-resource pool are obtained by a one-time call during the initialization process of the user-mode sub-resource pool.

[0154] The allocating module 74 is configured to allocate the target memory resource to the target module.

[0155] Optionally, the receiving module 71 may execute Figure 2 S201 in the embodiment.

[0156] Optionally, the determining module 72 may execute Figure 2 S202 in the embodiment.

[0157] Optionally, the obtaining module 73 may execute Figure 2 S203 in the embodiment.

[0158] Optionally, the allocating 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 may execute the technical solutions shown in the above method embodiments. The implementation principles and beneficial effects are similar, and will not be elaborated here.

[0160] In a possible implementation manner, the determining module 72 is specifically configured to:

[0161] Determine a corresponding target memory type according to the target memory attribute. The target memory type is dynamic random access memory or compute express link memory;

[0162] Determine the target memory management module according to the target memory type. The target memory management module is used to manage the resource pool of dynamic random access memory or the resource pool of compute express link memory.

[0163] Figure 8 This is a schematic structural diagram of an allocation device for memory resources provided by an embodiment of the present application. Based on the embodiment shown in Figure 7 as shown in 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, where

[0164] The judgment module 75 is used to: determine the available resource amount of the user-mode sub-resource pool;

[0165] judge whether the target memory capacity is less than or equal to the available resource amount;

[0166] If so, determine the target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool;

[0167] If not, determine the temporary memory resource from the upper-level resource pool of the user-mode sub-resource pool, allocate the temporary memory resource to the user-mode sub-resource pool, and determine the target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool.

[0168] The sending module 76 is used to: determine the usage status of the temporary memory resource, and the usage status is in use or completed;

[0169] If the usage status is completed, send the temporary memory resource to the upper-level resource pool.

[0170] The initialization module 77 is used to: determine the memory resource quota of the user-mode sub-resource pool according to the total amount of memory resources in the root resource pool;

[0171] According to the memory resource quota, determine the initial memory resource from the upper-level resource pool and allocate the initial memory resource to the user-mode sub-resource pool.

[0172] The adjustment module 78 is used to: determine the resource allocation record of the user-mode sub-resource pool, and the resource allocation record includes the number of times that the available resource amount of the user-mode sub-resource pool is insufficient;

[0173] If the number of times is greater than or equal to the first threshold, adjust the quota of the user-mode sub-resource pool.

[0174] The memory resource request further includes a target page number, and the target memory unit is a memory page; the first execution module 79 is used to: determine a multi-level page table from the page table area of the user-mode 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;

[0175] Determine the starting address of the second-level page table;

[0176] Determine the offset of the address of the target pointer corresponding to the target page number relative to the starting address according to the target page number;

[0177] Obtain the target pointer in the second-level page table according to the offset;

[0178] Determine the target memory page pointed to by the target pointer from the user-mode sub-resource pool, and determine the target memory page as the target memory resource.

[0179] In a possible implementation manner, the first execution module 79 is specifically configured to: determine the target address of the target pointer in the second-level page table according to the starting address and the offset;

[0180] Obtain the target pointer from the target address.

[0181] The adding module 710 is configured 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 general memory area of the user-mode sub-resource pool.

[0183] In a possible implementation manner, the multi-level page table further includes a first-level page table. The first-level page table includes a plurality of first-level page table entries. Each first-level page table entry includes a plurality of first-level pointers. Each first-level pointer points to a corresponding second-level page table entry in the second-level page table. Among them, each second-level page table entry includes a plurality of second-level pointers.

[0184] The target memory unit is an input / output block; the second execution module 711 is configured to: determine a free linked 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 linked list. Each candidate input / output block includes a plurality of memory pages;

[0185] Determine a plurality of status bitmaps from the plurality of candidate input / output blocks determined from the input / output block area. Each status bitmap represents the free status of the plurality of memory pages in the corresponding candidate input / output block;

[0186] According to the plurality of status bitmaps, determine a target input / output block from the plurality of candidate input / output blocks, and determine the target input / output block as the target memory resource. The free status in the status bitmap corresponding to the target input / output block is all free.

[0187] Among the plurality of candidate input / output blocks, there is no input / output block in which the free status in the status bitmap is all free; the construction module 712 is configured to: allocate a plurality of free memory pages from the free page area of the user-mode sub-resource pool;

[0188] Construct a new input / output block through the plurality of free memory pages, and add the new input / output block to the free linked list;

[0189] Determine the newly added input / output block as the target memory resource.

[0190] In a possible implementation, the input / output block area further includes: the next input / output block identifier, a flag bit, the number of free pages, the number of free input / output blocks, and an array of memory page numbers.

[0191] In a possible implementation, the user-mode sub-resource pool further includes a metadata area that stores the metadata of the user-mode sub-resource pool.

[0192] The management module 713 is configured to: determine the total number of memory pages of 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 execute a preset process to obtain the number of physical pages and the number of management pages. The number of management pages includes the number of pages of the second-level page table, the number of pages in the free page area, and the pages in the input / output block area;

[0195] Until the first condition or the second condition is satisfied, then perform area allocation on the user-mode sub-resource pool according to 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, and the second condition is that the intermediate variable is equal to the number of physical pages:

[0196] Wherein, the preset process includes: updating the number of iterations, determining the number of management pages according to the intermediate variable and the corresponding relationship, and determining the number of physical pages as the difference between the total number of memory pages and the number of management pages.

[0197] The reservation module 714 is configured to: determine the module identifier of the target module;

[0198] Generate a reservation mark according to the module identifier;

[0199] Add the reservation mark to the target memory resource to prevent the target memory management module from allocating the target memory resource to other modules when the target memory resource is in the user-mode sub-resource pool.

[0200] The removal module 715 is configured to: if the duration of the target memory resource in the user-mode sub-resource pool is greater than or equal to the duration threshold, then delete the reservation mark from the target memory resource.

[0201] For the description of the features in the embodiments corresponding to the memory resource allocation device, reference can be made to the relevant description in the embodiments corresponding to the memory resource allocation method, which will not be elaborated here one by one.

[0202] Figure 9 This is a schematic structural diagram of the electronic device provided by this application. As Figure 9As shown in the figure, 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. Among them, the processor 901, the memory 902, and the communication component 903 are connected through a bus.

[0203] In the specific implementation process, at least one processor 901 executes the computer execution instructions stored in the memory 902, so that at least one processor 901 executes the above-mentioned embodiment of the memory resource allocation method.

[0204] For the specific implementation process of the processor 901, reference can be made to the above method embodiment. The implementation principle and technical effect are similar, and will not be elaborated here in this embodiment.

[0205] In the above embodiment, it should be understood that the processor may be a central processing unit (Central Processing Unit, abbreviated as: CPU), or other general-purpose processors, digital signal processors (Digital Signal Processor, abbreviated as: DSP), application specific integrated circuits (Application Specific Integrated Circuit, abbreviated as: ASIC), etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the application can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.

[0206] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.

[0207] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, the bus in the attached drawings of this application is not limited to only one bus or one type of bus.

[0208] The embodiment of the present application also provides a non-volatile computer-readable storage medium, in which a computer program is stored, and the computer program is set to execute the steps in any of the above-mentioned embodiments of the memory resource allocation method when running.

[0209] In an exemplary embodiment, the above non-volatile computer-readable storage medium may include, but is not limited to: various media such as USB flash drives, read-only memory (ROM for short), random access memory (RAM for short), external hard drives, magnetic disks, or optical discs that can store computer programs.

[0210] An embodiment of the present application also provides a computer program product. The above computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above embodiments of the memory resource allocation method.

[0211] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above embodiments of the memory resource allocation method.

[0212] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Skilled professionals can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of the present application.

[0213] The above has introduced in detail a memory resource allocation method, device, electronic device, medium, and product provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in the technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. A method for allocating memory resources, characterized in that Including: Receiving 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; Determining a target memory management module corresponding to the target memory attribute according to the memory resource request; Determining, through the target memory management module, a target memory resource corresponding to the target memory capacity from a user-mode sub-resource pool corresponding to the target memory unit, where the memory resources in the user-mode sub-resource pool are obtained by a one-time call during the initialization process of the user-mode sub-resource pool; Allocating the target memory resource to the target module.

2. The memory resource allocation method according to claim 1, characterized in that, 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, where the target memory type is dynamic random access memory or compute express link memory; Determining the 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 manage a resource pool of compute express link memory.

3. The allocation method of memory resources according to claim 2, characterized in that, Determining, from a user-mode sub-resource pool corresponding to the target memory unit, a target memory resource corresponding to the target memory capacity includes: Determining the available resource amount of the user-mode sub-resource pool; Judging whether the target memory capacity is less than or equal to the available resource amount; If so, determining a target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool; If not, determining a temporary memory resource from a higher-level resource pool of the user-mode sub-resource pool, allocating the temporary memory resource to the user-mode sub-resource pool, and determining a target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool.

4. The allocation method of memory resources according to claim 3, wherein, The method further includes: Determining the usage status of the temporary memory resource, where the usage status is in use or use completed; If the usage status is use completed, sending the temporary memory resource to the higher-level resource pool.

5. The allocation method of memory resources according to claim 3, wherein The method further includes: Determining a memory resource quota of the user-mode sub-resource pool according to the total amount of memory resources in the root resource pool; Determining an initial memory resource from the higher-level resource pool according to the memory resource quota, and allocating the initial memory resource to the user-mode sub-resource pool.

6. The method for allocating memory resources according to claim 5, characterized in that, The method further includes: Determining a resource allocation record of the user-mode sub-resource pool, where the resource allocation record includes the number of times when the available resource amount of the user-mode sub-resource pool is insufficient; If the number of times is greater than or equal to a first number threshold, adjusting the quota of the user-mode sub-resource pool.

7. The method for allocating memory resources according to claim 3, wherein, The memory resource request further includes a target page number, and the target memory unit is a memory page; Determining, from a user-mode sub-resource pool corresponding to the target memory unit, a target memory resource corresponding to the target memory capacity includes: Determining a multi-level page table from a page table area of the user-mode sub-resource pool, where the multi-level page table is used to locate a memory page, and the multi-level page table includes a second-level page table; Determining the starting address of the second-level page table; Determining an offset of an address of a target pointer corresponding to the target page number relative to the starting address according to the target page number; Obtain the target pointer in the second-level page table according to the offset; Determine the target memory page pointed to by the target pointer from the user-mode sub-resource pool, and determine the target memory page as the target memory resource.

8. The method for allocating memory resources according to claim 7, wherein Obtaining the target pointer in the second-level page table according to the offset includes: Determine the target address of the target pointer in the second-level page table according to the starting address and the offset; Obtain the target pointer from the target address.

9. The allocation method of memory resources according to claim 8, wherein The method further includes: Remove the target memory page from the free page area of the user-mode sub-resource pool; Add the target memory page to the general memory area of the user-mode sub-resource pool.

10. The allocation method of memory resources according to claim 7, wherein, The multi-level page table further includes a first-level page table, the first-level page table includes a plurality of first-level page table entries, each first-level page table entry includes a plurality of first-level pointers, and 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 a plurality of second-level pointers.

11. The memory resource allocation method according to claim 3, characterized in that, The target memory unit is an input / output block; Determine the target memory resource corresponding to the target memory capacity from the user-mode sub-resource pool corresponding to the target memory unit, including: 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, and each candidate input / output block includes a plurality of memory pages; Determine a plurality of status bitmaps from the plurality of candidate input / output blocks determined in the input / output block area, and each status bitmap represents the free status of a plurality of memory pages in the corresponding candidate input / output block; According to the plurality of status bitmaps, determine a target input / output block from the plurality of candidate input / output blocks, and determine the target input / output block as the target memory resource, and the free status in the status bitmap corresponding to the target input / output block is all free.

12. The memory resource allocation method according to claim 11, characterized in that, If the free status in the status bitmap of the plurality of candidate input / output blocks does not include an input / output block that is all free; then the method further includes: Allocate a plurality of free memory pages from the free page area of the user-mode sub-resource pool; Construct a new input / output block through the plurality of free memory pages, and add the new input / output block to the free list; Determine the new input / output block as the target memory resource.

13. The memory resource allocation method according to claim 12, characterized in that, The input / output block area further includes: a next input / output block identifier, a flag bit, a free page count, a free input / output block count, and a memory page number array.

14. The allocation method of memory resources according to any one of claims 7-13, characterized in that The user-mode sub-resource pool further includes a metadata area, and the metadata area stores the metadata of the user-mode sub-resource pool.

15. The memory resource allocation method according to claim 14, wherein The method further includes: Determine the total number of memory pages of the user-mode sub-resource pool, and the corresponding relationship between the number of physical pages and the number of management pages; Determine the total number of memory pages as an intermediate variable; Iteratively execute a preset process to obtain the number of physical pages and the number of management pages, and the number of management pages includes the number of pages of the second-level page table, the number of pages of the free page area, and the pages of the input / output block area; Until the first condition or the second condition is satisfied, regional allocation is performed on the user-mode sub-resource pool according to 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, and the second condition is that the intermediate variable is equal to the number of physical pages: Among them, the preset processing includes: updating the number of iterations, determining the number of management pages according to the intermediate variable and the corresponding relationship, and determining the number of physical pages as the difference between the total number of memory pages and the number of management pages.

16. The memory resource allocation method according to claim 1, characterized in that, The method further includes: Determining the module identifier of the target module; Generating a reservation mark according to the module identifier; Adding the 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-mode sub-resource pool.

17. The memory resource allocation method according to claim 16, characterized in that, The method further includes: If the duration for which the target memory resource is located in the user-mode sub-resource pool is greater than or equal to the duration threshold, deleting the reservation mark from the target memory resource.

18. An electronic device, characterized in that, Including: A memory for storing a computer program; A processor for implementing the steps of the memory resource allocation method according to any one of claims 1 to 17 when executing the computer program.

19. A non-volatile computer-readable storage medium, characterized in that, A non-volatile computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the memory resource allocation method according to any one of claims 1 to 17.

20. A computer program product, comprising a computer program, characterized in that, The computer program, when executed by a processor, implements the steps of the memory resource allocation method according to any one of claims 1 to 17.

Citation Information

Patent Citations

  • Memory mapping method and memory mapping module

    CN103257936A

  • Subsystem memory management method and device

    CN116049023A

  • Memory management method for microkernel architecture operating system

    CN118069545A

  • Model training parameter storage method and device

    CN119598203A

  • Memory allocation method and device, electronic equipment and nonvolatile storage medium

    CN119690862A

Cited By

  • Resource management method and device, equipment, storage medium and program product

    CN120953045A