A flow table creation method, device, computer equipment and storage medium

By detecting and managing the flow table index cache area and memory pool of the CPU core, the problem of degraded flow table creation performance is solved, and efficient flow table creation in a multi-core environment is achieved.

CN114035946BActive Publication Date: 2025-03-25EVERSEC BEIJING TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111280393.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-29
Publication Date
2025-03-25
Estimated Expiration
2041-10-29

AI Technical Summary

Technical Problem

In the case of large flow table specifications, frequent creation, and large number of CPU cores, the existing technology has led to a degradation in the flow table creation performance.

Method used

By monitoring the emergence of new streams, the flow table index cache area of ​​the current CPU core is detected, and the flow table memory pool is locked when exhausted, and the free flow table index value is applied and added to the cache area, and the memory pool is unlocked, and the free flow table is obtained to create the flow table.

Benefits of technology

In a multi-core environment, the flow table creation performance is improved, the flow table creation speed is avoided, and the creation process interruption caused by large flow table specifications and small CPU cache is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114035946B_ABST
    Figure CN114035946B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a flow table creation method, device, computer equipment and storage medium. The method includes: when a new flow is detected, if the information of the new flow does not exist in the historical information of the traffic, the size of the flow table index cache corresponding to the current central processing unit CPU core is detected; if it is detected that the flow table index cache is exhausted, the flow table memory pool is locked; a set number of free flow tables are applied from the flow table memory pool, and the index value of the free flow table is added to the flow table index cache, and the flow table memory pool is unlocked; according to the free flow table index value, the free flow table is obtained from the flow table memory pool, and the information of the new flow is stored in the free flow table to create a flow table. Through the technical solution of the embodiment of the present invention, when the flow table specification is relatively large, the creation is relatively frequent, and the number of CPU cores is relatively large, the memory allocation efficiency can be improved, and the flow table creation performance can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present invention relate to the field of computer technology, and in particular to a flow table creation method, device, computer equipment, and storage medium. Background Art

[0002] With the rapid development of technology, the traffic data in Ethernet is growing rapidly. Therefore, it is very important to create a user-mode multi-core flow table to record Ethernet traffic forwarding actions, flow status and some other flow information.

[0003] In the prior art, the user-mode multi-core flow table is usually created by directly applying for memory and using a memory pool plus thread lock. However, when flow tables are frequently created and the number of CPU cores is relatively large, directly applying for memory and using a memory pool plus thread lock may lead to a decrease in flow table creation performance. When the flow table size is large, limited storage may also lead to a decrease in flow table creation performance. Therefore, how to improve flow table creation performance when flow tables are frequently created, flow tables are relatively large, and the number of CPU cores is relatively large is still an urgent problem to be solved. Summary of the invention

[0004] The embodiments of the present invention provide a flow table creation method, apparatus, computer equipment and storage medium, which can achieve that when the flow table specification is relatively large, the creation is relatively frequent, and the number of CPU cores is relatively large, each CPU can directly use the flow table corresponding to the index value in its own cache, thereby improving the flow table creation performance.

[0005] In a first aspect, an embodiment of the present invention provides a flow table creation method, including:

[0006] When a new flow is detected, if the information of the new flow does not exist in the historical information of the flow, the size of the flow table index buffer corresponding to the current CPU core is detected;

[0007] If it is detected that the flow table index cache is exhausted, the flow table memory pool is locked;

[0008] Apply for a set number of idle flow tables from the flow table memory pool, add the index values ​​of the idle flow tables to the flow table index buffer, and unlock the flow table memory pool;

[0009] An idle flow table is obtained from a flow table memory pool according to the idle flow table index value, and information of the new flow is stored in the idle flow table to create a flow table.

[0010] In a second aspect, an embodiment of the present invention further provides a flow table creation device, the device comprising:

[0011] The idle flow table detection module is used to detect the size of the flow table index buffer corresponding to the current CPU core when a new flow is detected and if the information of the new flow does not exist in the historical information of the flow;

[0012] A flow table memory pool locking module, configured to lock the flow table memory pool if it is detected that the flow table index buffer is exhausted;

[0013] An index value adding module, used for applying for a set number of idle flow tables from the flow table memory pool, adding the index values ​​of the idle flow tables to the flow table index buffer area, and unlocking the flow table memory pool;

