From: mjg Date: Tue, 10 Sep 2019 20:11:00 +0000 (+0000) Subject: cache: change the formula for calculating lock array sizes X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=5924940444ff6e760b180757440a41c85c380244;p=freebsd.git cache: change the formula for calculating lock array sizes It used to be mp_ncpus * 64, but this gives unnecessarily big values for small machines and at the same time constraints bigger ones. In particular this helps on a 104-way box for which the count is now doubled. While here make cache_purgevfs less likely. Currently it is not efficient in face of contention due to lock ordering issues. These are fixable but not worth it at the moment. Sponsored by: The FreeBSD Foundation --- diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 61d51c98f39..d45bc43052c 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -1879,19 +1879,21 @@ nchinit(void *dummy __unused) UMA_ZONE_ZINIT); nchashtbl = hashinit(desiredvnodes * 2, M_VFSCACHE, &nchash); - ncbuckethash = cache_roundup_2(mp_ncpus * 64) - 1; + ncbuckethash = cache_roundup_2(mp_ncpus * mp_ncpus) - 1; + if (ncbuckethash < 7) /* arbitrarily chosen to avoid having one lock */ + ncbuckethash = 7; if (ncbuckethash > nchash) ncbuckethash = nchash; bucketlocks = malloc(sizeof(*bucketlocks) * numbucketlocks, M_VFSCACHE, M_WAITOK | M_ZERO); for (i = 0; i < numbucketlocks; i++) rw_init_flags(&bucketlocks[i], "ncbuc", RW_DUPOK | RW_RECURSE); - ncvnodehash = cache_roundup_2(mp_ncpus * 64) - 1; + ncvnodehash = ncbuckethash; vnodelocks = malloc(sizeof(*vnodelocks) * numvnodelocks, M_VFSCACHE, M_WAITOK | M_ZERO); for (i = 0; i < numvnodelocks; i++) mtx_init(&vnodelocks[i], "ncvn", NULL, MTX_DUPOK | MTX_RECURSE); - ncpurgeminvnodes = numbucketlocks; + ncpurgeminvnodes = numbucketlocks * 2; ncneghash = 3; neglists = malloc(sizeof(*neglists) * numneglists, M_VFSCACHE,