Skip to contentSkip to conversation

block: Merge bio before checking ->cached_rq

PATCH Applied Xiao Ni 3 participants 3 messages Feb 9, 2023 Block layer

lore
Share & tools
lore

Xiao Ni

author
#0 lore raw

PATCH 1/1 block: Merge bio before checking ->cached_rq

It checks if plug->cached_rq is empty before merging bio. But the merge action doesn't have relationship with plug->cached_rq, it trys to merge bio with requests within plug->mq_list. Now it checks if ->cached_rq is empty before merging bio. If it's empty, it will miss the merge chances. So move the merge function before checking ->cached_rq.

---
 block/blk-mq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
block/blk-mq.c +4 -3
index 9c8dc70020bc..63bd7a34fe6f 100644
@@ -2894,15 +2894,16 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
 
 	if (!plug)
 		return NULL;
-	rq = rq_list_peek(&plug->cached_rq);
-	if (!rq || rq->q != q)
-		return NULL;
 
 	if (blk_mq_attempt_bio_merge(q, *bio, nsegs)) {
 		*bio = NULL;
 		return NULL;
 	}
 
+	rq = rq_list_peek(&plug->cached_rq);
+	if (!rq || rq->q != q)
+		return NULL;
+
 	type = blk_mq_get_hctx_type((*bio)->bi_opf);
 	hctx_type = rq->mq_hctx->type;
 	if (type != hctx_type &&
Signature · 1 line
2.32.0 (Apple Git-132)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Xiao Ni

It checks if plug->cached_rq is empty before merging bio. But the merge action doesn't have relationship with plug->cached_rq, it trys to merge bio with requests within plug->mq_list. Now it checks if ->cached_rq is empty before merging bio. If it's empty, it will miss the merge chances. So move the merge function before checking ->cached_rq.

---
 block/blk-mq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Looks fine,

Thanks,
Ming

maintainer Applied
#2 lore raw
In reply to Xiao Ni
Quoted 8 lines · Xiao Ni

It checks if plug->cached_rq is empty before merging bio. But the merge action doesn't have relationship with plug->cached_rq, it trys to merge bio with requests within plug->mq_list. Now it checks if ->cached_rq is empty before merging bio. If it's empty, it will miss the merge chances. So move the merge function before checking ->cached_rq.

[...]

Applied, thanks!

[1/1] block: Merge bio before checking ->cached_rq

      commit: 23f3e3272e7a4d9fb870485cd6df1e4f9539282c

Best regards,

Signature · 1 line
Jens Axboe