Linux block layer
 help / color / mirror / Atom feed
* [PATCH 00/17] Some bugfix and cleanup patches for bfq
@ 2023-02-19 10:42 Kemeng Shi
  2023-02-19 10:42 ` [PATCH 01/17] block, bfq: properly mark bfqq remained idle Kemeng Shi
                   ` (16 more replies)
  0 siblings, 17 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

Hi, this series contain some patches to improve in-service queue
preemption, protect max_budget updating race between configuration
and auto-tuning and so on. More details can be found in respective
log message. Thanks!

Kemeng Shi (17):
  block, bfq: properly mark bfqq remained idle
  block, bfq: try preemption if bfqq has higher weight and the same
    priority class
  block, bfq: only preempt plugged in_service_queue if
    bfq_better_to_idle say no
  block, bfq: recover the "service hole" if enough budget is left
  block, bfq: Update bfqd->max_budget with bfqd->lock held
  block, bfq: correct bfq_max_budget and bfq_min_budget
  block, bfq: correct interactive weight-raise check in
    bfq_set_budget_timeout
  block, bfq: start service_from_wr accumulating of async queues
    correctly
  block, bfq: stop to detect queue as waker queue if it already is now
  block, bfq: fix typo in comment
  block, bfq: simpfy computation of bfqd->budgets_assigned
  block, bfq: define and use soft_rt, in_burst and wr_or_deserves_wr
    only low_latency is enable
  block, bfq: remove unnecessary "wr" part of wr_or_deserves_wr
  block, bfq: remove redundant oom_bfqq check for bfqq from
    bfq_find_close_cooperator
  block, bfq: some cleanups for function bfq_pos_tree_add_move
  block, bfq: remove unnecessary goto tag in __bfq_weights_tree_remove
  block, bfq: remove unnecessary local variable __bfqq in
    bfq_setup_merge

 block/bfq-iosched.c | 176 +++++++++++++++++++++++---------------------
 block/bfq-wf2q.c    |   2 +-
 2 files changed, 95 insertions(+), 83 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 01/17] block, bfq: properly mark bfqq remained idle
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:42 ` [PATCH 02/17] block, bfq: try preemption if bfqq has higher weight and the same priority class Kemeng Shi
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

Bfqq activation will try to recover the "service hole" of bfqq which may
issues requests greedily while remained idle for other reasons: CPU high
load, bfqq not enjoying idling, I/O throttling somewhere in the path from
the process to the I/O scheduler. So we should mark bfqq remained idle
when expired for two reasons: BFQQE_NO_MORE_REQUESTS or BFQQE_TOO_IDLE.
More details can be found in comment of
bfq_bfqq_update_budg_for_activation.
So we should mark bfqq remained idle expired for BFQQE_NO_MORE_REQUESTS
or BFQQE_TOO_IDLE instead of (reason != BFQQE_BUDGET_TIMEOUT &&
reason != BFQQE_BUDGET_EXHAUSTED).

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 777dcab73c8e..3f5c740664ce 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -4420,8 +4420,8 @@ void bfq_bfqq_expire(struct bfq_data *bfqd,
 
 	/* mark bfqq as waiting a request only if a bic still points to it */
 	if (!bfq_bfqq_busy(bfqq) &&
-	    reason != BFQQE_BUDGET_TIMEOUT &&
-	    reason != BFQQE_BUDGET_EXHAUSTED) {
+	    reason == BFQQE_NO_MORE_REQUESTS &&
+	    reason == BFQQE_TOO_IDLE) {
 		bfq_mark_bfqq_non_blocking_wait_rq(bfqq);
 		/*
 		 * Not setting service to 0, because, if the next rq
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 02/17] block, bfq: try preemption if bfqq has higher weight and the same priority class
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
  2023-02-19 10:42 ` [PATCH 01/17] block, bfq: properly mark bfqq remained idle Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:42 ` [PATCH 03/17] block, bfq: only preempt plugged in_service_queue if bfq_better_to_idle say no Kemeng Shi
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

We will compare priority class and weight of current bfqq with
in_service_queue to check if bfqq could preempt in_service_queue.
Currently we will try to preempt in_service_queue if bfqq has higher
weight than in_service_queue even with lower priority class. Actually,
we will only serve bfqq with higher priority class (see
bfq_lookup_next_entity), so bfqq with higher weight and lower priority
class will not be a candidate to preempt in_service_queue.
Compare weight of bfqqs with the same priority in
bfq_bfqq_higher_class_or_weight to make preemption check more reasonable.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 3f5c740664ce..4868538c9745 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1768,6 +1768,10 @@ static bool bfq_bfqq_higher_class_or_weight(struct bfq_queue *bfqq,
 	if (bfqq->ioprio_class < in_serv_bfqq->ioprio_class)
 		return true;
 
+	/* only try weight comparison with same priority class */
+	if (bfqq->ioprio_class != in_serv_bfqq->ioprio_class)
+		return false;
+
 	if (in_serv_bfqq->entity.parent == bfqq->entity.parent) {
 		bfqq_weight = bfqq->entity.weight;
 		in_serv_weight = in_serv_bfqq->entity.weight;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 03/17] block, bfq: only preempt plugged in_service_queue if bfq_better_to_idle say no
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
  2023-02-19 10:42 ` [PATCH 01/17] block, bfq: properly mark bfqq remained idle Kemeng Shi
  2023-02-19 10:42 ` [PATCH 02/17] block, bfq: try preemption if bfqq has higher weight and the same priority class Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:42 ` [PATCH 04/17] block, bfq: recover the "service hole" if enough budget is left Kemeng Shi
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

