[PATCH RFC 6/7] blk-mq: move active request counter to struct tag_sharing

From: Yu Kuai
Date: Sun Jun 18 2023 - 04:09:39 EST


From: Yu Kuai <yukuai3@xxxxxxxxxx>

Now that there is a separate structure to control tag sharing, it make
sense to move such counter for tag sharing into this structure. There
are no functional changes.

Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx>
---
block/blk-core.c | 2 --
block/blk-mq.c | 3 ++-
block/blk-mq.h | 22 +++++++++++-----------
include/linux/blk-mq.h | 6 ------
include/linux/blkdev.h | 3 +--
5 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 99d8b9812b18..f2077ee32a99 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -413,8 +413,6 @@ struct request_queue *blk_alloc_queue(int node_id)

q->node = node_id;

- atomic_set(&q->nr_active_requests_shared_tags, 0);
-
timer_setup(&q->timeout, blk_rq_timed_out_timer, 0);
INIT_WORK(&q->timeout_work, blk_timeout_work);
INIT_LIST_HEAD(&q->icq_list);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 771802ff1d45..91020cd2f6bf 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3661,7 +3661,7 @@ blk_mq_alloc_hctx(struct request_queue *q, struct blk_mq_tag_set *set,
if (!zalloc_cpumask_var_node(&hctx->cpumask, gfp, node))
goto free_hctx;

- atomic_set(&hctx->nr_active, 0);
+ atomic_set(&hctx->tag_sharing.active_tags, 0);
if (node == NUMA_NO_NODE)
node = set->numa_node;
hctx->numa_node = node;
@@ -4237,6 +4237,7 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,

q->nr_requests = set->queue_depth;
q->tag_sharing.available_tags = set->queue_depth;
+ atomic_set(&q->tag_sharing.active_tags, 0);

blk_mq_init_cpu_queues(q, set->nr_hw_queues);
blk_mq_add_queue_tag_set(set, q);
diff --git a/block/blk-mq.h b/block/blk-mq.h
index fcfb040efbbd..c8923a8565b5 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -281,18 +281,18 @@ static inline int blk_mq_get_rq_budget_token(struct request *rq)
static inline void __blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
{
if (blk_mq_is_shared_tags(hctx->flags))
- atomic_inc(&hctx->queue->nr_active_requests_shared_tags);
+ atomic_inc(&hctx->queue->tag_sharing.active_tags);
else
- atomic_inc(&hctx->nr_active);
+ atomic_inc(&hctx->tag_sharing.active_tags);
}

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_sub(val, &hctx->queue->nr_active_requests_shared_tags);
+ atomic_sub(val, &hctx->queue->tag_sharing.active_tags);
else
- atomic_sub(val, &hctx->nr_active);
+ atomic_sub(val, &hctx->tag_sharing.active_tags);
}

static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
@@ -303,8 +303,8 @@ static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx)
{
if (blk_mq_is_shared_tags(hctx->flags))
- return atomic_read(&hctx->queue->nr_active_requests_shared_tags);
- return atomic_read(&hctx->nr_active);
+ return atomic_read(&hctx->queue->tag_sharing.active_tags);
+ return atomic_read(&hctx->tag_sharing.active_tags);
}
static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx,
struct request *rq)
@@ -398,7 +398,7 @@ static inline void blk_mq_free_requests(struct list_head *list)
static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
struct sbitmap_queue *bt)
{
- unsigned int depth;
+ struct tag_sharing *tag_sharing;

if (!hctx || !(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED))
return true;
@@ -415,15 +415,15 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
if (!test_bit(QUEUE_FLAG_HCTX_ACTIVE, &q->queue_flags))
return true;

- depth = READ_ONCE(q->tag_sharing.available_tags);
+ tag_sharing = &q->tag_sharing;
} else {
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
return true;
-
- depth = READ_ONCE(hctx->tag_sharing.available_tags);
+ tag_sharing = &hctx->tag_sharing;
}

- return __blk_mq_active_requests(hctx) < depth;
+ return atomic_read(&tag_sharing->active_tags) <
+ READ_ONCE(tag_sharing->available_tags);
}

/* run the code block in @dispatch_ops with rcu/srcu read lock held */
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 639d618e6ca8..fdfa63b76136 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -408,12 +408,6 @@ struct blk_mq_hw_ctx {
/** @queue_num: Index of this hardware queue. */
unsigned int queue_num;

- /**
- * @nr_active: Number of active requests. Only used when a tag set is
- * shared across request queues.
- */
- atomic_t nr_active;
-
/** @cpuhp_online: List to store request if CPU is going to die */
struct hlist_node cpuhp_online;
/** @cpuhp_dead: List to store request if some CPU die. */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f3faaf5f6504..0d25e7d2a94c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -378,6 +378,7 @@ struct blk_independent_access_ranges {
struct tag_sharing {
struct list_head node;
unsigned int available_tags;
+ atomic_t active_tags;
atomic_t fail_count;
unsigned long period;
};
@@ -462,8 +463,6 @@ struct request_queue {
struct timer_list timeout;
struct work_struct timeout_work;

- atomic_t nr_active_requests_shared_tags;
-
struct blk_mq_tags *sched_shared_tags;

struct list_head icq_list;
--
2.39.2