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

From: Barry Song

Date: Thu Dec 03 2026 - 23:15:37 EST


On Fri, Dec 4, 2026 at 11:56 AM Hongfeng Chen
<chenhongfeng0212@xxxxxxxxx> wrote:
>
> From: Hongfeng Chen <hongfengchen@xxxxxxxxxx>
>
> On Mon, Nov 23, 2026 at 02:47:37PM +0900, Sergey Senozhatsky wrote:
> [..]
> > +static void zram_stat_add(struct zram *zram, enum zram_pcpu_stat item,
> > + s64 amount)
> > +{
> > + struct zram_pcpu_stats *stats = get_cpu_ptr(zram->pcpu_stats);
> > +
> > + local64_add(amount, &stats->stat[item]);
> > + put_cpu_ptr(zram->pcpu_stats);
> > +}
>
> On x86 local64_add() is an add without the LOCK prefix, but on arm64,
> which has no asm/local.h, it is a full atomic64_add(), and this patch
> makes munmap() slower there.

Right. On x86, an RMW operation can be performed in a single
instruction, which is atomic with respect to the local CPU.
A LOCK prefix is needed to guarantee atomicity across CPUs
for ordinary RMW instructions.

On arm64, we have to rely on atomic instructions or disable
preemption for CPU-local RMW operations.

In your case, get_cpu_ptr() already disables preemption, so I
think it's safe to switch to non-atomic operations on both x86
and arm64, assuming there are no concurrent accesses from
interrupt contexts.

Hi Sergey,
Could we squash Hongfeng's change into your original patch?

Thanks,
Barry