linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Ming Lei <ming.lei@redhat.com>,
	Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Subject: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Date: Tue,  2 Nov 2021 21:35:02 +0800	[thread overview]
Message-ID: <20211102133502.3619184-4-ming.lei@redhat.com> (raw)
In-Reply-To: <20211102133502.3619184-1-ming.lei@redhat.com>

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.

Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fixes: f794f3351f26 ("block: add support for blk_mq_end_request_batch()")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq.c | 15 +++++++++++++--
 block/blk-mq.h | 12 +++++++++---
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 07eb1412760b..0dbe75034f61 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -825,6 +825,7 @@ void blk_mq_end_request_batch(struct io_comp_batch *iob)
 	struct blk_mq_hw_ctx *cur_hctx = NULL;
 	struct request *rq;
 	u64 now = 0;
+	int active = 0;
 
 	if (iob->need_ts)
 		now = ktime_get_ns();
@@ -846,16 +847,26 @@ void blk_mq_end_request_batch(struct io_comp_batch *iob)
 		rq_qos_done(rq->q, rq);
 
 		if (nr_tags == TAG_COMP_BATCH || cur_hctx != rq->mq_hctx) {
-			if (cur_hctx)
+			if (cur_hctx) {
+				if (active)
+					__blk_mq_sub_active_requests(cur_hctx,
+							active);
 				blk_mq_flush_tag_batch(cur_hctx, tags, nr_tags);
+			}
 			nr_tags = 0;
+			active = 0;
 			cur_hctx = rq->mq_hctx;
 		}
 		tags[nr_tags++] = rq->tag;
+		if (rq->rq_flags & RQF_MQ_INFLIGHT)
+			active++;
 	}
 
-	if (nr_tags)
+	if (nr_tags) {
+		if (active)
+			__blk_mq_sub_active_requests(cur_hctx, active);
 		blk_mq_flush_tag_batch(cur_hctx, tags, nr_tags);
+	}
 }
 EXPORT_SYMBOL_GPL(blk_mq_end_request_batch);
 
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 28859fc5faee..cb0b5482ca5e 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -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)
-- 
2.31.1


  parent reply	other threads:[~2021-11-02 13:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 13:34 [PATCH 0/3] blk-mq: misc fixes Ming Lei
2021-11-02 13:35 ` [PATCH 1/3] blk-mq: only try to run plug merge if request has same queue with incoming bio Ming Lei
2021-11-02 13:35 ` [PATCH 2/3] blk-mq: add RQF_ELV debug entry Ming Lei
2021-11-02 13:35 ` Ming Lei [this message]
2021-11-02 13:47   ` [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch() Jens Axboe
2021-11-02 13:57     ` Ming Lei
2021-11-02 14:57       ` Jens Axboe
2021-11-02 15:08         ` Ming Lei
2021-11-02 15:20           ` Jens Axboe
2021-11-02 15:23             ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211102133502.3619184-4-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=shinichiro.kawasaki@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).