A Method and System for DPDK Memory Management Based on Load Balancing

By introducing private SLAB and BUDDY allocators in the DPDK, the problem of inability to scale and fierce competition in memory pools is solved, the memory management performance and utilization rate are improved, and the operation efficiency of the application is improved.

CN119781954BActive Publication Date: 2025-08-01TMLAKE (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411701375.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-08-01
Estimated Expiration
2044-11-26

AI Technical Summary

Technical Problem

DPDK's memory management has problems such as inability to scale the memory pool, frequent call to rte_malloc() leads to fierce lock competition and large management head overhead, affecting application performance and memory utilization.

Method used

Using load balancing-based memory management method, by building private SLAB and BUDDY allocators in each worker thread, avoiding frequent calls to rte_malloc(). Each thread only applies for memory from its own private SLAB and BUDDY, reducing lock competition and management head overhead.

Benefits of technology

It improves the performance and memory utilization of memory management, solves the problem of inability to scale and large overhead of memory pools, reduces lock competition, and improves the operational performance of applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781954B_ABST
    Figure CN119781954B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for DPDK memory management based on load balancing. The method includes: defining a memory management structure based on a load balancing device and worker threads, and initializing the worker threads and the memory management structure, wherein the memory management structure includes: a page allocator and a memory allocator; receiving in real time and issuing a memory application request according to a user task processing request, and performing memory allocation processing on the memory application requests of the worker threads based on the page allocator and the memory allocator, and allocating a memory space for the memory application requests of the worker threads according to the memory allocation processing result; when the worker threads complete task processing using the memory space and release the memory, recycling the memory space. By applying the technical solution provided by the present invention, the lock competition in the memory application process is reduced, the management header overhead is reduced, and the performance of memory management and the memory utilization rate are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Internet technologies, and more specifically, to a method and system for DPDK memory management based on load balancing. Background Art

[0002] Load balancing is a basic element of application high availability. By distributing traffic to different backend servers, the service throughput capacity of the application system is expanded, single points of failure are eliminated, and the availability of the application system is improved.

[0003] Load balancing is a key performance device on the application high availability link. It undertakes large-scale traffic distribution tasks in the current Internet and has an extreme pursuit of high performance. Avoiding the kernel protocol stack through kernel bypass is the mainstream high-performance solution today. Among them, the DPDK solution is the most mature and widely used and has withstood the test of large-scale traffic.

[0004] Currently, for DPDK memory management, by optimizing the DPDK memory management module, the running performance of DPDK is improved, thereby improving the running performance of the application.

[0005] DPDK provides available memory for application programs through two types of interfaces: the DPDK memory pool interface and the DPDK memory application interface (rte_malloc()). Through memory pool pre-allocation and thread caching, available memory can be provided with extremely high performance; rte_malloc() defaults to preferentially allocating memory from the NUMA where the current CPU is located, taking into account the affinity between the CPU and memory (the memory access speed of the CPU accessing memory in the same NUMA is higher than accessing memory in other NUMA). However, the memory pool technology requires pre-allocation of memory, and the pre-allocated memory will always be occupied and cannot be scaled. Whether the program is busy or not, it will always be occupied throughout the application life cycle, resulting in a reduction in available memory for other modules. In addition, the implementation of rte_malloc() adds a spin lock, and frequent calls to rte_malloc() by multiple working threads will greatly affect the performance of the application program. The memory block management header applied by rte_malloc() occupies 80 bytes (DPDK 22.11.1). When applying for 50 available bytes, at least 130 bytes are actually applied. In this case, the effective memory occupancy is less than 50%, and the management header overhead is too large.

[0006] In view of the deficiencies in the above two DPDK memory management methods, it is necessary to introduce a new method and system that, while maintaining the advantages of the above two memory management methods, supports memory pool scaling, reduces the number of calls to rte_malloc() through reasonable design, thereby reducing lock contention during the memory application process, reducing management header overhead, and improving the performance of memory management and memory utilization. Summary of the Invention

[0007] In view of the above-mentioned technical problems, the present invention provides a method and system for DPDK memory management based on load balancing. By embedding a private allocator (SLAB) and a buddy system (BUDDY) in each working thread, it avoids the problems of non-scalability of the memory pool, intense lock competition when the working thread frequently calls (rte_malloc()), and excessive management header overhead of rte_malloc(). At the same time, each thread only applies for memory from its own private SLAB and BUDDY, and does not apply for memory from the SLAB and BUDDY of other threads, solving the technical problems in the prior art that the pre-allocated memory will always be occupied, non-scalable, the performance of the application program will decline, and the management header overhead is large, thereby reducing the lock competition in the memory application process, reducing the management header overhead, and improving the performance of memory management and memory utilization.

[0008] The present invention provides a method for DPDK memory management based on load balancing, and the method includes:

[0009] S1, defining a memory management structure: Based on the load balancing device and the working thread, define a memory management structure, and initialize the working thread and the memory management structure, wherein the memory management structure includes: a page allocator and a memory allocator;

[0010] S2, the working thread receives in real time and issues a memory application request according to the user task processing request, and performs memory allocation processing on the memory application request of the working thread based on the page allocator and the memory allocator, and allocates a memory space for the memory application request of the working thread according to the memory allocation processing result;

[0011] S3, when the working thread corresponding to the memory allocation request uses the memory space to complete task processing and releases the memory, recycle the memory space according to the source type type of the memory space;

[0012] Wherein,

[0013] Each working thread has a corresponding private page allocator and memory allocator. The memory allocator is used to respond to the memory application request of the working thread and allocate a memory space for the working thread according to the memory application request of the working thread. The page allocator is used to respond to the memory application request of the memory allocator, obtain a memory block from the DPDK large page memory, divide the obtained memory block into memory pages according to a preset memory block allocation length, and return it to the memory allocator;

[0014] The preset memory block allocation length is preset by the operator as needed.

[0015] Preferably, the page allocator includes: a memory domain, a memory block and an allocation page;

[0016] The memory allocator includes: an allocator structure struct slab, a cache structure struct slab_cache and a memory allocation pool structure struct slab_node;

[0017] in,

[0018] The memory domain includes: a free page mount point and the number of nodes;

[0019] The memory block includes: the total length of the block chunk_len, the first address addr and the busy page mount point page;

[0020] The allocation page includes: the mount point node, the first address of the block chunk_addr, the first address of the page page_addr, the total page length page_len, the free and used flags flag and the page index page_index;

[0021] The allocator structure struct slab includes: allocation pool mount point, total number of available memory blocks num_blocks, number of mounted nodes num_nodes, and fast cache point cache;

[0022] The cache structure struct slab_cache includes: maximum capacity cap, mask mask, cursor head head, cursor tail tail and pointer cache array ptr;

[0023] The allocation pool structure struct slab_node includes: source type type, thread ID, memory pool flag pool_flag, total length of data block, starting address addr, source address buddy_ad, mount node node, number of allocatable pointers nums, current number of allocatable pointers cur_nums, length, mask mask, cursor head head, cursor tail tail and pointer cache array ptr;

[0024] Among them, the current number of allocatable pointers cur_nums = head-tail, head is the value of the cursor head, and tail is the value of the cursor tail;

[0025] The values of the memory pool flag pool_flag include 0 and 1. Among them, when the value of the memory pool flag pool_flag is 1, it indicates that the mounting node node corresponding to the memory pool flag pool_flag is a permanent node, and the memory blocks of the permanent node will never be released. When the value of the memory pool flag pool_flag is 0, it indicates that the mounting node node corresponding to the memory pool flag pool_flag is a temporary node. When all the memory blocks cached in the buffer structure struct slab_cache have been released to the temporary node, the mounting node node corresponding to the memory pool flag pool_flag will be released;

[0026] The source type type includes: from system memory and from DPDK large page memory.

[0027] Preferably, in step S1, the step of initializing the working thread and the memory management structure includes the step of initializing the memory domain, specifically:

[0028] Initialize the memory domain, create a memory domain array buddy_zone[w], and create free page mounting points according to the memory domain array buddy_zone[count], where the free page mounting point nodes mount free memory pages.

[0029] buddy_zone[w] =.buddy_zone[0], buddy_zone[1], …, buddy_zone[count - 1]5, where count is the number of nodes of the created free page mounting points, 0 ≤ "<count;

[0030] Preferably, in step S1, the step of initializing the working thread and the memory management structure further includes the step of initializing the memory pool, specifically:

[0031] S121, Initialize the memory pool: Based on the working thread, define an allocator structure array struct_slab[y]. The memory allocator applies for an initial memory space from the page allocator, and divides the memory space obtained from the page allocator into memory units according to the preset memory block allocation length. Based on the divided memory units, the memory allocator initializes the buffer structure struct slab_cache, the allocator structure struct slab, and the memory allocation pool structure struct slab_node according to the allocator structure array struct_slab[y].

[0032] Wherein, y is a positive integer greater than or equal to 0, and each of the working threads includes at least one buffer structure struct slab_cache and at least one allocator structure struct slab, and the buffer structure struct slab_cache and the allocator structure struct slab correspond to each other one by one;

[0033] S122, initialize the source type type and set the source type type to come from the system memory.

[0034] Preferably, the step of S121 further includes:

[0035] When it is necessary to initialize the memory pool according to the preset memory pool length and the number of memory pools, the memory allocator determines the required minimum memory space according to the preset memory pool length, the number of memory pools and the minimum memory size calculation formula, and based on the minimum memory space, applies to the page allocator and obtains the memory space;

[0036] The memory allocator divides the memory space obtained from the page allocator into memory units according to the preset memory block allocation length. Based on the divided memory units, the memory allocator initializes the buffer structure struct slab_cache, the allocator structure struct slab and the memory allocation pool structure struct slab_node according to the allocator structure array struct_slab[j], and sets the memory pool flags pool_flag of the mounting nodes node of the memory allocation pool structure struct slab_node to 1;

[0037] Wherein,

[0038] The minimum memory size calculation formula is: Mi + memory pool = -×∑ m"1 0 m +0 $%de , Mi + memory pool is the minimum memory space, - is the number of memory pools, 0 m is the preset memory pool length, ∑ m"1 0 m is the sum of all the preset memory pool lengths, m is an integer equal to 1, 0 $%de is the memory size occupied by the hanging point corresponding to the memory allocation pool structure struct slab_node;

[0039] The preset memory pool length is preset by the operator according to the memory allocation requirements for task processing;

[0040] The array of allocator structures struct_slab[y] represents a mounting node with a memory length available for allocation by the memory allocator equal to the preset memory pool length.

[0041] Preferably, the step of S2 further includes:

[0042] S21, the memory allocator responds in real time and parses the memory application request of the working thread to obtain the memory size applied by the working thread;

[0043] S22, the memory allocator compares the memory size applied by the working thread with the preset memory length,

[0044] If the memory size applied by the working thread is greater than or equal to the preset memory length, the memory allocator applies for and obtains memory from the LINUX system and jumps to step S24;

[0045] If the memory size applied by the working thread is less than the preset memory length and there is memory in the memory allocator with a size equal to the memory size applied by the working thread, jump to step S24;

[0046] If the memory size applied by the working thread is less than the preset memory length and there is no memory in the memory allocator with a size equal to the memory size applied by the working thread, the memory allocator sends a memory application request to the page allocator according to the preset fixed memory page size;

[0047] S23, the page allocator responds to the memory application request of the memory allocator and allocates memory for the page allocator according to the available memory in the page allocator and the preset fixed memory page size. If the available memory in the page allocator is greater than or equal to the preset fixed memory page size, the memory allocator obtains memory pages from the available memory in the page allocator and divides the returned memory pages according to the memory size applied by the working thread and then jumps to step S24;

[0048] If the available memory in the page allocator is less than the preset fixed memory page size, the page allocator obtains a memory block from the DPDK large page memory, divides the obtained memory block into memory pages according to the preset memory block allocation length, and returns it to the memory allocator. The memory allocator divides the returned memory pages according to the memory size applied by the working thread and then jumps to step S24;

[0049] S24, the memory allocator allocates a memory space for the working thread;

[0050] Among them,

[0051] ]Both the preset memory page fixed size and the preset memory block allocation length are preset by the operator as needed.

