diff options
Diffstat (limited to 'drivers/md/dm.h')
-rw-r--r-- | drivers/md/dm.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/md/dm.h b/drivers/md/dm.h index 22eaed188907..a856e0aee73b 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,25 @@ 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()) << 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 |