Skip to content

Commit b6279f8

Browse files
author
Mike Snitzer
committed
dm bio prison v1: intelligently size dm_bio_prison's prison_regions
Size the dm_bio_prison's number of prison_region structs using dm_num_hash_locks(). Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent c627341 commit b6279f8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

drivers/md/dm-bio-prison-v1.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
/*----------------------------------------------------------------*/
1818

19-
#define NR_LOCKS 64
2019
#define MIN_CELLS 1024
2120

2221
struct prison_region {
@@ -27,7 +26,7 @@ struct prison_region {
2726
struct dm_bio_prison {
2827
mempool_t cell_pool;
2928
unsigned int num_locks;
30-
struct prison_region regions[NR_LOCKS];
29+
struct prison_region regions[];
3130
};
3231

3332
static struct kmem_cache *_cell_cache;
@@ -41,12 +40,14 @@ static struct kmem_cache *_cell_cache;
4140
struct dm_bio_prison *dm_bio_prison_create(void)
4241
{
4342
int ret;
44-
unsigned i;
45-
struct dm_bio_prison *prison = kzalloc(sizeof(*prison), GFP_KERNEL);
43+
unsigned int i, num_locks;
44+
struct dm_bio_prison *prison;
4645

46+
num_locks = dm_num_hash_locks();
47+
prison = kzalloc(struct_size(prison, regions, num_locks), GFP_KERNEL);
4748
if (!prison)
4849
return NULL;
49-
prison->num_locks = NR_LOCKS;
50+
prison->num_locks = num_locks;
5051

5152
for (i = 0; i < prison->num_locks; i++) {
5253
spin_lock_init(&prison->regions[i].lock);

0 commit comments

Comments
 (0)