Why we preempt in_service_queue when bfq_better_to_idle say no is (from
comment above the preemption expiration):
As for throughput, we ask bfq_better_to_idle() whether we still need to
plug I/O dispatching. If bfq_better_to_idle() says no, then plugging is
not needed any longer, either to boost throughput or to perserve service
guarantees. Then the best option is to stop plugging I/O, as not doing so
would certainly lower throughput.
This preemption only makes sense that IO of in_service_queue is currently
plugged and then there is a need to stop plugging.
Make sure bfqq is plugged before bfq_better_to_idle check to improve this.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 4868538c9745..7b416f9471b3 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1978,8 +1978,9 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 	if (bfqd->in_service_queue &&
 	    ((bfqq_wants_to_preempt &&
 	      bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) ||
-	     bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue) ||
-	     !bfq_better_to_idle(bfqd->in_service_queue)) &&
+	      bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue) ||
+	      (bfq_bfqq_wait_request(bfqq) &&
+	      !bfq_better_to_idle(bfqd->in_service_queue))) &&
 	    next_queue_may_preempt(bfqd))
 		bfq_bfqq_expire(bfqd, bfqd->in_service_queue,
 				false, BFQQE_PREEMPTED);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 04/17] block, bfq: recover the "service hole" if enough budget is left
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (2 preceding siblings ...)
  2023-02-19 10:42 ` [PATCH 03/17] block, bfq: only preempt plugged in_service_queue if bfq_better_to_idle say no Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:42 ` [PATCH 05/17] block, bfq: Update bfqd->max_budget with bfqd->lock held Kemeng Shi
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

If budget left is less than budget need by next request, the activated bfqq
will be expired if it preempts the in-service queue. Avoid to cause useless
overhead to check budget left is enough for next request.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 7b416f9471b3..edbf5c9aeb47 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1588,13 +1588,15 @@ static bool bfq_bfqq_update_budg_for_activation(struct bfq_data *bfqd,
 
 	/*
 	 * In the next compound condition, we check also whether there
-	 * is some budget left, because otherwise there is no point in
-	 * trying to go on serving bfqq with this same budget: bfqq
-	 * would be expired immediately after being selected for
-	 * service. This would only cause useless overhead.
+	 * is some budget left for next request to serve, because
+	 * otherwise there is no point in trying to go on serving bfqq
+	 * with this same budget: bfqq would be expired immediately
+	 * after being selected for service. This would only cause
+	 * useless overhead.
 	 */
 	if (bfq_bfqq_non_blocking_wait_rq(bfqq) && arrived_in_time &&
-	    bfq_bfqq_budget_left(bfqq) > 0) {
+	    bfq_bfqq_budget_left(bfqq) >=
+	    bfq_serv_to_charge(bfqq->next_rq, bfqq)) {
 		/*
 		 * We do not clear the flag non_blocking_wait_rq here, as
 		 * the latter is used in bfq_activate_bfqq to signal
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 05/17] block, bfq: Update bfqd->max_budget with bfqd->lock held
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (3 preceding siblings ...)
  2023-02-19 10:42 ` [PATCH 04/17] block, bfq: recover the "service hole" if enough budget is left Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:42 ` [PATCH 06/17] block, bfq: correct bfq_max_budget and bfq_min_budget Kemeng Shi
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

bfq_max_budget and bfq_user_max_budget maybe be in inconsisten state if
bfq_max_budget configuration and bfq_max_budget auto-update happen
concurrently.
Example sequence:
config                          auto-update
bfqd->bfq_max_budget =
  __data
                                if (bfqd->bfq_user_max_budget == 0)
                                  bfqd->bfq_max_budget =
                                    bfq_calc_max_budget(bfqd);
bfqd->bfq_user_max_budget =
  __data;

Users may set bfq_max_budget successfully while read a different value
from they set.
bfq_max_budget is only update in update_thr_responsiveness_params and
configuration code. As update_thr_responsiveness_params is always called
under bfqd->lock, fix this by holding lock in configuration code.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index edbf5c9aeb47..5b08711cbaf6 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -7489,6 +7489,7 @@ static ssize_t bfq_max_budget_store(struct elevator_queue *e,
 	if (ret)
 		return ret;
 
+	spin_lock_irq(&bfqd->lock);
 	if (__data == 0)
 		bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd);
 	else {
@@ -7498,6 +7499,7 @@ static ssize_t bfq_max_budget_store(struct elevator_queue *e,
 	}
 
 	bfqd->bfq_user_max_budget = __data;
+	spin_unlock_irq(&bfqd->lock);
 
 	return count;
 }
@@ -7523,8 +7525,11 @@ static ssize_t bfq_timeout_sync_store(struct elevator_queue *e,
 		__data = INT_MAX;
 
 	bfqd->bfq_timeout = msecs_to_jiffies(__data);
+
+	spin_lock_irq(&bfqd->lock);
 	if (bfqd->bfq_user_max_budget == 0)
 		bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd);
+	spin_unlock_irq(&bfqd->lock);
 
 	return count;
 }
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 06/17] block, bfq: correct bfq_max_budget and bfq_min_budget
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (4 preceding siblings ...)
  2023-02-19 10:42 ` [PATCH 05/17] block, bfq: Update bfqd->max_budget with bfqd->lock held Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:42 ` [PATCH 07/17] block, bfq: correct interactive weight-raise check in bfq_set_budget_timeout Kemeng Shi
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

For case that user set a max_budget, we should use bfq_max_budget
set by user instead of bfq_default_max_budget when budgets_assigned
is not enough to compulte auto-tuning max_budget.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 5b08711cbaf6..b32bae5259d5 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1458,7 +1458,8 @@ static int bfq_bfqq_budget_left(struct bfq_queue *bfqq)
  */
 static int bfq_max_budget(struct bfq_data *bfqd)
 {
-	if (bfqd->budgets_assigned < bfq_stats_min_budgets)
+	if (bfqd->budgets_assigned < bfq_stats_min_budgets &&
+			bfqd->bfq_user_max_budget == 0)
 		return bfq_default_max_budget;
 	else
 		return bfqd->bfq_max_budget;
@@ -1470,7 +1471,8 @@ static int bfq_max_budget(struct bfq_data *bfqd)
  */
 static int bfq_min_budget(struct bfq_data *bfqd)
 {
-	if (bfqd->budgets_assigned < bfq_stats_min_budgets)
+	if (bfqd->budgets_assigned < bfq_stats_min_budgets &&
+			bfqd->bfq_user_max_budget == 0)
 		return bfq_default_max_budget / 32;
 	else
 		return bfqd->bfq_max_budget / 32;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 07/17] block, bfq: correct interactive weight-raise check in bfq_set_budget_timeout
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (5 preceding siblings ...)
  2023-02-19 10:42 ` [PATCH 06/17] block, bfq: correct bfq_max_budget and bfq_min_budget Kemeng Shi
@ 2023-02-19 10:42 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 08/17] block, bfq: start service_from_wr accumulating of async queues correctly Kemeng Shi
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:42 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

After weight-raise finished, bfqq->wr_coeff is reset to 1 while
bfqq->wr_cur_max_time may not be reset. For example,
Function bfq_update_bfqq_wr_on_rq_arrival will only reset wr_coeff to 1 if
bfqq is created in burst creation. Function bfq_set_budget_timeout will be
called when bfqq is selected while it's wr_cur_max_time is set and wr_coeff
is 1. Fix this by check wr_coeff > 1 along with check wr_cur_max_time
check like other code do.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index b32bae5259d5..5610a7dcacdf 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -3297,7 +3297,8 @@ static void bfq_set_budget_timeout(struct bfq_data *bfqd,
 {
 	unsigned int timeout_coeff;
 
-	if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time)
+	if (bfqq->wr_coeff > 1 &&
+	    bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time)
 		timeout_coeff = 1;
 	else
 		timeout_coeff = bfqq->entity.weight / bfqq->entity.orig_weight;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 08/17] block, bfq: start service_from_wr accumulating of async queues correctly
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (6 preceding siblings ...)
  2023-02-19 10:42 ` [PATCH 07/17] block, bfq: correct interactive weight-raise check in bfq_set_budget_timeout Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 09/17] block, bfq: stop to detect queue as waker queue if it already is now Kemeng Shi
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

Start accumulating service_from_wr when async queues are weight raised.
The service_from_wr for async queues is accumulated and checked to finish
weight-raise as sync queues. We need charge service_from_wr for async
queues or service_from_wr will keep accumulating and async queues will
finish weight-raise soon after weight-raise starts.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 5610a7dcacdf..7a0283f08aed 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -2323,6 +2323,7 @@ static void bfq_add_request(struct request *rq)
 		    time_is_before_jiffies(
 				bfqq->last_wr_start_finish +
 				bfqd->bfq_wr_min_inter_arr_async)) {
+			bfqq->service_from_wr = 0;
 			bfqq->wr_coeff = bfqd->bfq_wr_coeff;
 			bfqq->wr_cur_max_time = bfq_wr_duration(bfqd);
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 09/17] block, bfq: stop to detect queue as waker queue if it already is now
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (7 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 08/17] block, bfq: start service_from_wr accumulating of async queues correctly Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 10/17] block, bfq: fix typo in comment Kemeng Shi
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

