blk-mq: misc fixes
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
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
@@ -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
PATCH v2 2/3 blk-mq: add RQF_ELV debug entry
In reply to Ming LeiLooks it is missed so add it.
--- block/blk-mq-debugfs.c | 1 + 1 file changed, 1 insertion(+)
block/blk-mq-debugfs.c +1 -0
@@ -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
PATCH v2 3/3 blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
In reply to Ming LeiIn 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.
--- block/blk-mq.c | 7 +++++++ block/blk-mq.h | 12 +++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-)
block/blk-mq.c +7 -0
@@ -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
@@ -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
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_activeis accounted when getting driver tag, so it has to be updated inblk_mq_end_request_batch().
Quoted 8 lines
Otherwise,
hctx->nr_activemay become same with queue depth, thenhctx_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 f794f3351f26 ("block: add support for blk_mq_end_request_batch()")Signed-off-by Ming Lei <[email protected]>
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
Jens Axboe
maintainerRe: [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_activeis accounted when getting driver tag, so it has to be updated inblk_mq_end_request_batch().Quoted 8 lines
Otherwise,
hctx->nr_activemay become same with queue depth, thenhctx_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 f794f3351f26 ("block: add support for blk_mq_end_request_batch()")Signed-off-by Ming Lei <[email protected]>
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:
Tested-by Shin'ichiro Kawasaki <[email protected]>
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
Jens Axboe
maintainerQuoted 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