From 8e97a6c93604014b126fb2e9e33642b11f4c2fc0 Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Thu, 15 Jan 2015 11:54:30 -0500 Subject: [PATCH] afs: Increase vcache and dcache hash table sizes Now that we are using a real hash function, larger hash tables will be more useful. The vcache hash tables are statically sized, and this increase will add about a megabyte to the kernel module's memory footprint. Update the algorithm used to dynamically size the dcache hash tables, keeping the old behavior for small numbers of dcaches, but growing the hash table's size to keep the average chain length near two for a range of dcache numbers. Cap the dcache hash tables at 32k entries to avoid excessive resource usage. This involves code from opr, namely opr/ffs.h, which is acceptable in the kernel module because that header is a standalone header like jhash.h, with no dependencies on the system. Change-Id: I7cdb3e993b1c2ad177a46ecc06bfa2be52e619e5 Reviewed-on: http://gerrit.openafs.org/11679 Reviewed-by: Benjamin Kaduk Tested-by: Benjamin Kaduk --- src/afs/afs.h | 2 +- src/afs/afs_dcache.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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);