* [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight
@ 2022-06-09 7:34 Chengming Zhou
2022-06-09 7:34 ` [PATCH 2/2] blk-iocost: fix vtime loss calculation when iocg deactivate Chengming Zhou
2022-06-10 8:45 ` [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight Andreas Herrmann
0 siblings, 2 replies; 3+ messages in thread
From: Chengming Zhou @ 2022-06-09 7:34 UTC (permalink / raw)
To: tj, axboe; +Cc: linux-block, linux-kernel, Chengming Zhou
The commit ac33e91e2dac ("blk-iocost: implement vtime loss compensation")
add the second current_hweight() in the loop of active iocgs list to
get old_hwi to calculate the vtime loss of the iocg.
Since the hwi can't change and the first current_hweight already get
hwa and hwi, so this second superfluous current_hweight() can be
removed. There should be no functional changes.
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
block/blk-iocost.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 33a11ba971ea..3cda08224d51 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -2238,7 +2238,7 @@ static void ioc_timer_fn(struct timer_list *timer)
/* calc usage and see whether some weights need to be moved around */
list_for_each_entry(iocg, &ioc->active_iocgs, active_list) {
u64 vdone, vtime, usage_us;
- u32 hw_active, hw_inuse;
+ u32 hwa, old_hwi;
/*
* Collect unused and wind vtime closer to vnow to prevent
@@ -2246,7 +2246,7 @@ static void ioc_timer_fn(struct timer_list *timer)
*/
vdone = atomic64_read(&iocg->done_vtime);
vtime = atomic64_read(&iocg->vtime);
- current_hweight(iocg, &hw_active, &hw_inuse);
+ current_hweight(iocg, &hwa, &old_hwi);
/*
* Latency QoS detection doesn't account for IOs which are
@@ -2271,15 +2271,15 @@ static void ioc_timer_fn(struct timer_list *timer)
/* see whether there's surplus vtime */
WARN_ON_ONCE(!list_empty(&iocg->surplus_list));
- if (hw_inuse < hw_active ||
+ if (old_hwi < hwa ||
(!waitqueue_active(&iocg->waitq) &&
time_before64(vtime, now.vnow - ioc->margins.low))) {
- u32 hwa, old_hwi, hwm, new_hwi, usage;
+ u32 hwm, new_hwi, usage;
u64 usage_dur;
if (vdone != vtime) {
u64 inflight_us = DIV64_U64_ROUND_UP(
- cost_to_abs_cost(vtime - vdone, hw_inuse),
+ cost_to_abs_cost(vtime - vdone, old_hwi),
ioc->vtime_base_rate);
usage_us = max(usage_us, inflight_us);
@@ -2300,7 +2300,6 @@ static void ioc_timer_fn(struct timer_list *timer)
* Already donating or accumulated enough to start.
* Determine the donation amount.
*/
- current_hweight(iocg, &hwa, &old_hwi);
hwm = current_hweight_max(iocg);
new_hwi = hweight_after_donation(iocg, old_hwi, hwm,
usage, &now);
--
2.36.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] blk-iocost: fix vtime loss calculation when iocg deactivate
2022-06-09 7:34 [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight Chengming Zhou
@ 2022-06-09 7:34 ` Chengming Zhou
2022-06-10 8:45 ` [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight Andreas Herrmann
1 sibling, 0 replies; 3+ messages in thread
From: Chengming Zhou @ 2022-06-09 7:34 UTC (permalink / raw)
To: tj, axboe; +Cc: linux-block, linux-kernel, Chengming Zhou
The commit ac33e91e2dac ("blk-iocost: implement vtime loss compensation")
will accumulate vtime loss of iocgs on the period, to compensate
the vtime loss we throw away, which is good for device utilization.
But the vtime loss calculation of iocg is wrong because of different
hweight_gen when having some iocgs deactivated.
ioc_check_iocgs()
...
} else if (iocg_is_idle(iocg)) {
ioc->vtime_err -= div64_u64(excess * old_hwi, --> old_hwi_1
WEIGHT_ONE);
}
commit_weights(ioc); --> hweight_gen increase
hweight_after_donation()
...
ioc->vtime_err -= div64_u64(excess * old_hwi, --> old_hwi_2
WEIGHT_ONE);
The old_hwi_2 of active iocgs is in fact not of the same hweight_gen
as the old_hwi_1 of idle iocgs. After idle iocgs deactivate and
hweight_gen increase, the old_hwi_2 become larger than it should be,
which cause the calculated vtime_err more than it should be.
I found this problem by noticing some abnormal vtime loss compensation
when having some cgroups with intermittent IO.
Since we already have recorded the usage_delta_us of each iocg, and
usage_us_sum is the sum of them, so the vtime loss calculation of
the period is straightforward and more accurate.
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
block/blk-iocost.c | 21 ++++-----------------
1 file changed, 4 insertions(+), 17 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 3cda08224d51..6c55c69d4aad 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -1730,7 +1730,6 @@ static u32 hweight_after_donation(struct ioc_gq *iocg, u32 old_hwi, u32 hwm,
atomic64_add(excess, &iocg->vtime);
atomic64_add(excess, &iocg->done_vtime);
vtime += excess;
- ioc->vtime_err -= div64_u64(excess * old_hwi, WEIGHT_ONE);
}
/*
@@ -2168,22 +2167,6 @@ static int ioc_check_iocgs(struct ioc *ioc, struct ioc_now *now)
} else if (iocg_is_idle(iocg)) {
/* no waiter and idle, deactivate */
u64 vtime = atomic64_read(&iocg->vtime);
- s64 excess;
-
- /*
- * @iocg has been inactive for a full duration and will
- * have a high budget. Account anything above target as
- * error and throw away. On reactivation, it'll start
- * with the target budget.
- */
- excess = now->vnow - vtime - ioc->margins.target;
- if (excess > 0) {
- u32 old_hwi;
-
- current_hweight(iocg, NULL, &old_hwi);
- ioc->vtime_err -= div64_u64(excess * old_hwi,
- WEIGHT_ONE);
- }
TRACE_IOCG_PATH(iocg_idle, iocg, now,
atomic64_read(&iocg->active_period),
@@ -2348,6 +2331,10 @@ static void ioc_timer_fn(struct timer_list *timer)
list_for_each_entry_safe(iocg, tiocg, &surpluses, surplus_list)
list_del_init(&iocg->surplus_list);
+ /* calculate vtime loss in this period */
+ if (period_vtime > usage_us_sum * ioc->vtime_base_rate)
+ ioc->vtime_err -= period_vtime - usage_us_sum * ioc->vtime_base_rate;
+
/*
* If q is getting clogged or we're missing too much, we're issuing
* too much IO and should lower vtime rate. If we're not missing
--
2.36.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight
2022-06-09 7:34 [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight Chengming Zhou
2022-06-09 7:34 ` [PATCH 2/2] blk-iocost: fix vtime loss calculation when iocg deactivate Chengming Zhou
@ 2022-06-10 8:45 ` Andreas Herrmann
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Herrmann @ 2022-06-10 8:45 UTC (permalink / raw)
To: Chengming Zhou; +Cc: tj, axboe, linux-block, linux-kernel
On Thu, Jun 09, 2022 at 03:34:49PM +0800, Chengming Zhou wrote:
> The commit ac33e91e2dac ("blk-iocost: implement vtime loss compensation")
> add the second current_hweight() in the loop of active iocgs list to
> get old_hwi to calculate the vtime loss of the iocg.
>
> Since the hwi can't change and the first current_hweight already get
> hwa and hwi, so this second superfluous current_hweight() can be
> removed. There should be no functional changes.
>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
FWIW. Looks ok.
Reviewed-by: Andreas Herrmann <aherrmann@suse.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-10 8:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-09 7:34 [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight Chengming Zhou
2022-06-09 7:34 ` [PATCH 2/2] blk-iocost: fix vtime loss calculation when iocg deactivate Chengming Zhou
2022-06-10 8:45 ` [PATCH 1/2] blk-iocost: remove the second superfluous current_hweight Andreas Herrmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox