public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>, Coly Li <colyli@suse.de>
Cc: Kent Overstreet <kent.overstreet@gmail.com>,
	linux-bcache@vger.kernel.org, linux-block@vger.kernel.org
Subject: [PATCH 3/6] bcache: clean up bio reuse for struct moving_io
Date: Wed, 13 Jun 2018 15:51:55 +0200	[thread overview]
Message-ID: <20180613135158.29477-4-hch@lst.de> (raw)
In-Reply-To: <20180613135158.29477-1-hch@lst.de>

Instead of reinitializing the bio everytime we can call bio_reuse when
reusing it.  Also removes the remainder of the moving_init helper
to improve readability.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/bcache/movinggc.c | 40 +++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c
index a24c3a95b2c0..890c055eb589 100644
--- a/drivers/md/bcache/movinggc.c
+++ b/drivers/md/bcache/movinggc.c
@@ -74,29 +74,20 @@ static void read_moving_endio(struct bio *bio)
 	bch_bbio_endio(io->op.c, bio, bio->bi_status, "reading data to move");
 }
 
-static void moving_init(struct moving_io *io)
-{
-	struct bio *bio = &io->bio.bio;
-
-	bio_init(bio, bio->bi_inline_vecs,
-		 DIV_ROUND_UP(KEY_SIZE(&io->w->key), PAGE_SECTORS));
-	bio_get(bio);
-	bio_set_prio(bio, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
-
-	bio->bi_iter.bi_size	= KEY_SIZE(&io->w->key) << 9;
-	bio->bi_private		= &io->cl;
-	bch_bio_map(bio, NULL);
-}
-
 static void write_moving(struct closure *cl)
 {
 	struct moving_io *io = container_of(cl, struct moving_io, cl);
 	struct data_insert_op *op = &io->op;
 
 	if (!op->status) {
-		moving_init(io);
+		struct bio *bio = &io->bio.bio;
+
+		bio_reuse(bio, KEY_SIZE(&io->w->key) << 9);
+		bio_get(bio);
+		bio_set_prio(bio, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
+		bio->bi_private = &io->cl;
+		bio->bi_iter.bi_sector = KEY_START(&io->w->key);
 
-		io->bio.bio.bi_iter.bi_sector = KEY_START(&io->w->key);
 		op->write_prio		= 1;
 		op->bio			= &io->bio.bio;
 
@@ -156,12 +147,19 @@ static void read_moving(struct cache_set *c)
 		io->op.c	= c;
 		io->op.wq	= c->moving_gc_wq;
 
-		moving_init(io);
 		bio = &io->bio.bio;
-
-		bio_set_op_attrs(bio, REQ_OP_READ, 0);
-		bio->bi_end_io	= read_moving_endio;
-
+		bio_init(bio, bio->bi_inline_vecs,
+			DIV_ROUND_UP(KEY_SIZE(&io->w->key), PAGE_SECTORS));
+		bio_get(bio);
+
+		bio->bi_iter.bi_size = KEY_SIZE(&io->w->key) << 9;
+		bio->bi_iter.bi_sector = KEY_START(&io->w->key);
+		bio->bi_opf = REQ_OP_READ;
+		bio_set_prio(bio, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
+		bio->bi_private = &io->cl;
+		bio->bi_end_io = read_moving_endio;
+
+		bch_bio_map(bio, NULL);
 		if (bch_bio_alloc_pages(bio, GFP_KERNEL))
 			goto err;
 
-- 
2.17.1

  parent reply	other threads:[~2018-06-13 13:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-13 13:51 [RFC] cleanup bcache bio handling v2 Christoph Hellwig
2018-06-13 13:51 ` [PATCH 1/6] block: add a bio_reuse helper Christoph Hellwig
2018-06-13 13:51 ` [PATCH 2/6] bcache: use bio_reuse instead of bio_reinit where applicable Christoph Hellwig
2018-06-13 13:51 ` Christoph Hellwig [this message]
2018-06-13 13:51 ` [PATCH 4/6] bcache: clean up bio reuse for struct dirty_io Christoph Hellwig
2018-06-13 13:51 ` [PATCH 5/6] bcache: don't clone bio in bch_data_verify Christoph Hellwig
2018-06-13 13:51 ` [PATCH 6/6] bcache: use bio_add_page instead of open coded bio manipulation Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2018-06-11 19:48 [RFC] cleanup bcache bio handling Christoph Hellwig
2018-06-11 19:48 ` [PATCH 3/6] bcache: clean up bio reuse for struct moving_io Christoph Hellwig

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=20180613135158.29477-4-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=colyli@suse.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@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