[0014] The flow table creation module is used to obtain an idle flow table from a flow table memory pool according to the idle flow table index value and store the information of the new flow in the idle flow table to create a flow table.

[0015] In a third aspect, an embodiment of the present invention further provides a computer device, the computer device comprising:

[0016] one or more processors;

[0017] a storage device for storing one or more programs,

[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the flow table creation method as described in any embodiment of the present invention.

[0019] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored, and when the program is executed by a processor, the flow table creation method as described in any embodiment of the present invention is implemented.

[0020] The technical solution of the embodiment of the present invention detects the size of the flow table index cache area corresponding to the current central processing unit CPU core when a new flow that has not been stored appears, and locks the flow table memory pool when the flow table index cache area is exhausted, and then adds the index values ​​of a set number of idle flow tables applied from the flow table memory pool to the flow table index cache area, and unlocks the flow table memory pool, and then obtains the idle flow table from the flow table memory pool according to the idle flow table index value and stores the information of the new flow in the idle flow table to create a flow table. This solves the problem of decreased flow table creation performance caused by large flow table specifications, frequent creation, and a large number of CPU cores, and improves the flow table creation performance in a multi-core environment, large flow table specifications, and a large number of CPU cores. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1ais a flow chart of a flow table creation method provided by an embodiment of the present invention;

[0022] Figure 1b It is a schematic diagram of a flow table hash map applicable to an embodiment of the present invention;

[0023] Figure 1c is a schematic diagram of a flow table linear storage applicable to an embodiment of the present invention;

[0024] Figure 2a is a flow chart of a flow table creation method provided by an embodiment of the present invention;

[0025] Figure 2b It is a structural schematic diagram of a flow table creation method provided by an embodiment of the present invention;

[0026] Figure 3 This is a flowchart of a preferred flow table creation method provided by an embodiment of the present invention;

[0027] Figure 4 It is a structural schematic diagram of a flow table creation device provided by an embodiment of the present invention;

[0028] Figure 5 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0029] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0030] Currently, Ethernet provides convenience for people's lives, but with the rapid growth of traffic data in Ethernet, it becomes very important to create a user-mode multi-core flow table to record Ethernet traffic forwarding actions, flow status and some other flow information.

[0031] In the prior art, the following two methods are usually used to create a user-mode multi-core flow table:

[0032] 1. Direct memory application method: The network card receive side scaling technology (Receive Side Scaling, RSS) stores the new flow hash to a specific CPU core. Finally, after entering the flow table module of the forwarding device, the flow table management module calls the system memory application application interface (Application Programming Interface, API) to apply for flow table storage space for the new flow and initialize the flow table information. At the same time, the index value of the flow table is stored in the hash table for easy query next time. Among them, the API operating system provides application developers with a unified interface that can be used to manage system IO resources and system memory resources. Application developers do not need to consider how the underlying source code is implemented or understand the details of its internal working mechanism. The API itself is abstract. It only defines an interface without involving the specific operations of the application in the actual implementation process.

[0033] 2. Memory pool + thread lock method: After the program starts, the flow table module is initialized and directly applies for a specified flow table memory pool by calling the operating system API, and waits for the new flow of the network card RSS to a specific CPU core. The flow table management module obtains a new flow table from the memory pool in a locked manner, initializes the flow table information and stores the index value of the flow table in the hash table to facilitate the next query. Among them, the memory pool is a certain number of memory blocks of equal size that are applied for allocation before the memory is actually used, and is kept as a backup. When there is a new memory demand, a part of the memory block is allocated from the memory pool. If the memory block is not enough, new memory will continue to be applied for, so that the memory allocation efficiency is improved.

[0034] However, method 1 applies for flow table memory by calling the operating system API. Although it can use the system layer to ensure that various problems caused by non-atomic operations when multiple cores access the same resource, frequent memory applications and releases through the system API will generate a large amount of memory fragments, which will reduce the running efficiency of the program. When dealing with flow tables at the 1000K specification level, frequent system calls will also generate a lot of additional CPU overhead, resulting in a significant decrease in the performance of creating new flow tables. At the same time, this method is also prone to memory leaks; method 2 uses a memory pool. Although it can solve the problems of memory fragmentation caused by frequent memory applications and releases, the problem of additional CPU overhead caused by frequent calls to the system API, and memory leaks in method 1, thread locks are mutually exclusive. In the case of multiple cores, once a CPU core obtains the lock and is applying for flow table memory, other CPU cores will spin-wait when they try to obtain the lock at this time. That is, once a CPU core obtains the lock, all CPU cores bound to the remaining program will be in a spin-wait state as long as they obtain the lock, which makes the performance of creating new flow tables significantly decrease when flow tables are frequently created and the number of CPU cores is relatively large.