[0052] Preferably, the step of S2 further includes:

[0053] When the memory size requested by the working thread is greater than or equal to the preset memory length, the memory length obtained by the memory allocator from the LINUX system is 0 工作线程 +8 of memory, and modify the starting address addr of the memory pool in the memory allocator to the address of the memory returned by the LINUX system, where 0 工作线程 is the memory size requested by the working thread;

[0054] When the memory size requested by the working thread is less than the preset memory length, the memory allocator obtains the cursor head head and cursor tail tail of the buffer structure struct slab_cache according to the allocator structure array struct_slab[y], and judges the values of the cursor head head and cursor tail tail;

[0055] 1) If the value of the cursor head head of the buffer structure struct slab_cache is equal to the value of the cursor tail tail, traverse the linked list head of the mounted node node under the allocator structure array struct_slab[y], and apply for memory from the page allocator according to the traversal result. Specifically:

[0056] If the values of the cursor head head of all the mounted nodes node under the allocator structure array struct_slab[y] are equal to the value of the cursor tail tail, apply for memory from the page allocator, divide the obtained memory from the page allocator into new mounted nodes, and update the new mounted nodes to the linked list in the allocator structure array struct_slab[y];

[0057] If there is a mounted node node under the allocator structure array struct_slab[y] where the value of the cursor head head is not equal to the value of the cursor tail tail, then available memory blocks will be obtained according to the current number of allocatable pointers cur_nums of the first mounted node node in the traversal result. Among them, if the current number of allocatable pointers cur_nums is greater than or equal to 256, 256 available memory blocks will be obtained from the first mounted node node. If the current number of allocatable pointers cur_nums is less than 256, all available memory blocks will be obtained from the first mounted node node. The number of available memory blocks is equal to the value of the current number of allocatable pointers cur_nums of the first mounted node node, cur_nums = head - tail, head is the value of the cursor head, tail is the value of the cursor tail, and the number of available memory blocks is greater than or equal to 1 and less than 256; the value of the cursor head head of the buffer structure struct slab_cache is incremented by 1 to obtain a new cursor head, and memory is allocated to the worker thread according to the new cursor head.

[0058] 2) If the value of the cursor head head of the buffer structure struct slab_cache is not equal to the value of the cursor tail tail, then based on the allocator structure array struct_slab[y], the memory unit with y equal to the cursor tail tail is obtained, the value of the cursor tail tail is incremented by 1 to obtain a new cursor tail, and according to the new cursor tail and the starting address of the memory pool corresponding to the new cursor tail, and at the same time, the mask mask of the mounted node corresponding to the starting address is updated according to the starting address.

[0059] Preferably, the step of S23 further includes:

[0060] S231, when the page allocator receives a memory allocation request from the memory allocator, the page allocator queries and aligns the memory pages of the page allocator based on the memory domain array buddy_zone[w] according to the memory size requested by the memory allocator and the total page length page_len of the allocated page, and determines the number of allocatable memory pages in the page allocator according to the query and alignment results. Among them, the length of querying and aligning the memory pages of the page allocator is 34567i86×2 z , 2 z is the number of allocatable memory pages, and z is a positive integer;

