diff --git a/src/afs/afs.h b/src/afs/afs.h index 2dc18fbc7d..a9877d536d 100644 --- a/src/afs/afs.h +++ b/src/afs/afs.h @@ -85,7 +85,7 @@ extern int afs_shuttingdown; #define NSERVERS 16 /* hash table size for server table */ #define NVOLS 64 /* hash table size for volume table */ #define NFENTRIES 256 /* hash table size for disk volume table */ -#define VCSIZEBITS 10 /* log of stat cache hash table size */ +#define VCSIZEBITS 16 /* log of stat cache hash table size */ #define VCSIZE (opr_jhash_size(VCSIZEBITS)) #define CBRSIZE 512 /* call back returns hash table size */ #define PIGGYSIZE 1350 /* max piggyback size */ diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index 56f883d18d..1bb3bd33e8 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -20,6 +20,8 @@ #include "afs/afs_cbqueue.h" #include "afs/afs_osidnlc.h" +#include + /* Forward declarations. */ static void afs_GetDownD(int anumber, int *aneedSpace, afs_int32 buckethint); static int afs_FreeDiscardedDCache(void); @@ -3249,6 +3251,7 @@ afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, int aflags) struct dcache *tdp; int i; int code; + int afs_dhashbits; afs_freeDCList = NULLIDX; afs_discardDCList = NULLIDX; @@ -3270,8 +3273,18 @@ afs_dcacheInit(int afiles, int ablocks, int aDentries, int achunk, int aflags) if (!aDentries) aDentries = DDSIZE; + /* afs_dhashsize defaults to 1024 */ if (aDentries > 512) afs_dhashsize = 2048; + /* Try to keep the average chain length around two unless the table + * would be ridiculously big. */ + if (aDentries > 4096) { + afs_dhashbits = opr_fls(aDentries) - 3; + /* Cap the hash tables to 32k entries. */ + if (afs_dhashbits > 15) + afs_dhashbits = 15; + afs_dhashsize = opr_jhash_size(afs_dhashbits); + } /* initialize hash tables */ afs_dvhashTbl = afs_osi_Alloc(afs_dhashsize * sizeof(afs_int32)); osi_Assert(afs_dvhashTbl != NULL);