diff options
author | Joe Thornber <ejt@redhat.com> | 2023-03-29 10:29:34 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@kernel.org> | 2023-03-30 15:57:51 -0400 |
commit | 363b7fd76c91dc611a56d992e9550bb1ba070e1a (patch) | |
tree | a8871fafe3b50344d8ff12a4fc7403cfdfd9772a /drivers/md/dm.h | |
parent | b6279f82eb11a1f380af3a26acf921c37505fc86 (diff) | |
download | linux-stable-363b7fd76c91dc611a56d992e9550bb1ba070e1a.tar.gz linux-stable-363b7fd76c91dc611a56d992e9550bb1ba070e1a.tar.bz2 linux-stable-363b7fd76c91dc611a56d992e9550bb1ba070e1a.zip |
dm: improve hash_locks sizing and hash function
Both bufio and bio-prison-v1 use the identical model for splitting
their respective locks and rbtrees. Improve dm_num_hash_locks() to
distribute across more rbtrees to improve overall performance -- but
the maximum number of locks/rbtrees is still 64.
Also factor out a common hash function named dm_hash_locks_index(),
the magic numbers used were determined to be best using this program:
https://gist.github.com/jthornber/e05c47daa7b500c56dc339269c5467fc
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Diffstat (limited to 'drivers/md/dm.h')
-rw-r--r-- | drivers/md/dm.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/drivers/md/dm.h b/drivers/md/dm.h index a1a5defddb07..a856e0aee73b 100644 --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -233,9 +233,21 @@ unsigned int dm_get_reserved_bio_based_ios(void); static inline unsigned int dm_num_hash_locks(void) { - unsigned int num_locks = roundup_pow_of_two(num_online_cpus()); + unsigned int num_locks = roundup_pow_of_two(num_online_cpus()) << 1; return min_t(unsigned int, num_locks, DM_HASH_LOCKS_MAX); } +#define DM_HASH_LOCKS_MULT 4294967291ULL +#define DM_HASH_LOCKS_SHIFT 6 + +static inline unsigned int dm_hash_locks_index(sector_t block, + unsigned int num_locks) +{ + sector_t h1 = (block * DM_HASH_LOCKS_MULT) >> DM_HASH_LOCKS_SHIFT; + sector_t h2 = h1 >> DM_HASH_LOCKS_SHIFT; + + return (h1 ^ h2) & (num_locks - 1); +} + #endif |