Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <kmo@daterainc.com>

+7 -35
-1
drivers/md/bcache/bcache.h
··· 279 279 unsigned long sectors_dirty_last; 280 280 long sectors_dirty_derivative; 281 281 282 - mempool_t *unaligned_bvec; 283 282 struct bio_set *bio_split; 284 283 285 284 unsigned data_csum:1;
+7 -30
drivers/md/bcache/request.c
··· 606 606 unsigned insert_bio_sectors; 607 607 608 608 unsigned recoverable:1; 609 - unsigned unaligned_bvec:1; 610 609 unsigned write:1; 611 610 unsigned read_dirty_data:1; 612 611 ··· 613 614 614 615 struct btree_op op; 615 616 struct data_insert_op iop; 617 + struct bio_vec bv[BIO_MAX_PAGES]; 616 618 }; 617 619 618 620 static void bch_cache_read_endio(struct bio *bio, int error) ··· 759 759 static void do_bio_hook(struct search *s) 760 760 { 761 761 struct bio *bio = &s->bio.bio; 762 - memcpy(bio, s->orig_bio, sizeof(struct bio)); 763 762 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); 764 767 bio->bi_end_io = request_endio; 765 768 bio->bi_private = &s->cl; 769 + 766 770 atomic_set(&bio->bi_cnt, 3); 767 771 } 768 772 ··· 778 774 if (s->iop.bio) 779 775 bio_put(s->iop.bio); 780 776 781 - if (s->unaligned_bvec) 782 - mempool_free(s->bio.bio.bi_io_vec, s->d->unaligned_bvec); 783 - 784 777 closure_debug_destroy(cl); 785 778 mempool_free(s, s->d->c->search); 786 779 } ··· 785 784 static struct search *search_alloc(struct bio *bio, struct bcache_device *d) 786 785 { 787 786 struct search *s; 788 - struct bio_vec *bv; 789 787 790 788 s = mempool_alloc(d->c->search, GFP_NOIO); 791 789 memset(s, 0, offsetof(struct search, iop.insert_keys)); ··· 802 802 s->recoverable = 1; 803 803 s->start_time = jiffies; 804 804 do_bio_hook(s); 805 - 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 805 815 806 return s; 816 807 } ··· 841 850 { 842 851 struct search *s = container_of(cl, struct search, cl); 843 852 struct bio *bio = &s->bio.bio; 844 - struct bio_vec *bv; 845 - int i; 846 853 847 854 if (s->recoverable) { 848 855 /* Retry from the backing device: */ 849 856 trace_bcache_read_retry(s->orig_bio); 850 857 851 858 s->iop.error = 0; 852 - bv = s->bio.bio.bi_io_vec; 853 859 do_bio_hook(s); 854 - s->bio.bio.bi_io_vec = bv; 855 - 856 - if (!s->unaligned_bvec) 857 - bio_for_each_segment(bv, s->orig_bio, i) 858 - bv->bv_offset = 0, bv->bv_len = PAGE_SIZE; 859 - else 860 - memcpy(s->bio.bio.bi_io_vec, 861 - bio_iovec(s->orig_bio), 862 - sizeof(struct bio_vec) * 863 - bio_segments(s->orig_bio)); 864 860 865 861 /* XXX: invalidate cache */ 866 862 ··· 883 905 s->cache_miss = NULL; 884 906 } 885 907 886 - if (verify(dc, &s->bio.bio) && s->recoverable && 887 - !s->unaligned_bvec && !s->read_dirty_data) 908 + if (verify(dc, &s->bio.bio) && s->recoverable && !s->read_dirty_data) 888 909 bch_data_verify(dc, s->orig_bio); 889 910 890 911 bio_complete(s);
-4
drivers/md/bcache/super.c
··· 739 739 } 740 740 741 741 bio_split_pool_free(&d->bio_split_hook); 742 - if (d->unaligned_bvec) 743 - mempool_destroy(d->unaligned_bvec); 744 742 if (d->bio_split) 745 743 bioset_free(d->bio_split); 746 744 if (is_vmalloc_addr(d->full_dirty_stripes)) ··· 791 793 return minor; 792 794 793 795 if (!(d->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || 794 - !(d->unaligned_bvec = mempool_create_kmalloc_pool(1, 795 - sizeof(struct bio_vec) * BIO_MAX_PAGES)) || 796 796 bio_split_pool_init(&d->bio_split_hook) || 797 797 !(d->disk = alloc_disk(1))) { 798 798 ida_simple_remove(&bcache_minor, minor);