[Devel] [PATCH vz10] fs/fuse kio: zero cs_stats accumulators on each seqlock retry
Alexey Kuznetsov
kuznet at virtuozzo.com
Tue Jun 9 13:02:36 MSK 2026
Ack
But initialization at procedure header is redundant now.
On Thu, Jun 4, 2026 at 5:41 PM Konstantin Khorenko
<khorenko at virtuozzo.com> wrote:
>
> do_show_cs_stats() sums the per-cpu latency/rate counters into the
> on-stack accumulators (iolat, netlat, read_ops_rate, write_ops_rate,
> sync_ops_rate) inside a read_seqretry() loop. The accumulators were
> initialised only once, before the loop. If a writer
> (pcs_cs_update_stat() / pcs_cs_stat_up(), both under
> write_seqlock(&cs->stat.seqlock)) runs concurrently, read_seqretry()
> re-executes the loop body, summing every per-cpu counter a second time
> on top of the already-populated structs - producing over-counted values
> in the cs_stats output.
>
> Zero the accumulators at the top of each pass so a retry starts clean.
>
> Fixes: 0fb245bf6f1a ("fs/fuse kio: implement cs_stats statistics info")
> https://virtuozzo.atlassian.net/browse/VSTOR-132310
> Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
> ---
> fs/fuse/kio/pcs/fuse_stat.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/fs/fuse/kio/pcs/fuse_stat.c b/fs/fuse/kio/pcs/fuse_stat.c
> index 447e4a617655..3f57ef03c455 100644
> --- a/fs/fuse/kio/pcs/fuse_stat.c
> +++ b/fs/fuse/kio/pcs/fuse_stat.c
> @@ -340,6 +340,17 @@ static int do_show_cs_stats(struct pcs_cs *cs, void *ctx)
> int cpu;
>
> seq = read_seqbegin(&cs->stat.seqlock);
> + /*
> + * read_seqretry() may re-run this loop if a writer updated the
> + * stats meanwhile; zero the accumulators on every pass so a
> + * retry does not sum the per-cpu counters on top of the values
> + * already gathered by the previous (aborted) pass.
> + */
> + memset(&iolat, 0, sizeof(iolat));
> + memset(&netlat, 0, sizeof(netlat));
> + memset(&read_ops_rate, 0, sizeof(read_ops_rate));
> + memset(&write_ops_rate, 0, sizeof(write_ops_rate));
> + memset(&sync_ops_rate, 0, sizeof(sync_ops_rate));
> for_each_possible_cpu(cpu) {
> struct fuse_lat_stat *pcpu_iolat, *pcpu_netlat;
> struct pcs_perf_rate_cnt *pcpu_read_rate,
> --
> 2.47.1
More information about the Devel
mailing list