From: Kent Overstreet <koverstreet@google.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
dm-devel@redhat.com, axboe@kernel.dk, tj@kernel.org,
"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: Re: [dm-devel] [PATCH v2 01/26] block: Convert integrity to bvec_alloc_bs(), and a bugfix
Date: Tue, 11 Sep 2012 13:48:44 -0700 [thread overview]
Message-ID: <20120911204844.GL19739@google.com> (raw)
In-Reply-To: <20120911203643.GC17113@redhat.com>
On Tue, Sep 11, 2012 at 04:36:43PM -0400, Vivek Goyal wrote:
> On Mon, Sep 10, 2012 at 05:22:12PM -0700, Kent Overstreet wrote:
> > This adds a pointer to the bvec array to struct bio_integrity_payload,
> > instead of the bvecs always being inline; then the bvecs are allocated
> > with bvec_alloc_bs().
>
> If you starting allocating bvec from same mempool for bio and bip,
> are you not breaking the principle of multiple allocations from a
> mempool and hence increasing the possibility of deadlock?
Argh, you're right. I should've thought about that.
It might be nice if mempools had some kind of internal watermark... here
we know we're only going to do at most 2 allocations from the same
mempool, so if we just passed the number we already had allocated to
mempool_alloc(), it could do the right thing and ensure we never
deadlocked.
I _think_ that'd let us make more efficient use of the reserve. But, for
just this it's not really worth the extra code, I think I'll just have
to add another mempool.
> Also there seems to be too much happening in this patch. Please break
> it down in 2. First fix the bio integrity bug you mentioned then
> introduce your changes on top.
Ok, I can do that.
> Thanks
> Vivek
>
> >
> > This is needed eventually for immutable bio vecs - immutable bvecs
> > aren't useful if we still have to copy them, hence the need for the
> > pointer. Less code is always nice too, though.
> >
> > Also fix an amusing bug in bio_integrity_split() - struct bio_pair
> > doesn't have the integrity bvecs after the bio_integrity_payloads, so
> > there was a buffer overrun. The code was confusing pointers with arrays.
> >
> > Signed-off-by: Kent Overstreet <koverstreet@google.com>
> > CC: Jens Axboe <axboe@kernel.dk>
> > CC: Martin K. Petersen <martin.petersen@oracle.com>
> > ---
> > fs/bio-integrity.c | 124 +++++++++++++++++-----------------------------------
> > include/linux/bio.h | 5 ++-
> > 2 files changed, 43 insertions(+), 86 deletions(-)
> >
> > diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
> > index a3f28f3..1d64f7f 100644
> > --- a/fs/bio-integrity.c
> > +++ b/fs/bio-integrity.c
> > @@ -27,48 +27,11 @@
> > #include <linux/workqueue.h>
> > #include <linux/slab.h>
> >
> > -struct integrity_slab {
> > - struct kmem_cache *slab;
> > - unsigned short nr_vecs;
> > - char name[8];
> > -};
> > -
> > -#define IS(x) { .nr_vecs = x, .name = "bip-"__stringify(x) }
> > -struct integrity_slab bip_slab[BIOVEC_NR_POOLS] __read_mostly = {
> > - IS(1), IS(4), IS(16), IS(64), IS(128), IS(BIO_MAX_PAGES),
> > -};
> > -#undef IS
> > +#define BIP_INLINE_VECS 4
> >
> > +static struct kmem_cache *bip_slab;
> > static struct workqueue_struct *kintegrityd_wq;
> >
> > -static inline unsigned int vecs_to_idx(unsigned int nr)
> > -{
> > - switch (nr) {
> > - case 1:
> > - return 0;
> > - case 2 ... 4:
> > - return 1;
> > - case 5 ... 16:
> > - return 2;
> > - case 17 ... 64:
> > - return 3;
> > - case 65 ... 128:
> > - return 4;
> > - case 129 ... BIO_MAX_PAGES:
> > - return 5;
> > - default:
> > - BUG();
> > - }
> > -}
> > -
> > -static inline int use_bip_pool(unsigned int idx)
> > -{
> > - if (idx == BIOVEC_MAX_IDX)
> > - return 1;
> > -
> > - return 0;
> > -}
> > -
> > /**
> > * bio_integrity_alloc - Allocate integrity payload and attach it to bio
> > * @bio: bio to attach integrity metadata to
> > @@ -84,37 +47,38 @@ struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
> > unsigned int nr_vecs)
> > {
> > struct bio_integrity_payload *bip;
> > - unsigned int idx = vecs_to_idx(nr_vecs);
> > struct bio_set *bs = bio->bi_pool;
> > + unsigned long idx = BIO_POOL_NONE;
> > + unsigned inline_vecs;
> > +
> > + if (!bs) {
> > + bip = kmalloc(sizeof(struct bio_integrity_payload) +
> > + sizeof(struct bio_vec) * nr_vecs, gfp_mask);
> > + inline_vecs = nr_vecs;
> > + } else {
> > + bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask);
> > + inline_vecs = BIP_INLINE_VECS;
> > + }
> >
> > - if (!bs)
> > - bs = fs_bio_set;
> > -
> > - BUG_ON(bio == NULL);
> > - bip = NULL;
> > + if (unlikely(!bip))
> > + return NULL;
> >
> > - /* Lower order allocations come straight from slab */
> > - if (!use_bip_pool(idx))
> > - bip = kmem_cache_alloc(bip_slab[idx].slab, gfp_mask);
> > + memset(bip, 0, sizeof(struct bio_integrity_payload));
> >
> > - /* Use mempool if lower order alloc failed or max vecs were requested */
> > - if (bip == NULL) {
> > - idx = BIOVEC_MAX_IDX; /* so we free the payload properly later */
> > - bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask);
> > -
> > - if (unlikely(bip == NULL)) {
> > - printk(KERN_ERR "%s: could not alloc bip\n", __func__);
> > - return NULL;
> > - }
> > + if (nr_vecs > inline_vecs) {
> > + bip->bip_vec = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, bs);
> > + if (!bip->bip_vec)
> > + goto err;
> > }
> >
> > - memset(bip, 0, sizeof(*bip));
> > -
> > bip->bip_slab = idx;
> > bip->bip_bio = bio;
> > bio->bi_integrity = bip;
> >
> > return bip;
> > +err:
> > + mempool_free(bip, bs->bio_integrity_pool);
> > + return NULL;
> > }
> > EXPORT_SYMBOL(bio_integrity_alloc);
> >
> > @@ -130,20 +94,19 @@ void bio_integrity_free(struct bio *bio)
> > struct bio_integrity_payload *bip = bio->bi_integrity;
> > struct bio_set *bs = bio->bi_pool;
> >
> > - if (!bs)
> > - bs = fs_bio_set;
> > -
> > - BUG_ON(bip == NULL);
> > -
> > /* A cloned bio doesn't own the integrity metadata */
> > if (!bio_flagged(bio, BIO_CLONED) && !bio_flagged(bio, BIO_FS_INTEGRITY)
> > && bip->bip_buf != NULL)
> > kfree(bip->bip_buf);
> >
> > - if (use_bip_pool(bip->bip_slab))
> > + if (bs) {
> > + if (bip->bip_slab != BIO_POOL_NONE)
> > + bvec_free_bs(bs, bip->bip_vec, bip->bip_slab);
> > +
> > mempool_free(bip, bs->bio_integrity_pool);
> > - else
> > - kmem_cache_free(bip_slab[bip->bip_slab].slab, bip);
> > + } else {
> > + kfree(bip);
> > + }
> >
> > bio->bi_integrity = NULL;
> > }
> > @@ -697,8 +660,8 @@ void bio_integrity_split(struct bio *bio, struct bio_pair *bp, int sectors)
> > bp->iv1 = bip->bip_vec[0];
> > bp->iv2 = bip->bip_vec[0];
> >
> > - bp->bip1.bip_vec[0] = bp->iv1;
> > - bp->bip2.bip_vec[0] = bp->iv2;
> > + bp->bip1.bip_vec = &bp->iv1;
> > + bp->bip2.bip_vec = &bp->iv2;
> >
> > bp->iv1.bv_len = sectors * bi->tuple_size;
> > bp->iv2.bv_offset += sectors * bi->tuple_size;
> > @@ -746,13 +709,10 @@ EXPORT_SYMBOL(bio_integrity_clone);
> >
> > int bioset_integrity_create(struct bio_set *bs, int pool_size)
> > {
> > - unsigned int max_slab = vecs_to_idx(BIO_MAX_PAGES);
> > -
> > if (bs->bio_integrity_pool)
> > return 0;
> >
> > - bs->bio_integrity_pool =
> > - mempool_create_slab_pool(pool_size, bip_slab[max_slab].slab);
> > + bs->bio_integrity_pool = mempool_create_slab_pool(pool_size, bip_slab);
> >
> > if (!bs->bio_integrity_pool)
> > return -1;
> > @@ -770,8 +730,6 @@ EXPORT_SYMBOL(bioset_integrity_free);
> >
> > void __init bio_integrity_init(void)
> > {
> > - unsigned int i;
> > -
> > /*
> > * kintegrityd won't block much but may burn a lot of CPU cycles.
> > * Make it highpri CPU intensive wq with max concurrency of 1.
> > @@ -781,14 +739,10 @@ void __init bio_integrity_init(void)
> > if (!kintegrityd_wq)
> > panic("Failed to create kintegrityd\n");
> >
> > - for (i = 0 ; i < BIOVEC_NR_POOLS ; i++) {
> > - unsigned int size;
> > -
> > - size = sizeof(struct bio_integrity_payload)
> > - + bip_slab[i].nr_vecs * sizeof(struct bio_vec);
> > -
> > - bip_slab[i].slab =
> > - kmem_cache_create(bip_slab[i].name, size, 0,
> > - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
> > - }
> > + bip_slab = kmem_cache_create("bio_integrity_payload",
> > + sizeof(struct bio_integrity_payload) +
> > + sizeof(struct bio_vec) * BIP_INLINE_VECS,
> > + 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
> > + if (!bip_slab)
> > + panic("Failed to create slab\n");
> > }
> > diff --git a/include/linux/bio.h b/include/linux/bio.h
> > index c32ea0d..7873465 100644
> > --- a/include/linux/bio.h
> > +++ b/include/linux/bio.h
> > @@ -182,7 +182,10 @@ struct bio_integrity_payload {
> > unsigned short bip_idx; /* current bip_vec index */
> >
> > struct work_struct bip_work; /* I/O completion */
> > - struct bio_vec bip_vec[0]; /* embedded bvec array */
> > +
> > + struct bio_vec *bip_vec;
> > + struct bio_vec bip_inline_vecs[0];/* embedded bvec array */
> > +
> > };
> > #endif /* CONFIG_BLK_DEV_INTEGRITY */
> >
> > --
> > 1.7.12
> >
> > --
> > dm-devel mailing list
> > dm-devel@redhat.com
> > https://www.redhat.com/mailman/listinfo/dm-devel
next prev parent reply other threads:[~2012-09-11 20:48 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-11 0:22 [PATCH v2 00/26] Prep work for immutable bio vecs Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 01/26] block: Convert integrity to bvec_alloc_bs(), and a bugfix Kent Overstreet
[not found] ` <1347322957-25260-2-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 20:36 ` [dm-devel] " Vivek Goyal
2012-09-11 20:48 ` Kent Overstreet [this message]
2012-09-11 22:07 ` Kent Overstreet
[not found] ` <20120911220750.GM19739-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-12 19:39 ` Martin K. Petersen
[not found] ` <yq1wqzzrpy1.fsf-+q57XtR/GgMb6DWv4sQWN6xOck334EZe@public.gmane.org>
2012-09-17 21:08 ` Kent Overstreet
2012-09-20 21:53 ` Tejun Heo
2012-09-11 0:22 ` [PATCH v2 02/26] block: Add bio_advance() Kent Overstreet
[not found] ` <1347322957-25260-3-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 21:58 ` Tejun Heo
2012-09-20 23:13 ` Kent Overstreet
[not found] ` <20120920231308.GB5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:25 ` Tejun Heo
[not found] ` <20120920232506.GI7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:38 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 03/26] block: Refactor blk_update_request() Kent Overstreet
[not found] ` <1347322957-25260-4-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:20 ` Tejun Heo
2012-09-20 23:36 ` Kent Overstreet
[not found] ` <20120920233632.GC5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:41 ` Tejun Heo
[not found] ` <20120920234133.GM7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:50 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 04/26] md: Convert md_trim_bio() to use bio_advance() Kent Overstreet
[not found] ` <1347322957-25260-5-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:27 ` Tejun Heo
2012-09-11 0:22 ` [PATCH v2 05/26] block: Add bio_end() Kent Overstreet
[not found] ` <1347322957-25260-6-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-17 9:17 ` Steven Whitehouse
2012-09-20 23:32 ` Tejun Heo
[not found] ` <20120920233225.GK7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:44 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 06/26] block: Use bio_sectors() more consistently Kent Overstreet
[not found] ` <1347322957-25260-7-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:36 ` Tejun Heo
[not found] ` <20120920233618.GL7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:47 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 07/26] block: Don't use bi_idx in bio_split() or require it to be 0 Kent Overstreet
[not found] ` <1347322957-25260-8-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:45 ` Tejun Heo
[not found] ` <20120920234544.GN7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:00 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 09/26] block: Remove some unnecessary bi_vcnt usage Kent Overstreet
[not found] ` <1347322957-25260-10-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:51 ` Tejun Heo
2012-09-11 0:22 ` [PATCH v2 10/26] block: Add submit_bio_wait(), remove from md Kent Overstreet
[not found] ` <1347322957-25260-11-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:56 ` Tejun Heo
[not found] ` <20120920235643.GQ7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:06 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 11/26] raid10: Use bio_reset() Kent Overstreet
2012-09-20 23:59 ` Tejun Heo
2012-09-11 0:22 ` [PATCH v2 13/26] raid5: use bio_reset() Kent Overstreet
[not found] ` <1347322957-25260-14-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 5:03 ` NeilBrown
[not found] ` <20120911150326.79f066c0-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-09-11 19:26 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 14/26] raid1: Refactor narrow_write_error() to not use bi_idx Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 15/26] block: Add bio_copy_data() Kent Overstreet
[not found] ` <1347322957-25260-16-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:06 ` Tejun Heo
2012-09-21 0:09 ` Kent Overstreet
[not found] ` <20120921000945.GK5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:15 ` Tejun Heo
2012-09-21 0:09 ` Tejun Heo
[not found] ` <20120921000947.GT7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:13 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 16/26] pktcdvd: use bio_copy_data() Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 17/26] pktcdvd: Use bio_reset() in disabled code to kill bi_idx usage Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 18/26] raid1: use bio_copy_data() Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 20/26] block: Add bio_for_each_segment_all() Kent Overstreet
[not found] ` <1347322957-25260-21-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:35 ` Tejun Heo
2012-09-11 0:22 ` [PATCH v2 22/26] block: Add bio_alloc_pages() Kent Overstreet
[not found] ` <1347322957-25260-23-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:47 ` Tejun Heo
[not found] ` <20120921004711.GZ7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 4:50 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 24/26] block: Add an explicit bio flag for bios that own their bvec Kent Overstreet
[not found] ` <1347322957-25260-1-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 0:22 ` [PATCH v2 08/26] block: Remove bi_idx references Kent Overstreet
[not found] ` <1347322957-25260-9-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:49 ` Tejun Heo
2012-09-21 0:04 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 12/26] raid1: use bio_reset() Kent Overstreet
[not found] ` <1347322957-25260-13-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 4:59 ` NeilBrown
2012-09-11 18:28 ` Kent Overstreet
[not found] ` <20120911182825.GG19739-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 21:17 ` NeilBrown
2012-09-11 0:22 ` [PATCH v2 19/26] bounce: Refactor __blk_queue_bounce to not use bi_io_vec Kent Overstreet
[not found] ` <1347322957-25260-20-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:25 ` Tejun Heo
2012-09-21 0:29 ` Kent Overstreet
2012-09-21 0:27 ` Tejun Heo
2012-09-21 0:34 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 21/26] block: Convert some code to bio_for_each_segment_all() Kent Overstreet
[not found] ` <1347322957-25260-22-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:38 ` Tejun Heo
[not found] ` <20120921003832.GY7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:50 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 23/26] raid1: use bio_alloc_pages() Kent Overstreet
[not found] ` <1347322957-25260-24-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 0:48 ` Tejun Heo
[not found] ` <20120921004827.GA7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21 4:51 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 25/26] bio-integrity: Add explicit field for owner of bip_buf Kent Overstreet
[not found] ` <1347322957-25260-26-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-12 19:41 ` Martin K. Petersen
[not found] ` <yq1sjanrpu7.fsf-+q57XtR/GgMb6DWv4sQWN6xOck334EZe@public.gmane.org>
2012-09-17 21:09 ` Kent Overstreet
2012-09-11 0:22 ` [PATCH v2 26/26] block: Add BIO_SUBMITTED flag, kill BIO_CLONED Kent Overstreet
2012-09-11 5:22 ` [PATCH v2 00/26] Prep work for immutable bio vecs NeilBrown
2012-09-20 23:22 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120911204844.GL19739@google.com \
--to=koverstreet@google.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@redhat.com \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=tj@kernel.org \
--cc=vgoyal@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).