Re: [RFC PATCH 00/10] mm/swap: ghost swapfile with backend switching via Redirect entries

From: Chris Li

Date: Sat Jul 11 2026 - 04:49:28 EST


Hi Baoquan,

Thanks for the patches series. That is very interesting take.

Some high level feedback follows:

On Tue, Jul 7, 2026 at 1:26 AM Baoquan He <baoquan.he@xxxxxxxxx> wrote:
>
> This series introduces a virtual "ghost" swapfile that can be backed
> by multiple physical swap devices, switching between them at runtime
> using a new "Redirect" swap table entry type.
>
> Motivation
> ----------
> Physical swap devices have fixed, large sizes but a machine may only
> need a fraction at any given time. Ghost swap decouples the logical
> swap capacity from physical swap allocation: it presents a large
> virtual swap device to userspace while lazily mapping slots to
> physical devices only when data must leave zswap (writeback). This
> enables overcommit of swap capacity without wasting physical disk
> space, and allows the ghost device to grow dynamically at runtime.
>
> Ghost swapfile characteristics
> --------------------------------
> Ghost swap decouples logical swap capacity from physical swap allocation.
> Key properties:
>
> - No backing store required. A ghost swap device can operate purely
> as a zswap container — compressed pages stay in the zswap pool without
> ever touching a physical swap device. No physical swap device needs
> to be attached.
>
> - Optional physical backing. One or more physical swap devices can be
> swapon'd alongside the ghost device, acting as writeback targets when
> the zswap pool needs to evict cold pages. The Redirect entry in the
> ghost swap table links each evicted slot to its physical destination.
>
> - Dynamic size growth. The ghost device can be extended at runtime via
> sysfs, up to a current maximum of 1TB. This is implemented through
> lazy vmalloc: a sparse 64MB virtual address space is reserved at
> swapon time to cover the full 1TB range, but physical pages for
> cluster_info[] structures are allocated only on demand as the device
> grows. The cluster_info pointer never changes, so all existing
> accessors (__swap_offset_to_cluster, cluster_index) work unchanged.

I think supporting swap file growth is useful at the swap
infrastructure level. I mean generic runtime size growth for swap
files. That does not need to tight to ghost swapfile. For example. If
your swapfile is backed by an LVM logical volume. You can grow the
swapfile size by growing the swapfile's logical volume.

I suggest focus on that allow increase of si->max as the baby step and
keep the optinal physical backing for later phase. That should make
your series much smaller and easier to merge.

>
> - sysfs control. Each ghost device exposes attributes under
> /sys/kernel/mm/ghost_swap/ghost_<N>/:

BTW, I want to rename the ghost swap file to remove the ghost part. I
inherited that ghost name but I feel ghost is a bit too spooky for my
taste. I am pretty bad at naming stuff myself. I was thinking
something like "VX swapfile" (virtual extendable swapfile) for
example.

> path (RO) — backing device name

Let's focus on the extendable part for now and worry about the
physical backing device later.

> max (RW) — current max pages; writing a larger value triggers
> swap_ghost_extend_max()

We can use a debugfs entry before we settle on the final
implementation. It is useful for demo and testing purposes if we have
some way to trigger the growth. Having the ability to grow is more
important than how it is triggered. We can also let it auto grow as
needed based on config.

BTW, I notice your patch series doesn't apply cleanly on mm-unstable.
I have to resolve some conflicts myself.


>
> Design overview
> ---------------
> A swap table slot can now hold a Redirect entry:
>
> Redirect: |----- physical swp_entry_t -----|101|
>
> This stores a plain swp_entry_t pointing to a slot on a real (physical)
> swap device. The low 3-bit mark (0b101) distinguishes it from Pointer
> (0b100), PFN (0b10), Shadow (0b1), and NULL (0) entries.
>
> The lifecycle is:
>
> 1. swapon a ghost device — reserves sparse vmalloc area (64MB virtual)
> and physically backs only the initial range. The device starts with
> no physical backing store: pages swapped out go to zswap, and zswap
> pool evictions go to any concurrently attached physical device.

Again, let's make it more generic also works on physical device change
size as well.

>
> 2. zswap writeback from ghost: when the zswap pool needs to evict,
> zswap_writeback_ghost() allocates a physical slot from any real
> swap device, writes the data there, and plants a Redirect entry
> in the ghost's swap table pointing to the physical slot.

Don't worry about zswap write back for now. Able to grow swap device
size is a useful phase by itself.

>
> 3. Swap-in from ghost: swap_read_folio() detects the ghost device
> (SWP_GHOST), resolves the Redirect to the physical swp_entry_t,
> and forwards the read I/O to the physical device.
>
> 4. When the swap cache folio is removed, the Redirect entry is restored
> from an xarray (redirect_xa) that persists the mapping, so
> subsequent reads still find the physical backing.
>
> 5. When the physical slot is freed, the ghost slot is also freed,
> cascading through swap_range_free().
>
> Note:
> ------
> Ghost swapfile is a proof of concept. Compared with the other patchset:
> [RFC PATCH v2 0/7] mm, swap: Virtual Swap Space (Swap Table Edition),
> it explores a different approach to implementing virtual swap on top of
> the existing swap table infrastructure, with a simpler implementation.
> It builds on Chris Li's earlier ghost swapfile work and is currently
> tentatively named "ghost swapfile" — alternative naming suggestions are
> welcome.

VXSwap or XSwap

> Ghost swapfile setup can also be integrated through modifications
> to the swapon API and the swapon command in util-linux, for example:
> swapon --ghost ghost_1:2G -p 5.

For the ghost swapfile, the eventual goal is that its size can
automatically grow as needed because there is no phyiscal backing
device.

Chris

>
> Baoquan He (9):
> mm/swap_table: add Redirect entry encoding for ghost swap backend
> switching
> mm/swap: add redirect_xa field and ghost redirect helper declarations
> mm/swapfile: implement ghost redirect helpers and free-path cascade
> mm/swap_state: restore Redirect entry when swap cache folio is removed
> mm/zswap: implement ghost-to-physical writeback for backend switching
> mm/page_io: forward ghost swap reads to physical device via Redirect
> mm/swapfile: manage ghost cluster_info via lazy vmalloc
> mm/swapfile: implement swap_ghost_extend_max() for dynamic growth
> mm/swapfile: add sysfs interface for ghost swap extension
>
> Chris Li (1):
> mm: ghost swapfile support for zswap
>
> include/linux/swap.h | 10 +
> mm/page_io.c | 51 +++-
> mm/swap.h | 16 +-
> mm/swap_state.c | 28 +++
> mm/swap_table.h | 38 +++
> mm/swapfile.c | 579 ++++++++++++++++++++++++++++++++++++++++---
> mm/zswap.c | 98 +++++++-
> 7 files changed, 772 insertions(+), 48 deletions(-)
>
> --
> 2.54.0
>
>