Multi-granularity remote memory runtime method based on user mode
Remote memory management is performed in user mode through compile-time program analysis and rewriting technology, which solves the problem of remote memory system compatibility and performance being difficult to balance, and achieves efficient remote memory access and prefetch optimization, which is suitable for native C/C++ languages. Written application.
Patent Information
- Application Number
- CN202410517975.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-26
- Publication Date
- 2024-08-23
AI Technical Summary
It is difficult for existing remote memory systems to achieve both high compatibility and high performance. The kernel-based switching mechanism has high-performance overhead and read and write amplification issues. However, the user-mode based solution lacks compatibility and requires a large number of modifications to the application.
Using compile-time program analysis and program rewriting technology, the LLVM tool chain performs fine-grained management and swap-in and swap-out work of remote memory in user mode. The compile-time plug-in module performs pointer flow analysis and instruction rewriting on native C/C++ code. , generate an executable file that supports remote memory, and the application can be compatible with the runtime without source code level modification.
It supports the remote memory function without source code modification, reduces the read and write amplification of remote memory access, improves the remote memory prefetch hit rate and performance, and takes into account the compatibility of the kernel state and the high-performance characteristics of the user state.
Smart Images

Figure CN118535352A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of remote memory, and in particular to a multi-granularity remote memory runtime method based on user mode. Background Art
[0002] With the advent of the big data era, memory-intensive applications in data centers are becoming more and more common. Such applications mainly include low-latency network applications (such as in-memory databases) and data-intensive applications (such as machine learning and graph computing). In this context, memory resources have gradually become one of the main bottlenecks in data centers.
[0003] There are two main problems caused by memory bottlenecks in data centers. One is the service instability and performance degradation caused by insufficient memory on a single machine. Modern operating systems usually use a memory swap mechanism to swap out cold pages to lower-level storage devices when memory pressure is high to achieve a certain degree of memory elasticity. However, the use of a swap mechanism will lead to a cliff-like drop in the performance of memory-intensive applications. According to data, about 790,000 tasks in Google's data centers were terminated due to memory pressure in a month. Existing solutions include using SSDs with higher I / O performance for page swapping, using memory compression technology, and using more aggressive page recycling mechanisms, but these only have a mitigating effect on performance issues. The second is the problem of single-machine memory utilization. For example, Google's tracking and analysis of data centers shows that applications often over-request memory, resulting in an actual memory utilization rate of only about 50%. Alibaba's research also shows that there is about 30% cold memory in data centers. Since the traditional monolithic server architecture lacks the ability to share memory across machines in the allocation and use of memory resources, these remaining memories cannot be efficiently shared with other servers at the data center level. Therefore, the lack of elasticity in memory allocation is also one of the key issues in memory allocation in data centers.
[0004] Memory disaggregation is a solution to the above problems proposed by the academic community in recent years. Its main content is to improve the elasticity of data center memory usage and improve the overall memory utilization rate by giving applications the ability to access memory on other nodes. The foundation of this technology lies in the Remote Direct Memory Access (RDMA) technology that has become increasingly mature in recent years. Through network devices that support RDMA, computing nodes can directly access the memory of remote nodes with microsecond delays, and do not require the participation of the remote node's CPU. Many studies have shown that memory-intensive applications can maintain high performance characteristics when the working set spans multiple nodes after being modified for RDMA. However, applying RDMA to the field of memory disaggregation, so that applications have the ability to use remote memory with little or no changes, requires redesigning the traditional software architecture that only targets local memory.
[0005] At present, research work in the field of remote memory is mainly divided into two mainstream directions:
[0006] The first is based on the kernel swap mechanism. Its main idea is to abstract the remote memory into a block device as a swap space of the system, and reuse the kernel swap mechanism to achieve the purpose of using remote memory. When an application accesses a page that is not in the local memory, the CPU will trigger a page fault and swap the page from the remote node to the local memory through the swap mechanism. Through the swap mechanism, the system will keep the hot page in the local memory and store the cold page in the remote memory. This idea uses page granularity to manage the remote memory. The advantage is that the application does not need to be modified, ensuring maximum compatibility. InfiniSwap first proposed and implemented this idea. In addition, the system robustness is ensured by asynchronously writing the swapped pages to the SSD. However, this method requires a complete kernel software stack, which will cause extremely high additional performance overhead, and the kernel's page swap page prefetching mechanism is not suitable for the scenario of fast access to remote memory. In addition, since the kernel swap mechanism itself is designed for disks, many of its internal algorithms are still being optimized for SSD scenarios (such as swap entry allocation algorithm), which is difficult to meet the high performance requirements of remote memory scenarios; the memory management method based on page granularity will also introduce the problem of read-write amplification.
[0007] The second is based on user-mode runtime, the main idea is to make changes to the object-oriented model mechanism, expand the object life cycle of the programming language, garbage collection mechanism, etc. to use remote memory. However, the disadvantage of this mechanism is the lack of compatibility, or dependence on a specific language runtime, or the need to make a lot of modifications to the application source code before it can run.
[0008] In addition to these two mainstream directions, the academic community also has a series of solutions that combine software and hardware, but the problem still lies in compatibility.
[0009] In summary, the current remote memory system solutions have a pair of incompatible contradictions: it is impossible to take into account both the advantages of high compatibility and high performance (low kernel overhead / low read-write amplification). In order to resolve this contradiction, the present invention starts from a point of entry that has not been tried in previous work: using compile-time program analysis and program rewriting technology to introduce support for remote memory to applications. The present invention proposes a new user-mode remote memory runtime, which can perform fine-grained management and swapping in and out of remote memory in user mode, and by introducing pointer flow analysis and instruction rewriting steps in the program compilation process, the application can be compatible with the runtime without source code level modification or only introducing a small amount of modification, so as to take into account the compatibility of the kernel-mode solution and the high-performance characteristics of the user-mode solution. Summary of the invention
[0010] In view of the above-mentioned defects of the prior art, the technical problem to be solved by the present invention is how to achieve both high compatibility and high performance.
[0011] To achieve the above-mentioned purpose, the present invention provides a multi-granularity remote memory runtime method based on user state, which is characterized in that the present invention introduces support for remote memory for applications written in native C / C++ / other languages supported by the LLVM ecosystem by using compile-time program analysis and program rewriting technology, and proposes a new user-state remote memory runtime, which can perform fine-grained management and swapping in and out of remote memory in user state. Through the compile-time steps, the application does not need to be modified at the source code level or only introduces a small amount of modification to be compatible with the runtime, so as to take into account the compatibility of the kernel-state solution and the high-performance characteristics of the user-state solution.
[0012] Furthermore, the compile-time part is based on the LLVM tool chain, and is mainly implemented as a compiler plug-in module in the compilation tool chain, which is called in the LLVM optimizer; the compiler plug-in module targets codes in the form of LLVM IR, and the compile-time function can support native C / C++ and other languages supported by the LLVM ecosystem and can be compiled into any language of LLVM IR.
[0013] Furthermore, for the native C / C++ code repository, the following steps are performed to generate an executable file that supports the remote memory:
[0014] S1.1 Mark the parts of the code that allocate dynamic memory;
[0015] The S1.2 code is translated into LLVM IR intermediate representation code by the Clang compiler;
[0016] After pre-optimization, S1.3 uses the results of S1.1 to perform pointer flow analysis and mark all pointers that may point to dynamically allocated memory;
[0017] S1.4 performs binary rewriting on all memory accesses that may point to dynamically allocated memory pointers according to the configuration file, and inserts calls to remote memory processing functions;
[0018] The S1.5 compiler performs data flow analysis on loops in the code, identifies memory access patterns in the loops, and inserts memory prefetching code at appropriate locations to guide the runtime library to prefetch data;
[0019] The S1.6 code is post-optimized to complete the complete optimization flow. The linker links the rewritten LLVM IR with the remote memory runtime library to generate an executable file.
[0020] Furthermore, in the step S1.1, the method of using dynamic memory allocation in the standard glibc is automatically marked by the clang compiler.
[0021] Furthermore, in step S1.3, the pointer flow analysis refers to the flow-sensitive, non-context-sensitive Andersen pointer flow analysis algorithm, and other more accurate pointer flow analysis algorithms may also be used in actual applications.
[0022] Furthermore, the memory access mode in step S1.5 is sequential memory access.
[0023] Furthermore, the runtime process is divided into an initialization process and a memory access process;
[0024] The initialization process is performed when the application is started, and is mainly responsible for establishing an RDMA link with the memory management program on the remote memory node and performing initialization operations on the local cache data structure and the remote memory.
[0025] Furthermore, the initialization process includes the following steps:
[0026] S2.1 The application calls the initialization callback function of the remote memory runtime library; the function call will be automatically inserted into the application initialization logic by the compiler plug-in during compilation;
[0027] S2.2 After the application calls the initialization callback, the runtime library allocates a fixed-size local memory as a cache for the remote memory and initializes the local cache data structure;
[0028] S2.3 The runtime library establishes an RDMA connection with the memory node program;
[0029] S2.4 After successfully establishing a connection, the memory node program sends BaseVA and R_key information to the runtime library on the computing node. These two pieces of information are used to calculate the virtual address of the remote memory object on the memory node and send RDMA read and write requests;
[0030] The S2.5 runtime library sends a request to the remote memory node to register a memory of a specified size as the remote memory exclusively used by the application;
[0031] After receiving the request, the S2.6 memory node program allocates a memory of a specified size in the local memory area and initializes the memory;
[0032] S2.7 If the memory node has enough memory, the memory node program returns a registration success instruction to the runtime library; if the registration fails, the entire initialization process is exited;
[0033] After receiving the successful registration request, the S2.8 runtime library returns the control flow to the application.
[0034] Furthermore, the memory access process is called when the application is running. Since the compiler plug-in has translated the remote memory access instruction into a callback function for accessing the remote memory in the runtime library during compilation, the application will automatically call the memory access process when accessing the memory managed by the runtime library. To support memory management of multiple granularities, the runtime library manages memories of different sizes through different data structures, wherein small-granularity memory is managed through a set-associative cache, and large-granularity memory is managed through a page cache in the form of a linked list and a separate page address mapping table. In addition to the application's explicit call to the prefetch function, the runtime library will also implicitly prefetch the memory when accessing memory to improve remote memory performance.
[0035] Furthermore, the memory access process includes the following steps:
[0036] S3.1 The application triggers the memory access callback function of the runtime library by accessing the heap memory;
[0037] The S3.2 runtime library determines the memory access granularity through the parameters in the callback function, determines the cache data structure to use based on the granularity, and searches the memory in the corresponding data structure;
[0038] If the search is successful, it means that the memory object exists in the local cache, and then jump directly to S3.6 to return; if the search fails, it means that the memory object needs to be retrieved from the remote end, and it is necessary to continue from the following steps;
[0039] S3.3 If the local cache is full, a local cache eviction operation is required. The runtime library selects a victim object victim and writes it back to the remote memory by sending an RDMA write request, and vacates the cache location.
[0040] The S3.4 runtime library reads the remote memory into the local empty cache location by sending an RDMA read request;
[0041] S3.5 If the current application memory access mode is recognized by the runtime library, the runtime library's default prefetch strategy is used to perform prefetching at a certain distance. The default prefetch strategy is sequential access and strided access.
[0042] After completing the above steps, S3.6 returns the control flow to the application.
[0043] The present invention has the following technical effects:
[0044] 1. For applications written in native C / C++ / other languages supported by the LLVM ecosystem, no or only a small amount of modification is required to enable them to support user-mode remote memory functions;
[0045] 2. Remote memory access no longer uses OS memory pages as a fixed granularity, effectively reducing read and write amplification during remote memory access;
[0046] 3. Improve the hit rate of remote memory prefetching in more complex memory access modes through prefetch optimization and reduce the memory access waiting time.
[0047] The concept, specific structure and technical effects of the present invention will be further described below in conjunction with the accompanying drawings to fully understand the purpose, characteristics and effects of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 is a system diagram of a preferred embodiment of the present invention;
[0049] Figure 2 It is a compile-time process and code example of a preferred embodiment of the present invention;
[0050] Figure 3 It is a runtime initialization process of a preferred embodiment of the present invention;
[0051] Figure 4 The present invention is a preferred embodiment of the run-time memory access process and data structure schematic diagram. DETAILED DESCRIPTION
[0052] The following describes several preferred embodiments of the present invention with reference to the drawings in the specification, so that the technical content is clearer and easier to understand. The present invention can be embodied in many different forms of embodiments, and the protection scope of the present invention is not limited to the embodiments mentioned in the text.
[0053] In the drawings, components with the same structure are indicated by the same numerical reference numerals, and components with similar structures or functions are indicated by similar numerical reference numerals. The size and thickness of each component shown in the drawings are arbitrarily shown, and the present invention does not limit the size and thickness of each component. In order to make the illustration clearer, the thickness of the components is appropriately exaggerated in some places in the drawings.
[0054] like Figure 1 The present invention introduces support for remote memory to applications written in native C / C++ / other languages supported by the LLVM ecosystem by using program analysis and program rewriting technology during compilation, and proposes a new user-mode remote memory runtime, which can perform fine-grained management and swapping in and out of remote memory in user mode. Through the aforementioned steps during compilation, the application can be compatible with the runtime without source code level modification or only a small amount of modification, so as to take into account the compatibility of kernel-mode solutions and the high-performance characteristics of user-mode solutions. The following examples describe the specific steps during compilation and during runtime.
[0055] 1. Compilation period
[0056] The compile-time part is based on the LLVM toolchain and is mainly implemented as a compiler plug-in module in the compile toolchain, which is called in the LLVM optimizer. Since the compiler plug-in module targets the code in the form of LLVM IR (intermediate representation), in theory, the compile-time function can support native C / C++ and any other language supported by the LLVM ecosystem that can be compiled into LLVM IR. Figure 2 For native C / C++ code repositories, perform the following steps to generate an executable file that supports remote memory:
[0057] S1.1 Annotate the code for dynamic memory allocation. The clang compiler automatically annotates the dynamic memory allocation method used in the standard glibc.
[0058] The S1.2 code is translated into LLVM IR intermediate representation code by the Clang compiler;
[0059] After pre-optimization, S1.3 uses the result of S1.1 to perform pointer flow analysis (in the figure, it is written as the non-flow-sensitive and non-context-sensitive Andersen pointer flow analysis algorithm. In actual application, other more accurate pointer flow analysis algorithms can also be used to mark all possible pointers pointing to dynamically allocated memory.
[0060] S1.4 performs binary rewriting on all memory accesses that may point to dynamically allocated memory pointers according to the configuration file, and inserts calls to remote memory processing functions;
[0061] The S1.5 compiler performs data flow analysis on the loops in the code, identifies the memory access mode in the loop (sequential memory access mode in the example), and inserts memory prefetch code at the appropriate location to guide the runtime library to perform data prefetching.
[0062] The S1.6 code is post-optimized to complete the optimization process. The linker links the rewritten LLVM IR with the remote memory runtime library to generate an executable file.
[0063] A specific code rewriting example is Figure 2 As shown in . It can be seen that in the above steps, only step S1.1 requires a small modification to the application code, which is a major innovation of this patent compared to other user-mode solutions that introduce very few modifications to the application.
[0064] 2. Operation period
[0065] The runtime process is divided into initialization process and memory access process.
[0066] The initialization process is performed when the application starts, and is mainly responsible for establishing an RDMA link with the memory manager on the remote memory node and initializing the local cache data structure and the remote memory. Figure 3 As shown, the process mainly performs the following steps:
[0067] S2.1 The application calls the initialization callback function of the remote memory runtime library (hereinafter referred to as the "runtime library"). This function call will be automatically inserted into the application initialization logic by the compiler plug-in during compilation;
[0068] S2.2 After the application calls the initialization callback, the runtime library allocates a fixed-size local memory as a cache for the remote memory and initializes the local cache data structure;
[0069] S2.3 The runtime library establishes an RDMA connection with the memory node program (the handshake step required to establish the RDMA link is omitted here);
[0070] S2.4 After successfully establishing a connection, the memory node program sends BaseVA and R_key information to the runtime library on the computing node. These two pieces of information are used to calculate the virtual address of the remote memory object on the memory node and send RDMA read and write requests;
[0071] The S2.5 runtime library sends a request to the remote memory node to register a memory of a specified size as the remote memory exclusively used by the application;
[0072] After receiving the request, the S2.6 memory node program allocates a memory of a specified size in the local memory area and initializes the memory;
[0073] S2.7 If the memory node has enough memory, the memory node program returns a registration success instruction to the runtime library; if the registration fails, the entire initialization process is exited;
[0074] After receiving the successful registration request, the S2.8 runtime library returns the control flow to the application.
[0075] The memory access process is called when the application is running. Since the compiler plug-in has translated the remote memory access instruction into the callback function for accessing remote memory in the runtime library during compilation, the application will automatically call the memory access process when accessing the memory managed by the runtime library. Figure 4 As shown in the figure, to support memory management of multiple granularities, the runtime library manages memory of different sizes through different data structures. Small-granularity memory (256B, 512B, 1K, 2K) is managed through a set-associative cache, and large-granularity memory (greater than or equal to 4K) is managed through a linked list page cache and a separate page address mapping table. In addition to the explicit call of the prefetch function by the application, the runtime library will also implicitly prefetch the memory when accessing memory to improve remote memory performance. The specific steps of the memory access process are as follows:
[0076] S3.1 The application triggers the memory access callback function of the runtime library by accessing the heap memory;
[0077] The S3.2 runtime library determines the memory access granularity through the parameters in the callback function, determines the cache data structure to use based on the granularity, and searches the memory in the corresponding data structure;
[0078] If the search is successful, it means that the memory object exists in the local cache, and then jump directly to S3.6 to return. If the search fails, it means that the memory object needs to be retrieved from the remote end, and you need to continue with the following steps:
[0079] S3.3 If the local cache is full, a local cache eviction operation is required. The runtime library selects a victim object and writes it back to the remote memory by sending an RDMA write request, freeing up the cache location.
[0080] The S3.4 runtime library reads the remote memory into the local empty cache location by sending an RDMA read request;
[0081] S3.5 If the current application memory access mode is recognized by the runtime library, the runtime library's default prefetch strategy is used to perform prefetching at a certain distance. The default prefetch strategy includes sequential access, strided access, etc.
[0082] After completing the above steps, S3.6 returns the control flow to the application.
[0083] The preferred specific embodiments of the present invention are described in detail above. It should be understood that ordinary technicians in the field can make many modifications and changes based on the concept of the present invention without creative work. Therefore, all technical solutions that can be obtained by technicians in the technical field based on the concept of the present invention through logical analysis, reasoning or limited experiments on the basis of the prior art should be within the scope of protection determined by the claims.
Claims
1. A multi-granularity remote memory runtime method based on user mode, characterized in that: The present invention introduces support for remote memory for applications written in native C / C++ / other languages supported by the LLVM ecosystem by using compile-time program analysis and program rewriting technology, and proposes a new user-mode remote memory runtime, which can perform fine-grained management and swapping in and out of remote memory in user mode. Through the compile-time steps, the application does not need to be modified at the source code level or only requires a small amount of modification to be compatible with the runtime, thereby taking into account the compatibility of the kernel-mode solution and the high-performance characteristics of the user-mode solution.
2. The multi-granularity remote memory runtime method based on user mode as claimed in claim 1, characterized in that: The compile-time part is based on the LLVM tool chain, and is mainly implemented as a compiler plug-in module in the compilation tool chain, which is called in the LLVM optimizer; the compiler plug-in module targets codes in the form of LLVM IR, and the compile-time function can support native C / C++ and other languages supported by the LLVM ecosystem and can be compiled into any language of LLVM IR.
3. The multi-granularity remote memory runtime method based on user mode as claimed in claim 2, characterized in that: For native C / C++ code repositories, perform the following steps to generate an executable file that supports remote memory: S1.1 Mark the parts of the code that allocate dynamic memory; The S1.2 code is translated into LLVM IR intermediate representation code by the Clang compiler; After pre-optimization, S1.3 uses the results of S1.1 to perform pointer flow analysis and mark all pointers that may point to dynamically allocated memory; S1.4 performs binary rewriting on all memory accesses that may point to dynamically allocated memory pointers according to the configuration file, and inserts calls to remote memory processing functions; The S1.5 compiler performs data flow analysis on loops in the code, identifies memory access patterns in the loops, and inserts memory prefetching code at appropriate locations to guide the runtime library to prefetch data; The S1.6 code is post-optimized to complete the complete optimization flow. The linker links the rewritten LLVM IR with the remote memory runtime library to generate an executable file.
4. The multi-granularity remote memory runtime method based on user mode as claimed in claim 3, characterized in that: In the step S1.1, the method of using dynamic memory allocation in the standard glibc is automatically marked by the clang compiler.
5. The multi-granularity remote memory runtime method based on user mode as claimed in claim 4, characterized in that: In step S1.3, the pointer flow analysis refers to the flow-sensitive, non-context-sensitive Andersen pointer flow analysis algorithm. In actual application, other more accurate pointer flow analysis algorithms may also be used instead.
6. The multi-granularity remote memory runtime method based on user mode as claimed in claim 5, characterized in that: The memory access mode in step S1.5 is sequential memory access.
7. The multi-granularity remote memory runtime method based on user mode as claimed in claim 6, characterized in that: The runtime process is divided into an initialization process and a memory access process; The initialization process is performed when the application is started, and is mainly responsible for establishing an RDMA link with the memory management program on the remote memory node and performing initialization operations on the local cache data structure and the remote memory.
8. The multi-granularity remote memory runtime method based on user mode as claimed in claim 7, characterized in that: The initialization process includes the following steps: S2.1 The application calls the initialization callback function of the remote memory runtime library; the function call will be automatically inserted into the application initialization logic by the compiler plug-in during compilation; S2.2 After the application calls the initialization callback, the runtime library allocates a fixed-size local memory as a cache for the remote memory and initializes the local cache data structure; S2.3 The runtime library establishes an RDMA connection with the memory node program; S2.4 After successfully establishing a connection, the memory node program sends BaseVA and R_key information to the runtime library on the computing node. These two pieces of information are used to calculate the virtual address of the remote memory object on the memory node and send RDMA read and write requests; The S2.5 runtime library sends a request to the remote memory node to register a memory of a specified size as the remote memory exclusively used by the application; After receiving the request, the S2.6 memory node program allocates a memory of a specified size in the local memory area and initializes the memory; S2.7 If the memory node has enough memory, the memory node program returns a registration success instruction to the runtime library; if the registration fails, the entire initialization process is exited; After receiving the successful registration request, the S2.8 runtime library returns the control flow to the application.
9. The multi-granularity remote memory runtime method based on user mode as claimed in claim 8, characterized in that: The memory access process is called when the application is running. Since the compiler plug-in has translated the remote memory access instruction into a callback function for accessing remote memory in the runtime library during compilation, the application will automatically call the memory access process when accessing the memory managed by the runtime library. In order to support memory management of multiple granularities, the runtime library manages memories of different sizes through different data structures, among which small-granularity memory is managed through a set-associative cache, and large-granularity memory is managed through a page cache in the form of a linked list and a separate page address mapping table. In addition to the application's explicit call to the prefetch function, the runtime library will also implicitly prefetch the memory when accessing memory to improve remote memory performance.
10. The multi-granularity remote memory runtime method based on user mode as claimed in claim 9, characterized in that: The memory access process includes the following steps: S3.1 The application triggers the memory access callback function of the runtime library by accessing the heap memory; The S3.2 runtime library determines the memory access granularity through the parameters in the callback function, determines the cache data structure to use based on the granularity, and searches the memory in the corresponding data structure; If the search is successful, it means that the memory object exists in the local cache, and then jump directly to S3.6 to return; if the search fails, it means that the memory object needs to be retrieved from the remote end, and it is necessary to continue from the following steps; S3.3 If the local cache is full, a local cache eviction operation is required. The runtime library selects a victim object victim and writes it back to the remote memory by sending an RDMA write request, and vacates the cache location. The S3.4 runtime library reads the remote memory into the local empty cache location by sending an RDMA read request; S3.5 If the current application memory access mode is recognized by the runtime library, the runtime library's default prefetch strategy is used to perform prefetching at a certain distance. The default prefetch strategy is sequential access and strided access. After completing the above steps, S3.6 returns the control flow to the application.
Citation Information
Cited By
Programmable data exchange system
CN119906754A
