Skip to content

Commit 6f1c819

Browse files
koverstreetaxboe
authored andcommitted
dm: convert to bioset_init()/mempool_init()
Convert dm to embedded bio sets. Acked-by: Mike Snitzer <[email protected]> Signed-off-by: Kent Overstreet <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent afeee51 commit 6f1c819

17 files changed

+197
-206
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
struct dm_bio_prison {
2121
spinlock_t lock;
22-
mempool_t *cell_pool;
22+
mempool_t cell_pool;
2323
struct rb_root cells;
2424
};
2525

@@ -34,14 +34,15 @@ static struct kmem_cache *_cell_cache;
3434
struct dm_bio_prison *dm_bio_prison_create(void)
3535
{
3636
struct dm_bio_prison *prison = kmalloc(sizeof(*prison), GFP_KERNEL);
37+
int ret;
3738

3839
if (!prison)
3940
return NULL;
4041

4142
spin_lock_init(&prison->lock);
4243

43-
prison->cell_pool = mempool_create_slab_pool(MIN_CELLS, _cell_cache);
44-
if (!prison->cell_pool) {
44+
ret = mempool_init_slab_pool(&prison->cell_pool, MIN_CELLS, _cell_cache);
45+
if (ret) {
4546
kfree(prison);
4647
return NULL;
4748
}
@@ -54,21 +55,21 @@ EXPORT_SYMBOL_GPL(dm_bio_prison_create);
5455

5556
void dm_bio_prison_destroy(struct dm_bio_prison *prison)
5657
{
57-
mempool_destroy(prison->cell_pool);
58+
mempool_exit(&prison->cell_pool);
5859
kfree(prison);
5960
}
6061
EXPORT_SYMBOL_GPL(dm_bio_prison_destroy);
6162

6263
struct dm_bio_prison_cell *dm_bio_prison_alloc_cell(struct dm_bio_prison *prison, gfp_t gfp)
6364
{
64-
return mempool_alloc(prison->cell_pool, gfp);
65+
return mempool_alloc(&prison->cell_pool, gfp);
6566
}
6667
EXPORT_SYMBOL_GPL(dm_bio_prison_alloc_cell);
6768

6869
void dm_bio_prison_free_cell(struct dm_bio_prison *prison,
6970
struct dm_bio_prison_cell *cell)
7071
{
71-
mempool_free(cell, prison->cell_pool);
72+
mempool_free(cell, &prison->cell_pool);
7273
}
7374
EXPORT_SYMBOL_GPL(dm_bio_prison_free_cell);
7475

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct dm_bio_prison_v2 {
2121
struct workqueue_struct *wq;
2222

2323
spinlock_t lock;
24-
mempool_t *cell_pool;
24+
mempool_t cell_pool;
2525
struct rb_root cells;
2626
};
2727

@@ -36,15 +36,16 @@ static struct kmem_cache *_cell_cache;
3636
struct dm_bio_prison_v2 *dm_bio_prison_create_v2(struct workqueue_struct *wq)
3737
{
3838
struct dm_bio_prison_v2 *prison = kmalloc(sizeof(*prison), GFP_KERNEL);
39+
int ret;
3940

4041
if (!prison)
4142
return NULL;
4243

4344
prison->wq = wq;
4445
spin_lock_init(&prison->lock);
4546

46-
prison->cell_pool = mempool_create_slab_pool(MIN_CELLS, _cell_cache);
47-
if (!prison->cell_pool) {
47+
ret = mempool_init_slab_pool(&prison->cell_pool, MIN_CELLS, _cell_cache);
48+
if (ret) {
4849
kfree(prison);
4950
return NULL;
5051
}
@@ -57,21 +58,21 @@ EXPORT_SYMBOL_GPL(dm_bio_prison_create_v2);
5758

5859
void dm_bio_prison_destroy_v2(struct dm_bio_prison_v2 *prison)
5960
{
60-
mempool_destroy(prison->cell_pool);
61+
mempool_exit(&prison->cell_pool);
6162
kfree(prison);
6263
}
6364
EXPORT_SYMBOL_GPL(dm_bio_prison_destroy_v2);
6465

6566
struct dm_bio_prison_cell_v2 *dm_bio_prison_alloc_cell_v2(struct dm_bio_prison_v2 *prison, gfp_t gfp)
6667
{
67-
return mempool_alloc(prison->cell_pool, gfp);
68+
return mempool_alloc(&prison->cell_pool, gfp);
6869
}
6970
EXPORT_SYMBOL_GPL(dm_bio_prison_alloc_cell_v2);
7071

7172
void dm_bio_prison_free_cell_v2(struct dm_bio_prison_v2 *prison,
7273
struct dm_bio_prison_cell_v2 *cell)
7374
{
74-
mempool_free(cell, prison->cell_pool);
75+
mempool_free(cell, &prison->cell_pool);
7576
}
7677
EXPORT_SYMBOL_GPL(dm_bio_prison_free_cell_v2);
7778

drivers/md/dm-cache-target.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,9 @@ struct cache {
447447
struct work_struct migration_worker;
448448
struct delayed_work waker;
449449
struct dm_bio_prison_v2 *prison;
450-
struct bio_set *bs;
450+
struct bio_set bs;
451451

452-
mempool_t *migration_pool;
452+
mempool_t migration_pool;
453453

454454
struct dm_cache_policy *policy;
455455
unsigned policy_nr_args;
@@ -550,7 +550,7 @@ static struct dm_cache_migration *alloc_migration(struct cache *cache)
550550
{
551551
struct dm_cache_migration *mg;
552552

553-
mg = mempool_alloc(cache->migration_pool, GFP_NOWAIT);
553+
mg = mempool_alloc(&cache->migration_pool, GFP_NOWAIT);
554554
if (!mg)
555555
return NULL;
556556

@@ -569,7 +569,7 @@ static void free_migration(struct dm_cache_migration *mg)
569569
if (atomic_dec_and_test(&cache->nr_allocated_migrations))
570570
wake_up(&cache->migration_wait);
571571

572-
mempool_free(mg, cache->migration_pool);
572+
mempool_free(mg, &cache->migration_pool);
573573
}
574574

575575
/*----------------------------------------------------------------*/
@@ -924,7 +924,7 @@ static void issue_op(struct bio *bio, void *context)
924924
static void remap_to_origin_and_cache(struct cache *cache, struct bio *bio,
925925
dm_oblock_t oblock, dm_cblock_t cblock)
926926
{
927-
struct bio *origin_bio = bio_clone_fast(bio, GFP_NOIO, cache->bs);
927+
struct bio *origin_bio = bio_clone_fast(bio, GFP_NOIO, &cache->bs);
928928

929929
BUG_ON(!origin_bio);
930930

@@ -2011,7 +2011,7 @@ static void destroy(struct cache *cache)
20112011
{
20122012
unsigned i;
20132013

2014-
mempool_destroy(cache->migration_pool);
2014+
mempool_exit(&cache->migration_pool);
20152015

20162016
if (cache->prison)
20172017
dm_bio_prison_destroy_v2(cache->prison);
@@ -2047,8 +2047,7 @@ static void destroy(struct cache *cache)
20472047
kfree(cache->ctr_args[i]);
20482048
kfree(cache->ctr_args);
20492049

2050-
if (cache->bs)
2051-
bioset_free(cache->bs);
2050+
bioset_exit(&cache->bs);
20522051

20532052
kfree(cache);
20542053
}
@@ -2498,8 +2497,8 @@ static int cache_create(struct cache_args *ca, struct cache **result)
24982497
cache->features = ca->features;
24992498
if (writethrough_mode(cache)) {
25002499
/* Create bioset for writethrough bios issued to origin */
2501-
cache->bs = bioset_create(BIO_POOL_SIZE, 0, 0);
2502-
if (!cache->bs)
2500+
r = bioset_init(&cache->bs, BIO_POOL_SIZE, 0, 0);
2501+
if (r)
25032502
goto bad;
25042503
}
25052504

@@ -2630,9 +2629,9 @@ static int cache_create(struct cache_args *ca, struct cache **result)
26302629
goto bad;
26312630
}
26322631

2633-
cache->migration_pool = mempool_create_slab_pool(MIGRATION_POOL_SIZE,
2634-
migration_cache);
2635-
if (!cache->migration_pool) {
2632+
r = mempool_init_slab_pool(&cache->migration_pool, MIGRATION_POOL_SIZE,
2633+
migration_cache);
2634+
if (r) {
26362635
*error = "Error creating cache's migration mempool";
26372636
goto bad;
26382637
}

drivers/md/dm-core.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ struct mapped_device {
9191
/*
9292
* io objects are allocated from here.
9393
*/
94-
struct bio_set *io_bs;
95-
struct bio_set *bs;
94+
struct bio_set io_bs;
95+
struct bio_set bs;
9696

9797
/*
9898
* freeze/thaw support require holding onto a super block

drivers/md/dm-crypt.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ struct crypt_config {
143143
* pool for per bio private data, crypto requests,
144144
* encryption requeusts/buffer pages and integrity tags
145145
*/
146-
mempool_t *req_pool;
147-
mempool_t *page_pool;
148-
mempool_t *tag_pool;
146+
mempool_t req_pool;
147+
mempool_t page_pool;
148+
mempool_t tag_pool;
149149
unsigned tag_pool_max_sectors;
150150

151151
struct percpu_counter n_allocated_pages;
152152

153-
struct bio_set *bs;
153+
struct bio_set bs;
154154
struct mutex bio_alloc_lock;
155155

156156
struct workqueue_struct *io_queue;
@@ -1245,7 +1245,7 @@ static void crypt_alloc_req_skcipher(struct crypt_config *cc,
12451245
unsigned key_index = ctx->cc_sector & (cc->tfms_count - 1);
12461246

12471247
if (!ctx->r.req)
1248-
ctx->r.req = mempool_alloc(cc->req_pool, GFP_NOIO);
1248+
ctx->r.req = mempool_alloc(&cc->req_pool, GFP_NOIO);
12491249

12501250
skcipher_request_set_tfm(ctx->r.req, cc->cipher_tfm.tfms[key_index]);
12511251

@@ -1262,7 +1262,7 @@ static void crypt_alloc_req_aead(struct crypt_config *cc,
12621262
struct convert_context *ctx)
12631263
{
12641264
if (!ctx->r.req_aead)
1265-
ctx->r.req_aead = mempool_alloc(cc->req_pool, GFP_NOIO);
1265+
ctx->r.req_aead = mempool_alloc(&cc->req_pool, GFP_NOIO);
12661266

12671267
aead_request_set_tfm(ctx->r.req_aead, cc->cipher_tfm.tfms_aead[0]);
12681268

@@ -1290,7 +1290,7 @@ static void crypt_free_req_skcipher(struct crypt_config *cc,
12901290
struct dm_crypt_io *io = dm_per_bio_data(base_bio, cc->per_bio_data_size);
12911291

12921292
if ((struct skcipher_request *)(io + 1) != req)
1293-
mempool_free(req, cc->req_pool);
1293+
mempool_free(req, &cc->req_pool);
12941294
}
12951295

12961296
static void crypt_free_req_aead(struct crypt_config *cc,
@@ -1299,7 +1299,7 @@ static void crypt_free_req_aead(struct crypt_config *cc,
12991299
struct dm_crypt_io *io = dm_per_bio_data(base_bio, cc->per_bio_data_size);
13001300

13011301
if ((struct aead_request *)(io + 1) != req)
1302-
mempool_free(req, cc->req_pool);
1302+
mempool_free(req, &cc->req_pool);
13031303
}
13041304

13051305
static void crypt_free_req(struct crypt_config *cc, void *req, struct bio *base_bio)
@@ -1409,7 +1409,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
14091409
if (unlikely(gfp_mask & __GFP_DIRECT_RECLAIM))
14101410
mutex_lock(&cc->bio_alloc_lock);
14111411

1412-
clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs);
1412+
clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, &cc->bs);
14131413
if (!clone)
14141414
goto out;
14151415

@@ -1418,7 +1418,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
14181418
remaining_size = size;
14191419

14201420
for (i = 0; i < nr_iovecs; i++) {
1421-
page = mempool_alloc(cc->page_pool, gfp_mask);
1421+
page = mempool_alloc(&cc->page_pool, gfp_mask);
14221422
if (!page) {
14231423
crypt_free_buffer_pages(cc, clone);
14241424
bio_put(clone);
@@ -1453,7 +1453,7 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone)
14531453

14541454
bio_for_each_segment_all(bv, clone, i) {
14551455
BUG_ON(!bv->bv_page);
1456-
mempool_free(bv->bv_page, cc->page_pool);
1456+
mempool_free(bv->bv_page, &cc->page_pool);
14571457
}
14581458
}
14591459

@@ -1492,7 +1492,7 @@ static void crypt_dec_pending(struct dm_crypt_io *io)
14921492
crypt_free_req(cc, io->ctx.r.req, base_bio);
14931493

14941494
if (unlikely(io->integrity_metadata_from_pool))
1495-
mempool_free(io->integrity_metadata, io->cc->tag_pool);
1495+
mempool_free(io->integrity_metadata, &io->cc->tag_pool);
14961496
else
14971497
kfree(io->integrity_metadata);
14981498

@@ -1565,7 +1565,7 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
15651565
* biovecs we don't need to worry about the block layer
15661566
* modifying the biovec array; so leverage bio_clone_fast().
15671567
*/
1568-
clone = bio_clone_fast(io->base_bio, gfp, cc->bs);
1568+
clone = bio_clone_fast(io->base_bio, gfp, &cc->bs);
15691569
if (!clone)
15701570
return 1;
15711571

@@ -2219,17 +2219,16 @@ static void crypt_dtr(struct dm_target *ti)
22192219

22202220
crypt_free_tfms(cc);
22212221

2222-
if (cc->bs)
2223-
bioset_free(cc->bs);
2222+
bioset_exit(&cc->bs);
22242223

2225-
mempool_destroy(cc->page_pool);
2226-
mempool_destroy(cc->req_pool);
2227-
mempool_destroy(cc->tag_pool);
2228-
2229-
if (cc->page_pool)
2224+
if (mempool_initialized(&cc->page_pool))
22302225
WARN_ON(percpu_counter_sum(&cc->n_allocated_pages) != 0);
22312226
percpu_counter_destroy(&cc->n_allocated_pages);
22322227

2228+
mempool_exit(&cc->page_pool);
2229+
mempool_exit(&cc->req_pool);
2230+
mempool_exit(&cc->tag_pool);
2231+
22332232
if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
22342233
cc->iv_gen_ops->dtr(cc);
22352234

@@ -2743,17 +2742,15 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
27432742
iv_size_padding = align_mask;
27442743
}
27452744

2746-
ret = -ENOMEM;
2747-
27482745
/* ...| IV + padding | original IV | original sec. number | bio tag offset | */
27492746
additional_req_size = sizeof(struct dm_crypt_request) +
27502747
iv_size_padding + cc->iv_size +
27512748
cc->iv_size +
27522749
sizeof(uint64_t) +
27532750
sizeof(unsigned int);
27542751

2755-
cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start + additional_req_size);
2756-
if (!cc->req_pool) {
2752+
ret = mempool_init_kmalloc_pool(&cc->req_pool, MIN_IOS, cc->dmreq_start + additional_req_size);
2753+
if (ret) {
27572754
ti->error = "Cannot allocate crypt request mempool";
27582755
goto bad;
27592756
}
@@ -2762,14 +2759,14 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
27622759
ALIGN(sizeof(struct dm_crypt_io) + cc->dmreq_start + additional_req_size,
27632760
ARCH_KMALLOC_MINALIGN);
27642761

2765-
cc->page_pool = mempool_create(BIO_MAX_PAGES, crypt_page_alloc, crypt_page_free, cc);
2766-
if (!cc->page_pool) {
2762+
ret = mempool_init(&cc->page_pool, BIO_MAX_PAGES, crypt_page_alloc, crypt_page_free, cc);
2763+
if (ret) {
27672764
ti->error = "Cannot allocate page mempool";
27682765
goto bad;
27692766
}
27702767

2771-
cc->bs = bioset_create(MIN_IOS, 0, BIOSET_NEED_BVECS);
2772-
if (!cc->bs) {
2768+
ret = bioset_init(&cc->bs, MIN_IOS, 0, BIOSET_NEED_BVECS);
2769+
if (ret) {
27732770
ti->error = "Cannot allocate crypt bioset";
27742771
goto bad;
27752772
}
@@ -2806,11 +2803,10 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
28062803
if (!cc->tag_pool_max_sectors)
28072804
cc->tag_pool_max_sectors = 1;
28082805

2809-
cc->tag_pool = mempool_create_kmalloc_pool(MIN_IOS,
2806+
ret = mempool_init_kmalloc_pool(&cc->tag_pool, MIN_IOS,
28102807
cc->tag_pool_max_sectors * cc->on_disk_tag_size);
2811-
if (!cc->tag_pool) {
2808+
if (ret) {
28122809
ti->error = "Cannot allocate integrity tags mempool";
2813-
ret = -ENOMEM;
28142810
goto bad;
28152811
}
28162812

@@ -2903,7 +2899,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio)
29032899
GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN)))) {
29042900
if (bio_sectors(bio) > cc->tag_pool_max_sectors)
29052901
dm_accept_partial_bio(bio, cc->tag_pool_max_sectors);
2906-
io->integrity_metadata = mempool_alloc(cc->tag_pool, GFP_NOIO);
2902+
io->integrity_metadata = mempool_alloc(&cc->tag_pool, GFP_NOIO);
29072903
io->integrity_metadata_from_pool = true;
29082904
}
29092905
}

0 commit comments

Comments
 (0)