Dynamic link library memory large-page method and system

By compiling the ELF file of the dynamic link library, recording relocation information, and migrating and integrating memory segments, the upgrade problem of code segments with insufficient large page capacity is solved, and the memory access efficiency and performance in the Serverless scenario are improved.

CN120763084APending Publication Date: 2025-10-10PEKING UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510650675.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-20
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

Existing technologies cannot upgrade dynamic link libraries or application code segments that do not have the required large page capacity to large pages. This results in low code segment memory access efficiency, low TLB cache hit rate, and memory fragmentation, which particularly affects performance in Serverless scenarios.

Method used

By obtaining the ELF file of the dynamic link library, compiling and recording the relocation information, parsing the memory segment type, dividing it into read-only data segment, code segment and writable data segment, and migrating and merging the memory segments of the same type into a continuous virtual memory space, updating the relative offset address, and using the large page fusion algorithm to avoid memory expansion.

Benefits of technology

It achieves automatic compilation of dynamic link libraries and fine-grained splitting and fusion of memory segments, improving memory utilization efficiency, reducing iTLB miss rate, avoiding memory fragmentation, and improving the performance and running speed of Serverless functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120763084A_ABST
    Figure CN120763084A_ABST
Patent Text Reader

Abstract

The invention relates to a dynamic link library memory large-page method and system, and belongs to the technical field of computers. The invention provides a dynamic link library memory large-page method in the first aspect. The method comprises the steps that ELF files of one or more dynamic link libraries are obtained; compiling and linking the ELF file, and recording relocation information; and carrying out migration and fusion on the ELF file by utilizing the relocation information. According to the method, the limitation of an Ali cloud code large page technology is broken through, all dynamic link libraries can be actively upgraded into large pages, the iTLB miss of a program is further reduced, the 2MB iTLB utilization rate of a CPU is increased, the problem of memory fragmentation or memory expansion is avoided, and the memory utilization efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method and system for converting a dynamic link library into large memory pages, belonging to the technical field of computers. Background Art

[0002] Traditional paging: In operating systems, memory is typically managed in 4KB pages. For programs with large code segments (such as databases and JVMs), frequent page table lookups and TLB (Translation Lookaside Buffer) misses can lead to performance degradation.

[0003] Huge Pages: Huge pages are a memory management optimization technology that usually allocates memory in units of 2MB or 1GB, reducing the number of page table entries and TLB miss rate, thereby improving memory access performance.

[0004] Linux Transparent Huge Pages: Transparent Huge Pages is a memory management optimization technology in the Linux kernel that improves system performance by automatically merging small pages into large pages. While it offers the advantages of transparency, dynamic management, and performance improvements, it can also introduce issues such as memory fragmentation and latency overhead. With proper configuration and tuning, Transparent Huge Pages can significantly improve the performance of memory-intensive applications.

[0005] Some recent research involves scanning pages to proactively split and eliminate memory bloat, such as HawkEye, which reduces memory bloat by scanning mapped large pages and reclaiming zero-filled 4KB pages. It uses copy-on-write to merge zero-filled pages into a single page, freeing up memory.

[0006] Alibaba Cloud provides a huge code page technology, which is an optimization extension based on Linux transparent huge pages. This technology supports placing the executable parts of applications and dynamic link libraries into huge pages (usually 2MB or larger). This helps reduce iTLB misses in programs and improves the CPU's 2MB iTLB utilization, avoiding memory fragmentation and memory expansion problems, and improving memory utilization efficiency. It is suitable for business scenarios with large code segments, such as databases and large applications.

[0007] Specifically, traditional large page mechanisms typically only optimize memory access efficiency for data segments (such as heaps and stacks) or large-scale memory-intensive applications. However, for code segments, especially during dynamic loading and execution, the memory pages of code segments usually still maintain a smaller page size. This leads to the following problems:

[0008] Low code segment memory access efficiency: Traditional large page mechanisms only optimize data memory, ignoring code segments. Since code segments are typically continuous execution sequences, if large pages cannot be used, the CPU will have low efficiency when accessing these small pages, resulting in limited execution speed.

[0009] Reduce TLB cache hit rate: For frequently executed code segments, the traditional small page management mode may result in a low TLB hit rate, thereby increasing the latency of memory access. Frequent memory access will affect overall performance, especially in large-scale applications or complex programs.

[0010] Memory fragmentation problem: Although large pages can effectively reduce memory allocation fragmentation, the inability to optimize code segments may lead to code page fragmentation during execution, further affecting memory usage efficiency and program execution efficiency.

