Skip to content

Commit 1e84c4b

Browse files
author
Mike Snitzer
committed
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>
1 parent 36c18b8 commit 1e84c4b

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

drivers/md/dm-bufio.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/stacktrace.h>
2222
#include <linux/jump_label.h>
2323

24+
#include "dm.h"
25+
2426
#define DM_MSG_PREFIX "bufio"
2527

2628
/*
@@ -379,8 +381,6 @@ struct dm_buffer {
379381
* only enough to ensure get/put are threadsafe.
380382
*/
381383

382-
#define NR_LOCKS 64
383-
384384
struct buffer_tree {
385385
struct rw_semaphore lock;
386386
struct rb_root root;
@@ -393,7 +393,7 @@ struct dm_buffer_cache {
393393
* on the locks.
394394
*/
395395
unsigned int num_locks;
396-
struct buffer_tree trees[NR_LOCKS];
396+
struct buffer_tree trees[];
397397
};
398398

399399
static inline unsigned int cache_index(sector_t block, unsigned int num_locks)
@@ -976,7 +976,7 @@ struct dm_bufio_client {
976976
*/
977977
unsigned long oldest_buffer;
978978

979-
struct dm_buffer_cache cache;
979+
struct dm_buffer_cache cache; /* must be last member */
980980
};
981981

982982
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
24222422
unsigned int flags)
24232423
{
24242424
int r;
2425+
unsigned int num_locks;
24252426
struct dm_bufio_client *c;
24262427
char slab_name[27];
24272428

@@ -2431,12 +2432,13 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
24312432
goto bad_client;
24322433
}
24332434

2434-
c = kzalloc(sizeof(*c), GFP_KERNEL);
2435+
num_locks = dm_num_hash_locks();
2436+
c = kzalloc(sizeof(*c) + (num_locks * sizeof(struct buffer_tree)), GFP_KERNEL);
24352437
if (!c) {
24362438
r = -ENOMEM;
24372439
goto bad_client;
24382440
}
2439-
cache_init(&c->cache, NR_LOCKS);
2441+
cache_init(&c->cache, num_locks);
24402442

24412443
c->bdev = bdev;
24422444
c->block_size = block_size;

0 commit comments

Comments
 (0)