[0061] S232. Determine the value of z according to the number of pages of allocatable memory in the page allocator, and judge the value of z. If z is greater than 10, return failure. If z is less than or equal to 10, update the value of the number of nodes count of the free page mount point in the memory domain array buddy_zone[w] according to the value of z;

[0062] S233. If the value of the number of nodes count of the free page mount point is greater than 0, delete the first free page mount point in the memory domain array buddy_zone[w], subtract 1 from the value of the number of nodes count of the free page mount point, and according to the starting address chunk_addr of the block to which the first deleted free page mount point belongs in the allocated page corresponding to the starting address, mount the free page mount point corresponding to the starting address chunk_addr of the block to which it belongs under the busy page mount point page;

[0063] If the value of the number of nodes count of the free page mount point is equal to 0, traverse and query the memory domain array buddy_zone[w] according to the subscript of the preset traversal query. If the result of traversing and querying the memory domain array buddy_zone[w] is not empty, the page allocator returns a memory block with a memory page length of 34567i86×2 z to the memory allocator. If the result of traversing and querying the memory domain array buddy_zone[w] is empty, the page allocator obtains a memory block from the DPDK large page memory, divides the obtained memory block into memory pages according to the preset memory block allocation length, and returns it to the memory allocator;

[0064] Among them, the value of the subscript of the preset traversal query is greater than or equal to (z + 1) and less than or equal to 9.

[0065] Preferably, the steps of S3 include the memory release step of the memory allocator and the memory release step of the page allocator;

[0066] The memory release step of the memory allocator is specifically:

[0067] S31-1. After the user completes the task processing using the allocated memory, submit a memory release request to the working thread corresponding to the memory allocation request;

[0068] S31-2, the memory allocator obtains the starting address of the memory corresponding to the memory allocation request through the working thread, and releases the memory according to the source type type of the memory corresponding to the memory allocation request. If the source type type of the memory corresponding to the memory allocation request is from the system memory, it calls the LINUX system memory release interface to release the memory. If the source type type of the memory corresponding to the memory allocation request is from the DPDK large page memory, it releases the memory corresponding to the memory allocation request into the cache of the cache structure struct slab_cache of the memory allocator;

[0069] If the cache of the cache structure struct slab_cache is full, it releases 256 memory blocks in the cache to the mount node node of the allocation pool structure struct slab_node, and releases all mount nodes node. If the mount node node is a temporary node and the value of the current allocable pointer number cur_nums in the mount node node is equal to the allocable pointer number nums, it releases all the memory blocks of the mount node node to the page allocator; if the cache of the cache structure struct slab_cache is not full, it releases the memory corresponding to the memory allocation request into the cache of the cache structure struct slab_cache of the memory allocator;

[0070] The memory release step of the page allocator is specifically as follows:

[0071] When the memory allocator releases memory, the page allocator merges and releases the memory released by the memory allocator according to the allocation page information in the pointer for the memory allocator to release memory, and according to the memory page length of 34567i86×2 z where 2 z is the number of pages of allocable memory, and z is a positive integer.

[0072] Correspondingly, the present invention also provides a DPDK memory management system based on load balancing. The system includes a memory initialization unit, a memory allocation unit, and a memory recovery unit;

[0073] Among them,

[0074] The memory initialization unit is used to define a memory management structure: based on a load balancing device and a working thread, define a memory management structure, and initialize the working thread and the memory management structure. Among them, the memory management structure includes: a page allocator and a memory allocator;

[0075] The memory allocation unit is configured to enable the working thread to receive in real time and issue a memory application request according to the user task processing request, perform memory allocation processing on the memory application request of the working thread based on the page allocator and the memory allocator, and allocate a memory space for the memory application request of the working thread according to the memory allocation processing result;

[0076] The memory recycling unit is configured to recycle the memory space according to the source type type of the memory space when the working thread corresponding to the memory allocation request completes task processing and releases the memory after using the memory space;

[0077] Each working thread has a corresponding private page allocator and memory allocator. The memory allocator is configured to respond to the memory application request of the working thread and allocate a memory space for the working thread according to the memory application request of the working thread. The page allocator is configured to respond to the memory application request of the memory allocator, obtain a memory block from the DPDK large page memory, divide the obtained memory block into memory pages according to a preset memory block allocation length, and return it to the memory allocator;

[0078] The preset memory block allocation length is preset by the operator as needed.

[0079] By applying the above technical solutions, the present invention realizes the problems of the memory pool being unable to scale, intense lock competition when the working thread frequently calls (rte_malloc()), and too large management header overhead by building a private allocator (SLAB) and buddy system (BUDDY) in each working thread. At the same time, each thread only applies for memory from its own private SLAB and BUDDY, and does not apply for memory from the SLAB and BUDDY of other threads, solving the technical problems of the pre-allocated memory being continuously occupied, unable to scale, the performance of the application program decreasing, and large management header overhead existing in the prior art, thereby reducing the lock competition in the memory application process, reducing the management header overhead, and improving the performance of memory management and memory utilization. BRIEF DESCRIPTION OF THE DRAWINGS

[0080] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those skilled in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0081] Figure 1 It shows a schematic flowchart of a method for DPDK memory management based on load balancing proposed in an embodiment of the present invention;

[0082] Figure 2 shows the DPDK memory management architecture diagram;

[0083] Figure 3 shows the schematic diagram of the mounting situation of a memory block in BUDDY at a certain moment;

[0084] Figure 4 shows the schematic diagram of the SLAB allocator structure;

[0085] Figure 5 shows the schematic diagram of the memory blocks in the SLAB memory pool;

[0086] Figure 6 shows the schematic diagram of the SLAB cache;

[0087] Figure 7 shows the schematic diagram of the structure of a DPDK memory management system based on load balancing proposed in an embodiment of the present invention. Detailed implementation manners

[0088] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0089] The present invention provides a method for DPDK memory management based on load balancing, as Figure 1 shown, the method includes the following steps:

[0090] S1. Define the memory management structure: Based on the load balancing device and the working threads, define the memory management structure, and initialize the working threads and the memory management structure. Among them, the memory management structure includes: a page allocator (BUDDY) and a memory allocator (SLAB).

[0091] Among them,

[0092] each of the working threads has a corresponding private page allocator (BUDDY) and memory allocator (SLAB). The memory allocator (SLAB) is used to respond to the memory application requests of the working threads, and allocate memory spaces for the working threads according to the memory application requests of the working threads. The page allocator (BUDDY) is used to respond to the memory application requests of the memory allocator (SLAB), obtain memory blocks from the DPDK large page memory, divide the obtained memory blocks into memory pages according to the preset memory block allocation length, and return them to the memory allocator (SLAB);

[0093] The preset memory block allocation length is preset by the operator as needed.

[0094] In this embodiment, the page allocator (BUDDY) includes: a memory domain (buddy_zone), a memory block (buddy_chunk) and an allocation page (buddy_page);

[0095] The memory allocator (SLAB) includes: an allocator structure struct slab, a cache structure struct slab_cache and a memory allocation pool structure struct slab_node;

[0096] in,

[0097] The memory domain (buddy_zone) includes: a free page mount point head and a node count;

[0098] The memory block (buddy_chunk) includes: the total length of the block chunk_len, the first address addr and the busy page mount point page;

[0099] The allocation page (buddy_page) includes: the mount point node, the first address of the block chunk_addr, the first address of the page page_addr, the total page length page_len, the free and used flags flag and the page index page_index;

[0100] The allocator structure struct slab includes: allocation pool mount point, total number of available memory blocks num_blocks, number of mounted nodes num_nodes, and fast cache point cache;

[0101] The cache structure struct slab_cache includes: maximum capacity cap, mask mask, cursor head head, cursor tail tail and pointer cache array ptr;