[0035] In order to solve the above problems existing in the prior art, an embodiment of the present invention proposes a flow table creation method. When a new flow is detected and the information of the new flow does not exist in the historical information of the traffic, the size of the flow table index cache corresponding to the current central processing unit CPU core is detected, that is, by setting a corresponding flow table index cache for the CPU core and storing an idle flow table index value in each flow table index cache, the CPU core can obtain the idle flow table index value without locking the flow table index cache when the flow table is created. This solves the problem that when there are many CPU cores and multiple cores compete, one CPU core obtains the lock, and all the remaining CPU cores will be in a spin-waiting state as long as they obtain the lock, resulting in a decrease in the flow table creation speed. At the same time, it solves the problem that when the flow table is created frequently, multiple CPU cores simultaneously apply for flow from the same memory pool. table, resulting in a problem of decreased flow table creation speed; and, when it is detected that the flow table index cache is exhausted, the flow table memory pool is locked, and then a set number of free flow tables are applied for from the flow table memory pool, the index value of the free flow table is added to the flow table index cache, and the flow table memory pool is unlocked, thereby, the free flow table can be obtained from the memory pool according to the free flow table index value, and the information of the new flow is stored in the free flow table to create a flow table, which solves the problem of decreased flow table creation performance caused by multiple CPU cores frequently and directly applying for flow tables from the flow table memory pool when there are many CPU cores, and the problem that the flow table creation process cannot continue due to a small CPU cache when the flow table specification is relatively large.

[0036] Figure 1a A flowchart of a flow table creation method provided in an embodiment of the present invention is applicable to situations where flow tables are created when the flow table specifications are relatively large, new flow tables are created frequently, and the number of CPU cores is relatively large. The method can be executed by a flow table creation device, which can be implemented in hardware and / or software and can generally be integrated in a computer device.

[0037] like Figure 1a As shown, a flow table creation method provided by an embodiment of the present invention includes the following specific steps:

[0038] S110: When a new flow is detected, if the information of the new flow does not exist in the historical information of the flow, the size of the flow table index buffer corresponding to the current CPU core is detected.

[0039] Among them, the historical information of traffic may refer to the relevant information of the stored historical traffic. A flow table may refer to a way for a network forwarding device to record Ethernet traffic forwarding actions, flow status and some other flow information; usually the flow table will carry the forwarding action of the current flow: forwarding, discarding or caching, etc. The flow table index cache area corresponding to the current central processing unit CPU core may refer to a cache pre-allocated to each CPU core, which is used to store the index value of each flow table, wherein each CPU core has its corresponding cache. The flow table index value may refer to a value for quickly indexing the storage location of the flow table. A certain number of flow table index values ​​are stored separately for each CPU core in the cache, so that each CPU can directly obtain the flow table index value from the cache without lock when creating a flow table. An idle flow table may refer to a flow table that does not store traffic information. An idle flow table index value may refer to a flow table index value corresponding to the idle flow table in the cache. Since each flow table has its corresponding index value, the corresponding idle flow table can be detected by calculating the size of the flow table index cache area.

[0040] In an optional implementation of the embodiment of the present invention, if the information of the new flow does not exist in the historical information of the traffic, the size of the flow table index cache corresponding to the current central processing unit CPU core is detected, including: if the information of the new flow does not exist in the flow table hash table used to store the historical information of the traffic, the number of free flow table index values ​​in the flow table index cache corresponding to the current CPU core is detected. The flow table is usually stored in the device in a hashing manner, and generally uses a five-tuple, namely source IP, destination IP, source port, destination port and protocol number, as the keyword key, and value as the memory index value that actually stores the flow table information, such as Figure 1b The figure shows a schematic diagram of a flow table hash map, which is used to indicate that the flow table content can be directly accessed through the value index value of the flow table hash table when querying the flow table. Bucket can refer to a hash method with a hash bucket. In the embodiment of the present invention, there is no limit on the number of hash buckets. Among them, the historical information of the traffic can refer to the traffic five-tuple key value stored in the flow table hash table and the corresponding value index value. Specifically, if the flow table hash table does not contain the key value corresponding to the new flow and the value index value corresponding to the key value, it proves that the new flow has not been stored and a new flow table needs to be created. Furthermore, the number of free flow table index values ​​in the flow table index cache corresponding to the current CPU core is detected.

