Whamcloud - gitweb
LU-14676 lnet: improve hash distribution across CPTs
authorSerguei Smirnov <ssmirnov@whamcloud.com>
Thu, 20 Jan 2022 16:40:28 +0000 (08:40 -0800)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 31 Mar 2022 04:20:10 +0000 (04:20 +0000)
Change the nid-to-cpt allocation function to use
(sum-by-multiplication of nid bytes) mod (number of CPTs)
to match nid to a CPT. This patch only addresses IPV4 nids.

Make the matching change for the nid-to-cpt function
used by the 'lnetctl cpt-of-nid' utility.

Lustre-change: https://review.whamcloud.com/46233
Lustre-commit: 9b6e27755507b9bb47a1d7b4aede6302a876a14d

Test-parameters: trivial testlist=sanity-lnet

Signed-off-by: Serguei Smirnov <ssmirnov@whamcloud.com>
Change-Id: I1052414947c4cae8c63993ffa21f67cb389bb463
Reviewed-by: Cyril Bordage <cbordage@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/46398
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/lnet/api-ni.c
lnet/utils/lnetconfig/liblnetconfig.c

index b8313e2..54bca39 100644 (file)
@@ -1389,20 +1389,21 @@ lnet_get_net_locked(__u32 net_id)
 unsigned int
 lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
 {
-       __u64           key = nid;
-       unsigned int    val;
+       __u64 key = nid;
+       __u64 pair_bits = 0x0001000100010001LLU;
+       __u64 mask = pair_bits * 0xFF;
+       __u64 pair_sum;
 
-       LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
-
-       if (number == 1)
-               return 0;
+       /* Use (sum-by-multiplication of nid bytes) mod (number of CPTs)
+        * to match nid to a CPT.
+        */
+       pair_sum = (key & mask) + ((key >> 8) & mask);
+       pair_sum = (pair_sum * pair_bits) >> 48;
 
-       val = hash_long(key, LNET_CPT_BITS);
-       /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
-       if (val < number)
-               return val;
+       CDEBUG(D_NET, "Match nid %s to cpt %u\n",
+              libcfs_nid2str(nid), (unsigned int)(pair_sum) % number);
 
-       return (unsigned int)(key + val + (val >> 1)) % number;
+       return (unsigned int)(pair_sum) % number;
 }
 
 int
index 46d2d27..53bc675 100644 (file)
@@ -44,7 +44,6 @@
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <libcfs/util/ioctl.h>
-#include <libcfs/util/hash.h>
 #include <linux/lnet/lnetctl.h>
 #include "liblnd.h"
 #include <sys/types.h>
@@ -3620,22 +3619,18 @@ out:
 unsigned int
 lnet_nid_cpt_hash(lnet_nid_t nid, long int number)
 {
-       __u64           key = nid;
-       unsigned int    val;
-       int cpt_bits = 0;
+       __u64 key = nid;
+       __u64 pair_bits = 0x0001000100010001LLU;
+       __u64 mask = pair_bits * 0xFF;
+       __u64 pair_sum;
 
        if (number == 1)
                return 0;
 
-       while ((1 << cpt_bits) < number)
-               cpt_bits++;
+       pair_sum = (key & mask) + ((key >> 8) & mask);
+       pair_sum = (pair_sum * pair_bits) >> 48;
 
-       val = hash_long(key, cpt_bits);
-       /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
-       if (val < number)
-               return val;
-
-       return (unsigned int)(key + val + (val >> 1)) % number;
+       return (unsigned int)(pair_sum) % number;
 }
 
 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts)