From: Kent Overstreet <koverstreet@google.com>
To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org,
dm-devel@redhat.com
Cc: Kent Overstreet <koverstreet@google.com>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH v9 6/9] block: Add bio_reset()
Date: Thu, 6 Sep 2012 14:32:53 -0700 [thread overview]
Message-ID: <1346967179-28596-7-git-send-email-koverstreet@google.com> (raw)
In-Reply-To: <1346967179-28596-1-git-send-email-koverstreet@google.com>
Reusing bios is something that's been highly frowned upon in the past,
but driver code keeps doing it anyways. If it's going to happen anyways,
we should provide a generic method.
This'll help with getting rid of bi_destructor - drivers/block/pktcdvd.c
was open coding it, by doing a bio_init() and resetting bi_destructor.
This required reordering struct bio, but the block layer is not yet
nearly fast enough for any cacheline effects to matter here.
v5: Add a define BIO_RESET_BITS, to be very explicit about what parts of
bio->bi_flags are saved.
v6: Further commenting verbosity, per Tejun
v9: Add a function comment
Signed-off-by: Kent Overstreet <koverstreet@google.com>
CC: Jens Axboe <axboe@kernel.dk>
Acked-by: Tejun Heo <tj@kernel.org>
---
fs/bio.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/fs/bio.c b/fs/bio.c
index 208141f..74ab3f0 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -277,6 +277,30 @@ void bio_reset(struct bio *bio)
EXPORT_SYMBOL(bio_reset);
/**
+ * bio_reset - reinitialize a bio
+ * @bio: bio to reset
+ *
+ * Description:
+ * After calling bio_reset(), @bio will be in the same state as a freshly
+ * allocated bio returned bio bio_alloc_bioset() - the only fields that are
+ * preserved are the ones that are initialized by bio_alloc_bioset(). See
+ * comment in struct bio.
+ */
+void bio_reset(struct bio *bio)
+{
+ unsigned long flags = bio->bi_flags & (~0UL << BIO_RESET_BITS);
+
+ if (bio_integrity(bio))
+ bio_integrity_free(bio, bio->bi_pool);
+
+ bio_disassociate_task(bio);
+
+ memset(bio, 0, BIO_RESET_BYTES);
+ bio->bi_flags = flags|(1 << BIO_UPTODATE);
+}
+EXPORT_SYMBOL(bio_reset);
+
+/**
* bio_alloc_bioset - allocate a bio for I/O
* @gfp_mask: the GFP_ mask given to the slab allocator
* @nr_iovecs: number of iovecs to pre-allocate
--
1.7.12
next prev parent reply other threads:[~2012-09-06 21:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-06 21:32 [PATCH v9 0/9] Block cleanups Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 1/9] block: Generalized bio pool freeing Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 2/9] block: Ues bi_pool for bio_integrity_alloc() Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 3/9] dm: Use bioset's front_pad for dm_rq_clone_bio_info Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 4/9] block: Add bio_reset() Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 5/9] pktcdvd: Switch to bio_kmalloc() Kent Overstreet
2012-09-06 21:32 ` Kent Overstreet [this message]
2012-09-06 21:32 ` [PATCH v8 6/8] block: Kill bi_destructor Kent Overstreet
2012-09-06 21:32 ` [PATCH v8 7/8] block: Consolidate bio_alloc_bioset(), bio_kmalloc() Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 7/9] block: Kill bi_destructor Kent Overstreet
2012-09-06 21:32 ` [PATCH v8 8/8] block: Add bio_clone_bioset(), bio_clone_kmalloc() Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 8/9] block: Consolidate bio_alloc_bioset(), bio_kmalloc() Kent Overstreet
2012-09-06 21:32 ` [PATCH v9 9/9] block: Add bio_clone_bioset(), bio_clone_kmalloc() 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=1346967179-28596-7-git-send-email-koverstreet@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 \
/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
all inboxes | Powered by JetHome®