From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796186356; b=aCs4UE+9tOQZkgNJVpyQW64ckB3mweL8nsvHBOqUNxssYU7icSd5tsBWhcn3uNaVRMaQ FnEyhshvkXQ8K4sgdVRud+npyIc2YfCFvBCmO+q0RUtDkwyhS5D7oG8BG3bOxeK8bp/6E AwyvM4Bz4NRTcKDZhaBtagv2PVlaq8fB9yZcwTAKVRonJt+J3ryWCUEsMEIwbWo2DGU5t 9ZTSrICHhN02MtGS8ctJKXNGzR+jBPK7zkEY3pn8Ccrqqa8XtapKOYaaV9yY+rXb30APY sug6GxAMVamDLFnnHu5t4FkThSXxHPDcC5BUGBJ/2GpOtYBVKwFavDhApr761isPLOg== 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=sm47j29UYbnO0hmmXuG27k3xZG/YdYbuEPtts/kE4z0ym8+jugaKEjatdBAAfqudRedx rhbdg+JG6TYSwdPuYp/BAOyS+xpaJ4DfEOHarfiUT/yAyT6E4KD5s9UkJdLhbzQqgqMYL CIiEnI5qoSh7+7N6WxdJ1o8KhDqUdQBb2SnVFbKNCof9XXcm0lSI8PR9aj/zXQ2SEb37q 9HUPsyn/qDKT/q1Rrjkx4kdqSNwwzh0KlTcSe6icGdAcv7Wci7GnylLjffuJtmS3mu+mX e3xumftF6myM4IU3e0NPXABbcJ8O3UoXH/ryTtR1Nan8F73AlIKe8Rj21Ws8qJ+6l1w== 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=nj1skWOw; arc=none smtp.remote-ip=209.85.215.200 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (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 81B78606A322 for ; Wed, 2 Dec 2026 04:39:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 81B78606A322 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=nj1skWOw Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cd5fd34fee0so7345416a12.3 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=vger.kernel.org; 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=nj1skWOwkUfg3G5CklPxkcCxSiKWQYeLudVkjown60IEszg2M9ZFjuHmgldN0UjB9P 4QJPgfU9IcnjwqXsvRIIBc3LdwJAMx5wcBnMtKrGV0F4JYdw//GhQwRSG5kIiQeFrHeS XfkGw4lSaBJjviOHZQvcZbz3yfG/WOlMTqjholVanguWZ+BL4TyPx7hvzvXdObbD8vmm aF7MHEtMzgos9tROlfh4b/K3kwy0DDbqUFJZO2szvTiBhSEYYyLfWdXDy3++6vR58NUN DqfmLLcmqFDYPwLQgKnqF6KoQEp40kasr0O1cwMWDTcCPNlsVxBT4NlhtfFitcCIniNT +7Og== 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=DCjAO9YypZa1EiyBPHlApNJwz9EFDxtY/zfNQ5JSfCWyfyC29mtn91K0m6+Xg2diqh a02B96I45RyLXFlWQj9ti1U71no/Ic2FDDXAH3Es8tyI/ZmZVTtNKndmLyun+bEvTI+o VAg4dsR13EVrVl6o0lhJFP9s05UwMwB2uxeOFnSIdcKzRqqLvUcCZlTiTyc7e2qna3k2 tcUwUOnxb1AhtUPwGEw6JZFZ3FLVA6hLwL2BxytzeLMqV3M5ciLZtNgiQMq+SLBpiy97 vQiXTxw+C8grFn70HOg6h2insHbMzD7EUSnvJombNRyPmjPBq40JPHdUFBrXja8NKytB w3oQ== X-Forwarded-Encrypted: i=1; AL+hErGbItN2RLiS8veP8DnAJEApO74RUPnd89+G48XEG/01nbJYZ7HoPDv/WtxjuTIx6UAKV5pMXHJ3yVFBlO8=@vger.kernel.org X-Gm-Message-State: APuU4Z9ZYVHLSIkCIZKSHxGHzIjZW7OrBg7YhLaOF2YERoySaT3wp3fZ NdM1X69X23AHpdeiipWG+PS/mQLQrhoIwPVml3UVBJXUyKIHfZke76k6xbsIl9/hHvY14bzLe6m O0IyJkjfeCAgBBpmLvQxscg== 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: linux-kernel@vger.kernel.org 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