Skip to content

Commit d19936a

Browse files
koverstreetaxboe
authored andcommitted
bcache: convert to bioset_init()/mempool_init()
Convert bcache to embedded bio sets. Reviewed-by: Coly Li <[email protected]> Signed-off-by: Kent Overstreet <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b906bbb commit d19936a

File tree

7 files changed

+37
-52
lines changed

7 files changed

+37
-52
lines changed

drivers/md/bcache/bcache.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ struct bcache_device {
269269
atomic_t *stripe_sectors_dirty;
270270
unsigned long *full_dirty_stripes;
271271

272-
struct bio_set *bio_split;
272+
struct bio_set bio_split;
273273

274274
unsigned data_csum:1;
275275

@@ -530,9 +530,9 @@ struct cache_set {
530530
struct closure sb_write;
531531
struct semaphore sb_write_mutex;
532532

533-
mempool_t *search;
534-
mempool_t *bio_meta;
535-
struct bio_set *bio_split;
533+
mempool_t search;
534+
mempool_t bio_meta;
535+
struct bio_set bio_split;
536536

537537
/* For the btree cache */
538538
struct shrinker shrink;
@@ -657,7 +657,7 @@ struct cache_set {
657657
* A btree node on disk could have too many bsets for an iterator to fit
658658
* on the stack - have to dynamically allocate them
659659
*/
660-
mempool_t *fill_iter;
660+
mempool_t fill_iter;
661661

662662
struct bset_sort_state sort;
663663

drivers/md/bcache/bset.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,7 @@ struct bkey *bch_btree_iter_next_filter(struct btree_iter *iter,
11181118

11191119
void bch_bset_sort_state_free(struct bset_sort_state *state)
11201120
{
1121-
if (state->pool)
1122-
mempool_destroy(state->pool);
1121+
mempool_exit(&state->pool);
11231122
}
11241123

11251124
int bch_bset_sort_state_init(struct bset_sort_state *state, unsigned page_order)
@@ -1129,11 +1128,7 @@ int bch_bset_sort_state_init(struct bset_sort_state *state, unsigned page_order)
11291128
state->page_order = page_order;
11301129
state->crit_factor = int_sqrt(1 << page_order);
11311130

1132-
state->pool = mempool_create_page_pool(1, page_order);
1133-
if (!state->pool)
1134-
return -ENOMEM;
1135-
1136-
return 0;
1131+
return mempool_init_page_pool(&state->pool, 1, page_order);
11371132
}
11381133
EXPORT_SYMBOL(bch_bset_sort_state_init);
11391134

@@ -1191,7 +1186,7 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter,
11911186

11921187
BUG_ON(order > state->page_order);
11931188

1194-
outp = mempool_alloc(state->pool, GFP_NOIO);
1189+
outp = mempool_alloc(&state->pool, GFP_NOIO);
11951190
out = page_address(outp);
11961191
used_mempool = true;
11971192
order = state->page_order;
@@ -1220,7 +1215,7 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter,
12201215
}
12211216

12221217
if (used_mempool)
1223-
mempool_free(virt_to_page(out), state->pool);
1218+
mempool_free(virt_to_page(out), &state->pool);
12241219
else
12251220
free_pages((unsigned long) out, order);
12261221

drivers/md/bcache/bset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static inline struct bkey *bch_bset_search(struct btree_keys *b,
347347
/* Sorting */
348348

349349
struct bset_sort_state {
350-
mempool_t *pool;
350+
mempool_t pool;
351351

352352
unsigned page_order;
353353
unsigned crit_factor;

drivers/md/bcache/btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void bch_btree_node_read_done(struct btree *b)
204204
struct bset *i = btree_bset_first(b);
205205
struct btree_iter *iter;
206206

207-
iter = mempool_alloc(b->c->fill_iter, GFP_NOIO);
207+
iter = mempool_alloc(&b->c->fill_iter, GFP_NOIO);
208208
iter->size = b->c->sb.bucket_size / b->c->sb.block_size;
209209
iter->used = 0;
210210

@@ -271,7 +271,7 @@ void bch_btree_node_read_done(struct btree *b)
271271
bch_bset_init_next(&b->keys, write_block(b),
272272
bset_magic(&b->c->sb));
273273
out:
274-
mempool_free(iter, b->c->fill_iter);
274+
mempool_free(iter, &b->c->fill_iter);
275275
return;
276276
err:
277277
set_btree_node_io_error(b);

drivers/md/bcache/io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
void bch_bbio_free(struct bio *bio, struct cache_set *c)
1818
{
1919
struct bbio *b = container_of(bio, struct bbio, bio);
20-
mempool_free(b, c->bio_meta);
20+
mempool_free(b, &c->bio_meta);
2121
}
2222

2323
struct bio *bch_bbio_alloc(struct cache_set *c)
2424
{
25-
struct bbio *b = mempool_alloc(c->bio_meta, GFP_NOIO);
25+
struct bbio *b = mempool_alloc(&c->bio_meta, GFP_NOIO);
2626
struct bio *bio = &b->bio;
2727

2828
bio_init(bio, bio->bi_inline_vecs, bucket_pages(c));

drivers/md/bcache/request.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void bch_data_insert_start(struct closure *cl)
213213
do {
214214
unsigned i;
215215
struct bkey *k;
216-
struct bio_set *split = op->c->bio_split;
216+
struct bio_set *split = &op->c->bio_split;
217217

218218
/* 1 for the device pointer and 1 for the chksum */
219219
if (bch_keylist_realloc(&op->insert_keys,
@@ -548,7 +548,7 @@ static int cache_lookup_fn(struct btree_op *op, struct btree *b, struct bkey *k)
548548

549549
n = bio_next_split(bio, min_t(uint64_t, INT_MAX,
550550
KEY_OFFSET(k) - bio->bi_iter.bi_sector),
551-
GFP_NOIO, s->d->bio_split);
551+
GFP_NOIO, &s->d->bio_split);
552552

553553
bio_key = &container_of(n, struct bbio, bio)->key;
554554
bch_bkey_copy_single_ptr(bio_key, k, ptr);
@@ -707,15 +707,15 @@ static void search_free(struct closure *cl)
707707

708708
bio_complete(s);
709709
closure_debug_destroy(cl);
710-
mempool_free(s, s->d->c->search);
710+
mempool_free(s, &s->d->c->search);
711711
}
712712

713713
static inline struct search *search_alloc(struct bio *bio,
714714
struct bcache_device *d)
715715
{
716716
struct search *s;
717717

718-
s = mempool_alloc(d->c->search, GFP_NOIO);
718+
s = mempool_alloc(&d->c->search, GFP_NOIO);
719719

720720
closure_init(&s->cl, NULL);
721721
do_bio_hook(s, bio, request_endio);
@@ -864,7 +864,7 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
864864
s->cache_missed = 1;
865865

866866
if (s->cache_miss || s->iop.bypass) {
867-
miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split);
867+
miss = bio_next_split(bio, sectors, GFP_NOIO, &s->d->bio_split);
868868
ret = miss == bio ? MAP_DONE : MAP_CONTINUE;
869869
goto out_submit;
870870
}
@@ -887,14 +887,14 @@ static int cached_dev_cache_miss(struct btree *b, struct search *s,
887887

888888
s->iop.replace = true;
889889

890-
miss = bio_next_split(bio, sectors, GFP_NOIO, s->d->bio_split);
890+
miss = bio_next_split(bio, sectors, GFP_NOIO, &s->d->bio_split);
891891

892892
/* btree_search_recurse()'s btree iterator is no good anymore */
893893
ret = miss == bio ? MAP_DONE : -EINTR;
894894

895895
cache_bio = bio_alloc_bioset(GFP_NOWAIT,
896896
DIV_ROUND_UP(s->insert_bio_sectors, PAGE_SECTORS),
897-
dc->disk.bio_split);
897+
&dc->disk.bio_split);
898898
if (!cache_bio)
899899
goto out_submit;
900900

@@ -1008,7 +1008,7 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
10081008
struct bio *flush;
10091009

10101010
flush = bio_alloc_bioset(GFP_NOIO, 0,
1011-
dc->disk.bio_split);
1011+
&dc->disk.bio_split);
10121012
if (!flush) {
10131013
s->iop.status = BLK_STS_RESOURCE;
10141014
goto insert_data;
@@ -1021,7 +1021,7 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
10211021
closure_bio_submit(s->iop.c, flush, cl);
10221022
}
10231023
} else {
1024-
s->iop.bio = bio_clone_fast(bio, GFP_NOIO, dc->disk.bio_split);
1024+
s->iop.bio = bio_clone_fast(bio, GFP_NOIO, &dc->disk.bio_split);
10251025
/* I/O request sent to backing device */
10261026
bio->bi_end_io = backing_request_endio;
10271027
closure_bio_submit(s->iop.c, bio, cl);

drivers/md/bcache/super.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,7 @@ static void bcache_device_free(struct bcache_device *d)
753753
put_disk(d->disk);
754754
}
755755

756-
if (d->bio_split)
757-
bioset_free(d->bio_split);
756+
bioset_exit(&d->bio_split);
758757
kvfree(d->full_dirty_stripes);
759758
kvfree(d->stripe_sectors_dirty);
760759

@@ -796,9 +795,8 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
796795
if (idx < 0)
797796
return idx;
798797

799-
if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio),
800-
BIOSET_NEED_BVECS |
801-
BIOSET_NEED_RESCUER)) ||
798+
if (bioset_init(&d->bio_split, 4, offsetof(struct bbio, bio),
799+
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER) ||
802800
!(d->disk = alloc_disk(BCACHE_MINORS))) {
803801
ida_simple_remove(&bcache_device_idx, idx);
804802
return -ENOMEM;
@@ -1500,14 +1498,10 @@ static void cache_set_free(struct closure *cl)
15001498

15011499
if (c->moving_gc_wq)
15021500
destroy_workqueue(c->moving_gc_wq);
1503-
if (c->bio_split)
1504-
bioset_free(c->bio_split);
1505-
if (c->fill_iter)
1506-
mempool_destroy(c->fill_iter);
1507-
if (c->bio_meta)
1508-
mempool_destroy(c->bio_meta);
1509-
if (c->search)
1510-
mempool_destroy(c->search);
1501+
bioset_exit(&c->bio_split);
1502+
mempool_exit(&c->fill_iter);
1503+
mempool_exit(&c->bio_meta);
1504+
mempool_exit(&c->search);
15111505
kfree(c->devices);
15121506

15131507
mutex_lock(&bch_register_lock);
@@ -1718,21 +1712,17 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
17181712
INIT_LIST_HEAD(&c->btree_cache_freed);
17191713
INIT_LIST_HEAD(&c->data_buckets);
17201714

1721-
c->search = mempool_create_slab_pool(32, bch_search_cache);
1722-
if (!c->search)
1723-
goto err;
1724-
17251715
iter_size = (sb->bucket_size / sb->block_size + 1) *
17261716
sizeof(struct btree_iter_set);
17271717

17281718
if (!(c->devices = kzalloc(c->nr_uuids * sizeof(void *), GFP_KERNEL)) ||
1729-
!(c->bio_meta = mempool_create_kmalloc_pool(2,
1730-
sizeof(struct bbio) + sizeof(struct bio_vec) *
1731-
bucket_pages(c))) ||
1732-
!(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) ||
1733-
!(c->bio_split = bioset_create(4, offsetof(struct bbio, bio),
1734-
BIOSET_NEED_BVECS |
1735-
BIOSET_NEED_RESCUER)) ||
1719+
mempool_init_slab_pool(&c->search, 32, bch_search_cache) ||
1720+
mempool_init_kmalloc_pool(&c->bio_meta, 2,
1721+
sizeof(struct bbio) + sizeof(struct bio_vec) *
1722+
bucket_pages(c)) ||
1723+
mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size) ||
1724+
bioset_init(&c->bio_split, 4, offsetof(struct bbio, bio),
1725+
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER) ||
17361726
!(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
17371727
!(c->moving_gc_wq = alloc_workqueue("bcache_gc",
17381728
WQ_MEM_RECLAIM, 0)) ||

0 commit comments

Comments
 (0)