Skip to content

Commit ff7666c

Browse files
author
Ming Lei
committed
block: use plug request list tail for one-shot backmerge attempt
JIRA: https://issues.redhat.com/browse/RHEL-96294 commit 961296e Author: Jens Axboe <axboe@kernel.dk> Date: Wed Jun 11 08:48:46 2025 -0600 block: use plug request list tail for one-shot backmerge attempt 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: e70c301 ("block: don't reorder requests in blk_add_rq_to_plug") Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 09176fc commit ff7666c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

block/blk-merge.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,20 +1127,20 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
11271127
if (!plug || rq_list_empty(&plug->mq_list))
11281128
return false;
11291129

1130-
rq_list_for_each(&plug->mq_list, rq) {
1131-
if (rq->q == q) {
1132-
if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1133-
BIO_MERGE_OK)
1134-
return true;
1135-
break;
1136-
}
1130+
rq = plug->mq_list.tail;
1131+
if (rq->q == q)
1132+
return blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1133+
BIO_MERGE_OK;
1134+
else if (!plug->multiple_queues)
1135+
return false;
11371136

1138-
/*
1139-
* Only keep iterating plug list for merges if we have multiple
1140-
* queues
1141-
*/
1142-
if (!plug->multiple_queues)
1143-
break;
1137+
rq_list_for_each(&plug->mq_list, rq) {
1138+
if (rq->q != q)
1139+
continue;
1140+
if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1141+
BIO_MERGE_OK)
1142+
return true;
1143+
break;
11441144
}
11451145
return false;
11461146
}

0 commit comments

Comments
 (0)