Skip to content

Commit a91a278

Browse files
martinkpetersenJens Axboe
authored and
Jens Axboe
committed
block: Require subsystems to explicitly allocate bio_set integrity mempool
MD and DM create a new bio_set for every metadevice. Each bio_set has an integrity mempool attached regardless of whether the metadevice is capable of passing integrity metadata. This is a waste of memory. Instead we defer the allocation decision to MD and DM since we know at metadevice creation time whether integrity passthrough is needed or not. Automatic integrity mempool allocation can then be removed from bioset_create() and we make an explicit integrity allocation for the fs_bio_set. Signed-off-by: Martin K. Petersen <[email protected]> Reported-by: Zdenek Kabelac <[email protected]> Acked-by: Mike Snitzer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 82f04ab commit a91a278

File tree

11 files changed

+41
-22
lines changed

11 files changed

+41
-22
lines changed

drivers/md/dm-table.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct dm_table {
5555
struct dm_target *targets;
5656

5757
unsigned discards_supported:1;
58+
unsigned integrity_supported:1;
5859

5960
/*
6061
* Indicates the rw permissions for the new logical
@@ -859,7 +860,7 @@ int dm_table_alloc_md_mempools(struct dm_table *t)
859860
return -EINVAL;
860861
}
861862

862-
t->mempools = dm_alloc_md_mempools(type);
863+
t->mempools = dm_alloc_md_mempools(type, t->integrity_supported);
863864
if (!t->mempools)
864865
return -ENOMEM;
865866

@@ -935,8 +936,10 @@ static int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device
935936
struct dm_dev_internal *dd;
936937

937938
list_for_each_entry(dd, devices, list)
938-
if (bdev_get_integrity(dd->dm_dev.bdev))
939+
if (bdev_get_integrity(dd->dm_dev.bdev)) {
940+
t->integrity_supported = 1;
939941
return blk_integrity_register(dm_disk(md), NULL);
942+
}
940943

941944
return 0;
942945
}

drivers/md/dm.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -2620,9 +2620,10 @@ int dm_noflush_suspending(struct dm_target *ti)
26202620
}
26212621
EXPORT_SYMBOL_GPL(dm_noflush_suspending);
26222622

2623-
struct dm_md_mempools *dm_alloc_md_mempools(unsigned type)
2623+
struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity)
26242624
{
26252625
struct dm_md_mempools *pools = kmalloc(sizeof(*pools), GFP_KERNEL);
2626+
unsigned int pool_size = (type == DM_TYPE_BIO_BASED) ? 16 : MIN_IOS;
26262627

26272628
if (!pools)
26282629
return NULL;
@@ -2639,13 +2640,18 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type)
26392640
if (!pools->tio_pool)
26402641
goto free_io_pool_and_out;
26412642

2642-
pools->bs = (type == DM_TYPE_BIO_BASED) ?
2643-
bioset_create(16, 0) : bioset_create(MIN_IOS, 0);
2643+
pools->bs = bioset_create(pool_size, 0);
26442644
if (!pools->bs)
26452645
goto free_tio_pool_and_out;
26462646

2647+
if (integrity && bioset_integrity_create(pools->bs, pool_size))
2648+
goto free_bioset_and_out;
2649+
26472650
return pools;
26482651

2652+
free_bioset_and_out:
2653+
bioset_free(pools->bs);
2654+
26492655
free_tio_pool_and_out:
26502656
mempool_destroy(pools->tio_pool);
26512657

drivers/md/dm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void dm_kcopyd_exit(void);
149149
/*
150150
* Mempool operations
151151
*/
152-
struct dm_md_mempools *dm_alloc_md_mempools(unsigned type);
152+
struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity);
153153
void dm_free_md_mempools(struct dm_md_mempools *pools);
154154

155155
#endif

drivers/md/linear.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ static int linear_run (mddev_t *mddev)
210210
blk_queue_merge_bvec(mddev->queue, linear_mergeable_bvec);
211211
mddev->queue->backing_dev_info.congested_fn = linear_congested;
212212
mddev->queue->backing_dev_info.congested_data = mddev;
213-
md_integrity_register(mddev);
214-
return 0;
213+
return md_integrity_register(mddev);
215214
}
216215

217216
static void free_conf(struct rcu_head *head)

drivers/md/md.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,12 @@ int md_integrity_register(mddev_t *mddev)
18031803
mdname(mddev));
18041804
return -EINVAL;
18051805
}
1806-
printk(KERN_NOTICE "md: data integrity on %s enabled\n",
1807-
mdname(mddev));
1806+
printk(KERN_NOTICE "md: data integrity enabled on %s\n", mdname(mddev));
1807+
if (bioset_integrity_create(mddev->bio_set, BIO_POOL_SIZE)) {
1808+
printk(KERN_ERR "md: failed to create integrity pool for %s\n",
1809+
mdname(mddev));
1810+
return -EINVAL;
1811+
}
18081812
return 0;
18091813
}
18101814
EXPORT_SYMBOL(md_integrity_register);

drivers/md/multipath.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static int multipath_remove_disk(mddev_t *mddev, int number)
315315
p->rdev = rdev;
316316
goto abort;
317317
}
318-
md_integrity_register(mddev);
318+
err = md_integrity_register(mddev);
319319
}
320320
abort:
321321

@@ -489,7 +489,10 @@ static int multipath_run (mddev_t *mddev)
489489

490490
mddev->queue->backing_dev_info.congested_fn = multipath_congested;
491491
mddev->queue->backing_dev_info.congested_data = mddev;
492-
md_integrity_register(mddev);
492+
493+
if (md_integrity_register(mddev))
494+
goto out_free_conf;
495+
493496
return 0;
494497

495498
out_free_conf:

drivers/md/raid0.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ static int raid0_run(mddev_t *mddev)
379379

380380
blk_queue_merge_bvec(mddev->queue, raid0_mergeable_bvec);
381381
dump_zones(mddev);
382-
md_integrity_register(mddev);
383-
return 0;
382+
return md_integrity_register(mddev);
384383
}
385384

386385
static int raid0_stop(mddev_t *mddev)

drivers/md/raid1.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ static int raid1_remove_disk(mddev_t *mddev, int number)
11321132
p->rdev = rdev;
11331133
goto abort;
11341134
}
1135-
md_integrity_register(mddev);
1135+
err = md_integrity_register(mddev);
11361136
}
11371137
abort:
11381138

@@ -2017,8 +2017,7 @@ static int run(mddev_t *mddev)
20172017

20182018
mddev->queue->backing_dev_info.congested_fn = raid1_congested;
20192019
mddev->queue->backing_dev_info.congested_data = mddev;
2020-
md_integrity_register(mddev);
2021-
return 0;
2020+
return md_integrity_register(mddev);
20222021
}
20232022

20242023
static int stop(mddev_t *mddev)

drivers/md/raid10.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ static int raid10_remove_disk(mddev_t *mddev, int number)
11881188
p->rdev = rdev;
11891189
goto abort;
11901190
}
1191-
md_integrity_register(mddev);
1191+
err = md_integrity_register(mddev);
11921192
}
11931193
abort:
11941194

@@ -2343,7 +2343,10 @@ static int run(mddev_t *mddev)
23432343

23442344
if (conf->near_copies < conf->raid_disks)
23452345
blk_queue_merge_bvec(mddev->queue, raid10_mergeable_bvec);
2346-
md_integrity_register(mddev);
2346+
2347+
if (md_integrity_register(mddev))
2348+
goto out_free_conf;
2349+
23472350
return 0;
23482351

23492352
out_free_conf:

fs/bio-integrity.c

+3
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ int bioset_integrity_create(struct bio_set *bs, int pool_size)
761761
{
762762
unsigned int max_slab = vecs_to_idx(BIO_MAX_PAGES);
763763

764+
if (bs->bio_integrity_pool)
765+
return 0;
766+
764767
bs->bio_integrity_pool =
765768
mempool_create_slab_pool(pool_size, bip_slab[max_slab].slab);
766769

fs/bio.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1636,9 +1636,6 @@ struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
16361636
if (!bs->bio_pool)
16371637
goto bad;
16381638

1639-
if (bioset_integrity_create(bs, pool_size))
1640-
goto bad;
1641-
16421639
if (!biovec_create_pools(bs, pool_size))
16431640
return bs;
16441641

@@ -1682,6 +1679,9 @@ static int __init init_bio(void)
16821679
if (!fs_bio_set)
16831680
panic("bio: can't allocate bios\n");
16841681

1682+
if (bioset_integrity_create(fs_bio_set, BIO_POOL_SIZE))
1683+
panic("bio: can't create integrity pool\n");
1684+
16851685
bio_split_pool = mempool_create_kmalloc_pool(BIO_SPLIT_ENTRIES,
16861686
sizeof(struct bio_pair));
16871687
if (!bio_split_pool)

0 commit comments

Comments
 (0)