The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] block/blk-stat: fix mean loss when re-summing aggregated stats
@ 2026-07-20 13:38 Tao Cui
  2026-07-20 17:05 ` Tang Yizhou
  0 siblings, 1 reply; 3+ messages in thread
From: Tao Cui @ 2026-07-20 13:38 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Tejun Heo, Josef Bacik, Omar Sandoval, Bart Van Assche,
	linux-block, cgroups, linux-kernel, cui.tao, Tao Cui

From: Tao Cui <cuitao@kylinos.cn>

blk_rq_stat_sum() folds src into dst but only advances dst->mean and
dst->nr_samples, leaving dst->batch untouched.  The mean is computed
from src->batch (the raw per-cpu sum), so a stat that has already been
through one sum carries batch=0; if that aggregated stat is then used
as the src of another sum, its samples add nothing to the new mean.

iolatency hits exactly that: iolatency_check_latencies() first sums the
per-cpu stats into a local stat, then sums that local stat into
iolat->cur_stat.  After the first sum the local stat has batch=0, so
every later window drives cur_stat->mean toward zero.  On non-SSD
devices it stays at 0, making the latency_sum_ok(&cur_stat) check that
gates scaling up always true -- the scale-up hysteresis is effectively
defeated.  SSD devices use the percentile path and are unaffected.

Keep dst->batch in sync across sums so an aggregated stat can be reused
as a src.  blk_rq_stat.batch is internal to blk_rq_stat_init/_add/_sum
(no other reader in the tree), so the wbt and blk-mq consumers, which
only read ->mean/->min/->nr_samples, behave as before.

Fixes: 34dbad5d26e2 ("blk-stat: convert to callback-based statistics reporting")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>

---
 block/blk-stat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/blk-stat.c b/block/blk-stat.c
index de126e1ea5ac..4d4781350083 100644
--- a/block/blk-stat.c
+++ b/block/blk-stat.c
@@ -36,6 +36,7 @@ void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
 	dst->mean = div_u64(src->batch + dst->mean * dst->nr_samples,
 				dst->nr_samples + src->nr_samples);
 
+	dst->batch += src->batch;
 	dst->nr_samples += src->nr_samples;
 }
 
--
2.43.0

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

end of thread, other threads:[~2026-07-21  2:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 13:38 [PATCH] block/blk-stat: fix mean loss when re-summing aggregated stats Tao Cui
2026-07-20 17:05 ` Tang Yizhou
2026-07-21  2:36   ` Tao Cui

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