Skip to content

Commit ed9c47b

Browse files
author
Kent Overstreet
committed
bcache: Kill unaligned bvec hack
Bcache has a hack to avoid cloning the biovec if it's all full pages - but with immutable biovecs coming this won't be necessary anymore. For now, we remove the special case and always clone the bvec array so that the immutable biovec patches are simpler. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 2c30c71 commit ed9c47b

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

drivers/md/bcache/bcache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ struct bcache_device {
279279
unsigned long sectors_dirty_last;
280280
long sectors_dirty_derivative;
281281

282-
mempool_t *unaligned_bvec;
283282
struct bio_set *bio_split;
284283

285284
unsigned data_csum:1;

drivers/md/bcache/request.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,14 @@ struct search {
606606
unsigned insert_bio_sectors;
607607

608608
unsigned recoverable:1;
609-
unsigned unaligned_bvec:1;
610609
unsigned write:1;
611610
unsigned read_dirty_data:1;
612611

613612
unsigned long start_time;
614613

615614
struct btree_op op;
616615
struct data_insert_op iop;
616+
struct bio_vec bv[BIO_MAX_PAGES];
617617
};
618618

619619
static void bch_cache_read_endio(struct bio *bio, int error)
@@ -759,10 +759,14 @@ static void bio_complete(struct search *s)
759759
static void do_bio_hook(struct search *s)
760760
{
761761
struct bio *bio = &s->bio.bio;
762-
memcpy(bio, s->orig_bio, sizeof(struct bio));
763762

763+
bio_init(bio);
764+
bio->bi_io_vec = s->bv;
765+
bio->bi_max_vecs = BIO_MAX_PAGES;
766+
__bio_clone(bio, s->orig_bio);
764767
bio->bi_end_io = request_endio;
765768
bio->bi_private = &s->cl;
769+
766770
atomic_set(&bio->bi_cnt, 3);
767771
}
768772

@@ -774,17 +778,13 @@ static void search_free(struct closure *cl)
774778
if (s->iop.bio)
775779
bio_put(s->iop.bio);
776780

777-
if (s->unaligned_bvec)
778-
mempool_free(s->bio.bio.bi_io_vec, s->d->unaligned_bvec);
779-
780781
closure_debug_destroy(cl);
781782
mempool_free(s, s->d->c->search);
782783
}
783784

784785
static struct search *search_alloc(struct bio *bio, struct bcache_device *d)
785786
{
786787
struct search *s;
787-
struct bio_vec *bv;
788788

789789
s = mempool_alloc(d->c->search, GFP_NOIO);
790790
memset(s, 0, offsetof(struct search, iop.insert_keys));
@@ -803,15 +803,6 @@ static struct search *search_alloc(struct bio *bio, struct bcache_device *d)
803803
s->start_time = jiffies;
804804
do_bio_hook(s);
805805

806-
if (bio->bi_size != bio_segments(bio) * PAGE_SIZE) {
807-
bv = mempool_alloc(d->unaligned_bvec, GFP_NOIO);
808-
memcpy(bv, bio_iovec(bio),
809-
sizeof(struct bio_vec) * bio_segments(bio));
810-
811-
s->bio.bio.bi_io_vec = bv;
812-
s->unaligned_bvec = 1;
813-
}
814-
815806
return s;
816807
}
817808

@@ -850,26 +841,13 @@ static void cached_dev_read_error(struct closure *cl)
850841
{
851842
struct search *s = container_of(cl, struct search, cl);
852843
struct bio *bio = &s->bio.bio;
853-
struct bio_vec *bv;
854-
int i;
855844

856845
if (s->recoverable) {
857846
/* Retry from the backing device: */
858847
trace_bcache_read_retry(s->orig_bio);
859848

860849
s->iop.error = 0;
861-
bv = s->bio.bio.bi_io_vec;
862850
do_bio_hook(s);
863-
s->bio.bio.bi_io_vec = bv;
864-
865-
if (!s->unaligned_bvec)
866-
bio_for_each_segment(bv, s->orig_bio, i)
867-
bv->bv_offset = 0, bv->bv_len = PAGE_SIZE;
868-
else
869-
memcpy(s->bio.bio.bi_io_vec,
870-
bio_iovec(s->orig_bio),
871-
sizeof(struct bio_vec) *
872-
bio_segments(s->orig_bio));
873851

874852
/* XXX: invalidate cache */
875853

@@ -905,8 +883,7 @@ static void cached_dev_read_done(struct closure *cl)
905883
s->cache_miss = NULL;
906884
}
907885

908-
if (verify(dc, &s->bio.bio) && s->recoverable &&
909-
!s->unaligned_bvec && !s->read_dirty_data)
886+
if (verify(dc, &s->bio.bio) && s->recoverable && !s->read_dirty_data)
910887
bch_data_verify(dc, s->orig_bio);
911888

912889
bio_complete(s);

drivers/md/bcache/super.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,6 @@ static void bcache_device_free(struct bcache_device *d)
739739
}
740740

741741
bio_split_pool_free(&d->bio_split_hook);
742-
if (d->unaligned_bvec)
743-
mempool_destroy(d->unaligned_bvec);
744742
if (d->bio_split)
745743
bioset_free(d->bio_split);
746744
if (is_vmalloc_addr(d->full_dirty_stripes))
@@ -793,8 +791,6 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
793791
return minor;
794792

795793
if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
796-
!(d->unaligned_bvec = mempool_create_kmalloc_pool(1,
797-
sizeof(struct bio_vec) * BIO_MAX_PAGES)) ||
798794
bio_split_pool_init(&d->bio_split_hook) ||
799795
!(d->disk = alloc_disk(1))) {
800796
ida_simple_remove(&bcache_minor, minor);

0 commit comments

Comments
 (0)