summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorYu Kuai <yukuai3@huawei.com>2025-09-10 16:04:41 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-10-15 12:03:29 +0200
commitfc0328336cfaa25497aff8174b38ca053d733a39 (patch)
tree06b3f76cfdcf3d1daa4559124197684a6b29b3fa /block
parent64cb378502fbca246ff7103386afbba0b8ae1e54 (diff)
downloadlinux-fc0328336cfaa25497aff8174b38ca053d733a39.tar.gz
linux-fc0328336cfaa25497aff8174b38ca053d733a39.tar.bz2
linux-fc0328336cfaa25497aff8174b38ca053d733a39.zip
blk-mq: split bitmap grow and resize case in blk_mq_update_nr_requests()
[ Upstream commit e63200404477456ec60c62dd8b3b1092aba2e211 ] No functional changes are intended, make code cleaner and prepare to fix the grow case in following patches. Signed-off-by: Yu Kuai <yukuai3@huawei.com> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Stable-dep-of: b86433721f46 ("blk-mq: fix potential deadlock while nr_requests grown") Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'block')
-rw-r--r--block/blk-mq.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c
index bcb7495893a0..1bafbdced7bd 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4935,25 +4935,40 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
blk_mq_quiesce_queue(q);
if (blk_mq_is_shared_tags(set->flags)) {
+ /*
+ * Shared tags, for sched tags, we allocate max initially hence
+ * tags can't grow, see blk_mq_alloc_sched_tags().
+ */
if (q->elevator)
blk_mq_tag_update_sched_shared_tags(q);
else
blk_mq_tag_resize_shared_tags(set, nr);
- } else {
+ } else if (!q->elevator) {
+ /*
+ * Non-shared hardware tags, nr is already checked from
+ * queue_requests_store() and tags can't grow.
+ */
queue_for_each_hw_ctx(q, hctx, i) {
if (!hctx->tags)
continue;
- /*
- * If we're using an MQ scheduler, just update the
- * scheduler queue depth. This is similar to what the
- * old code would do.
- */
- if (hctx->sched_tags)
- ret = blk_mq_tag_update_depth(hctx,
- &hctx->sched_tags, nr);
- else
- ret = blk_mq_tag_update_depth(hctx,
- &hctx->tags, nr);
+ sbitmap_queue_resize(&hctx->tags->bitmap_tags,
+ nr - hctx->tags->nr_reserved_tags);
+ }
+ } else if (nr <= q->elevator->et->nr_requests) {
+ /* Non-shared sched tags, and tags don't grow. */
+ queue_for_each_hw_ctx(q, hctx, i) {
+ if (!hctx->sched_tags)
+ continue;
+ sbitmap_queue_resize(&hctx->sched_tags->bitmap_tags,
+ nr - hctx->sched_tags->nr_reserved_tags);
+ }
+ } else {
+ /* Non-shared sched tags, and tags grow */
+ queue_for_each_hw_ctx(q, hctx, i) {
+ if (!hctx->sched_tags)
+ continue;
+ ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
+ nr);
if (ret)
goto out;
}