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-
384384struct 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
399399static 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
982982static 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