From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.199 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796186356; b=BUztuzX3sniw6cTcW8CmbKg848OAPIfO4rJBlKaMZrPnWHzNYksRFf/16zeUL64f+KHA f3nPoKTGXJ8lcmrEO0uKboyyGUSaNISUtpWbQHDH8d0qO1XhLe65/O9DFT0x5FqwnMAFs 4qZ08z9oyUz/CkBa6gneQ7HQoGSQGvsLr771WK1BdrYdsEKrduuGSUUYL93qHGJR1ZEVc aUxJ9C5hmafCoV5D4rBaIP7M1R6kg/59HKd0Z+PmCuXv/i+I81gdHKSAEn2aaKtVjDeqY 2PfskxeVUPUcI5fA90+Ww258IM0wS26RI+6H3UZ2tQfH1yqfN6aSEAbGEv1Sb2k+5qQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796186356; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=v+T0ef4fuXdeqemycZx5zjZd8lddu0p1gqFp3glWggY=; b=bfRc5qRJm6UH5bwvnZak/6hpNY731/mvBLlETlb9IGe1iuhS8ENqiooewdDxbJwqAdR/ xoWkP9Xl5sIzTkJ7IhUmCxY2tQBeB/DC9SrFX+GIXCrT8MUikExoUPBjnjX/SNuWhWb+n Urbwkhv1Csv54LMymtQ+ZmPMHumhnwYDs0VRZqdsSLD0c4esZdWxSEvELU6Io6FJ4Furs 6jfRv883GgRPj13zpS72aH5o+aQMwwtBunhgCH+Yb37xtrFZA8Vt1hjmd++crtbyfcnAO +dgaTk1vru4VhGbYS2pOCPyBv4CzW3ft+oWTiFcOkKeIIXbzKET1h7YLyjBLs8Hsw4Q== 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=UTKW9Se9; arc=none smtp.remote-ip=209.85.210.199 Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.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 7F976606A31A for ; Wed, 2 Dec 2026 04:39:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F976606A31A 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=UTKW9Se9 Received: by mail-pf1-f199.google.com with SMTP id d2e1a72fcca58-8a0522cdaf3so8684906b3a.0 for ; Tue, 01 Dec 2026 20:39:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796186355; x=1796791155; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=v+T0ef4fuXdeqemycZx5zjZd8lddu0p1gqFp3glWggY=; b=UTKW9Se9eQHpmjC3AEkRt2mSqNXFm4kG3zf33rowMTSVGpaU3WXgyY5HvPTX6umh4h eqiwWjW5KdFEENkQnovA5QIyXz+3vmi5oolojA31Z4+kK4qcyftIfjSTE4vUJRe3Df1r Z353mUrdfiRj+My/4WUwGjrg+GyaJ/NK+z/PGA+qvTzChY0h0e+ZkHbOWl1ymJx5Z9TT bwJf7YXTlPFmckLwuisB5sFMtZdZgRpNTLAJQVMUoLcKpPtcAVCdVtUFkK9jm+qhDJWO Enbov4ZDoRRQPyudi5dk/tc03bWLEHCuohnAsUxKG1xDdBirXet8uYwduYDZA09BNW1Y un0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796186355; x=1796791155; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=v+T0ef4fuXdeqemycZx5zjZd8lddu0p1gqFp3glWggY=; b=uvvJJ7uyPJoy3XeyepaRBYJUoc2TaYs5lV1FbL9z/KDwpuMbo/Gto7MJy7obN+L/Ea Xqsn+u4leLBaSrLxzoNLXT1jCbGz0XhJE4ScrrEEeu7+0GP7btF7GlPUfhC+mApDk77M t1NsX8jrrCjEN1JxBwDlXxpksY2Uh91Pd6swCCvDZrZluZscmtatqN695fpM1rhk1JVY bmNSOeEaPU2fLkFE9AEJhL69yxrPxu36pcXSCk/d7xJcJaRBN8zeT0kI6B9KHbo+YOHg f0Bg/K6M7Yn8o1PIqhyH4XjTuL8SNGRe8CEvDb8yBB3Wj5pDd26h1DA430kQbDNETB6H 4hHw== X-Forwarded-Encrypted: i=1; AL+hErHdTmwFiORnqv0DresmOOe2oRCL66UVbz13Kv/tqI1R4el88OU7zDCYdPYGIvoHOH5bIEnG@lists.linux.dev X-Gm-Message-State: APuU4Z/VjFQPSrm55jHdeyyD9HynQhakK+YCZToBa6g+/Pqi20XBI7DJ ZG3hWOzp9XymeBLKrtGeE0c6Pk9f8UFkhr71HJ9lR7/eBMAKE4cxaR0KDcKtpcWy8TiUHWhD93m +lDBpjQjapqNVHzi7OREC0g== X-Received: from pgbq38.prod.google.com ([2002:a63:5c26:0:b0:cd6:23e7:ad7a]) (user=jenhaochen job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6372:a708:b0:400:9acd:e3eb with SMTP id adf61e73a8af0-4014d45ee7emr34267193637.37.1796186354411; Tue, 01 Dec 2026 20:39:14 -0800 (PST) Date: Wed, 2 Dec 2026 04:39:09 +0000 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 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202043911.2556266-1-jenhaochen@google.com> Subject: [PATCH v2 0/2] mm/zsmalloc: optimize zs_store() fast path 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" This two-patch series optimizes the zs_store() fast path on top of the stabilized zsmalloc changes in mm-new / next-20261201 (mm tree commit 5973b750e388): 1. Outline zs_store()'s new-zspage allocation path into a 6-arg noinline zs_store_slow(), matching free_page_chain(). This keeps alloc_zspage() and its zpdescs[] array off the fast path, enables sibling tail calls on x86_64, and shrinks zs_store() by 19-73%. 2. Pass size_class and a payload struct obj_loc directly from obj_malloc() to obj_write() and mark both __always_inline, eliminating the location_to_obj() -> obj_to_location() / class->size * obj_idx / ZsHugePage() round-trip and two out-of-line calls per store. Cumulative results (base -> patch 2; 4K pages, chain size 8): - arm64 Clang 22 -O2: -5.2% insns/pair, net .text +858 B - arm64 Clang 22 AFDO: -6.4% insns/pair, zs_store -56%, net .text +930 B - x86_64 Clang 22 -O2: -5.9% insns/pair, -6.0% pair / -7.3% zs_store() cycles, -5.0% pool growth, net .text +430 B - x86_64 Clang 22 AFDO: -6.9% insns/pair, -4.7% pair / -6.9% zs_store() cycles, -4.3% pool growth, zs_store -45%, net .text +446 B - x86_64 GCC 15 -O2: -4.1% insns/pair, zs_store() cycles neutral, -3.1% pool growth, zs_store -56%, net .text +372 B Verified byte-for-byte read-back via zs_obj_read_sg_begin()/end() across 1,024 regular objects (384..3136 B, including page-spanning slots) plus 4096 B huge objects, and clean builds across default, CONFIG_COMPACTION=n, and CONFIG_DEBUG_VM=y. Changes in v2: - Rebased onto next-20261201 (Sergey's object alloc API redesign and Wenchao's ZS_OBJ_CLASS_BITS lockless zs_free()). - Split into 2 patches separating slow-path outlining from the payload location handoff and inlining. - Outlined the full slow path into a 6-arg noinline zs_store_slow() instead of only marking alloc_zspage() noinline. - Passed size_class and struct obj_loc directly to obj_write() instead of relying on compiler CSE across lock calls. - Dropped __always_inline on obj_free(): on next-20261201, Clang 22 already inlines obj_free(), while forcing it inline on GCC 15 spills handle across _raw_spin_lock and regresses zs_free() (~+5 cycles). - Added bloat-o-meter / net .text deltas and cold pool growth numbers. - Link to v1: https://lore.kernel.org/r/20261030121700.260975-1-jenhaochen@google.com Jenhao Chen (2): mm/zsmalloc: outline slow path in zs_store() mm/zsmalloc: pass payload location to obj_write() mm/zsmalloc.c | 126 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 49 deletions(-) -- 2.56.1.911.g883d8bcb20-goog