Skip to content

Commit 3b87c6e

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
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 <[email protected]> Fixes: f794f33 ("block: add support for blk_mq_end_request_batch()") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 62ba0c0 commit 3b87c6e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

block/blk-mq.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@ static inline void blk_mq_flush_tag_batch(struct blk_mq_hw_ctx *hctx,
818818
{
819819
struct request_queue *q = hctx->queue;
820820

821+
/*
822+
* All requests should have been marked as RQF_MQ_INFLIGHT, so
823+
* update hctx->nr_active in batch
824+
*/
825+
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
826+
__blk_mq_sub_active_requests(hctx, nr_tags);
827+
821828
blk_mq_put_tags(hctx->tags, tag_array, nr_tags);
822829
percpu_ref_put_many(&q->q_usage_counter, nr_tags);
823830
}

block/blk-mq.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,18 @@ static inline void __blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
225225
atomic_inc(&hctx->nr_active);
226226
}
227227

228-
static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
228+
static inline void __blk_mq_sub_active_requests(struct blk_mq_hw_ctx *hctx,
229+
int val)
229230
{
230231
if (blk_mq_is_shared_tags(hctx->flags))
231-
atomic_dec(&hctx->queue->nr_active_requests_shared_tags);
232+
atomic_sub(val, &hctx->queue->nr_active_requests_shared_tags);
232233
else
233-
atomic_dec(&hctx->nr_active);
234+
atomic_sub(val, &hctx->nr_active);
235+
}
236+
237+
static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
238+
{
239+
__blk_mq_sub_active_requests(hctx, 1);
234240
}
235241

236242
static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx)

0 commit comments

Comments
 (0)