summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@kernel.org>2023-03-27 20:59:25 +0300
committerMike Snitzer <snitzer@kernel.org>2023-03-30 22:57:51 +0300
commit0bac3f2f28b87b520e50a196c42409485acfe5cf (patch)
tree9b284a765f4e18da335e78af8be01d87c61de3c3 /drivers
parent3f8d3f5432078a558151e27230e20bcf93c23ffe (diff)
downloadlinux-0bac3f2f28b87b520e50a196c42409485acfe5cf.tar.xz
dm: add dm_num_hash_locks()
Simple helper to use when DM core code needs to appropriately size, based on num_online_cpus(), its data structures that split locks. dm_num_hash_locks() rounds up num_online_cpus() to next power of 2 but caps return at DM_HASH_LOCKS_MAX (64). This heuristic may evolve as warranted, but as-is it will serve as a more informed basis for sizing the sharded lock structs in dm-bufio's dm_buffer_cache (buffer_trees) and dm-bio-prison-v1's dm_bio_prison (prison_regions). Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/dm.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 22eaed188907..a1a5defddb07 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -20,6 +20,7 @@
#include <linux/completion.h>
#include <linux/kobject.h>
#include <linux/refcount.h>
+#include <linux/log2.h>
#include "dm-stats.h"
@@ -228,4 +229,13 @@ void dm_free_md_mempools(struct dm_md_mempools *pools);
*/
unsigned int dm_get_reserved_bio_based_ios(void);
+#define DM_HASH_LOCKS_MAX 64
+
+static inline unsigned int dm_num_hash_locks(void)
+{
+ unsigned int num_locks = roundup_pow_of_two(num_online_cpus());
+
+ return min_t(unsigned int, num_locks, DM_HASH_LOCKS_MAX);
+}
+
#endif