[0102] The allocation pool structure struct slab_node includes: source type type, thread ID, memory pool flag pool_flag, total length of data block, starting address addr, source address buddy_ad, mount node node, number of allocatable pointers nums, current number of allocatable pointers cur_nums, length, mask mask, cursor head head, cursor tail tail and pointer cache array ptr;

[0103] Among them, the current number of allocatable pointers cur_nums = head - tail, where head is the value of the cursor head and tail is the value of the cursor tail;

[0104] The value of the memory pool flag pool_flag includes 0 and 1. Among them, when the value of the memory pool flag pool_flag is 1, it indicates that the mounted node node corresponding to the memory pool flag pool_flag is a permanent node, and the memory blocks of the permanent node will never be released. When the value of the memory pool flag pool_flag is 0, it indicates that the mounted node node corresponding to the memory pool flag pool_flag is a temporary node. When all the memory blocks cached in the buffer structure struct slab_cache have been released to the temporary node, the mounted node node corresponding to the memory pool flag pool_flag will be released;

[0105] The source type type includes: from system memory and from DPDK large page memory.

[0106] In this embodiment, in step S1, the step of initializing the working thread and the memory management structure includes the step of memory domain initialization, specifically:

[0107] Initialize the memory domain, create a memory domain array buddy_zone[w], and create an idle page mount point head according to the memory domain array buddy_zone[count]. Among them, the idle page mount point head node mounts idle memory pages.

[0108] buddy_zone[w] =.buddy_zone[0], buddy_zone[1], …, buddy_zone[count - 1]5, where count is the number of nodes count of the created idle page mount point head, 0 ≤ "<count;

[0109] In this embodiment, it is characterized in that, in step S1, the step of initializing the working thread and the memory management structure further includes the step of memory pool initialization, specifically:

[0110] S121, Initialize the memory pool: Based on the working thread, define an array of allocator structures struct_slab[y]. The memory allocator (SLAB) requests an initialized memory space from the page allocator (BUDDY), and divides the memory space obtained from the page allocator (BUDDY) into memory units according to the preset memory block allocation length. Based on the divided memory units, the memory allocator (SLAB) initializes the cache structure struct slab_cache, the allocator structure struct slab, and the memory allocation pool structure structslab_node according to the array of allocator structures struct_slab[y].

[0111] Where y is a positive integer greater than or equal to 0, and each working thread includes at least one cache structure structslab_cache and at least one allocator structure struct slab, and the cache structure struct slab_cache and the allocator structure struct slab correspond one by one;

[0112] S122, Initialize the source type type and set the source type type to come from system memory.

[0113] In this embodiment, the steps of S121 further include:

[0114] When it is necessary to initialize the memory pool according to the preset memory pool length and the number of memory pools, the memory allocator (SLAB) determines the required minimum memory space according to the preset memory pool length, the number of memory pools, and the minimum memory size calculation formula, and based on the minimum memory space, requests and obtains a memory space from the page allocator (BUDDY);

[0115] The memory allocator (SLAB) divides the memory space obtained from the page allocator (BUDDY) into memory units according to the preset memory block allocation length. Based on the divided memory units, the memory allocator (SLAB) initializes the cache structure struct slab_cache, the allocator structure struct slab, and the memory allocation pool structure struct slab_node according to the array of allocator structures struct_slab[j], and sets the memory pool flags pool_flag of the mounting nodes node of the memory allocation pool structure struct slab_node to 1;

[0116] Where

[0117] The minimum memory size calculation formula is: Mi + memory pool = -×∑ m"1 0m +0 $%de , the Mi + memory pool is the minimum memory space, - is the number of memory pools, 0 m is the preset memory pool length, ∑ m"1 0 m is the sum of all the preset memory pool lengths, m is an integer equal to 1, 0 $%de is the memory size occupied by the hanging point corresponding to the memory allocation pool structure struct slab_node;

[0118] The preset memory pool length is preset by the operator according to the memory allocation requirements for task processing;

[0119] The allocator structure array struct_slab[y] represents a mounting node where the memory length available for the memory allocator (SLAB) to allocate is the preset memory pool length.

[0120] S2. The working thread receives in real time and issues a memory application request according to the user task processing request, and performs memory allocation processing on the memory application request of the working thread based on the page allocator (BUDDY) and the memory allocator (SLAB), and allocates a memory space for the memory application request of the working thread according to the memory allocation processing result.

[0121] In this embodiment, the steps of S2 further include:

[0122] S21. The memory allocator (SLAB) responds in real time and parses the memory application request of the working thread to obtain the memory size applied by the working thread;

[0123] S22. The memory allocator (SLAB) compares the memory size applied by the working thread with the preset memory length,

[0124] If the memory size applied by the working thread is greater than or equal to the preset memory length, the memory allocator (SLAB) applies for and obtains memory from the LINUX system and jumps to step S24;

[0125] If the memory size applied by the working thread is less than the preset memory length and there is memory in the memory allocator (SLAB) whose size is equal to the memory size applied by the working thread, it jumps to step S24;

[0126] If the memory size requested by the working thread is less than the preset memory length, and there is no memory in the memory allocator (SLAB) with a size equal to the memory size requested by the working thread, then the memory allocator (SLAB) sends a memory request to the page allocator (BUDDY) according to the preset fixed size of the memory page;

[0127] S23. The page allocator (BUDDY) responds to the memory request of the memory allocator (SLAB), and allocates memory for the page allocator (BUDDY) according to the available memory in the page allocator (BUDDY) and the preset fixed size of the memory page. If the available memory in the page allocator (BUDDY) is greater than or equal to the preset fixed size of the memory page, the memory allocator (SLAB) obtains a memory page from the available memory in the page allocator (BUDDY), divides the returned memory page according to the memory size requested by the working thread, and then jumps to step S24;

[0128] If the available memory in the page allocator (BUDDY) is less than the preset fixed size of the memory page, the page allocator (BUDDY) obtains a memory block from the DPDK large page memory, divides the obtained memory block into memory pages according to the preset memory block allocation length, and returns them to the memory allocator (SLAB). The memory allocator (SLAB) divides the returned memory page according to the memory size requested by the working thread, and then jumps to step S24;

[0129] S24. The memory allocator (SLAB) allocates a memory space for the working thread;

[0130] Among them,

[0131] Both the preset fixed size of the memory page and the preset memory block allocation length are preset by the operator as needed.

[0132] In this embodiment, the steps of S2 further include:

[0133] When the memory size requested by the working thread is greater than or equal to the preset memory length, the memory allocator (SLAB) obtains a memory with a length of 0 working thread + 8 from the LINUX system, and modifies the starting address addr of the memory pool in the memory allocator (SLAB) to the address of the memory returned by the LINUX system, where 0 工作线程 is the memory size requested by the working thread;

[0134] When the memory size requested by the working thread is less than the preset memory length, the memory allocator (SLAB) obtains the cursor head and cursor tail of the buffer structure struct slab_cache according to the allocator structure array struct_slab[y], and judges the values of the cursor head and cursor tail;

[0135] 1) If the value of the cursor head of the buffer structure struct slab_cache is equal to the value of the cursor tail, traverse the linked list head of the mounted node node under the allocator structure array struct_slab[y], and apply for memory from the page allocator according to the traversal result. Specifically:

[0136] If the values of the cursor heads of all the mounted nodes node under the allocator structure array struct_slab[y] are equal to the values of the cursor tails, apply for memory from the page allocator, divide the memory obtained from the page allocator into new mounted nodes, and update the new mounted nodes to the linked list of the allocator structure array struct_slab[y];