If last_completed_rq_bfqq is the current waker queue of bfqq, it's no
meaning to execute the detection logic as nothing will change whether
detection successes or fails.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 7a0283f08aed..0a11a381ee7d 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -2147,7 +2147,8 @@ static void bfq_check_waker(struct bfq_data *bfqd, struct bfq_queue *bfqq,
 	    bfq_bfqq_has_short_ttime(bfqq) ||
 	    now_ns - bfqd->last_completion >= 4 * NSEC_PER_MSEC ||
 	    bfqd->last_completed_rq_bfqq == &bfqd->oom_bfqq ||
-	    bfqq == &bfqd->oom_bfqq)
+	    bfqq == &bfqd->oom_bfqq ||
+	    bfqd->last_completed_rq_bfqq == bfqq->waker_bfqq)
 		return;
 
 	/*
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 10/17] block, bfq: fix typo in comment
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (8 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 09/17] block, bfq: stop to detect queue as waker queue if it already is now Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 11/17] block, bfq: simpfy computation of bfqd->budgets_assigned Kemeng Shi
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

IO/ -> I/O
bfq_fqq_update_budg_for_activation -> bfq_bfqq_update_budg_for_activation

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 2 +-
 block/bfq-wf2q.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 0a11a381ee7d..2559343593bb 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -5734,7 +5734,7 @@ bfq_do_early_stable_merge(struct bfq_data *bfqd, struct bfq_queue *bfqq,
  *
  * Putting these two facts together, this commits merges stably the
  * bfq_queues associated with these I/O flows, i.e., with the
- * processes that generate these IO/ flows, regardless of how many the
+ * processes that generate these I/O flows, regardless of how many the
  * involved processes are.
  *
  * To decide whether a set of bfq_queues is actually associated with
diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c
index 7941b6f07391..1b8d05bae116 100644
--- a/block/bfq-wf2q.c
+++ b/block/bfq-wf2q.c
@@ -931,7 +931,7 @@ static void __bfq_activate_entity(struct bfq_entity *entity,
 	bool backshifted = false;
 	unsigned long long min_vstart;
 
-	/* See comments on bfq_fqq_update_budg_for_activation */
+	/* See comments on bfq_bfqq_update_budg_for_activation */
 	if (non_blocking_wait_rq && bfq_gt(st->vtime, entity->finish)) {
 		backshifted = true;
 		min_vstart = entity->finish;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 11/17] block, bfq: simpfy computation of bfqd->budgets_assigned
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (9 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 10/17] block, bfq: fix typo in comment Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 12/17] block, bfq: define and use soft_rt, in_burst and wr_or_deserves_wr only low_latency is enable Kemeng Shi
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

The computation of budgets_assigned is a little confusing as we only need
to check if it's updated more than 10 times. Simpfy the computation to
improve readability.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 2559343593bb..a8cb0a0d36f3 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -175,7 +175,7 @@ static const int bfq_back_penalty = 2;
 static u64 bfq_slice_idle = NSEC_PER_SEC / 125;
 
 /* Minimum number of assigned budgets for which stats are safe to compute. */
-static const int bfq_stats_min_budgets = 194;
+static const int bfq_stats_min_budgets = 11;
 
 /* Default maximum budget values, in sectors and number of requests. */
 static const int bfq_default_max_budget = 16 * 1024;
