* [PATCH 1/4] blk-throttle: use 'READ/WRITE' instead of '0/1'
2022-08-23 1:38 [PATCH 0/4] blk-throttle cleanups Yu Kuai
@ 2022-08-23 1:38 ` Yu Kuai
2022-08-23 1:38 ` [PATCH 2/4] blk-throttle: calling throtl_dequeue/enqueue_tg in pairs Yu Kuai
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: Yu Kuai @ 2022-08-23 1:38 UTC (permalink / raw)
To: tj, axboe; +Cc: cgroups, linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang
From: Yu Kuai <yukuai3@huawei.com>
Make the code easier to read, like everywhere else.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
---
block/blk-throttle.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 9f5fe62afff9..fe1fa6441105 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -329,8 +329,8 @@ static struct bio *throtl_pop_queued(struct list_head *queued,
/* init a service_queue, assumes the caller zeroed it */
static void throtl_service_queue_init(struct throtl_service_queue *sq)
{
- INIT_LIST_HEAD(&sq->queued[0]);
- INIT_LIST_HEAD(&sq->queued[1]);
+ INIT_LIST_HEAD(&sq->queued[READ]);
+ INIT_LIST_HEAD(&sq->queued[WRITE]);
sq->pending_tree = RB_ROOT_CACHED;
timer_setup(&sq->pending_timer, throtl_pending_timer_fn, 0);
}
@@ -1106,7 +1106,7 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq)
nr_disp += throtl_dispatch_tg(tg);
sq = &tg->service_queue;
- if (sq->nr_queued[0] || sq->nr_queued[1])
+ if (sq->nr_queued[READ] || sq->nr_queued[WRITE])
tg_update_disptime(tg);
if (nr_disp >= THROTL_QUANTUM)
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/4] blk-throttle: calling throtl_dequeue/enqueue_tg in pairs
2022-08-23 1:38 [PATCH 0/4] blk-throttle cleanups Yu Kuai
2022-08-23 1:38 ` [PATCH 1/4] blk-throttle: use 'READ/WRITE' instead of '0/1' Yu Kuai
@ 2022-08-23 1:38 ` Yu Kuai
2022-08-23 1:38 ` [PATCH 3/4] blk-throttle: cleanup tg_update_disptime() Yu Kuai
2022-08-23 1:38 ` [PATCH 4/4] blk-throttle: cleanup throtl_dequeue_tg() Yu Kuai
3 siblings, 0 replies; 8+ messages in thread
From: Yu Kuai @ 2022-08-23 1:38 UTC (permalink / raw)
To: tj, axboe; +Cc: cgroups, linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang
From: Yu Kuai <yukuai3@huawei.com>
It's a little weird to call throtl_dequeue_tg() unconditionally in
throtl_select_dispatch(), since it will be called in tg_update_disptime()
again if some bio is still throttled. Thus call it later if there are no
throttled bio. There are no functional changes.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
---
block/blk-throttle.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index fe1fa6441105..64002435fa43 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1101,13 +1101,13 @@ static int throtl_select_dispatch(struct throtl_service_queue *parent_sq)
if (time_before(jiffies, tg->disptime))
break;
- throtl_dequeue_tg(tg);
-
nr_disp += throtl_dispatch_tg(tg);
sq = &tg->service_queue;
if (sq->nr_queued[READ] || sq->nr_queued[WRITE])
tg_update_disptime(tg);
+ else
+ throtl_dequeue_tg(tg);
if (nr_disp >= THROTL_QUANTUM)
break;
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/4] blk-throttle: cleanup tg_update_disptime()
2022-08-23 1:38 [PATCH 0/4] blk-throttle cleanups Yu Kuai
2022-08-23 1:38 ` [PATCH 1/4] blk-throttle: use 'READ/WRITE' instead of '0/1' Yu Kuai
2022-08-23 1:38 ` [PATCH 2/4] blk-throttle: calling throtl_dequeue/enqueue_tg in pairs Yu Kuai
@ 2022-08-23 1:38 ` Yu Kuai
2022-08-23 18:29 ` Tejun Heo
2022-08-23 1:38 ` [PATCH 4/4] blk-throttle: cleanup throtl_dequeue_tg() Yu Kuai
3 siblings, 1 reply; 8+ messages in thread
From: Yu Kuai @ 2022-08-23 1:38 UTC (permalink / raw)
To: tj, axboe; +Cc: cgroups, linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang
From: Yu Kuai <yukuai3@huawei.com>
tg_update_disptime() only need to adjust postion for 'tg' in
'parent_sq', there is no need to call throtl_enqueue/dequeue_tg(),
since they will set/clear flag THROTL_TG_PENDING and increase/decrease
nr_pending, which is useless. By the way, clear the flag/decrease
nr_pending while there are still throttled bios is not good for debugging.
There are no functional changes.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
block/blk-throttle.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 64002435fa43..47142a1dd102 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -520,7 +520,6 @@ static void throtl_rb_erase(struct rb_node *n,
{
rb_erase_cached(n, &parent_sq->pending_tree);
RB_CLEAR_NODE(n);
- --parent_sq->nr_pending;
}
static void update_min_dispatch_time(struct throtl_service_queue *parent_sq)
@@ -572,7 +571,11 @@ static void throtl_enqueue_tg(struct throtl_grp *tg)
static void throtl_dequeue_tg(struct throtl_grp *tg)
{
if (tg->flags & THROTL_TG_PENDING) {
- throtl_rb_erase(&tg->rb_node, tg->service_queue.parent_sq);
+ struct throtl_service_queue *parent_sq =
+ tg->service_queue.parent_sq;
+
+ throtl_rb_erase(&tg->rb_node, parent_sq);
+ --parent_sq->nr_pending;
tg->flags &= ~THROTL_TG_PENDING;
}
}
@@ -990,9 +993,9 @@ static void tg_update_disptime(struct throtl_grp *tg)
disptime = jiffies + min_wait;
/* Update dispatch time */
- throtl_dequeue_tg(tg);
+ throtl_rb_erase(&tg->rb_node, tg->service_queue.parent_sq);
tg->disptime = disptime;
- throtl_enqueue_tg(tg);
+ tg_service_queue_add(tg);
/* see throtl_add_bio_tg() */
tg->flags &= ~THROTL_TG_WAS_EMPTY;
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 3/4] blk-throttle: cleanup tg_update_disptime()
2022-08-23 1:38 ` [PATCH 3/4] blk-throttle: cleanup tg_update_disptime() Yu Kuai
@ 2022-08-23 18:29 ` Tejun Heo
0 siblings, 0 replies; 8+ messages in thread
From: Tejun Heo @ 2022-08-23 18:29 UTC (permalink / raw)
To: Yu Kuai; +Cc: axboe, cgroups, linux-block, linux-kernel, yukuai3, yi.zhang
On Tue, Aug 23, 2022 at 09:38:09AM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> tg_update_disptime() only need to adjust postion for 'tg' in
> 'parent_sq', there is no need to call throtl_enqueue/dequeue_tg(),
> since they will set/clear flag THROTL_TG_PENDING and increase/decrease
> nr_pending, which is useless. By the way, clear the flag/decrease
> nr_pending while there are still throttled bios is not good for debugging.
>
> There are no functional changes.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/4] blk-throttle: cleanup throtl_dequeue_tg()
2022-08-23 1:38 [PATCH 0/4] blk-throttle cleanups Yu Kuai
` (2 preceding siblings ...)
2022-08-23 1:38 ` [PATCH 3/4] blk-throttle: cleanup tg_update_disptime() Yu Kuai
@ 2022-08-23 1:38 ` Yu Kuai
2022-08-23 18:34 ` Tejun Heo
3 siblings, 1 reply; 8+ messages in thread
From: Yu Kuai @ 2022-08-23 1:38 UTC (permalink / raw)
To: tj, axboe; +Cc: cgroups, linux-block, linux-kernel, yukuai3, yukuai1, yi.zhang
From: Yu Kuai <yukuai3@huawei.com>
Now that throtl_dequeue_tg() is called when the last bio is dispatched,
there is no need to check the flag THROTL_TG_PENDING, since it's ensured
to be set when bio is throttled.
There are no functional changes.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
block/blk-throttle.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 47142a1dd102..e47506a8ef47 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -570,14 +570,11 @@ static void throtl_enqueue_tg(struct throtl_grp *tg)
static void throtl_dequeue_tg(struct throtl_grp *tg)
{
- if (tg->flags & THROTL_TG_PENDING) {
- struct throtl_service_queue *parent_sq =
- tg->service_queue.parent_sq;
+ struct throtl_service_queue *parent_sq = tg->service_queue.parent_sq;
- throtl_rb_erase(&tg->rb_node, parent_sq);
- --parent_sq->nr_pending;
- tg->flags &= ~THROTL_TG_PENDING;
- }
+ throtl_rb_erase(&tg->rb_node, parent_sq);
+ --parent_sq->nr_pending;
+ tg->flags &= ~THROTL_TG_PENDING;
}
/* Call with queue lock held */
--
2.31.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 4/4] blk-throttle: cleanup throtl_dequeue_tg()
2022-08-23 1:38 ` [PATCH 4/4] blk-throttle: cleanup throtl_dequeue_tg() Yu Kuai
@ 2022-08-23 18:34 ` Tejun Heo
2022-08-24 1:19 ` Yu Kuai
0 siblings, 1 reply; 8+ messages in thread
From: Tejun Heo @ 2022-08-23 18:34 UTC (permalink / raw)
To: Yu Kuai; +Cc: axboe, cgroups, linux-block, linux-kernel, yukuai3, yi.zhang
On Tue, Aug 23, 2022 at 09:38:10AM +0800, Yu Kuai wrote:
> From: Yu Kuai <yukuai3@huawei.com>
>
> Now that throtl_dequeue_tg() is called when the last bio is dispatched,
> there is no need to check the flag THROTL_TG_PENDING, since it's ensured
> to be set when bio is throttled.
>
> There are no functional changes.
>
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> block/blk-throttle.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/block/blk-throttle.c b/block/blk-throttle.c
> index 47142a1dd102..e47506a8ef47 100644
> --- a/block/blk-throttle.c
> +++ b/block/blk-throttle.c
> @@ -570,14 +570,11 @@ static void throtl_enqueue_tg(struct throtl_grp *tg)
>
> static void throtl_dequeue_tg(struct throtl_grp *tg)
> {
> - if (tg->flags & THROTL_TG_PENDING) {
> - struct throtl_service_queue *parent_sq =
> - tg->service_queue.parent_sq;
> + struct throtl_service_queue *parent_sq = tg->service_queue.parent_sq;
>
> - throtl_rb_erase(&tg->rb_node, parent_sq);
> - --parent_sq->nr_pending;
> - tg->flags &= ~THROTL_TG_PENDING;
> - }
> + throtl_rb_erase(&tg->rb_node, parent_sq);
> + --parent_sq->nr_pending;
> + tg->flags &= ~THROTL_TG_PENDING;
Yeah, I don't know about this one. This breaks the symmetry with
throtl_enqueue_tg() and it's a bit odd that we aren't at least
WARN_ON_ONCE() on the flag given what the flag tracks. If you want to do
this, I think the prev approach of just removing the flag is better as that
was symmetric at least.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 4/4] blk-throttle: cleanup throtl_dequeue_tg()
2022-08-23 18:34 ` Tejun Heo
@ 2022-08-24 1:19 ` Yu Kuai
0 siblings, 0 replies; 8+ messages in thread
From: Yu Kuai @ 2022-08-24 1:19 UTC (permalink / raw)
To: Tejun Heo, Yu Kuai
Cc: axboe, cgroups, linux-block, linux-kernel, yi.zhang, yukuai (C)
Hi, Tejun
在 2022/08/24 2:34, Tejun Heo 写道:
> On Tue, Aug 23, 2022 at 09:38:10AM +0800, Yu Kuai wrote:
>> From: Yu Kuai <yukuai3@huawei.com>
>>
>> Now that throtl_dequeue_tg() is called when the last bio is dispatched,
>> there is no need to check the flag THROTL_TG_PENDING, since it's ensured
>> to be set when bio is throttled.
>>
>> There are no functional changes.
>>
>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>> ---
>> block/blk-throttle.c | 11 ++++-------
>> 1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/block/blk-throttle.c b/block/blk-throttle.c
>> index 47142a1dd102..e47506a8ef47 100644
>> --- a/block/blk-throttle.c
>> +++ b/block/blk-throttle.c
>> @@ -570,14 +570,11 @@ static void throtl_enqueue_tg(struct throtl_grp *tg)
>>
>> static void throtl_dequeue_tg(struct throtl_grp *tg)
>> {
>> - if (tg->flags & THROTL_TG_PENDING) {
>> - struct throtl_service_queue *parent_sq =
>> - tg->service_queue.parent_sq;
>> + struct throtl_service_queue *parent_sq = tg->service_queue.parent_sq;
>>
>> - throtl_rb_erase(&tg->rb_node, parent_sq);
>> - --parent_sq->nr_pending;
>> - tg->flags &= ~THROTL_TG_PENDING;
>> - }
>> + throtl_rb_erase(&tg->rb_node, parent_sq);
>> + --parent_sq->nr_pending;
>> + tg->flags &= ~THROTL_TG_PENDING;
>
> Yeah, I don't know about this one. This breaks the symmetry with
> throtl_enqueue_tg() and it's a bit odd that we aren't at least
> WARN_ON_ONCE() on the flag given what the flag tracks. If you want to do
> this, I think the prev approach of just removing the flag is better as that
> was symmetric at least.
Yes, you are right, thanks for the advice. Since now it's a bit
ambivalent, we might as well just remove this patch?
Thanks,
Kuai
>
> Thanks.
>
^ permalink raw reply [flat|nested] 8+ messages in thread