public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: "linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Cc: Hazem Mohamed Abuelfotoh <abuehaze@amazon.com>
Subject: [PATCH] block: use plug request list tail for one-shot backmerge attempt
Date: Wed, 11 Jun 2025 08:53:23 -0600	[thread overview]
Message-ID: <4856d1fc-543d-4622-9872-6ca66e8e7352@kernel.dk> (raw)

Previously, the block layer stored the requests in the plug list in
LIFO order. For this reason, blk_attempt_plug_merge() would check
just the head entry for a back merge attempt, and abort after that
unless requests for multiple queues existed in the plug list. If more
than one request is present in the plug list, this makes the one-shot
back merging less useful than before, as it'll always fail to find a
quick merge candidate.

Use the tail entry for the one-shot merge attempt, which is the last
added request in the list. If that fails, abort immediately unless
there are multiple queues available. If multiple queues are available,
then scan the list. Ideally the latter scan would be a backwards scan
of the list, but as it currently stands, the plug list is singly linked
and hence this isn't easily feasible.

Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/linux-block/20250611121626.7252-1-abuehaze@amazon.com/
Reported-by: Hazem Mohamed Abuelfotoh <abuehaze@amazon.com>
Fixes: e70c301faece ("block: don't reorder requests in blk_add_rq_to_plug")
Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 3af1d284add5..70d704615be5 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -998,20 +998,20 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
 	if (!plug || rq_list_empty(&plug->mq_list))
 		return false;
 
-	rq_list_for_each(&plug->mq_list, rq) {
-		if (rq->q == q) {
-			if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
-			    BIO_MERGE_OK)
-				return true;
-			break;
-		}
+	rq = plug->mq_list.tail;
+	if (rq->q == q)
+		return blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
+			BIO_MERGE_OK;
+	else if (!plug->multiple_queues)
+		return false;
 
-		/*
-		 * Only keep iterating plug list for merges if we have multiple
-		 * queues
-		 */
-		if (!plug->multiple_queues)
-			break;
+	rq_list_for_each(&plug->mq_list, rq) {
+		if (rq->q != q)
+			continue;
+		if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
+		    BIO_MERGE_OK)
+			return true;
+		break;
 	}
 	return false;
 }

-- 
Jens Axboe


             reply	other threads:[~2025-06-11 14:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-11 14:53 Jens Axboe [this message]
2025-06-11 16:55 ` [PATCH] block: use plug request list tail for one-shot backmerge attempt Mohamed Abuelfotoh, Hazem
2025-06-11 17:53   ` Jens Axboe
2025-06-12  5:22     ` Christoph Hellwig
2025-06-12  5:23       ` Christoph Hellwig
2025-06-12 11:49       ` Jens Axboe
2025-06-12 11:56         ` Christoph Hellwig
2025-06-12 12:21           ` Jens Axboe
2025-06-12 12:23             ` Christoph Hellwig
2025-06-12 12:28               ` Jens Axboe
2025-06-16 13:11                 ` Christoph Hellwig
2025-06-16 16:01                   ` Caleb Sander Mateos
2025-06-17  2:36                     ` Ming Lei
2025-06-17  4:39                       ` Christoph Hellwig
2025-06-18  6:04                   ` Hannes Reinecke
2025-06-12 12:27     ` Mohamed Abuelfotoh, Hazem
2025-06-24 10:45     ` Mohamed Abuelfotoh, Hazem

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=4856d1fc-543d-4622-9872-6ca66e8e7352@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=abuehaze@amazon.com \
    --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