Network data packet forwarding performance optimization method and system based on multi-core processor
The kernel thread polls received packets and uses dynamic stream classification hashing algorithm to store queues. Combined with the kernel-state and user-state communication mechanism, the problem of limited packet forwarding performance of multi-core processor networks is solved, and efficient packet processing and transmission is achieved.
Patent Information
- Application Number
- CN202510968954.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-15
- Publication Date
- 2025-08-12
- Estimated Expiration
- 2045-07-15
AI Technical Summary
The network packet forwarding performance of multi-core processors is limited by the problem of mismatch between the number of network card queues and the number of CPU cores. The DPDK solution requires a large number of customized development and cannot fully utilize Linux system resources.
The kernel thread is used to receive data packets in the form of polling, and the hierarchical vectorization algorithm of dynamic stream classification hashing is used to store and allocate queues. A kernel-state and user-state communication mechanism is established, and efficient processing and transmission of data packets are achieved through shared queues.
Improve packet reception efficiency, make full use of the parallel capabilities of multi-core processors, realize efficient sharing and exchange of data packets, and improve the overall performance of the system.
Smart Images

Figure CN120474993A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a method and system for optimizing network data packet forwarding performance based on a multi-core processor. Background Art
[0002] In recent years, hardware technology has advanced rapidly, and multi-core processors have become increasingly common in various computing scenarios. Their core counts have also continued to climb, with CPUs with sixteen or more cores now commonplace. At the same time, modern network adapters (NICs) generally support multi-queue functionality. This feature aims to improve overall processing power by assigning packets to different queues, enabling multiple CPU cores to efficiently process network packets in parallel. However, as the number of CPU cores continues to increase, the mismatch between the number of NIC queues and the number of CPU cores has become increasingly prominent, limiting the performance of multi-core processors to a certain extent.
[0003] DPDK, a widely known packet forwarding acceleration solution, can effectively improve packet processing speeds, but it has specific support requirements for network cards. Furthermore, as a kernel bypass solution, it bypasses the operating system kernel and interacts directly with the hardware. While this design reduces kernel overhead, it also prevents the full utilization of the Linux system's rich software ecosystem. Therefore, in practical applications, adopting the DPDK solution often requires extensive customized development to adapt to different hardware environments and software requirements, which undoubtedly increases the complexity and cost of project implementation.
[0004] Therefore, how to provide a method and system for optimizing network packet forwarding performance based on a multi-core processor is an urgent problem to be solved. Summary of the Invention
[0005] The embodiments of the present invention provide a method and system for optimizing network data packet forwarding performance based on a multi-core processor to solve the problems in the prior art.
[0006] To provide a basic understanding of some aspects of the disclosed embodiments, the following is a brief summary. This summary is not intended to be an extensive review, identify key or critical elements, or delineate the scope of these embodiments. Its sole purpose is to present some concepts in a simplified form as a prelude to the detailed description that follows.
[0007] According to a first aspect of an embodiment of the present invention, a method for optimizing network data packet forwarding performance based on a multi-core processor is provided.
[0008] In one embodiment, a method for optimizing network packet forwarding performance based on a multi-core processor includes the following steps: The kernel thread receives network data packets transmitted by the network card in a polling manner, and uses the layered vectorization algorithm of dynamic flow classification hash to store the received data packets in the form of queues to obtain the data packet sending queue; The kernel thread assigns the packet sending queue to different user states for processing, establishes a communication mechanism between the kernel state and the user state, and passes the address information of the packet sending queue to the corresponding user state to form a shared queue; The user state receives the data packets assigned to it through the shared queue, modifies the data packets, generates a new data queue, and feeds the address information of the new data packet queue back to the kernel thread through the communication mechanism established with the kernel state; The kernel thread takes out the new data packet queue from the shared queue according to the feedback address information, and calls the network card driver to send the new data packet to the network.
[0009] In one embodiment, the kernel thread receives network data packets transmitted by the network card in a polling manner, and stores the received data packets in the form of queues using a layered vectorization algorithm of dynamic flow classification hashing. Obtaining a data packet transmission queue includes the following steps: A dynamic five-tuple hash algorithm is used to analyze the five-tuple features of the data packet, and based on the five-tuple features, the received network data packet is mapped to the initial queue according to the flow classification; Based on real-time traffic characteristics, a dynamic weight value is assigned to each flow category in the initial queue using a spin graph structure; Combine the five-tuple features of the data packet with the dynamic weight value and map them to sub-queues of different priorities through a multi-layer hash function; According to the priority order of the sub-queues, the data packets are dispatched to the sending buffer in sequence to form the final data packet sending queue.
[0010] In one embodiment, the method of analyzing the five-tuple features of the data packet using the dynamic five-tuple hash algorithm and mapping the received network data packet to the initial queue according to the flow classification based on the five-tuple features includes the following steps: Extract field information from the header of the network data packet, parse the field information, and obtain the five-tuple features of each data packet; Using a double hash function combination, the hash value of the five-tuple feature is calculated and combined with the timestamp information of the data packet to generate a flow identifier; Map the data packet to the corresponding initial queue based on the modulo operation of the flow ID and the number of initial queues; Determine whether the mapped initial queue already has a corresponding flow record. If so, insert the data packet into the queue. Otherwise, create a new flow record and initialize the queue before inserting the data packet.
[0011] In one embodiment, the method of calculating the hash value of the five-tuple feature by combining a double hash function and generating a flow identifier in combination with the timestamp information of the data packet includes the following steps: Based on the five-tuple feature, the primary hash function and the auxiliary hash function are used to perform hash calculations respectively to obtain the primary hash value and the auxiliary hash value; The main hash value and the auxiliary hash value are fused using the XOR operation to obtain the hash value of the five-tuple feature; Collect the timestamp information of the data packet received, and mix the timestamp information hash seed with the hash value of the five-tuple feature to obtain the flow identifier.
[0012] In one embodiment, allocating a dynamic weight value to each flow category in the initial queue using a spin graph structure based on real-time traffic characteristics includes the following steps: Obtain real-time traffic information for each flow category, calculate real-time traffic features based on the real-time traffic information, and use correlation analysis to analyze the correlation between the traffic features; Based on the correlation between each flow feature, a spin graph structure of flow categories is constructed to determine the connection relationship between flow category vertices and edges; According to the traffic characteristics and edge connection relationships, dynamic weight values are assigned to the edges in the spin graph structure based on feature similarity.
[0013] In one embodiment, constructing a spin graph structure of flow categories based on the correlation between each flow feature and determining the flow category vertex and edge connection relationship includes the following steps: Each flow category is mapped to a vertex in the spin graph structure, and a correlation matrix is established based on the correlation between each flow feature; According to the correlation matrix, spin edges and adjacent edges are added to each vertex, and adjacent edges are filtered based on the preset correlation threshold; Based on spin edges and adjacency edges, a flow-class spin graph structure is constructed.
[0014] In one embodiment, the kernel thread assigns data packet send queues to different user states for processing, establishes a communication mechanism between the kernel state and the user state, and transmits address information of the data packet send queue to the corresponding user state. Forming a shared queue includes the following steps: Create a shared memory area through kernel threads and configure the synchronization mechanism, obtain the shared memory identifier, map the shared memory area to the kernel address space, and initialize the queue information of the packet sending queue in the shared memory; The user-state program obtains the shared memory identifier through a preset identifier transfer method, and uses the same shared memory identifier to map the shared memory area to the user-state address space; The user-mode program obtains the synchronization mechanism, reads the queue information through the shared memory, and accesses the corresponding data packet sending queue in the shared memory according to the queue information to form a shared queue.
[0015] In one embodiment, the user-mode program obtains a synchronization mechanism, reads queue information through a shared memory, and accesses a corresponding data packet sending queue in the shared memory according to the queue information. Forming a shared queue includes the following steps: The user-mode program reads the identifier of the synchronization mechanism from the shared memory and calls the corresponding system function according to the identifier to obtain the handle of the synchronization mechanism; Based on the handle of the synchronization mechanism, the queue information area in the shared memory is locked and the queue information is read from the locked shared memory; The user-mode program accesses the corresponding data packet sending queue in the shared memory through pointer operations based on the read queue information, and parses and processes the data packets to form a shared queue.
[0016] In one embodiment, the user state receives a data packet assigned to itself through a shared queue, modifies the data packet to generate a new data queue, and feeds back address information of the new data packet queue to the kernel thread through a communication mechanism established with the kernel state, including the following steps: The user state parses and processes the received data packets and modifies the parsed data packets based on business needs; Create a new data packet queue in the user state memory, insert the modified data packets into the queue in order to form a new data queue; The user state writes the address information of the new packet queue into the memory area shared with the kernel state and updates the queue status flag in the shared memory; The user state triggers the kernel thread through the communication mechanism established with the kernel state, notifying it that there is a new packet queue that needs to be processed, and waits for the kernel thread to confirm receipt or completion of processing.
[0017] According to a second aspect of an embodiment of the present invention, a network data packet forwarding performance optimization system based on a multi-core processor is provided.
[0018] In one embodiment, the multi-core processor-based network data packet forwarding performance optimization system includes: The queue generation module is used by the kernel thread to receive network data packets transmitted by the network card in a polling manner, and uses the layered vectorization algorithm of dynamic flow classification hashing to store the received data packets in the form of queues to obtain the data packet sending queue; The data sharing module is used by the kernel thread to allocate the data packet sending queue to different user states for processing, establish a communication mechanism between the kernel state and the user state, and pass the address information of the data packet sending queue to the corresponding user state to form a shared queue; The information feedback module is used by the user state to receive data packets assigned to it through the shared queue, modify the data packets, generate new data queues, and feed back the address information of the new data packet queue to the kernel thread through the communication mechanism established with the kernel state; The data sending module is used by the kernel thread to take out the new data packet queue from the shared queue according to the feedback address information, and call the network card driver to send the new data packet to the network.
[0019] According to a third aspect of an embodiment of the present invention, a computer device is provided.
[0020] In some embodiments, the computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0021] According to a fourth aspect of embodiments of the present invention, a computer-readable storage medium is provided.
[0022] In one embodiment, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0023] The technical solution provided by the embodiment of the present invention may have the following beneficial effects: 1. The kernel thread in the present invention receives network data packets transmitted by the network card in a polling manner, avoiding context switching and interrupt delays caused by interrupt processing, thereby improving the efficiency of data packet reception. In addition, a layered vectorization algorithm of dynamic flow classification hash is used to map data packets to different queues according to flow classification, and dynamic weight values are assigned based on real-time traffic characteristics, so that data packets can be scheduled to the sending buffer in order of priority, further improving the processing efficiency of data packets.
[0024] 2. The present invention fully utilizes the parallel processing capabilities of multi-core processors by allocating data packet sending queues to different user states for processing, allowing multiple CPU cores to process data packets simultaneously, thereby improving the overall performance of the system. Through the shared queue mechanism between kernel state and user state, efficient sharing and exchange of data packets is achieved, allowing user state and kernel state to independently perform data processing and sending operations.
[0025] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0027] Figure 1 This is a flow chart of a method for optimizing network data packet forwarding performance based on a multi-core processor according to an exemplary embodiment; Figure 2 This is a principle block diagram of a multi-core processor-based network data packet forwarding performance optimization system according to an exemplary embodiment; Figure 3 The figure is a schematic diagram showing the structure of a computer device according to an exemplary embodiment. DETAILED DESCRIPTION
[0028] The following description and accompanying drawings sufficiently illustrate the specific embodiments herein to enable those skilled in the art to practice them. Portions and features of some embodiments may be included in or substituted for portions and features of other embodiments. The scope of the embodiments herein includes the entire scope of the claims, including all available equivalents thereof. Herein, the terms "first," "second," and the like are used solely to distinguish one element from another and do not require or imply any actual relationship or order between these elements. In practice, the first element can also be referred to as the second element, and vice versa. Furthermore, the terms "comprise," "comprising," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a structure, device, or apparatus comprising a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such structure, device, or apparatus. Without further limitation, an element defined by the phrase "comprising a..." does not preclude the presence of other identical elements in the structure, device, or apparatus comprising the element. The various embodiments herein are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Similar or identical parts between the various embodiments can be referenced to each other.
[0029] The terms "longitudinal", "transverse", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like used herein to indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, are intended only to facilitate the description of this document and simplify the description, and are not intended to indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation on the present invention. In the description herein, unless otherwise specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, they can be mechanical or electrical connections, or they can be internal connections between two elements, they can be directly connected, or they can be indirectly connected through an intermediate medium. For those of ordinary skill in the art, the specific meanings of the above terms can be understood according to the specific circumstances.
[0030] As used herein, unless otherwise specified, the term "plurality" means two or more.
[0031] In this document, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B means: A or B.
[0032] In this article, the term "and / or" is used to describe the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0033] It should be understood that, although the various steps in the flowchart are shown in sequence as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps may be performed in other orders. Moreover, at least a portion of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily performed at the same time, but may be performed at different times. The execution order of these sub-steps or stages is not necessarily to be performed in sequence, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0034] Each module in the device or system of the present application can be implemented in whole or in part by software, hardware, or a combination thereof. The above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software so that the processor can call and execute the operations corresponding to the above modules.
[0035] In the absence of conflict, the embodiments of the present invention and the features thereof may be combined with each other.
[0036] Figure 1An embodiment of the network data packet forwarding performance optimization method based on a multi-core processor of the present invention is shown.
[0037] In this optional embodiment, the method for optimizing network data packet forwarding performance based on a multi-core processor includes the following steps: Step S101: The kernel thread receives network data packets transmitted by the network card in a polling manner, and stores the received data packets in the form of queues using a layered vectorization algorithm based on dynamic flow classification and hashing to obtain a data packet sending queue. It should be noted that polling is an active query technology, that is, the kernel thread periodically or continuously checks whether there are new data packets arriving at the network card. Polling does not need to wait for the network card to send an interrupt signal to notify the kernel that a data packet has arrived. Instead, the kernel actively and periodically queries the status of the network card.
[0038] Specifically, active polling means that the kernel thread periodically (or continuously in some implementations) checks the network card's receive buffer to see if any new data packets have arrived. Since there is no need to wait for and process interrupts, polling can reduce context switching and interrupt latency caused by interrupt processing, thereby improving the overall system performance.
[0039] In addition, after startup, the kernel configures interrupts for the cores (core numbers M+1...), specifying which cores are used to handle interrupts and how these interrupts are handled. To minimize the interference of interrupts on user-mode message processing, the kernel disables all hardware interrupts and soft interrupt processing capabilities except for the basic clock interrupt. The basic clock interrupt is necessary for the normal operation of the operating system and is used to maintain the system's timing and scheduling functions. Other hardware interrupts and soft interrupts may introduce additional delays and overhead, affecting the efficiency of user-mode message processing.
[0040] Step S102: The kernel thread assigns the data packet sending queue to different user states for processing, establishes a communication mechanism between the kernel state and the user state, and transmits the address information of the data packet sending queue to the corresponding user state to form a shared queue. Step S103: The user state receives the data packet assigned to it through the shared queue, modifies the data packet to generate a new data queue, and feeds back the address information of the new data packet queue to the kernel thread through the communication mechanism established with the kernel state. In step S104, the kernel thread takes out a new data packet queue from the shared queue according to the fed-back address information, and calls the network card driver to send the new data packet to the network.
[0041] In this optional embodiment, when the kernel thread receives network data packets transmitted by the network card in a polling manner and uses a hierarchical vectorization algorithm of dynamic flow classification hashing to store the received data packets in the form of queues to obtain a data packet sending queue, a dynamic five-tuple hash algorithm can be used to analyze the five-tuple features of the data packet, and based on the five-tuple features, the received network data packet is mapped to the initial queue according to the flow classification; based on the real-time traffic characteristics, a dynamic weight value is assigned to each flow category in the initial queue using a spin graph structure; the five-tuple features of the data packet are combined with the dynamic weight value and mapped to sub-queues of different priorities through a multi-layer hash function; the data packets are scheduled to the sending buffer in sequence according to the priority order of the sub-queues to form a final data packet sending queue.
[0042] In this optional embodiment, when a dynamic five-tuple hash algorithm is used to analyze the five-tuple features of a data packet, and the received network data packet is mapped to the initial queue according to the flow classification based on the five-tuple features, field information can be extracted from the header of the network data packet, and the field information can be parsed to obtain the five-tuple features of each data packet; a double hash function combination is used to calculate the hash value of the five-tuple feature, and a flow identifier is generated in combination with the timestamp information of the data packet; the data packet is mapped to the corresponding initial queue based on the modulo operation of the flow identifier and the number of initial queues; it is determined whether the mapped initial queue already has a corresponding flow record, and if so, the data packet is inserted into the queue, otherwise a new flow record is created and the queue is initialized before the data packet is inserted.
[0043] It should be noted that the dynamic five-tuple hashing algorithm is a technology used to classify and identify network packets. It performs hash calculations based on the five-tuple characteristics of the packet, thereby achieving rapid classification and mapping of the packet.
[0044] The quintuple signature refers to the five key fields in a network packet: source IP address, destination IP address, source port number, destination port number, and protocol type. These five fields uniquely identify a network connection or session. Using these five fields, packets can be categorized into specific "flows." A flow is defined as all network packets with the same quintuple signature, typically belonging to the same session or connection (for example, a TCP session with the same source and destination IP and port pair).
[0045] In this optional embodiment, when using a double hash function combination to calculate the hash value of the five-tuple feature and generating a flow identifier in combination with the timestamp information of the data packet, hash calculations can be performed based on the five-tuple feature using the main hash function and the auxiliary hash function respectively to obtain the main hash value and the auxiliary hash value; the main hash value and the auxiliary hash value are fused using an exclusive OR operation to obtain the hash value of the five-tuple feature; the timestamp information of the data packet reception is collected, and the timestamp information hash seed is mixed with the hash value of the five-tuple feature to obtain the flow identifier.
[0046] Specifically, when processing network packets, a dual hash function combination is used to more accurately identify and classify data flows. Five-tuple features are hashed using two different hash functions (a primary hash function and a secondary hash function) to improve the stability and uniqueness of the hash value.
[0047] A primary hash function (such as MD5, SHA-1, CRC32, or MurmurHash) is used to hash the five-tuple features (source IP address, destination IP address, source port number, destination port number, and protocol type) to generate the primary hash value. A secondary hash function (such as the FNV-1a algorithm) is used to hash the same five-tuple features to generate the secondary hash value.
[0048] Furthermore, to combine the primary and secondary hash values into a more stable hash value, an exclusive OR (XOR) operation can be used. The XOR operation is a bitwise operation that compares corresponding bits of two binary numbers. If they are identical, the result is 0; if they are different, the result is 1. Through the XOR operation, the information in the primary and secondary hash values can be combined to generate a new hash value that incorporates information from both the primary and secondary hash functions.
[0049] In addition to the five-tuple feature, the packet's timestamp is also an important basis for generating a flow identifier. The timestamp records the time a packet was received or sent, helping to distinguish packets arriving at different times with the same five-tuple feature. The timestamp serves as a hash seed and is combined with the five-tuple feature's hash value (the result of fusing the primary and secondary hash values) for a hash calculation. This combination involves combining the timestamp with the five-tuple feature's hash value in some manner (such as concatenation or weighting) and then performing another hash calculation. Alternatively, the timestamp is directly used as one of the input parameters of the hash function. This combination yields a new hash value, which serves as the flow identifier. A flow identifier uniquely identifies a data flow.
[0050] In this optional embodiment, when a dynamic weight value is assigned to each flow category in the initial queue based on real-time traffic characteristics using a spin graph structure, real-time traffic information of each flow category can be obtained, real-time traffic characteristics can be calculated based on the real-time traffic information, and the correlation between each flow characteristic can be analyzed using a correlation analysis method; based on the correlation between each flow characteristic, a spin graph structure of the flow category is constructed, and the flow category vertices and edge connection relationships are determined; based on the traffic characteristics and edge connection relationships, dynamic weight values are assigned to the edges in the spin graph structure based on feature similarity.
[0051] It should be noted that real-time traffic information refers to key metrics such as the current transmission rate, packet size, packet arrival interval, and latency for each flow. This can be obtained through real-time monitoring of network interfaces or using traffic sampling methods (such as NetFlow and sFlow). Certain flow categories within a network may have similar traffic characteristics. For example, some flows may exhibit similar arrival intervals, data volumes, or bandwidth utilization patterns. To achieve effective traffic management, it is necessary to analyze the correlation between these traffic characteristics. This involves extracting relevant features, such as flow rate, packet size, and arrival interval, from each flow's real-time traffic information. Similarity calculation methods (such as the Pearson correlation coefficient, cosine similarity, and covariance) are used to calculate feature similarity between different flow categories. Based on these similarity calculation results, a correlation matrix is constructed to represent the relationships between the various traffic features. Each element in the matrix represents the similarity between two flow categories, with larger values indicating greater similarity between the characteristics.
[0052] In this optional embodiment, when constructing a spin graph structure of flow categories based on the correlation between each flow feature and determining the flow category vertex and edge connection relationship, each flow category can be mapped to a vertex in the spin graph structure, and based on the correlation between each flow feature, an association matrix is established; according to the association matrix, spin edges and adjacent edges are added to each vertex, and adjacent edges are filtered based on a preset correlation threshold; based on the spin edges and adjacent edges, the spin graph structure of the flow category is constructed.
[0053] It should be noted that a spin graph is a graph structure that contains two types of edges: spin edges and adjacency edges. In a spin graph, vertices represent different flow categories, and edges describe the correlation between these flow categories. Spin edges represent the correlation between a flow category and itself. Spin edges are used to capture the internal dynamic characteristics of a flow category, such as flow fluctuations and adaptive changes in flow. They can help identify the state changes of a flow category over time. Adjacency edges represent the similarity or correlation between two flow categories and are established based on the correlation between flow characteristics.
[0054] To reduce redundancy and improve efficiency, a threshold is used to filter adjacent edges. An adjacent edge is added to the spin graph only when the correlation between flow categories exceeds this threshold. For example, if the similarity between flows A and B is 0.8, which exceeds a set threshold (such as 0.7), an adjacent edge is added between them. If the similarity is 0.5, which is below the set threshold, no adjacent edge is added.
[0055] By constructing a spin graph, the correlation between different flow categories can be represented in the graph, so that data packets can be more accurately classified into appropriate queues or processing units.
[0056] In this optional embodiment, when the kernel thread assigns the data packet sending queue to different user states for processing, establishes a communication mechanism between the kernel state and the user state, and passes the address information of the data packet sending queue to the corresponding user state to form a shared queue, a shared memory area can be created through the kernel thread and a synchronization mechanism can be configured to obtain a shared memory identifier, map the shared memory area to the kernel address space, and initialize the queue information of the data packet sending queue in the shared memory; the user state program obtains the shared memory identifier through a preset identifier transfer method, and uses the same shared memory identifier to map the shared memory area to the address space of the user state; the user state program obtains the synchronization mechanism, reads the queue information through the shared memory, and accesses the corresponding data packet sending queue in the shared memory according to the queue information to form a shared queue.
[0057] It's important to note that kernel threads create a shared memory area in kernel space. This shared memory area is mapped into the user-mode program's address space so that both can share data. This shared memory area is used to store packet queues and related status information (such as the queue's starting position and the current processing position).
[0058] The synchronization mechanism is used to ensure the correct synchronization between kernel mode and user mode to avoid data races. Commonly used synchronization mechanisms include semaphores, event identifiers, or futexes.
[0059] In this optional embodiment, when the user-state program obtains the synchronization mechanism, reads the queue information through the shared memory, and accesses the corresponding data packet sending queue in the shared memory according to the queue information to form a shared queue, the user-state program can read the identifier of the synchronization mechanism from the shared memory, and call the corresponding system function according to the identifier to obtain the handle of the synchronization mechanism; based on the handle of the synchronization mechanism, the queue information area in the shared memory is locked, and the queue information is read from the locked shared memory; the user-state program accesses the corresponding data packet sending queue in the shared memory through pointer operations according to the read queue information, and parses and processes the data packet to form a shared queue.
[0060] It's important to note that once shared memory is successfully mapped into the user-mode address space, the user-mode program needs to obtain a synchronization mechanism handle so that it can synchronize accesses to the data in the shared memory. The user-mode program reads the synchronization mechanism identifier from the shared memory. This identifier is provided by the kernel when creating the shared memory and is used to identify the specific synchronization mechanism.
[0061] The user-mode program uses this identifier to call the corresponding system function, such as sem_init(), eventfd(), or futex(), to obtain a handle to the synchronization mechanism. This handle represents an instance of the synchronization mechanism, allowing the user-mode program to synchronize operations with the kernel. Using the synchronization mechanism handle, the user-mode program can lock the queue information area in shared memory. After locking, the user-mode program can safely read relevant information about the packet queue (such as the queue starting position and current queue size) from shared memory.
[0062] In this optional embodiment, when the user state receives a data packet assigned to itself through a shared queue, modifies the data packet to generate a new data queue, and feeds back the address information of the new data packet queue to the kernel thread through a communication mechanism established with the kernel state, the user state can parse and process the received data packet, and modify the parsed data packet based on business needs; create a new data packet queue in the user state memory, insert the modified data packet into the queue in sequence to form a new data queue; the user state writes the address information of the new data packet queue into a memory area shared with the kernel state, and updates the queue status identifier in the shared memory; the user state triggers the kernel thread through the communication mechanism established with the kernel state, notifies it that there is a new data packet queue that needs to be processed, and waits for the kernel thread to confirm receipt or completion of processing.
[0063] Specifically, user-mode programs receive data packets from the network or other processes through a socket mechanism. A socket is a programming interface for network communication that allows data to be exchanged between different processes or hosts. User-mode programs parse received data packets and extract key information from them, such as the source IP address, destination IP address, port number, protocol type, and payload data. Based on business needs, user-mode programs then modify the parsed data packets. These modifications include: Change the source or destination IP address, port number, TTL value, etc.
[0064] Convert private IP addresses to public IP addresses, and vice versa.
[0065] Analyze the contents of data packets to identify and filter out malicious traffic or specific types of data packets.
[0066] It should be noted that after processing a received message, the user-mode program does not send it directly through the socket. Instead, it places the processed message into a shared queue. This separates the processing logic from the sending logic, improving the flexibility and scalability of the system.
[0067] In addition, data packets can be taken out in sequence and processed as necessary (such as parsing, modification, etc.); user-mode programs will process data packets according to business needs; for example, modifying the packet header, performing network address translation (NAT), performing deep packet inspection (DPI), etc.; the processed data packets are inserted into a new data queue to form a new shared queue, and finally fed back to the kernel thread for further processing or sending.
[0068] Figure 2 An embodiment of the network data packet forwarding performance optimization system based on a multi-core processor of the present invention is shown.
[0069] In this optional embodiment, the multi-core processor-based network data packet forwarding performance optimization system includes: The queue generation module 201 is configured to receive network data packets transmitted by the network card in a polling manner through a kernel thread, and store the received data packets in the form of queues using a layered vectorization algorithm based on dynamic flow classification and hashing to obtain a data packet transmission queue; The data sharing module 202 is used for the kernel thread to allocate the data packet sending queue to different user states for processing, establish a communication mechanism between the kernel state and the user state, and pass the address information of the data packet sending queue to the corresponding user state to form a shared queue; The information feedback module 203 is used for receiving data packets assigned to the user state through the shared queue, modifying the data packets to generate a new data queue, and feeding back the address information of the new data packet queue to the kernel thread through the communication mechanism established with the kernel state; The data sending module 204 is used for the kernel thread to take out a new data packet queue from the shared queue according to the fed-back address information, and call the network card driver to send the new data packet to the network.
[0070] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 3As shown. The computer device includes a processor, a memory, and a network interface connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store static information and dynamic information data. The network interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the steps of the above-mentioned method embodiment are implemented.
[0071] Those skilled in the art will understand that Figure 3 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present invention and does not constitute a limitation on the computer device to which the solution of the present invention is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0072] In addition, the present invention also provides a computer device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiment when executing the computer program.
[0073] In addition, the present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the above method embodiment are implemented.
[0074] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware using a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes in the above-described method embodiments. Any reference to memory, storage, database, or other media used in the various embodiments provided herein may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0075] The present invention is not limited to the structures described above and shown in the drawings, and various modifications and changes can be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for optimizing network packet forwarding performance based on a multi-core processor, characterized in that: The following steps are involved: The kernel thread receives network data packets transmitted by the network card in a polling manner, and uses the layered vectorization algorithm of dynamic flow classification hashing to store the received data packets in the form of queues to obtain the data packet sending queue; The kernel thread assigns the packet sending queue to different user states for processing, establishes a communication mechanism between the kernel state and the user state, and passes the address information of the packet sending queue to the corresponding user state to form a shared queue; The user state receives the data packets assigned to it through the shared queue, modifies the data packets, generates a new data queue, and feeds the address information of the new data packet queue back to the kernel thread through the communication mechanism established with the kernel state; The kernel thread takes out the new data packet queue from the shared queue according to the feedback address information, and calls the network card driver to send the new data packet to the network.
2. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 1, characterized in that: The kernel thread receives network data packets transmitted by the network card in a polling manner, and stores the received data packets in the form of queues using a layered vectorization algorithm of dynamic flow classification hashing. Obtaining a data packet sending queue includes the following steps: A dynamic five-tuple hash algorithm is used to analyze the five-tuple features of the data packet, and based on the five-tuple features, the received network data packet is mapped to the initial queue according to the flow classification; Based on real-time traffic characteristics, a dynamic weight value is assigned to each flow category in the initial queue using a spin graph structure; Combine the five-tuple features of the data packet with the dynamic weight value and map them to sub-queues of different priorities through a multi-layer hash function; According to the priority order of the sub-queues, the data packets are dispatched to the sending buffer in sequence to form the final data packet sending queue.
3. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 2, characterized in that: The method of analyzing the five-tuple features of the data packet by using the dynamic five-tuple hash algorithm and mapping the received network data packet to the initial queue according to the flow classification based on the five-tuple features includes the following steps: Extract field information from the header of the network data packet, parse the field information, and obtain the five-tuple features of each data packet; Using a double hash function combination, the hash value of the five-tuple feature is calculated and combined with the timestamp information of the data packet to generate a flow identifier; Map the data packet to the corresponding initial queue based on the modulo operation of the flow ID and the number of initial queues; Determine whether the mapped initial queue already has a corresponding flow record. If so, insert the data packet into the queue. Otherwise, create a new flow record and initialize the queue before inserting the data packet.
4. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 3, characterized in that: The method of calculating the hash value of the five-tuple feature by combining the double hash function and generating the flow identifier by combining the timestamp information of the data packet includes the following steps: Based on the five-tuple feature, the primary hash function and the auxiliary hash function are used to perform hash calculations respectively to obtain the primary hash value and the auxiliary hash value; The main hash value and the auxiliary hash value are fused using the XOR operation to obtain the hash value of the five-tuple feature; Collect the timestamp information of the data packet received, and mix the timestamp information hash seed with the hash value of the five-tuple feature to obtain the flow identifier.
5. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 4, characterized in that: The method of allocating a dynamic weight value to each flow category in the initial queue using a spin graph structure based on real-time traffic characteristics includes the following steps: Obtain real-time traffic information for each flow category, calculate real-time traffic features based on the real-time traffic information, and use correlation analysis to analyze the correlation between the traffic features; Based on the correlation between each flow feature, a spin graph structure of flow categories is constructed to determine the connection relationship between flow category vertices and edges; According to the traffic characteristics and edge connection relationships, dynamic weight values are assigned to the edges in the spin graph structure based on feature similarity.
6. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 5, characterized in that: The method of constructing a spin graph structure of flow categories based on the correlation between each flow feature and determining the connection relationship between flow category vertices and edges includes the following steps: Each flow category is mapped to a vertex in the spin graph structure, and a correlation matrix is established based on the correlation between each flow feature; According to the correlation matrix, spin edges and adjacent edges are added to each vertex, and adjacent edges are filtered based on the preset correlation threshold; Based on spin edges and adjacency edges, a flow-class spin graph structure is constructed.
7. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 1, characterized in that: The kernel thread allocates the data packet sending queue to different user states for processing, establishes a communication mechanism between the kernel state and the user state, and transmits the address information of the data packet sending queue to the corresponding user state. The formation of a shared queue includes the following steps: Create a shared memory area through kernel threads and configure the synchronization mechanism, obtain the shared memory identifier, map the shared memory area to the kernel address space, and initialize the queue information of the packet sending queue in the shared memory; The user-state program obtains the shared memory identifier through a preset identifier transfer method, and uses the same shared memory identifier to map the shared memory area to the user-state address space; The user-mode program obtains the synchronization mechanism, reads the queue information through the shared memory, and accesses the corresponding data packet sending queue in the shared memory according to the queue information to form a shared queue.
8. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 7, characterized in that: The user state program obtains a synchronization mechanism, reads queue information through shared memory, and accesses the corresponding data packet sending queue in the shared memory according to the queue information. Forming a shared queue includes the following steps: The user-mode program reads the identifier of the synchronization mechanism from the shared memory and calls the corresponding system function according to the identifier to obtain the handle of the synchronization mechanism; Based on the handle of the synchronization mechanism, the queue information area in the shared memory is locked and the queue information is read from the locked shared memory; The user-mode program accesses the corresponding data packet sending queue in the shared memory through pointer operations based on the read queue information, and parses and processes the data packets to form a shared queue.
9. The method for optimizing network data packet forwarding performance based on a multi-core processor according to claim 1, wherein: The user state receives the data packet assigned to itself through the shared queue, modifies the data packet to generate a new data queue, and feeds back the address information of the new data packet queue to the kernel thread through the communication mechanism established with the kernel state, including the following steps: The user state parses the received data packets and modifies them based on business needs. Create a new data packet queue in the user state memory, insert the modified data packets into the queue in order to form a new data queue; The user state writes the address information of the new packet queue into the memory area shared with the kernel state and updates the queue status flag in the shared memory; The user state triggers the kernel thread through the communication mechanism established with the kernel state, notifying it that there is a new packet queue that needs to be processed, and waits for the kernel thread to confirm receipt or completion of processing.
10. A network data packet forwarding performance optimization system based on a multi-core processor, characterized in that: include: The queue generation module is used by the kernel thread to receive network data packets transmitted by the network card in a polling manner, and uses the layered vectorization algorithm of dynamic flow classification hashing to store the received data packets in the form of queues to obtain the data packet sending queue; The data sharing module is used by the kernel thread to allocate the data packet sending queue to different user states for processing, establish a communication mechanism between the kernel state and the user state, and pass the address information of the data packet sending queue to the corresponding user state to form a shared queue; The information feedback module is used by the user state to receive data packets assigned to it through the shared queue, modify the data packets, generate new data queues, and feed back the address information of the new data packet queue to the kernel thread through the communication mechanism established with the kernel state; The data sending module is used by the kernel thread to take out the new data packet queue from the shared queue according to the feedback address information, and call the network card driver to send the new data packet to the network.
Citation Information
Patent Citations
X86 platform based method for achieving trillion traffic rapid packaging
CN103731364A
Method and device for forwarding message
CN104796337A
Network data packet processing method and device
CN110022267A
Data packet transceiving method and device, and medium
CN111211942A
Datagram processing method and device, electronic equipment and storage medium
CN119892957A