@@ -3317,7 +3317,7 @@ static void __bfq_set_in_service_queue(struct bfq_data *bfqd,
 	if (bfqq) {
 		bfq_clear_bfqq_fifo_expire(bfqq);
 
-		bfqd->budgets_assigned = (bfqd->budgets_assigned * 7 + 256) / 8;
+		bfqd->budgets_assigned++;
 
 		if (time_is_before_jiffies(bfqq->last_wr_start_finish) &&
 		    bfqq->wr_coeff > 1 &&
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 12/17] block, bfq: define and use soft_rt, in_burst and wr_or_deserves_wr only low_latency is enable
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (10 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 11/17] block, bfq: simpfy computation of bfqd->budgets_assigned Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 13/17] block, bfq: remove unnecessary "wr" part of wr_or_deserves_wr Kemeng Shi
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

The soft_rt, in_burst and wr_or_deserves_wr are only used when low_latency
is enable. Currently, these variables are computed even low_latency is
disable. Define these variables in successful branch of bfqd->low_latency
check and compute them if needed to remove redundant computation and
improve readability.
The interactive parameter will be used only if low_latency is enabled
outside bfq_bfqq_handle_idle_busy_switch, so it's safe to move
interactive assignment inside branch where low_latency is true.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 81 +++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 39 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index a8cb0a0d36f3..eda6669d0571 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1828,8 +1828,7 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 					     struct request *rq,
 					     bool *interactive)
 {
-	bool soft_rt, in_burst,	wr_or_deserves_wr,
-		bfqq_wants_to_preempt,
+	bool bfqq_wants_to_preempt,
 		idle_for_long_time = bfq_bfqq_idle_for_long_time(bfqd, bfqq),
 		/*
 		 * See the comments on
@@ -1840,43 +1839,6 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 			bfqq->ttime.last_end_request +
 			bfqd->bfq_slice_idle * 3;
 	unsigned int act_idx = bfq_actuator_index(bfqd, rq->bio);
-	bool bfqq_non_merged_or_stably_merged =
-		bfqq->bic || RQ_BIC(rq)->bfqq_data[act_idx].stably_merged;
-
-	/*
-	 * bfqq deserves to be weight-raised if:
-	 * - it is sync,
-	 * - it does not belong to a large burst,
-	 * - it has been idle for enough time or is soft real-time,
-	 * - is linked to a bfq_io_cq (it is not shared in any sense),
-	 * - has a default weight (otherwise we assume the user wanted
-	 *   to control its weight explicitly)
-	 */
-	in_burst = bfq_bfqq_in_large_burst(bfqq);
-	soft_rt = bfqd->bfq_wr_max_softrt_rate > 0 &&
-		!BFQQ_TOTALLY_SEEKY(bfqq) &&
-		!in_burst &&
-		time_is_before_jiffies(bfqq->soft_rt_next_start) &&
-		bfqq->dispatched == 0 &&
-		bfqq->entity.new_weight == 40;
-	*interactive = !in_burst && idle_for_long_time &&
-		bfqq->entity.new_weight == 40;
-	/*
-	 * Merged bfq_queues are kept out of weight-raising
-	 * (low-latency) mechanisms. The reason is that these queues
-	 * are usually created for non-interactive and
-	 * non-soft-real-time tasks. Yet this is not the case for
-	 * stably-merged queues. These queues are merged just because
-	 * they are created shortly after each other. So they may
-	 * easily serve the I/O of an interactive or soft-real time
-	 * application, if the application happens to spawn multiple
-	 * processes. So let also stably-merged queued enjoy weight
-	 * raising.
-	 */
-	wr_or_deserves_wr = bfqd->low_latency &&
-		(bfqq->wr_coeff > 1 ||
-		 (bfq_bfqq_sync(bfqq) && bfqq_non_merged_or_stably_merged &&
-		  (*interactive || soft_rt)));
 
 	/*
 	 * Using the last flag, update budget and check whether bfqq
@@ -1911,6 +1873,24 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 	bfq_clear_bfqq_just_created(bfqq);
 
 	if (bfqd->low_latency) {
+		bool soft_rt, in_burst,	wr_or_deserves_wr;
+		bool bfqq_non_merged_or_stably_merged =
+			bfqq->bic ||
+			RQ_BIC(rq)->bfqq_data[act_idx].stably_merged;
+
+		/*
+		 * bfqq deserves to be weight-raised if:
+		 * - it is sync,
+		 * - it does not belong to a large burst,
+		 * - it has been idle for enough time or is soft real-time,
+		 * - is linked to a bfq_io_cq (it is not shared in any sense),
+		 * - has a default weight (otherwise we assume the user wanted
+		 *   to control its weight explicitly)
+		 */
+		in_burst = bfq_bfqq_in_large_burst(bfqq);
+		*interactive = !in_burst && idle_for_long_time &&
+			bfqq->entity.new_weight == 40;
+
 		if (unlikely(time_is_after_jiffies(bfqq->split_time)))
 			/* wraparound */
 			bfqq->split_time =
@@ -1918,6 +1898,29 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 
 		if (time_is_before_jiffies(bfqq->split_time +
 					   bfqd->bfq_wr_min_idle_time)) {
+			soft_rt = bfqd->bfq_wr_max_softrt_rate > 0 &&
+				!BFQQ_TOTALLY_SEEKY(bfqq) &&
+				!in_burst &&
+				time_is_before_jiffies(bfqq->soft_rt_next_start) &&
+				bfqq->dispatched == 0 &&
+				bfqq->entity.new_weight == 40;
+			/*
+			 * Merged bfq_queues are kept out of weight-raising
+			 * (low-latency) mechanisms. The reason is that these queues
+			 * are usually created for non-interactive and
+			 * non-soft-real-time tasks. Yet this is not the case for
+			 * stably-merged queues. These queues are merged just because
+			 * they are created shortly after each other. So they may
+			 * easily serve the I/O of an interactive or soft-real time
+			 * application, if the application happens to spawn multiple
+			 * processes. So let also stably-merged queued enjoy weight
+			 * raising.
+			 */
+			wr_or_deserves_wr = (bfqq->wr_coeff > 1 ||
+				(bfq_bfqq_sync(bfqq) &&
+				bfqq_non_merged_or_stably_merged &&
+				(*interactive || soft_rt)));
+
 			bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq,
 							 old_wr_coeff,
 							 wr_or_deserves_wr,
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 13/17] block, bfq: remove unnecessary "wr" part of wr_or_deserves_wr
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (11 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 12/17] block, bfq: define and use soft_rt, in_burst and wr_or_deserves_wr only low_latency is enable Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 14/17] block, bfq: remove redundant oom_bfqq check for bfqq from bfq_find_close_cooperator Kemeng Shi
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