[0011] Alibaba Cloud's huge page technology addresses the aforementioned issues to some extent, but it also has limitations. This technology cannot upgrade code pages of dynamic link libraries or applications that do not fit within the huge page capacity to huge pages. This is because the code contains relative jumps, which fix the order of code segments and the distance between segments. Therefore, native binary code does not support merging multiple code segments to form huge pages. According to our statistics, in Serverless scenarios, approximately 73% of dynamic link library code segments are smaller than 2MB (the minimum huge page size). Why can't current huge page promotion technology upgrade code segments that do not fit within the huge page capacity to huge pages? This is because upgrading a code segment smaller than 2MB to a huge page would change its relative position relative to the data segment. In current Linux systems, both dynamic link libraries and application binary instructions use relative address access to retrieve data, which can disrupt the entire program. Therefore, current huge page technology can only upgrade code segments that exceed the huge page capacity to huge pages, limiting its application to code segments.

[0012] Serverless scenarios have three characteristics: 1) Serverless applications consist of small functions with very small code segments; 2) Applications link to numerous dynamic link libraries (DLLs) and primarily execute code within those DLLs; and 3) A significant portion (73%) of the DLL code referenced by serverless applications is insufficient for existing technologies to optimize for large page execution. This invention aims to provide a technology for splitting, migrating, and fusing memory segments of dynamic link libraries. This technology achieves the capacity requirements for large pages by fusing the read-only and code segments of multiple DLLs. It then traverses and modifies all relative address offsets to ensure correct function execution after migration. Furthermore, a large page fusion algorithm virtually eliminates the memory bloat associated with large pages. Summary of the Invention

[0013] This method overcomes the limitations of Alibaba Cloud's huge code page technology by proactively upgrading all dynamic link libraries to huge pages, further reducing program iTLB misses and improving the CPU's 2MB iTLB utilization. This prevents memory fragmentation and bloat, improving memory efficiency. It also achieves significant optimization results in small serverless function scenarios, resulting in an average 10% performance improvement for serverless functions.

[0014] To achieve the above technical objectives, the first aspect of the present invention provides a method for converting a dynamic link library into large memory pages, comprising:

[0015] Get one or more ELF files of dynamic link libraries;

[0016] Compile and link the ELF file and record relocation information;

[0017] The ELF file is migrated and merged using the relocation information.

[0018] Furthermore, compiling and linking the ELF file includes migrating the relocation segments of the ELF text to large pages with corresponding permission attributes.

[0019] Further, the process of migrating and merging the ELF file includes:

[0020] Parsing the ELF file to obtain memory segments;

[0021] According to the type of the memory segment, it is divided into a first memory segment, a second memory segment and a third memory segment;

[0022] Migrate and merge memory segments of the same type into the same memory area;

[0023] The relative offset address of each memory segment is updated using the relocation information.

[0024] Furthermore, the first memory segment is a read-only data segment for which the process has only read permission; the second memory segment is a code segment for which the process has read and execute permission; and the third memory segment is a writable data segment for which the process has read and write permission.

[0025] Furthermore, memory segments of the same type are migrated and merged into the same memory area of ​​a memory compartment, where the memory compartment is a continuous 2.5 GB virtual memory space.

[0026] Furthermore, in the memory compartment, 0-0.5 GB stores read-only data segments, 0.5-2.0 GB stores code segments, and 2.0 GB-2.5 GB stores writable data segments.

[0027] Furthermore, in response to exhaustion of resources in the same memory area of ​​a memory compartment, a new memory compartment is opened.

[0028] A second aspect of the present invention provides a dynamic link library memory large page system, comprising:

[0029] A data acquisition module is used to obtain the ELF files of one or more dynamic link libraries;

[0030] Compile and link module, in order to compile and link described ELF file, and record relocation information;

[0031] The migration and fusion module is used to migrate and fuse the ELF file using the relocation information.

[0032] A third aspect of the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for the above method.

[0033] A fourth aspect of the present invention provides a storage medium storing a computer program, wherein the computer program implements the above method when executed by a computer.

[0034] The beneficial effects of the present invention are as follows:

[0035] 1. The present invention provides an automated compilation script modification program that can automatically record relocation information during dynamic link library compilation. This method is not involved in the prior art, thereby effectively solving the tedious problem of manually recording relocation information and improving the efficiency and accuracy of the compilation process.

