svn commit: r352178 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Tue Sep 10 20:11:01 UTC 2019


Author: mjg
Date: Tue Sep 10 20:11:00 2019
New Revision: 352178
URL: https://svnweb.freebsd.org/changeset/base/352178

Log:
  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

Modified:
  head/sys/kern/vfs_cache.c

Modified: head/sys/kern/vfs_cache.c
==============================================================================
--- head/sys/kern/vfs_cache.c	Tue Sep 10 20:08:24 2019	(r352177)
+++ head/sys/kern/vfs_cache.c	Tue Sep 10 20:11:00 2019	(r352178)
@@ -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,


More information about the svn-src-head mailing list