Before commit 96a291c38c3299 ("block, bfq: preempt lower-weight or
lower-priority queues"), wr_or_deserves_wr is used to check if
preempt is wanted. Currently, wr_or_deserves_wr is only used in
bfq_update_bfqq_wr_on_rq_arrival to check if weight raising is
needed, so the "wr" part of wr_or_deserves_wr is not needed
anymore. Rename wr_or_deserves_wr to deserves_wr and remove
unnecessary bfqq->wr_coeff > 1 for original wr_or_deserves_wr.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index eda6669d0571..6a8ea9a451cc 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -1656,12 +1656,12 @@ static unsigned long bfq_smallest_from_now(void)
 static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd,
 					     struct bfq_queue *bfqq,
 					     unsigned int old_wr_coeff,
-					     bool wr_or_deserves_wr,
+					     bool deserves_wr,
 					     bool interactive,
 					     bool in_burst,
 					     bool soft_rt)
 {
-	if (old_wr_coeff == 1 && wr_or_deserves_wr) {
+	if (old_wr_coeff == 1 && deserves_wr) {
 		/* start a weight-raising period */
 		if (interactive) {
 			bfqq->service_from_wr = 0;
@@ -1873,7 +1873,7 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 	bfq_clear_bfqq_just_created(bfqq);
 
 	if (bfqd->low_latency) {
-		bool soft_rt, in_burst,	wr_or_deserves_wr;
+		bool soft_rt, in_burst,	deserves_wr;
 		bool bfqq_non_merged_or_stably_merged =
 			bfqq->bic ||
 			RQ_BIC(rq)->bfqq_data[act_idx].stably_merged;
@@ -1916,14 +1916,13 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd,
 			 * processes. So let also stably-merged queued enjoy weight
 			 * raising.
 			 */
-			wr_or_deserves_wr = (bfqq->wr_coeff > 1 ||
-				(bfq_bfqq_sync(bfqq) &&
+			deserves_wr = (bfq_bfqq_sync(bfqq) &&
 				bfqq_non_merged_or_stably_merged &&
-				(*interactive || soft_rt)));
+				(*interactive || soft_rt));
 
 			bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq,
 							 old_wr_coeff,
-							 wr_or_deserves_wr,
+							 deserves_wr,
 							 *interactive,
 							 in_burst,
 							 soft_rt);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 14/17] block, bfq: remove redundant oom_bfqq check for bfqq from bfq_find_close_cooperator
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (12 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 13/17] block, bfq: remove unnecessary "wr" part of wr_or_deserves_wr Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 15/17] block, bfq: some cleanups for function bfq_pos_tree_add_move Kemeng Shi
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

The oom_bfqq is never added to tree in bfq_pos_tree_add_move, so bfqq
returned from bfq_find_close_cooperator is no need to be checked if it's
oom_bfqq.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 6a8ea9a451cc..ee02c7502394 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -3038,8 +3038,7 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq,
 	new_bfqq = bfq_find_close_cooperator(bfqd, bfqq,
 			bfq_io_struct_pos(io_struct, request));
 
-	if (new_bfqq && likely(new_bfqq != &bfqd->oom_bfqq) &&
-	    bfq_may_be_close_cooperator(bfqq, new_bfqq))
+	if (new_bfqq && bfq_may_be_close_cooperator(bfqq, new_bfqq))
 		return bfq_setup_merge(bfqq, new_bfqq);
 
 	return NULL;
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 15/17] block, bfq: some cleanups for function bfq_pos_tree_add_move
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (13 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 14/17] block, bfq: remove redundant oom_bfqq check for bfqq from bfq_find_close_cooperator Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 16/17] block, bfq: remove unnecessary goto tag in __bfq_weights_tree_remove Kemeng Shi
  2023-02-19 10:43 ` [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge Kemeng Shi
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

There are three cleanups in this patch:
1. The oom_bfqq is never inserted to tree, so return immediately for
oom_bfqq before unnecessary NULL check of bfqq->pos_root.
2. Only set bfqq->pos_root after bfq_rq_pos_tree_lookup successes rather
than set bfqq->pos_root unconditionally and reset to NULL if
bfq_rq_pos_tree_lookup fails.
3. Remove unnecessary local variable __bfqq which is only used to check
return value of bfq_rq_pos_tree_lookup.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index ee02c7502394..6ba096e9aec6 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -783,17 +783,16 @@ void __cold
 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq)
 {
 	struct rb_node **p, *parent;
-	struct bfq_queue *__bfqq;
+
+	/* oom_bfqq does not participate in queue merging */
+	if (bfqq == &bfqd->oom_bfqq)
+		return;
 
 	if (bfqq->pos_root) {
 		rb_erase(&bfqq->pos_node, bfqq->pos_root);
 		bfqq->pos_root = NULL;
 	}
 
-	/* oom_bfqq does not participate in queue merging */
-	if (bfqq == &bfqd->oom_bfqq)
-		return;
-
 	/*
 	 * bfqq cannot be merged any longer (see comments in
 	 * bfq_setup_cooperator): no point in adding bfqq into the
@@ -807,14 +806,13 @@ bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq)
 	if (!bfqq->next_rq)
 		return;
 
+	if (bfq_rq_pos_tree_lookup(bfqd, &bfqq_group(bfqq)->rq_pos_tree,
+			blk_rq_pos(bfqq->next_rq), &parent, &p))
+		return;
+
 	bfqq->pos_root = &bfqq_group(bfqq)->rq_pos_tree;
-	__bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root,
-			blk_rq_pos(bfqq->next_rq), &parent, &p);
-	if (!__bfqq) {
-		rb_link_node(&bfqq->pos_node, parent, p);
-		rb_insert_color(&bfqq->pos_node, bfqq->pos_root);
-	} else
-		bfqq->pos_root = NULL;
+	rb_link_node(&bfqq->pos_node, parent, p);
+	rb_insert_color(&bfqq->pos_node, bfqq->pos_root);
 }
 
 /*
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 16/17] block, bfq: remove unnecessary goto tag in __bfq_weights_tree_remove
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (14 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 15/17] block, bfq: some cleanups for function bfq_pos_tree_add_move Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-19 10:43 ` [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge Kemeng Shi
  16 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

Do free work if num_active == 0 and remove unnecessary tag
reset_entity_pointer.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 6ba096e9aec6..2705a24ab146 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -976,13 +976,11 @@ void bfq_weights_tree_remove(struct bfq_queue *bfqq)
 
 	root = &bfqq->bfqd->queue_weights_tree;
 	bfqq->weight_counter->num_active--;
-	if (bfqq->weight_counter->num_active > 0)
-		goto reset_entity_pointer;
-
-	rb_erase_cached(&bfqq->weight_counter->weights_node, root);
-	kfree(bfqq->weight_counter);
+	if (bfqq->weight_counter->num_active == 0) {
+		rb_erase_cached(&bfqq->weight_counter->weights_node, root);
+		kfree(bfqq->weight_counter);
+	}
 
-reset_entity_pointer:
 	bfqq->weight_counter = NULL;
 	bfq_put_queue(bfqq);
 }
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge
  2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
                   ` (15 preceding siblings ...)
  2023-02-19 10:43 ` [PATCH 16/17] block, bfq: remove unnecessary goto tag in __bfq_weights_tree_remove Kemeng Shi
