Dynamically size dbuf hash mutex array
commit505df8d133788c28a2d6fcdf504dd1ffa55fa43f
authorBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 19 Sep 2022 19:17:11 +0000 (19 12:17 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 22 Sep 2022 19:59:56 +0000 (22 12:59 -0700)
treeed86bdbe439cead434bac280f862b457f88da549
parent223b04d23d6e84dfb6c983c46f69d5986625125c
Dynamically size dbuf hash mutex array

Incorrectly sizing the array of hash locks used to protect the
dbuf hash table can lead to contention and reduce performance.
We could unconditionally allocate a larger array for the locks
but it's wasteful, particularly for a low-memory system.
Instead, dynamically allocate the array of locks and scale
it based on total system memory.

Additionally, add a new `dbuf_mutex_cache_shift` module option
which can be used to override the hash lock array size.  This is
disabled by default (dbuf_mutex_hash_shift=0) and can only be
set at module load time.  The minimum target array size is set
to 8192, this matches the current constant value.

Note that the count of the dbuf hash table and count of the
mutex array were added to the /proc/spl/kstat/zfs/dbufstats
kstat.

Finally, this change removes the _KERNEL conditional checks.
These were not required since for the user space build there
is no difference between the kmem and vmem interfaces.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13928
include/sys/dbuf.h
man/man4/zfs.4
module/zfs/dbuf.c