Hash table conflict processing and entry redistribution method and exchange chip
By using N independent hash tables and cross-mapping master-slave hash functions in the switching chip, the problem of uncertain lookup and write latency caused by hash collisions is solved, achieving efficient utilization and adaptive optimization of storage space, and reducing the probability of hash collisions and lookup latency.
Patent Information
- Application Number
- CN202611401703.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-10
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2046-09-10
AI Technical Summary
In high-concurrency scenarios, when hash collisions occur in a hash table, the lookup and write latency is uncertain, and it is difficult to optimize the layout of overflow entries in the hardware pipeline.
N independent hash tables are used, each with a primary hash function and a backup hash function. Through cross-mapping, during insertion, the primary hash function is used first to write to the primary bucket. If there is no free slot, the entry is written to the backup bucket. During lookup, a two-stage lookup is performed. If an entry in the backup storage state is found, it is migrated back to the primary bucket. The cross-mapping relationship between the primary and backup hash functions is used to migrate the entry back.
It effectively mitigates hash collisions, reduces lookup latency, improves storage space utilization, and achieves adaptive optimization of table entry layout with zero additional computational overhead, thereby reducing the probability of hash collisions.
Smart Images

Figure CN122891515B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, specifically to a method for hash table collision handling and entry redistribution, and a switching chip. Background Technology
[0002] With the rapid development of network communication technologies, especially the widespread adoption of 5G, the Internet of Things (IoT), and hyperscale data centers, the throughput and concurrent data stream scale that network devices (such as switches, routers, and security gateways) need to handle are experiencing explosive growth. In these network devices, fast, high-concurrency table lookups are a core component of packet forwarding. Common lookup tables include the Media Access Control Address Table (MAC table), the Forwarding Information Base (FIB) table, and the Flow Table. To achieve line-rate forwarding of data packets, the efficiency of table storage and lookup is crucial.
[0003] In hardware implementation, hash tables are widely used for storing and retrieving the aforementioned high-performance network table entries because they theoretically have an ultra-low lookup complexity of O(1) on average.
[0004] Typically, a hash algorithm uses one or more specific hash functions to calculate the input key, mapping it to a fixed-length index. During storage, this index serves as the physical or logical address of the storage space, and the corresponding table entry data is written to the storage space at that address. During the lookup phase, the hardware circuitry uses the same hash function to calculate the bucket index for the key to be searched, and directly retrieves the data from the storage space at that physical address.
[0005] In practical engineering implementations, the physical storage space corresponding to a hash table is usually divided into multiple buckets, each containing W fixed slots, and each slot can physically accommodate just one complete table entry.
[0006] During hash lookup, the hardware circuitry calculates the corresponding bucket index using a hash function and generates a read enable signal. Because the chip's internal memory has a wide data bus, the hardware can read all W slots of data from the bucket into an on-chip register in a single clock cycle. Subsequently, multiple hardware comparators deployed in parallel within the chip simultaneously compare the key values in these W slots with the target key value to be searched. If a match is found, a hit is declared and the corresponding data is output. This design fully utilizes the high bandwidth of on-chip static random access memory (SRAM), significantly improving lookup efficiency while ensuring timely lookup.
[0007] While the aforementioned hash table based on multi-slot buckets exhibits excellent performance, it suffers from a fatal physical flaw in real-world high-concurrency scenarios: hash collisions. A hash collision occurs when different keys, after being processed by the same hash function, yield identical index values, thus pointing to the same physical bucket. In high-performance network hardware implementations, since the number of slots in each bucket is fixed during the chip design phase, if the number of keys mapped to the same bucket exceeds the slot limit, the bucket will overflow, leading to entry write failures.
[0008] Therefore, how to effectively alleviate physical bucket collisions in hardware hash tables and improve the utilization of on-chip storage space while ensuring fast lookups is a technical problem that urgently needs to be solved in the design of high-speed network switching chips and hardware accelerator cards. Summary of the Invention
[0009] The main technical problems solved by this invention are: solving the problem of uncertain lookup and write latency when hash collisions occur in hash tables, and the problem of difficulty in optimizing the layout of overflow entries in hardware pipelines.
[0010] According to the first aspect, one embodiment provides a hash table collision handling and entry redistribution method, applicable to a switching chip containing N independent hash tables, where N≥2 and is a positive integer;
[0011] Each hash table has a primary hash function and a secondary hash function. The secondary hash function of each hash table is the primary hash function of any hash table other than the current hash table.
[0012] Each hash table includes multiple physical buckets. The physical bucket determined by the main hash function of the current hash table is the main bucket of the current hash table, and the physical bucket determined by the backup hash function of the current hash table is the backup bucket of the current hash table. Each physical bucket contains multiple slots for storing entries, and each entry is set with a status bit to identify the main storage status or the backup storage status.
[0013] The method includes:
[0014] Get the item to be inserted;
[0015] The system uses each primary hash function to search for free slots in the primary buckets corresponding to each hash table. If a free slot exists, the entry to be inserted is written into the free slot of one of the primary buckets, and the free slot of the primary bucket where the entry to be inserted is written is set to primary storage status. If no free slot exists, the system uses each backup hash function to write the entry to be inserted into the free slot of one of the backup buckets, and the free slot of the backup bucket where the entry to be inserted is written is set to backup storage status.
[0016] Retrieve the target key value to be searched;
[0017] A first-stage search is performed in the main bucket of each hash table based on the target key value. If no entry matching the target key value is found in the first-stage search, a second-stage search is performed in the spare bucket of each hash table based on the target key value to complete the search for the entry matching the target key value. The hash table that stores the entry matching the target key value is the target hash table.
[0018] If the storage status of the entry in the target hash table that matches the target key value is in the standby storage status, the entry that matches the target key value and is in the standby storage status will be determined as the hit migration entry.
[0019] The target migration hash table is determined based on the target hash table, and the primary bucket corresponding to the backup bucket storing the hit migration entry in the target migration hash table is determined as the target primary bucket.
[0020] Determine whether there is a free slot in the target main bucket. If there is a free slot, move the hit migration entry to the free slot in the target main bucket and change the storage status of the hit migration entry to the main storage status.
[0021] In one embodiment, determining the target migration hash table for migrating back the hit migration entry based on the target hash table includes:
[0022] Obtain the alternative hash function for the target hash table;
[0023] The hash table whose backup hash function is used as the primary hash function is determined as the target migration hash table.
[0024] In one embodiment, the method further includes:
[0025] Hash tables with free slots are identified as free hash tables, and the physical buckets corresponding to the free slots in the free hash tables are the target physical buckets.
[0026] The idle hash table is used to determine the hash table to be filled. It is then determined whether there is an entry in the physical bucket corresponding to the target physical bucket in the hash table to be filled. If there is an entry in the backup storage state, the entry in the backup storage state is migrated back to the target physical bucket, and the backup storage state is changed to the primary storage state.
[0027] In one embodiment, if the target physical bucket is the primary bucket, then determining the hash table to be filled based on the free hash table includes:
[0028] Obtain the main hash function of the free hash table;
[0029] The hash table whose main hash function is used as the backup hash function is determined as the hash table to be filled in;
[0030] If the target physical bucket is a spare bucket, then the hash table to be filled is determined based on the free hash table, including:
[0031] Obtain the alternative hash function for the free hash table;
[0032] The hash table whose backup hash function is used as the main hash function of the idle hash table is determined as the hash table to be filled.
[0033] In one embodiment, if the physical bucket corresponding to the target physical bucket in the hash table to be filled contains multiple entries for backup storage states, then the process is traversed according to the slot position order of the entries storing each backup storage state, and the entry for backup storage state that satisfies the preset rule is selected to be migrated back to the target physical bucket.
[0034] In one embodiment, the step of selecting entries with a preset storage state that satisfy a predefined rule and migrating them back to the target physical bucket includes:
[0035] Alternatively, the entry in the first backup storage state can be migrated back to the target physical bucket; or, the entry in the backup storage state with the longest write time can be migrated back to the target physical bucket; or, the entry in the backup storage state with the lowest access frequency can be migrated back to the target physical bucket.
[0036] In one embodiment, the first-stage lookup in the main buckets of each hash table based on the target key value includes:
[0037] The target key value is calculated using the master hash function of each hash table to determine the main bucket index;
[0038] The main bucket index is used to search the main buckets of each hash table to determine whether there is an entry in the main bucket of each hash table that matches the target key value.
[0039] In one embodiment, the second-stage lookup in the backup buckets of each hash table based on the target key value includes:
[0040] The target key value is calculated using the backup hash function of each hash table to determine the backup bucket index;
[0041] The backup bucket index is used to search the backup buckets of each hash table to determine whether there is an entry in the backup buckets of each hash table that matches the target key value.
[0042] In one embodiment, the step of performing a first-stage search in the main bucket of each hash table based on the target key value, and if no entry matching the target key value is found in the first-stage search, then performing a second-stage search in the backup bucket of each hash table based on the target key value, includes:
[0043] During the first stage of the search, N read ports are invoked to search the main bucket of each hash table in parallel. If there is no entry matching the target key value in the main bucket of each hash table, the second stage of the search is executed, and the N read ports are reused to search the backup bucket of each hash table in parallel.
[0044] or,
[0045] During the first-stage lookup, a single read port is invoked to sequentially search the main buckets of each hash table. If no entry matching the target key value is found in the main buckets of each hash table, the second-stage lookup is executed, reusing the single read port to sequentially search the backup buckets of each hash table.
[0046] In one embodiment, if the found main bucket contains multiple free slots, the system traverses the free slots according to their positional order and stores the entry to be inserted in the first free slot of each free slot, or stores the entry to be inserted in the last free slot of each free slot.
[0047] If the found backup bucket contains multiple free slots, then the bucket is traversed in the order of their positions, and the entry to be inserted is stored in the first free slot of each free slot, or the entry to be inserted is stored in the last free slot of each free slot.
[0048] In one embodiment, the backup hash function for each hash table is the main hash function of any hash table other than the current hash table, including:
[0049] The primary hash function of the i-th hash table is the backup hash function of the (i+1)-th hash table, and the primary hash function of the N-th hash table is the backup hash function of the 1-th hash table, so that the primary hash functions and backup hash functions of the N tables form a circular cross-mapping, where 1≤i<N.
[0050] According to a second aspect, one embodiment provides a switching chip, comprising:
[0051] The memory contains N independent hash tables, where N ≥ 2 and is a positive integer; each hash table has a master hash function and a backup hash function, wherein the backup hash function of each hash table is the master hash function of any hash table other than the current hash table; each hash table includes multiple physical buckets, and each physical bucket includes multiple slots for storing entries, and each entry is set with a status bit for identifying the master storage state or the backup storage state;
[0052] The interface unit is used to obtain the entry to be inserted and the target key value to be searched.
[0053] The insertion control unit is used to search for free slots in the main buckets corresponding to each hash table using each main hash function. If a free slot exists, the entry to be inserted is written into the free slot of one of the main buckets, and the free slot of the main bucket where the entry to be inserted is written is set to the main storage state. If no free slot exists, the entry to be inserted is written into the free slot of one of the backup buckets using each backup hash function, and the free slot of the backup bucket where the entry to be inserted is written is set to the backup storage state.
[0054] The lookup control unit is used to perform a first-stage lookup in the main bucket of each hash table according to the target key value. If no entry matching the target key value is found in the first-stage lookup, a second-stage lookup is performed in the spare bucket of each hash table according to the target key value to complete the lookup of the entry matching the target key value. The hash table that stores the entry matching the target key value is the target hash table.
[0055] A migration control unit is configured to, when the storage status of an entry matching the target key value in the target hash table is a standby storage status, determine the entry matching the target key value in the standby storage status as a hit migration entry; and determine a target migration hash table for migrating the hit migration entry according to the target hash table, and determine the primary bucket corresponding to the standby bucket storing the hit migration entry in the target migration hash table as the target primary bucket;
[0056] The transfer control unit is used to determine whether there is a free slot in the target main bucket. If there is a free slot, the hit migration entry is moved to the free slot in the target main bucket, and the storage status of the hit migration entry is changed to the main storage status.
[0057] According to the hash table collision handling and entry redistribution method and switching chip in the above embodiments, the method is implemented based on N independent hash tables. Each hash table has a primary hash function and a backup hash function, and the primary and backup hash functions of each hash table form a cross-mapping. When an entry to be inserted is received, the primary hash function is used first to search for a free slot in the corresponding primary bucket of each hash table. If a free slot exists, the entry to be inserted is written to the free slot of one of the primary buckets, and that slot is set to primary storage status. If no primary bucket has a free slot, the backup hash function is used to write the entry to be inserted to the free slot of one of the backup buckets, and that slot is set to backup storage status.
[0058] After the table entry insertion is completed, during the table entry lookup process, the target key value to be searched is obtained. The first-stage lookup is performed using the primary hash function in the primary bucket corresponding to each hash table. If no match is found, the second-stage lookup is performed using the backup hash function in the backup bucket corresponding to each hash table to determine the target hash table. If the entry that is found in the second-stage lookup is in backup storage state, the entry is identified as a hit migration entry, and the target migration hash table corresponding to the hit migration entry and the target primary bucket corresponding to the hit migration entry in the target migration hash table are determined. If there is a free slot in the target primary bucket, the hit migration entry is moved to the free slot in the target primary bucket, and the storage state of the free slot is changed to primary storage state.
[0059] Therefore, this application utilizes N independent hash tables and a cross-mapping relationship between the primary and backup hash functions to ensure that each hash table has multiple optional storage locations, thereby avoiding hash collisions and the latency jitter caused by hash collision handling. Furthermore, this application leverages the symmetric cross-mapping relationship between the primary and backup hash functions, eliminating the need to recalculate hash values during active migration. Location and migration can be completed directly using only the current bucket index and status bit, resulting in virtually zero hardware overhead and control timing. The two-stage lookup and the migration during the second-stage lookup ensure that entries are moved towards the primary bucket as much as possible, guaranteeing that the vast majority of subsequent searches will directly hit the target in the first stage, significantly reducing search latency. Simultaneously, the cross-mapping increases the number of candidate storage buckets, thereby significantly reducing the probability of hash collisions. Attached Figure Description
[0060] Figure 1 This is a schematic diagram of the structure of a switching chip according to one embodiment;
[0061] Figure 2 A flowchart illustrating the steps of a hash table collision handling and entry redistribution method according to one embodiment;
[0062] Figure 3This is a flowchart illustrating step S110 in a hash table collision handling and entry redistribution method according to one embodiment.
[0063] Figure 4 A flowchart illustrating a method for inserting an entry to be inserted, according to one embodiment;
[0064] Figure 5 This is a flowchart illustrating step S120 in a hash table collision handling and entry redistribution method according to one embodiment.
[0065] Figure 6 This is a flowchart illustrating a method for searching a key value according to one embodiment.
[0066] Figure 7 This is a flowchart of an active migration method according to one embodiment;
[0067] Figure 8 This is a schematic diagram of an embodiment where N=2;
[0068] Figure 9 This is a flowchart of a passive transfer method according to one embodiment;
[0069] Figure 10 This is a schematic diagram of insertion when N=2 in one embodiment;
[0070] Figure 11 This is a schematic diagram illustrating the search process when N=2 in one embodiment;
[0071] Figure 12 This is a schematic diagram of passive migration with N=2 in one embodiment.
[0072] Label Explanation: 1-Switching chip, 11-Memory, 12-Interface unit, 13-Insert control unit, 14-Search control unit, 15-Return control unit, 16-Transfer control unit. Detailed Implementation
[0073] The present invention will now be described in further detail with reference to specific embodiments and accompanying drawings. Similar elements in different embodiments are referred to by associated similar element reference numerals. In the following embodiments, many details are described to facilitate a better understanding of the invention. However, those skilled in the art will readily recognize that some features may be omitted in different situations, or may be replaced by other elements, materials, or methods. In some cases, certain operations related to the present invention are not shown or described in the specification. This is to avoid obscuring the core parts of the invention with excessive description. For those skilled in the art, detailed description of these related operations is not necessary; they can fully understand the related operations based on the description in the specification and general technical knowledge in the art.
[0074] Furthermore, the features, operations, or characteristics described in the specification can be combined in any suitable manner to form various embodiments. At the same time, the steps or actions in the method description can be rearranged or adjusted in a manner obvious to those skilled in the art. Therefore, the various orders in the specification and drawings are only for the clear description of a particular embodiment and do not imply a necessary order, unless otherwise stated that a particular order must be followed.
[0075] The serial numbers assigned to components in this document, such as "first" and "second," are used only to distinguish the described objects and have no sequential or technical meaning. The terms "connection" and "linkage" used in this invention, unless otherwise specified, include both direct and indirect connections (linkages).
[0076] To make the objectives, technical solutions, and advantages of this invention clearer, the overall design concept, hardware topology, and control logic of this application are described below in conjunction with specific hardware implementation architecture, network chip design constraints, and data processing flow.
[0077] In high-performance network switching chips and network processors, hardware pipelines have stringent requirements for deterministic latency and line-rate throughput in table lookup and update operations. However, when designing high-speed hardware lookup engines, since hash collisions cannot be physically avoided, reducing the probability of collisions and resolving collisions during insertion has been a long-standing challenge in the field of chip design.
[0078] To address the conflict, several different technical implementation methods exist in existing system designs, but when implemented in hardware, they all face irreconcilable resource, timing, or power consumption issues.
[0079] In some conventional technical solutions, a dual-hash table architecture is used to increase candidate positions. This architecture configures two physically independent storage spaces (Table 1 and Table 2) and uses independent hash functions F1 and F2, respectively. When a key is input, the system needs to compute F1(Key) and F2(Key) in parallel. During a lookup, read accesses must be performed simultaneously on the F1(Key) address in Table 1 and the F2(Key) address in Table 2. This means that to increase the number of candidate positions from 1×X (where X is the number of bits in a single table's bucket) to 2×X, the chip must simultaneously activate the read ports of both memories and deploy 2×X hardware comparators for parallel key-value comparisons. If the number of candidate buckets is further expanded to d (d≥3) to reduce collisions, the number of read ports, hash calculation engines, on-chip wiring, and hardware comparators will increase linearly by a factor of d. In chip designs where on-chip space is extremely valuable, this space-for-collision-rate tradeoff method leads to greater power consumption and area overhead, and may even cause timing non-convergence.
[0080] Another strategy is to use the Cuckoo hashing scheme, which provides two candidate buckets for each key-value pair. When both candidate buckets are full, space is freed up by recursively kicking out existing entries. In the event of multi-level collisions, the system needs to kick out the entry in the current slot and move it to its spare address; if the spare address is also full, the recursive kicking out must continue. This causes a normal write operation to potentially evolve into multiple serial read-modify-write loops, with worst-case latency being completely unpredictable. To prevent the kicking process from getting stuck in an infinite loop, the hardware must be designed with complex depth counters, backtracking pointer stacks, and loop detection logic, greatly increasing the number of gate circuits and verification complexity, making it unsuitable for hardened switching pipelines with extremely high latency deterministic requirements.
[0081] Some designs add a collision resolution table or global overflow area outside the main hash table, such as using TCAM. When a collision occurs in the main table, a new entry is written to the overflow area. TCAM uses a special transistor structure, and its physical area and power consumption are much higher than ordinary SRAM of the same capacity. In large-capacity flow table scenarios, extensive use of TCAM can cause the overall cost and power consumption of the chip to run out of control. The capacity of the overflow area is usually extremely limited. Once the overflow area is full, subsequent new entries cannot be written, leading to packet loss or a sharp decline in system performance. At the same time, lookups often require additional serial or parallel access to the overflow area, increasing access latency.
[0082] In some multi-table improved designs, when a conflict occurs during the insertion of a new entry, the conflicting entry in one table is selected, and a migration chain is established using a depth-first search to move it to the corresponding backup location in another table. The length of this migration chain is unpredictable, potentially consuming dozens of clock cycles in the worst case. Each migration requires re-hashing the key value of the entry to be migrated to determine the target address. This not only necessitates an additional hash calculation module within the chip but also frequently consumes read / write bandwidth on the main lookup path. Furthermore, the hardware also needs to support complex control logic such as depth counting and backtracking selection.
[0083] Besides their respective physical or logical limitations, all the existing solutions share a common systemic flaw: the inability to adaptively optimize table entry storage. In actual network operation, entries stored in hash tables are aged out or actively deleted by software, freeing up new idle slots. However, in the existing solutions, entries that were pushed to the spare bucket or external overflow area due to conflicts do not actively migrate back to these newly released idle slots. This forces every subsequent lookup of entries pushed to the spare bucket or external overflow area to perform a cross-table access or spare bucket retrieval, preventing them from enjoying the fast path of direct hits from the primary bucket. Simultaneously, the primary bucket becomes fragmented and idle, while the spare space or overflow area remains continuously occupied, causing the system's performance and resource distribution to deteriorate over time.
[0084] Therefore, in response to the above technical solutions, this application proposes a hash table collision handling and entry redistribution method and a switching chip, which obtains more candidate buckets without increasing hardware costs, ensures the deterministic latency of insertion and lookup, and achieves adaptive optimization of entry layout through lazy backtracking with zero additional computational overhead. The details are described below.
[0085] Please refer to Figure 1 In one embodiment, this application provides a switching chip 1, including a memory 11, an interface unit 12, an insertion control unit 13, a lookup control unit 14, a return control unit 15, and a transfer control unit 16. The various units are connected via a high-speed bus within the chip or dedicated control signal lines.
[0086] In one embodiment, the memory 11 is physically or logically divided into N independent hash tables, such as hash tables. ,in And must be a positive integer, with each hash table having an independent physical address space.
[0087] In one embodiment, each hash table The configuration has two hash calculation engines, corresponding to the main hash function F. main_i and backup hash function F sub_i Hash table The backup hash function F sub_i In hardware, it is directly bound to any hash table other than the current hash table. The main hash function, that is:
[0088] F sub_i =F main_j
[0089] Among them, F sub_i Hash table The backup hash function, F main_jHash table The main hash function.
[0090] In one embodiment, N hash tables can also form a ring topology, then the hash function F of hash table Ti is... sub_i It is hardware-bound to a hash table. The main hash function, that is:
[0091] F sub_i =F main_i+1
[0092] Among them, F sub_i Hash table The backup hash function, F main_i+1 Hash table The main hash function.
[0093] In one embodiment, each hash table is divided into multiple physical buckets. The physical bucket determined by the master hash function of each hash table is the master bucket of its own hash table, and the physical bucket determined by the backup hash function of each hash table is the backup bucket of its own hash table. That is, each hash table is divided into multiple master buckets and multiple backup buckets. Each physical bucket contains a fixed number of slots for storing entries in parallel.
[0094] In one embodiment, in each entry, the switching chip 1 is provided with a 1-bit status bit for distinguishing the storage state of the entry. When the 1-bit status bit is marked with a first value (e.g., 0), it indicates that the entry is the main storage state calculated by the main hash function and written to the corresponding main bucket; when the 1-bit status bit is marked with a second value (e.g., 1), it indicates that the entry is the backup storage state calculated by the backup hash function and written to the corresponding backup bucket.
[0095] It should be noted that, in terms of physical hardware implementation, the 1-bit status bit can be directly allocated as an additional 1-bit physical storage medium in each slot of memory 11, and read and written along with the table entry. Alternatively, in a pointer-addressable or chained memory structure, the 1-bit status bit can be implicitly marked using the least significant bit of the table entry address pointer. Furthermore, the 1-bit status bit can be implemented in a dedicated bitmap storage area within memory 11, independent of the data slot area, where each bit corresponds one-to-one with each slot in the hash table. When accessing a target slot, the bit value at the corresponding index position in the dedicated bitmap storage area is read synchronously to determine the primary / backup storage status of that target slot. Additionally, when a slot stores a signature value for fast comparison, the 1-bit status bit is directly encoded and embedded in a preset reserved bit of the signature value.
[0096] Through the aforementioned storage structure design, this application achieves a minimal increase in hardware cost. The switching chip 1 only requires adding 1 bit of status bit in each slot (for a hash table with millions of entries, the additional storage overhead is less than 0.12 MB), and this 1 bit of status bit supports implicit storage in various flexible forms such as pointers, dedicated bitmaps, or signature values, with negligible impact on chip hardware area and logic gate circuits.
[0097] In actual operation, the switching chip 1 provided in this application can support two business scenarios: table entry insertion and real-time lookup. The interface unit 12 serves as the unified data interaction entry point for the switching chip 1, used to obtain the entry to be inserted and the target key value to be looked up, and to distribute the corresponding data to different control units for processing according to the business type.
[0098] In one embodiment, when performing a table entry insertion service, the interface unit 12 receives an external configuration instruction or table entry update request, obtains the entry to be inserted and the key value to be inserted, and transmits them to the insertion control unit 13, which then performs a two-stage priority write.
[0099] In one embodiment, the insertion control unit 13 is connected to the interface unit 12 and each hash table respectively, and is used to receive the entry to be inserted and the corresponding key value to be inserted transmitted by the interface unit 12, and to perform two-stage priority writing of the entry to be inserted using the main hash function / backup hash function of each hash table.
[0100] Specifically, upon receiving an entry to be inserted, the insertion control unit 13 first uses the main hash function of each hash table to calculate the index of the key value to be inserted in each hash table, thereby determining the main bucket corresponding to each hash table, and then searches in parallel or serially whether there are any free slots in each main bucket. If there are free slots, the insertion control unit 13 writes the entry to be inserted into one of the free slots in the main bucket, and sets the storage state of the slot where the entry to be inserted is written to the main storage state.
[0101] If no free slots exist in the primary buckets corresponding to each hash table, the insertion control unit 13 uses the backup hash function of each hash table to calculate the index of the key value to be inserted in each hash table, thereby determining the backup buckets corresponding to each hash table, and searches in parallel or serially for whether there are free slots in each backup bucket. If a free slot exists, the insertion control unit 13 writes the entry to be inserted into the free slot of one of the backup buckets, and sets the storage state of the slot where the entry to be inserted is written to the backup storage state.
[0102] In one embodiment, when performing a message lookup service, the interface unit 12 receives externally transmitted data messages to be processed in real time, parses the messages according to preset message extraction rules and extracts feature fields, and combines the extracted feature fields into a target key value to be searched and transmits it to the lookup control unit 14.
[0103] In one embodiment, the lookup control unit 14 executes two stages of lookup logic. In the first stage of the lookup, the lookup control unit 14 uses the main hash function of each hash table to perform hash calculation on the target key value, generates the main bucket index of each hash table, and calls the read port in parallel to read the main buckets of all hash tables. The target key value is compared in parallel with the key values of all valid slots in each main bucket. If a match is found in a certain main bucket, the lookup success and the corresponding table entry content are returned directly, and the first stage of the lookup ends. If no match is found in any main bucket, the second stage of the lookup is triggered.
[0104] In the second phase of the search, the search control unit 14 uses the backup hash function of each hash table to perform hash calculation on the target key value, generates backup bucket indexes for each hash table, and calls the read port in parallel to read the backup buckets of all hash tables. The target key value is then compared in parallel with the key values of all valid slots in each backup bucket. If a match is found in a backup bucket, the system directly returns a successful search and the corresponding table entry, and the hash table containing the matched target key value is recorded as the target hash table.
[0105] In one embodiment, when the second-stage lookup matches a target entry in the backup bucket of the target hash table, the migration control unit 15 reads the status bit of the entry in real time. If the status bit of the entry is in backup storage status, the entry is marked as a matched migration entry. Due to the cross-mapping of the backup hash function, the migration control unit 15 determines the migration entry based on the hash table. The backup hash function is a hash table. (or hash table) The mapping relationship of the master hash function can be used to deduce the target migration hash table (i.e., hash table) for migration of the hit migration entry. Or hash table Subsequently, the migration control unit 15 identifies the primary bucket in the target migration hash table that is physically identical to the backup bucket currently storing the entry as the target primary bucket.
[0106] In one embodiment, the transfer control unit 16 reads the target master bucket and checks all slots within it to determine if there are any valid free slots. If at least one free slot exists in the target master bucket, the transfer control unit 16 initiates a write operation, writing the hit migration entry into the free slot of the target master bucket and changing its status bit from backup storage to master storage. Simultaneously, the old slot of the hit migration entry in the original backup bucket is cleared. If there are no free slots in the target master bucket, the transfer control unit 16 abandons this migration, and the hit migration entry remains stored in the original backup bucket, waiting to attempt migration again during the next search.
[0107] In summary, the switching chip 1 described in detail above constitutes the hardware architecture of the technical solution of this application. Based on this hardware architecture, this application further provides a method for hash table collision handling and entry redistribution.
[0108] It is understood that each process step, data comparison, status determination, and physical movement operation in the following method embodiments can be executed collaboratively or independently by the corresponding hardware unit in the aforementioned switching chip 1. Specifically, data acquisition and feature extraction in the method are performed by the interface unit 12, the two-stage entry insertion and lookup are performed by the insertion control unit 13 and the lookup control unit 14 in conjunction with the read port of the memory 11, the reading of status bits, the determination of entries to be migrated back, and the positioning of the target master bucket are performed by the migration control unit 15, and the determination of free slots, the writing of entries, the release of original slots, and the modification of status bits are performed by the transfer control unit 16 in conjunction with the write port of the memory 11.
[0109] To keep the specification concise, when describing specific processes in the following method embodiments, if the hardware structure already specified in the embodiment of switching chip 1 is involved, its definition and physical topology shall be consistent with those of the aforementioned embodiment of switching chip 1.
[0110] Based on the aforementioned hardware architecture of the switching chip 1, this application further provides a method for hash table collision handling and entry redistribution. The following section first discusses... The general architecture and methodology are explained, followed by... We will take a typical double hash table structure as an example to explain in detail.
[0111] In one embodiment, the method of this application operates in a topology of a switching chip 1 containing N independent hash tables. Each hash table has an independent physical address space. The configuration has two hash calculation engines, corresponding to the main hash function F. main_i and backup hash function F sub_i Hash table The backup hash function F sub_i In hardware, it is directly bound to any hash table other than the current hash table. The main hash function. Furthermore, N hash tables can also form a ring topology, then the hash table... The backup hash function F sub_i It is hardware-bound to a hash table. The main hash function F main_i+1 .
[0112] In one embodiment, each hash table is divided into multiple physical buckets. The physical bucket determined by the master hash function of each hash table is the master bucket of its own hash table, and the physical bucket determined by the backup hash function of each hash table is the backup bucket of its own hash table. That is, each hash table is divided into multiple master buckets and multiple backup buckets. Each physical bucket contains a fixed number of slots for storing entries in parallel.
[0113] In one embodiment, in each entry, the switching chip 1 is provided with a 1-bit status bit for distinguishing the storage state of the entry. When the 1-bit status bit is marked with a first value (e.g., 0), it indicates that the entry is the main storage state calculated by the main hash function and written to the corresponding main bucket; when the 1-bit status bit is marked with a second value (e.g., 1), it indicates that the entry is the backup storage state calculated by the backup hash function and written to the corresponding backup bucket.
[0114] Please refer to Figure 2 In one embodiment, the hash table collision handling and entry redistribution method provided in this application includes the following steps.
[0115] Step S110: Two-stage writing of the entry to be inserted.
[0116] Please refer to Figure 3 and Figure 4 In one embodiment, the two-stage writing of the entry to be inserted in step S110 includes the following steps.
[0117] Step S111: First-stage priority writing based on the master hash function.
[0118] In one embodiment, during the entry insertion stage, the interface unit 12 obtains the entry to be inserted and its corresponding key value to be inserted. The dedicated write control unit of the exchange chip 1 calls the main hash function and backup hash function of each hash table configured by the exchange chip 1 to calculate the key value to be inserted, and generates the insertion main bucket index and insertion backup bucket index corresponding to each hash table.
[0119] The write control unit checks the slots in all hash tables corresponding to the main buckets to be inserted based on the calculated insertion main bucket indexes. If a main bucket to be inserted has a free slot, the write control unit stores the entry to be inserted in the free slot and sets the status bit of the entry to be inserted to the main storage status, and the insertion process ends.
[0120] If a main bucket to be inserted has multiple free slots, the write control unit traverses the slots according to their physical location order and selects whether to store the item to be inserted in the first free slot or the last free slot through the priority encoder. The specific configuration can be flexibly made according to the hardware circuit.
[0121] Step S112: Second-stage sub-priority write based on the backup hash function.
[0122] In one embodiment, if there are no free slots in all the main buckets to be inserted, it indicates that a main bucket hash collision has been triggered. The write control unit checks the slots inside all the backup buckets to be inserted according to the index of each backup bucket to be inserted. If there is a free slot in a backup bucket to be inserted, the write control unit stores the entry to be inserted in the free slot and sets the status bit of the entry to be inserted to the backup storage status, and the insertion process ends.
[0123] If a certain backup bucket to be inserted has multiple free slots, the write control unit traverses according to the physical location order of each slot, and selects whether to store the entry to be inserted in the first free slot or the last free slot through the priority encoder. The specific configuration can be flexibly configured according to the hardware circuit.
[0124] If there are no free slots in all the backup buckets to be inserted, the write control unit writes the entry to be inserted into the overflow area. Relying on the cross-mapping of the hash function in this application, most entries can be inserted in the first two stages. Therefore, the probability of entering the overflow area is greatly reduced, which significantly saves the hardware area and power consumption of the chip.
[0125] For entries already stored in the overflow area, the switching chip 1 can be configured with a background scanning thread to periodically poll and scan the entries in the overflow area and re-execute the above insertion process. Once the hash table releases a free slot in the main bucket / standby bucket due to entry aging or migration, the entries in the overflow area can be moved to the corresponding hash table to further reduce the space occupied by the overflow area.
[0126] Step S120: Two-stage lookup of the target key value to be searched.
[0127] Please refer to Figure 5 and Figure 6 In one embodiment, the two-stage lookup of the target key value to be searched in step S120 includes the following steps.
[0128] Step S121: Perform the first-stage lookup for each main bucket based on the main hash function.
[0129] In one embodiment, the interface unit 12 obtains the target key value to be searched and transmits it to the search control unit 14. The search control unit 14 calculates the target key value using the master hash function corresponding to each hash table, generates the master bucket index of each hash table, and reads the master buckets of all hash tables in parallel, comparing the target key value with the entries in each slot of each master bucket. If a match is found in the master bucket of any hash table, the matching entry content is returned directly, and the first stage of the search is completed; if no match is found in the master buckets of all hash tables, the second stage of the search is triggered.
[0130] Step S122: Perform the second-stage lookup for each backup bucket based on the backup hash function.
[0131] In one embodiment, the lookup control unit 14 calculates the target key value using the backup hash function corresponding to each hash table, generates backup bucket indexes for each hash table, and reads the backup buckets in all hash tables in parallel, comparing the target key value with the entries in each slot of each backup bucket. If a match is found in any backup bucket of a hash table, the matching entry content is directly returned, the second-stage lookup is completed, and the hash table that matches the target key value is marked as the target hash table; if no match is found in any backup bucket of any hash table, a miss signal is output.
[0132] It should be noted that in the first stage search of step S121 and the second stage search of step S122, the two stages of search can be flexibly configured as parallel search mode or serial search mode according to the different requirements of the throughput and chip area / power consumption of the switching chip 1.
[0133] In scenarios with high requirements for lookup throughput and latency, the switching chip 1 is configured with N hardware read ports. During the first-stage lookup, the lookup control unit 14 calls upon the N read ports to perform single-cycle parallel reading and key-value comparison on all the main buckets of the hash tables. If all main buckets are not matched, the lookup control unit 14 reuses the N read ports in the next clock cycle to perform single-cycle parallel reading and key-value comparison on all the backup buckets of the hash tables.
[0134] by Taking a double hash table as an example, the corresponding hash tables are hash table A and hash table B:
[0135] Switch chip 1 is configured with two read ports. During the first-stage lookup, these two read ports are multiplexed to simultaneously read the main bucket of hash table A and the main bucket of hash table B within one cycle. If a miss occurs, the two read ports are reused in the second-stage lookup to simultaneously read the spare bucket of hash table A and the spare bucket of hash table B within the second cycle. In this mode, the worst-case lookup latency for a hit or miss is only two clock cycles.
[0136] In scenarios where chip area, the number of memory ports, or hardware power consumption are limited, the switching chip 1 can be configured with only one read port. During the first-stage lookup, the lookup control unit 14 utilizes this single read port to sequentially read the main buckets of each hash table for key-value comparison. If no match is found in any of the main buckets, the lookup control unit 14 continues to reuse this single read port to sequentially read the backup buckets of each hash table for key-value comparison.
[0137] by Taking a double hash table as an example, the corresponding hash tables are hash table A and hash table B:
[0138] Switch chip 1 is configured with one read port. During the first-stage lookup, this read port is used to compare key-value pairs in the order of the main bucket of hash table A and the main bucket of hash table B. If no match is found in any of the main buckets, the read port is used again in the second-stage lookup to compare key-value pairs in the order of the spare buckets of hash table A and the spare buckets of hash table B. In this mode, the worst-case lookup latency for a hit or miss is 4 clock cycles.
[0139] Step S130: Perform active migration based on the search results of the second stage.
[0140] Please refer to Figure 7 In one embodiment, during the second-stage search, if an entry corresponding to the target key value is found in the backup bucket of the target hash table, the migration control unit 15 obtains the status bit of the entry. If the status bit is in backup storage status, the entry is determined as a hit migration entry that needs to be actively migrated.
[0141] In one embodiment, in order to actively migrate the hit migration entry, the migration control unit 15 needs to calculate the destination that the hit migration entry needs to migrate to, that is, the target migration hash table.
[0142] The specific implementation logic is as follows: The migration control unit 15 first obtains the backup hash function of the target hash table that currently hits the entry. Assuming the target hash table is a table... The corresponding hash function is F. sub_x Because the hit reset entry is currently stored in F sub_x In the calculated backup bucket, according to the pre-set cross mapping, the migration control unit 15 can look up F in all hash tables. sub_x The hash table, which serves as the primary hash function, can also be more preferably determined based on the ring topology, with F as the hash function. sub_x The hash table, as the primary hash function, regardless of the method used, aims to determine the destination of the matched backtracking entry, i.e., using F... sub_x The hash table that serves as the primary hash function is the target backtracking hash table. Let's assume the hash table to be backtracked is a table... The corresponding master hash function is F. main_y .
[0143] After determining the target backhaul hash table Then, the migration control unit 15 will send the hash table to be migrated back. The primary bucket that corresponds to the current backup bucket containing the hit migration entry in terms of physical addressing (i.e., via the primary hash function F) is the same as the primary bucket in terms of physical addressing. main_y The primary bucket index obtained by calculating the target key value is determined as the target primary bucket.
[0144] In one embodiment, after determining the target migration hash table and the target main bucket, the transfer control unit 16 reads the target migration hash table and the target main bucket, detects the slots in the target main bucket, and determines whether there are any unoccupied free slots.
[0145] If there is a free slot in the target primary bucket, the transfer control unit 16 initiates a write operation to move the hit migration entry to the free slot in the target primary bucket of the target migration hash table. At the same time, the status bit of the entry is changed from backup storage status to primary storage status, and the corresponding slot in the original backup bucket is released.
[0146] If there are no free slots in the target main bucket, it means that the target main bucket of the current target migration hash table is still fully loaded. The migration control unit 16 temporarily abandons this migration, and the entry continues to be kept in the standby bucket of the current target hash table, waiting for the next standby lookup to trigger the migration attempt again.
[0147] To more intuitively understand the above process, the following diagram illustrates the process. Whether it's a hash table mapping structure where the backup hash function of each storage table is the main hash function of any storage table other than the current storage table, or a more preferable ring topology structure for the hash table, in... The execution methods for double hash tables are the same, as follows: We will use the parallel structure of a double hash table as an example for a more detailed explanation.
[0148] Please refer to Figure 8 ,exist At that time, the switching chip 1 is configured with physically independent first hash tables. Second hash table The first hash table The main hash function is For F1, prepare the hash function. F2; Second hash table Main hash function For F2, prepare the hash function. It is F1, that is, it satisfies ,and First hash table Second hash table They can be located in different banks (storage sub-modules) of the same SRAM (Static Random Access Memory) or in different physical storage units. Each hash table is divided into multiple buckets (Bucket[0]-Bucket[m]), and each bucket contains W slots (Slot(0)-Slot(W)), where W is a preset positive integer. Each slot is used to store an entry, which includes a key value (or signature), forwarding result (such as outgoing port or next hop information), and a 1-bit status bit.
[0149] For the target key value Key, the primary bucket index of the first hash table is F1(Key), and the secondary bucket index of the first hash table is F2(Key); the primary bucket index of the second hash table is F2(Key), and the secondary bucket index of the second hash table is F1(Key).
[0150] As can be seen from the above rules, a target key value can obtain four candidate bucket indices through one concurrent hash calculation: the primary bucket index of the first hash table, the backup bucket index of the first hash table, the primary bucket index of the second hash table, and the backup bucket index of the second hash table. Among them, the primary bucket index of the first hash table and the backup bucket index of the second hash table are completely equal, and the primary bucket index of the second hash table and the backup bucket index of the first hash table are completely equal, thus forming a perfect symmetrical cross-mapping relationship.
[0151] It's worth noting that through cross-mapping, the number of candidate buckets for a single target key value increases from the traditional two to four, effectively doubling the total number of candidate slots. At the same load rate, the probability of all candidate slots being full decreases exponentially, significantly reducing overflow area utilization and thus minimizing the additional latency associated with accessing the overflow area. The lookup and active migration performed at that time are as follows: In the first phase of the lookup, the primary bucket index of the first hash table and the primary bucket index of the second hash table are read simultaneously. If neither is found, the second phase of the lookup reads the backup bucket index of the first hash table and the backup bucket index of the second hash table simultaneously.
[0152] If the entry found in the second phase of the lookup in the backup bucket of the first hash table (backup bucket index F2(Key)) is in backup storage state, given the first hash table... Alternate hash function and second hash table The primary hash function is F2. The migration control unit 15 directly reuses the backup bucket index F2(Key) and sets the second hash table accordingly. The primary bucket with index F2 (Key) is determined as the target primary bucket.
[0153] If the entry found in the second-stage search of the backup bucket (backup bucket index F1(Key)) of the second hash table is in backup storage state, given the second hash table... backup hash function and first hash table The primary hash function is F1. The migration control unit 15 directly reuses the backup bucket index F1(Key) and sets the first hash table... The primary bucket with index F1(Key) is determined as the target primary bucket.
[0154] If there is a free slot in the target main bucket, the entry will be moved there and the status will be changed from backup storage status to main storage status.
[0155] Therefore, this application divides the search process into two stages: the primary bucket and the backup bucket, reusing the original read ports without adding additional hardware data paths. In parallel mode, the worst-case search latency is limited to 2 clock cycles, completely eliminating the search latency uncertainty and timing degradation problems caused by recursion in traditional Cuckoo hashing or depth-first eviction schemes, and greatly improving the chip's data throughput.
[0156] In one embodiment, the hash table collision handling and entry redistribution method provided in this application includes passive migration in addition to active migration. Unlike active migration, which is triggered in real time during lookup access, passive migration is an entry layout optimization triggered by hardware idleness when a bucket entry is deleted or aged out and frees up a slot.
[0157] Please refer to Figure 9 In one embodiment, when an entry deletion or aging release operation occurs, the migration control unit 15 detects and identifies hash tables with newly released free slots, and records them as free hash tables. Simultaneously, the physical bucket containing the free slots in the free hash table is identified as the target physical bucket.
[0158] In one embodiment, the migration control unit 15 detects the existence of a hash table containing passively migrated entries, i.e., a hash table to be filled, based on the status bit of the target physical bucket and the corresponding hash function.
[0159] If the target physical bucket is the primary bucket, then the migration control unit 15 obtains the primary hash function of the free hash table. The migration control unit 15 searches and determines the hash table that uses the primary hash function as the backup hash function, and then the hash table is the hash table to be filled.
[0160] If the target physical bucket is a spare bucket, then the migration control unit 15 obtains the spare hash function of the free hash table. The migration control unit 15 retrieves and determines the hash table that uses the spare hash function as the main hash function. Then, the hash table is the hash table to be filled.
[0161] In one embodiment, after determining the hash table to be filled, the migration control unit 15 checks the physical bucket in the hash table to be filled that is exactly the same as the target physical bucket index, and determines whether there is a valid entry in the physical bucket whose status bit is in the backup storage state.
[0162] If there are no valid entries in the backup storage state, it means that there are currently no entries waiting to be passively migrated back.
[0163] If there is a single valid entry in the backup storage state, the transfer control unit 16 will directly use that entry as the target to be migrated back to the free slot in the target physical bucket.
[0164] If multiple valid entries for backup storage states exist, the migration control unit 16 traverses the slots according to their physical arrangement and selects one entry that conforms to a preset rule for migration. The preset rule includes, but is not limited to, any of the following: The migration control unit 16 can passively migrate the first backup storage state entry read during the hardware priority encoder or physical traversal to an empty slot in the target physical bucket. Alternatively, the migration control unit 16 can passively migrate the backup storage state entry with the longest write time (or longest lifespan) in the current physical bucket to an empty slot in the target physical bucket. Or, the migration control unit 16 can passively migrate the backup storage state entry with the lowest access frequency to an empty slot in the target physical bucket.
[0165] Regardless of which backup storage state entry is selected for passive migration, after the migration is complete, the backup storage state of that entry must be changed to the primary storage state, and the old slots in the physical bucket of the original hash table to be filled must be cleared and released.
[0166] It should be noted that both the active and passive migration methods provided in this application rely on the cross-mapping of hash functions. For any key value, its backup bucket index in one table is physically identical to its primary bucket index in another corresponding table. Therefore, whether it is active or passive migration, there is no need to recalculate the hash value of the key value during the migration process. The migration can be completely located and performed solely based on the current bucket index and the status bit of the entry, reducing hardware computational overhead and control timing.
[0167] Through proactive migration during the second-stage lookup and passive migration after deletion / aging, standby storage state entries originally stored in the standby bucket due to initial hash collisions are moved to the primary bucket during operation, achieving proactive convergence of storage space. This ensures that most lookup accesses can be directly hit during the first-stage lookup, thereby locking the average lookup latency within one clock cycle.
[0168] In addition to active and passive migration, the switching chip 1 can be configured with a dedicated timer and a state machine for inspection. The timer periodically polls and triggers scanning tasks at preset time intervals. Alternatively, a traffic monitoring unit can be configured on the switching chip 1. When the traffic monitoring unit detects that the external data traffic is lower than a preset idle threshold, or when the interface unit 12 enters an idle state, the migration control unit 15 uses the chip's idle read / write ports and bus bandwidth to search and perform batch migration of entries in the backup storage state of all hash tables.
[0169] Therefore, this application utilizes a cross-symmetric relationship, eliminating the need to recalculate hash values for either active or passive migration. It directly determines the target table and target bucket index based solely on the current bucket index and status bit. The migration operation is simple, requiring only copying entries, modifying status bits, and clearing the original slots, resulting in extremely lightweight hardware implementation. Two triggering scenarios cover the main opportunities for table entry optimization, allowing migration to occur naturally. As lookups and deletions / aging occur, entries gradually migrate from the backup bucket to the primary bucket, leading to an optimal table entry distribution. After long-term operation, the vast majority of entries reside in the primary bucket, and lookups almost always hit in the first stage, achieving steady-state optimal performance for swap chip 1. This optimization process requires no software intervention and is entirely automated by hardware.
[0170] It should be noted that in scenarios where chips operate concurrently, both active and passive migrations may occur concurrently with entry lookups or insertions. To ensure data consistency and correctness during cross-table physical migrations, this application, in its preferred hardware architecture, physically stores different hash tables in independent storage sub-modules of static random access memory (SRAM). Since the original and target slots involved in each migration belong to different hash tables, the release of the original slot and the writing of the target slot operate on two completely independent storage sub-modules. This physically isolated architecture completely eliminates write conflicts within the same SRAM storage sub-module from a hardware perspective.
[0171] In some low-cost or highly integrated chip designs, if each hash table is set in a different storage partition of the same storage submodule, when a migration is triggered, the relocation control unit 16 sets a short-term lock signal on the original physical bucket and the target physical bucket involved. During the lock period, if there is a concurrent lookup or insert request to access the locked physical bucket, the concurrent request is temporarily stored or delayed for 1 clock cycle.
[0172] Therefore, the entry insertion process provided in this application involves no kick-outs or recursive shifts, checks a maximum of 2N buckets, and writes to the overflow area if all are full. Each bucket is checked by comparing a fixed number of slots in parallel, thus the insertion time can be precisely predicted, making it suitable for the pipeline design of the switching chip 1. This avoids the pipeline stalls or packet loss risks caused by excessively long kick-out chains in Cuckoo hashing.
[0173] Please refer to Figure 10 The following is an explanation of entry insertion using a specific example.
[0174] by Taking a double hash table as an example, the primary hash function of the first hash table is Fa, and the secondary hash function is Fb; the primary hash function of the second hash table is Fb, and the secondary hash function is Fa.
[0175] Suppose we need to insert key100 now, follow these steps in sequence:
[0176] Calculate Fa(key100) and Fb(key100) to obtain the main bucket index of the first hash table as Bucket[i] and the main bucket index of the second hash table as Bucket[j]. After traversing, it is found that all slots in the main buckets of both hash tables are not empty, so the backup buckets of the two hash tables are searched, namely Bucket[j] of the first hash table and Bucket[i] of the second hash table. It is found that Bucket[j] of the first hash table has an empty slot, so key100 or its signature data and complete data are marked as being in backup storage status and inserted into that slot.
[0177] Please refer to Figure 11 The following is an explanation of entry lookup using a specific example.
[0178] Similarly Taking a double hash table as an example, the primary hash function of the first hash table is Fa, and the secondary hash function is Fb; the primary hash function of the second hash table is Fb, and the secondary hash function is Fa.
[0179] Suppose we need to find key100, we would follow these steps:
[0180] Calculate Fa(key100) and Fb(key100) to obtain the primary bucket index of the first hash table as Bucket[i] and the primary bucket index of the second hash table as Bucket[j]. Perform parallel comparisons of key100 with the entries stored in each slot of the primary buckets of both hash tables, assuming no match is found. Then, perform parallel comparisons of key100 with the entries stored in each slot of the backup buckets of both hash tables, i.e., Bucket[j] of the first hash table and Bucket[i] of the second hash table. Find that the second entry in Bucket[j] of the first hash table matches, and return the result. Search for any free slots in Bucket[j] of the second hash table. Assuming there are free slots, copy the matched entry, change the backup storage state to the primary storage state, directly insert it into the free slot of Bucket[j] of the second hash table, and delete or mark the corresponding slot of Bucket[j] of the second hash table as empty.
[0181] Please refer to Figure 12 The passive migration will be explained with a specific example.
[0182] Similarly Taking a double hash table as an example, the primary hash function of the first hash table is Fa, and the secondary hash function is Fb; the primary hash function of the second hash table is Fb, and the secondary hash function is Fa.
[0183] Suppose an entry is now deleted or expired, perform the following steps in sequence:
[0184] Suppose that Bucket[j] of the second hash table releases a slot. Check if there is an entry marked as being in standby storage state in Bucket[j] of the first hash table. If not, end the process. Suppose that there is an entry key200 marked as being in standby storage state in Bucket[j] of the first hash table. Copy the entry and modify it to be in primary storage state. Then, insert it directly into the released slot in Bucket[j] of the second hash table. Delete or mark the source slot in Bucket[j] of the first hash table as empty.
[0185] This document describes various exemplary embodiments with reference to them. However, those skilled in the art will recognize that changes and modifications can be made to the exemplary embodiments without departing from the scope of this document. For example, various operational steps and components for performing operational steps can be implemented in different ways depending on the specific application or considering any number of cost functions associated with the operation of the system (e.g., one or more steps can be deleted, modified, or combined with other steps).
[0186] While the principles herein have been illustrated in various embodiments, numerous modifications to the structures, arrangements, proportions, elements, materials, and components, particularly suited to specific environments and operational requirements, may be used without departing from the principles and scope of this disclosure. These modifications and other alterations or alterations will be included within the scope of this document. Those skilled in the art will recognize that many changes can be made to the details of the above embodiments without departing from the fundamental principles of the invention.
Claims
1. A method for hash table collision handling and entry redistribution, characterized in that, Suitable for exchange chips containing N independent hash tables, where N≥2 and are positive integers; Each hash table has a primary hash function and a secondary hash function. The secondary hash function of each hash table is the primary hash function of any hash table other than the current hash table. Each hash table includes multiple physical buckets. The physical bucket determined by the main hash function of the current hash table is the main bucket of the current hash table, and the physical bucket determined by the backup hash function of the current hash table is the backup bucket of the current hash table. Each physical bucket contains multiple slots for storing entries, and each entry is set with a status bit to identify the main storage status or the backup storage status. The method includes: Get the item to be inserted; The system uses each primary hash function to search for free slots in the primary buckets corresponding to each hash table. If a free slot exists, the entry to be inserted is written into the free slot of one of the primary buckets, and the free slot of the primary bucket where the entry to be inserted is written is set to primary storage status. If no free slot exists, the system uses each backup hash function to write the entry to be inserted into the free slot of one of the backup buckets, and the free slot of the backup bucket where the entry to be inserted is written is set to backup storage status. Retrieve the target key value to be searched; A first-stage search is performed in the main bucket of each hash table based on the target key value. If no entry matching the target key value is found in the first-stage search, a second-stage search is performed in the spare bucket of each hash table based on the target key value to complete the search for the entry matching the target key value. The hash table that stores the entry matching the target key value is the target hash table. If the storage status of the entry in the target hash table that matches the target key value is in the standby storage status, the entry that matches the target key value and is in the standby storage status will be determined as the hit migration entry. The target migration hash table is determined based on the target hash table, and the primary bucket corresponding to the backup bucket storing the hit migration entry in the target migration hash table is determined as the target primary bucket. Determine whether there is a free slot in the target main bucket. If there is a free slot, move the hit migration entry to the free slot in the target main bucket and change the storage status of the hit migration entry to the main storage status.
2. The hash table collision handling and entry redistribution method as described in claim 1, characterized in that, The step of determining the target migration hash table for migrating back the hit migration entry based on the target hash table includes: Obtain the alternative hash function for the target hash table; The hash table whose backup hash function is used as the primary hash function is determined as the target migration hash table.
3. The hash table collision handling and entry redistribution method as described in claim 1, characterized in that, The method further includes: Hash tables with free slots are identified as free hash tables, and the physical buckets corresponding to the free slots in the free hash tables are the target physical buckets. The idle hash table is used to determine the hash table to be filled. It is then determined whether there is an entry in the physical bucket corresponding to the target physical bucket in the hash table to be filled. If there is an entry in the backup storage state, the entry in the backup storage state is migrated back to the target physical bucket, and the backup storage state is changed to the primary storage state.
4. The hash table collision handling and entry redistribution method as described in claim 3, characterized in that, If the target physical bucket is the primary bucket, then the hash table to be filled in is determined based on the free hash table, including: Obtain the main hash function of the free hash table; The hash table whose main hash function is used as the backup hash function is determined as the hash table to be filled in; If the target physical bucket is a spare bucket, then the hash table to be filled is determined based on the free hash table, including: Obtain the alternative hash function for the free hash table; The hash table whose backup hash function is used as the main hash function of the idle hash table is determined as the hash table to be filled.
5. The hash table collision handling and entry redistribution method as described in claim 3, characterized in that, If the physical bucket corresponding to the target physical bucket in the hash table to be filled contains multiple entries for backup storage states, then the entries for backup storage states that satisfy the preset rules are selected and migrated back to the target physical bucket.
6. The hash table collision handling and entry redistribution method as described in claim 5, characterized in that, The process of selecting entries with a preset storage state that satisfy a predefined rule and migrating them back to the target physical bucket includes: Alternatively, the entry in the first backup storage state can be migrated back to the target physical bucket; or, the entry in the backup storage state with the longest write time can be migrated back to the target physical bucket; or, the entry in the backup storage state with the lowest access frequency can be migrated back to the target physical bucket.
7. The hash table collision handling and entry redistribution method as described in claim 1, characterized in that, The first-stage lookup in the main bucket of each hash table based on the target key value includes: The target key value is calculated using the master hash function of each hash table to determine the main bucket index; The main bucket index is used to search the main buckets of each hash table to determine whether there is an entry in the main bucket of each hash table that matches the target key value.
8. The hash table collision handling and entry redistribution method as described in claim 7, characterized in that, The second-stage lookup in the backup buckets of each hash table based on the target key value includes: The target key value is calculated using the backup hash function of each hash table to determine the backup bucket index; The backup bucket index is used to search the backup buckets of each hash table to determine whether there is an entry in the backup buckets of each hash table that matches the target key value.
9. The hash table collision handling and entry redistribution method as described in claim 8, characterized in that, The first-stage search is performed in the main bucket of each hash table based on the target key value. If no entry matching the target key value is found in the first-stage search, a second-stage search is performed in the backup bucket of each hash table based on the target key value, including: During the first stage of the search, N read ports are invoked to search the main bucket of each hash table in parallel. If there is no entry matching the target key value in the main bucket of each hash table, the second stage of the search is executed, and the N read ports are reused to search the backup bucket of each hash table in parallel. or, During the first-stage lookup, a single read port is invoked to sequentially search the main buckets of each hash table. If no entry matching the target key value is found in the main buckets of each hash table, the second-stage lookup is executed, reusing the single read port to sequentially search the backup buckets of each hash table.
10. The hash table collision handling and entry redistribution method as described in claim 1, characterized in that, If the main bucket contains multiple free slots, iterate through the free slots in order of their positions and store the entry to be inserted in the first free slot of each free slot, or store the entry to be inserted in the last free slot of each free slot. If the found backup bucket contains multiple free slots, then the bucket is traversed in the order of their positions, and the entry to be inserted is stored in the first free slot of each free slot, or the entry to be inserted is stored in the last free slot of each free slot.
11. The hash table collision handling and entry redistribution method as described in claim 1, characterized in that, The backup hash function for each hash table is the main hash function of any hash table other than the current hash table, including: The primary hash function of the i-th hash table is the backup hash function of the (i+1)-th hash table, and the primary hash function of the N-th hash table is the backup hash function of the 1-th hash table, so that the primary hash functions and backup hash functions of the N tables form a circular cross-mapping, where 1≤i<N.
12. A switching chip, characterized in that, include: The memory contains N independent hash tables, where N ≥ 2 and is a positive integer; each hash table has a master hash function and a backup hash function, wherein the backup hash function of each hash table is the master hash function of any hash table other than the current hash table; each hash table includes multiple physical buckets, wherein the physical bucket determined according to the master hash function of the current hash table is the master bucket of the current hash table, and the physical bucket determined according to the backup hash function of the current hash table is the backup bucket of the current hash table, and each physical bucket contains multiple slots for storing entries, and each entry is set with a status bit for identifying the master storage status or the backup storage status; The interface unit is used to obtain the entry to be inserted and the target key value to be searched. The insertion control unit is used to search for free slots in the main buckets corresponding to each hash table using each main hash function. If a free slot exists, the entry to be inserted is written into the free slot of one of the main buckets, and the free slot of the main bucket where the entry to be inserted is written is set to the main storage state. If no free slot exists, the entry to be inserted is written into the free slot of one of the backup buckets using each backup hash function, and the free slot of the backup bucket where the entry to be inserted is written is set to the backup storage state. The lookup control unit is used to perform a first-stage lookup in the main bucket of each hash table according to the target key value. If no entry matching the target key value is found in the first-stage lookup, a second-stage lookup is performed in the spare bucket of each hash table according to the target key value to complete the lookup of the entry matching the target key value. The hash table that stores the entry matching the target key value is the target hash table. A migration control unit is configured to, when the storage status of an entry matching the target key value in the target hash table is a standby storage status, determine the entry matching the target key value in the standby storage status as a hit migration entry; and determine a target migration hash table for migrating the hit migration entry according to the target hash table, and determine the primary bucket corresponding to the standby bucket storing the hit migration entry in the target migration hash table as the target primary bucket; The transfer control unit is used to determine whether there is a free slot in the target main bucket. If there is a free slot, the hit migration entry is moved to the free slot in the target main bucket, and the storage status of the hit migration entry is changed to the main storage status.
Citation Information
Patent Citations
Horton-Cuckoo hash table for switch table lookup
CN120186109A
Lens distribution
US10355994B1