[0137] If there is a mounted node node under the allocator structure array struct_slab[y] where the value of the cursor head is not equal to the value of the cursor tail, obtain available memory blocks according to the current number of allocatable pointers cur_nums of the first mounted node in the traversal result. Specifically, if the current number of allocatable pointers cur_nums is greater than or equal to 256, obtain 256 available memory blocks from the first mounted node. If the current number of allocatable pointers cur_nums is less than 256, obtain all available memory blocks from the first mounted node. The number of available memory blocks is equal to the value of the current number of allocatable pointers cur_nums of the first mounted node, cur_nums = head - tail, head is the value of the cursor head, tail is the value of the cursor tail, and the number of available memory blocks is greater than or equal to 1 and less than 256; add 1 to the value of the cursor head of the buffer structure struct slab_cache to get a new cursor head, and allocate memory for the working thread according to the new cursor head;

[0138] 2) If the value of the cursor head of the buffer structure struct slab_cache is not equal to the value of the cursor tail, obtain the memory cell where y is equal to the cursor tail based on the allocator structure array struct_slab[y], add 1 to the value of the cursor tail to obtain a new cursor tail, and update the mask of the mounted node corresponding to the head address according to the new cursor tail and the head address of the memory pool corresponding to the new cursor tail.

[0139] In this embodiment, the step of S23 further includes:

[0140] S231, when the page allocator (BUDDY) receives a memory allocation request from the memory allocator (SLAB), the page allocator (BUDDY) queries and aligns the memory pages of the page allocator (BUDDY) based on the memory domain array buddy_zone[w], according to the memory size requested by the memory allocator (SLAB) and the total page length page_len of the allocated page (buddy_page), and determines the number of allocatable memory pages in the page allocator (BUDDY), where the length of querying and aligning the memory pages of the page allocator (BUDDY) is 34567i-eight-six × 2 z , 2 z is the number of allocatable memory pages, and z is a positive integer;

[0141] S232, determine the value of z according to the number of allocatable memory pages in the page allocator (BUDDY), and judge the value of z. If z is greater than 10, return failure. If z is less than or equal to 10, update the value of the node count count of the free page mount point head in the memory domain array buddy_zone[w] according to the value of z;

[0142] S233, if the value of the node count count of the free page mount point head is greater than 0, delete the first free page mount point head in the memory domain array buddy_zone[w], subtract 1 from the value of the node count count of the free page mount point head, and mount the free page mount point head corresponding to the chunk address chunk_addr in the allocated page (buddy_page) corresponding to the first deleted free page mount point head under the busy page mount point page;

[0143] If the number of nodes count of the free page mount point head is equal to 0, traverse and query the memory zone array buddy_zone[w] according to the preset traversal query subscript. If the result of traversing and querying the memory zone array buddy_zone[w] is not empty, the page allocator (BUDDY) returns a memory block with a memory page length of 34567i86×2 to the memory allocator (SLAB). z If the result of traversing and querying the memory zone array buddy_zone[w] is empty, the page allocator (BUDDY) obtains a memory block from the DPDK large page memory, divides the obtained memory block into memory pages according to the preset memory block allocation length, and returns it to the memory allocator (SLAB).

[0144] Among them, the value of the preset traversal query subscript is greater than or equal to (z + 1) and less than or equal to 9.

[0145] S3. When the working thread corresponding to the memory allocation request uses the memory space to complete task processing and releases the memory, recycle the memory space according to the source type type of the memory space.

[0146] In this embodiment, the step of S3 includes the memory release step of the memory allocator and the memory release step of the page allocator.

[0147] The memory release step of the memory allocator is specifically as follows:

[0148] S31-1. After the user uses the allocated memory to complete task processing, submit a memory release request to the working thread corresponding to the memory allocation request.

[0149] S31-2. The memory allocator (SLAB) obtains the starting address of the memory corresponding to the memory allocation request through the working thread, and releases the memory according to the source type type of the memory corresponding to the memory allocation request. If the source type type of the memory corresponding to the memory allocation request is from the system memory, call the LINUX system memory release interface to release the memory. If the source type type of the memory corresponding to the memory allocation request is from the DPDK large page memory, release the memory corresponding to the memory allocation request to the cache of the cache structure struct slab_cache of the memory allocator (SLAB).

[0150] If the cache of the cache structure struct slab_cache is full, release 256 memory blocks in the cache to the mount node node of the allocation pool structure struct slab_node, and release all mount nodes node. If the mount node node is a temporary node and the value of the current allocable pointer count cur_nums in the mount node node is equal to the allocable pointer count nums, release all memory blocks of the mount node node to the page allocator;

[0151] If the cache of the cache structure struct slab_cache of the memory allocator is not full, release the memory corresponding to the memory allocation request to the cache of the cache structure struct slab_cache of the memory allocator (SLAB);

[0152] The memory release step of the page allocator is specifically as follows:

[0153] When the memory allocator (SLAB) releases memory, the page allocator (BUDDY) releases the memory released by the memory allocator (SLAB) after merging it according to the allocated page (buddy_page) information in the pointer for the memory allocator (SLAB) to release memory, and according to the memory page length of 34567i86×2 z where 2 z is the number of pages of allocable memory, and z is a positive integer.

[0154] To enable those skilled in the art to better understand the technical solution provided by the present invention, the above steps are further supplemented and illustrated by examples as Figures 2 to 6 shown.

[0155] The working thread applies for memory from SLAB. If the size of the applied memory is greater than or equal to the preset length, such as 1MB, SLAB directly calls the system memory application function malloc() to apply for memory from the LINUX system. If the size is less than the preset memory size of 1MB and there is just the right size of memory in SLAB, it is directly allocated to the working thread;

[0156] If there is no memory of the right size in SLAB, SLAB applies for a certain number of memory pages of the preset fixed size from BUDDY. SLAB divides the applied number of memory pages into memory blocks that are just greater than or equal to the size requirement of the memory block applied by the working thread, makes them into multiple allocable memory blocks of the same size, and then the SLAB allocator returns one of them;

[0157] If the SLAB requests a fixed-size memory block from the BUDDY and there is no available memory in the BUDDY, the BUDDY calls rte_malloc() to request a memory block of a preset size from the DPDK large-page memory. The size of the requested preset memory block is much larger than 80 bytes.

[0158] As described above, only when the BUDDY has no memory, rte_malloc() is called to allocate memory, which greatly reduces the number of calls to the rte_malloc() interface, thereby reducing lock contention. Moreover, the preset memory block that the BUDDY requests from the DPDK each time is much larger than the 80-byte management header, thus improving memory utilization. Each thread requests memory from its own private SLAB and BUDDY. If there is appropriate memory in either the SLAB or the BUDDY, there is no competition problem.

[0159] To avoid exceptions caused by the memory applied for by the current thread being released by other threads, the upper-layer application needs to ensure that the memory applied for by the current thread must be released by the current thread.

[0160] The specific implementation steps are as follows:

[0161] Step 1: Design a memory management architecture based on the load balancer device

[0162] Based on the disadvantages of the current DPDK solution, this solution proposes a new memory management architecture design scheme as Figure 2 shown. Each thread has a thread-private SLAB and BUDDY. The BUDDY obtains a preset memory block from the DPDK and organizes and manages it by page. The SLAB obtains a multiple-of-page memory from the BUDDY and divides it into memory blocks of 8, 16, 32, etc. for refined management. The user obtains available memory from the SLAB.

[0163] Step 2: The structure of the BUDDY, as well as the initialization, usage, and recycling of the BUDDY

[0164] The BUDDY structure is divided into struct buddy_page, strcut buddy_chunk, and struct buddy_zone. struct buddy_zone manages all free struct buddy_pages, and strcut buddy_chunk mounts the struct buddy_pages that are busy (being used) in the current chunk.

[0165] The struct buddy_zone structure is shown in Table 1.

[0166] Table 1

[0167]

[0168] The struct buddy_chunk structure is shown in Table 2.

[0169] Table 2

[0170]

[0171]

[0172] The struct buddy_page structure is shown in Table 3.

[0173] Table 3

[0174]