[0041] S120: If it is detected that the flow table index cache is exhausted, the flow table memory pool is locked.

[0042] Among them, the flow table index cache is exhausted, which may refer to the remaining number of free flow tables corresponding to the free flow table index values ​​in the cache corresponding to each CPU core being less than a preset number, that is, the remaining number of free flow tables corresponding to the free flow table index values ​​in the flow table index cache cannot satisfy the continued storage of traffic information. Locking the flow table memory pool may refer to protecting the flow table memory pool so that subsequent operation processes are not affected by other CPUs.

[0043] In an optional implementation of an embodiment of the present invention, if it is detected that the flow table index cache is exhausted, the flow table memory pool is locked, including: if it is detected that the number of free flow table index values ​​in the flow table index cache is less than 1, the flow table memory pool is locked by an atomic lock. Specifically, when the number of free flow table index values ​​in the flow table index cache is less than 1, it proves that the free flow table corresponding to the free flow table index value is exhausted, and the flow table memory pool needs to be locked by an atomic lock so that the subsequent operation process is not affected by other CPUs.

[0044] S130: Apply for a set number of free flow tables from the flow table memory pool, add the index values ​​of the free flow tables to the flow table index buffer, and unlock the flow table memory pool.

[0045] Among them, the flow table memory pool can be used to store each flow table linearly, such as Figure 1c The figure shows a schematic diagram of linear storage of a flow table, wherein Flow-entry may refer to a small memory block for storing information of each flow. The set number may refer to the size of the free flow table memory pool set according to the actual application, for example, 5K, 10K or 20K, which is not limited in the embodiment of the present invention. Unlocking may refer to removing the protection of the flow table memory pool by the atomic lock.

[0046] Specifically, when it is detected that the idle flow table corresponding to the idle flow table index value is exhausted, the flow table memory pool is locked by using an atomic lock and a batch of idle flow tables are re-applied from the flow table memory pool, and then the index values ​​of the applied idle flow tables are added to the flow table index buffer area corresponding to the current CPU core, and the flow table memory pool is unlocked. In this way, the flow table index buffer area corresponding to the CPU core can be refilled, so that the flow table creation process can be completed.

[0047] S140: Obtain an idle flow table from a flow table memory pool according to the idle flow table index value, and store the information of the new flow in the idle flow table to create a flow table.

[0048] Specifically, according to the idle flow table index value in the flow table index cache area corresponding to the CPU core, the idle flow table corresponding to the idle flow table index value in the flow table index cache area is obtained from the flow table memory pool, and the information of the new flow is stored in the above idle flow table to complete the creation of the flow table.

[0049] In an optional embodiment, after obtaining an idle flow table from the flow table memory pool according to the flow table index value and storing the information of the new flow in the idle flow table to create a flow table, it also includes: updating the flow table hash table storing the historical traffic information. Specifically, the five-tuple information of the new flow can be stored in the keyword KEY in the flow table hash table and the index value in the new flow table can be stored in the value in the flow table hash table, so as to complete the update of the historical information in the flow table hash table, so that the next time a new flow enters, the updated flow table hash table can be used to judge whether there is new flow information in the historical information of the traffic.

[0050] The technical solution of the embodiment of the present invention detects the size of the flow table index cache area corresponding to the current central processing unit CPU core when a new flow that has not been stored appears, and locks the flow table memory pool when the flow table index cache area is exhausted, and then adds the index values ​​of a set number of idle flow tables applied from the flow table memory pool to the flow table index cache area, and unlocks the flow table memory pool, and then obtains the idle flow table from the flow table memory pool according to the idle flow table index value and stores the information of the new flow in the idle flow table to create a flow table. This solves the problem of decreased flow table creation performance caused by large flow table specifications, frequent creation, and a large number of CPU cores, and improves the flow table creation performance in a multi-core environment, large flow table specifications, and a large number of CPU cores.

