Skip to contentSkip to conversation

blk-mq: check on cpu id when there is only one ctx mapping

PATCH Applied Ed Tsai 3 participants 3 messages Jun 14, 2023 Block layer

lore
Share & tools
lore

Ed Tsai

author
#0 lore raw

PATCH v3 1/1 blk-mq: check on cpu id when there is only one ctx mapping

commit f168420c62e7 ("blk-mq: don't redirect completion for hctx withs only one ctx mapping") When nvme applies a 1:1 mapping of hctx and ctx, there will be no remote request.

But for ufs, the submission and completion queues could be asymmetric. (e.g. Multiple SQs share one CQ) Therefore, 1:1 mapping of hctx and ctx won't complete request on the submission cpu. In this situation, this nr_ctx check could violate the QUEUE_FLAG_SAME_FORCE, as a result, check on cpu id when there is only one ctx mapping.

---
 block/blk-mq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-mq.c +2 -1
index 41f7e2b500bd..ecc30ebe9483 100644
@@ -1176,7 +1176,8 @@ bool blk_mq_complete_request_remote(struct request *rq)
 	 * or a polled request, always complete locally,
 	 * it's pointless to redirect the completion.
 	 */
-	if (rq->mq_hctx->nr_ctx == 1 ||
+	if ((rq->mq_hctx->nr_ctx == 1 &&
+	     rq->mq_ctx->cpu == raw_smp_processor_id()) ||
 		rq->cmd_flags & REQ_POLLED)
 		return false;
 
Signature · 1 line
2.18.0
Reviewed-by on v3 1/1
#1 lore raw

This looks fine to me:

block/blk-mq.c bool blk_mq_complete_request_remote(struct request *rq) · line 1181

Quoted 4 lines
block/blk-mq.c +2 -1
-	if (rq->mq_hctx->nr_ctx == 1 ||
+	if ((rq->mq_hctx->nr_ctx == 1 &&
+	     rq->mq_ctx->cpu == raw_smp_processor_id()) ||
 		rq->cmd_flags & REQ_POLLED)

But please fix the incorrct indentation in the existing code here please while you're at it (maybe Jens can just fold it in):

	if ((rq->mq_hctx->nr_ctx == 1 &&
	     rq->mq_ctx->cpu == raw_smp_processor_id()) ||

(rq->cmd_flags & REQ_POLLED))

maintainer Applied
#2 lore raw
In reply to Ed Tsai
Quoted 11 lines · Ed Tsai

commit f168420c62e7 ("blk-mq: don't redirect completion for hctx withs only one ctx mapping") When nvme applies a 1:1 mapping of hctx and ctx, there will be no remote request.

But for ufs, the submission and completion queues could be asymmetric. (e.g. Multiple SQs share one CQ) Therefore, 1:1 mapping of hctx and ctx won't complete request on the submission cpu. In this situation, this nr_ctx check could violate the QUEUE_FLAG_SAME_FORCE, as a result, check on cpu id when there is only one ctx mapping.

[...]

Applied, thanks!

[1/1] blk-mq: check on cpu id when there is only one ctx mapping

      commit: 30654614f3d27230200b1650f6025a2ce67900b4

Best regards,

Signature · 1 line
Jens Axboe