[0175] BUDDY initialization: At initialization, first initialize the structure array, which mounts all free pages: static __thread struct buddy_zone buddy_zone

[10] ;

[0176] Initialize each member of buddy_zone: head->next = head->prev;

[0177] count = 0;

[0178] BUDDY usage: SLAB requests memory from BUDDY. According to the memory size required by SLAB plus the length of the struct buddy_page structure, align it upward to the page length 34567i86×2 z , where Z is the smallest positive integer that can meet the requirement, and Z does not exceed 10 at most. SLAB ensures that it will not request memory with N exceeding 10. If it exceeds, it returns failure. According to the calculated Z, then judge the count of buddy_zone[w];

[0179] If the count of buddy_zone[w] (available memory) is not 0, then delete the first node mounted under the head of buddy_zone[w], then decrement count by 1, and according to the element chunk_addr in struct buddy_page in the start address of the deleted first node, mount this node under the corresponding busy node mount point struct buddy_chunk;

[0180] If it is 0, then search for elements in the buddy_zone subscript range from N + 1 to 9 (10 - 1). If there is an available page, split out a 34567i86×2 zMemory: Mount the struct buddy_page of the starting address of the split memory under the corresponding struct buddy_chunk. Make the remaining memory into the structure of one or more struct buddy_pages, mount it under the head of the corresponding buddy_zone element, and increase the count value under this element (for example, the production method: if 1 page is taken from 4 pages and 3 pages remain, then the starting address of the 1 page with the lowest address among these 3 pages is converted into a struct buddy_page page instance, and then initialized. Let this struct buddy_page page manage this 1 page. Finally, mount this struct buddy_page page that manages 1 page under buddy_zone[0]. The starting address part of the remaining 2 pages is converted into struct buddy_page page2, and then initialized to let it manage these 2 pages. Finally, mount it under buddy_zone[1]);

[0181] If no available element is found in the range search, directly apply to DPDK for the memory with the length of struct buddy_chunk + 34567i86×2 z Memory: The starting part of the applied memory is a struct buddy_chunk structure, which is initialized. Then, mount the page nodes to be allocated under this struct buddy_chunk according to the searched process, and mount the free nodes under the struct buddy_zone element.

[0182] BUDDY recycling: When the SLAB releases a page, BUDDY obtains the struct buddy_page structure before the pointer according to the released pointer, and then judges whether it can be merged into a 34567i86×2 z block. If it can, merge and mount it under the corresponding buddy_zone[N]. If N is 10, release it to DPDK. If not, mount the released page under the corresponding buddy_zone[len / pagesize] element according to the len of the struct buddy_page element of the released page, and wait to be applied next time.

[0183] Step 3: The structure of SLAB and the initialization, usage and recycling of SLAB

[0184] After the working thread starts, it is necessary to initialize the private SLAB. The SLAB consists of, for example Figure 4It consists of the three structures shown below, namely: the allocator structure struct slab, the cache structure struct slab_cache, and the memory allocation pool structure struct slab_node.

[0185] The struct slab structure is shown in Table 4:

[0186] Table 4

[0187] member type meaning head struct list SLAB allocation pool mount point num_blocks uint32_t Total number of available memory blocks num_nodes uint32_t Number of mounted nodes cache struct slab_cache Fast cache point

[0188] The struct slab_cache structure is shown in Table 5:

[0189] Table 5

[0190]

[0191]

[0192] The struct slab_node structure is shown in Table 6:

[0193] Table 6

[0194]

[0195] The source types are shown in the following table:

[0196]

[0197] SLAB initialization: Define a private structure array static __thread struct list slab

[245] ; The memory block length organization table is shown in Table 7. Initialize each element in the structure: slab->next = slab->prev. slab[0] is the mounting point of the struct slab_node with an allocable memory block length of 8, and slab[1] is the mounting point of the struct slab_node with an allocable memory block length of 16. It can be inferred in accordance with Table 7.

[0198] Table 7

[0199]

[0200]

[0201] Initialize an enumeration type variable to determine the memory source int type = SLAB_TYPE_SYSTEM;

[0202] Initially, if a thread requires a memory pool of a certain length, SLAB calculates the minimum memory size (N * (L + 8 + 9) + sizeof(struct slab_node)) based on the given number N and length L, and then applies for memory from BUDDY. After the application, the initial address part of the memory stores and initializes the struct slab_node structure, where the pool_flags field is initialized to 1, indicating that this struct slab_node will not be released.

[0203] SLAB usage: The SLAB memory model is as Figure 5 shown. For memory greater than or equal to 1MB, the initial address of SLAB points to the address of the type with the value of SLAB_TYPE_SYSTEM; for memory less than 1MB, the initial address of SLAB points to the initial address returned by BUDDY, and this address stores the struct slab_node structure.

[0204] Threads apply for DPDK large-page memory through the SLAB interface, in two cases:

[0205] When the input memory length is greater than or equal to 1MB, SLAB calls the LINUX system interface to apply for memory (required length = user memory required length + 8), and makes the initial address of SLAB equal to the address of the type. In this way, when this memory is released, obtaining this type can directly release it to the LINUX system;

[0206] When the input memory length is less than 1MB, SLAB first obtains the corresponding slab index N, and then obtains a memory block from the cache under struct_slab[y]. The cache is as Figure 6 shown. Determine whether tail and head are equal. If they are not equal, there is available memory. Obtain the memory block with the subscript of tail, and let tail + 1. Then, after setting the mask bit of the corresponding struct slab_node according to the initial address of this SLAB, return the return address; if tail and head are equal, traverse the head of struct_slab[y], obtain up to 512 / 2 memory blocks and store them in the cache, move the cursor head to head + the number of obtained memory blocks, and then return an available one. If there are no available memory blocks when traversing head, apply for memory from BUDDY, create a struct slab_node, and mount it to the head under struct_slab[y] for allocation.

[0207] SLAB recycling: When the user releases memory, obtain the initial address of SLAB, and then release it according to the source type type:

[0208] If it is SLAB_TYPE_SYSTEM, call the system release interface;

[0209] If it is SLAB_TYPE_DPDK, store it in the cache of the SLAB and clear the corresponding mask bit. If the cache is not full after storage, the release ends. If the cache is full, obtain 512 / 2 = 256 caches and store them in the struct slab_node. If all the memory blocks in a certain struct slab_node have been released during the processing of these 256 memory blocks and the pool_flags is not 1, release this struct slab_node block to the BUDDY system.

[0210] By applying the above technical solutions, it is possible to avoid the problem that the memory pool cannot be scaled, the lock competition is fierce when the working thread frequently calls (rte_malloc()), and the management header overhead of rte_malloc() is too large by building a private allocator (SLAB) and buddy system (BUDDY) in each working thread. At the same time, each thread will only apply for memory from its own private SLAB and BUDDY, rather than from the SLAB and BUDDY of other threads, solving the technical problems in the prior art that the pre-allocated memory will always be occupied, cannot be scaled, the performance of the application program decreases, and the management header overhead is large, thereby reducing the lock competition during the memory application process, reducing the management header overhead, and improving the performance of memory management and memory utilization.

[0211] Corresponding to the method for DPDK memory management based on load balancing in an embodiment of the present invention, the present invention also discloses a system for DPDK memory management based on load balancing, as Figure 7 shown. The system includes a memory initialization unit, a memory allocation unit, and a memory recovery unit;

[0212] Among them,

[0213] The memory initialization unit is used to define a memory management structure: based on a load balancing device and a working thread, define a memory management structure, and initialize the working thread and the memory management structure, where the memory management structure includes: a page allocator (BUDDY) and a memory allocator (SLAB);

