From: Jenhao Chen <jenhaochen@google.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>,
Minchan Kim <minchan@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Johannes Weiner <hannes@cmpxchg.org>,
Yosry Ahmed <yosry@kernel.org>, Nhat Pham <nphamcs@gmail.com>,
Chengming Zhou <chengming.zhou@linux.dev>,
Brian Geffon <bgeffon@google.com>,
minchan@google.com, liumartin@google.com, benwei@google.com
Subject: [PATCH v2 1/2] mm/zsmalloc: outline slow path in zs_store()
Date: Wed, 2 Dec 2026 04:39:10 +0000 [thread overview]
Message-ID: <20261202043911.2556266-2-jenhaochen@google.com> (raw)
In-Reply-To: <20261202043911.2556266-1-jenhaochen@google.com>
Because alloc_zspage() is static with a single caller, GCC 15 (-O2) and
Clang 22 (with CONFIG_AUTOFDO_CLANG) inline it into zs_store(). That
pulls alloc_zspage()'s zpdescs[ZS_MAX_PAGES_PER_ZSPAGE] array (64-128 B
on 64-bit) and its zero-fill under CONFIG_INIT_STACK_ALL_ZERO into
zs_store()'s stack frame and inflates the fast-path body up to 3 KB.
Move the new-zspage allocation path into a static noinline helper
zs_store_slow(), following the same pattern as free_page_chain(). Keep
zs_store()'s 6-argument signature (re-deriving size_class inside the slow
path) so x86_64 emits a register-only sibling tail call (jmp) without
spilling nid to the stack.
mm/zsmalloc.o sizes (4K pages, chain size 8):
Build zs_store() net .text bloat-o-meter
arm64 Clang 22 -O2 1,156 -> 940 B +146 B +0.71%
arm64 Clang 22 AFDO 3,060 -> 940 B +202 B +0.54%
x86_64 Clang 22 -O2 784 -> 622 B +34 B +0.24%
x86_64 Clang 22 AFDO 2,187 -> 850 B +178 B +1.21%
x86_64 GCC 15 -O2 1,993 -> 540 B +91 B +0.33%
Steady-state zs_store() + zs_free() benchmark (8 classes, 384..3136 B,
1,024 live objects, 4K pages; arm64 insns via QEMU, x86_64 native on AMD
EPYC 7B13, n=15 interleaved runs):
Build insns/pair pair cycles cold pool growth
arm64 Clang 22 -O2 +0.2% - -
arm64 Clang 22 AFDO -1.1% - -
x86_64 Clang 22 -O2 -0.1% -1.0% -1.4%
x86_64 Clang 22 AFDO -1.0% -0.7% +1.3% (noise)
x86_64 GCC 15 -O2 -0.7% +0.3% (noise) -0.7%
Signed-off-by: Jenhao Chen <jenhaochen@google.com>
---
mm/zsmalloc.c | 66 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 25 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index a1b6161..5f4e589 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1283,6 +1283,46 @@ static unsigned long obj_malloc(struct zs_pool *pool,
return obj;
}
+/*
+ * Allocate a new zspage and store into it. Not inlined (see
+ * free_page_chain()), so alloc_zspage()'s zpdescs[] array and slow-path
+ * register pressure stay off the zs_store() fast path. Matches
+ * zs_store()'s 6-argument signature to allow sibling tail calls on x86_64.
+ */
+static noinline int zs_store_slow(struct zs_pool *pool,
+ struct zs_handle *handle, const void *src,
+ size_t size, gfp_t gfp, const int nid)
+{
+ struct size_class *class = lookup_size_class(pool, size);
+ struct zspage *zspage;
+ unsigned long obj;
+ int newfg;
+
+ zspage = alloc_zspage(pool, class, gfp, nid);
+ if (!zspage)
+ return -ENOMEM;
+
+ /*
+ * New zspage is not in class->fullness_list or movable yet, so we
+ * can allocate the object and copy data before taking class->lock
+ * and without zspage_read_lock().
+ */
+ obj = obj_malloc(pool, zspage, handle);
+ obj_write(class, zspage, obj, src, size);
+
+ spin_lock(&class->lock);
+ newfg = get_fullness_group(class, zspage);
+ insert_zspage(class, zspage, newfg);
+ atomic_long_add(class->pages_per_zspage, &pool->pages_allocated);
+ class_stat_add(class, ZS_OBJS_ALLOCATED, class->objs_per_zspage);
+ class_stat_add(class, ZS_OBJS_INUSE, 1);
+
+ /* We completely set up zspage so mark them as movable */
+ SetZsPageMovable(pool, zspage);
+ spin_unlock(&class->lock);
+
+ return 0;
+}
/**
* zs_store() - Allocate block of given size from pool and copy data into it.
@@ -1306,7 +1346,6 @@ int zs_store(struct zs_pool *pool, struct zs_handle *handle, const void *src,
{
struct size_class *class;
unsigned long obj;
- int newfg;
struct zspage *zspage;
if (WARN_ON_ONCE(!valid_unallocated_handle(handle)))
@@ -1338,30 +1377,7 @@ int zs_store(struct zs_pool *pool, struct zs_handle *handle, const void *src,
spin_unlock(&class->lock);
- zspage = alloc_zspage(pool, class, gfp, nid);
- if (!zspage)
- return -ENOMEM;
-
- /*
- * New zspage is not in class->fullness_list or movable yet, so we
- * can allocate the object and copy data before taking class->lock
- * and without zspage_read_lock().
- */
- obj = obj_malloc(pool, zspage, handle);
- obj_write(class, zspage, obj, src, size);
-
- spin_lock(&class->lock);
- newfg = get_fullness_group(class, zspage);
- insert_zspage(class, zspage, newfg);
- atomic_long_add(class->pages_per_zspage, &pool->pages_allocated);
- class_stat_add(class, ZS_OBJS_ALLOCATED, class->objs_per_zspage);
- class_stat_add(class, ZS_OBJS_INUSE, 1);
-
- /* We completely set up zspage so mark them as movable */
- SetZsPageMovable(pool, zspage);
- spin_unlock(&class->lock);
-
- return 0;
+ return zs_store_slow(pool, handle, src, size, gfp, nid);
}
EXPORT_SYMBOL_GPL(zs_store);
--
2.56.1.911.g883d8bcb20-goog
next prev parent reply other threads:[~2026-12-02 4:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 4:39 [PATCH v2 0/2] mm/zsmalloc: optimize zs_store() fast path Jenhao Chen
2026-12-02 4:39 ` Jenhao Chen [this message]
2026-12-02 4:39 ` [PATCH v2 2/2] mm/zsmalloc: pass payload location to obj_write() Jenhao Chen
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=20261202043911.2556266-2-jenhaochen@google.com \
--to=jenhaochen@google.com \
--cc=akpm@linux-foundation.org \
--cc=benwei@google.com \
--cc=bgeffon@google.com \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liumartin@google.com \
--cc=llvm@lists.linux.dev \
--cc=minchan@google.com \
--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