Re: [PATCH v3 2/2] zram: keep the hot statistics per CPU

From: Sergey Senozhatsky

Date: Sun Dec 06 2026 - 00:27:28 EST


On (26/12/06 12:58), Barry Song wrote:
> On Sun, Dec 6, 2026 at 11:55 AM Sergey Senozhatsky
> <senozhatsky@xxxxxxxxxxxx> wrote:
> >
> > On (26/12/04 11:56), Hongfeng Chen wrote:
> > [..]
> > > @@ -106,7 +106,7 @@ static void zram_stat_add(struct zram *zram, enum zram_pcpu_stat item,
> > > {
> > > struct zram_pcpu_stats *stats = get_cpu_ptr(zram->pcpu_stats);
> > >
> > > - local64_add(amount, &stats->stat[item]);
> > > + WRITE_ONCE(stats->stat[item], stats->stat[item] + amount);
> > > put_cpu_ptr(zram->pcpu_stats);
> > > }
> > >
> > > @@ -115,7 +115,7 @@ static void zram_stat_sub(struct zram *zram, enum zram_pcpu_stat item,
> > > {
> > > struct zram_pcpu_stats *stats = get_cpu_ptr(zram->pcpu_stats);
> > >
> > > - local64_sub(amount, &stats->stat[item]);
> > > + WRITE_ONCE(stats->stat[item], stats->stat[item] - amount);
> > > put_cpu_ptr(zram->pcpu_stats);
> >
> > How about __local64_add() / __local64_sub()?
>
> Makes sense to me, thanks!

It seems that on arm64 with LTO enabled __READ_ONCE emits ldapr/ldar +
"memory". So I ended up doing s64, with u64_stats_sync, basically
what Hongfeng had in RFC patch.