Packet processing method and network device
By introducing a variety of packet treatment methods and dynamic memory management in the network interface controller circuit, the problem of low packet treatment efficiency in the existing technology has been solved, and more efficient packet treatment and system resource management have been achieved.
Patent Information
- Application Number
- CN202310882418.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-18
- Publication Date
- 2025-01-21
AI Technical Summary
When the existing network interface controller circuit processes packets, a single packet processing method causes the system operation efficiency to decrease, especially when the data volume is large or small, and frequent memory space application and release also affects the system efficiency.
Provides a packet processing method with multiple packet processing methods and memory management. By configuring the storage pool and dynamically managing storage blocks, selecting the appropriate processing method according to the amount of packet data, using the interrupt function or polling function, and reporting to the kernel when necessary Apply to increase storage blocks or expand storage pool capacity.
It improves the efficiency of packet processing, avoids excessive occupation of system resources, and enhances the processing capability and operating efficiency of network devices.
Smart Images

Figure CN119342022A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to a packet processing method, and more particularly to a packet processing method and a network device having multiple packet processing modes and memory management. Background Art
[0002] Network interface controller (NIC) circuits are commonly found in various network devices for sending and processing packets. In some related technologies, the network interface controller circuit only uses a single packet processing method to process packets. However, in some situations (for example, if the amount of data of the packet to be processed is large, or if the amount of data of the packet to be processed is small or the number of packets to be processed is small), the running time occupied by the packet processing method may be too long, resulting in a significant decrease in system operating efficiency. On the other hand, when processing packets, the network interface controller circuit needs to apply for memory space from the system kernel to store the packet, and release the previously used memory space when the packet processing is completed. If the number of packets to be processed is large, the frequent operations of applying for and releasing memory space may also reduce the system operating efficiency. Summary of the invention
[0003] In some implementations, one of the purposes of the present disclosure is (but not limited to) to provide a packet processing method and a network device with multiple packet processing modes and memory management to improve the deficiencies of the prior art.
[0004] In some embodiments, the packet processing method includes the following operations: configuring a portion of the storage space of a memory circuit as a storage pool, wherein the storage pool includes multiple first storage blocks; when the data volume of a packet is less than or equal to a preset value, storing the packet in one of the first storage blocks, and returning the one of the first storage blocks to the storage pool after the packet processing is completed; when the number of remaining storage blocks in the first storage blocks that have not yet stored data is less than a critical value, applying to a kernel to increase the number of the first storage blocks; and when the data volume of the packet is greater than the preset value, applying to the kernel for at least one second storage block to increase the data capacity of the storage pool so as to store the packet in the storage pool, and returning the at least one second storage block to the kernel after the packet processing is completed.
[0005] In some embodiments, the network device includes a network interface controller circuit, a central processing unit circuit, and a memory circuit. The network interface controller circuit is used to receive a packet. The central processing unit circuit is used to run a kernel and a network interface controller driver. A portion of the storage space of the memory circuit is configured as a storage pool including a plurality of first storage blocks, and the storage pool is used to apply to the kernel to increase the number of the first storage blocks when the number of remaining storage blocks that have not yet stored data in the first storage blocks is less than a critical value. The network interface controller driver is used to: when the data volume of the packet is less than or equal to a preset value, store the packet in one of the first storage blocks, and return the one of the first storage blocks to the storage pool after the packet processing is completed; and when the data volume of the packet is greater than the preset value, apply to the kernel for at least one second storage block to increase the data capacity of the storage pool so as to store the packet in the storage pool, and return the at least one second storage block to the kernel after the packet processing is completed.
[0006] The features, implementation and technical effects of the present disclosure are described in detail below with reference to the accompanying drawings as preferred embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] Figure 1 A schematic diagram of a network device drawn according to some embodiments of the present disclosure;
[0008] Figure 2 According to some embodiments of the present disclosure Figure 1 A flowchart of the operations related to the processing of packets by a network interface controller (NIC) driver;
[0009] Figure 3A According to some embodiments of the present disclosure Figure 1 A schematic diagram of the operation of the storage pool in the first situation;
[0010] Figure 3B According to some embodiments of the present disclosure Figure 1 A schematic diagram of the operation of the storage pool in the second situation;
[0011] Figure 3C According to some embodiments of the present disclosure Figure 1 Operation diagram of the storage pool;
[0012] Figure 4 A schematic diagram of a network device according to some embodiments of the present disclosure; and
[0013] Figure 5 The present invention is a flowchart of a packet processing method drawn according to some embodiments of the present disclosure.
[0014] Explanation of symbols
[0015] 100: Network device
[0016] 110: CPU circuit
[0017] 112: Network Interface Controller (NIC) Driver
[0018] 114: Protocol stack
[0019] 116: Kernel
[0020] 120: Network interface controller (NIC) circuit
[0021] 130: Memory Circuit
[0022] 135: Storage Pool
[0023] 301A~301D: Storage blocks
[0024] 310,320: At least one storage block
[0025] 400: Network Device
[0026] 401,402: Connection port
[0027] 500: Packet processing method
[0028] P: Header
[0029] P1, P1', P2: Packet
[0030] PR: Constant Data
[0031] PV: Preset value
[0032] S210,S220,S230,S240,S510,S520,S530,S540: Operation
[0033] TH: Threshold DETAILED DESCRIPTION
[0034] All words used herein have their ordinary meanings. The definitions of the above words in commonly used dictionaries and the use examples of any words discussed herein in the content of this disclosure are only illustrative and should not limit the scope and meaning of this disclosure. Similarly, this disclosure is not limited to the various embodiments shown in this specification.
[0035] As used herein, "coupled" or "connected" may refer to two or more elements making direct physical or electrical contact with each other, or making indirect physical or electrical contact with each other, or may refer to two or more elements operating or acting on each other. As used herein, the term "circuit" may be a device composed of at least one transistor and / or at least one active and passive element connected in a certain manner to process signals.
[0036] As used herein, the term "and / or" includes any combination of one or more of the listed associated items. In this article, the words first, second, third, etc. are used to describe and distinguish each element. Therefore, the first element in this article can also be called the second element without departing from the original intention of the present disclosure. For ease of understanding, similar elements in the various drawings will be designated with the same reference numerals.
[0037] Figure 1 The diagram is a schematic diagram of a network device 100 according to some embodiments of the present disclosure. In some embodiments, the network device 100 may be, but is not limited to, a network device such as a switch, a router, or a wireless access point.
[0038] The network device 100 includes a central processing unit circuit 110, a network interface controller (NIC) circuit 120, and a memory circuit 130, wherein the central processing unit circuit 110 can be used to run a NIC driver 112, a protocol stack 114, and a kernel 116. In some embodiments, the NIC driver 112 can be a driver executed by the central processing unit circuit 110, which can be used to set or control the NIC circuit 120 to process the received packet P1. In some embodiments, the protocol stack 114 can be a software implementation of a computer network protocol, which can be used to interact with the NIC circuit 120 and the kernel 116 to process the received packet P1. In some embodiments, the kernel 116 can be, but is not limited to, a computer program in the operating system used to manage the data transmission and reception requirements of each hardware component.
[0039] In some embodiments, the NIC circuit 120 may also be referred to as a network interface card. In some embodiments, the NIC circuit 120 may be a circuit system for implementing a specific network standard (e.g., Ethernet, local area network, etc.), which may allow the network device 100 to interact with other devices on the network. The NIC circuit 120 may transmit or receive packets via the network. In a normal mode, under the control of the NIC driver 112, the NIC circuit 120 may transmit the received packet P1 to the protocol stack 114 for parsing. Alternatively, in a normal mode, the protocol stack 114 may send the packet P2 to be transmitted to other devices (not shown) via the NIC circuit 120. In some embodiments, when the NIC circuit 120 may operate in a loopback mode, the NIC driver 112 may transmit the received packet P1 (labeled as packet P1') back to the NIC circuit 120. In this way, the NIC circuit 120 may confirm whether the packet P1 is consistent with the packet P1', thereby checking whether the connection between the network device 100 and the other device that sent the packet P1 is correct.
[0040] In some embodiments, the NIC driver 112 can selectively use the interrupt function or the polling function to process the packet P1 according to the data volume of the packet P1. In this way, the appropriate packet processing method can be used according to the actual data volume of the received packet P1 to improve the efficiency of packet processing. The operation here will be referred to later. Figure 2 In some embodiments, the aforementioned interrupt function may be, but not limited to, an interrupt request (IRQ) of a Linux system. In some embodiments, the aforementioned polling function may be, but not limited to, a polling function of a Linux system.
[0041] In some embodiments, the memory circuit 130 is mainly managed by the kernel 116. In some embodiments, the memory circuit 130 can be used to store various data, and a portion of the storage space of the memory circuit 130 is configured as a storage pool 135. In some embodiments, multiple storage blocks in the storage pool 135 (i.e., different storage spaces in the memory circuit 130) can be used to store transient data generated during the processing of the packet P1. In some embodiments, the NIC driver 112 can adjust the configuration of the storage blocks in the storage pool 135 to improve the efficiency of sending and receiving packets. The operation here will be referred to later. FIG. 3A to FIG. 3C Provide explanation.
[0042] Figure 2 According to some embodiments of the present disclosure Figure 1Flowchart of the related operations of the NIC driver 112 processing the packet P1. In operation S210, when a packet is received, an interrupt request is sent and the polling function is started, and the interrupt request is disabled. In operation S220, it is confirmed whether the data volume of the packet is less than a weight. If the data volume of the packet is less than the weight, operation S230 is performed. Alternatively, if the data volume of the packet is greater than or equal to the weight, operation S240 is performed. In operation S230, an interrupt request is issued to stop using the polling function, and the interrupt function is used to process the packet. In operation S240, the polling function is used to process the packet.
[0043] In some embodiments, the weight W (e.g. Figure 1 (shown) may be a preset value pre-recorded by the NIC driver 112. In some embodiments, the weight W may be set according to the network traffic. For example, the weight W may be set to, but not limited to, 32 or 64. The NIC driver 112 may select a corresponding one of the polling function or the interrupt function to process the packet P1 by comparing the weight W with the data volume of the received packet P1. In detail, when the NIC circuit 120 receives the packet P1, an interrupt request is issued, and the polling function is started in the corresponding interrupt processing process, and then the interrupt request is disabled (i.e., operation S210). The NIC driver 112 may compare the weight W with the data volume of the received packet P1 (i.e., operation S220). If the data volume of the packet P1 is greater than or equal to the weight W, the NIC driver 112 may use the polling function to process the packet P1 (i.e., operation S240). Alternatively, if the data volume of the packet P1 is less than the weight W, the NIC driver 112 may issue an interrupt request to stop the polling function and use the interrupt function to process the packet P1 (i.e., operation S230).
[0044] Through the above configuration, when the packet P1 is a packet with a large data volume, the NIC driver 112 can use the polling function to process the packet P1. On the other hand, when the packet P1 is a packet with a small data volume, the NIC driver 112 can use the interrupt function to process the packet P1. In other words, according to the data volume of the packet P1 to be processed, the NIC driver 112 can use a suitable packet processing method, thereby avoiding excessive use of the processing time of the CPU circuit 110 and improving the packet processing efficiency.
[0045] For ease of understanding and examples, the following will refer to FIG. 3A to FIG. 3B The network device 100 processes the packet P1 in the loopback mode as an example for description, but the present disclosure is not limited thereto.
[0046] Figure 3A According to some embodiments of the present disclosure Figure 1Schematic diagram of the operation of the storage pool 135 in a first scenario. In some embodiments, when the NIC driver 112 uses the polling function and / or the interrupt function to process the packet P1, the NIC driver 112 can temporarily store the packet P1 in at least one storage block of the storage pool 135, and release the at least one storage block back to the storage pool 135 after processing the packet P1. In some embodiments, before the network device 100 is about to transmit the processed packet P1', the NIC circuit 120 will output an interrupt request, and the NIC driver 112 can respond to the interrupt request to release the aforementioned at least one storage block. In other words, Figure 3A The operations shown can be viewed as Figure 2 For example, when executing the polling function, the NIC driver 112 may store multiple descriptors of the packet P1 in at least one storage block of the storage pool 135, thereby parsing the multiple descriptors in the at least one storage block. After parsing all descriptors in the packet P1, the NIC driver 112 may release the at least one storage block back to the storage pool 135 using the free function (which is a space release function).
[0047] In some embodiments, before starting to receive packets, the NIC driver 112 may request the kernel 116 to allocate storage space in the memory circuit 130 to configure the storage space as the storage pool 135. For example, the NIC driver 112 may use the malloc function (which is a memory allocation function) to request the kernel 116 to allocate a portion of the space in the memory circuit 130 to the storage pool 135. Figure 3A As shown, the storage pool 135 includes a plurality of storage blocks 301A-301D, which are configured based on a chain table structure. The storage block 301A is the first storage block in the storage pool 135, which may store a header P. In some embodiments, the header P may indicate the starting position of the chain table, the length of the chain table (i.e., the number of the plurality of storage blocks 301A-301D), the number of storage blocks in the plurality of storage blocks 301A-301D that have not yet stored data, and other information related to the storage pool 135. In some embodiments, each of the plurality of storage blocks 301A-301D has a same preset data capacity, which may be, but is not limited to, 1600 bytes.
[0048] In some embodiments, the NIC driver 112 may compare the data volume of the received packet P1 with a preset value PV (eg, Figure 1 When the data volume of packet P1 is less than or equal to the preset value PV (i.e. Figure 3AIn the first scenario shown in FIG. 1 , the NIC driver 112 may store the packet P1 in one of the plurality of storage blocks 301A to 301D. In some embodiments, the preset value PV may be based on the aforementioned preset data capacity, and may be a preset value previously recorded by the NIC driver 112. For example, the preset value PV may be set to a value that is the same as the aforementioned preset data capacity. In this way, when the amount of data of the packet P1 is less than or equal to the preset value PV, it means that the storage space of any one of the plurality of storage blocks 301A to 301D is sufficient to store the packet P1. Under this condition, the NIC driver 112 may store the packet P1 in one of the plurality of storage blocks 301A to 301D (for example, storage block 301B) to process the packet P1. Then, after the NIC driver 112 has processed the packet P1, the NIC driver 112 may return the storage block 301B to the storage pool 135 (instead of the kernel 116).
[0049] For example, Figure 3A As shown, after the packet P1 is processed, the NIC driver 112 may return the storage block 301B to the storage pool 135. The storage block 301B may be set as the first storage block of the storage pool 135 (i.e., updated to the first storage block in the linked list). Under this condition, the header P1 stored in the storage block 301A will be transferred to be stored in the storage block 301B.
[0050] Figure 3B According to some embodiments of the present disclosure Figure 1 Schematic diagram of the operation of the storage pool 135 in the second situation. Figure 3A In the first case, Figure 3B When the data volume of packet P1 is greater than the preset value PV (i.e. Figure 3BThe second situation shown in FIG. 1 represents that the storage space of any one of the plurality of storage blocks 301A-301D may not be sufficient to store the packet P1. Under this condition, the NIC driver 112 may use the aforementioned malloc function to request the kernel 116 for additional space (e.g., at least one storage block 310) of the memory circuit 130 to increase the storage capacity of the storage pool 135, thereby storing the packet P1 in the storage pool 135. For example, the NIC driver 112 may store the data of the packet P1 in the plurality of storage blocks 301B-301D in sequence. After obtaining at least one storage block 310, the NIC driver 112 may transfer the packet P1 in the plurality of storage blocks 301B-301D to at least one storage block 310. In other words, when the data volume of the packet P1 is large, the NIC driver 112 may request the kernel 116 to use more storage blocks in the memory circuit 130 to ensure that the data capacity of at least one storage block (i.e., at least one storage block 310) in the storage pool 135 is sufficient to store the packet P1. Next, after the NIC driver 112 processes the packet P1, the NIC driver 112 may return at least one storage block 310 to the kernel 116. Under this condition, the number of the plurality of storage blocks 301A-301D in the storage pool 135 may remain unchanged.
[0051] Figure 3C According to some embodiments of the present disclosure Figure 1 Schematic diagram of the operation of the storage pool 135. Figure 3A and / or Figure 3B During the operation shown, the memory pool 135 in the memory circuit 130 can be configured based on the information of the header P and the threshold TH (eg Figure 1 As shown in FIG. 1 , the core 116 is selectively requested to request more storage space in the memory circuit to increase the number of storage blocks in the storage pool 135. For example, the threshold value TH may be a preset value recorded in advance in the storage pool 135. Figure 3C As shown, it is assumed that the critical value TH is set to 2, and the plurality of memory blocks 301B, 301C, and 301D have all stored the packet P1. In other words, in the memory pool 135, the remaining memory block that has not yet stored data is the memory block 301A, and the number of the remaining memory blocks is 1. The memory pool 135 can learn the number of remaining memory blocks according to the header P, and compare this number with the critical value TH. Since the number of remaining memory blocks is less than the critical value TH, the memory pool 135 can use the malloc function via the NIC driver 112 to request more memory blocks (for example, at least one memory block 320) in the memory circuit 130 from the kernel 116, thereby increasing the number of available memory blocks in the memory pool 135. In this way, the memory pool 135 can have a certain number of available memory blocks (whose number is greater than or equal to the critical value TH) before processing the next packet, so as to maintain the packet processing efficiency.
[0052] exist Figure 3A , Figure 3B and Figure 3C The various values mentioned (eg, the preset value PV, the threshold value TH, the number of storage blocks in each drawing) are all used for examples, and the present disclosure is not limited thereto.
[0053] Figure 4 Schematic diagram of a network device 400 drawn according to some embodiments of the present disclosure. In this example, the NIC circuit 110 is configured to operate as a one-armed router, so that the network device 400 can be configured with multiple sub-ports to connect different virtual local area networks (VLANs). For example, the connection port 401 belongs to the first virtual local area network, and the connection port 402 belongs to the second virtual local area network, wherein the first virtual local area network and the second virtual local area network can be connected and communicated with each other via the network device 400. In some embodiments, the network device 400 (and / or the NIC circuit 110) has the function of a third layer switch.
[0054] Under this condition, the NIC driver 112 can add constant data PR to the packet P1 when receiving the packet P1 (e.g., from the connection port 401). For example, in the process of processing the packet P1, based on the network data structure of Linux, the NIC driver 112 can extract the constant data PR from the original storage block (e.g., Figure 3A When the NIC driver 112 reads the packet P1 from the plurality of storage blocks 301A-301D in the storage pool 135, the constant data PR is added to the data structure of the packet P1 (e.g., the data field cb in the data structure skb). Then, when the NIC driver 112 transmits a packet, it can determine whether the packet includes the constant data PR. If the packet includes the constant data PR, it means that the packet is read from the storage pool 135 (e.g., the packet P1). Under this condition, the NIC driver 112 can release the storage block (e.g., the storage block 114) previously used to store the packet P1 in the storage pool 135. Figure 3A Alternatively, if the packet to be transmitted does not contain the constant data PR, it means that the packet is not read from the original storage block of the storage pool 135. Under this condition, the NIC driver 112 may release the storage space previously used to store the packet to the kernel 116 after transmitting the packet. Figure 4 In the example, the NIC driver 112 provides the packet P1 to the protocol stack 114 for processing.
[0055] Figure 5A flow chart of a packet processing method 500 drawn according to some embodiments of the present disclosure. In operation S510, a portion of storage space in a memory circuit is configured as a storage pool, wherein the storage pool includes a plurality of first storage blocks. In operation S520, when the amount of data in a packet is less than or equal to a preset value, the packet is stored in one of the first storage blocks, and the one of the first storage blocks is returned to the storage pool after the packet processing is completed. In operation S530, when the number of remaining storage blocks in the first storage blocks that have not yet stored data is less than a critical value, an application is made to a kernel to increase the number of the first storage blocks. In operation S540, when the amount of data in the packet is greater than the preset value, an application is made to the kernel to increase the data capacity of the storage pool so as to store the packet in the storage pool, and the at least one second storage block is returned to the kernel after the packet processing is completed.
[0056] The description of the multiple operations of the above-mentioned packet processing method 500 can refer to the aforementioned multiple embodiments, so it will not be repeated here. The above-mentioned multiple operations are only examples and are not limited to being performed in the order in this example. Without violating the operating mode and scope of each embodiment of the present disclosure, the various operations under the packet processing method 500 can be appropriately increased, replaced, omitted or performed in a different order. Alternatively, one or more operations under the packet processing method 500 can be performed simultaneously or partially simultaneously. For example, the operation of operation S530 can be performed simultaneously or partially simultaneously with operation S520 and / or operation S540.
[0057] In summary, the packet processing method and network device provided in some embodiments of the present disclosure can select a suitable processing method from a variety of packet processing methods according to the data volume of the packet, and configure a dynamically manageable storage pool to help speed up packet processing. In this way, the efficiency of sending and receiving packets of the entire system can be improved.
[0058] Although the embodiments of the present disclosure are described above, these embodiments are not intended to limit the present disclosure. Those skilled in the art may make changes to the technical features of the present disclosure based on the explicit or implicit contents of the present disclosure. All these changes may fall within the scope of patent protection sought by the present disclosure. In other words, the scope of patent protection of the present disclosure shall be based on what is defined in the claims of this specification.
Claims
1. A packet processing method, comprising: configuring a portion of storage space of a memory circuit as a storage pool, wherein the storage pool includes a plurality of first storage blocks; When the data volume of a packet is less than or equal to a preset value, the packet is stored in one of the plurality of first storage blocks, and after the packet processing is completed, the one of the plurality of first storage blocks is returned to the storage pool; When the number of remaining storage blocks in the plurality of first storage blocks that have not stored data is less than a critical value, applying to a core to increase the number of the plurality of first storage blocks; and When the data volume of the packet is greater than the preset value, at least one second storage block is applied to the kernel to increase the data capacity of the storage pool to store the packet in the storage pool, and the at least one second storage block is returned to the kernel after the packet processing is completed.
2. The packet processing method as claimed in claim 1, wherein the storage pool is configured based on a linked list structure.
3. The packet processing method as claimed in claim 1, wherein a first one of the plurality of first storage blocks is used to store a header, and the header is used to indicate the number of the plurality of first storage blocks and the number of the remaining storage blocks that have not yet stored data.
4. The packet processing method according to claim 1, further comprising: comparing the data volume of the packet with a weight; When the data volume of the packet is less than the weight, using an interrupt function to process the packet; and When the data volume of the packet is greater than or equal to the weight, a polling function is used to process the packet.
5. The packet processing method according to claim 1, further comprising: When reading the packet from the one of the plurality of first memory blocks, adding a constant data to the packet; When transmitting the packet, determining whether the packet contains the constant data; as well as If the packet includes the constant data, returning the one of the plurality of first storage blocks to the storage pool after the packet is transmitted.
6. The packet processing method according to claim 5, further comprising: If the packet does not contain the constant data, the at least one second storage block is returned to the core after the packet is transmitted.
7. The packet processing method of claim 5, wherein the packet is received via a network interface controller circuit, and the network interface controller circuit operates as a one-armed router.
8. The packet processing method of claim 1, wherein the packet is a packet received by a network interface controller circuit in a loopback mode.
9. The packet processing method as claimed in claim 1, wherein the preset value is the same as a preset data capacity of each of the plurality of first storage blocks.
10. A network device comprising: A network interface controller circuit for receiving a packet; a central processing unit circuit for running a kernel and a network interface controller driver; as well as A memory circuit, wherein a portion of the memory space of the memory circuit is configured as a memory pool including a plurality of first memory blocks, and the memory pool is used to apply to the kernel to increase the number of the plurality of first memory blocks when the number of remaining memory blocks that have not stored data in the plurality of first memory blocks is less than a critical value, The network interface controller driver is used to: When the data amount of the packet is less than or equal to a preset value, the packet is stored in one of the plurality of first storage blocks, and after the packet processing is completed, the one of the plurality of first storage blocks is returned to the storage pool; as well as When the data volume of the packet is greater than the preset value, at least one second storage block is applied to the kernel to increase the data capacity of the storage pool to store the packet in the storage pool, and the at least one second storage block is returned to the kernel after the packet processing is completed.