DPDK memory management method and system based on load balancing

By building SLAB and BUDDY allocators in each worker thread, the problem of memory pools not scaling and lock competition in DPDK memory management is solved, and memory management performance and utilization are improved.

CN119781954AActive Publication Date: 2025-04-08TMLAKE (BEIJING) TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411701375.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-26
Publication Date
2025-04-08
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 of rte_malloc() by worker threads, resulting in fierce lock competition and too much overhead for management heads.

Method used

Built-in private SLAB and BUDDY allocators in each worker thread to avoid the inability to scale the memory pool, and reduce the number of calls to rte_malloc(), reducing lock competition and management head overhead.

Benefits of technology

It solves the problem of inability to scale and fierce competition in memory pools, and improves the performance and memory utilization of memory management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119781954A_ABST
    Figure CN119781954A_ABST
Patent Text Reader

Abstract

The invention discloses a DPDK memory management method and system based on load balancing, and the method comprises the steps: defining a memory management structure based on a load balancing device and a working thread, and initializing the working thread and the memory management structure, the memory management structure comprising a page allocator and a memory allocator; receiving a memory application request in real time and sending the memory application request according to a user task processing request, performing memory allocation processing on the memory application request of the working thread based on the page allocator and the memory allocator, and allocating a memory space for the memory application request of the working thread according to a memory allocation processing result; and when the working thread uses the memory space to complete task processing and release the memory, recovering the memory space. By applying the technical scheme provided by the invention, the lock competition in the memory application process is reduced, the management head overhead is reduced, and the memory management performance and the memory utilization rate are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, 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 of the application system can be expanded, single points of failure can be eliminated, and the availability of the application system can be improved.

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

[0004] The current DPDK memory management improves the DPDK running performance and thus the application running performance by optimizing the DPDK memory management module.

[0005] DPDK provides available memory to applications through two types of interfaces: DPDK memory pool interface and DPDK memory request interface (rte_malloc()). Through memory pool pre-allocation and thread caching, available memory can be provided with extremely high performance; rte_malloc() defaults to allocating memory from the NUMA where the current CPU is located, taking into account the affinity between CPU and memory (the CPU accesses memory in the same NUMA faster than accessing memory in other NUMAs). However, memory pool technology requires pre-allocation of memory and pre-allocated memory will always be occupied and cannot be scaled. Regardless of 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 rte_malloc() implementation adds a spin lock, and multiple worker threads frequently calling rte_malloc() will greatly affect the performance of the application. The memory block management header requested by rte_malloc() occupies 80 bytes (DPDK 22.11.1). 50 available bytes are requested, and at least 130 bytes are actually requested. In this case, the effective memory accounts for less than 50%, and the management header overhead is too large.

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

[0007] In response to the technical problems mentioned above, the present invention provides a method and system for DPDK memory management based on load balancing, which avoids the problem that the memory pool cannot be scaled, the fierce lock competition when the working thread frequently calls (rte_malloc()), and the excessive management header overhead of rte_malloc() by building a private allocator (SLAB) and a partner system (BUDDY) in each working thread. At the same time, each thread will only apply for memory from its own private SLAB and BUDDY, and will not apply for memory from the SLAB and BUDDY of other threads, thereby solving the technical problems in the prior art that the pre-allocated memory will be always occupied, cannot be scaled, the performance of the application program is reduced, and the management header overhead is large, thereby reducing lock contention 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, the method comprising:

[0009] 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;

[0010] S2, the working 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 working thread based on the page allocator and the memory allocator, and allocates 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 memory, reclaiming the memory space according to the source type type of the memory space;

[0012] in,

[0013] 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;

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

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

[0016] The memory allocator comprises: 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: a mount point node, a chunk header address chunk_addr, a page header address page_addr, a total page length page_len, free and used flags flag, and a page index page_index;

[0021] The allocator structure struct slab includes: an allocation pool mount point, a total number of available memory blocks num_blocks, a number of mounted nodes num_nodes, and a 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, start address addr, source address buddy_ad, mount node node, number of allocatable pointers nums, number of current 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 value of the memory pool tag pool_flag includes 0 and 1, wherein when the value of the memory pool tag pool_flag is 1, it indicates that the mount node node corresponding to the memory pool tag 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 tag pool_flag is 0, it indicates that the mount node node corresponding to the memory pool tag pool_flag is a temporary node, and when the memory blocks cached in the cache structure struct slab_cache have been released to the temporary node, the mount node node corresponding to the memory pool tag 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 a step of initializing a memory domain, specifically:

[0028] Initialize the memory domain, create a memory domain array buddy_zone[w], and create a free page mount point according to the memory domain array buddy_zone[count], wherein the free page mount point node mounts the free memory page,

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

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

[0031] S121, initializing a memory pool: based on the working thread, defining an allocator structure array struct_slab[y], the memory allocator applies to the page allocator for initializing memory space, and divides the memory space obtained from the page allocator into memory units according to the preset memory block allocation length, based on the memory units obtained by the division, the memory allocator initializes a cache structure struct slab_cache, an allocator structure struct slab and a 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, each of the working threads comprises 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 to one;

[0033] S122, initializing the source type type, and setting the source type type to be from the system memory.

[0034] Preferably, the step 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 applies for and obtains the memory space from the page allocator based on the minimum 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 memory units obtained by the division, 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[j], and sets the memory pool flag pool_flag of the mount node node of the memory allocation pool structure struct slab_node to 1;

[0037] in,

[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 the lengths of all the preset memory pools, m is an integer equal to 1, 0 $%de 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 of task processing;

[0040] The allocator structure array struct_slab[y] represents a mount node whose memory length that can be allocated by the memory allocator is the preset memory pool length.

[0041] Preferably, the step S2 further comprises:

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

[0043] S22, the memory allocator compares the memory size requested by the worker thread with a preset memory length,

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

[0045] If the memory size requested by the worker thread is smaller than the preset memory length, and there is memory in the memory allocator whose size is equal to the memory size requested by the worker thread, jump to step S24;

[0046] If the memory size requested by the worker thread is smaller than the preset memory length, and there is no memory in the memory allocator whose size is equal to the memory size requested by the worker thread, the memory allocator sends a memory request to the page allocator according to the preset fixed size of the memory page;

[0047] S23, the page allocator responds to the memory application request of the memory allocator, and allocates memory to 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 memory pages from the available memory in the page allocator, divides the returned memory pages according to the memory size requested by the worker thread, and then jumps to step S24;

[0048] 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 the memory block to the memory allocator, and the memory allocator divides the returned memory page according to the memory size requested by the worker thread and jumps to step S24;

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

[0050] in,

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

[0052] Preferably, the step S2 further includes:

[0053] When the memory size requested by the worker 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 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 工作线程 The memory size requested for the worker thread;

[0054] When the memory size requested by the worker thread is smaller than the preset memory length, the memory allocator obtains the cursor head and the cursor tail of the cache structure struct slab_cache according to the allocator structure array struct_slab[y], and determines the values ​​of the cursor head and the cursor tail;

[0055] 1) If the value of the cursor head of the cache structure struct slab_cache is equal to the value of the cursor tail, then traverse the linked list head of the mount 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 heads of all mount 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 mount nodes, and update the new mount nodes to the linked list of the allocator structure array struct_slab[y];

[0057] If there is a mount node node whose cursor head value is not equal to the cursor tail value under the allocator structure array struct_slab[y], then the available memory blocks will be obtained according to the current allocatable pointer number cur_nums of the first mount node node in the traversal result, wherein if the current allocatable pointer number cur_nums is greater than or equal to 256, 256 available memory blocks will be obtained from the first mount node node, and if the current allocatable pointer number cur_nums is less than 256, then all available memory blocks will be obtained from the first mount node node, and the number of available memory blocks is equal to the value of the current allocatable pointer number cur_nums of the first mount 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 of the cache structure struct slab_cache is added by 1 to obtain a new cursor head, and memory is allocated to the working thread according to the new cursor head;

[0058] 2) If the value of the cursor head of the cache structure struct slab_cache is not equal to the value of the cursor tail, based on the allocator structure array struct_slab[y], obtain the memory unit where y is equal to the cursor tail, and add 1 to the value of the cursor tail to obtain a new cursor tail, and based on the new cursor tail and the first address of the memory pool corresponding to the new cursor tail, update the mask mask of the mount node corresponding to the first address at the same time.

[0059] Preferably, the step S23 further includes:

[0060] S231, when the page allocator receives the memory application request of 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 pages of memory that can be allocated in the page allocator according to the query and alignment results, wherein the memory page length of the page allocator that is queried and aligned is 34567i86×2 ( , 2 ( is the number of pages that can be allocated memory, and z is a positive integer;

[0061] S232, determining the value of z according to the number of pages of memory that can be allocated in the page allocator, and judging the value of z, if z is greater than 10, returning failure, if z is less than or equal to 10, updating the value of the number of nodes count of free page mount points in the memory domain array buddy_zone[w] according to the value of z;

[0062] S233, if the value of the node number count of the free page mount point is greater than 0, then delete the first free page mount point in the memory domain array buddy_zone[w], reduce the value of the node number count of the free page mount point by 1, and mount the free page mount point corresponding to the block first address chunk_addr to the busy page mount point page according to the block first address chunk_addr in the allocation page corresponding to the first address of the deleted first free page mount point;

[0063] If the number of nodes count of the free page mount point is equal to 0, the memory domain array buddy_zone[w] is traversed and queried according to the preset traversal query index. If the traversal query result of the memory domain array buddy_zone[w] is not empty, the page allocator returns a memory page length of 34567i86×2 to the memory allocator. ( If the result of traversing and querying the memory domain array buddy_zone[w] is empty, the page allocator obtains the 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] The preset traversal query index value is greater than or equal to (z+1) and less than or equal to 9.

[0065] Preferably, the step of S3 includes a memory release step of a memory allocator and a memory release step of a page allocator;

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

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

[0068] S31-2, the memory allocator obtains the first 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, the LINUX system memory release interface is called 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, the memory corresponding to the memory allocation request is released to 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, the 256 memory blocks in the cache are released to the mount node node of the allocation pool structure struct slab_node, and all the mount nodes node are released. If the mount node node is a temporary node, and the value of the current number of allocatable pointers cur_nums in the mount node node is equal to the number of allocatable pointers nums, all the memory blocks of the mount node node are released to the page allocator; if the cache of the cache structure struct slab_cache is not full, the memory corresponding to the memory allocation request is released to the cache of the cache structure struct slab_cache of the memory allocator;

[0070] The memory release steps of the page allocator are specifically as follows:

[0071] When the memory allocator releases memory, the page allocator allocates the allocated page information in the pointer of the memory allocator according to the memory page length of 34567i86×2 ( The memory released by the memory allocator is merged and released, wherein 2 ( is the number of pages that can be allocated memory, and z is a positive integer.

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

[0073] in,

[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, wherein the memory management structure includes: a page allocator and a memory allocator;

[0075] 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 memory space for the memory application request of the working thread according to the memory allocation processing result;

[0076] The memory recycling 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;

[0077] 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;

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

[0079] By applying the above technical scheme, the present invention realizes that a private allocator (SLAB) and a buddy system (BUDDY) are built into each working thread to avoid the problems of the inability to scale the memory pool, fierce lock competition when the working thread frequently calls (rte_malloc()), and excessive rte_malloc() management header overhead. At the same time, each thread will only apply for memory from its own private SLAB and BUDDY, and will not apply for memory from the SLAB and BUDDY of other threads. The technical problems existing in the prior art that the pre-allocated memory will be always occupied, cannot be scaled, the performance of the application program is reduced, and the management header overhead is large are solved, thereby reducing 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 drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0081] Figure 1 A schematic flow chart of a method for DPDK memory management based on load balancing proposed in an embodiment of the present invention is shown;

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

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

[0084] Figure 4 Shown is a schematic diagram of the SLAB distributor structure;

[0085] Figure 5 A schematic diagram of memory blocks in the SLAB memory pool is shown;

[0086] Figure 6 A schematic diagram of a SLAB cache is shown;

[0087] Figure 7 A structural schematic diagram of a DPDK memory management system based on load balancing proposed in an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0088] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

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

[0090] S1, 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, wherein the memory management structure includes: a page allocator (BUDDY) and a memory allocator (SLAB).

[0091] in,

[0092] Each of the worker threads has a corresponding private page allocator (BUDDY) and memory allocator (SLAB). The memory allocator (SLAB) 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 (BUDDY) is used 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 the preset memory block allocation length, and return it 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) comprises: 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 number 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: mount point node, chunk header address chunk_addr, page header address page_addr, total page length page_len, free and used flags flag and page index page_index;

[0100] The allocator structure struct slab includes: an allocation pool mount point, a total number of available memory blocks num_blocks, a number of mounted nodes num_nodes, and a 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, start address addr, source address buddy_ad, mount node node, number of allocatable pointers nums, number of current 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, head is the value of the cursor head, and tail is the value of the cursor tail;

[0104] The value of the memory pool tag pool_flag includes 0 and 1, wherein when the value of the memory pool tag pool_flag is 1, it indicates that the mount node node corresponding to the memory pool tag 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 tag pool_flag is 0, it indicates that the mount node node corresponding to the memory pool tag pool_flag is a temporary node, and when the memory blocks cached in the cache structure struct slab_cache have been released to the temporary node, the mount node node corresponding to the memory pool tag 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 a step of initializing a memory domain, specifically:

[0107] Initialize the memory domain, create a memory domain array buddy_zone[w], and create a free page mount point head according to the memory domain array buddy_zone[count], wherein the free page mount point head node mounts the free memory page,

[0108] buddy_zone[w]=.buddy_zone[0],buddy_zone[1],…,buddy_zone[count-1]5,count is the number of nodes of the created free 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 also includes the step of initializing the memory pool, which is specifically:

[0110] S121, initializing the memory pool: based on the working thread, defining the allocator structure array struct_slab[y], the memory allocator (SLAB) applies to the page allocator (BUDDY) for initializing the memory space, 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 memory units obtained by the division, 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 allocator structure array struct_slab[y],

[0111] Wherein, y is a positive integer greater than or equal to 0, each of the working threads comprises 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 to one;

[0112] S122, initializing the source type type, and setting the source type type to be from the system memory.

[0113] In this embodiment, the step S121 further includes:

[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 applies for and obtains the memory space from the page allocator (BUDDY) based on the minimum memory space;

[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 memory units obtained by the division, 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 allocator structure array struct_slab[j], and sets the memory pool flag pool_flag of the mount node node of the memory allocation pool structure struct slab_node to 1;

[0116] in,

[0117] The minimum memory size calculation formula is: Mi + memory pool = - × ∑ m"1 0m +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 the lengths of all the preset memory pools, m is an integer equal to 1, 0 $%de 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 of task processing;

[0119] The allocator structure array struct_slab[y] represents a mount node whose memory length that can be allocated by the memory allocator (SLAB) 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 memory space for the memory application request of the working thread according to the memory allocation processing result.

[0121] In this embodiment, the step S2 further includes:

[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 requested by the working thread;

[0123] S22, the memory allocator (SLAB) compares the memory size requested by the worker thread with a preset memory length,

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

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

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

[0127] S23, the page allocator (BUDDY) responds to the memory application request of the memory allocator (SLAB), and allocates memory to 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 memory pages from the available memory in the page allocator (BUDDY), divides the returned memory pages 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 it to the memory allocator (SLAB), and the memory allocator (SLAB) divides the returned memory page according to the memory size requested by the worker thread and jumps to step S24;

[0129] S24, the memory allocator (SLAB) allocates memory space to the working thread;

[0130] in,

[0131] The preset memory page fixed size and the preset memory block allocation length are both preset by an operator as needed.

[0132] In this embodiment, the step S2 further includes:

[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 the memory length of 0 working threads + 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 工作线程 The memory size requested for the worker thread;

[0134] When the memory size requested by the worker thread is smaller than the preset memory length, the memory allocator (SLAB) obtains the cursor head and the cursor tail of the cache structure struct slab_cache according to the allocator structure array struct_slab[y], and determines the values ​​of the cursor head and the cursor tail;

[0135] 1) If the value of the cursor head of the cache structure struct slab_cache is equal to the value of the cursor tail, then traverse the linked list head of the mount 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 mount 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 mount nodes, and update the new mount nodes to the linked list of the allocator structure array struct_slab[y];

[0137] If there is a mount node node whose cursor head value is not equal to the cursor tail value under the allocator structure array struct_slab[y], then the available memory blocks will be obtained according to the current allocatable pointer number cur_nums of the first mount node node in the traversal result, wherein if the current allocatable pointer number cur_nums is greater than or equal to 256, 256 available memory blocks will be obtained from the first mount node node, and if the current allocatable pointer number cur_nums is less than 256, then all available memory blocks will be obtained from the first mount node node, and the number of available memory blocks is equal to the value of the current allocatable pointer number cur_nums of the first mount 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 of the cache structure struct slab_cache is added by 1 to obtain a new cursor head, and memory is allocated to the working thread according to the new cursor head;

[0138] 2) If the value of the cursor head of the cache structure struct slab_cache is not equal to the value of the cursor tail, based on the allocator structure array struct_slab[y], obtain the memory unit where y is equal to the cursor tail, and add 1 to the value of the cursor tail to obtain a new cursor tail, and based on the new cursor tail and the first address of the memory pool corresponding to the new cursor tail, update the mask mask of the mount node corresponding to the first address at the same time.

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

[0140] S231, when the page allocator (BUDDY) receives the memory application 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 allocation page (buddy_page), and determines the number of pages of allocable memory in the page allocator (BUDDY) according to the query and alignment results, wherein the memory page length of the page allocator (BUDDY) is 34567i86×2 ( , 2 ( is the number of pages that can be allocated memory, and z is a positive integer;

[0141] S232, determine the value of z according to the number of pages of memory that can be allocated 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 number of nodes 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 number count of the free page mount point head is greater than 0, then the first free page mount point head in the memory domain array buddy_zone[w] is deleted, the value of the node number count of the free page mount point head is reduced by 1, and according to the block first address chunk_addr in the allocation page (buddy_page) corresponding to the first address of the deleted first free page mount point head, the free page mount point head corresponding to the block first address chunk_addr is mounted 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, the memory domain array buddy_zone[w] is traversed and queried according to the preset traversal query index. If the traversal query result of the memory domain array buddy_zone[w] is not empty, the page allocator (BUDDY) returns a memory page length of 34567i86×2 to the memory allocator (SLAB). ( If the result of traversing and querying the memory domain array buddy_zone[w] is empty, the page allocator (BUDDY) obtains the 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] The preset traversal query index value 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 memory, the memory space is reclaimed according to the source type type of the memory space.

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

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

[0148] S31-1, after the user completes task processing using the allocated memory, the user submits a memory release request to the working thread corresponding to the memory allocation request;

[0149] S31-2, the memory allocator (SLAB) obtains the first 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, the LINUX system memory release interface is called 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, the memory corresponding to the memory allocation request is released to the cache of the cache structure structslab_cache of the memory allocator (SLAB);

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

[0151] If the cache of the cache structure struct slab_cache is not full, releasing 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 steps of the page allocator are specifically as follows:

[0153] When the memory allocator (SLAB) releases memory, the page allocator (BUDDY) releases the memory according to the allocation page (buddy_page) information in the pointer of the memory allocator (SLAB), and according to the memory page length of 34567i86×2 ( The memory released by the memory allocator (SLAB) is merged and released, wherein 2 ( is the number of pages that can be allocated memory, and z is a positive integer.

[0154] In order to enable the technical personnel in the field to better understand the technical solution provided by the present invention, the above steps are further supplemented with examples. Figure 2 to Figure 6 shown.

[0155] The worker thread applies for memory from SLAB. If the size of the memory applied for 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 memory of the appropriate size in SLAB, it is directly allocated to the worker thread.

[0156] If there is no memory of the appropriate size in SLAB, SLAB will apply for several memory pages of a preset fixed size from BUDDY. SLAB divides the requested memory pages into memory blocks that are just greater than or equal to the size of the memory block requested by the worker thread, and makes them into multiple allocatable memory blocks of the same size. Then the SLAB allocator returns one of them.

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

[0158] As shown in the above steps, rte_malloc() is called to allocate memory only when BUDDY has no memory, which greatly reduces the number of calls to the rte_malloc() interface, thereby reducing lock contention; and the preset memory block that BUDDY applies to DPDK each time is much larger than the 80 bytes of the management header, thereby improving memory utilization. Each thread applies for memory from its own private SLAB and BUDDY. If SLAB or BUDDY has suitable memory, there is no contention problem.

[0159] In order to avoid exceptions caused by the memory requested by the current thread being released by other threads, the upper-layer application needs to ensure that the memory requested 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 load balancing devices

[0162] Based on the shortcomings of the current DPDK solution, this solution proposes a new memory management architecture design solution such as Figure 2 As shown in the figure, each thread has a thread-private SLAB and BUDDY. BUDDY obtains the preset memory block from DPDK and organizes it by page. SLAB obtains memory in multiples of pages from BUDDY and divides it into 8, 16, 32 and other memory blocks for detailed management. The user obtains available memory from SLAB.

[0163] Step 2: BUDDY structure and BUDDY initialization, use and recycling

[0164] The BUDDY structure is divided into struct buddy_page, strcut buddy_chunk and struct buddy_zone. Struct buddy_zone manages all idle struct buddy_pages, and strcut buddy_chunk mounts the busy (being used) struct buddy_page 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: During initialization, the structure array is initialized first, and the structure array 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 use: SLAB requests memory from BUDDY, adds the length of the structure structbuddy_page to the memory size required by SLAB, and aligns it upward to the page length 34567i86×2 ( , Z is the smallest positive integer that can meet the requirements, and the maximum value of Z is no more than 10. SLAB guarantees that it will not apply for memory N exceeding 10. If it exceeds, it will return failure. Based on the calculated Z, the count of buddy_zone[w] is determined;

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

[0180] If it is 0, search for elements with buddy_zone subscript interval N+1 to 9(10-1), and split a 34567i86×2 (The memory of the split memory is mounted under the corresponding struct buddy_chunk. The remaining memory is made into one or more struct buddy_page structures, mounted under the corresponding buddy_zone element head, and the count value under the element is increased (for example, if 1 page is split from 4 pages and 3 pages are left, the address header of the low address page among the 3 pages is converted into a struct buddy_pagepage instance, and then initialized to let this struct buddy_page page manage this 1 page. Finally, the struct buddy_page page that manages 1 page is mounted under buddy_zone[0]. The address headers of the remaining 2 pages are converted into structbuddy_page page2, and then initialized to let it manage these 2 pages, and finally mounted under buddy_zone[1]);

[0181] If no available elements are found in the interval search, directly apply to DPDK for the length of the struct buddy_chunk structure + 34567i86×2 ( The memory applied for is headed by the struct buddy_chunk structure, which is initialized. Then, according to the searched process, the page nodes to be allocated are mounted under this struct buddy_chunk, and the idle nodes are mounted under the struct buddy_zone element.

[0182] BUDDY recovery: When SLAB releases a page, BUDDY obtains the structbuddy_page structure before the pointer according to the released pointer, and then determines whether it can be merged into a 34567i86×2 ( If possible, merge and mount the blocks to the corresponding buddy_zone[N]. If N is 10, release them to DPDK. If not, mount the released pages to the corresponding buddy_zone[len / pagesize] elements according to the released page struct buddy_page element len, and wait for the next request.

[0183] Step 3: SLAB structure and SLAB initialization, use and recycling

[0184] After the worker thread is started, it needs to initialize the private SLAB. The SLAB consists of Figure 4The three structures shown are: allocator structure struct slab, cache structure struct slab_cache and 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 The total number of available memory blocks num_nodes uint32_t Number of mounted nodes cache struct slab_cache Quick Cache Points

[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, and each element in the structure is initialized: slab->next = slab->prev. slab[0] is the mount point of struct slab_node with an allocatable memory block length of 8, slab[1] is the mount point of struct slab_node with an allocatable memory block length of 16, and the same can be said according to 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 the thread needs 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 struct slab_node structure is stored in the first address of the memory and initialized, where the pool_flags field is initialized to 1, indicating that the struct slab_node will not be released.

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

[0204] There are two cases where a thread applies for DPDK large page memory through the SLAB interface:

[0205] When the length of the memory passed in is greater than or equal to 1MB, SLAB calls the LINUX system interface to apply for (required length = required memory length of user memory + 8) memory, and makes the first address of SLAB equal to the address of type, so that when this memory is released, this type can be directly released to the LINUX system;

[0206] If the length of the memory passed in is less than 1MB, SLAB first obtains the corresponding slab index N, and then obtains the memory block from the cache under struct_slab[y]. The cache is as follows: Figure 6 As shown, determine whether tail and head are equal. If they are not equal, there is available memory. Get the memory block with subscript tail and set tail+1. Then set the mask bit of the corresponding structslab_node according to the first address of this SLAB and return the return address. If tail and head are equal, traverse the head of struct_slab[y], get up to 512 / 2 memory blocks and store them in the cache, move the cursor head to head+the number of memory blocks obtained, and then return an available one. If there is no available memory block when traversing the head, apply for memory from BUDDY and make it into struct slab_node and mount it to the head under struct_slab[y] for allocation.

[0207] SLAB recovery: The user releases memory, obtains the first address of SLAB, and then releases it according to the source type:

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

[0209] If it is SLAB_TYPE_DPDK, it is stored in the cache of SLAB and the corresponding mask bit is cleared. If the cache is not full after being stored in it, the release is completed. If the cache is full, 512 / 2=256 caches are obtained and stored in the struct slab_node. If all the memory blocks in a certain struct slab_node have been released when processing these 256 memory blocks, and pool_flags is not 1, then this struct slab_node block is released to the BUDDY system.

[0210] By applying the above technical solutions, it is achieved that a private allocator (SLAB) and a buddy system (BUDDY) are built into each working thread to avoid the problems of the memory pool being unable to scale, fierce lock contention when the working thread frequently calls (rte_malloc()), and excessive rte_malloc() management header overhead. At the same time, each thread will only apply for memory from its own private SLAB and BUDDY, and will not apply for memory from the SLAB and BUDDY of other threads. This solves the technical problems in the prior art that the pre-allocated memory will be always occupied, unable to scale, the performance of the application program will be reduced, and the management header overhead is large, thereby reducing lock contention in the memory application process, reducing the management header overhead, and improving the performance of memory management and memory utilization.

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

[0212] in,

[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, wherein 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 a 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 memory space for the memory application request of the working thread according to the memory allocation processing result;

[0215] The memory recycling 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;

[0216] Each of the worker threads has a corresponding private page allocator (BUDDY) and memory allocator (SLAB). The memory allocator (SLAB) 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 (BUDDY) is used 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 the 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, and the same or similar parts between the embodiments can be referenced to each other, and 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 working 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 working thread based on the page allocator and the memory allocator, and allocates memory space for the memory application request of the working thread according to the memory allocation processing result; S3, when the working thread corresponding to the memory allocation request uses the memory space to complete task processing and releases memory, reclaiming the memory space according to the source type 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, characterized in that The page allocator includes: a memory domain, a memory block and an allocation page; The memory allocator comprises: 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: a mount point node, a chunk header address chunk_addr, a page header address page_addr, a total page length page_len, free and used flags flag, and a page index page_index; The allocator structure struct slab includes: an allocation pool mount point, a total number of available memory blocks num_blocks, a number of mounted nodes num_nodes, and a 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 length of data block, start address addr, source address buddy_ad, mount node node, number of allocatable pointers nums, number of current allocatable pointers cur_nums, length, mask mask, cursor head head, cursor tail tail and pointer cache array ptr; 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; The value of the memory pool tag pool_flag includes 0 and 1, wherein when the value of the memory pool tag pool_flag is 1, it indicates that the mount node node corresponding to the memory pool tag 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 tag pool_flag is 0, it indicates that the mount node node corresponding to the memory pool tag pool_flag is a temporary node, and when the memory blocks cached in the cache structure struct slab_cache have been released to the temporary node, the mount node node corresponding to the memory pool tag 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, characterized in that 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 a free page mount point according to the memory domain array buddy_zone[count], wherein the free page mount point node mounts the free memory page, buddy_zone[w]=.buddy_zone[0],buddy_zone[1],…,buddy_zone[count-1]5,count is the number of nodes of the created free page mount point, 0≤" <count。 4. The method according to claim 1, characterized in that In step S1, the step of initializing the working thread and the memory management structure also includes the step of initializing the memory pool, which is specifically: S121, initializing a memory pool: based on the working thread, defining an allocator structure array struct_slab[y], the memory allocator applies to the page allocator for initializing memory space, and divides the memory space obtained from the page allocator into memory units according to the preset memory block allocation length, based on the memory units obtained by the division, the memory allocator initializes a cache structure struct slab_cache, an allocator structure struct slab and a memory allocation pool structure struct slab_node according to the allocator structure array struct_slab[y], Wherein, y is a positive integer greater than or equal to 0, each of the working threads comprises 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 to one; S122, initializing the source type type, and setting the source type type to be from the system memory.

5. The method according to claim 4, characterized in that The step S121 further includes: 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 applies for and obtains the memory space from the page allocator based on the minimum 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 memory units obtained by the division, 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[j], and sets the memory pool flag pool_flag of the mount node node of the memory allocation pool structure struct slab_node to 1; in, 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 the lengths of all the preset memory pools, m is an integer equal to 1, 0 $%de 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 a mount node whose memory length that can be allocated by the memory allocator is the preset memory pool length.

6. The method according to claim 1, characterized in that The step of S2 further comprises: S21, the memory allocator responds in real time and parses the memory application request of the working thread to obtain the memory size requested by the working thread; S22, the memory allocator compares the memory size requested by the worker thread with a preset memory length, If the memory size requested by the working thread is greater than or equal to the preset memory length, the memory allocator requests and obtains memory from the LINUX system, and jumps to step S24; If the memory size requested by the worker thread is smaller than the preset memory length, and there is memory in the memory allocator whose size is equal to the memory size requested by the worker thread, jump to step S24; If the memory size requested by the worker thread is smaller than the preset memory length, and there is no memory in the memory allocator whose size is equal to the memory size requested by the worker thread, the memory allocator sends a memory request to the page allocator according to the preset fixed size of the memory page; S23, the page allocator responds to the memory application request of the memory allocator, and allocates memory to 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 memory pages from the available memory in the page allocator, divides the returned memory pages according to the memory size requested by the worker 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 the memory block to the memory allocator, and the memory allocator divides the returned memory page according to the memory size requested by the worker thread and jumps to step S24; S24, the memory allocator allocates memory space to the working thread; in, The preset memory page fixed size and the preset memory block allocation length are both preset by an operator as needed.

7. The method according to claim 6, characterized in that The step of S2 further includes: When the memory size requested by the worker 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 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 工作线程 The memory size requested for the worker thread; When the memory size requested by the worker thread is smaller than the preset memory length, the memory allocator obtains the cursor head and the cursor tail of the cache structure struct slab_cache according to the allocator structure array struct_slab[y], and determines the values ​​of the cursor head and the cursor tail; 1) If the value of the cursor head of the cache structure struct slab_cache is equal to the value of the cursor tail, then traverse the linked list head of the mount 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 heads of all mount 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 mount nodes, and update the new mount nodes to the linked list of the allocator structure array struct_slab[y]; If there is a mount node node whose cursor head value is not equal to the cursor tail value under the allocator structure array struct_slab[y], then the available memory blocks will be obtained according to the current allocatable pointer number cur_nums of the first mount node node in the traversal result, wherein if the current allocatable pointer number cur_nums is greater than or equal to 256, 256 available memory blocks will be obtained from the first mount node node, and if the current allocatable pointer number cur_nums is less than 256, then all available memory blocks will be obtained from the first mount node node, and the number of available memory blocks is equal to the value of the current allocatable pointer number cur_nums of the first mount 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 of the cache structure struct slab_cache is added by 1 to obtain a new cursor head, and memory is allocated to the working thread according to the new cursor head; 2) If the value of the cursor head of the cache structure struct slab_cache is not equal to the value of the cursor tail, based on the allocator structure array struct_slab[y], obtain the memory unit where y is equal to the cursor tail, and add 1 to the value of the cursor tail to obtain a new cursor tail, and based on the new cursor tail and the first address of the memory pool corresponding to the new cursor tail, update the mask mask of the mount node corresponding to the first address at the same time.

8. The method according to claim 6, characterized in that The step of S23 further includes: S231, when the page allocator receives the memory application request of 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 pages of memory that can be allocated in the page allocator according to the query and alignment results, wherein the memory page length of the page allocator that is queried and aligned is 34567i86×2 ( , 2 ( is the number of pages that can be allocated memory, and z is a positive integer; S232, determining the value of z according to the number of pages of memory that can be allocated in the page allocator, and judging the value of z, if z is greater than 10, returning failure, if z is less than or equal to 10, updating the value of the number of nodes count of free page mount points in the memory domain array buddy_zone[w] according to the value of z; S233, if the value of the node number count of the free page mount point is greater than 0, then delete the first free page mount point in the memory domain array buddy_zone[w], reduce the value of the node number count of the free page mount point by 1, and mount the free page mount point corresponding to the block first address chunk_addr to the busy page mount point page according to the block first address chunk_addr in the allocation page corresponding to the first address of the deleted first free page mount point; If the number of nodes count of the free page mount point is equal to 0, the memory domain array buddy_zone[w] is traversed and queried according to the preset traversal query index. If the traversal query result of the memory domain array buddy_zone[w] is not empty, the page allocator returns a memory page length of 34567i86×2 to the memory allocator. ( If the result of traversing and querying the memory domain array buddy_zone[w] is empty, the page allocator obtains the 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 preset traversal query index value 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 step of S3 includes a memory release step of a memory allocator and a memory release step of a page allocator; The memory release step of the memory allocator is specifically as follows: S31-1, after the user completes task processing using the allocated memory, the user submits a memory release request to the working thread corresponding to the memory allocation request; S31-2, the memory allocator obtains the first 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, the LINUX system memory release interface is called 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, the memory corresponding to the memory allocation request is released to 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, then the 256 memory blocks in the cache are released to the mount node node of the allocation pool structure struct slab_node, and all the mount nodes node are released. If the mount node node is a temporary node, and the value of the current allocatable pointer number cur_nums in the mount node node is equal to the allocatable pointer number nums, then all the memory blocks of the mount node node are released to the page allocator; If the cache of the cache structure struct slab_cache is not full, releasing 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 steps of the page allocator are specifically as follows: When the memory allocator releases memory, the page allocator allocates the allocated page information in the pointer of the memory allocator according to the memory page length of 34567i86×2 ( The memory released by the memory allocator is merged and released, wherein 2 ( is the number of pages that can be allocated memory, and z is a positive integer.

10. A system for implementing the method for 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; in, 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, wherein 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 memory space for the memory application request of the working thread according to the memory allocation processing result; The memory recycling 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 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.

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

  • Memory allocation management method and device

    CN115562871A

  • Workload scheduler for memory allocation

    US20200192715A1