From: Hongfeng Chen <chenhongfeng0212@gmail.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Hongfeng Chen <hongfengchen@xiaomi.com>,
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>,
Barry Song <baohua@kernel.org>, 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: Fri, 4 Dec 2026 11:56:39 +0800 [thread overview]
Message-ID: <20261204035642.582133-1-chenhongfeng0212@gmail.com> (raw)
In-Reply-To: <20261123054746.2579253-3-senozhatsky@chromium.org>
From: Hongfeng Chen <hongfengchen@xiaomi.com>
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.
munmap() of 256MB of swapped out memory per process (ms), mm-new and
mm-new with the diff below:
mm-new patched speed-up
RK3588 A76 1 proc 23.23 19.94 1.165x
RK3588 A76 4 procs 40.00 37.86 1.057x
RK3588 A55 1 proc 47.98 45.84 1.047x
RK3588 A55 4 procs 95.97 94.73 1.013x
i7-14700HX 1 proc 10.24 10.22 1.002x
i7-14700HX 4 procs 30.26 29.89 1.012x
Could you fold something like this in?
---
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index cadce71c2d2a..ca4d38cadf77 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -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);
}
@@ -127,7 +127,7 @@ static u64 zram_stat_read(struct zram *zram, enum zram_pcpu_stat item)
for_each_possible_cpu(cpu) {
stats = per_cpu_ptr(zram->pcpu_stats, cpu);
- sum += local64_read(&stats->stat[item]);
+ sum += READ_ONCE(stats->stat[item]);
}
return sum < 0 ? 0 : sum;
diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h
index 1fbb00dc2c29..fe6ab482b280 100644
--- a/drivers/block/zram/zram_drv.h
+++ b/drivers/block/zram/zram_drv.h
@@ -16,7 +16,6 @@
#define _ZRAM_DRV_H_
#include <asm/byteorder.h>
-#include <asm/local64.h>
#include <linux/rwsem.h>
#include <linux/zsmalloc.h>
@@ -110,7 +109,7 @@ enum zram_pcpu_stat {
};
struct zram_pcpu_stats {
- local64_t stat[NR_ZRAM_PCPU_STATS];
+ s64 stat[NR_ZRAM_PCPU_STATS];
};
struct zram_stats {
next prev parent reply other threads:[~2026-12-04 3:56 UTC|newest]
Thread overview: 13+ 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-23 5:47 ` [PATCH v3 2/2] zram: keep the hot statistics per CPU Sergey Senozhatsky
2026-12-04 3:56 ` Hongfeng Chen [this message]
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
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=20261204035642.582133-1-chenhongfeng0212@gmail.com \
--to=chenhongfeng0212@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=baohua@kernel.org \
--cc=bgeffon@google.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=senozhatsky@chromium.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®