[0051] Figure 2a A flow chart of a flow table creation method provided by an embodiment of the present invention, Figure 2b A structural diagram of a flow table creation method provided for an embodiment of the present invention. In this embodiment, optionally, the method further includes: applying for a flow table memory pool according to the flow table specification; initializing the flow table hash table according to the flow table specification; initializing the atomic lock; allocating cache memory to each CPU core according to the number of CPU cores bound to the application software, and adding the applied preset number of flow table index values ​​in the flow table index cache corresponding to the CPU core.

[0052] Optionally, a flow table memory pool is applied for according to the flow table specifications, including: applying for the size of the flow table memory pool according to the size of the flow table specifications that can be accommodated in the configuration file and the device memory.

[0053] Optionally, initializing the flow table hash table according to the flow table specification includes: setting the size of the flow table hash table according to the flow table specification so that the size of the flow table hash table is larger than the size of the flow table specification.

[0054] like Figure 2a As shown, a flow table creation method provided by an embodiment of the present invention includes the following specific steps:

[0055] S210: Apply for a flow table memory pool according to the flow table specifications.

[0056] Optionally, a flow table memory pool is applied for according to the flow table specifications, including: applying for the size of the flow table memory pool according to the size of the flow table specifications that can be accommodated in the configuration file and the device memory. For example, if the configuration file indicates that a maximum of one thousand flow tables can be configured, then the flow table specification is one thousand. At the same time, the device memory needs to be considered so that the size of the flow table memory pool applied for is sufficient to meet the flow table specification requirements. Specifically, if the device memory is 100G, and the configuration file indicates that a maximum of one thousand flow tables can be configured, and each flow table occupies 5 bytes, then one thousand flow tables require 1000*5 bytes. The above device memory of 100G meets the requirements. Therefore, a flow table memory pool that can accommodate 1000*5 bytes can be applied for, so as to reduce the waste of memory resources on the basis of meeting the flow table specifications.

[0057] S220: Initialize the flow table hash table according to the flow table specification.

[0058] Optionally, the flow table hash table is initialized according to the flow table specification, including: setting the size of the flow table hash table according to the flow table specification so that the size of the flow table hash table is larger than the size of the flow table specification. Since the value index value of the flow table is stored in the flow table hash table, if the specification of the flow table hash table is smaller than the flow table specification, some value index values ​​of the flow table cannot be stored, and hash conflicts are likely to occur, affecting the performance of creating a new flow table. Therefore, the specification of the flow table hash table needs to be larger than the flow table specification so that the flow table creation process can proceed smoothly.

[0059] S230: Initialize the atomic lock.

[0060] Among them, initializing the atomic lock may refer to setting the atomic lock according to the usage requirements, that is, indicating the properties of the atomic lock. When multiple CPU cores apply for free flow tables from the memory pool at the same time, multiple CPU cores may write to the same memory address at the same time. Therefore, it is necessary to use an atomic lock to avoid the problem of multiple cores operating the same memory at the same time, causing errors in the information stored in the memory.

[0061] S240: Allocate cache memory to each CPU core according to the number of CPU cores bound to the application software, and add the preset number of flow table index values ​​applied for in the flow table index cache area corresponding to the CPU core.

[0062] Among them, the number of CPU cores bound to the application software operation may refer to the number of CPU cores used displayed in the configuration file when the program is running. The preset number of flow table index values ​​may refer to the optimal number of flow table index value applications obtained through experimental testing, so that the flow table creation performance will not be reduced during the flow table creation process. Specifically, by obtaining the number of CPU cores when the program is running, a respective flow table index cache area can be set for each CPU core, and then the preset number of flow table index values ​​can be added to the corresponding flow table index cache area, so that each CPU will not be affected by other CPUs when creating a flow table, thereby improving the performance of flow table creation.

[0063] S250: When a new flow is detected, if the information of the new flow does not exist in the flow table hash table used to store traffic history information, the number of free flow table index values ​​in the flow table index cache corresponding to the current CPU core is detected.

[0064] S260: If it is detected that the number of free flow table index values ​​in the flow table index cache is less than 1, the flow table memory pool is locked by an atomic lock.

[0065] S270: Apply for a set number of free flow tables from the flow table memory pool, add the index values ​​of the free flow tables to the flow table index buffer, and unlock the flow table memory pool.

[0066] S280: Obtain an idle flow table from a flow table memory pool according to the idle flow table index value, and store the information of the new flow in the idle flow table to create a flow table.