[0036] 2. The present invention provides a Linux system mechanism for fine-grained splitting, migration and fusion of each memory segment of a dynamic link library, which can ensure the normal operation of the dynamic link library memory segment after migration. This technology overcomes the defect of the existing technology that causes operation abnormalities during the code segment migration process.

[0037] 3. The present invention provides a large page fusion algorithm, which obtains large page gains when optimizing the dynamic link library runtime while effectively avoiding the memory expansion problem caused by large pages.

[0038] 4. The present invention separates and merges the memory segments of three permission types into large pages, and can continue to ensure the independence of each segment's permissions, preventing malicious code from being executed by elevating permissions, thereby improving the security of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 The figure is a flow chart of converting a dynamic link library into large pages according to an embodiment of the present invention.

[0040] Figure 2 A schematic diagram of overcoming memory expansion according to an embodiment of the present invention. DETAILED DESCRIPTION

[0041] In the following description, the modulation method of the present invention is further described through specific embodiments to facilitate a more thorough understanding of the features and advantages of the present invention by those skilled in the art. It should be noted that the description below is merely a representative typical application. Obviously, the present invention is not limited to any specific structure, function, device, and method described herein, and may have other embodiments or combinations of other embodiments. The software / hardware modules described in the present invention or shown in the accompanying drawings may also be flexibly adjusted as needed.

[0042] This embodiment implements a new method for large page optimization and dynamic code optimization for dynamic link libraries (DLLs) in a Serverless system. This new large page optimization method requires re-arranging the memory addresses of the ELF executable files corresponding to the DLLs, merging the memory data of multiple DLLs with the same permissions into a continuous large page. This requires: 1) recording relocation information during the compilation and linking process; 2) using this relocation information to migrate and merge the memory segments of the DLL ELF executable files; and 3) implementing a large page fusion algorithm to minimize memory fragmentation. Figure 1 The key components and workflow of the Serverless system dynamic link library optimization in an embodiment of the present invention are demonstrated: first, the system environment is prepared. The dynamic link library in the Serverless application running environment needs to be recompiled, and all the relocation information of each ELF segment is generated during compilation; then the improved GNU loader of the present invention is used. The improved GNU loader of the present invention has a dynamic link library loading function with large page fusion capability; the large page fusion loading function of the dynamic link library realizes small page fusion, that is, physical large page data loading and virtual address mapping of the dynamic link library through cooperation between system modules; the present invention also provides a large page fusion algorithm, which can avoid the problem of direct jump range exceeding the limit and minimize the generation of memory fragmentation.

[0043] Step 1: Record relocation information during compilation and linking

[0044] In the first step of system flow, the present invention provides a set of ELF file relocation information full recording mechanism.In the ELF file, the relocation segment includes the relocation information that is used to correct the symbolic address. Under the default setting of gcc, since the relocation of many symbolic addresses has been completed in the link stage, the overwhelming majority of relocation information has been removed, and only two relocation segments, .rela.dyn and .rela.plt, have been retained to load the foundation of GOT (Global Offset Table) table after the dynamic link library (DLL).And in the new method of dynamic link library large page optimization, each segment will be migrated to the large page of corresponding permission attribute, and the relative offset of its symbolic address will change, so whole relocation information should be recorded in the compilation process.Specific implementation method is, the program of relocation information record is opened to Makefile compilation script automation. The specific implementation of the program is as follows: automatically checking the make statements in the compilation script of the dynamic link library to be recompiled, adding the compilation setting "-Wl, --emit-relocs" to the make statements (this is the link-time relocation information full record setting that both gcc and llvm compilers have), and automatically adding the glibc runtime environment provided by the present invention, thereby realizing automatic compilation-time relocation information recording.

[0045] Step 2: Use relocation information to achieve the migration and fusion of each memory segment of the dynamic link library ELF executable file

