From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796186359; b=ra6t8R/4yzYU1GfDERBK5S+h9NRbfGkEmKI626mbfzC1zVU4i0ak53J41fzWcfmfYnUr 1e/jrgTxbMcXJ34/ge+qibqrWSTIXVRMyVP13cYZzBP18l41f7jvidPwpvJOZ/bQ2QAP3 mSME7dyioWgruHwalZtthhGSqr7abEagM3U0nseiWsouFGW7YOObgCfaPXbAUw7xoiDGk 2vIHwRk+gCf3Yrd00UcpAt6jw4+1hcnI0pYuVoQ6Nzn5McCtW1u1Ll14ARSU1Wz2T1+4S C0NMvZn1n96GyiG6VOt2NfmBb2eCWmja4HNShd0jTLU4Yo7fG9VcJCrcZh8hLoB1RWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796186359; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=Gx3pQnj1cIBGMuG+EtubD1hW9/LxT5oMhtOAv4gB2RU=; b=eQROLaSY2UWyJsSf4qPsZMTdaHniuy0utrmKVb8Qp4zBGPsqyAB8o57l3DL/307fScPQ x0Ob3G1P3vMYtDzkYShHMkjAdLW4zwRVMH5lXWFNjWrJ8zatQ8Iy6yaM4IaDwME1NBbj8 YUALEkCv/37mrhpZQ9JqQE7G57mFifQo5oecsBqmkWTMYqOxcbXW+50dIIuiCOVbieB3T iXyf1g6SJjwmA7tdnbuxRXBLpFSIq5duIRXfarzoFAVUOu/7YMhAs67a+z8mnjQZkHe96 dmg8+IZ0DsAZhMSKoEhJ0mfyS/UZ5v99XzQ/D94o82hR+gMoW8GMQevR+EhZ6e/cPwg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--jenhaochen.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=OchgrmaF; arc=none smtp.remote-ip=209.85.167.199 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44491606A322 for ; Wed, 2 Dec 2026 04:39:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44491606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jenhaochen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=OchgrmaF Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-4dc57e2a3f2so15500443b6e.0 for ; Tue, 01 Dec 2026 20:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796186358; x=1796791158; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Gx3pQnj1cIBGMuG+EtubD1hW9/LxT5oMhtOAv4gB2RU=; b=OchgrmaFGYMsIyFecl3v7RgvsX8SoLQQDnZuGCf8XYcT6Wah5AXG5XuPBGl7Q/eXQa dBZ/jXVA1RMcLmVZ5uf3zfOyYiP57ckGU+fpISjA9dF8qVTWuxwT0fbHjsJfFcLyk5Kl nb/LiqVozImD7YDQUpEf/mpzfqlx+CCHPvIGoOFkS4p8lAkX6jTQEOJq7gh0gGKanIgN 3y/MhUk3GaBnvp+3oQkw99r7h/nT4eKDgQpHUp0Njjpp/wFaK5jE+zmZDYtKkNL3CRKe AI7+BKmoQgieK3fZpfyE2WrcxssKi8vmH6xLPHZHOLEsfKdNKVey2/cnzHbnIwgnEwKB FIVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796186358; x=1796791158; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Gx3pQnj1cIBGMuG+EtubD1hW9/LxT5oMhtOAv4gB2RU=; b=dV4e04iKyEe46Qd1WVln105NwSfiYlxp11BZL6KoFM0voqA3qBa8+uclBx042faBTj oChIeh6Xg3uI0YtY0/9eUv0Feg2UEUK+nUIf54YDrw391t72sAASMFpuTGUX9MbBqXQM HkzcqwpqN0Lb78DwTt9r0z0Cuey9cQMTy43YJhoPbIVgZgvrOuCiT4pk+ufmQCpzGCZZ h5xhYW1EFvbbvRJN6ErcfhQoGdzZycbuNYcg3m4Ql25OITZmijFz0ls62WwoaxhM4qqS lf9gkjLG98Rd5CClgy+VUyZR6ZBFw4bR98q68tI27UoC5UyAZSWonr/x4Y13Qd8DAbwH DHwA== X-Forwarded-Encrypted: i=1; AL+hErF02PYVZ7U0JlMcvaX97zHYqTDKmOLUhcWUiTpWaitdNNCYadG+MU7Y1BVNolyBraMN4CR2@lists.linux.dev X-Gm-Message-State: APuU4Z/FwvDTbQckai7NgTuVg1yKRI1gNstoQsxkX3dWbM98bVguiThI 2DZEtmmfoSFi9Yw9XYdaPE4ibamf/ErNDn79wON26PZU8HWUsTjSsNTKOFja8HLVx2Qe9KIYh5s tqZJYTcSCVFn0BpttCfx48g== X-Received: from iok20-n1.prod.google.com ([2002:a05:6602:c614:10b0:9e8:9d0f:5a50]) (user=jenhaochen job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1a1f:b0:567:dd01:fcb8 with SMTP id 5614622812f47-57a056ce332mr40925415b6e.9.1796186357821; Tue, 01 Dec 2026 20:39:17 -0800 (PST) Date: Wed, 2 Dec 2026 04:39:10 +0000 In-Reply-To: <20261202043911.2556266-1-jenhaochen@google.com> X-Mailing-List: llvm@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202043911.2556266-1-jenhaochen@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202043911.2556266-2-jenhaochen@google.com> Subject: [PATCH v2 1/2] mm/zsmalloc: outline slow path in zs_store() From: Jenhao Chen To: Sergey Senozhatsky , Minchan Kim , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Brian Geffon , minchan@google.com, liumartin@google.com, benwei@google.com Content-Type: text/plain; charset="UTF-8" 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 --- 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