[0214] The memory allocation unit is used for the working thread to receive in real time and issue a memory application request according to the user task processing request, and perform memory allocation processing on the memory application request of the working thread based on the page allocator (BUDDY) and the memory allocator (SLAB), and allocate a memory space for the memory application request of the working thread according to the memory allocation processing result;

[0215] The memory recycling unit is configured to recycle the memory space according to the source type type of the memory space when the working thread corresponding to the memory allocation request uses the memory space to complete task processing and releases the memory.

[0216] Each of the working threads has a corresponding private page allocator (BUDDY) and memory allocator (SLAB). The memory allocator (SLAB) is configured to respond to the memory application request of the working thread and allocate a memory space for the working thread according to the memory application request of the working thread. The page allocator (BUDDY) is configured to respond to the memory application request of the memory allocator (SLAB), obtain a memory block from the DPDK large page memory, divide the obtained memory block into memory pages according to a preset memory block allocation length, and return it to the memory allocator (SLAB).

[0217] The preset memory block allocation length is preset by the operator as needed.

[0218] Each embodiment in this specification is described in a related manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments.

[0219] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A method for DPDK memory management based on load balancing, characterized in that The method comprises: S1, defining a memory management structure: based on a load balancing device and a working thread, defining a memory management structure, and initializing the working thread and the memory management structure, wherein the memory management structure includes: a page allocator and a memory allocator; S2, the worker thread receives in real time and issues a memory application request according to the user task processing request, performs memory allocation processing on the memory application request of the worker thread based on the page allocator and the memory allocator, and allocates memory space for the memory application request of the worker thread according to the memory allocation processing result; S3, when the worker thread corresponding to the memory allocation request completes task processing using the memory space and releases memory, reclaiming the memory space according to the source type of the memory space; in, Each of the worker threads has a corresponding private page allocator and memory allocator. The memory allocator is used to respond to the memory application request of the worker thread and allocate memory space to the worker thread according to the memory application request of the worker thread. The page allocator is used to respond to the memory application request of the memory allocator, obtain memory blocks from the DPDK large page memory, divide the obtained memory blocks into memory pages according to the preset memory block allocation length, and return them to the memory allocator. The preset memory block allocation length is preset by the operator as needed.

2. The method according to claim 1, wherein The page allocator includes: a memory domain, a memory block and an allocation page; The memory allocator includes: an allocator structure struct slab, a cache structure struct slab_cache and a memory allocation pool structure struct slab_node; in, The memory domain includes: a free page mount point and the number of nodes; The memory block includes: the total length of the block chunk_len, the first address addr and the busy page mount point page; The allocation page includes: the mount point node, the first address of the block chunk_addr, the first address of the page page_addr, the total page length page_len, the free and used flags flag and the page index page_index; The allocator structure struct slab includes: allocation pool mount point, total number of available memory blocks num_blocks, number of mounted nodes num_nodes, and fast cache point cache; The cache structure struct slab_cache includes: maximum capacity cap, mask mask, cursor head head, cursor tail tail and pointer cache array ptr; The allocation pool structure struct slab_node includes: source type type, thread ID, memory pool flag pool_flag, total data block length, starting address addr, source address buddy_ad, mounted node node, number of allocable pointers nums, current number of allocable pointers cur_nums, length, mask mask, cursor head head, cursor tail tail, and pointer cache array ptr; Among them, the current number of allocable pointers cur_nums = head - tail, where head is the value of the cursor head and tail is the value of the cursor tail; The value of the memory pool flag pool_flag includes 0 and 1. Among them, when the value of the memory pool flag pool_flag is 1, it indicates that the mounted node node corresponding to the memory pool flag pool_flag is a permanent node, and the memory block of the permanent node will never be released. When the value of the memory pool flag pool_flag is 0, it indicates that the mounted node node corresponding to the memory pool flag pool_flag is a temporary node. When all the memory blocks cached in the cache structure struct slab_cache have been released to the temporary node, the mounted node node corresponding to the memory pool flag pool_flag will be released; The source type type includes: from system memory and from DPDK large page memory.

3. The method according to claim 1, wherein In step S1, the step of initializing the working thread and the memory management structure includes the step of initializing the memory domain, specifically: Initialize the memory domain, create a memory domain array buddy_zone[w], and create free page mounting points according to the memory domain array buddy_zone[count], where free memory pages are mounted in the free page mounting point nodes, buddy_zone[w] =.buddy_zone[0], buddy_zone[1], …, buddy_zone[count - 1]5, where count is the number of nodes of the created free page mounting points, 0 ≤ "<count.

4. The method according to claim 1, wherein In step S1, the step of initializing the working thread and the memory management structure also includes the step of initializing the memory pool, specifically: S121, Initialize the memory pool: Based on the working thread, define an allocator structure array struct_slab[y]. The memory allocator applies for an initialized memory space from the page allocator, and divides the memory space obtained from the page allocator into memory units according to the preset memory block allocation length. Based on the divided memory units, the memory allocator initializes the cache structure struct slab_cache, the allocator structure struct slab, and the memory allocation pool structure struct slab_node according to the allocator structure array struct_slab[y], Where y is a positive integer greater than or equal to 0, each of the working threads includes at least 1 buffer structure struct slab_cache and at least 1 allocator structure struct slab, and the buffer structure struct slab_cache and the allocator structure struct slab correspond to each other one by one; S122, initialize the source type type and set the source type type to be from the system memory.

5. The method according to claim 4, wherein The steps of S121 further include: When it is necessary to initialize the memory pool according to the preset memory pool length and the number of memory pools, the memory allocator determines the required minimum memory space according to the preset memory pool length, the number of memory pools, and the minimum memory size calculation formula, and based on the minimum memory space, applies to the page allocator and obtains the memory space; The memory allocator divides the memory space obtained from the page allocator into memory units according to the preset memory block allocation length. Based on the divided memory units, the memory allocator initializes the buffer structure struct slab_cache, the allocator structure struct slab, and the memory allocation pool structure struct slab_node according to the allocator structure array struct_slab[j], and sets the memory pool flags pool_flag of the mounting nodes node of the memory allocation pool structure struct slab_node to 1; Where The calculation formula for the minimum memory size is: Mi + memory pool = - × ∑ m"1 0 m + 0 $%de , where Mi + memory pool is the minimum memory space, - is the number of memory pools, 0 m is the preset memory pool length, and ∑ m"1 0 m is the sum of all the preset memory pool lengths, m is an integer equal to 1, 0 $%de is the memory size occupied by the hanging point corresponding to the memory allocation pool structure struct slab_node; The preset memory pool length is preset by the operator according to the memory allocation requirements of task processing; The allocator structure array struct_slab[y] represents the mounting node with a memory length of the preset memory pool length available for the memory allocator to allocate.

6. The method according to claim 1, wherein The steps of S2 further include: S21, the memory allocator responds in real time and parses the memory application request of the working thread to obtain the memory size applied by the working thread; S22, the memory allocator compares the memory size applied by the working thread with the preset memory length, If the memory size applied by the working thread is greater than or equal to the preset memory length, the memory allocator applies to the LINUX system and obtains the memory, and jumps to step S24; If the memory size applied by the working thread is less than the preset memory length and there is memory in the memory allocator with a size equal to the memory size applied by the working thread, jump to step S24; If the memory size applied by the working thread is less than the preset memory length and there is no memory in the memory allocator with a size equal to the memory size applied by the working thread, the memory allocator sends a memory application request to the page allocator according to the preset memory page fixed size; S23, the page allocator responds to the memory application request of the memory allocator, and allocates memory for the page allocator according to the available memory in the page allocator and the preset fixed size of the memory page. If the available memory in the page allocator is greater than or equal to the preset fixed size of the memory page, the memory allocator obtains a memory page from the available memory in the page allocator, divides the returned memory page according to the memory size applied by the working thread, and then jumps to step S24; If the available memory in the page allocator is less than the preset fixed size of the memory page, the page allocator obtains a memory block from the DPDK large page memory, divides the obtained memory block into memory pages according to the preset memory block allocation length, and returns it to the memory allocator. The memory allocator divides the returned memory page according to the memory size applied by the working thread and then jumps to step S24; S24, the memory allocator allocates a memory space for the working thread; Among them, both the preset fixed size of the memory page and the preset memory block allocation length are preset by the operator as needed.

