All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: linux-block@vger.kernel.org
Cc: hch@infradead.org, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 2/5] block: split request allocation components into helpers
Date: Thu,  4 Nov 2021 12:21:58 -0600	[thread overview]
Message-ID: <20211104182201.83906-3-axboe@kernel.dk> (raw)
In-Reply-To: <20211104182201.83906-1-axboe@kernel.dk>

This is in preparation for a fix, but serves as a cleanup as well moving
the cached vs regular alloc logic out of blk_mq_submit_bio().

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 block/blk-mq.c | 71 ++++++++++++++++++++++++++++++++++----------------
 1 file changed, 48 insertions(+), 23 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 5498454c2164..dcb413297a96 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2478,6 +2478,51 @@ static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug)
 	return BLK_MAX_REQUEST_COUNT;
 }
 
+static struct request *blk_mq_get_new_requests(struct request_queue *q,
+					       struct blk_plug *plug,
+					       struct bio *bio)
+{
+	struct blk_mq_alloc_data data = {
+		.q		= q,
+		.nr_tags	= 1,
+		.cmd_flags	= bio->bi_opf,
+	};
+	struct request *rq;
+
+	if (plug) {
+		data.nr_tags = plug->nr_ios;
+		plug->nr_ios = 1;
+		data.cached_rq = &plug->cached_rq;
+	}
+
+	rq = __blk_mq_alloc_requests(&data);
+	if (rq)
+		return rq;
+
+	rq_qos_cleanup(q, bio);
+	if (bio->bi_opf & REQ_NOWAIT)
+		bio_wouldblock_error(bio);
+	return NULL;
+}
+
+static inline struct request *blk_mq_get_request(struct request_queue *q,
+						 struct blk_plug *plug,
+						 struct bio *bio)
+{
+	if (plug) {
+		struct request *rq;
+
+		rq = rq_list_peek(&plug->cached_rq);
+		if (rq) {
+			plug->cached_rq = rq_list_next(rq);
+			INIT_LIST_HEAD(&rq->queuelist);
+			return rq;
+		}
+	}
+
+	return blk_mq_get_new_requests(q, plug, bio);
+}
+
 /**
  * blk_mq_submit_bio - Create and send a request to block device.
  * @bio: Bio pointer.
@@ -2518,29 +2563,9 @@ void blk_mq_submit_bio(struct bio *bio)
 	rq_qos_throttle(q, bio);
 
 	plug = blk_mq_plug(q, bio);
-	if (plug && plug->cached_rq) {
-		rq = rq_list_pop(&plug->cached_rq);
-		INIT_LIST_HEAD(&rq->queuelist);
-	} else {
-		struct blk_mq_alloc_data data = {
-			.q		= q,
-			.nr_tags	= 1,
-			.cmd_flags	= bio->bi_opf,
-		};
-
-		if (plug) {
-			data.nr_tags = plug->nr_ios;
-			plug->nr_ios = 1;
-			data.cached_rq = &plug->cached_rq;
-		}
-		rq = __blk_mq_alloc_requests(&data);
-		if (unlikely(!rq)) {
-			rq_qos_cleanup(q, bio);
-			if (bio->bi_opf & REQ_NOWAIT)
-				bio_wouldblock_error(bio);
-			goto queue_exit;
-		}
-	}
+	rq = blk_mq_get_request(q, plug, bio);
+	if (unlikely(!rq))
+		goto queue_exit;
 
 	trace_block_getrq(bio);
 
-- 
2.33.1


  parent reply	other threads:[~2021-11-04 18:22 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 18:21 [PATCHSET v3 0/5] Alloc batch fixes Jens Axboe
2021-11-04 18:21 ` [PATCH 1/5] block: have plug stored requests hold references to the queue Jens Axboe
2021-11-04 18:34   ` Christoph Hellwig
2021-11-04 18:35     ` Jens Axboe
2021-11-04 18:21 ` Jens Axboe [this message]
2021-11-04 18:35   ` [PATCH 2/5] block: split request allocation components into helpers Christoph Hellwig
2021-11-04 18:21 ` [PATCH 3/5] block: make blk_try_enter_queue() available for blk-mq Jens Axboe
2021-11-04 18:22 ` [PATCH 4/5] block: move queue enter logic into blk_mq_submit_bio() Jens Axboe
2021-11-04 18:36   ` Christoph Hellwig
2021-11-04 18:37     ` Jens Axboe
2021-11-04 18:39       ` Christoph Hellwig
2021-11-04 18:40         ` Jens Axboe
2021-11-04 18:45           ` Jens Axboe
2021-11-04 18:52             ` Christoph Hellwig
2021-11-04 19:02               ` Jens Axboe
2021-11-04 19:04                 ` Christoph Hellwig
2021-11-04 19:15                   ` Jens Axboe
2021-11-11 12:58                     ` Geert Uytterhoeven
2021-11-11 13:19                       ` Martin K. Petersen
2021-11-11 14:48                         ` Geert Uytterhoeven
2021-11-11 15:36                           ` Martin K. Petersen
2021-11-11 21:35                           ` Michael Schmitz
2021-11-12  7:37                             ` Geert Uytterhoeven
2021-11-12 22:34                               ` Michael Schmitz
2021-11-13  7:02                                 ` Michael Schmitz
2021-11-13 10:06                                 ` Geert Uytterhoeven
2021-11-13 22:11                               ` Michael Schmitz
2021-11-11 13:44                       ` Ming Lei
2021-11-11 14:51                         ` Geert Uytterhoeven
2021-11-11 15:23                           ` Ming Lei
2021-11-11 22:17                             ` Jens Axboe
2021-11-12  0:44                               ` Ming Lei
2021-11-12  7:51                                 ` Geert Uytterhoeven
2021-11-15 19:23                                   ` Michael Schmitz
2021-11-04 18:22 ` [PATCH 5/5] block: ensure cached plug request matches the current queue Jens Axboe
2021-11-04 18:36   ` 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=20211104182201.83906-3-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=hch@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.