From: Tao Cui <cui.tao@linux.dev>
To: Guixin Liu <kanie@linux.alibaba.com>,
Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
Tejun Heo <tj@kernel.org>, Josef Bacik <josef@toxicpanda.com>,
Nilay Shroff <nilay@linux.ibm.com>,
Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.de>,
Tang Yizhou <yizhou.tang@shopee.com>
Cc: cui.tao@linux.dev, linux-block@vger.kernel.org
Subject: Re: [PATCH 5/7] blk-stat: account for the mean of the source in blk_rq_stat_sum()
Date: Thu, 19 Nov 2026 21:32:12 +0800 [thread overview]
Message-ID: <d64b0846-2da8-409e-af7f-86b4e0e02a2a@linux.dev> (raw)
In-Reply-To: <20261119070548.3125491-6-kanie@linux.alibaba.com>
Hello, Guixin,
在 2026/11/19 15:05, Guixin Liu 写道:
> blk_rq_stat_sum() folds a src into a dst by combining dst->mean with
> src->batch only, so it is only correct while src has never been folded
> itself: its mean is then either zero or stale. blk-iolatency folds the
> per-cpu stats into a window-local stat first and then folds that result
> into iolat->cur_stat, so the second fold drops the whole window and
> cur_stat.rqs.mean stays at zero. On rotating disks, where the mean
> decides whether the accumulated window meets the latency target,
> iolatency_check_latencies() therefore always considers the accumulated
> window OK and scales up more aggressively than intended.
>
> Fold src->mean * src->nr_samples into the result as well. The per-cpu
> users keep their mean at zero through blk_rq_stat_init(), so their
> behavior is unchanged.
>
I posted a fix for the same issue before, which Tang Yizhou reviewed:
https://lore.kernel.org/all/20260904065426.1281914-1-cui.tao@linux.dev/
Adding him here to take a look at your approach as well. Hope the link helps.
Thanks,
Tao
> Fixes: 451bb7c33197 ("blk-iolatency: keep track of previous windows stats")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
> ---
> block/blk-stat.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/block/blk-stat.c b/block/blk-stat.c
> index d57c2fc6bf06..6345ae366658 100644
> --- a/block/blk-stat.c
> +++ b/block/blk-stat.c
> @@ -24,7 +24,10 @@ void blk_rq_stat_init(struct blk_rq_stat *stat)
> stat->batch = 0;
> }
>
> -/* src is a per-cpu stat, mean isn't initialized */
> +/*
> + * The mean of @src must have been calculated or set to zero by
> + * blk_rq_stat_init() before calling this.
> + */
> void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
> {
> if (dst->nr_samples + src->nr_samples <= dst->nr_samples)
> @@ -33,7 +36,8 @@ void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
> dst->min = min(dst->min, src->min);
> dst->max = max(dst->max, src->max);
>
> - dst->mean = div_u64(src->batch + dst->mean * dst->nr_samples,
> + dst->mean = div_u64(dst->mean * dst->nr_samples +
> + src->mean * src->nr_samples + src->batch,
> dst->nr_samples + src->nr_samples);
>
> dst->nr_samples += src->nr_samples;
next prev parent reply other threads:[~2026-11-19 13:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 7:05 [PATCH 0/7] block fixes found by code inspection Guixin Liu
2026-11-19 7:05 ` [PATCH 1/7] blk-mq: free the rqs arrays of tags in the SRCU callback Guixin Liu
2026-11-19 7:05 ` [PATCH 2/7] blk-mq: clear stale stopped flag on hctx reuse Guixin Liu
2026-11-19 7:05 ` [PATCH 3/7] blk-iocost: don't take rq_qos_mutex before the queue is frozen in cost model write Guixin Liu
2026-11-19 13:40 ` Tao Cui
2026-11-19 7:05 ` [PATCH 4/7] blk-iocost: unfreeze the queue before dropping the bdev reference in qos write Guixin Liu
2026-11-19 7:05 ` [PATCH 5/7] blk-stat: account for the mean of the source in blk_rq_stat_sum() Guixin Liu
2026-11-19 13:32 ` Tao Cui [this message]
2026-11-19 7:05 ` [PATCH 6/7] blk-cgroup: don't attach a qos policy to a dead disk Guixin Liu
2026-11-19 7:05 ` [PATCH 7/7] blk-mq: unpublish the tags before deferring their free to SRCU Guixin Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d64b0846-2da8-409e-af7f-86b4e0e02a2a@linux.dev \
--to=cui.tao@linux.dev \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=kanie@linux.alibaba.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nilay@linux.ibm.com \
--cc=tj@kernel.org \
--cc=yizhou.tang@shopee.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox