Re: [PATCH] block, bfq: do the all counting of pending-request if CONFIG_BFQ_GROUP_IOSCHED is enabled

From: Yu Kuai
Date: Thu Nov 10 2022 - 04:28:21 EST


Hi,

在 2022/11/09 21:29, Yuwei Guan 写道:
The 'bfqd->num_groups_with_pending_reqs' is used when
CONFIG_BFQ_GROUP_IOSCHED is enabled, so let the variables and processes
take effect when ONFIG_BFQ_GROUP_IOSCHED is enabled.

Cc: Yu Kuai <yukuai3@xxxxxxxxxx>
Signed-off-by: Yuwei Guan <Yuwei.Guan@xxxxxxxxxxxxx>
---
block/bfq-iosched.c | 5 ++++-
block/bfq-iosched.h | 6 ++++++
block/bfq-wf2q.c | 10 ++++++----
3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 2381cf220ba2..5a648433fd89 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -6192,8 +6192,9 @@ static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd)
* mechanism).
*/
bfqq->budget_timeout = jiffies;
-
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
bfq_del_bfqq_in_groups_with_pending_reqs(bfqq);
+#endif
bfq_weights_tree_remove(bfqq);
}

Thanks for the patch, this make sense. However, I prefer to
declare a empty function if the config is disabled instead of adding
"#ifdef" everywhere the function is called.

Thanks,
Kuai
@@ -7051,7 +7052,9 @@ static int bfq_init_queue(struct request_queue *q, struct elevator_type *e)
bfqd->idle_slice_timer.function = bfq_idle_slice_timer;
bfqd->queue_weights_tree = RB_ROOT_CACHED;
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
bfqd->num_groups_with_pending_reqs = 0;
+#endif
INIT_LIST_HEAD(&bfqd->active_list);
INIT_LIST_HEAD(&bfqd->idle_list);
diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h
index 9fa89577322d..d6b9fad28a3b 100644
--- a/block/bfq-iosched.h
+++ b/block/bfq-iosched.h
@@ -197,8 +197,10 @@ struct bfq_entity {
/* flag, set to request a weight, ioprio or ioprio_class change */
int prio_changed;
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
/* flag, set if the entity is counted in groups_with_pending_reqs */
bool in_groups_with_pending_reqs;
+#endif
/* last child queue of entity created (for non-leaf entities) */
struct bfq_queue *last_bfqq_created;
@@ -491,6 +493,7 @@ struct bfq_data {
*/
struct rb_root_cached queue_weights_tree;
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
/*
* Number of groups with at least one process that
* has at least one request waiting for completion. Note that
@@ -538,6 +541,7 @@ struct bfq_data {
* with no request waiting for completion.
*/
unsigned int num_groups_with_pending_reqs;
+#endif
/*
* Per-class (RT, BE, IDLE) number of bfq_queues containing
@@ -1074,8 +1078,10 @@ void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
bool expiration);
void bfq_del_bfqq_busy(struct bfq_queue *bfqq, bool expiration);
void bfq_add_bfqq_busy(struct bfq_queue *bfqq);
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
void bfq_add_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq);
void bfq_del_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq);
+#endif
/* --------------- end of interface of B-WF2Q+ ---------------- */
diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index b02b53658ed4..a29187ecdc39 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -1610,16 +1610,15 @@ void bfq_requeue_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq,
bfqq == bfqd->in_service_queue, expiration);
}
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
void bfq_add_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq)
{
struct bfq_entity *entity = &bfqq->entity;
if (!entity->in_groups_with_pending_reqs) {
entity->in_groups_with_pending_reqs = true;
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
if (!(bfqq_group(bfqq)->num_queues_with_pending_reqs++))
bfqq->bfqd->num_groups_with_pending_reqs++;
-#endif
}
}
@@ -1629,12 +1628,11 @@ void bfq_del_bfqq_in_groups_with_pending_reqs(struct bfq_queue *bfqq)
if (entity->in_groups_with_pending_reqs) {
entity->in_groups_with_pending_reqs = false;
-#ifdef CONFIG_BFQ_GROUP_IOSCHED
if (!(--bfqq_group(bfqq)->num_queues_with_pending_reqs))
bfqq->bfqd->num_groups_with_pending_reqs--;
-#endif
}
}
+#endif
/*
* Called when the bfqq no longer has requests pending, remove it from
@@ -1659,7 +1657,9 @@ void bfq_del_bfqq_busy(struct bfq_queue *bfqq, bool expiration)
bfq_deactivate_bfqq(bfqd, bfqq, true, expiration);
if (!bfqq->dispatched) {
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
bfq_del_bfqq_in_groups_with_pending_reqs(bfqq);
+#endif
/*
* Next function is invoked last, because it causes bfqq to be
* freed. DO NOT use bfqq after the next function invocation.
@@ -1683,7 +1683,9 @@ void bfq_add_bfqq_busy(struct bfq_queue *bfqq)
bfqd->busy_queues[bfqq->ioprio_class - 1]++;
if (!bfqq->dispatched) {
+#ifdef CONFIG_BFQ_GROUP_IOSCHED
bfq_add_bfqq_in_groups_with_pending_reqs(bfqq);
+#endif
if (bfqq->wr_coeff == 1)
bfq_weights_tree_add(bfqq);
}