From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39A2F606A322 for ; Thu, 3 Dec 2026 18:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=uQHXzsHI Received: by kanga.kvack.org (Postfix) id 56FB56B00EF; Thu, 3 Dec 2026 13:13:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F89F6B05B2; Thu, 3 Dec 2026 13:13:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E7116B05B6; Thu, 3 Dec 2026 13:13:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0CBDF6B00EF for ; Thu, 3 Dec 2026 13:13:31 -0500 (EST) Received: from smtpin25.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9748F160435 for ; Thu, 3 Dec 2026 18:13:30 +0000 (UTC) X-FDA: 85503469380.25.E1B2089 Received: from mta1.migadu.com (out-40.mta1.migadu.com [95.215.58.40]) by imf31.hostedemail.com (Postfix) with ESMTP id 57D5420009 for ; Thu, 3 Dec 2026 18:13:28 +0000 (UTC) Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=uQHXzsHI; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf31.hostedemail.com: domain of baoquan.he@linux.dev designates 95.215.58.40 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796321608; b=jSVOmXd4FQIXlePza+H9q2HkrNvAbC0KU1uknmWQYxgrYChPaoWTI99UbPzqocckVhxxAd ec5BziW+iriXNvuGI25Yd1Uky/ghjGjgMJObQL6kCzFpoqqHKol31lexJCMU6N+U1Vircx I+54CGRScsMkqssFaAuqadNgH3orB3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796321608; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=Ix9AXq/rXrihISjXoEENytqrkAPuNq5hXmwI2V2wXog=; b=EzFyfZXaSnvQroFE8jJ3BOIDhw1BJEVgr40+ppN7hjeLu933XvHyOHrTUMb1M+UM9PWKRY 6Ki6YPCpnL+nBliz/Og9/gNEzGBZjX6H3JxsqFHwjoN52/v/UwSuLveq23TSE3gd11Pql1 sUV4rLJZGG7w+PRCn6HFTCL3TcfRpYE= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=uQHXzsHI; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf31.hostedemail.com: domain of baoquan.he@linux.dev designates 95.215.58.40 as permitted sender) smtp.mailfrom=baoquan.he@linux.dev X-Envelope-To: linux-mm@kvack.org DKIM-Signature: a=rsa-sha256; bh=BmpT+u0SW1azQzNG9SIVgQUyxDBDcim8oBuw2npUA/M=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796321606; v=1; x=1796926406; b=uQHXzsHIO0kH787Fv5vQLlx9Z1UpLY3BXuQJlhwP2hmIVxcY44vMYL5mAZmYvVlwUlazsj1w Hs8SfHNqh+JfoJP4Q9iJCWkNca47pPic+H1aakdDBhhkkrNkgnWlMTXlMpdI6IZBPm76ui4As6I fyhNb7OdBerZZnakrdndynxQ= X-Envelope-To: linux-mm@kvack.org Received: by mta11.migadu.com with ESMTPS id d93e974bfc8657fd; Thu, 03 Dec 2026 18:13:26 +0000 X-Mizu-Trace-ID: d93e974bfc8657fd X-Migadu-Flow: FLOW_OUT From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org, kasong@tencent.com, hannes@cmpxchg.org, corbet@lwn.net, yosry@kernel.org, nphamcs@gmail.com, muchun.song@linux.dev, baohua@kernel.org, youngjun.park@lge.com, hughd@google.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, Baoquan He Subject: [PATCH v2 00/32] mm, swap: extendable swap devices (xswap phases II-IV) Date: Fri, 4 Dec 2026 02:12:47 +0800 Message-ID: <20261203181319.901844-1-baoquan.he@linux.dev> X-Mailer: git-send-email 2.54.0 X-Archived-By: MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 57D5420009 X-Stat-Signature: ic3h4ni77gxncshgc14w5ui4hc73q6nt X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_PASS,SPF_PASS, TVD_PH_BODY_ACCOUNTS_PRE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-HE-Tag: 1796321608-401500 X-HE-Meta: U2FsdGVkX1/WIc4XpdrJZ60YCv5aoXwv17VlCDgWIe/bXmNJY4+RqxYys67eEnRL1KojMjG71tLj9OMRXiYHS16pWo+tqKblXB/Au42AYlZSoZMHJzimmOs1YcQiHR3QBMkZo3RFf9mWn4lGr0M6N+ViQ4HScNYm1zN89k6d7NXqXItHyfK4nhFd+z2/vTQjM8Kw4wgc2TSre5QjFPAixYhblQ/NKblZuSFJpe5UUkLrsiRSSDbgfO3twlmwnl1CYzK8BvkZ8VEhr3UIXdTicPRwytEFkq9INBcLqJFOI5I0VAtAN6JT8cbtu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YHAmbb5xqB2vMmjICGCSX8RPdflJiE7J1kBDkY8ZOoFvAn/AVKxAnQ9KaNhywAjK4KdVgbekXocA584rpyXg= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Baoquan He This is the second part of the xswap series. Phase I, posted separately, added the file-less swap device: a sparse swap address space that grows on demand, with the data stored in zswap. This part gives the device a physical backend, accounts the swap that really reaches a device, and unifies the per-slot backend records. It applies on top of the phase I series. Phase II (patches 1-17): a physical backend for xswap slots ----------------------------------------------------------- A zswap-only slot has one copy: when zswap evicts or refuses the page, the data is gone. A slot can now be written to a contiguous range of physical swap slots on a real swap device. The xswap slot stays the identity, and the physical slots are tagged with their owning xswap entry, so writeback, readback and rebuild can find each other. zswap eviction now has a destination, and a refused store falls back to a real device instead of leaving the page resident. A cache-only entry releases its physical range early. A large xswap folio is accepted only when a contiguous physical range can back it, and is read back with one I/O; otherwise reclaim is asked to split the folio. THP swapin is enabled for entries whose whole range is contiguous on one device. A backend that requires NOFS is skipped when the caller may not enter the filesystem. This partially refers to Nhat's vswap-v4 series: patch 1 is consistent with his patch 3, patch 18/19/20/21 are from his patch 8. Tagging a swap table entry with its owning xswap entry, releasing the physical range of a cache-only entry, and enabling THP swapin, the principle is similar, but the implementation is not, because the underlying data structures differ, add Nhat's Co-developed-by. Phase III (patches 18-26): swap accounting ------------------------------------------ An xswap entry is recorded with its owner at allocation, but the swap charge is taken only when the entry gets a physical backend slot, and given back with it. memory.swap.current therefore matches the backend device's Used page for page. A zswap-only entry is not charged: the compressed pool is already charged as memory, and charging it as swap would count it twice. memory.swap.max=0 still permits swapout through zswap. cgroup v1 keeps memsw on the slot, so xswap must not touch memsw when it uncharges the backing. Phase IV (patches 27-32): per-slot backend records -------------------------------------------------- Every swap device keeps a per-cluster backend table, allocated on demand: 512 words, one per slot. A word is either a zswap entry pointer (low bit 1) or a physical backend entry (low bit 0); zero means no record. zswap entries are indexed here instead of a per-type xarray, so a lookup is O(1) by cluster. Reads take no cluster lock; the table is allocated before the first record is published. A folio's slots or a cluster's free batch are released with one range walk. The xswap specific hooks run only on xswap devices. Design notes ------------ An xswap slot is still a swap entry: the physical backend is a range of slots on the real device, not a separate address space. The reverse map is kept on the physical slot, so the physical device's reclaim scanner can find the owner without walking the xswap cluster array. The owner is published before the reverse map, and a stale range is dropped before it is reused. Testing ------- QEMU KVM guest, 8G RAM, booted with xswap.max=10G. The complete 46-patch queue was built and booted on 1a7610248a38: - functional matrix: 30 checks passed, 0 failed; the overcommit case was run separately with vm.overcommit_memory=2 (8.15G RAM, overcommit_ratio 50, CommitLimit 14.56G, Committed_AS 4.65G, a 10.49G device) and passed - swapoff xswap and swapoff -a, including destroying with 1,075,128 kB of live pages - 2000 create/destroy cycles: no per-cluster state is leaked (largest slab growth 196 objects) - a cgroup that cannot zswap gets no xswap slot - the vmallocinfo-reader stress with the grow test is clean - dmesg is clean except for the memcg OOM kill that the cgroup gate test asks for The backend-specific tests were run on the previous base; the rebase to 1a7610248a38 is patch-identical (range-diff reports no change), so the results carry over: - backend readback: every byte still holds the pattern (1.57M pages) - writeback + destroy: 3 cycles, the backend returns to 0 every time - THP swapin: 570,880 pages read back - shmem and split fallback: PASS - memcg charge P1-P6: ALL PASS - limit and race tests: PASS Performance ----------- The phase II backend is about capacity, not pageout speed. With the complete queue on an earlier mm-new snapshot: - 128 GiB MADV_PAGEOUT, 144 threads, interleaved NUMA: 87,540 vs 87,015 instructions per swapped page (-0.6%), 3,296 vs 3,304 MB/s, about 40 seconds of pageout on both. The difference is within the run-to-run spread. - usemem 64G in a 48G cgroup: with both kernels keeping the data in zswap, the median was 151.8 s (base) vs 145.2 s (xswap). That 4.3% difference is smaller than the run-to-run spread. - kbench, 1G memcg, 40 jobs, THP off, no writeback: median 225.58 s vs 225.21 s, total CPU 5657.9 s vs 5580.8 s, peak RSS 867 vs 863 MiB, zswap peak 193 vs 227 MiB. This run measures the slot array and the zswap frontend; the backend is not used with writeback off. Limitations ----------- A large folio needs a contiguous physical range. If the range cannot be allocated, the folio is split; a zswap-backed or mixed large folio is read back at a smaller order. THP swapin is only used when the whole range is contiguous on one device. Writeback needs a real swap device; xswap-only capacity is still the zswap pool. xswap.max=max reserves a large vmalloc range for the cluster_info array. The per-type zswap tree of phase I is gone in this series: zswap entries are indexed in the per-cluster backend table (phase IV). The overcommit semantics for the swap address space are still open, as described in the phase I posting. Runtime shrink is phase V and is not part of this series. This series depends on the phase I series ([PATCH v8 00/14]); apply phase I first. The base is 1a7610248a38 (mm-new, 7.4.0-rc4); the phase I tip is 779bedee9865 and this series ends at 3722b1e2daa3. History: ====== [PATCH 00/12] mm, swap: give xswap a physical backend (xswap phase II) https://lore.kernel.org/all/20261003005900.909710-1-hebaoquan@kylinos.cn/T/#u [PATCH 0/6] mm, swap: charge xswap for physical backing (xswap phase III) https://lore.kernel.org/all/20261003011111.1003090-1-hebaoquan@kylinos.cn/T/#u The entire xswap code can be found here: ==== https://github.com/baoquan-he/linux.git xswap-v8 Baoquan He (27): mm, swap: tag a swap table entry with its owning xswap entry mm, swap: prepare the folio-less allocation path for xswap mm, swap: add a physical backend for xswap slots mm, swap: support swapoff of an xswap physical backend mm, swap: use the xswap physical backend mm, swap: fall back to disk when zswap refuses an xswap page mm, swap: reclaim physical slots backing cache-only xswap entries mm, swap: drop swap_folio_sector() mm, swap: drop a stale xswap physical slot range before reallocating mm, swap: publish the xswap backend owner before its reverse map mm, swap: skip a NOFS backend for xswap physical writeback mm, swap: pass the folio order through the swap slot allocator mm, swap: allocate a multi-slot range without a folio mm, swap: pass the folio order to the xswap physical backend mm, swap: enable large xswap folios with a contiguous physical slot range mm, swap: enable THP swapin for xswap entries mm, swap: do not retake the cluster lock when uncharging an xswap slot mm, swap: uncharge an xswap backend where its record is cleared mm, swap: account xswap backends for cgroup v1 mm, swap: drop a refused xswap backend slot range directly mm, swap: route xswap by the zswap eligibility without flushing mm, swap: keep a per-cluster backend record for every swap device mm, swap: encode the per-slot backend record mm, swap: add accessors for the backend record mm, zswap: index entries in the swap device's backend table mm, swap: release a range of backend handles at once mm, swap: only run the xswap backend hooks on xswap devices Nhat Pham (5): mm, swap: prepare the swap IO path for xswap backends mm, swap: split the swap memcg charge helpers mm, swap: do not charge zswap-backed xswap entries mm, swap: charge an xswap entry when it gets physical backing mm, swap: don't gate xswap on the physical swap free count .../admin-guide/cgroup-v1/memcg_test.rst | 2 +- Documentation/admin-guide/mm/zswap.rst | 12 + include/linux/memcontrol.h | 6 + include/linux/swap.h | 74 +- include/linux/swap_ops.h | 11 +- include/linux/zswap.h | 15 +- mm/memcontrol-v1.c | 3 +- mm/memcontrol.c | 170 +- mm/memory.c | 25 +- mm/page_io.c | 119 +- mm/shmem.c | 2 +- mm/swap.h | 52 +- mm/swap_state.c | 9 + mm/swap_table.h | 92 +- mm/swapfile.c | 1567 ++++++++++++++--- mm/vmscan.c | 48 +- mm/zswap.c | 258 ++- 17 files changed, 2008 insertions(+), 457 deletions(-) -- 2.54.0