[0067] The technical solution of this embodiment is to add a flow table module initialization process before the flow table creation process and allocate memory occupied by the flow table index cache area to each CPU core and add a preset number of idle flow table index values ​​applied for in the corresponding flow table index cache area. When a new flow appears, the hash table storing the traffic history information is queried to see whether it contains the new flow information. If the new flow information is not contained, the size of the flow table index cache area corresponding to the current CPU core is detected, and when the number of idle flow table index values ​​is less than 1, the number of idle index values ​​in the flow table index cache area is expanded, so that the flow table creation process can continue. This solves the problem of decreased flow table creation performance caused by large flow table specifications, frequent creation, and a large number of CPU cores, and improves the flow table creation performance in a multi-core environment, large flow table specifications, and a large number of CPU cores.

[0068] Figure 3 A flowchart of a preferred flow table creation method provided for an embodiment of the present invention. In this embodiment, optionally, the method further includes: if it is detected that the number of idle flow table index values ​​in the flow table index cache is greater than or equal to 1, obtaining the idle flow table index value from the flow table index cache, and determining the target idle flow table from the flow table memory pool according to the obtained idle flow table index value, and storing the information of the new flow in the target idle flow table.

[0069] like Figure 3 As shown, a flow table creation method provided by an embodiment of the present invention includes the following specific steps:

[0070] S310: Apply for the size of the flow table memory pool according to the size of the flow table specification that can be accommodated in the configuration file and the device memory.

[0071] S320: Setting the size of the flow table hash table according to the flow table specification so that the size of the flow table hash table is larger than the size of the flow table specification.

[0072] S330: Initialize the atomic lock.

[0073] S340: Allocate cache memory to each CPU core according to the number of CPU cores bound to the application software, and add the preset number of flow table index values ​​applied for in the flow table index cache area corresponding to the CPU core.

[0074] S350: When a new flow is detected, if the information of the new flow does not exist in the flow table hash table used to store traffic history information, the number of free flow table index values ​​in the flow table index cache corresponding to the current CPU core is detected.

[0075] S360: Determine whether the number of free flow table index values ​​in the flow table index cache is less than 1. If so, execute S370; if not, execute S390.

[0076] S370: Lock the flow table memory pool through an atomic lock.

[0077] S380: Apply for a set number of free flow tables from the flow table memory pool, add the index values ​​of the free flow tables to the flow table index buffer, and unlock the flow table memory pool.

[0078] S390: Obtain an idle flow table index value from the flow table index cache, determine a target idle flow table from the flow table memory pool according to the obtained idle flow table index value, and store the information of the new flow in the target idle flow table.

[0079] The target idle flow table may refer to an idle flow table corresponding to the idle flow table index value obtained in the flow table index buffer.

[0080] S3100: Update the flow table hash table storing the traffic history information.

[0081] The technical solution of this embodiment is to add a flow table module initialization process before the flow table creation process and allocate memory occupied by the flow table index cache area to each CPU core and add a preset number of idle flow table index values ​​applied for in the corresponding flow table index cache area. When a new flow appears, it is queried in the hash table storing the traffic history information whether it contains the new flow information. If it does not contain the new flow information, the size of the flow table index cache area corresponding to the current CPU core is detected, and when the number of idle flow table index values ​​is less than 1, the number of idle index values ​​in the flow table index cache area is expanded, and then the flow table is created, so that the flow table creation process can continue; when the number of idle flow table index values ​​in the flow table index cache area is greater than or equal to 1, the flow table creation process is directly performed, which solves the problem of decreased flow table creation performance caused by large flow table specifications, frequent creation, and a large number of CPU cores, and improves the flow table creation performance in a multi-core environment, large flow table specifications, and a large number of CPU cores.

[0082] Figure 4 The schematic diagram of the structure of a flow table creation device provided in an embodiment of the present invention is a flow table creation device that can execute the flow table creation method involved in the above embodiments. The device can be implemented in software and / or hardware, such as Figure 4 As shown, the flow table creation device specifically includes: an idle flow table detection module 410, a flow table memory pool locking module 420, an index value adding module 430, and a flow table creation module 440.

[0083] The idle flow table detection module 410 is used to detect the size of the flow table index buffer corresponding to the current CPU core when a new flow is detected and if the information of the new flow does not exist in the historical information of the flow;

[0084] A flow table memory pool locking module 420 is used to lock the flow table memory pool if it is detected that the flow table index buffer is exhausted;

