Skip to content

Commit 0bac3f2

Browse files
author
Mike Snitzer
committed
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>
1 parent 3f8d3f5 commit 0bac3f2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/md/dm.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/completion.h>
2121
#include <linux/kobject.h>
2222
#include <linux/refcount.h>
23+
#include <linux/log2.h>
2324

2425
#include "dm-stats.h"
2526

@@ -228,4 +229,13 @@ void dm_free_md_mempools(struct dm_md_mempools *pools);
228229
*/
229230
unsigned int dm_get_reserved_bio_based_ios(void);
230231

232+
#define DM_HASH_LOCKS_MAX 64
233+
234+
static inline unsigned int dm_num_hash_locks(void)
235+
{
236+
unsigned int num_locks = roundup_pow_of_two(num_online_cpus());
237+
238+
return min_t(unsigned int, num_locks, DM_HASH_LOCKS_MAX);
239+
}
240+
231241
#endif

0 commit comments

Comments
 (0)