summaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-bufio.c
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@kernel.org>2023-03-27 14:30:46 -0400
committerMike Snitzer <snitzer@kernel.org>2023-03-30 15:57:51 -0400
commit1e84c4b7322d44a5b7d7f83eced1f60cc0ecf1a4 (patch)
treeb87893ab832c7d86229fe3eb599d9157d2a430d6 /drivers/md/dm-bufio.c
parent36c18b86390824f93ed1580500df9698978e2006 (diff)
downloadlinux-1e84c4b7322d44a5b7d7f83eced1f60cc0ecf1a4.tar.gz
linux-1e84c4b7322d44a5b7d7f83eced1f60cc0ecf1a4.tar.bz2
linux-1e84c4b7322d44a5b7d7f83eced1f60cc0ecf1a4.zip
dm bufio: intelligently size dm_buffer_cache's buffer_trees
Size the dm_buffer_cache's number of buffer_tree structs using dm_num_hash_locks(). Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Diffstat (limited to 'drivers/md/dm-bufio.c')
-rw-r--r--drivers/md/dm-bufio.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 2250799a70e4..c1126ad45bdb 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -21,6 +21,8 @@
#include <linux/stacktrace.h>
#include <linux/jump_label.h>
+#include "dm.h"
+
#define DM_MSG_PREFIX "bufio"
/*
@@ -379,8 +381,6 @@ struct dm_buffer {
* only enough to ensure get/put are threadsafe.
*/
-#define NR_LOCKS 64
-
struct buffer_tree {
struct rw_semaphore lock;
struct rb_root root;
@@ -393,7 +393,7 @@ struct dm_buffer_cache {
* on the locks.
*/
unsigned int num_locks;
- struct buffer_tree trees[NR_LOCKS];
+ struct buffer_tree trees[];
};
static inline unsigned int cache_index(sector_t block, unsigned int num_locks)
@@ -976,7 +976,7 @@ struct dm_bufio_client {
*/
unsigned long oldest_buffer;
- struct dm_buffer_cache cache;
+ struct dm_buffer_cache cache; /* must be last member */
};
static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
@@ -2422,6 +2422,7 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
unsigned int flags)
{
int r;
+ unsigned int num_locks;
struct dm_bufio_client *c;
char slab_name[27];
@@ -2431,12 +2432,13 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
goto bad_client;
}
- c = kzalloc(sizeof(*c), GFP_KERNEL);
+ num_locks = dm_num_hash_locks();
+ c = kzalloc(sizeof(*c) + (num_locks * sizeof(struct buffer_tree)), GFP_KERNEL);
if (!c) {
r = -ENOMEM;
goto bad_client;
}
- cache_init(&c->cache, NR_LOCKS);
+ cache_init(&c->cache, num_locks);
c->bdev = bdev;
c->block_size = block_size;