7. The method according to claim 6, wherein The steps of S2 further include: When the memory size requested by the working thread is greater than or equal to the preset memory length, the memory length obtained by the memory allocator from the LINUX system is 0 工作线程 +8 of memory, and modify the starting address addr of the memory pool in the memory allocator to the address of the memory returned by the LINUX system, where 0 工作线程 is the memory size requested for the working thread; When the memory size applied by the working thread is less than the preset memory length, the memory allocator obtains the cursor head head and cursor tail tail of the cache structure struct slab_cache according to the allocator structure array struct_slab[y], and judges the values of the cursor head head and cursor tail tail; 1) If the value of the cursor head head of the cache structure struct slab_cache is equal to the value of the cursor tail tail, traverse the linked list head of the mounted node node under the allocator structure array struct_slab[y], and apply for memory from the page allocator according to the traversal result. Specifically: If the values of the cursor head head of all the mounted nodes node under the allocator structure array struct_slab[y] are equal to the value of the cursor tail tail, apply for memory from the page allocator, divide the memory obtained from the page allocator into new mounted nodes, and update the new mounted nodes to the linked list of the allocator structure array struct_slab[y]; If there is a mounted node node under the allocator structure array struct_slab[y] where the value of the cursor head head is not equal to the value of the cursor tail tail, then available memory blocks will be obtained according to the current number of allocable pointers cur_nums of the first mounted node node in the traversal result. Among them, if the current number of allocable pointers cur_nums is greater than or equal to 256, 256 available memory blocks will be obtained from the first mounted node node. If the current number of allocable pointers cur_nums is less than 256, all available memory blocks will be obtained from the first mounted node node. The number of available memory blocks is equal to the value of the current number of allocable pointers cur_nums of the first mounted node node. cur_nums = head - tail, where head is the value of the cursor head and tail is the value of the cursor tail. The number of available memory blocks is greater than or equal to 1 and less than 256. Add 1 to the value of the cursor head head of the buffer structure struct slab_cache to obtain a new cursor head, and allocate memory for the working thread according to the new cursor head. 2) If the value of the cursor head head of the buffer structure struct slab_cache is not equal to the value of the cursor tail tail, then based on the allocator structure array struct_slab[y], obtain the memory unit where y is equal to the cursor tail tail, add 1 to the value of the cursor tail tail to obtain a new cursor tail, and according to the new cursor tail and the starting address of the memory pool corresponding to the new cursor tail, and at the same time update the mask mask of the mounted node corresponding to the starting address according to the starting address.

8. The method according to claim 6, wherein The steps of S23 also include: S231. When the page allocator receives a memory allocation request from the memory allocator, the page allocator queries and aligns the memory pages of the page allocator based on the memory domain array buddy_zone[w], according to the memory size requested by the memory allocator and the total page length page_len of the allocated pages, and determines the number of allocatable memory pages in the page allocator according to the query and alignment results. Among them, the length of querying and aligning the memory pages of the page allocator is 34567i86×2 z , 2 z is the number of allocatable memory pages, and z is a positive integer; S232, determine the value of z according to the number of allocable memory pages in the page allocator, and judge the value of z. If z is greater than 10, return failure. If z is less than or equal to 10, update the value of the number of nodes count of the free page mount point in the memory domain array buddy_zone[w] according to the value of z. S233, if the value of the number of nodes count of the free page mount point is greater than 0, delete the first free page mount point in the memory domain array buddy_zone[w], subtract 1 from the value of the number of nodes count of the free page mount point, and according to the starting address chunk_addr of the allocated page corresponding to the first deleted free page mount point, mount the free page mount point corresponding to the starting address chunk_addr under the busy page mount point page. If the number of nodes count of the free page mount point is equal to 0, traverse and query the memory domain array buddy_zone[w] according to the subscript of the preset traversal query. If the result of traversing and querying the memory domain array buddy_zone[w] is not empty, the page allocator returns a memory block with a memory page length of 34567i86×2 to the memory allocator. z If the result of traversing and querying the memory domain array buddy_zone[w] is empty, the page allocator obtains a memory block from the DPDK large page memory, divides the obtained memory block into memory pages according to the preset memory block allocation length, and returns it to the memory allocator; Among them, the value of the preset traversal query subscript is greater than or equal to (z + 1) and less than or equal to 9.

9. The method according to claim 1, characterized in that, The steps of S3 include the memory release step of the memory allocator and the memory release step of the page allocator; The memory release step of the memory allocator is specifically: S31-1, after the user uses the allocated memory to complete the task processing, submit a memory release request to the working thread corresponding to the memory allocation request. S31-2, the memory allocator obtains the starting address of the memory corresponding to the memory allocation request through the working thread, and releases the memory according to the source type type of the memory corresponding to the memory allocation request. If the source type type of the memory corresponding to the memory allocation request is from the system memory, it calls the LINUX system memory release interface to release the memory. If the source type type of the memory corresponding to the memory allocation request is from the DPDK large page memory, it releases the memory corresponding to the memory allocation request into the cache of the cache structure struct slab_cache of the memory allocator; If the cache of the cache structure struct slab_cache is full, it releases 256 memory blocks in the cache to the mounting node node of the allocation pool structure struct slab_node, and releases all the mounting nodes node. If the mounting node node is a temporary node and the value of the current allocable pointer number cur_nums in the mounting node node is equal to the allocable pointer number nums, it releases all the memory blocks of the mounting node node to the page allocator; If the cache of the cache structure struct slab_cache is not full, it releases the memory corresponding to the memory allocation request into the cache of the cache structure struct slab_cache of the memory allocator; The memory release step of the page allocator is specifically as follows: When the memory allocator releases memory, the page allocator releases the memory released by the memory allocator after merging it according to the allocated page information in the pointer for releasing memory by the memory allocator, and according to the memory page length of 34567i86×2 z where 2 z is the number of pages of memory that can be allocated, and z is a positive integer.

10. A system for implementing the method of DPDK memory management based on load balancing according to claim 1, characterized in that, The system includes a memory initialization unit, a memory allocation unit, and a memory recovery unit; Among them, The memory initialization unit is used to define a memory management structure: based on the load balancing device and the working thread, define a memory management structure, and initialize the working thread and the memory management structure. Among them, the memory management structure includes: a page allocator and a memory allocator; The memory allocation unit is used for the working thread to receive in real time and issue a memory application request according to the user task processing request, and perform memory allocation processing on the memory application request of the working thread based on the page allocator and the memory allocator, and allocate a memory space for the memory application request of the working thread according to the memory allocation processing result; The memory recovery unit is used to recycle the memory space according to the source type type of the memory space when the working thread corresponding to the memory allocation request uses the memory space to complete task processing and releases the memory; Each working thread has a corresponding private page allocator and memory allocator. The memory allocator is used to respond to the memory application request of the working thread and allocate a memory space for the working thread according to the memory application request of the working thread. The page allocator is used to respond to the memory application request of the memory allocator, obtain memory blocks from the DPDK large page memory, divide the obtained memory blocks into memory pages according to the preset memory block allocation length, and return them to the memory allocator; The preset memory block allocation length is preset by the operator as needed.

Citation Information

Patent Citations

  • Large-page memory dynamic migration method and device based on DPDK

    CN113094173A

  • Memory allocator metadata alternate mapping method and system based on persistent memory

    CN114510439A