Re: [PATCH v2] zram: keep the hot statistics per CPU
From: Sergey Senozhatsky
Date: Sun Dec 06 2026 - 02:16:25 EST
On (26/12/06 14:53), Barry Song wrote:
> > ret = sysfs_emit(buf,
> > "%8llu %8llu %8llu %8lu %8ld %8llu %8lu %8llu %8llu\n",
> > orig_size << PAGE_SHIFT,
> > - (u64)atomic64_read(&zram->stats.compr_data_size),
> > + zram_stat_read(zram, ZRAM_STAT_COMPR_DATA_SIZE),
> > mem_used << PAGE_SHIFT,
> > zram->limit_pages << PAGE_SHIFT,
> > max_used << PAGE_SHIFT,
> > - (u64)atomic64_read(&zram->stats.same_pages),
> > + zram_stat_read(zram, ZRAM_STAT_SAME_PAGES),
> > atomic_long_read(&pool_stats.pages_compacted),
> > - (u64)atomic64_read(&zram->stats.huge_pages),
> > - (u64)atomic64_read(&zram->stats.huge_pages_since));
> > + zram_stat_read(zram, ZRAM_STAT_HUGE_PAGES),
> > + zram_stat_read(zram, ZRAM_STAT_HUGE_PAGES_SINCE));
> >
>
> I'm wondering if batching multiple counter updates and reads would
> help further, along the lines of what Hongfeng originally proposed
> (with the code adapted to Sergey's new implementation, of course):
>
> + stats = get_cpu_ptr(zram->pcpu_stats);
> + u64_stats_update_begin(&stats->syncp);
> + WRITE_ONCE(stats->pages_stored, stats->pages_stored + pages);
> + WRITE_ONCE(stats->compr_data_size, stats->compr_data_size + bytes);
> + WRITE_ONCE(stats->same_pages, stats->same_pages + same);
> + WRITE_ONCE(stats->huge_pages, stats->huge_pages + huge);
> + u64_stats_update_end(&stats->syncp);
> + put_cpu_ptr(zram->pcpu_stats);
I suppose on 64-bit this just saves preempt_disable/enable, as
__u64_stats_update_begin/end should be no-ops?