From: Kent Overstreet <koverstreet@google.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
dm-devel@redhat.com, axboe@kernel.dk, agk@redhat.com,
neilb@suse.de, drbd-dev@lists.linbit.com, vgoyal@redhat.com,
mpatocka@redhat.com, sage@newdream.net, yehuda@hq.newdream.net
Subject: [PATCH] Consolidate bio_clone_bioset(), bio_kmalloc()
Date: Wed, 8 Aug 2012 19:38:11 -0700 [thread overview]
Message-ID: <20120809023811.GJ7262@moria.home.lan> (raw)
In-Reply-To: <20120808231552.GJ6983@dhcp-172-17-108-109.mtv.corp.google.com>
On Wed, Aug 08, 2012 at 04:15:52PM -0700, Tejun Heo wrote:
> > +struct bio *bio_clone_kmalloc(struct bio *bio, gfp_t gfp_mask)
> > +{
> > + struct bio *b = bio_kmalloc(gfp_mask, bio->bi_max_vecs);
>
> Can't we use %NULL bioset as an indication to allocate from kmalloc
> instead of duping interfaces like this?
So, if bio_clone_bioset(gfp, nr_iovecs, BIO_KMALLOC_POOL) just does
bio_kmalloc(), the rest just falls out naturally.
We could do this by either just having bio_clone_bioset() call
bio_kmalloc(), or consolidate them both into a single function.
I'm leaning towards the latter, because while looking at it I noticed a
couple subtle behavioural differences.
* bio_kmalloc(GFP_KERNEL, 0) sets bi_io_vec = bi_inline_vecs,
bio_alloc_bioset sets it to NULL. This is a bug waiting to happen, if it
isn't one already - bi_io_vec != NULL is exactly what bio_has_data()
checks.
* bio_alloc_bioset() could return a bio with bi_max_vecs greater than
requested if you asked for a bio with fewer than BIO_INLINE_VECS.
Unlikely to ever be a real problem, but subtle enough that I wouldn't
bet too much against it.
* bio_kmalloc() fails if asked for more than UIO_MAXIOV bvecs (wtf!?),
which is 1024; bio_alloc_bioset fails if asked for more than
BIO_MAX_PAGES (which is 256, and it'd probably take you a bit to see
where/why it fails).
So here's my initial stab at it. Tell me if you think this is too
contorted:
diff --git a/fs/bio.c b/fs/bio.c
index 22596af..c852665 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -295,34 +295,45 @@ EXPORT_SYMBOL(bio_reset);
**/
struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
{
+ unsigned front_pad;
+ unsigned inline_vecs;
unsigned long idx = BIO_POOL_NONE;
struct bio_vec *bvl = NULL;
struct bio *bio;
void *p;
- p = mempool_alloc(bs->bio_pool, gfp_mask);
+ if (nr_iovecs > UIO_MAXIOV)
+ return NULL;
+
+ if (bs == BIO_KMALLOC_POOL) {
+ p = kmalloc(sizeof(struct bio) +
+ nr_iovecs * sizeof(struct bio_vec),
+ gfp_mask);
+ front_pad = 0;
+ inline_vecs = nr_iovecs;
+ } else {
+ p = mempool_alloc(bs->bio_pool, gfp_mask);
+ front_pad = bs->front_pad;
+ inline_vecs = BIO_INLINE_VECS;
+ }
+
if (unlikely(!p))
return NULL;
- bio = p + bs->front_pad;
+ bio = p + front_pad;
bio_init(bio);
- bio->bi_pool = bs;
-
- if (unlikely(!nr_iovecs))
- goto out_set;
- if (nr_iovecs <= BIO_INLINE_VECS) {
- bvl = bio->bi_inline_vecs;
- nr_iovecs = BIO_INLINE_VECS;
- } else {
+ if (nr_iovecs > inline_vecs) {
bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs);
if (unlikely(!bvl))
goto err_free;
- nr_iovecs = bvec_nr_vecs(idx);
bio->bi_flags |= 1 << BIO_OWNS_VEC;
+ } else if (nr_iovecs) {
+ bvl = bio->bi_inline_vecs;
}
-out_set:
+
+ bio->bi_pool = bs;
bio->bi_flags |= idx << BIO_POOL_OFFSET;
bio->bi_max_vecs = nr_iovecs;
bio->bi_io_vec = bvl;
next prev parent reply other threads:[~2012-08-09 2:38 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-06 22:08 [PATCH v5 00/12] Block cleanups Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 01/12] block: Generalized bio pool freeing Kent Overstreet
2012-08-08 22:25 ` Tejun Heo
2012-08-09 0:26 ` Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 02/12] dm: Use bioset's front_pad for dm_rq_clone_bio_info Kent Overstreet
2012-08-08 22:06 ` Tejun Heo
2012-08-08 23:57 ` Kent Overstreet
2012-08-11 5:24 ` Joseph Glanville
2012-08-13 21:44 ` Kent Overstreet
2012-08-14 5:33 ` Jun'ichi Nomura
2012-08-15 20:46 ` Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 03/12] block: Add bio_reset() Kent Overstreet
2012-08-08 22:11 ` Tejun Heo
2012-08-09 0:07 ` Kent Overstreet
2012-08-09 6:00 ` Tejun Heo
2012-08-09 6:06 ` Kent Overstreet
2012-08-09 6:30 ` Tejun Heo
2012-08-06 22:08 ` [PATCH v5 04/12] pktcdvd: Switch to bio_kmalloc() Kent Overstreet
2012-08-08 22:13 ` Tejun Heo
2012-08-09 0:08 ` Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 05/12] block: Kill bi_destructor Kent Overstreet
2012-08-07 3:19 ` Mike Snitzer
2012-08-09 0:14 ` Kent Overstreet
2012-08-08 22:22 ` Tejun Heo
2012-08-09 0:21 ` Kent Overstreet
2012-08-09 6:05 ` Tejun Heo
2012-08-09 6:12 ` Kent Overstreet
2012-08-09 6:34 ` Tejun Heo
2012-08-15 22:19 ` Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 06/12] block: Add an explicit bio flag for bios that own their bvec Kent Overstreet
2012-08-08 22:28 ` Tejun Heo
2012-08-06 22:08 ` [PATCH v5 07/12] block: Rename bio_split() -> bio_pair_split() Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 08/12] block: Introduce new bio_split() Kent Overstreet
2012-08-08 22:58 ` Tejun Heo
2012-08-09 1:19 ` Kent Overstreet
2012-08-09 6:44 ` Tejun Heo
2012-08-13 21:55 ` Kent Overstreet
2012-08-13 22:05 ` Tejun Heo
2012-08-08 23:05 ` Tejun Heo
2012-08-09 1:39 ` Kent Overstreet
2012-08-09 7:22 ` Tejun Heo
2012-08-09 7:33 ` Kent Overstreet
2012-08-09 17:32 ` Tejun Heo
2012-08-13 22:09 ` Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 09/12] block: Rework bio_pair_split() Kent Overstreet
2012-08-08 23:09 ` Tejun Heo
2012-08-06 22:08 ` [PATCH v5 10/12] block: Add bio_clone_kmalloc() Kent Overstreet
2012-08-08 23:15 ` Tejun Heo
2012-08-09 1:57 ` Kent Overstreet
2012-08-09 6:55 ` Tejun Heo
2012-08-09 7:02 ` Kent Overstreet
2012-08-09 2:38 ` Kent Overstreet [this message]
2012-08-09 6:56 ` [PATCH] Consolidate bio_clone_bioset(), bio_kmalloc() Tejun Heo
2012-08-06 22:08 ` [PATCH v5 11/12] block: Add bio_clone_bioset() Kent Overstreet
2012-08-08 23:21 ` Tejun Heo
2012-08-09 2:56 ` Kent Overstreet
2012-08-09 6:52 ` Tejun Heo
2012-08-09 6:59 ` Kent Overstreet
2012-08-06 22:08 ` [PATCH v5 12/12] block: Only clone bio vecs that are in use Kent Overstreet
2012-08-06 23:16 ` [dm-devel] " Mikulas Patocka
2012-08-08 23:28 ` Tejun Heo
2012-08-08 23:47 ` Muthu Kumar
2012-08-09 3:19 ` Kent Overstreet
2012-08-09 3:25 ` Kent Overstreet
2012-08-10 1:50 ` Muthu Kumar
2012-08-09 7:01 ` Tejun Heo
2012-08-10 2:29 ` Muthu Kumar
2012-08-08 23:30 ` Tejun Heo
2012-08-09 3:06 ` Kent Overstreet
2012-08-09 17:37 ` Tejun Heo
2012-08-13 21:46 ` Kent Overstreet
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=20120809023811.GJ7262@moria.home.lan \
--to=koverstreet@google.com \
--cc=agk@redhat.com \
--cc=axboe@kernel.dk \
--cc=dm-devel@redhat.com \
--cc=drbd-dev@lists.linbit.com \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=neilb@suse.de \
--cc=sage@newdream.net \
--cc=tj@kernel.org \
--cc=vgoyal@redhat.com \
--cc=yehuda@hq.newdream.net \
/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).