@ 2023-02-19 10:43 ` Kemeng Shi
  2023-02-23  5:48   ` Dan Carpenter
  16 siblings, 1 reply; 20+ messages in thread
From: Kemeng Shi @ 2023-02-19 10:43 UTC (permalink / raw)
  To: paolo.valente, axboe, jack; +Cc: linux-block, linux-kernel, shikemeng

We could traversal bfqq->new_bfqq list without a local variable easily and
intuitively. So remove unnecessary local variable __bfqq.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/bfq-iosched.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index 2705a24ab146..037f73a25567 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -2752,7 +2752,6 @@ static struct bfq_queue *
 bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)
 {
 	int process_refs, new_process_refs;
-	struct bfq_queue *__bfqq;
 
 	/*
 	 * If there are no process references on the new_bfqq, then it is
@@ -2764,10 +2763,9 @@ bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)
 		return NULL;
 
 	/* Avoid a circular list and skip interim queue merges. */
-	while ((__bfqq = new_bfqq->new_bfqq)) {
-		if (__bfqq == bfqq)
+	while ((new_bfqq = new_bfqq->new_bfqq)) {
+		if (new_bfqq == bfqq)
 			return NULL;
-		new_bfqq = __bfqq;
 	}
 
 	process_refs = bfqq_process_refs(bfqq);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge
  2023-02-19 10:43 ` [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge Kemeng Shi
@ 2023-02-23  5:48   ` Dan Carpenter
  2023-02-23  6:34     ` Kemeng Shi
  0 siblings, 1 reply; 20+ messages in thread
From: Dan Carpenter @ 2023-02-23  5:48 UTC (permalink / raw)
  To: oe-kbuild, Kemeng Shi, paolo.valente, axboe, jack
  Cc: lkp, oe-kbuild-all, linux-block, linux-kernel, shikemeng

Hi Kemeng,

https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kemeng-Shi/block-bfq-properly-mark-bfqq-remained-idle/20230219-104312
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20230219104309.1511562-18-shikemeng%40huaweicloud.com
patch subject: [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge
config: openrisc-randconfig-m041-20230219 (https://download.01.org/0day-ci/archive/20230220/202302200841.9zinyY7i-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 12.1.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Link: https://lore.kernel.org/r/202302200841.9zinyY7i-lkp@intel.com/

New smatch warnings:
block/bfq-iosched.c:2785 bfq_setup_merge() error: we previously assumed 'new_bfqq' could be null (see line 2766)

Old smatch warnings:
block/bfq-iosched.c:6195 __bfq_insert_request() warn: variable dereferenced before check 'bfqq' (see line 6191)

vim +/new_bfqq +2785 block/bfq-iosched.c

36eca894832351 Arianna Avanzini 2017-04-12  2751  static struct bfq_queue *
36eca894832351 Arianna Avanzini 2017-04-12  2752  bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)
36eca894832351 Arianna Avanzini 2017-04-12  2753  {
36eca894832351 Arianna Avanzini 2017-04-12  2754  	int process_refs, new_process_refs;
36eca894832351 Arianna Avanzini 2017-04-12  2755  
36eca894832351 Arianna Avanzini 2017-04-12  2756  	/*
36eca894832351 Arianna Avanzini 2017-04-12  2757  	 * If there are no process references on the new_bfqq, then it is
36eca894832351 Arianna Avanzini 2017-04-12  2758  	 * unsafe to follow the ->new_bfqq chain as other bfqq's in the chain
36eca894832351 Arianna Avanzini 2017-04-12  2759  	 * may have dropped their last reference (not just their last process
36eca894832351 Arianna Avanzini 2017-04-12  2760  	 * reference).
36eca894832351 Arianna Avanzini 2017-04-12  2761  	 */
36eca894832351 Arianna Avanzini 2017-04-12  2762  	if (!bfqq_process_refs(new_bfqq))
36eca894832351 Arianna Avanzini 2017-04-12  2763  		return NULL;
36eca894832351 Arianna Avanzini 2017-04-12  2764  
36eca894832351 Arianna Avanzini 2017-04-12  2765  	/* Avoid a circular list and skip interim queue merges. */
114533e1e26a36 Kemeng Shi       2023-02-19 @2766  	while ((new_bfqq = new_bfqq->new_bfqq)) {
114533e1e26a36 Kemeng Shi       2023-02-19  2767  		if (new_bfqq == bfqq)
36eca894832351 Arianna Avanzini 2017-04-12  2768  			return NULL;
36eca894832351 Arianna Avanzini 2017-04-12  2769  	}

This now loops until new_bfqq is NULL.

36eca894832351 Arianna Avanzini 2017-04-12  2770  
36eca894832351 Arianna Avanzini 2017-04-12  2771  	process_refs = bfqq_process_refs(bfqq);
36eca894832351 Arianna Avanzini 2017-04-12  2772  	new_process_refs = bfqq_process_refs(new_bfqq);

What?

36eca894832351 Arianna Avanzini 2017-04-12  2773  	/*
36eca894832351 Arianna Avanzini 2017-04-12  2774  	 * If the process for the bfqq has gone away, there is no
36eca894832351 Arianna Avanzini 2017-04-12  2775  	 * sense in merging the queues.
36eca894832351 Arianna Avanzini 2017-04-12  2776  	 */
36eca894832351 Arianna Avanzini 2017-04-12  2777  	if (process_refs == 0 || new_process_refs == 0)
36eca894832351 Arianna Avanzini 2017-04-12  2778  		return NULL;
36eca894832351 Arianna Avanzini 2017-04-12  2779  
c1cee4ab36acef Jan Kara         2022-04-01  2780  	/*
c1cee4ab36acef Jan Kara         2022-04-01  2781  	 * Make sure merged queues belong to the same parent. Parents could
c1cee4ab36acef Jan Kara         2022-04-01  2782  	 * have changed since the time we decided the two queues are suitable
c1cee4ab36acef Jan Kara         2022-04-01  2783  	 * for merging.
c1cee4ab36acef Jan Kara         2022-04-01  2784  	 */
c1cee4ab36acef Jan Kara         2022-04-01 @2785  	if (new_bfqq->entity.parent != bfqq->entity.parent)
c1cee4ab36acef Jan Kara         2022-04-01  2786  		return NULL;
c1cee4ab36acef Jan Kara         2022-04-01  2787  
36eca894832351 Arianna Avanzini 2017-04-12  2788  	bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d",
36eca894832351 Arianna Avanzini 2017-04-12  2789  		new_bfqq->pid);
36eca894832351 Arianna Avanzini 2017-04-12  2790  
36eca894832351 Arianna Avanzini 2017-04-12  2791  	/*
36eca894832351 Arianna Avanzini 2017-04-12  2792  	 * Merging is just a redirection: the requests of the process
36eca894832351 Arianna Avanzini 2017-04-12  2793  	 * owning one of the two queues are redirected to the other queue.
36eca894832351 Arianna Avanzini 2017-04-12  2794  	 * The latter queue, in its turn, is set as shared if this is the
36eca894832351 Arianna Avanzini 2017-04-12  2795  	 * first time that the requests of some process are redirected to
36eca894832351 Arianna Avanzini 2017-04-12  2796  	 * it.
36eca894832351 Arianna Avanzini 2017-04-12  2797  	 *
6fa3e8d34204d5 Paolo Valente    2017-04-12  2798  	 * We redirect bfqq to new_bfqq and not the opposite, because
6fa3e8d34204d5 Paolo Valente    2017-04-12  2799  	 * we are in the context of the process owning bfqq, thus we
6fa3e8d34204d5 Paolo Valente    2017-04-12  2800  	 * have the io_cq of this process. So we can immediately
6fa3e8d34204d5 Paolo Valente    2017-04-12  2801  	 * configure this io_cq to redirect the requests of the
6fa3e8d34204d5 Paolo Valente    2017-04-12  2802  	 * process to new_bfqq. In contrast, the io_cq of new_bfqq is
6fa3e8d34204d5 Paolo Valente    2017-04-12  2803  	 * not available any more (new_bfqq->bic == NULL).
6fa3e8d34204d5 Paolo Valente    2017-04-12  2804  	 *
6fa3e8d34204d5 Paolo Valente    2017-04-12  2805  	 * Anyway, even in case new_bfqq coincides with the in-service
6fa3e8d34204d5 Paolo Valente    2017-04-12  2806  	 * queue, redirecting requests the in-service queue is the
6fa3e8d34204d5 Paolo Valente    2017-04-12  2807  	 * best option, as we feed the in-service queue with new
6fa3e8d34204d5 Paolo Valente    2017-04-12  2808  	 * requests close to the last request served and, by doing so,
6fa3e8d34204d5 Paolo Valente    2017-04-12  2809  	 * are likely to increase the throughput.
36eca894832351 Arianna Avanzini 2017-04-12  2810  	 */
36eca894832351 Arianna Avanzini 2017-04-12  2811  	bfqq->new_bfqq = new_bfqq;
15729ff8143f81 Paolo Valente    2021-11-25  2812  	/*
15729ff8143f81 Paolo Valente    2021-11-25  2813  	 * The above assignment schedules the following redirections:
15729ff8143f81 Paolo Valente    2021-11-25  2814  	 * each time some I/O for bfqq arrives, the process that
15729ff8143f81 Paolo Valente    2021-11-25  2815  	 * generated that I/O is disassociated from bfqq and
15729ff8143f81 Paolo Valente    2021-11-25  2816  	 * associated with new_bfqq. Here we increases new_bfqq->ref
15729ff8143f81 Paolo Valente    2021-11-25  2817  	 * in advance, adding the number of processes that are
15729ff8143f81 Paolo Valente    2021-11-25  2818  	 * expected to be associated with new_bfqq as they happen to
15729ff8143f81 Paolo Valente    2021-11-25  2819  	 * issue I/O.
15729ff8143f81 Paolo Valente    2021-11-25  2820  	 */
36eca894832351 Arianna Avanzini 2017-04-12  2821  	new_bfqq->ref += process_refs;
36eca894832351 Arianna Avanzini 2017-04-12  2822  	return new_bfqq;
36eca894832351 Arianna Avanzini 2017-04-12  2823  }

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge
  2023-02-23  5:48   ` Dan Carpenter
@ 2023-02-23  6:34     ` Kemeng Shi
  0 siblings, 0 replies; 20+ messages in thread
From: Kemeng Shi @ 2023-02-23  6:34 UTC (permalink / raw)
  To: Dan Carpenter, oe-kbuild, paolo.valente, axboe, jack
  Cc: lkp, oe-kbuild-all, linux-block, linux-kernel



on 2/23/2023 1:48 PM, Dan Carpenter wrote:
> Hi Kemeng,
> 
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Kemeng-Shi/block-bfq-properly-mark-bfqq-remained-idle/20230219-104312
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
> patch link:    https://lore.kernel.org/r/20230219104309.1511562-18-shikemeng%40huaweicloud.com
> patch subject: [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge
> config: openrisc-randconfig-m041-20230219 (https://download.01.org/0day-ci/archive/20230220/202302200841.9zinyY7i-lkp@intel.com/config)
> compiler: or1k-linux-gcc (GCC) 12.1.0
> 
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
> | Reported-by: Dan Carpenter <error27@gmail.com>
> | Link: https://lore.kernel.org/r/202302200841.9zinyY7i-lkp@intel.com/
> 
> New smatch warnings:
> block/bfq-iosched.c:2785 bfq_setup_merge() error: we previously assumed 'new_bfqq' could be null (see line 2766)
> 
> Old smatch warnings:
> block/bfq-iosched.c:6195 __bfq_insert_request() warn: variable dereferenced before check 'bfqq' (see line 6191)
> 
> vim +/new_bfqq +2785 block/bfq-iosched.c
> 
> 36eca894832351 Arianna Avanzini 2017-04-12  2751  static struct bfq_queue *
> 36eca894832351 Arianna Avanzini 2017-04-12  2752  bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)
> 36eca894832351 Arianna Avanzini 2017-04-12  2753  {
> 36eca894832351 Arianna Avanzini 2017-04-12  2754  	int process_refs, new_process_refs;
> 36eca894832351 Arianna Avanzini 2017-04-12  2755  
> 36eca894832351 Arianna Avanzini 2017-04-12  2756  	/*
> 36eca894832351 Arianna Avanzini 2017-04-12  2757  	 * If there are no process references on the new_bfqq, then it is
> 36eca894832351 Arianna Avanzini 2017-04-12  2758  	 * unsafe to follow the ->new_bfqq chain as other bfqq's in the chain
> 36eca894832351 Arianna Avanzini 2017-04-12  2759  	 * may have dropped their last reference (not just their last process
> 36eca894832351 Arianna Avanzini 2017-04-12  2760  	 * reference).
> 36eca894832351 Arianna Avanzini 2017-04-12  2761  	 */
> 36eca894832351 Arianna Avanzini 2017-04-12  2762  	if (!bfqq_process_refs(new_bfqq))
> 36eca894832351 Arianna Avanzini 2017-04-12  2763  		return NULL;
> 36eca894832351 Arianna Avanzini 2017-04-12  2764  
> 36eca894832351 Arianna Avanzini 2017-04-12  2765  	/* Avoid a circular list and skip interim queue merges. */
> 114533e1e26a36 Kemeng Shi       2023-02-19 @2766  	while ((new_bfqq = new_bfqq->new_bfqq)) {
> 114533e1e26a36 Kemeng Shi       2023-02-19  2767  		if (new_bfqq == bfqq)
> 36eca894832351 Arianna Avanzini 2017-04-12  2768  			return NULL;
> 36eca894832351 Arianna Avanzini 2017-04-12  2769  	}
> 
> This now loops until new_bfqq is NULL.
> 
> 36eca894832351 Arianna Avanzini 2017-04-12  2770  
> 36eca894832351 Arianna Avanzini 2017-04-12  2771  	process_refs = bfqq_process_refs(bfqq);
> 36eca894832351 Arianna Avanzini 2017-04-12  2772  	new_process_refs = bfqq_process_refs(new_bfqq);
> 
> What?Sorry, I didn't expect that there is a behavior change. I will drop
this one in next version. Thanks.

-- 
Best wishes
Kemeng Shi


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-02-23  6:34 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-19 10:42 [PATCH 00/17] Some bugfix and cleanup patches for bfq Kemeng Shi
2023-02-19 10:42 ` [PATCH 01/17] block, bfq: properly mark bfqq remained idle Kemeng Shi
2023-02-19 10:42 ` [PATCH 02/17] block, bfq: try preemption if bfqq has higher weight and the same priority class Kemeng Shi
2023-02-19 10:42 ` [PATCH 03/17] block, bfq: only preempt plugged in_service_queue if bfq_better_to_idle say no Kemeng Shi
2023-02-19 10:42 ` [PATCH 04/17] block, bfq: recover the "service hole" if enough budget is left Kemeng Shi
2023-02-19 10:42 ` [PATCH 05/17] block, bfq: Update bfqd->max_budget with bfqd->lock held Kemeng Shi
2023-02-19 10:42 ` [PATCH 06/17] block, bfq: correct bfq_max_budget and bfq_min_budget Kemeng Shi
2023-02-19 10:42 ` [PATCH 07/17] block, bfq: correct interactive weight-raise check in bfq_set_budget_timeout Kemeng Shi
2023-02-19 10:43 ` [PATCH 08/17] block, bfq: start service_from_wr accumulating of async queues correctly Kemeng Shi
2023-02-19 10:43 ` [PATCH 09/17] block, bfq: stop to detect queue as waker queue if it already is now Kemeng Shi
2023-02-19 10:43 ` [PATCH 10/17] block, bfq: fix typo in comment Kemeng Shi
2023-02-19 10:43 ` [PATCH 11/17] block, bfq: simpfy computation of bfqd->budgets_assigned Kemeng Shi
2023-02-19 10:43 ` [PATCH 12/17] block, bfq: define and use soft_rt, in_burst and wr_or_deserves_wr only low_latency is enable Kemeng Shi
2023-02-19 10:43 ` [PATCH 13/17] block, bfq: remove unnecessary "wr" part of wr_or_deserves_wr Kemeng Shi
2023-02-19 10:43 ` [PATCH 14/17] block, bfq: remove redundant oom_bfqq check for bfqq from bfq_find_close_cooperator Kemeng Shi
2023-02-19 10:43 ` [PATCH 15/17] block, bfq: some cleanups for function bfq_pos_tree_add_move Kemeng Shi
2023-02-19 10:43 ` [PATCH 16/17] block, bfq: remove unnecessary goto tag in __bfq_weights_tree_remove Kemeng Shi
2023-02-19 10:43 ` [PATCH 17/17] block, bfq: remove unnecessary local variable __bfqq in bfq_setup_merge Kemeng Shi
2023-02-23  5:48   ` Dan Carpenter
2023-02-23  6:34     ` Kemeng Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox