blk-mq: misc fixes
cover blk-mq: misc fixes
Hello,
Here are 3 small fixes against latest linus tree.
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 | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 4 files changed, 27 insertions(+), 7 deletions(-)
Signature · 1 line
2.31.1
PATCH 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 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 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 | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)
block/blk-mq.c +13 -2
@@ -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);
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
Jens Axboe
maintainerRe: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Quoted 37 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().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]>--- block/blk-mq.c | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)block/blk-mq.c +4
-1@@ -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,
block/blk-mq.c void blk_mq_end_request_batch(struct io_comp_batch *iob) · line 862
Quoted 10 lines
block/blk-mq.c +5
-0+ 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++;
Are there any cases where either none or all of requests have the flag set, and hence active == nr_tags?
Apart from that, the patch looks conceptually good.
Signature · 1 line
Jens Axboe
Re: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Quoted 43 lines · Jens Axboe
Quoted 42 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().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]>--- block/blk-mq.c | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)block/blk-mq.c +7
-1@@ -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 ;
Quoted 8 lines
block/blk-mq.c void blk_mq_end_request_batch(struct io_comp_batch *iob) · line 862
Quoted 5 lines
block/blk-mq.c +2
-0cur_hctx = rq->mq_hctx; } tags[nr_tags++] = rq->tag; +if (rq->rq_flags &RQF_MQ_INFLIGHT ) + active++;Are there any cases where either none or all of requests have the flag set, and hence active ==
nr_tags?
none and BLK_MQ_F_TAG_QUEUE_SHARED, and Shinichiro only observed the issue on two NSs.
Thanks,
Ming
Jens Axboe
maintainerRe: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Quoted 53 lines · Ming Lei
Quoted 43 lines · Jens Axboe
Quoted 42 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().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]>--- block/blk-mq.c | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)block/blk-mq.c +7
-1@@ -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 ;Quoted 8 lines
block/blk-mq.c void blk_mq_end_request_batch(struct io_comp_batch *iob) · line 862
Quoted 5 lines
block/blk-mq.c +2
-0cur_hctx = rq->mq_hctx; } tags[nr_tags++] = rq->tag; +if (rq->rq_flags &RQF_MQ_INFLIGHT ) + active++;Are there any cases where either none or all of requests have the flag set, and hence active ==
nr_tags?
Quoted 2 lines
none and
BLK_MQ_F_TAG_QUEUE_SHARED, and Shinichiro only observed the issue on two NSs.
Maybe I wasn't clear enough. What I'm saying is that either all of the requests will have RQF_MQ_INFLIGHT set, or none of them. Hence active should be either 0, or == nr_tags.
That's the hypothesis that I wanted to check, because if that's true, then we can do this in a better way.
Signature · 1 line
Jens Axboe
Re: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Quoted 54 lines · Jens Axboe
Quoted 53 lines · Ming Lei
Quoted 51 lines · Jens Axboe
Quoted 37 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().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]>--- block/blk-mq.c | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)block/blk-mq.c +4
-1@@ -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,block/blk-mq.c void blk_mq_end_request_batch(struct io_comp_batch *iob) · line 862
Quoted 10 lines
block/blk-mq.c +5
-0+ 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++;Are there any cases where either none or all of requests have the flag set, and hence active ==
nr_tags?
Quoted 6 lines
Quoted 2 lines
none and
BLK_MQ_F_TAG_QUEUE_SHARED, and Shinichiro only observed the issue on two NSs.Maybe I wasn't clear enough. What I'm saying is that either all of the requests will have
RQF_MQ_INFLIGHTset, or none of them. Hence active should be either 0, or ==nr_tags.
Yeah, that is right since BLK_MQ_F_TAG_QUEUE_SHARED is updated after queue is frozen. Meantime blk_mq_end_request_batch() is only called for ending successfully completed requests.
Will do that in V2.
Thanks,
Ming
Jens Axboe
maintainerRe: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Quoted 62 lines · Ming Lei
Quoted 54 lines · Jens Axboe
Quoted 53 lines · Ming Lei
Quoted 51 lines · Jens Axboe
Quoted 37 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().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]>--- block/blk-mq.c | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)block/blk-mq.c +4
-1@@ -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,block/blk-mq.c void blk_mq_end_request_batch(struct io_comp_batch *iob) · line 862
Quoted 10 lines
block/blk-mq.c +5
-0+ 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++;Are there any cases where either none or all of requests have the flag set, and hence active ==
nr_tags?Quoted 6 lines
Quoted 2 lines
none and
BLK_MQ_F_TAG_QUEUE_SHARED, and Shinichiro only observed the issue on two NSs.Maybe I wasn't clear enough. What I'm saying is that either all of the requests will have
RQF_MQ_INFLIGHTset, or none of them. Hence active should be either 0, or ==nr_tags.
Quoted 5 lines
Yeah, that is right since
BLK_MQ_F_TAG_QUEUE_SHAREDis updated after queue is frozen. Meantimeblk_mq_end_request_batch()is only called for ending successfully completed requests.Will do that in V2.
Thanks, then it just becomes a single check in blk_mq_flush_tag_batch(), which is a lot better than per-request.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerRe: [PATCH 3/3] blk-mq: update hctx->nr_active in blk_mq_end_request_batch()
Quoted 63 lines · Jens Axboe
Quoted 62 lines · Ming Lei
Quoted 60 lines · Jens Axboe
Quoted 53 lines · Ming Lei
Quoted 43 lines · Jens Axboe
Quoted 42 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().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]>--- block/blk-mq.c | 15 +++++++++++++-- block/blk-mq.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-)block/blk-mq.c +7
-1@@ -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 ;Quoted 8 lines
block/blk-mq.c void blk_mq_end_request_batch(struct io_comp_batch *iob) · line 862
Quoted 5 lines
block/blk-mq.c +2
-0cur_hctx = rq->mq_hctx; } tags[nr_tags++] = rq->tag; +if (rq->rq_flags &RQF_MQ_INFLIGHT ) + active++;Are there any cases where either none or all of requests have the flag set, and hence active ==
nr_tags?Quoted 2 lines
none and
BLK_MQ_F_TAG_QUEUE_SHARED, and Shinichiro only observed the issue on two NSs.Maybe I wasn't clear enough. What I'm saying is that either all of the requests will have
RQF_MQ_INFLIGHTset, or none of them. Hence active should be either 0, or ==nr_tags.
Quoted 8 lines
Quoted 5 lines
Yeah, that is right since
BLK_MQ_F_TAG_QUEUE_SHAREDis updated after queue is frozen. Meantimeblk_mq_end_request_batch()is only called for ending successfully completed requests.Will do that in V2.
Thanks, then it just becomes a single check in
blk_mq_flush_tag_batch(), which is a lot better than per-request.
Something like this, untested. FWIW, I did apply 1-2 from this series, so just do a v2 of 3/3 and that should do it.
block/blk-mq.c +2 -0
@@ -817,6 +817,8 @@ static inline void blk_mq_flush_tag_batch(struct blk_mq_hw_ctx *hctx,struct request_queue *q = hctx->queue;blk_mq_put_tags (hctx->tags, tag_array, nr_tags); +if (hctx->flags &BLK_MQ_F_TAG_QUEUE_SHARED ) +__blk_mq_sub_active_requests (hctx, 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
Jens Axboe