[0085] An index value adding module 430, used to apply for a set number of idle flow tables from the flow table memory pool, add the index values ​​of the idle flow tables to the flow table index buffer area, and unlock the flow table memory pool;

[0086] The flow table creation module 440 is used to obtain an idle flow table from the flow table memory pool according to the idle flow table index value, and store the information of the new flow in the idle flow table to create a flow table.

[0087] The technical solution of the embodiment of the present invention detects the size of the flow table index cache area corresponding to the current central processing unit CPU core when a new flow that has not been stored appears, and locks the flow table memory pool when the flow table index cache area is exhausted, and then adds the index values ​​of a set number of idle flow tables applied from the flow table memory pool to the flow table index cache area, and unlocks the flow table memory pool, and then obtains the idle flow table from the flow table memory pool according to the idle flow table index value and stores the information of the new flow in the idle flow table to create a flow table. This solves the problem of decreased flow table creation performance caused by large flow table specifications, frequent creation, and a large number of CPU cores, and improves the flow table creation performance in a multi-core environment, large flow table specifications, and a large number of CPU cores.

[0088] Optionally, the idle flow table detection module 410 may be specifically used to detect the number of idle flow table index values ​​in the flow table index cache corresponding to the current CPU core if the information of the new flow does not exist in the flow table hash table used to store the traffic history information;

[0089] Correspondingly, the flow table memory pool locking module 420 can be specifically used to lock the flow table memory pool through an atomic lock if it is detected that the number of free flow table index values ​​in the flow table index cache is less than 1.

[0090] Optionally, the flow table creation device may also include an initialization module, which is used to apply for a flow table memory pool according to the flow table specifications; initialize the flow table hash table according to the flow table specifications; initialize the atomic lock; allocate cache memory to each CPU core according to the number of CPU cores bound to the application software, and add a preset number of applied flow table index values ​​in the flow table index cache area corresponding to the CPU core.

[0091] Optionally, the flow table creation device may also include an index value judgment module, which is used to obtain the idle flow table index value from the flow table index cache area if it is detected that the number of idle flow table index values ​​in the flow table index cache area is greater than or equal to 1, and determine the target idle flow table from the flow table memory pool based on the obtained idle flow table index value, and store the information of the new flow in the target idle flow table.

[0092] Optionally, the initialization module may include a flow table memory pool specification application unit, which is used to apply for the size of the flow table memory pool according to the size of the flow table specification that can be accommodated in the configuration file and the device memory.

[0093] Optionally, the flow table creation device may also include a flow table hash table update module, which is used to update the flow table hash table storing traffic history information after obtaining an idle flow table from the flow table memory pool according to the flow table index value and storing the information of the new flow in the idle flow table to create the flow table.

[0094] Optionally, the initialization module may further include a flow table hash table specification setting unit, which is used to set the size of the flow table hash table according to the flow table specification, so that the size of the flow table hash table is larger than the size of the flow table specification.

[0095] The flow table creation device provided in the embodiment of the present invention can execute the flow table creation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0096] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention is shown in FIG. Figure 5 As shown, the computer device includes a processor 510, a memory 520, an input device 530, and an output device 540; the number of the processor 510 in the computer device can be one or more. Figure 5 A processor 510 is taken as an example; the processor 510, the memory 520, the input device 530 and the output device 540 in the computer device can be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.

[0097] The memory 520, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the flow table creation method in the embodiment of the present invention (for example, the idle flow table detection module 410, the flow table memory pool locking module 420, the index value adding module 430 and the flow table creation module 440 in the flow table creation device). The processor 510 executes various functional applications and data processing of the computer device by running the software programs, instructions and modules stored in the memory 520, that is, implements the above-mentioned flow table creation method.

[0098] The memory 520 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal, etc. In addition, the memory 520 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 520 may further include a memory remotely arranged relative to the processor 510, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0099] The input device 530 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the computer device. The output device 540 may include a display device such as a display screen.

[0100] An embodiment of the present invention further provides a storage medium containing computer executable instructions, wherein the computer executable instructions are used to execute a flow table creation method when executed by a computer processor, the method comprising:

[0101] When a new flow is detected, if the information of the new flow does not exist in the historical information of the flow, the size of the flow table index buffer corresponding to the current CPU core is detected;

[0102] If it is detected that the flow table index cache is exhausted, the flow table memory pool is locked;

