From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796103445; b=mCIDpVHkznJDuouIdbR+4hTRMGM5XPuHuIb1ZBI154AC+kHzX/zVUMqFjNgi6QEfhvvm n3NEYQyVn2jwdJpzlfs/qkH5YsiIRCPserr08xmCNQvtewX43lkB/n0zslHY7VFE9CVxM GOiznCIbXRWxORvEhixlgyDuM5g2MGNdDWlb5wCtZHRUnCcgdYO9kEdlOsIYoEs7eoI2U 5liycw/SCkOoyLTsH7S/SM927EO+fUtZlYOrmRKWcnz5ru5mNXGqKsiu1sPZSdRJtjBbG 0vEFiRMQUhFgBdczedV2mw1aGwDxjxFUBnyD3M38P9KYQuDKZ1wSZKvAEEaKjCmhiKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796103445; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=xFn4MLOXlmYgktRAaX1zzc9+9xZ8hqz6M/pTpqHaQqQ=; b=2Rvf0SGemOCZoFvFiYI6OR48E3m3GCmSJaZk/D4usCELk/OIb8cRlqSGgOyRf5TePLyv GwpEV8GlI24JO5DFZRyXBaD3l2DMgSQfvVgAmpJuCT3HEywSj3+VOq6xzCFVUn1DH/H5H OD1p0S3bUXtwWdpyagVOu/zFQEY5lI3pmKQl8i/5jS8iRlQvyApe4FvDSqxdmFYAZfNSU /OZwTIgTfdn0jcD5axH/RAPbBRisvHuWh9C0cQjMUWLR6El8810kryViSPTS8Rbfg611r pMAAyHY/69BWvzQLHbHHYK+l+s1UwUXLC59tUbHSbmQVef3S9HeuB1BjLgHNLyMSrUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CAkNZtkg; arc=none smtp.remote-ip=74.125.82.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (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 CFFDB606A320 for ; Tue, 1 Dec 2026 05:37:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CFFDB606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=CAkNZtkg Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-1a2761c69fbso18969155c88.0 for ; Mon, 30 Nov 2026 21:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796103443; x=1796708243; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=xFn4MLOXlmYgktRAaX1zzc9+9xZ8hqz6M/pTpqHaQqQ=; b=CAkNZtkgeyKmtMmv1Ep95Qx+oSCSxhBbM2vLLJaGSIk3yHFJyojKM4BexaG2t2Jiw9 +/Gh0XrhP8+y3nUF3o3l8/rUmXdsyEyE0o6RRyRItf62rbhX0/BLVgljZ97tva2QQULu GbfwEW9VXGazWG1DhGb3RbCbUuPSbzpBdmTpAacYoXn2CY+LMckd7iUZ+iPv1ORaaVkb DpBKaReSYaTqhcqju7yD0oO2atLoQ3ObsIPoidWeSe5IE6Z1qvpEa9Sj0o9c28AsBrsL wxc19C207EQ1vSOUu5VhAuhahnV+8EuZfQtcIqSch+W9yHOXZu+99fbDwDWQ26eX2RxB 5qng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796103443; x=1796708243; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xFn4MLOXlmYgktRAaX1zzc9+9xZ8hqz6M/pTpqHaQqQ=; b=FojoxZtyyvdvYbKun0gQN5vG3pat1WiU/rQJR8WP7l6+2VSbZhyYdjuMpYeJwlnrYY 5uk3EWGUZoIN//cz31/ZBzEdI7cOogl+/32rSiqQCkj9TEMw4UR/H7WAif7CEGct/E8U GT78TCEMRqQmVHeJQifU3qTuKeKrvgREzZSD/etDuU2BGHlIJz72LieuX8ze7PbKSUCl ehO/OJ9+2GT6xgmmCOs1y1wxhTXoZEqljaPFqlqw72Ca20V97MZC4IPCSwTG+CpRpU4Z LrdumxD1+GotIGjKeoQzbozt/weA5xUpF/d7yaf/hCl3be5lYBumHfPlWR9ADrPlqD9b hbFw== X-Forwarded-Encrypted: i=1; AL+hErGl3I+uK+Y3OOrlriLbGbnqcMZVQ3ARi6A8BanIfr1ISryjerW43DqruuNHmsI06TU21wu6ANLsJyr6NT8=@vger.kernel.org X-Gm-Message-State: APuU4Z/4L9ucSzihYXaKzhon5MT7LZawb69QCeIem78lidjNnlN93W8u TaZpEnZS4h7clYlpCj/4AbU1O2g7Wl7SWFP9qnd6F78s0vpG/y3K71luQfJSk8Y/ X-Gm-Gg: AZFdTZf76eEbG7O0Yz4xqB/c7WQPRQh6RXC3EDV1lv8tkXZH12WSITu3ZV4aUtEPBXQ dQn4gKniPPay1vAhAVje/eeSpktvj1peyV9Q9xzVhTr0/NpXRIF9oDqM3HkZyLhKvez+Zi95g48 ko7R/6/FFEr7atLcCqXZIHRCtEJRzkeOA1JsCwhkrnP1g0fJ20rJSUaMQUzNpm2OzeD2ZVHUf8N mFZZIH1BlBAh8fbAUT6Z6tdZjGXAazmdl0yCG5McT6/E447KYeoWqTyF8jAxKFhX2EqcY0bFMdI 7Zl56XOiCGqNpAlP1gG9vdwRe88sRcPih9cVCFbPBQvnU1s0pIOQ5qqz6BV9vQ0it1fKUfy9qFd 3HTZB3KZmmJm70v9OgkA7L4WOJ0N2ohmqBmq94CLqrUmIVaS8NyHXjT9SH8swcLRnvSDYdW/jEK 40eQBQcIYncoGpmrhQIeJKR/pwgtj6n3Dyi8Vo7mtie6fDt4l2OLQr8cEQ6DL7hZ8QAz0ff8zkc ZsZKTEDvHgifvUAsXVAswIizsSaMPb/+yTSGcab//jEhwtXpt2IbAp709GJkfhPIz4ebCvbisiU AMp6rke06vlN6AN1JWqmZWc0H6BUud4BrJokzufbKg== X-Received: by 2002:a05:701b:4593:b0:177:9a5b:a89 with SMTP id a92af1059eb24-1b556906925mr36043778c88.29.1796103442447; Mon, 30 Nov 2026 21:37:22 -0800 (PST) Received: from penguin.lxd ([12.187.136.98]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5566c3052sm81183292c88.1.2026.11.30.21.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 21:37:21 -0800 (PST) From: "Kanchana P. Sridhar" To: hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, chengming.zhou@linux.dev, akpm@linux-foundation.org, linux-mm@kvack.org, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, kanchanapsridhar2026@gmail.com, linux-kernel@vger.kernel.org Cc: rientjes@google.com, willy@infradead.org, senozhatsky@chromium.org Subject: [PATCH v5 0/9] Batched zswap_store() framework with compression batching Date: Mon, 30 Nov 2026 21:37:02 -0800 Message-Id: <20261201053711.8090-1-kanchanapsridhar2026@gmail.com> X-Mailer: git-send-email 2.39.5 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 Content-Transfer-Encoding: 8bit v5: Batched zswap_store() framework with compression batching ============================================================= This series is a spin-off of "v14: zswap compression batching with optimized iaa_crypto driver" [1], and focuses on the generic crypto_acomp and zswap compression batching enablers. Resuming work on this series following a gap since v14 (January 2026). Please note that my email address and affiliation have changed from kanchana.p.sridhar@intel.com to kanchanapsridhar2026@gmail.com. I have retained the original Intel sign-offs on prior patches for historical attribution while signing off v5 of this series with my current address. The main focus of v5 was to validate zswap_store() latency gains with compression batching using BPFTRACE measurements, and co-relate those gains with high level Sys time workload metrics. This was done using an Intel Sapphire Rapids bare-metal instance with 48 physical cores and by running "usemem30", i.e., 30 concurrent usemem processes, each of which allocates 10G, in a 150G memory.high contrained cgroup, for 10 iterations. Both, unmodified usemem, and a locally modified version that reads the Silesia dataset [2] were run at scale under stringent 2x memory over-commit constraints. The environment was set up to minimize performance jitter so we can understand the system-level/workload-level advantages of zswap compression batching when running workloads at scale. To summarize the main contribution of this patch series: Batching is introduced in zswap_store() of large folios: we carve out a large folio into batches of ZSWAP_MAX_BATCH_SIZE (4 pages) for software compressors, and store each batch. Moving the fundamental operations that need to be happen to store a page to now work at the granularity of a batch offers opportunities to optimize them from these perspectives: 1) Utilize existing kernel API that minimize obtaining locks for bulk operations, e.g. kmem_cache_alloc_bulk()/kmem_cache_free_bulk(). 2) We keep the working set for each of the core store functionalities (alloc/initialize zswap entries, compress pages, store pages in zsmalloc, pool/objcg reference increments, objcg charging) to be focused on a batch, thereby minimizing cache evictions and benefiting from cache locality. 3) Along the lines of (1), the main zswap_compress() batching routine obtains the comp_ctx mutex lock once per batch, and releases it after it has processed all pages in that batch. 4) Any zswap store functionality that works on a batch can potentially be optimized via bulk-processing/parallelized as a next step, to further improve performance. Validation was done with mm-unstable as of 11-17-2026 (Baseline: commit 866f761fd414) and with this patch series. ======================================================================== PERFORMANCE TESTING PHASE 1 (ZSTD): Unmodified usemem30 with 100% over-commit: ======================================================================== Validation platform: Intel Xeon Sapphire Rapids bare-metal instance with 48 cores. Bare-metal instance specs: -------------------------- - 48 physical cores - 190G RAM - 200G SWAP disk partition Workload: 30 concurrent usemem processes, each allocates 10G: ------------------------------------------------------------- The vm-scalability "usemem" test (unmodified version) was run in a cgroup with memory.high fixed at 150G. There is no swap limit set for the cgroup. To quantify the performance benefit of zswap compress batching at scale, 30 usemem processes were run ("usemem30"), each allocating and writing 10G of memory, and sleeping for 10 sec before exiting. usemem -w -O -b 5 -s 10 -n 30 10g echo 0 > /sys/module/zswap/parameters/shrinker_enabled ZSTD is the zswap compressor. Performance validation methodology: ----------------------------------- These settings were used to minimize variation: - All cores were fixed to run at 2.4GHz with "performance" scaling governor. - Turbo boost was disabled. - CPU power-saving C-states restricted with: GRUB_CMDLINE_LINUX_DEFAULT="intel_idle.max_cstate=1 processor.max_cstate=1" The usemem30 experiments were run with the baseline mm-unstable as of 11-17-2026 (commit 866f761fd414) and with this patch-series. After booting into each kernel: 1) Constrain the cgroup's memory.high to 150G. 2) Run 2 warm-up iterations of usemem30. Don't use this data for benchmarking since sys time typically skews higher for initial runs. 3) Next, run 10 benchmarking iterations of usemem30: - Log these high-level metrics: Sys time and individual usemem throughput. 4) Sys time and Throughput metrics were gathered for three mTHP settings: - 2048kB - 1024kB - 64kB 5) Benchmark summary data includes Sys time and Throughput components from the 10 iterations of usemem30: - Total Samples - Mean Value - Std Deviation - CoV (Variance): Coefficient of variation (relative standard deviation) measures spread relative to the mean rather than statistical variance. An LLM was used to help generate the benchmarking and data processing scripts. usemem30 ZSTD Benchmarking Summary: =================================== ------------------------------------------------------------------ Improvement over mm-unstable with zswap compress batching ------------------------------------------------------------------ mTHP enabled: 2048kB 1024kB 64kB ------------------------------------------------------------------ Sys time: -13.87% -2.64% -1.72% Throughput: +3.85% +0.42% +1.31% ------------------------------------------------------------------ Detailed usemem30 ZSTD benchmarking data: ========================================= 1) 2048kB mTHP: =============== ----------------------------------------------------------------------- 2048kB mTHP usemem30 benchmark suite: 10 runs (Limit: 150G). ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (sec) batching (sec) ----------------------------------------------------------------------- [Run 1/10] Sys Time: 1581.414s 1356.252s [Run 2/10] Sys Time: 1642.874s 1478.929s [Run 3/10] Sys Time: 1594.458s 1411.252s [Run 4/10] Sys Time: 1580.988s 1380.959s [Run 5/10] Sys Time: 1579.654s 1380.609s [Run 6/10] Sys Time: 1627.765s 1345.582s [Run 7/10] Sys Time: 1593.872s 1334.485s [Run 8/10] Sys Time: 1623.189s 1405.471s [Run 9/10] Sys Time: 1661.954s 1433.365s [Run 10/10] Sys Time: 1602.098s 1329.813s ----------------------------------------------------------------------- ----------------------------------------------------------------------- METRIC: System CPU Time (Sys Time) : 2048kB mTHP ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (sec) batching (sec) ----------------------------------------------------------------------- Total Samples : 10 10 Mean Value : 1,608.83 1,385.67 Std Deviation : 28.67 47.47 CoV (Variance) : 1.78% 3.43% ----------------------------------------------------------------------- METRIC: Per-Process Throughput : 2048kB mTHP ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (KB/s) batching (KB/s) ----------------------------------------------------------------------- Total Samples : 300 300 Mean Value : 292,261 303,508 Std Deviation : 12,946 20,806 CoV (Variance) : 4.42% 6.86% ----------------------------------------------------------------------- 2) 1024kB mTHP: =============== ----------------------------------------------------------------------- 1024kB mTHP usemem30 benchmark suite: 10 runs (Limit: 150G). ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (sec) batching (sec) ----------------------------------------------------------------------- [Run 1/10] Sys Time: 1567.639s 1594.696s [Run 2/10] Sys Time: 1537.577s 1456.113s [Run 3/10] Sys Time: 1538.562s 1521.887s [Run 4/10] Sys Time: 1626.176s 1531.962s [Run 5/10] Sys Time: 1593.955s 1528.733s [Run 6/10] Sys Time: 1643.519s 1558.482s [Run 7/10] Sys Time: 1510.613s 1480.177s [Run 8/10] Sys Time: 1632.018s 1584.093s [Run 9/10] Sys Time: 1569.424s 1528.915s [Run 10/10] Sys Time: 1552.747s 1570.451s ----------------------------------------------------------------------- ----------------------------------------------------------------------- METRIC: System CPU Time (Sys Time) : 1024kB mTHP ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (sec) batching (sec) ----------------------------------------------------------------------- Total Samples : 10 10 Mean Value : 1,577.22 1,535.55 Std Deviation : 45.13 43.79 CoV (Variance) : 2.86% 2.85% ----------------------------------------------------------------------- METRIC: Per-Process Throughput : 1024kB mTHP ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (KB/s) batching (KB/s) ----------------------------------------------------------------------- Total Samples : 300 300 Mean Value : 289,904 291,114 Std Deviation : 15,385 14,553 CoV (Variance) : 5.31% 5.00% ----------------------------------------------------------------------- 3) 64kB mTHP: ============= ----------------------------------------------------------------------- 64kB mTHP usemem30 benchmark suite: 10 runs (Limit: 150G). ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (sec) batching (sec) ----------------------------------------------------------------------- [Run 1/10] Sys Time: 1914.525s 1878.483s [Run 2/10] Sys Time: 1869.412s 1863.177s [Run 3/10] Sys Time: 1944.049s 1863.502s [Run 4/10] Sys Time: 1942.757s 1900.144s [Run 5/10] Sys Time: 1866.505s 1887.285s [Run 6/10] Sys Time: 1877.716s 1861.668s [Run 7/10] Sys Time: 1861.741s 1868.788s [Run 8/10] Sys Time: 1904.735s 1816.372s [Run 9/10] Sys Time: 1891.074s 1850.435s [Run 10/10] Sys Time: 1893.366s 1849.747s ----------------------------------------------------------------------- ----------------------------------------------------------------------- METRIC: System CPU Time (Sys Time) : 64kB mTHP ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (sec) batching (sec) ----------------------------------------------------------------------- Total Samples : 10 10 Mean Value : 1,896.59 1,863.96 Std Deviation : 29.86 22.96 CoV (Variance) : 1.57% 1.23% ----------------------------------------------------------------------- METRIC: Per-Process Throughput : 64kB mTHP ----------------------------------------------------------------------- Baseline mm-unstable zswap compress (KB/s) batching (KB/s) ----------------------------------------------------------------------- Total Samples : 300 300 Mean Value : 239,114 242,254 Std Deviation : 9,090 6,419 CoV (Variance) : 3.80% 2.65% ----------------------------------------------------------------------- BPFTRACE of zswap_store() with ZSTD and PMD folios: =================================================== Performance validation Phases 2 and 3 measure the zswap_store() latency gains directly with bpftrace and co-relate this to Sys time improvements at the workload level. PMD folios are enabled for the usemem30 experiments. 1) Ran Unmodified Usemem and Usemem that reads in the Silesia compression dataset [2] for 10 iterations. 2) Gathered zswap_store() bpftrace kernel latencies for each iteration, with the help of LLM generated scripts: a) Each iteration reports Sys time along with cumulative zswap_store() latency for that iteration. b) bpftrace aggegrates nsec spent in zswap_store() calls. c) bpftrace uses lhist windows: Much better accuracy than log2 hist: PMD folios lhist: /* 10000 us - 25000 us in 15 us steps (1000 buckets) */ @zswap_higher_order_folio_store_ns = lhist($lat, 10000000, 25000000, 15000); Order-0 folios lhist: /* 0 - 500 us in 500 ns steps (1000 buckets) */ @zswap_order0_folio_store_ns = lhist($lat, 0, 500000, 500); 3) Ran without/with zswap shrinker enabled. Results and conclusions follow. ======================================================================= BPFTRACE PERFORMANCE TESTING PHASE 2 (ZSTD): Unmodified & Silesia usemem30 with 100% over-commit: without zswap shrinker: ======================================================================= zswap_compressor = ZSTD, zswap_shrinker = N: ================================================================================ Unmodified Usemem (100% over-commit): ================================================================================ usemem -w -O -b 5 -s 10 -n 30 10g cgroup memory.high = 150G zswap max_pool_percent = 20% (default) -------------------------------------------------------------------------------- Baseline: ========= [+] Starting benchmark suite: 10 runs (Limit: 150G). ---------------------------------------------------------------------------- [Run 1/10] Sys Time: 2082.624s | zswap_store: 1279.346867s [Run 2/10] Sys Time: 2076.123s | zswap_store: 1279.284415s [Run 3/10] Sys Time: 2067.660s | zswap_store: 1279.446595s [Run 4/10] Sys Time: 2087.806s | zswap_store: 1279.958761s [Run 5/10] Sys Time: 2105.170s | zswap_store: 1278.988750s [Run 6/10] Sys Time: 2059.407s | zswap_store: 1278.937106s [Run 7/10] Sys Time: 2076.392s | zswap_store: 1279.162205s [Run 8/10] Sys Time: 2078.407s | zswap_store: 1279.057718s [Run 9/10] Sys Time: 2074.148s | zswap_store: 1279.366872s [Run 10/10] Sys Time: 2045.885s | zswap_store: 1279.217773s ---------------------------------------------------------------------------- zswap_compress_batching: ======================== [+] Starting benchmark suite: 10 runs (Limit: 150G). ---------------------------------------------------------------------------- [Run 1/10] Sys Time: 1980.633s | zswap_store: 1274.292791s [Run 2/10] Sys Time: 2029.989s | zswap_store: 1274.619375s [Run 3/10] Sys Time: 1983.237s | zswap_store: 1274.533935s [Run 4/10] Sys Time: 2022.402s | zswap_store: 1274.328900s [Run 5/10] Sys Time: 1989.381s | zswap_store: 1275.065320s [Run 6/10] Sys Time: 1976.409s | zswap_store: 1274.698973s [Run 7/10] Sys Time: 1984.453s | zswap_store: 1274.511715s [Run 8/10] Sys Time: 1967.692s | zswap_store: 1274.588755s [Run 9/10] Sys Time: 1984.806s | zswap_store: 1274.987864s [Run 10/10] Sys Time: 1929.026s | zswap_store: 1274.268613s ---------------------------------------------------------------------------- -------------------------------------------------------------------------------- Avg of 10 usemem30 baseline zswap compress Gain Gain iterations batching actual % -------------------------------------------------------------------------------- Avg Sys time (seconds) 2,075.3622 1,984.8028 -90.56 sec -4.36% Avg Throughput (KB/s) 248,769 249,663 894 KB/s 0.36% Avg zswap_store (seconds) 1,279.2767 1,274.5896 -4.6871 sec -0.37% cumulative latency from bpftrace -------------------------------------------------------------------------------- PMD folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 894,463 894,462 -1 Avg (us) 14,302.107 14,249.720 -52.387 us -0.37% p50 (us) 14,368.092 14,310.851 -57.241 us -0.40% p95 (us) 14,456.748 14,419.225 -37.523 us -0.26% p99 (us) 14,602.678 14,610.077 7.399 us 0.05% -------------------------------------------------------------------------------- Order-0 folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 3,516 3,532 16 Avg (us) 17.591 17.877 0.286 us 1.63% p50 (us) 14.797 15.197 0.400 us 2.70% p95 (us) 29.124 29.628 0.504 us 1.73% p99 (us) 57.710 65.340 7.630 us 13.22% -------------------------------------------------------------------------------- vmstats (includes 2 warm-up iterations) -------------------------------------------------------------------------------- pswpin 0 0 0 pswpout 0 0 0 zswpin 3,754 3,844 90 zswpout 549,561,421 549,560,490 -931 zswpwb 0 0 0 2048kB-alloc 1,843,260 1,843,260 0 2048kB-zswpout 1,073,354 1,073,352 -2 2048kB-swpout 0 0 0 2048kB-swpout-fallback 0 0 0 zswap_pool_limit_hit 0 0 0 zswap_written_back_pages 0 0 0 ================================================================================ ================================================================================ Usemem Silesia (100% over-commit): ================================================================================ usemem -w --read-silesia -O -b 5 -s 10 -n 30 6g cgroup memory.high = 90G zswap max_pool_percent = 50% -------------------------------------------------------------------------------- Baseline: ========= [+] Starting benchmark suite: 10 runs of Usemem with Silesia Dataset (Limit: 90G). ---------------------------------------------------------------------------- [Run 1/10] Sys Time: 3843.464s | zswap_store: 2277.627313s [Run 2/10] Sys Time: 3836.637s | zswap_store: 2278.318722s [Run 3/10] Sys Time: 3856.074s | zswap_store: 2278.190603s [Run 4/10] Sys Time: 3823.647s | zswap_store: 2278.387886s [Run 5/10] Sys Time: 3813.093s | zswap_store: 2278.740563s [Run 6/10] Sys Time: 3788.743s | zswap_store: 2277.697021s [Run 7/10] Sys Time: 3868.892s | zswap_store: 2277.858950s [Run 8/10] Sys Time: 3797.672s | zswap_store: 2278.514745s [Run 9/10] Sys Time: 3865.027s | zswap_store: 2279.041594s [Run 10/10] Sys Time: 3789.124s | zswap_store: 2279.485606s ---------------------------------------------------------------------------- zswap_compress_batching: ======================== [+] Starting benchmark suite: 10 runs (Limit: 90G). ---------------------------------------------------------------------------- [Run 1/10] Sys Time: 3852.547s | zswap_store: 2266.829664s [Run 2/10] Sys Time: 3824.707s | zswap_store: 2267.232763s [Run 3/10] Sys Time: 3839.655s | zswap_store: 2266.313908s [Run 4/10] Sys Time: 3805.258s | zswap_store: 2265.486178s [Run 5/10] Sys Time: 3775.986s | zswap_store: 2266.747005s [Run 6/10] Sys Time: 3842.518s | zswap_store: 2266.647259s [Run 7/10] Sys Time: 3837.615s | zswap_store: 2266.726275s [Run 8/10] Sys Time: 3848.061s | zswap_store: 2266.902372s [Run 9/10] Sys Time: 3831.397s | zswap_store: 2266.195312s [Run 10/10] Sys Time: 3826.463s | zswap_store: 2267.386639s ---------------------------------------------------------------------------- -------------------------------------------------------------------------------- Avg of 10 usemem30 baseline zswap compress Gain Gain iterations batching actual % -------------------------------------------------------------------------------- Avg Sys time (seconds) 3,828.2373 3,828.4207 0.18 sec 0.00% Avg Throughput (KB/s) 61,506 61,383 -123 KB/s -0.20% Avg zswap_store (seconds) 2,278.3863 2,266.6467 -11.7396 sec -0.52% cumulative latency from bpftrace -------------------------------------------------------------------------------- PMD folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 922,600 922,601 1 Avg (us) 16,035.212 15,816.040 -219.172 us -1.37% p50 (us) 16,916.945 16,682.504 -234.441 us -1.39% p95 (us) 20,518.592 20,134.788 -383.804 us -1.87% p99 (us) 20,866.739 20,474.772 -391.967 us -1.88% -------------------------------------------------------------------------------- Order-0 folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 275,102,932 275,099,516 -3,416 Avg (us) 29.043 29.351 0.308 us 1.06% p50 (us) 28.975 29.273 0.298 us 1.03% p95 (us) 31.528 31.841 0.313 us 0.99% p99 (us) 33.273 33.523 0.250 us 0.75% -------------------------------------------------------------------------------- vmstats (includes 2 warm-up iterations) -------------------------------------------------------------------------------- pswpin 0 0 0 pswpout 0 0 0 zswpin 566,262,293 566,273,230 10,937 zswpout 1,446,525,371 896,978,740 -549,546,631 -37.99% zswpwb 0 0 0 2048kB-alloc 2,950,440 1,107,181 -1,843,259 -62.47% 2048kB-zswpout 2,180,497 1,107,145 -1,073,352 -49.23% 2048kB-swpout 0 0 0 2048kB-swpout-fallback 0 0 0 zswap_pool_limit_hit 0 0 0 zswap_written_back_pages 0 0 0 ================================================================================ ======================================================================= BPFTRACE PERFORMANCE TESTING PHASE 3 (ZSTD): Unmodified & Silesia usemem30 with 100% & 50% over-commit respectively: with zswap shrinker: ======================================================================= zswap_compressor = ZSTD, zswap_shrinker = Y: ================================================================================ Unmodified Usemem (100% over-commit): ================================================================================ usemem -w -O -b 5 -s 10 -n 30 10g cgroup memory.high = 150G zswap max_pool_percent = 20% (default) -------------------------------------------------------------------------------- Avg of 10 usemem30 baseline zswap compress Gain Gain iterations batching actual % -------------------------------------------------------------------------------- Avg Sys time (seconds) 1,798.0412 1,754.8673 -43.17 sec -2.40% Avg Throughput (KB/s) 35,794 36,239 445 KB/s 1.24% Avg zswap_store (seconds) 1,243.6329 1,229.9446 -13.6883 sec -1.10% cumulative latency from bpftrace -------------------------------------------------------------------------------- PMD folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 857,921 854,237 -3,684 Avg (us) 14,495.816 14,398.087 -97.729 us -0.67% p50 (us) 14,535.149 14,412.360 -122.789 us -0.84% p95 (us) 15,012.265 14,923.469 -88.796 us -0.59% p99 (us) 15,241.253 15,120.714 -120.539 us -0.79% -------------------------------------------------------------------------------- Order-0 folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 3,602 3,607 5 Avg (us) 17.660 18.530 0.870 us 4.93% p50 (us) 14.939 14.801 -0.138 us -0.92% p95 (us) 29.822 30.622 0.800 us 2.68% p99 (us) 58.990 182.465 123.475 us 209.32% -------------------------------------------------------------------------------- vmstats (includes 2 warm-up iterations) -------------------------------------------------------------------------------- pswpin 2,325 2,215 -110 pswpout 12,976,001 13,093,265 117,264 zswpin 1,881 1,952 71 zswpout 526,979,887 524,858,122 -2,121,765 -0.40% zswpwb 12,976,001 13,093,265 117,264 2048kB-alloc 1,843,259 1,843,258 -1 0.00% 2048kB-zswpout 1,029,249 1,025,105 -4,144 -0.40% 2048kB-swpout 0 0 0 2048kB-swpout-fallback 0 0 0 zswap_pool_limit_hit 0 0 0 zswap_written_back_pages 10,852,812 10,656,928 -195,884 -1.80% zswap_reject_reclaim_fail 2 0 -2 ================================================================================ ================================================================================ Usemem Silesia (50% over-commit): ================================================================================ usemem -w --read-silesia -O -b 5 -s 10 -n 30 3g cgroup memory.high = 60G zswap max_pool_percent = 50% -------------------------------------------------------------------------------- Avg of 10 usemem30 baseline zswap compress Gain Gain iterations batching actual % -------------------------------------------------------------------------------- Avg Sys time (seconds) 1,484.1499 1,423.1080 -61.04 sec -4.11% Avg Throughput (KB/s) 20,286 26,221 5,935 KB/s 29.26% Avg zswap_store (seconds) 931.9412 899.9983 -31.9429 sec -3.43% cumulative latency from bpftrace -------------------------------------------------------------------------------- PMD folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 443,054 442,711 -343 Avg (us) 16,133.793 15,843.956 -289.837 us -1.80% p50 (us) 16,995.086 16,690.560 -304.526 us -1.79% p95 (us) 20,599.966 20,175.044 -424.922 us -2.06% p99 (us) 20,985.086 20,519.836 -465.250 us -2.22% -------------------------------------------------------------------------------- Order-0 folios: zswap_store() latency distribution across 10 usemem30 iterations -------------------------------------------------------------------------------- Calls 72,463,111 65,014,011 -7,449,100 Avg (us) 29.964 30.542 0.578 us 1.93% p50 (us) 29.148 29.585 0.437 us 1.50% p95 (us) 40.240 41.857 1.617 us 4.02% p99 (us) 46.286 48.478 2.192 us 4.74% -------------------------------------------------------------------------------- vmstats (includes 2 warm-up iterations) -------------------------------------------------------------------------------- pswpin 16,738,539 15,222,068 -1,516,471 pswpout 17,397,394 15,573,879 -1,823,515 zswpin 255,766,769 253,289,826 -2,476,943 zswpout 364,661,348 349,709,030 -14,952,318 -4.10% zswpwb 17,397,394 15,573,879 -1,823,515 2048kB-alloc 554,218 554,266 48 0.01% 2048kB-zswpout 535,430 534,030 -1,400 -0.26% 2048kB-swpout 0 0 0 2048kB-swpout-fallback 0 0 0 zswap_pool_limit_hit 0 0 0 zswap_written_back_pages 14,180,330 12,753,257 -1,427,073 -10.06% zswap_reject_reclaim_fail 4 4 0 ================================================================================ Conclusions based on the BPFTRACE results: ========================================== 1) Gains in zswap_store() latency are unambiguously established with zswap compress batching, both, for unmodified usemem and usemem reading Silesia. 2) Gains in zswap_store() latency are seen without and with zswap shrinker enabled. 3) More significant zswap_store() latency gains are seen with the zswap shrinker: Unmodified usemem: Sys time -2.4%, zswap_store() total latency -1.10% Usemem with Silesia: Sys time -4.11%, zswap_store() total latency -3.43% 4) With zswap shrinker, up to 4.10% fewer zswpout and up to 10.06% fewer zswap_written_back_pages are observed with the patch-series wrt baseline. 5) Without zswap shrinker, the usemem30 Silesia experiments show 38% fewer zswpout, 62% fewer PMD folio allocations and 49% fewer PMD THP zswpouts, with 0 pswpout/zswpwb/pool_limit_hit. This is indicative of the zswap_store() speed-up resulting in less memory pressure. 6) zswap_store() bpftrace avg, p50, p95, p99 latency distributions improve consistently for PMD folios. Analysis of performance improvements with zswap store batching and zswap compress batching: ======================================================================== The batching of zswap_store() phases and compress batching optimizations benefit zswap_store() latency overall. The benefits are attributable firstly to the store batching framework added in patches 7-8, that is fully utilized in patch 9 to improve zswap_compress() latency by giving it a batch of pages to be compressed. Gains seen from store batching alone (patches 7-8) are due to: 1) Bulk allocating the zswap entries for the batch, 2) Minimizing computes by getting the wb_enabled once per PMD folio, rather than per-page, 3) Fewer function calls: zswap_store_pages() called once every 4 pages, rather than per-page. Furthermore, the batch compression added in patch 9 improves latency for these reasons: a) Minimizes computes, especially conditionals. For e.g. crypto API that set things up for a batch, rather than for a page. b) The working set is kept focused on batch-centric data pertaining to a handful of operations on the batch, to minimize cache evictions and benefit from cache locality. c) Each block of compute in zswap_compress() is doing checks/state changes for a batch, which I believe simplifies the architecture and allows us to build further optimizations. The mechanisms used by batch compression to improve latency, are: 1) Per-CPU sg_table with ZSWAP_MAX_BATCH_SIZE scatterlists that are statically mapped to compression dst buffers for that CPU, thereby minimizing local SG lists initialization, and using compact new crypto_acomp API introduced in patches 1-4 that set up an acomp_req's src/dst to be SG lists. 2) Patch 7 allocates ZSWAP_MAX_BATCH_SIZE destination buffers in the per-CPU acomp_ctx, for an added memory overhead of ~12 KB per-CPU. However, it allows us to not have to immediately call zs_store() with the compressed buffer, but instead continue to compress the next page. The hypothesis is that this minimizes cache evictions because we run a focused set of computes on a specific data set. 3) A one-shot zswap_update_entries() does all the zsmalloc handle allocation and copying for the batch. The key concept driving efficiency is that the working set is kept focused on batch-centric data pertaining to a handful of operations on the batch, to minimize cache evictions and benefit from cache locality. 4) Bulk accounting for the batch instead of per-page. 5) Single point error-handling in zswap_store_pages() to avoid conditionals, so as to not wash away batching gains. 6) By making zswap_compress() more efficient, we are able to lock the comp mutex per batch of ZSWAP_MAX_BATCH_SIZE (4) pages instead of per-page. 7) Optimize most-likely-to-succeed fast paths, move conditionals and error processing to less-likely code (which is also consolidated to a single error handling label). 8) The batching code doesn't proceed to the next stage of batch processing until this stage is successful for its specific functionality scope. This minimizes computes by failing a batch at the earliest error at functionality scope, rather than completing the full store loop per-page, only to re-wind upon an error in an intermediate page of a large folio. Conclusions: ============ The data demonstrates how the low-level zswap_store() bptrace latency savings translate to performance improvements at the system level and workload level. Performance validation is done at scale with 30 concurrent usemem processes, with Sys time and Throughput being the key high-level metrics. Sys time measured across 10 consecutive iterations of usemem30 improves significantly with zswap compress batching, -13.87% lower than mm-unstable for PMD THP. Per-process Throughput increases by 3.85% for PMD folios. As this patch-series impacts batching within folios, the Sys time savings reduces for lower order folios. The immediate benefit of zswap compress batching is saving CPU compute cycles, that can imply lower power consumption and existing kernel optimizations with reduced CPU compute cycles spent in critical paths. This patch-series delivers modest throughput improvements. As other kernel components related to mTHP become more efficient, the net realized performance benefit can only be better with this patch-series than without, given the significant Sys time reduction with zswap store and compress batching. The batching framework established in this series allows us to make locking and bulk-processing improvements in each stage of zswap_store(). One of the ideas that has shown very promising results is to replace zsmalloc with SLUB compressed caches and an RFC will be submitted separately. This will be directly optimizing zswap_update_entries(), where compressed buffers can be binned based on size and bulk allocated from SLUB. The speedup with zswap store batching of large folios has a propelling effect on other parts of mm, especially, by enabling large folios to be swapped out without splitting, as the higher-order folio vmstat data shows. This enables other mm components that are optimized for large folios, such as munmap(), folio refcounts/mapcounts updates, PTE invalidation upon freeing memory, zswap_invalidate(); which benefit from xarray offsets/range continuity. As a result, subsequent large folio swapouts are more likely to find contiguous swap slots, there are fewer large folio splits during reclaim and the cycle continues. As the data demonstrates, this directly contributes to more memory over-commit opportunity. Architectural considerations for the zswap batching framework: ============================================================== The zswap batching framework is designed to be hardware-agnostic. It can be leveraged by any hardware accelerator or software-based compressor. Potential future clients of the batching framework: =================================================== This patch-series demonstrates the performance benefits of compression batching when used in zswap_store() of large folios. Compression batching can be used for other use cases such as batching compression in zram, batch compression of different folios during reclaim, kcompressd, file systems, etc. Decompression batching can be used to improve efficiency of zswap writeback (Thanks Nhat for this idea), batching decompressions in zram, etc. [1]: https://patchwork.kernel.org/project/linux-mm/cover/20260125033537.334628-1-kanchana.p.sridhar@intel.com/ [2]: https://wanos.co/assets/silesia.tar Changes since v4: ================= 1) Validated zswap_store() bpftrace latency gains, co-related to high level Sys time metrics without/with zswap shrinker, for unmodified usemem30 and for usemem30 reading the Silesia dataset. All experiments were done under 100% over-commit, except usemem30 Silesia with shrinker=Y, which was run at 50% over-commit. 2) Rebased to mm-unstable as of 11-30-2026, commit cee8d70a6bb5. 3) Addressed Nhat's code review comments: - Fixed "nid" description in struct zswap_entry comment header. - Separate patch to obtain folio's zswap writeback enabled status once, and pass it to zswap_store_page()/zswap_compress() to minimize compute overhead for large folios. - Drop "gfp" parameter to zswap_entries_cache_alloc_batch(), use GFP_KERNEL directly when calling kmem_cache_alloc_bulk(). - Delete obj_cgroup_charge_zswap(). - Added comment in zswap_tree_stores() error handling path, explaining local cleanup vs. batch-level cleanup happening in zswap_store(). 4) Addressed Sashiko's comment on batch compression checks needing fix to cast sg->length to int before checking (int)sg->length >= PAGE_SIZE, to disambiguate between an error code and a real case of an invalid compress length in error stats. 5) Incorporated Herbert's suggestion to add the high-level API guards inside the crypto compression/decompression routines. Changes since v3: ================= 1) Rebased to latest mm-unstable as of 11-17-2026, commit 866f761fd414. 2) Sashiko's v3 code review comments addressed in v4: - Patch 7: - Modified obj_cgroup_charge_zswap() to call obj_cgroup_charge_zswap_many() to avoid the charging code duplication. - memcontrol.c: Added a stub for obj_cgroup_get_many() in the #else section of the #ifdef CONFIG_MEMCG block. - We skip the incompressible page updates in zswap_tree_stores() and obj_cgroup_charge_zswap_many() if the nr_incomp_pages is 0. - Patch 8: - Clamp nr_batch_pages to zc->nr_pages - batch_start on each iteration over zc->nr_pages in zswap_compress(). Calculate slen accordingly, before proceeding to use slen for the subsequent crypto() API calls. - In the post-crypto_acomp_compress() !wb_enabled block that checks for negative errors codes in sg->length, cast sg->length to (int) before checking for sg->length <= 0. 3) Gathered high-level metrics (Sys time, throughput) as suggested by Yosry. Changes since v2: ================= Resolved v2 code review issues highlighted by Sashiko. Baseline mm-unstable as of 10-25-2026, commit a2abad0d7f45. 1) Patch 3: - Re-wrote the fast path conditional to be !acomp_is_async(tfm) instead of !acomp_req_on_stack(req). - Moved the state-flag changes from acomp_save_req() back to acomp_virt_to_sg(). 2) Patch 4: - Replaced the ambiguous use of "cra_flags & CRYPTO_ALG_TYPE_ACOMPRESS" with directly checkinf for "cra_type == &crypto_acomp_type" to detect an acomp_alg. 3) Patch 5: - Fixed the off-by-one bitfield width by modifying ZSWAP_MAX_COMPR_LENGTH_SHIFT to 19U and the build time assertion check for BUILD_BUG_ON(ZSWAP_MAX_COMPR_LENGTH_SHIFT <= PAGE_SHIFT)). 4) Patch 6: - Moved the "u8 compr_batch_size" to struct zswap_comp_ctx, which is per-CPU to address the "unsynchronized write to pool->compr_batch_size on CPU hotplug" issue Sashiko highlighted. 5) Patch 7: - The special casing for comp_ret=0 with dlen == PAGE_SIZE (among other end-cases) when writeback is disabled, is replicated in the batched version of zswap_compress() as well. 6) Patch 8: - Added obj_cgroup_charge_zswap_many() to correctly account for MEMCG_ZSWAP* counters with bulk-charging total compressed bytes to zswap. - Resolved zsmalloc() handles leak issue in case of compress batch failures in zswap_update_entries(). - Deleted zswap_pool_get(). Changes since v1: ================= 1) Rebased to mm-unstable as of 10-25-2026, commit a2abad0d7f45. 2) Addressed Herbert's comments on checking for the req->unit_size being equal to the req->slen to identify singleton acomp_reqs and to quickly short-circuit with setting the dst SG list length instead of going through the request chaining flow. Further, the most common code path is the very first check, with the short-circuit, in crypto_acomp_compress(). 3) Addressed Yosry's comments wrt: - struct zswap_entry "length" field build-time assertion to have sufficient bit-fields for the architecture's PAGE_SIZE. - Use kmem_cache_alloc() instead of kmem_cache_alloc_node() in zswap_entry_cache_alloc(). 4) Established a reliable and accurate performance validation methodology, based on Yosry's comments. 5) Refactored the sub-components of zswap_store_pages() where each routine processes a batch. The new zswap_account_stores() gets refs, updates statistics and charges cgroup for the batch, rather than for a page at a time. zswap_store_pages() is more readable and maintainable. This batching framework can be immediately useful for implementing more ideas such as SLUB bulk allocation of compressed data, reclaiming a batch of folios from shrink_folio_list(), etc. Changes since [1]: ================== 1) Better cacheline placement of struct zswap_pool and struct zswap_entry members for temporal memory access efficiency in zswap store/load hot paths, while minimizing holes. 2) Refactored the core compression batching functionality to a separate __zswap_compress() function, which is called by zswap_compress(), as per Nhat's and Yosry's comments. Hopefully this helps explain the outer "store batching" zswap_compress() vis-a-vis the inner "compress batching" __zswap_compress() distinction. 3) The acomp_ctx is locked once and is passed to the routine that compresses a batch, per the algorithm's batch-size. Similarly, the folio's node id and writeback_enabled status are computed once and passed to the routines that implement the different store functionalities, to save latency by avoid localized recomputes of information that doesn't change. 4) Moved the folio node id being stored in zswap_entry to a separate patch, per Yosry's comment. 5) Addressed the kunmap_local() issue flagged by Jixin He in the IS_ERR_VALUE(handle) error path (https://patchwork.kernel.org/comment/27095925) - thanks! 6) Moved comments inline, per Yosry's suggestions. Thanks, Kanchana Kanchana P. Sridhar (9): crypto: acomp - Define a unit_size in struct acomp_req to enable batching. mm: zswap: Set the unit size for zswap to PAGE_SIZE. crypto: acomp - Add bit to indicate segmentation support. crypto: acomp - Add trivial segmentation wrapper. crypto: acomp - Add API to get a compression algorithm's batch-size. mm: zswap: Store the folio's node id in the zswap_entry. mm: zswap: Obtain folio's wb_enabled status once in zswap_store(). mm: zswap: Store large folios in batches. mm: zswap: Refactor and optimize zswap_store_pages() batch operations. mm: zswap: Batched zswap_compress() for storing large folios in batches. crypto/acompress.c | 59 ++- include/crypto/acompress.h | 66 ++- include/crypto/algapi.h | 5 + include/crypto/internal/acompress.h | 10 +- include/linux/crypto.h | 5 +- include/linux/memcontrol.h | 13 +- mm/memcontrol.c | 16 +- mm/zswap.c | 664 +++++++++++++++++++++------- 8 files changed, 662 insertions(+), 176 deletions(-) -- 2.39.5