From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Hongfeng Chen <chenhongfeng0212@gmail.com>
Cc: Barry Song <baohua@kernel.org>,
Hongfeng Chen <hongfengchen@xiaomi.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
Minchan Kim <minchan@kernel.org>, Nhat Pham <nphamcs@gmail.com>,
Yosry Ahmed <yosry@kernel.org>,
Brian Geffon <bgeffon@google.com>, Jens Axboe <axboe@kernel.dk>,
linux-mm@kvack.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] zram: keep the hot statistics per CPU
Date: Sun, 6 Dec 2026 14:34:23 +0900 [thread overview]
Message-ID: <axTzkF6jZLzhC9aP@google.com> (raw)
In-Reply-To: <20261206052928.1523132-1-chenhongfeng0212@gmail.com>
Hi,
On (26/12/06 13:29), Hongfeng Chen wrote:
> On Sun, Dec 06, 2026 at 12:58:53PM +0800, Barry Song wrote:
> > On Sun, Dec 6, 2026 at 11:55 AM Sergey Senozhatsky
> > <senozhatsky@chromium.org> wrote:
> > >
> > > How about __local64_add() / __local64_sub()?
> >
> > Makes sense to me, thanks!
> >
> > > Is {WRITE, READ}_ONCE of s64 is going to work on 32-bit arch?
> >
> > I don't think so if there are cross-CPU reads. get_cpu_ptr()
> > only disables preemption on the local CPU and doesn't prevent
> > other CPUs from concurrently reading the counter. A remote
> > CPU could still observe a torn 64-bit value on a 32-bit
> > architecture.
>
> Agreed. How about the below? It reads the counters under
> u64_stats_sync. On 32-bit this keeps the 64-bit reads consistent. On
> 64-bit u64_stats_sync is empty.
>
> ---
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index cadce71c2d2a..820e693f0593 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -106,7 +106,9 @@ 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]);
> + u64_stats_update_begin(&stats->syncp);
> + __local64_add(amount, &stats->stat[item]);
> + u64_stats_update_end(&stats->syncp);
I did a combo of syncp and s64 [1]
[1] https://lore.kernel.org/linux-kernel/20261206052927.2499698-1-senozhatsky@chromium.org
next prev parent reply other threads:[~2026-12-06 5:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 5:47 [PATCH v3 0/2] zram: zsmalloc: speed up zspage free path Sergey Senozhatsky
2026-11-23 5:47 ` [PATCH v3 1/2] zsmalloc: free a zspage's pages in one batch Sergey Senozhatsky
2026-11-24 0:11 ` + zsmalloc-free-a-zspages-pages-in-one-batch.patch added to mm-new branch Andrew Morton
2026-11-23 5:47 ` [PATCH v3 2/2] zram: keep the hot statistics per CPU Sergey Senozhatsky
2026-11-24 0:11 ` + zram-keep-the-hot-statistics-per-cpu.patch added to mm-new branch Andrew Morton
2026-12-06 5:29 ` [PATCH v2] zram: keep the hot statistics per CPU Sergey Senozhatsky
2026-12-06 5:35 ` Sergey Senozhatsky
2026-12-04 3:56 ` [PATCH v3 2/2] " Hongfeng Chen
2026-12-04 4:15 ` Barry Song
2026-12-06 3:44 ` Sergey Senozhatsky
2026-12-06 3:55 ` Sergey Senozhatsky
2026-12-06 4:58 ` Barry Song
2026-12-06 5:27 ` Sergey Senozhatsky
2026-12-06 5:29 ` Hongfeng Chen
2026-12-06 5:34 ` Sergey Senozhatsky [this message]
2026-12-06 6:19 ` Barry Song
2026-12-06 6:22 ` Sergey Senozhatsky
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=axTzkF6jZLzhC9aP@google.com \
--to=senozhatsky@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=baohua@kernel.org \
--cc=bgeffon@google.com \
--cc=chenhongfeng0212@gmail.com \
--cc=hongfengchen@xiaomi.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=nphamcs@gmail.com \
--cc=yosry@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.