From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796186359; b=UxmoGENVUVHHJIc9zI0egbaVhJInejXdCKSYSUm2x6OzWyGY3oBuhSm864WD0BCri/SO /PtfAIxzSnkbXYu8ZXDexZozi/zDpgBznb7L6Ock4GrQup5anV0vyQoPLo+0lnIxAX/H8 uIy6FfTuvriwPRXVnHOnEcgtLta9AX1Nmmv0CzoraFTEX24AxPgtVvebyzcDSeeImSjS2 y/dDZew5Uvuj5wTgVHH5RZlJOIOu7f16a+USHekyb4Br7xcf+6XBAIX8PgRmyBLxlTbf/ Q577ReyTdhWkgfUryu3J0K4nJaUf0g6d8HegmT4O7ux+vMMpLeeU5Au4m+bmDyHEdyw== 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=pMUMA1wfg0qI9ZTu/lP35cR6tjNPpg1qXNrwvF+gUy7V2jG6/hSvLol/YmhNRg7yFu7X 1KgJajb3B8CO8Xi/Ickh77iLT9C8rsSnIi16Y8hE3nKwZqTDUcpm5hffT1oaxh/qdWNyV gilNUF6Ld5fRu9aHIBriqdBwroLUcCoBjARgPm1AuHlPlyANp/+sTrMjEHy1qm+Dzbq7B XQSsYKJ9xyglTV5iDBOQht97BpNtIbbAAjOno8vppv3urwByLf8VNETm0/bhJmdbtSqm+ Z8hPkDc0vRACIBRbPIix4SLz+bAO6h5tg5ur9b4enIyofK+HCFzIPnPZktR2Ixeph3Q== 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=IjTTpx8H; arc=none smtp.remote-ip=209.85.167.198 Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) (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 4B6BC606A329 for ; Wed, 2 Dec 2026 04:39:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4B6BC606A329 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=IjTTpx8H Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-4dc57e2a3f2so15500442b6e.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=vger.kernel.org; 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=IjTTpx8HnS7Hyu0v76NhgTRgDPsTb1ldAsYoG2es634O+o4vNlBApxGSyIHkZ+nxiA MYE3YjgoAORRJJjGNLyxy3oNl31+VuYyPyHDs/PlNFhpFKKmf9q3pYzZ/IQc2HBKAeCJ EIoYbbpOWiV/3CWcQH2DIBpwscJLpupGEKX8fGleAiD2ZzJyVg2+CmupOLtGRvP2eiMA ySYlm2hSs31W/Zdyq5tHPM0dTTWMLXMJTn/yYxnMZN9pkmrB83596dE9SKJrIc/GsAj2 7GXyQXSAiuHwDms6GSAtItuaB7P5erMDdTRaY9SeEbzVa7sFt+XO35Q4iIwPJ7KA4Z/K PaIg== 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=ZpG//Dd2JrHkuoOepCLd792X8YmATaN3DvKzAD51ZTtxeBzkV6cwDkQHaJwCFTQ0Rg SnEHLi4BGTL2MuEAadWzOTNAWWFaA2f5Ns61x1tIRaFezQuw8Mo1tQpAa0HL73QRZ912 GsbBxw8OlXvogndbw+c8MxsCfmJkv1HOZqz55n3SQNXbZeiLOrc3sl1ARN7xJAiP4/sw f0yqSkc7ylxxA3nhWr+ScKV7pIggE4y0uRFbq9ZZtIkCUVHT37BXIPv9iVVJjdwRsWTq fm1LBig+7Obt7/HpsPHblznBu770Vuns7QSrQPTyoys94TMEv0R1Tgd+z7ihb2z55iGO Pr5Q== X-Forwarded-Encrypted: i=1; AL+hErF09jrHpwTgiUPka/gTHMbg/J+jYlHVqHUQihtMAjnPetYkgErK8t3ltsXqE1zPbXnB6lGZhd2vAin+ygo=@vger.kernel.org X-Gm-Message-State: APuU4Z+xS/KrBKEWqi2qXt7R7J3xzLmTLxxFocw93zC1Zd1OPwR4E8gh DMT8n50f+Cbb/08KIEpJqGv+uZwB1hsNd8k9zuJsjrCRUPx5OlCtfvEnDaPdecReOkKx058q93G GJTuT1HelhrV5PJKRs1QX/A== 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: linux-kernel@vger.kernel.org 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