Switch to jhash for VNODE_HASH
authorBenjamin Kaduk <kaduk@mit.edu>
Mon, 12 Jan 2015 21:13:28 +0000 (16:13 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Sat, 22 Aug 2015 16:44:18 +0000 (12:44 -0400)
Remove the vnodeHashOffset field, as the Jenkins hash will get
a uniform-enough distribution without this extra help.  Per-volume
unique hashing is retained by using the volume ID as the initial
value input to the Jenkins hash.

While here, increase the vnode hash table size from 256 to 2048.

Change-Id: I353dfc8178f13f4e9adcd03a331adf2a7c64a1a9
Reviewed-on: http://gerrit.openafs.org/11666
Reviewed-by: Daria Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>

src/vol/fssync-debug.c
src/vol/vnode.c
src/vol/volume.c
src/vol/volume.h

index e51fcad..47562df 100644 (file)
@@ -706,7 +706,6 @@ VolQuery(struct cmd_syndesc * as, void * rock)
        printf("\tlinkHandle      = %p\n", v.linkHandle);
        printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
        printf("\tdiskDataHandle  = %p\n", v.diskDataHandle);
-       printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
        printf("\tshuttingDown    = %d\n", v.shuttingDown);
        printf("\tgoingOffline    = %d\n", v.goingOffline);
        printf("\tcacheCheck      = %u\n", v.cacheCheck);
index d9f8c1f..ab1c349 100644 (file)
@@ -30,6 +30,7 @@
 #ifdef AFS_PTHREAD_ENV
 #include <opr/lock.h>
 #endif
+#include <opr/jhash.h>
 #include "rx/rx_queue.h"
 #include <afs/afsint.h>
 #include "nfs.h"
@@ -83,49 +84,18 @@ VNLog(afs_int32 aop, afs_int32 anparms, ... )
 }
 
 
-
-
-/* Vnode hash table.  Find hash chain by taking lower bits of
- * (volume_hash_offset + vnode).
- * This distributes the root inodes of the volumes over the
- * hash table entries and also distributes the vnodes of
- * volumes reasonably fairly.  The volume_hash_offset field
- * for each volume is established as the volume comes on line
- * by using the VOLUME_HASH_OFFSET macro.  This distributes the
- * volumes fairly among the cache entries, both when servicing
- * a small number of volumes and when servicing a large number.
- */
-
-/* VolumeHashOffset -- returns a new value to be stored in the
- * volumeHashOffset of a Volume structure.  Called when a
- * volume is initialized.  Sets the volumeHashOffset so that
- * vnode cache entries are distributed reasonably between
- * volumes (the root vnodes of the volumes will hash to
- * different values, and spacing is maintained between volumes
- * when there are not many volumes represented), and spread
- * equally amongst vnodes within a single volume.
+/* Vnode hash table.  Just use the Jenkins hash of the vnode number,
+ * with the volume ID as an initval because it's there.  (That will
+ * make the same vnode number in different volumes hash to a different
+ * value, which would probably not even be a big deal anyway.)
  */
-int
-VolumeHashOffset_r(void)
-{
-    static int nextVolumeHashOffset = 0;
-    /* hashindex Must be power of two in size */
-#   define hashShift 3
-#   define hashMask ((1<<hashShift)-1)
-    static byte hashindex[1 << hashShift] =
-       { 0, 128, 64, 192, 32, 160, 96, 224 };
-    int offset;
-    offset = hashindex[nextVolumeHashOffset & hashMask]
-       + (nextVolumeHashOffset >> hashShift);
-    nextVolumeHashOffset++;
-    return offset;
-}
 
-/* Change hashindex (above) if you change this constant */
-#define VNODE_HASH_TABLE_SIZE 256
+#define VNODE_HASH_TABLE_BITS 11
+#define VNODE_HASH_TABLE_SIZE opr_jhash_size(VNODE_HASH_TABLE_BITS)
+#define VNODE_HASH_TABLE_MASK opr_jhash_mask(VNODE_HASH_TABLE_BITS)
 private Vnode *VnodeHashTable[VNODE_HASH_TABLE_SIZE];
 #define VNODE_HASH(volumeptr,vnodenumber)\
-    ((volumeptr->vnodeHashOffset + vnodenumber)&(VNODE_HASH_TABLE_SIZE-1))
+    (opr_jhash_int((vnodenumber), V_id((volumeptr))) & VNODE_HASH_TABLE_MASK)
 
 
 
index 49793a6..01595ec 100644 (file)
@@ -8490,7 +8490,6 @@ AddVolumeToHashTable(Volume * vp, VolumeId hashid)
     head->len++;
     vp->hashid = hashid;
     queue_Append(head, vp);
-    vp->vnodeHashOffset = VolumeHashOffset_r();
 }
 
 /**
index 7762f23..c0b74a6 100644 (file)
@@ -665,9 +665,6 @@ typedef struct Volume {
                                 * uniquifier should be rewritten with the
                                 * value nextVnodeVersion */
     IHandle_t *diskDataHandle; /* Unix inode holding general volume info */
-    bit16 vnodeHashOffset;     /* Computed by HashOffset function in vnode.h.
-                                * Assigned to the volume when initialized.
-                                * Added to vnode number for hash table index */
     byte shuttingDown;         /* This volume is going to be detached */
     byte goingOffline;         /* This volume is going offline */
     bit32 cacheCheck;          /* Online sequence number to be used to invalidate vnode cache entries