Skip to contentSkip to conversation

blk-mq: misc fixes

PATCH In review Ming Lei 3 participants 7 messages Nov 2, 2021 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

v2 cover blk-mq: misc fixes

Hello,

Here are 3 small fixes against latest linus tree.

V2:

	- move batched update into blk_mq_flush_tag_batch() as suggested by
	  Jens, 3/3

Ming Lei (3):
blk-mq: only try to run plug merge if request has same queue with
incoming bio
blk-mq: add RQF_ELV debug entry
blk-mq: update hctx->nr_active in blk_mq_end_request_batch()

 block/blk-merge.c      |  6 ++++--
 block/blk-mq-debugfs.c |  1 +
 block/blk-mq.c         |  7 +++++++
 block/blk-mq.h         | 12 +++++++++---
 4 files changed, 21 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH v2 1/3 blk-mq: only try to run plug merge if request has same queue with incoming bio

It is obvious that io merge can't be done between two different queues, so just try to run io merge in case of same queue.

---
 block/blk-merge.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-merge.c +4 -2
index df69f4bb7717..893c1a60b701 100644
@@ -1101,9 +1101,11 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
 		 * the same queue, there should be only one such rq in a queue
 		 */
 		*same_queue_rq = true;
+
+		if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) ==
+				BIO_MERGE_OK)
+			return true;
 	}
-	if (blk_attempt_bio_merge(q, rq, bio, nr_segs, false) == BIO_MERGE_OK)
-		return true;
 	return false;
 }
 
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH v2 2/3 blk-mq: add RQF_ELV debug entry

In reply to Ming Lei

Looks it is missed so add it.

---
 block/blk-mq-debugfs.c | 1 +
 1 file changed, 1 insertion(+)
block/blk-mq-debugfs.c +1 -0
index f5076c173477..4f2cf8399f3d 100644
@@ -308,6 +308,7 @@ static const char *const rqf_name[] = {
 	RQF_NAME(SPECIAL_PAYLOAD),
 	RQF_NAME(ZONE_WRITE_LOCKED),
 	RQF_NAME(MQ_POLL_SLEPT),
+	RQF_NAME(ELV),
 };
 #undef RQF_NAME
 
Signature · 1 line
2.31.1
author
#3 lore raw

PATCH v2 3/3 blk-mq: update hctx->nr_active in blk_mq_end_request_batch()

In reply to Ming Lei

In case of shared tags and none io sched, batched completion still may be run into, and hctx->nr_active is accounted when getting driver tag, so it has to be updated in blk_mq_end_request_batch().

Otherwise, hctx->nr_active may become same with queue depth, then hctx_may_queue() always return false, then io hang is caused.

Fixes the issue by updating the counter in batched way.

Fixes f794f3351f26 ("block: add support for blk_mq_end_request_batch()")
---
 block/blk-mq.c |  7 +++++++
 block/blk-mq.h | 12 +++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
block/blk-mq.c +7 -0
index 07eb1412760b..2a2c57c98bbd 100644
@@ -815,6 +815,13 @@ static inline void blk_mq_flush_tag_batch(struct blk_mq_hw_ctx *hctx,
 {
 	struct request_queue *q = hctx->queue;
 
+	/*
+	 * All requests should have been marked as RQF_MQ_INFLIGHT, so
+	 * update hctx->nr_active in batch
+	 */
+	if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
+		__blk_mq_sub_active_requests(hctx, nr_tags);
+
 	blk_mq_put_tags(hctx->tags, tag_array, nr_tags);
 	percpu_ref_put_many(&q->q_usage_counter, nr_tags);
 }
block/blk-mq.h +9 -3
index 28859fc5faee..cb0b5482ca5e 100644
@@ -225,12 +225,18 @@ static inline void __blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
 		atomic_inc(&hctx->nr_active);
 }
 
-static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
+static inline void __blk_mq_sub_active_requests(struct blk_mq_hw_ctx *hctx,
+		int val)
 {
 	if (blk_mq_is_shared_tags(hctx->flags))
-		atomic_dec(&hctx->queue->nr_active_requests_shared_tags);
+		atomic_sub(val, &hctx->queue->nr_active_requests_shared_tags);
 	else
-		atomic_dec(&hctx->nr_active);
+		atomic_sub(val, &hctx->nr_active);
+}
+
+static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
+{
+	__blk_mq_sub_active_requests(hctx, 1);
 }
 
 static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx)
Signature · 1 line
2.31.1
Tested-by on v2 3/3
#4 lore raw

Re: [PATCH V2 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()

Quoted 4 lines · Ming Lei

In case of shared tags and none io sched, batched completion still may be run into, and hctx->nr_active is accounted when getting driver tag, so it has to be updated in blk_mq_end_request_batch().

Quoted 8 lines

Otherwise, hctx->nr_active may become same with queue depth, then hctx_may_queue() always return false, then io hang is caused.

Fixes the issue by updating the counter in batched way.

Fixes f794f3351f26 ("block: add support for blk_mq_end_request_batch()")

Ming, thank you very much. I have confirmed that the blktests block/005 hang disappears using NVMe devices with two namespaces.

Though this patch is already queued up to for-5.16/block, in case it is still meaningful:

Signature · 2 lines
Best Regards,
Shin'ichiro Kawasaki
maintainer
#5 lore raw

Re: [PATCH V2 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()

Quoted 14 lines · Shinichiro Kawasaki
Quoted 4 lines · Ming Lei

In case of shared tags and none io sched, batched completion still may be run into, and hctx->nr_active is accounted when getting driver tag, so it has to be updated in blk_mq_end_request_batch().

Quoted 8 lines

Otherwise, hctx->nr_active may become same with queue depth, then hctx_may_queue() always return false, then io hang is caused.

Fixes the issue by updating the counter in batched way.

Fixes f794f3351f26 ("block: add support for blk_mq_end_request_batch()")
Quoted 7 lines

Ming, thank you very much. I have confirmed that the blktests block/005 hang disappears using NVMe devices with two namespaces.

Though this patch is already queued up to for-5.16/block, in case it is still meaningful:

Testing is _always_ meaningful! So thanks for doing that, and reporting it in the first place. The patch has been queued up this morning for 5.16.

Signature · 1 line
Jens Axboe
maintainer
#6 lore raw
In reply to Ming Lei
Quoted 7 lines · Ming Lei

Hello,

Here are 3 small fixes against latest linus tree.

V2:

	- move batched update into blk_mq_flush_tag_batch() as suggested by
	  Jens, 3/3

Thanks Ming, applied.

Signature · 1 line
Jens Axboe