Commit 5b205071 authored by Jens Axboe's avatar Jens Axboe
Browse files

block: ensure plug merging checks the correct queue at least once



Song reports that a RAID rebuild workload runs much slower recently,
and it is seeing a lot less merging than it did previously. The reason
is that a previous commit reduced the amount of work we do for plug
merging. RAID rebuild interleaves requests between disks, so a last-entry
check in plug merging always misses a merge opportunity since we always
find a different disk than what we are looking for.

Modify the logic such that it's still a one-hit cache, but ensure that
we check enough to find the right target before giving up.

Fixes: d38a9c04 ("block: only check previous entry for plug merge attempt")
Reported-and-tested-by: default avatarSong Liu <song@kernel.org>
Reviewed-by: default avatarSong Liu <songliubraving@fb.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 5ca7546f
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -1087,12 +1087,20 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
	if (!plug || rq_list_empty(plug->mq_list))
		return false;

	/* check the previously added entry for a quick merge attempt */
	rq = rq_list_peek(&plug->mq_list);
	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;
		}

		/*
		 * Only keep iterating plug list for merges if we have multiple
		 * queues
		 */
		if (!plug->multiple_queues)
			break;
	}
	return false;
}