Skip to content

Commit 961296e

Browse files
committed
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: [email protected] Link: https://lore.kernel.org/linux-block/[email protected]/ Reported-by: Hazem Mohamed Abuelfotoh <[email protected]> Fixes: e70c301 ("block: don't reorder requests in blk_add_rq_to_plug") Signed-off-by: Jens Axboe <[email protected]>
1 parent cf62501 commit 961296e

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
@@ -998,20 +998,20 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
998998
if (!plug || rq_list_empty(&plug->mq_list))
999999
return false;
10001000

1001-
rq_list_for_each(&plug->mq_list, rq) {
1002-
if (rq->q == q) {
1003-
if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1004-
BIO_MERGE_OK)
1005-
return true;
1006-
break;
1007-
}
1001+
rq = plug->mq_list.tail;
1002+
if (rq->q == q)
1003+
return blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1004+
BIO_MERGE_OK;
1005+
else if (!plug->multiple_queues)
1006+
return false;
10081007

1009-
/*
1010-
* Only keep iterating plug list for merges if we have multiple
1011-
* queues
1012-
*/
1013-
if (!plug->multiple_queues)
1014-
break;
1008+
rq_list_for_each(&plug->mq_list, rq) {
1009+
if (rq->q != q)
1010+
continue;
1011+
if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
1012+
BIO_MERGE_OK)
1013+
return true;
1014+
break;
10151015
}
10161016
return false;
10171017
}

0 commit comments

Comments
 (0)