[ovs-discuss] conn_key_hash change hash arithmetic

Darrell Ball dball at vmware.com
Thu Dec 14 17:56:26 UTC 2017



From: <ovs-discuss-bounces at openvswitch.org> on behalf of "liucheng (J)" <liucheng11 at huawei.com>
Date: Wednesday, December 13, 2017 at 9:04 AM
To: "ovs-discuss at openvswitch.org" <ovs-discuss at openvswitch.org>
Subject: [ovs-discuss] conn_key_hash change hash arithmetic

Hello all,
I run a test with the user conntrack. And I found if I only change the udp port, then the hash with function “conn_key_hash” is not balance.

[Darrell] You are changing src and dst UDP ports; what algorithm is used to select the ports ?


I change the hmap num(ct->buckets) to 4096

[Darrell] I assume you refer to CONNTRACK_BUCKETS ?


and ct->n_conn_limit to 30,000,000.

[Darrell] That is a large number for only varying the L4 ports; don’t you think ?
                 Do you think this represents a common use case or connection distribution?


And I print the num of the nodes contained in the hmap’s bucket.
As an example, a result looks like below. Most bucket is empty, and some bucket contain hundreds of nodes;
~~~~~~~~~~~~~~~~~hmap 4095 count 4310 mask 4095~~~~~~~~~~~~~~~
buket 488 content 367 node
buket 1077 content 514 node
buket 1118 content 281 node
buket 1261 content 423 node
buket 1280 content 268 node
buket 1603 content 319 node
buket 1724 content 352 node
buket 2676 content 155 node
buket 2993 content 471 node
buket 3028 content 325 node
buket 3836 content 355 node
buket 4060 content 480 node

[Darrell] I assume you are referring to ct->buckets; i.e. first level buckets ?

Then I change the code in conn_key_hash as the patch. And test result is the max nodes in one bucket is 12.
The num of the bucket contained only one node is 5000542.
The num of the bucket contained only two node is 4337097.
The num of the bucket contained only three node is 2588535.
The num of the bucket contained only four node is 1196063.
The num of the bucket contained only five node is 460865.
The num of the bucket contained only six node is 155936.
The num of the bucket contained only seven node is 48727.
Most buckets contain few nodes.

[Darrell] I am assuming you are referring to ct->buckets, still ?
                 1 of 4096 first level buckets ?




diff --git a/lib/conntrack.c b/lib/conntrack.c
index 6d078f5..3edf809 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -2034,7 +2034,7 @@ conn_key_hash(const struct conn_key *key, uint32_t basis)
     hdst = ct_endpoint_hash_add(hdst, &key->dst);

     /* Even if source and destination are swapped the hash will be the same. */
-    hash = hsrc ^ hdst;
+    hash = hsrc + hdst;

     /* Hash the rest of the key(L3 and L4 types and zone). */
     hash = hash_words((uint32_t *) (&key->dst + 1),

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-discuss/attachments/20171214/cd53e1b7/attachment-0001.html>


More information about the discuss mailing list