[0103] Apply for a set number of idle flow tables from the flow table memory pool, add the index values ​​of the idle flow tables to the flow table index buffer, and unlock the flow table memory pool;

[0104] An idle flow table is obtained from a flow table memory pool according to the idle flow table index value, and information of the new flow is stored in the idle flow table to create a flow table.

[0105] Of course, the computer executable instructions of a storage medium containing computer executable instructions provided in an embodiment of the present invention are not limited to the operations of the method described above, and can also execute related operations in the flow table creation method provided in any embodiment of the present invention.

[0106] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0107] It is worth noting that in the embodiment of the above-mentioned flow table creation device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.

[0108] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A flow table creation method, characterized in that: include: When a new flow is detected, if the new flow information does not exist in the historical flow information, The size of the flow table index buffer corresponding to the front central processing unit CPU core is detected; If it is detected that the flow table index cache is exhausted, the flow table memory pool is locked; Apply for a set number of idle flow tables from the flow table memory pool, add the index values ​​of the idle flow tables to the flow table index buffer, and unlock the flow table memory pool; Obtaining an idle flow table from a flow table memory pool according to the idle flow table index value, and storing the information of the new flow in the idle flow table to create a flow table; If the information of the new flow does not exist in the historical information of the flow, detecting the size of the flow table index buffer corresponding to the current central processing unit CPU core includes: If the information of the new flow does not exist in the flow table hash table used to store the traffic history information, the number of free flow table index values ​​in the flow table index buffer corresponding to the current CPU core is detected; Correspondingly, if it is detected that the flow table index cache is exhausted, the flow table memory pool is locked, including: If it is detected that the number of free flow table index values ​​in the flow table index cache is less than 1, the flow table memory pool is locked by an atomic lock.

2. The method according to claim 1, characterized in that Also includes: Apply for a flow table memory pool based on the flow table specifications; Initializing the flow table hash table according to the flow table specification; Initializing the atomic lock; The memory occupied by the cache is allocated to each CPU core according to the number of CPU cores bound to the application software, and the preset number of flow table index values ​​applied for are added to the flow table index cache area corresponding to the CPU core.

3. The method according to claim 1, characterized in that Also includes: If it is detected that the number of idle flow table index values ​​in the flow table index cache is greater than or equal to 1, the idle flow table index value is obtained from the flow table index cache, and the target idle flow table is determined from the flow table memory pool according to the obtained idle flow table index value, and the information of the new flow is stored in the target idle flow table.

4. The method according to claim 2, characterized in that: Apply for a flow table memory pool based on the flow table specifications, including: The size of the flow table memory pool that can be accommodated in the configuration file and the device memory is used to apply for the flow table memory pool.

5. The method according to claim 1, characterized in that After obtaining an idle flow table from a flow table memory pool according to the idle flow table index value and storing the information of the new flow in the idle flow table to create a flow table, the method further includes: The flow table hash table storing the traffic history information is updated.

6. The method according to claim 2, characterized in that Initializing the flow table hash table according to the flow table specification, including: The size of the flow table hash table is set according to the flow table specification so that the size of the flow table hash table is larger than the size of the flow table specification.

7. A flow table creation device, characterized in that: include: The idle flow table detection module is used to detect the size of the flow table index buffer corresponding to the current CPU core when a new flow is detected and if the information of the new flow does not exist in the historical information of the flow; A flow table memory pool locking module, used to lock the flow table memory pool if it is detected that the flow table index buffer is exhausted; An index value adding module, used for applying for a set number of idle flow tables from the flow table memory pool, adding the index values ​​of the idle flow tables to the flow table index buffer area, and unlocking the flow table memory pool; A flow table creation module, used for obtaining an idle flow table from a flow table memory pool according to the idle flow table index value, and storing the information of the new flow in the idle flow table to create a flow table; The idle flow table detection module is specifically used to detect the number of idle flow table index values ​​in the flow table index cache area corresponding to the current CPU core if the information of the new flow does not exist in the flow table hash table used to store the traffic history information; Correspondingly, the flow table memory pool locking module is specifically used to lock the flow table memory pool through an atomic lock if it is detected that the number of free flow table index values ​​in the flow table index cache is less than 1.

8. A computer device, characterized in that: The computer device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the flow table creation method as described in any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the flow table creation method as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Quick-speed application EMS memory method

    CN101140531A

  • Method and device for managing memory pool

    CN102253897A