Skip to content

Commit 5538af3

Browse files
axboegregkh
authored andcommitted
block: use plug request list tail for one-shot backmerge attempt
commit 961296e upstream. 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6e12761 commit 5538af3

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
@@ -1180,20 +1180,20 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
11801180
if (!plug || rq_list_empty(&plug->mq_list))
11811181
return false;
11821182

1183-
rq_list_for_each(&plug->mq_list, rq) {
1184-
if (rq->q == q) {
1185-
if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1186-
BIO_MERGE_OK)
1187-
return true;
1188-
break;
1189-
}
1183+
rq = plug->mq_list.tail;
1184+
if (rq->q == q)
1185+
return blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1186+
BIO_MERGE_OK;
1187+
else if (!plug->multiple_queues)
1188+
return false;
11901189

1191-
/*
1192-
* Only keep iterating plug list for merges if we have multiple
1193-
* queues
1194-
*/
1195-
if (!plug->multiple_queues)
1196-
break;
1190+
rq_list_for_each(&plug->mq_list, rq) {
1191+
if (rq->q != q)
1192+
continue;
1193+
if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1194+
BIO_MERGE_OK)
1195+
return true;
1196+
break;
11971197
}
11981198
return false;
11991199
}

0 commit comments

Comments
 (0)