[0046] In the second step of the system flow, the present invention provides a Linux system module mechanism that utilizes relocation information to implement the migration and fusion of memory segments within the dynamic link library (ELF) executable file. Glibc's ld.so is the loader required for all dynamic link programs in Linux when starting up. When loading a dynamic link library, this loader parses the phdr structure within the dynamic link library's ELF file and uses mmap to map the dynamic link library's code segment, read-only data segment, and writable data segment in a fixed order to the current process's virtual memory space in the form of small pages. This loading method creates the following problems: instructions use relative offsets for addressing and instruction jumps. These relative offset data are distributed across the dynamic link library's memory segments in 4-byte or 8-byte form. Only by using the full record of relocation information provided in step 1 can the location of all offset data be located. This results in a fixed and unchangeable order of the memory segments loaded by conventional loaders. The Linux system module mechanism for migrating and fusion of memory segments within the dynamic link library (ELF) executable file implemented by the present invention can address these two major issues. Specifically, loader is added to the relative offset of each memory segment actual relative to base address (address of first segment), and the logic of address relocation related code is changed, the base address+offset address that address relocation related code uses is changed to base address+segment relative offset+relative offset, obtains improved loader.The memory segment of three kinds of permission types that dynamic link library is imported is migrated and merged, when loader loads dynamic link library, the loader improved by the present invention can carry out the judgment of permission to each memory segment, divides them into three types, read-only data segment (process has only read permission), code segment (process has read and executable permission) and writable data segment (process has read and write permission).Then the memory segment of all dynamic link library same permissions is migrated and merged in same memory area, in order to allow the code of dynamic link library to operate normally, by parsing the relocation information of step 1 full record, find the storage location of each relative offset address data, update the relative offset address after migration.

[0047] Step 3: Use the large page fusion algorithm to eliminate memory fragmentation as much as possible.

[0048] In the third step of the system process, the system module of the present invention also provides a large page fusion algorithm with minimal memory fragmentation. The present invention roughly counts the memory segment occupancy of the dynamic link library in Linux. The memory segment size of 73% of the dynamic link library is less than the capacity of a large page (2MB). Modifying the offset to the large page granularity during compilation will produce an expected 2 times of memory expansion. The present invention proposes the concept of a memory compartment, which occupies a continuous 2.5GB virtual memory space as a memory compartment, of which 0~0.5GB stores read-only data segments, 0.5~2.0GB stores code segments, and 2.0GB~2.5GB stores writable data segments. The size is set to 2.5GB because the relative offset memory access of the instruction can only span a maximum of +-2GB of space. The algorithm first counts the occupancy of the three types of segments of the dynamic link library, and then searches for the memory compartment that can accommodate the three types of segments at the same time. After finding the memory compartment that can accommodate them, the memory data is placed. By combining steps 2 and 3, the large page expansion problem can be overcome, such as Figure 2 shown.

[0049] After the read-only segments, executable segments, and writable segments of multiple dynamic link libraries are migrated and merged, the free memory fragments in the huge pages are naturally filled. In this way, each memory compartment only has free memory fragments in the last huge page of the read-only segment, executable segment, and writable segment. Compared with the original method where each huge page would generate nearly half of the memory fragments, the algorithm of the present invention reduces the generation of memory fragments by 50% through experiments.

[0050] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the present invention. Any skilled artisan may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be as set forth in the appended claims.

Claims

1. A method for converting a dynamic link library into large pages, comprising: Get one or more ELF files of dynamic link libraries; Compile and link the ELF file and record relocation information; The ELF file is migrated and merged using the relocation information.

2. The method according to claim 1, characterized in that Compiling and linking the ELF file includes migrating the relocation segments of the ELF text to large pages with corresponding permission attributes.

3. The method according to claim 1, characterized in that The process of migrating and fusing the ELF file comprises: parsing the ELF file to obtain a memory segment; According to the type of the memory segment, it is divided into a first memory segment, a second memory segment and a third memory segment; Migrate and merge memory segments of the same type into the same memory area; The relative offset address of each memory segment is updated using the relocation information.

4. The method according to claim 3, characterized in that The first memory segment is a read-only data segment for which the process has only read permission; the second memory segment is a code segment for which the process has read and execute permission; and the third memory segment is a writable data segment for which the process has read and write permission.

5. The method according to claim 3, characterized in that Memory segments of the same type are migrated and merged into the same memory area of ​​a memory compartment, which is a continuous 2.5GB virtual memory space.

6. The method according to claim 5, characterized in that In the memory compartment, 0 to 0.5 GB stores read-only data segments, 0.5 to 2.0 GB stores code segments, and 2.0 GB to 2.5 GB stores writable data segments.

7. The method according to claim 5, characterized in that In response to exhaustion of resources in the same memory area of ​​a memory compartment, a new memory compartment is opened.

8. A dynamic link library memory large page system, comprising: A data acquisition module is used to obtain the ELF files of one or more dynamic link libraries; Compile and link module, in order to compile and link described ELF file, and record relocation information; The migration and fusion module is used to migrate and fuse the ELF file using the relocation information.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, the computer program being configured to be executed by the processor, the computer program comprising instructions for executing the method according to any one of claims 1 to 7.

10. A storage medium storing a computer program, wherein when the computer program is executed by a computer, the method according to any one of claims 1 to 7 is implemented.