Memory allocation method, computer device, storage medium, and product
By defining dedicated APIs and memory mapping interfaces, the performance instability caused by the mixed use of CXL memory and local memory in the server was resolved, achieving stable CXL memory allocation and performance improvement.
Patent Information
- Application Number
- PCT/CN2025/084161
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-04-30
- Filing Date
- 2025-03-21
- Publication Date
- 2025-11-06
AI Technical Summary
Using both regular local memory and CXL memory simultaneously in a server can lead to performance instability and fluctuating access speeds.
Define a dedicated application programming interface for allocating CXL memory. Pass the CXL memory identifier to the kernel mode through the memory mapping interface, allocate hardware resources related to CXL memory in the kernel mode, divide the memory allocation pools of CXL memory and local memory in user mode, and add a memory mapping flag to distinguish memory types.
This ensures that users can use CXL memory stably, reduces the amount of code modification, and improves the stability and performance of memory allocation.
Smart Images

Figure CN2025084161_06112025_PF_FP_ABST
Abstract
Description
Memory allocation method, computer device, storage medium and product
[0001] Cross-reference of Related Applications
[0002] The present application claims priority to the Chinese patent application No. 202410535902.9, filed on April 30, 2024, and entitled "Memory allocation method, computer device, storage medium and product", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD
[0003] The present application relates to the technical field of memory management, in particular to a memory allocation method, a computer device, a storage medium and a product. BACKGROUND
[0004] Compared with the traditional ordinary local memory, the CXL (Compute Express Link) memory can expand the memory capacity and improve the memory resource access bandwidth, but the CXL memory has higher latency.
[0005] When the ordinary local memory and the CXL memory are used simultaneously in a server, the user is mixedly allocated the local memory and the CXL memory, resulting in unstable performance. SUMMARY
[0006] Therefore, the present application provides a memory allocation method, a computer device, a storage medium and a product to solve the problem of unstable performance when allocating memory.
[0007] In a first aspect, the present application provides a memory allocation method, comprising:
[0008] defining a special application program interface for allocating CXL memory;
[0009] obtaining a calling request for calling the application program interface;
[0010] in the case where the calling request is used to call the special application program interface, generating a CXL memory identifier representing the allocation of the CXL memory;
[0011] passing the CXL memory identifier to the kernel state through a memory mapping interface, and allocating hardware resources related to the CXL memory in the kernel state.
[0012] In some optional embodiments, defining a special application program interface for allocating CXL memory comprises:
[0013] modifying the function name of the standard application program interface according to the same modification rule, and taking the modified function name as the function name in the special application program interface; the standard application program interface is used to allocate memory.
[0014] In some optional embodiments, defining a dedicated application interface for allocating CXL memory further comprises:
[0015] Defining for the dedicated application interface at least one of: a first obtaining function for obtaining a total amount of CXL memory regions requested, a second obtaining function for obtaining a total amount of CXL memory regions allocated through a client development package, a third obtaining function for obtaining a number of available bytes of a specified CXL memory region, a fourth obtaining function for obtaining a total amount of CXL memory regions in a specified memory node, a fifth obtaining function for obtaining a number of available bytes of a CXL memory region in a specified memory node, a sixth obtaining function for obtaining state data of a plurality of CXL memory regions, and a seventh obtaining function for obtaining state data of corresponding CXL memory regions under a plurality of memory nodes.
[0016] In some optional embodiments, the method further comprises:
[0017] Dividing a first memory allocation pool for allocating CXL memory in a user mode and a second memory allocation pool for allocating local memory in the user mode;
[0018] In a case where a call request is made for calling the dedicated application interface, the first memory allocation pool is selected;
[0019] Allocating memory space in the first memory allocation pool according to the call request to allocate CXL memory in the user mode.
[0020] In some optional embodiments, allocating memory space in the first memory allocation pool according to the call request comprises:
[0021] Determining a memory allocation function corresponding to the call request;
[0022] Adding a memory mapping flag in the user mode in the memory allocation function, and assigning the memory mapping flag according to a CXL memory identifier; the memory mapping flag is used to indicate whether to allocate CXL memory;
[0023] Allocating memory space in the first memory allocation pool according to the memory allocation function.
[0024] In some optional embodiments, adding the memory mapping flag in the user mode in the memory allocation function comprises:
[0025] Adding the memory mapping flag in the user mode in a memory allocation structure in the memory allocation pool.
[0026] In some optional embodiments, the method further comprises:
[0027] A setting function is preset for setting the memory mapping flag;
[0028] When a memory allocation pool is created, the setting function is called to set the memory mapping flag of the created memory allocation pool to a default value, and the default value indicates that local memory is allocated;
[0029] The memory mapping flag is assigned according to the CXL memory identifier, including:
[0030] The setting function is called to assign the CXL memory identifier to the memory mapping flag.
[0031] In some optional embodiments, the CXL memory identifier is passed to the kernel state through a memory mapping interface, including:
[0032] Based on the memory allocation kernel function in the memory management file, the obtaining function for obtaining the memory mapping flag is called to obtain the memory mapping flag;
[0033] The memory mapping flag passing function is set, and the memory mapping flag is passed according to the memory mapping flag passing function;
[0034] The memory mapping flag is added in the operating system memory page mapping function of the memory page file to pass the memory mapping flag to the memory mapping interface of the kernel.
[0035] In some optional embodiments, the memory mapping flag is passed according to the memory mapping flag passing function, including:
[0036] The memory mapping flag is merged into a local variable representing an interleaving strategy;
[0037] The local variable is passed according to the memory mapping flag passing function.
[0038] In some optional embodiments, a first memory allocation pool for allocating CXL memory of a user state and a second memory allocation pool for allocating local memory of a user state are divided, including:
[0039] A plurality of memory allocation pools are allocated for each core of the processor, and part of the memory allocation pools are used as the first memory allocation pool for allocating CXL memory of a user state, and another part of the memory allocation pools are used as the second memory allocation pool for allocating local memory of a user state.
[0040] In some optional embodiments, hardware resources related to CXL memory are allocated in the kernel state, including:
[0041] A CXL memory allocation area is divided for independently managing kernel space CXL memory;
[0042] According to the allocation request, the memory space in the CXL memory allocation area is allocated to allocate the hardware resources related to the CXL memory.
[0043] In some optional embodiments, the CXL memory allocation area for independently managing the kernel space CXL memory is divided, including:
[0044] A type corresponding to the CXL memory allocation area is added in the memory region type of the memory region management header file of the operating system kernel;
[0045] The memory mapping system call interface in the kernel state is extended, and the memory mapping system call interface is added with a flag indicating mapping CXL memory and a flag indicating mapping local memory.
[0046] In some optional embodiments, the CXL memory allocation area for independently managing the kernel space CXL memory is divided, further including:
[0047] A sub-memory region structure body is added in the memory region management header file, and each sub-memory region structure body corresponds to a CXL memory;
[0048] The sub-memory region structure body includes memory region data, memory start address and memory end address; wherein the memory region data is generated compatibly on the basis of the existing memory allocation area.
[0049] In some optional embodiments, the CXL memory allocation area for independently managing the kernel space CXL memory is divided, further including:
[0050] A sub-memory region index structure body is added in the memory region management header file; the sub-memory region index structure body includes a pointer of the corresponding sub-memory region and an index identifier of the sub-memory region in the sub-memory region list.
[0051] In some optional embodiments, the CXL memory allocation area for independently managing the kernel space CXL memory is divided, further including:
[0052] A variable is added to the memory region structure body in the memory region management header file; the added variable includes: a free sub-memory region queue structure body, a sub-memory region list, a sub-memory region number and an index identifier of the currently allocated sub-memory region.
[0053] In some optional embodiments, according to the allocation request, the memory space in the CXL memory allocation area is allocated, including:
[0054] The index identifier of the next sub-memory region is obtained from the linked list of the free sub-memory region;
[0055] According to the index identifier of the next sub-memory area, an idle sub-memory area is located from the idle sub-memory area queue structure, and memory allocation is performed according to the idle sub-memory area.
[0056] In some optional embodiments, the method further includes:
[0057] The CXL memory configuration options are encapsulated in a macro definition, and the macro definition is selectively enabled in the kernel configuration; the CXL memory configuration options include at least one of modified code, added functions, and variables to the operating system kernel.
[0058] In a third aspect, the present application provides a computer device, comprising: a memory and a processor, which are in communication connection with each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the memory allocation method of the first aspect or any of the corresponding embodiments thereof.
[0059] In a third aspect, the present application provides a computer non-transitory readable storage medium, which stores computer instructions, and the computer instructions are used to make a computer execute the memory allocation method of the first aspect or any of the corresponding embodiments thereof.
[0060] In a fourth aspect, the present application provides a computer program product, which comprises computer instructions, and the computer instructions are used to make a computer execute the memory allocation method of the first aspect or any of the corresponding embodiments thereof.
[0061] The present application defines a special API (Application Programming Interface) specially used for allocating CXL memory, and a user can realize the allocation of CXL memory by calling the special API, at this time, no local memory is allocated to the user, so that it can be ensured that the user can stably use the CXL memory; and by defining the special API, when the user needs to allocate CXL memory, the user only needs to modify the called API, the code modification amount of the user side is small, and the human cost caused by code modification can be reduced. BRIEF DESCRIPTION OF DRAWINGS
[0062] In order to more clearly illustrate the technical solutions in the specific embodiments or the related art, the drawings needed to be used in the specific embodiments or the related art description will be briefly introduced. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can also obtain other drawings according to these drawings without creative labor.
[0063] FIG. 1 is a flow diagram of a memory allocation method according to an embodiment of the present application;
[0064] FIG. 2 is a flow diagram of another memory allocation method according to an embodiment of the present application;
[0065] FIG. 3 is a process diagram of memory allocation by selecting a memory allocation pool according to an embodiment of the present application;
[0066] FIG. 4 is a process diagram of passing a memory mapping flag to a kernel according to an embodiment of the present application;
[0067] FIG. 5 is a flow diagram of still another memory allocation method according to an embodiment of the present application;
[0068] FIG. 6 is a hierarchical logical memory view of an operating system kernel according to an embodiment of the present application;
[0069] FIG. 7 is a whole process diagram of implementing memory allocation according to an embodiment of the present application;
[0070] FIG. 8 is a structural block diagram of a memory allocation apparatus according to an embodiment of the present application;
[0071] FIG. 9 is a hardware structure diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0072] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0073] CXL (Compute Express Link) is a brand-new device interconnection technology standard. Based on CXL technology, computing, memory, storage and network can be decoupled, and persistent memory can be provided on a CXL bus. The key feature of CXL is that it supports cache-coherent memory access semantics (Cache-coherent Load / Store). CXL not only supports capacity and bandwidth expansion of memory subsystems, but also can be used for interconnection between heterogeneous processors and peripheral devices such as GPUs (Graphics Processing Units) and smart network cards, to realize decoupling and pooling of computing resources and memory resources.
[0074] CXL provides a high-speed interconnection technology of hundreds of nanoseconds. The type 3 device specified in the CXL protocol is a CXL memory module or a CXL memory allocation pool, that is, CXL memory. This device can expand the memory capacity and improve the memory resource access bandwidth. At the same time, the CXL memory module does not occupy the memory slot on the server. The forms of CXL memory mainly include three types: E3.S-shaped memory module, ASIC (Application Specific Integrated Circuit) memory card, and JBOM (memory box). Among them, the ASIC memory card is generally inserted into the server PCIe (Peripheral Component Interconnect express, a high-speed serial computer expansion bus standard) slot, and then several DDR (Double Data Rate) memories such as 4, 8, etc. are inserted into the card.
[0075] Compared with the traditional DDR memory, the CXL memory has the following characteristics:
[0076] 1) Latency: The latency of E3.S memory module and ASIC memory card is twice that of local DDR memory. The local memory is about 100ns, and the CXL memory is about 200ns-250ns. The latency difference between the two memories is more than 2 times, which will actually affect the application performance and need to be used in layers. The latency of JBOM+CXL 2.0 switch is higher, reaching 500ns, which is about 5 times the latency of local memory.
[0077] 2) Capacity: CXL memory does not occupy DIMM (Dual-Inline-Memory-Modules) slot and CPU (Central Processing Unit) memory channel, and can realize capacity expansion.
[0078] 3) Bandwidth: CXL memory does not occupy DIMM slot and CPU memory channel, and can realize bandwidth expansion.
[0079] Using ordinary local memory (such as DDR memory) and CXL memory on a server at the same time will cause performance instability. Alternatively, when a user applies for memory space to the operating system, for example, the user uses the malloc function (C language, dynamic memory allocation function) to apply for memory space to the operating system, and the operating system will provide memory to the user according to its own strategy. However, since the operating system does not distinguish between ordinary local memory and CXL memory, when the user applies for CXL memory, the access speed will be slow. Overall, the user sometimes accesses the memory fast and sometimes slow, and the fast and slow latency will exceed 2 times.
[0080] The memory allocation method provided in the embodiments of the present application defines an application program interface for allocating CXL memory for a user, and the user can request allocation of CXL memory by calling the application program interface, at this time, no local memory is allocated to the user, thereby ensuring that the user can stably use the CXL memory.
[0081] According to the embodiments of the present application, a memory allocation method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0082] In the embodiments, a memory allocation method is provided, which can be applied to devices that need to allocate memory, such as terminals, servers, etc. Optionally, the method can be implemented by relying on storage software (such as memory software) for memory allocation. FIG. 1 is a flowchart of the memory allocation method according to the embodiments of the present application, as shown in FIG. 1, the flow includes the following steps.
[0083] Step S101, defining a special application program interface for allocating CXL memory.
[0084] When a user needs to allocate memory, such as when the user needs to apply for memory, the memory allocation can be achieved by calling the application program interface (Application Programming Interface, API) provided by the storage software. For the convenience of description, the application program interface is referred to as a standard application program interface, and is referred to as a standard API hereinafter. When there are local memory (such as DDR memory) and CXL memory on the server at the same time, if the memory allocation is based on the standard API, the operating system will not distinguish between local memory and CXL memory; when the user applies for local memory, the access speed is fast, and when the user applies for CXL memory, the access speed is slow, thereby causing the problem of fast and slow access speed, resulting in unstable memory performance.
[0085] In the embodiments, a special application program interface for allocating CXL memory is defined for a user, which is referred to as a special application program interface, and is referred to as a special API hereinafter. When the user uses the special API to allocate memory, it can be determined that CXL memory needs to be allocated at present.
[0086] It should be noted that the "allocation" of memory in the embodiments refers to any one or more of the following operations: applying for memory, releasing (recycling) memory, memory initialization, memory expansion, memory contraction, memory alignment, etc., which can be determined based on actual conditions.
[0087] Step S102, obtaining a calling request for calling an application program interface.
[0088] When the user needs to allocate memory, the calling request can be initiated by calling the application program interface; for example, when the user's application program needs to apply for a piece of memory, a function for applying for memory in the application program interface can be called.
[0089] In the embodiment, since the special API for allocating CXL memory is provided, when the user needs to call CXL memory, the special API can be called, and a corresponding function in the special API can be called to complete the required memory allocation requirement. Moreover, the standard API is still retained, that is, the standard API is still provided externally; when the user does not need to deliberately allocate CXL memory, the standard API can still be called.
[0090] For example, when the user needs a large amount of memory space and the performance requirement is not so high, the user can directly apply for CXL memory to the operating system, that is, the special API is called; when the user needs a small amount of memory and requires high performance (for example, low latency), the standard API provided by default can be used.
[0091] Step S103, in the case where the calling request is for calling the special application program interface, generating a CXL memory identifier indicating allocation of CXL memory.
[0092] In the embodiment, in the user mode, whether the current calling request is for calling the special application program interface can be determined based on which application program interface is called by the calling request. For example, if the memory allocation function currently called by the user is a function in the special API, it can be determined that the special API is currently called by the user, that is, the user currently requests allocation of CXL memory.
[0093] If the calling request initiated by the user is for calling the special API, it can be determined that the user currently requests allocation of CXL memory, and in this case, a corresponding identifier is generated to indicate that CXL memory needs to be currently allocated; for the convenience of description, the identifier is referred to as CXL memory identifier (MAP_CXLMEM). The CXL memory identifier (MAP_CXLMEM) can be represented by a certain flag bit, that is, different values are used to represent whether CXL memory needs to be allocated.
[0094] It can be understood that when the user does not need to allocate the CXL memory, for example, the user currently needs to allocate the normal local memory (for example, the DDR memory), the user can still call in the manner of calling the standard API, and the user does not need to modify the program code of calling the standard API, and the memory allocated to the user is generally the mixed memory including the local memory and the CXL memory. When the user needs to allocate the CXL memory, only the API needs to be modified, that is, the code related to the API calling in the application is modified from the standard API to the special API, and the amount of code modification on the user side is small.
[0095] In step S104, the CXL memory identifier is transmitted to the kernel state through the memory mapping interface, and the hardware resource related to the CXL memory is allocated in the kernel state.
[0096] In the embodiment, when the calling request is obtained in the user state and it is determined whether the calling request is used to call the special API, the CXL memory identifier (MAP_CXLMEM) is generated in the user state, and the CXL memory identifier (MAP_CXLMEM) needs to be transmitted to the kernel state for the CXL memory capable of operating the hardware resource.
[0097] Optionally, the identifier of the allocated CXL memory (that is, the CXL memory identifier) is brought to the operating system kernel (for example, the Linux kernel) through the memory mapping interface (that is, the mmap interface) of the operating system. Generally, the memory management in the user state is implemented based on the memory allocator (for example, jemalloc), and the system call can be made through the memory mapping interface downward, so that the Linux kernel can be accessed.
[0098] The memory allocation method provided in the embodiment defines the special API specially used for allocating the CXL memory, and the user can realize the allocation of the CXL memory by calling the special API, and the local memory is not allocated to the user at this time, so that it can be guaranteed that the user can stably use the CXL memory. Moreover, by defining the special API, when the user needs to allocate the CXL memory, only the API needs to be modified, and the amount of code modification on the user side is small, and the human cost caused by modifying the code can be reduced.
[0099] In the embodiment, a memory allocation method is provided, which can be applied to a device needing to perform memory allocation. FIG. 2 is a flowchart of the memory allocation method according to the embodiment of the application. As shown in FIG. 2, the flowchart includes the following steps.
[0100] In step S201, a special application program interface (API) used for allocating the CXL memory is defined.
[0101] For details, refer to step S101 of the embodiment shown in FIG. 1, which will not be repeated here.
[0102] In some optional embodiments, the step S201 of defining a dedicated application program interface for allocating CXL memory comprises: modifying a function name of a standard application program interface according to a same modification rule, and taking the modified function name as a function name in the dedicated application program interface; the standard application program interface is used for allocating memory.
[0103] In the embodiment, when memory allocation is needed, a standard API provided by a memory allocator is generally called; for example, a user normally accesses memory through a malloc function in the standard API provided by a jemalloc library. The standard API normally based on C language for applying and releasing memory, and part of memory allocation functions of the standard API can be seen in Table 1.
[0104] Table 1
[0105] In the embodiment, when the dedicated API is defined, the standard API is modified to obtain the required dedicated API. Alternatively, the function name of the function in the standard API is modified, and the modified function name is taken as the function name of the corresponding function in the dedicated API; and for different function names, a unified modification rule is used for modification, so that the function name in the dedicated API corresponds to the function name in the standard API.
[0106] The modification rule for modifying the function name can be that a prefix or a suffix is added to the original function name. For example, a prefix “in” can be added to the original function name to generate the function name in the dedicated API. Alternatively, for the memory application function malloc in the standard API, the prefix “in” is added to generate the memory application function in_malloc in the dedicated API, and similarly, for the memory reallocation function realloc and the memory recovery function free in the standard API, the memory reallocation function in_realloc and the memory recovery function in_free in the dedicated API can also be generated.
[0107] If the user currently applies local memory (calls the standard API), and needs to apply CXL memory at this time, only the function name of the called API needs to be modified, that is, the prefix “in” is added to the function name of the originally called API, so that the dedicated API is called, and CXL memory is applied, and the amount of user-side code modification is small.
[0108] In addition, alternatively, in the embodiment, a plurality of obtaining functions for returning corresponding parameters are also defined for the dedicated application program interface, and the obtaining functions can include at least one of the following obtaining functions:
[0109] A first obtaining function for obtaining the total amount (i.e., total bytes) of the CXL memory region requested; the first obtaining function can be in_get_memsize_total shown in Table 2 below.
[0110] A second obtaining function for obtaining the total amount of the CXL memory region allocated by the client development package; the second obtaining function can be in_get_memsize_used shown in Table 2 below.
[0111] A third obtaining function for obtaining the available bytes of the specified CXL memory region; the third obtaining function can be in_get_memsize_available shown in Table 2 below.
[0112] A fourth obtaining function for obtaining the total amount of the CXL memory region in the specified memory node; the fourth obtaining function can be in_get_memsize_node_total shown in Table 2 below.
[0113] A fifth obtaining function for obtaining the available bytes of the CXL memory region in the specified memory node; the fifth obtaining function can be in_get_memsize_node_available shown in Table 2 below.
[0114] A sixth obtaining function for obtaining the status data of the plurality of CXL memory regions; the sixth obtaining function can be in_stats_print shown in Table 2 below. The status data can include the total memory, the used memory bytes, and the available memory bytes.
[0115] A seventh obtaining function for obtaining the status data of the corresponding CXL memory regions under the plurality of memory nodes; the seventh obtaining function can be in_stats_node_print shown in Table 2 below.
[0116] The special API defined in the embodiment includes the functions shown in Table 2 below.
[0117] Table 2
[0118] Step S202: Divide a first memory allocation pool for allocating the CXL memory of the user state and a second memory allocation pool for allocating the local memory of the user state.
[0119] The memory allocation pool (arena pool) in the memory allocator generally has only one kind; for example, the memory allocator jemalloc has only one memory allocation pool jemalloc_arena_pool; in this embodiment, the memory allocation pool is extended into two kinds of memory allocation pools, one of which is used to allocate CXL memory in the user mode, and the subsequent memory allocation pool is referred to as the first memory allocation pool (cxlmem_arena_pool), and the other is used to allocate local memory in the user mode, and the subsequent memory allocation pool is referred to as the second memory allocation pool (normal_arena_pool).
[0120] Optionally, the step S202 of "dividing the first memory allocation pool for allocating CXL memory in the user mode and the second memory allocation pool for allocating local memory in the user mode" can include: allocating a plurality of memory allocation pools for each core of the processor, wherein part of the memory allocation pools are used as the first memory allocation pool for allocating CXL memory in the user mode, and the other part of the memory allocation pools are used as the second memory allocation pool for allocating local memory in the user mode. For example, the plurality of memory allocation pools allocated for the processor core can be evenly divided, that is, the number of the first memory allocation pool and the second memory allocation pool is consistent.
[0121] During initialization, the number of each kind of memory allocation pool (arena pool) can be set. For example, the original memory allocator generally configures 4 memory allocation pools for each processor core (CPU core); in this embodiment, 8 memory allocation pools are configured for each processor core, of which four are used to allocate CXL memory, that is, as the first memory allocation pool (cxlmem_arena_pool), and the other four are used to allocate local memory, that is, as the second memory allocation pool (normal_arena_pool). Therefore, for the standard API, because only one of the first memory allocation pool and the second memory allocation pool can be selected at the same time, the runtime number of the modified memory allocation pool is the same as that of the memory allocation pool of the original memory allocator. However, for the special API of CXL memory, the user application program can allocate local memory and CXL memory in parallel, that is, the two kinds of memory allocation pools can be used at the same time.
[0122] In step S203, a calling request of a calling application program interface is obtained.
[0123] For details, please refer to step S102 of the embodiment shown in FIG. 1, which will not be repeated here.
[0124] In step S204, in the case where the calling request is used to call the special application program interface, a CXL memory identifier indicating the allocation of CXL memory is generated.
[0125] For details, please refer to step S103 of the embodiment shown in FIG. 1, which will not be repeated here.
[0126] Step S205, in the case of calling a request for calling a dedicated application interface, a first memory allocation pool is selected, and the memory space in the first memory allocation pool is allocated according to the calling request to allocate the user mode CXL memory.
[0127] In this embodiment, the corresponding calling request can be obtained based on the memory allocator interface, and the appropriate memory allocation pool is selected based on the calling request. Optionally, if the calling request initiated by the user is used to call a dedicated API, for example, the memory allocation function called in the calling request has a prefix in, then the first memory allocation pool is selected; on the contrary, if the calling request is to call a standard API, then the second memory allocation pool can be called.
[0128] After selecting the corresponding memory allocation pool, the memory space in the selected memory allocation pool can be allocated according to the calling request, for example, the corresponding memory space is applied and recycled.
[0129] Optionally, the above step S205 "allocating the memory space in the first memory allocation pool according to the calling request" can include the following steps A1 to A3.
[0130] Step A1, determine the memory allocation function corresponding to the calling request.
[0131] The memory allocation function of the corresponding API is included in the calling request, based on which the memory allocation function required by the memory allocator can be determined. For example, the calling request is used to apply for a piece of memory space, and the memory allocation function thereof is malloc function, and the corresponding memory allocation function for applying for memory in the memory allocator is, for example, je_mallocx.
[0132] Step A2, add a user mode memory mapping flag in the memory allocation function, and assign the memory mapping flag according to the CXL memory identifier; the memory mapping flag is used to indicate whether to allocate CXL memory.
[0133] In this embodiment, a flag for indicating whether to allocate CXL memory is added in the memory allocation function of the memory allocator, that is, a memory mapping flag (arena_mmap_flag); after generating the CXL memory identifier (MAP_CXLMEM), the CXL memory identifier (MAP_CXLMEM) can be assigned to the memory mapping flag (arena_mmap_flag); for example, arena_mmap_flag = MAP_CXLMEM. Similarly, if the current call request is to call a standard API, a local memory identifier (MAP_NORMAL) for indicating allocation of local memory can also be set and assigned to the memory mapping flag (arena_mmap_flag); for example, arena_mmap_flag = MAP_NORMAL.
[0134] Optionally, the step A1 of "adding a user-mode memory mapping flag in the memory allocation function" comprises a step A11.
[0135] The step A11 comprises adding a user-mode memory mapping flag in the memory allocation structure of the memory allocation pool.
[0136] The memory allocation pool generally has a data structure for memory allocation, that is, a memory allocation structure (arena_s); in this embodiment, the data structure of the memory allocation pool is extended, that is, a flag is added, that is, a user-mode memory mapping flag (arena_mmap_flag), so as to distinguish whether the memory allocation pool is local memory or CXL memory in the user mode. For example, in the alloc_core function, the arena_mmap_flag of arena_s is used to determine whether to allocate local memory or CXL memory this time, and finally generate a parameter flag for the kernel, so that the kernel can allocate corresponding memory. The process can be referred to FIG. 3.
[0137] It can be understood that the remaining contents of the memory allocation pool are unchanged, such as the remaining data structures, memory management mechanisms, and memory allocation methods.
[0138] Optionally, a setting function for setting the memory mapping flag (arena_mmap_flag) can also be added, for example, arena_set_mmap_flag, and a getting function for getting the memory mapping flag (arena_mmap_flag) can also be added, for example, arena_get_mmap_flag. Optionally, the method further comprises the following steps B1 to B2.
[0139] The step B1 comprises presetting a setting function for setting the memory mapping flag.
[0140] Step B2, when a new memory allocation pool is created, a setting function is called to set the memory mapping flag of the new memory allocation pool to a default value; the default value indicates that local memory is allocated (MAP_NORMAL).
[0141] And, the step A2 of assigning a value to the memory mapping flag according to the CXL memory identifier can include: calling a setting function to assign the CXL memory identifier to the memory mapping flag.
[0142] In this embodiment, when a new memory allocation pool is created, the setting function arena_set_mmap_flag can be called based on the initialization function init_arena_pool, and the memory mapping flag (arena_mmap_flag) is set to the default local memory identifier (MAP_NORMAL) when initialization is performed, i.e. arena_mmap_flag = MAP_NORMAL. In other words, the user is allocated memory based on the traditional allocation mode by default. And when the user allocates memory based on the special API, the newly added setting function can also be used to assign a value to the memory mapping flag.
[0143] Step A3, according to the memory allocation function, the memory space in the first memory allocation pool is allocated.
[0144] After determining the memory allocation function of the memory allocator, the memory space in the first memory allocation pool can be allocated based on the memory allocation function, such as applying for and recycling the first memory allocation pool.
[0145] Step S206, through the memory mapping interface, the CXL memory identifier is transmitted to the kernel state, and the hardware resources related to the CXL memory are allocated in the kernel state.
[0146] For details, please refer to step S104 of the embodiment shown in FIG. 1, which will not be repeated here.
[0147] Optionally, the modification of the memory allocator supports the new special API on the one hand, and on the other hand, it can bring the identifier of the CXL memory used to the kernel through the memory mapping interface of the operating system. In order to be able to transmit the CXL memory identifier to the kernel, in this embodiment, based on which memory allocation pool is used, the memory management file (extent.c) is used for parameter transmission. Optionally, the step S206 of transmitting the CXL memory identifier to the kernel state through the memory mapping interface includes steps C1 to C3.
[0148] Step C1, based on the memory allocation kernel function in the memory management file, a getting function for getting the memory mapping flag is called to get the memory mapping flag.
[0149] In the embodiment, the memory allocator is provided with a memory management file, i.e. extent.c, which is provided with a memory allocation kernel function, i.e. extent_alloc_core. The memory allocation kernel function extent_alloc_core is used to obtain the corresponding memory mapping flag from the memory allocation pool. Alternatively, a newly added obtaining function arena_get_mmap_flag can be called to obtain the current memory mapping flag based on the obtaining function arena_get_mmap_flag.
[0150] In step C2, a memory mapping flag passing function is set, and the memory mapping flag is passed according to the memory mapping flag passing function.
[0151] In the embodiment, after the memory mapping flag is obtained, the memory mapping flag passing function extent_alloc_mmap_flag in the memory management file extent.c can be used for passing. Alternatively, when the memory mapping flag is passed, the memory mapping flag (arena_mmap_flag) can be merged into a local variable (interleave_policy) representing an interleaving strategy, and then the local variable (interleave_policy) is passed according to the memory mapping flag passing function extent_alloc_mmap_flag.
[0152] In step C3, the memory mapping flag is added in an operating system memory page mapping function of the memory page file, so as to pass the memory mapping flag to the memory mapping interface of the kernel.
[0153] The memory allocator is provided with a memory page file, i.e. pages.c. The memory mapping flag can be merged, for example, a local variable including the memory mapping flag and other additional identifiers are merged, and then the merged identifier is passed to the operating system memory page mapping function, i.e. os_pages_map_flag, in the memory page file pages.c. The corresponding identifier is added in the operating system memory page mapping function os_pages_map_flag, so that the memory mapping flag can be passed to the mmap interface of the kernel. For example, MAP_JEMALLOC_INTERNAL_MMAP can be added in the operating system memory page mapping function os_pages_map_flag and passed to the kernel mmap interface, so as to realize identifier passing. The passing process can be referred to FIG. 4.
[0154] The memory allocation method provided in the embodiment defines a special API specially used for allocating CXL memory, and a user can realize allocation of CXL memory by calling the special API, at this time, no local memory is allocated to the user, so that it can be ensured that the user can stably use CXL memory; and by defining the special API, the code modification amount on the user side is small, and the human cost caused by modifying the code can be reduced. The first memory allocation pool and the second memory allocation pool are divided in the user mode, so that the CXL memory can be adaptively allocated; the memory mapping flag of the user mode is newly added in the memory allocation function, so that the condition that the user calls the special API can be effectively responded; and the memory mapping flag is passed by using the memory management file, so that the problem that it is difficult to directly pass the identifier to the kernel can be solved.
[0155] In the embodiment, a memory allocation method is provided, which can be applied to a device requiring memory allocation. FIG. 5 is a flowchart of the memory allocation method according to the embodiment of the application. As shown in FIG. 5, the flowchart includes the following steps.
[0156] In step S501, a special application program interface used for allocating CXL memory is defined.
[0157] For details, refer to step S101 of the embodiment shown in FIG. 1, which will not be repeated here.
[0158] In step S502, a calling request for calling the application program interface is obtained.
[0159] For details, refer to step S102 of the embodiment shown in FIG. 1, which will not be repeated here.
[0160] In step S503, in a case where the calling request is used for calling the special application program interface, a CXL memory identifier indicating allocation of CXL memory is generated.
[0161] For details, refer to step S103 of the embodiment shown in FIG. 1, which will not be repeated here.
[0162] In step S504, the CXL memory identifier is passed to the kernel mode through a memory mapping interface.
[0163] For details, refer to step S104 of the embodiment shown in FIG. 1, which will not be repeated here.
[0164] In step S505, a CXL memory allocation area used for independently managing CXL memory in the kernel space is divided.
[0165] Since the frequency range, protocol, function, etc. of the hardware controller of the two memory devices are different due to the local memory and the CXL memory, the two memory devices need to be distinguished. In the embodiment, a new memory allocation zone is introduced, which is used to independently manage the CXL memory in the kernel space. For the convenience of description, the memory allocation zone is referred to as the CXL memory allocation zone (CXLMem_zone).
[0166] Figure 6 shows a hierarchical logical memory view in the virtual machine manager (VMM) of the operating system kernel, which covers multiple granularities of memory nodes, memory zones, memory buddies and memory pages. According to the requirements of hardware and software, the virtual machine manager extends multiple memory zones as memory allocation zones. For example, the Linux VMM has extended the zone to better utilize physical memory, such as DMA (Direct Memory Access) / DMA32 Zone, MOVABLE Zone, NORMAL Zone, etc. Among them, the DMA / DMA2 Zone includes a series of IO (Input / Output) device page address spaces, which are limited; the MOVABLE Zone aims to reduce fragmentation and support memory hot-plugging; generally, the NORMAL Zone is mostly used by the system and applications, that is, most DRAM (Dynamic Random Access Memory) pages belong to the NORMAL Zone.
[0167] In the embodiment, on the basis of reserving the local memory allocation zone (for example, the NORMAL Zone), the CXL memory allocation zone (CXLMem_zone) is newly added in the kernel state, which is used for allocation and management of the CXL memory.
[0168] In some optional embodiments, the step S505 of "dividing the CXL memory allocation zone for independently managing the CXL memory in the kernel space" includes the following steps D1 to D2.
[0169] Step D1: Add the type (ZONE_CXLMEM) corresponding to the CXL memory allocation zone (CXLMem_zone) in the memory zone type (enum zone_type) of the memory zone management header file of the operating system kernel.
[0170] For the operating system kernel, such as the Linux kernel, a memory region management header file mmzone.h is provided; the memory region management header file mmzone.h is a header file in the Linux kernel responsible for memory region management; wherein the memory region management is the core part of the memory management of the Linux kernel, mainly responsible for managing the physical memory and the swap space of the system. The type of the existing memory allocation area, i.e., the memory region type (enum zone_type), is defined therein. For example, the memory region type of the local memory allocation area NORMAL Zone is ZONE_NORMAL. In this embodiment, the type corresponding to the CXL memory allocation area (CXLMem_zone) is added in the memory region type of the memory region management header file mmzone.h, for example, ZONE_CXLMEM is added.
[0171] Optionally, in order to start the function of allocating CXL on demand, in this embodiment, the modified code of the operating system kernel related to the CXL memory, the newly added functions, variables and other CXL memory configuration options (CONFIG_CXLMEM) are all encapsulated in the macro definition, so that the corresponding macro definition can be selectively enabled in the kernel configuration.
[0172] The code for setting the CXL memory configuration option using the macro definition is as follows:
[0173] #ifdef CONFIG_CXLMEM
[0174] Modified code, newly added functions and variables
[0175] #endif
[0176] For example, the memory region type of the CXL memory allocation area set above belongs to the modified code of the operating system kernel, so the memory region type of the CXL memory allocation area can be added based on the macro definition.
[0177] Step D2, extend the memory mapping system call interface in the kernel mode, add a flag indicating mapping CXL memory and a flag indicating mapping local memory to the memory mapping system call interface.
[0178] In this embodiment, the memory mapping (mmap) system call interface in the kernel mode is extended, and the extension is to add a flag to distinguish between calling local memory or CXL memory. Among them, the memory mapping system call interface can be added with a flag indicating mapping CXL memory, such as the CXL memory identifier MAP_CXLMEM described above, and a flag indicating mapping local memory, such as the local memory identifier MAP_NORMAL described above.
[0179] Further optionally, the step S505 of dividing the CXL memory allocation area for independently managing the kernel space CXL memory can further include the following step D3.
[0180] Step D3: add a subzone structure in the memory region management header file, each subzone structure corresponding to a CXL memory. The subzone structure includes memory region data, memory start address and memory end address; wherein the memory region data is generated based on the existing memory allocation area (zone).
[0181] In this embodiment, since the hardware layer generally includes multiple CXL memories, and the kernel mode CXL memory allocation area (CXLMem_zone) corresponds to multiple CXL memories; in order to allocate memory in CXL memory units, the memory region corresponding to a CXL memory is called a subzone, and a corresponding structure, i.e., a subzone structure (also referred to as a subzone structure), is added.
[0182] Optionally, a subzone structure, i.e., a subzone structure, is added in the memory region management header file mmzone.h, each subzone structure representing a CXL memory, thereby supporting multiple CXL memories.
[0183] Further, the subzone structure includes memory region data zone_dat, memory start address start_pfn and memory end address end_pfn; it can be understood that the memory here refers to CXL memory. Further, the memory region data zone_dat is generated based on the existing memory allocation area (zone), for example, the memory region data zone_dat can be constructed by wrapping a layer of subzone outside the original kernel designed memory allocation area (zone), thereby being compatible with the previous kernel design.
[0184] When allocating CXL memory based on a call request, the subzone structure can be used to represent the CXL memory to be allocated, and the corresponding CXL memory can be applied for, recycled, etc.
[0185] In addition, a function add_subzone for adding a subzone and a function remove_subzone for removing a subzone can be added, which will not be described in detail in this embodiment.
[0186] It can be understood that the sub-memory region structure is a newly added CXL memory configuration option, and therefore the sub-memory region structure can also be added in the memory region management header file mmzone.h by macro definition.
[0187] Optionally, the step S505 of dividing the CXL memory allocation area for independently managing the CXL memory in the kernel space can further include the following step D4.
[0188] Step D4: adding a sub-memory region index structure in the memory region management header file; the sub-memory region index structure includes a pointer of a corresponding sub-memory region and an index identifier (subozne_idx) of the sub-memory region in a sub-memory region list (subzonelist).
[0189] In this embodiment, in order to better refer to each sub-memory region subzone, in addition to adding the sub-memory region structure, a sub-memory region index structure, which can be referred to as a subzoneref structure, is also added. Similar to the newly added sub-memory region structure, the sub-memory region index structure, i.e., the subzoneref structure, is added in the memory region management header file mmzone.h.
[0190] The sub-memory region index structure includes a pointer of a corresponding sub-memory region; and the sub-memory region list subzonelist represents all sub-memory regions subzone, and the sub-memory region index structure further includes an index identifier of a corresponding sub-memory region in the sub-memory region list subzonelist; for example, the index identifier is ID, and the variable name of the index identifier can be represented as subozne_idx.
[0191] It can be understood that the sub-memory region index structure is also a newly added CXL memory configuration option, and therefore the sub-memory region index structure can also be added in the memory region management header file mmzone.h by macro definition.
[0192] Optionally, the step S505 of dividing the CXL memory allocation area for independently managing the CXL memory in the kernel space can further include the following step D5.
[0193] Step D5: adding a variable in the memory region structure in the memory region management header file; the added variable includes: a free sub-memory region queue structure, a sub-memory region list (subzonelist), a number of sub-memory regions (nr_subzones), and an index identifier (cur_subzone_idx) of a currently allocated sub-memory region.
[0194] The memory region structure body struct zone is provided in the memory region management header file mmzone.h, and is a key data structure representing a memory region (zone). In this embodiment, a variable related to a sub-memory region subzone is added to the memory region structure body struct zone.
[0195] Optionally, a key structure body, i.e., a free sub-memory region queue structure body, is added to the memory region structure body struct zone. The original free memory queue (for example, the free queue of local memory) designed by Linux is called free_area. In order to implement unified CXL memory management, the corresponding free memory queue free_area is modified to the structure body of the free sub-memory region queue, and the variable name is free_area_subzone. In this embodiment, a new free_area_subzone structure body array is introduced for CXL memory, and a suitable free memory queue is selected according to whether it is a CXL memory region. For example, in a place where a free memory queue is needed, free_area or free_area_subzone can be selected according to whether it is a CXL memory region.
[0196] In addition, the memory region structure body struct zone further adds a sub-memory region list (subzone list, including a linked list of all sub-memory regions), a sub-memory region number (nr_subzones, i.e., the number of all sub-memory regions), and a current allocated sub-memory region index identifier (cur_subzone_idx). The added variables in the memory region structure body struct zone can be seen from Table 3.
[0197] Table 3
[0198] Similarly, when adding variables to the memory region structure body struct zone, the added variables can also be configured based on macro definition.
[0199] In step S506, the memory space in the CXL memory allocation region is allocated according to the calling request, so as to allocate the hardware resources related to the CXL memory.
[0200] The block diagram of memory allocation based on standard API and special API is shown in FIG. 7. After the user state memory allocator implements the parameter passing based on the memory mapping interface, the corresponding memory allocation region is used in the kernel state based on the current demand, so as to allocate the memory of the corresponding type, i.e., to allocate the hardware resources related to the CXL memory in the kernel state.
[0201] Optionally, the step S506 of "allocating memory space in the CXL memory allocation zone according to the call request" can include: obtaining the index identifier of the next sub-memory area from the linked list of the free sub-memory area; locating the free sub-memory area from the free sub-memory area queue structure according to the index identifier of the next sub-memory area, and performing memory allocation according to the free sub-memory area.
[0202] In the embodiment, to implement the initialization of the newly added CXL memory allocation zone (CXLMem_zone), the mm_init.c file of the kernel can be modified to extend zone_init_free_lists. If the current memory allocation zone is a CXL memory allocation zone (CXLMem_zone), the newly defined free_area_subzone structure of the free sub-memory area queue can be used to initialize the INIT_LIST_HEAD of the kernel to complete the initialization.
[0203] If the user calls the special API, the newly added CXL memory allocation zone (CXLMem_zone) needs to be allocated at present, at this time, the index identifier of the next sub-memory area (i.e. the sub-memory area after the currently allocated sub-memory area) can be determined; for example, the get_next_subzone_id function can be set for the newly added sub-memory area subzone, based on which the index identifier of the next sub-memory area can be obtained from the linked list of the free sub-memory area. Then, the free sub-memory area can be located from the free sub-memory area queue structure according to the index identifier of the next sub-memory area, and memory allocation can be performed according to the free sub-memory area, i.e. memory allocation can be performed according to the next sub-memory area.
[0204] The memory allocation method provided in the embodiment defines a special API specially used for allocating CXL memory, and the user can realize the allocation of CXL memory by calling the special API, so as to ensure that the user can stably use CXL memory and the amount of code modification on the user side is small, and the human cost caused by code modification can be reduced. The CXL memory allocation zone is newly added in the kernel state, so that the CXL memory can be specially managed; the subzone structure and the subzoneref structure are newly added, and when the CXL memory is allocated, the CXL memory can be allocated as a unit, which can meet the user demand; the modified code and the CXL memory configuration options are configured in the form of macro definition, so that the CXL memory allocation function can be conveniently started or stopped, and when the user calls the standard API, the process of allocating local memory will not be affected.
[0205] In the embodiment, a memory allocation apparatus is also provided, which is configured to implement the above-mentioned embodiments and optional implementation manners, and the description of which has been made above. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, implementation in hardware or a combination of software and hardware is also possible and contemplated.
[0206] The embodiment provides a memory allocation apparatus, as shown in FIG. 8, comprising:
[0207] An interface defining module 801 is configured to define a special application program interface for allocating CXL memory.
[0208] An obtaining module 802 is configured to obtain a calling request for calling the application program interface.
[0209] A processing module 803 is configured to, in a case where the calling request is for calling the special application program interface, generate a CXL memory identifier representing the allocated CXL memory.
[0210] A parameter passing allocation module 804 is configured to pass the CXL memory identifier to the kernel mode through a memory mapping interface, and allocate hardware resources related to the CXL memory in the kernel mode.
[0211] In some optional implementation manners, the interface defining module 801 defines the special application program interface for allocating CXL memory, comprising:
[0212] According to the same modification rule, the function name of the standard application program interface is modified, and the modified function name is used as the function name in the special application program interface; the standard application program interface is used for allocating memory.
[0213] In some optional implementation manners, the interface defining module 801 defines the special application program interface for allocating CXL memory, further comprising:
[0214] The special application program interface is defined with at least one of: a first obtaining function for obtaining the total amount of CXL memory regions, a second obtaining function for obtaining the total amount of CXL memory regions allocated through a client development package, a third obtaining function for obtaining the available byte amount of a specified CXL memory region, a fourth obtaining function for obtaining the total amount of CXL memory regions in a specified memory node, a fifth obtaining function for obtaining the available byte amount of a CXL memory region in a specified memory node, a sixth obtaining function for obtaining state data of a plurality of CXL memory regions, and a seventh obtaining function for obtaining state data of corresponding CXL memory regions under a plurality of memory nodes.
[0215] In some optional embodiments, the apparatus further comprises a division module configured to divide a first memory allocation pool for allocating CXL memory of a user mode and a second memory allocation pool for allocating local memory of the user mode.
[0216] The processing module 803 is further configured to, in the case of a call request for invoking a special application program interface, select the first memory allocation pool; and perform allocation processing on the memory space in the first memory allocation pool according to the call request to allocate CXL memory of a user mode.
[0217] In some optional embodiments, the processing module 803 performs allocation processing on the memory space in the first memory allocation pool according to the call request, comprising:
[0218] determining a memory allocation function corresponding to the call request;
[0219] adding a memory mapping flag of a user mode in the memory allocation function, and assigning the memory mapping flag according to the CXL memory identifier; the memory mapping flag is used to indicate whether to allocate CXL memory;
[0220] performing allocation processing on the memory space in the first memory allocation pool according to the memory allocation function.
[0221] In some optional embodiments, the processing module 803 adds the memory mapping flag of the user mode in the memory allocation function, comprising:
[0222] adding the memory mapping flag of the user mode in the memory allocation structure of the memory allocation pool.
[0223] In some optional embodiments, further comprising an initialization module configured to: preset a setting function for setting the memory mapping flag; when a memory allocation pool is newly created, call the setting function to set the memory mapping flag of the newly created memory allocation pool to a default value; the default value indicates to allocate local memory;
[0224] The processing module 803 assigns the memory mapping flag according to the CXL memory identifier, comprising: calling the setting function to assign the CXL memory identifier to the memory mapping flag.
[0225] In some optional embodiments, the parameter passing allocation module 804 passes the CXL memory identifier to the kernel mode through the memory mapping interface, comprising:
[0226] based on the memory allocation kernel function in the memory management file, calling a getting function for getting the memory mapping flag to get the memory mapping flag;
[0227] setting a memory mapping flag passing function, and passing the memory mapping flag according to the memory mapping flag passing function;
[0228] adding a memory mapping flag in an operating system memory page mapping function of the memory page file, to pass the memory mapping flag to a memory mapping interface of the kernel.
[0229] In some optional embodiments, the parameter passing allocation module 804 passes parameters to the memory mapping flag according to a memory mapping flag passing function, including:
[0230] merging the memory mapping flag into a local variable representing the interleaving strategy;
[0231] passing parameters to the local variable according to the memory mapping flag passing function.
[0232] In some optional embodiments, the division module divides a first memory allocation pool for allocating CXL memory of the user space, and a second memory allocation pool for allocating local memory of the user space, including:
[0233] allocating a plurality of memory allocation pools for each core of the processor, wherein part of the memory allocation pools are used as the first memory allocation pool for allocating CXL memory of the user space, and another part of the memory allocation pools are used as the second memory allocation pool for allocating local memory of the user space.
[0234] In some optional embodiments, the parameter passing allocation module 804 allocates hardware resources related to the CXL memory in the kernel mode, including:
[0235] dividing a CXL memory allocation area for independently managing CXL memory of the kernel space;
[0236] performing allocation processing on memory space in the CXL memory allocation area according to a call request, to allocate hardware resources related to the CXL memory.
[0237] In some optional embodiments, the parameter passing allocation module 804 divides a CXL memory allocation area for independently managing CXL memory of the kernel space, including:
[0238] adding a type corresponding to the CXL memory allocation area in a memory area type of a memory area management header file of the operating system kernel;
[0239] extending a memory mapping system call interface of the kernel mode, and adding a flag representing mapping CXL memory and a flag representing mapping local memory to the memory mapping system call interface.
[0240] In some optional embodiments, the parameter passing allocation module 804 divides a CXL memory allocation area for independently managing CXL memory of the kernel space, and further includes:
[0241] adding a sub-memory area structure in the memory area management header file, and each sub-memory area structure corresponds to a piece of CXL memory;
[0242] The sub-memory region structure includes memory region data, a memory start address, and a memory end address; the memory region data is generated compatibly on the basis of an existing memory allocation area.
[0243] In some optional embodiments, the parameter passing allocation module 804 divides the CXL memory allocation area for independently managing the CXL memory in the kernel space, and further includes:
[0244] A sub-memory region index structure is added in the memory region management header file; the sub-memory region index structure includes a pointer of a corresponding sub-memory region and an index identifier of the sub-memory region in a sub-memory region list.
[0245] In some optional embodiments, the parameter passing allocation module 804 divides the CXL memory allocation area for independently managing the CXL memory in the kernel space, and further includes:
[0246] A variable is added in the memory region structure in the memory region management header file; the added variable includes a free sub-memory region queue structure, a sub-memory region list, a sub-memory region number, and an index identifier of a currently allocated sub-memory region.
[0247] In some optional embodiments, the parameter passing allocation module 804 performs allocation processing on the memory space in the CXL memory allocation area according to a call request, including:
[0248] The index identifier of the next sub-memory region is obtained from the linked list of the free sub-memory region;
[0249] The free sub-memory region is located from the free sub-memory region queue structure according to the index identifier of the next sub-memory region, and the memory is allocated according to the free sub-memory region.
[0250] In some optional embodiments, the parameter passing allocation module 804 is configured to:
[0251] The CXL memory configuration options are encapsulated in a macro definition, and the macro definition is selectively enabled in the kernel configuration; the CXL memory configuration options include at least one of modified code, added functions, and variables of the operating system kernel.
[0252] Further function descriptions of the above various modules and units are the same as those of the corresponding embodiments described above, and will not be repeated here.
[0253] The memory allocation apparatus in the embodiment is in the form of functional units, where the units refer to ASIC (Application Specific Integrated Circuit) circuits, including processors and memories that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0254] The embodiment of the present application further provides a computer device having the memory allocation apparatus shown in Figure 8.
[0255] Referring to Figure 9, Figure 9 is a structural schematic diagram of a computer device according to an optional embodiment of the present application. As shown in Figure 9, the computer device includes one or more processors 10, a memory 20, and an interface configured to connect various components, including high-speed interfaces and low-speed interfaces. The various components are communicatively connected with each other by using different buses, and can be installed on a common motherboard or in other manners as needed. The processor can process instructions executed in the computer device, including graphical information stored in the memory or on the memory to display a GUI (Graphical User Interface) on an external input / output device, such as a display device coupled to the interface. In some optional embodiments, multiple processors and / or multiple buses can be used together with multiple memories if needed. Similarly, multiple computer devices can be connected, each providing part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). One processor 10 is taken as an example in Figure 9.
[0256] The processor 10 can be a central processor, a network processor, or a combination thereof. The processor 10 can further include a hardware chip. The hardware chip can be an ASIC (Application Specific Integrated Circuit), a PLD (Programmable Logic Device), or a combination thereof. The PLD can be a CPLD (Complex Programmable Logic Device), an FPGA (Field Programmable Gate Array), a GAL (Generic Array Logic), or any combination thereof.
[0257] The memory 20 stores instructions executable by the at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiments.
[0258] The memory 20 can include a program storage area and a data storage area. The program storage area can store an operating system, application programs required for at least one function, etc. The data storage area can store data created according to the use of the computer device, etc. In addition, the memory 20 can include a high-speed random access memory, and can also include a non-transitory memory such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid state memory device. In some alternative embodiments, the memory 20 can optionally include a memory that is remotely located with respect to the processor 10, and these remote memories can be connected to the computer device through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0259] The memory 20 can include a volatile memory, such as a random access memory, and can also include a non-volatile memory, such as a flash memory, a hard disk, or a solid state disk. The memory 20 can also include a combination of the above-mentioned types of memory.
[0260] The computer device also includes a communication interface 30 configured to enable the computer device to communicate with other devices or a communication network.
[0261] The embodiments of the present application also provide a computer readable storage medium. The above-mentioned method according to the embodiments of the present application can be implemented in hardware, firmware, or recorded in a storage medium, or implemented as computer code to be originally stored in a remote storage medium or a non-transitory machine readable storage medium downloaded through a network and stored in a local storage medium, so that the method described herein can be processed by such software on a storage medium using a general purpose computer, a special purpose processor, or programmable or special purpose hardware. The storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, or a solid state disk, etc. Alternatively, the storage medium can also include a combination of the above-mentioned types of memory. It can be understood that the computer, processor, microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code, when the software or computer code is accessed and executed by the computer, processor, or hardware, the method shown in the above embodiments is implemented.
[0262] Part of the present application can be applied as a computer program product, for example, computer program instructions, when executed by a computer, through the operation of the computer, can invoke or provide a method according to the present application, and / or, technical solutions. Those skilled in the art should understand that the form of computer program instructions in computer readable medium includes but is not limited to source file, executable file, installation package file and the like, accordingly, the way of computer program instructions executed by computer includes but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer readable medium can be any available computer readable storage medium or communication medium accessible to the computer.
[0263] Although the embodiments of the present application are described in conjunction with the drawings, various modifications and changes can be made by those skilled in the art without departing from the spirit and scope of the present application, and such modifications and changes fall within the scope defined by the appended claims.
Claims
1. A memory allocation method, characterized by, The method comprises: defining a special application program interface for allocating CXL memory; obtaining a calling request for calling the application program interface; in the case where the calling request is used to call the special application program interface, generating a CXL memory identifier representing the allocation of CXL memory; passing the CXL memory identifier to the kernel state through a memory mapping interface, and allocating hardware resources related to CXL memory in the kernel state.
2. The method of claim 1, wherein, The definition of the special application program interface for allocating CXL memory comprises: According to the same modification rule, the function name of the standard application program interface is modified, and the modified function name is used as the function name in the special application program interface; the standard application program interface is used to allocate memory.
3. The method of claim 2, wherein, The definition of the special application program interface for allocating CXL memory further comprises: At least one of the following is defined for the special application program interface: a first obtaining function for obtaining the total amount of CXL memory area, a second obtaining function for obtaining the total amount of CXL memory area allocated through a client development package, a third obtaining function for obtaining the available byte number of a specified CXL memory area, a fourth obtaining function for obtaining the total amount of CXL memory area in a specified memory node, a fifth obtaining function for obtaining the available byte number of CXL memory area in a specified memory node, a sixth obtaining function for obtaining the state data of multiple CXL memory areas, and a seventh obtaining function for obtaining the state data of corresponding CXL memory areas under multiple memory nodes.
4. The method of claim 1, wherein, Further comprising: dividing a first memory allocation pool for allocating CXL memory in the user state, and a second memory allocation pool for allocating local memory in the user state; in the case where the calling request is used to call the special application program interface, selecting the first memory allocation pool; allocating CXL memory in the user state according to the allocation processing of the memory space in the first memory allocation pool according to the calling request.
5. The method of claim 4, wherein, The allocation processing of the memory space in the first memory allocation pool according to the calling request comprises: determining a memory allocation function corresponding to the calling request; adding a memory mapping flag in the user state in the memory allocation function, and assigning the memory mapping flag according to the CXL memory identifier; the memory mapping flag is used to indicate whether to allocate CXL memory; allocating the memory space in the first memory allocation pool according to the memory allocation function.
6. The method of claim 5, wherein, The addition of the memory mapping flag in the user state in the memory allocation function comprises: adding a memory mapping flag in the user state in the memory allocation structure of the memory allocation pool.
7. The method of claim 6, wherein, Further comprising: presetting a setting function for setting the memory mapping flag; when a memory allocation pool is newly created, calling the setting function to set the memory mapping flag of the newly created memory allocation pool to a default value; the default value indicates the allocation of local memory; the assignment of the memory mapping flag according to the CXL memory identifier comprises: calling the setting function to assign the CXL memory identifier to the memory mapping flag.
8. The method of claim 5, wherein, The CXL memory identifier is transmitted to the kernel state through the memory mapping interface, including: Based on the memory allocation core function in the memory management file, calling the acquisition function for acquiring the memory mapping flag, and acquiring the memory mapping flag; Setting a memory mapping flag transmission function, and performing parameter transmission on the memory mapping flag according to the memory mapping flag transmission function; In the operating system memory page mapping function of the memory page file, the memory mapping flag is added to the memory mapping interface of the kernel.
9. The method of claim 8, wherein, The parameter transmission on the memory mapping flag according to the memory mapping flag transmission function includes: The memory mapping flag is combined into a local variable representing an interleaving strategy; The parameter transmission on the local variable according to the memory mapping flag transmission function.
10. The method of claim 4, wherein, The first memory allocation pool for allocating user state CXL memory and the second memory allocation pool for allocating user state local memory are divided, including: A plurality of memory allocation pools are allocated for each core of the processor, wherein part of the memory allocation pools are used as the first memory allocation pool for allocating user state CXL memory, and another part of the memory allocation pools are used as the second memory allocation pool for allocating user state local memory.
11. The method of claim 1, wherein, The hardware resources related to the CXL memory are allocated in the kernel state, including: The CXL memory allocation area for independently managing the kernel space CXL memory is divided; According to the call request, the memory space in the CXL memory allocation area is allocated and processed to allocate the hardware resources related to the CXL memory.
12. The method of claim 11, wherein, The CXL memory allocation area for independently managing the kernel space CXL memory is divided, including: A type corresponding to the CXL memory allocation area is added in the memory region type of the memory region management header file of the operating system kernel; The memory mapping system call interface of the kernel state is extended, and the memory mapping system call interface is added with a flag representing mapping CXL memory and a flag representing mapping local memory.
13. The method of claim 12, wherein, The CXL memory allocation area for independently managing the kernel space CXL memory is divided, further including: A sub-memory region structure body is added in the memory region management header file, and each sub-memory region structure body corresponds to a CXL memory; The sub-memory region structure body includes memory region data, a memory start address and a memory end address; wherein the memory region data is generated compatible based on the existing memory allocation area.
14. The method of claim 13, wherein, The CXL memory allocation area for independently managing the kernel space CXL memory is divided, further including: A sub-memory region index structure body is added in the memory region management header file; the sub-memory region index structure body includes a pointer of the corresponding sub-memory region and an index identifier of the sub-memory region in the sub-memory region list.
15. The method of claim 13, wherein, The CXL memory allocation area for independently managing the kernel space CXL memory is divided, further including: A variable is added to the memory region structure body in the memory region management header file; the added variable includes: a free sub-memory region queue structure body, a sub-memory region list, a sub-memory region number and an index identifier of the currently allocated sub-memory region.
16. The method of claim 15, wherein, The memory space in the CXL memory allocation area is allocated according to the call request, and the allocation process comprises the following steps: Get the index identifier of the next sub-memory area from the linked list of the idle sub-memory area; According to the index identifier of the next sub-memory area, the idle sub-memory area is located from the idle sub-memory area queue structure body, and the memory is allocated according to the idle sub-memory area.
17. The method according to any one of claims 11 to 16, characterized in that, Also includes: Encapsulate the CXL memory configuration option in the macro definition, and selectively enable the macro definition in the kernel configuration; The CXL memory configuration option includes at least one of modified code, added functions and variables of the operating system kernel.
18. A computer device, comprising: Including: The memory and the processor are mutually connected in communication, the memory stores computer instructions, and the processor executes the computer instructions to execute the memory allocation method in any one of claims 1-17.
19. A computer non-transitory readable storage medium, characterized in that, The computer non-transitory readable storage medium stores computer instructions, and the computer instructions are used to make the computer execute the memory allocation method in any one of claims 1-17.
20. A computer program product, characterised in that, Including computer instructions, the computer instructions are used to make the computer execute the memory allocation method in any one of claims 1-17.
Citation Information
Patent Citations
Method and device for communication between kernel mode and user mode and terminal
CN108062253A
CXL memory module and memory storage system
CN115982078A
Shared memory processing method and device, computer equipment and storage medium
CN116302598A
Memory allocation method, computer equipment, storage medium and product
CN118132274A
System resource allocation for code execution
US20220058062A1
Cited By
Memory scheduling method and device, electronic equipment and storage medium
CN121680722A