Re: Path forward for Virtualized Swap?
From: Kairui Song
Date: Sat Sep 12 2026 - 04:56:03 EST
On Sat, Sep 12, 2026 at 3:04 AM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
>
> On Fri, Sep 11, 2026 at 11:14 AM Kairui Song <ryncsn@xxxxxxxxx> wrote:
> >
> > > Would something like this fix it for you? ZRAM users will not get
> > > vswap indirection overhead at all, because it would bypass vswap :)
> > > Down the line we can revisit this decision - for e.g, if there is a
> > > use case for vswap-on-top-of-swapfile. There might be other interface
> > > that makes more sense.
> >
> > Hmm, this interface looks confusing though. you mean tangles vswap
> > with zswap through the cgroup's zswap limit? I originally expected
> > this to be a problem solved by tiering, skipping certain tiers seems
> > much more intuitive. Maybe Youngjun have some idea here?
>
> It wouldn't be confusing if this is something users don't have to
> think about at all :) My point is that we don't have a use case where
> we need userspace input on vswap-enablement on a per-cgroup basis yet,
Ha, you really can't assume that for everyone :), we even have
workloads working at different compression levels, and the tiering
series shows different cgroups working on different devices, there has
been pathes enabling per-cgroup swap device a decade ago.
> > > Potentially, but we have many users at Meta. There's a huge diversity
> > > of machine types, workingset size, access patterns (both frequency and
> > > file:anon split), compressibility, etc.
> >
> > You can just set the number as 8PB? :)
>
> Sure, but with the vmalloc-array approach, there is more metadata
> overhead even if we have not allocated the backing page of the
> clusters yet. This will be annoying on the smaller size machines
> (O(dozen of GB)) to also pay the overhead of 8PB-swap space metadata
> reservation.
Not al all? With VM_SPARSE, you literally have zero overhead, unless
you really use these slots.
And even if you really use these slots, the overhead in both CPU and
memory is lower than Xarray, if I did the math right. I just ran a
quick test with Baoquan's Xswap, forcing it to start with 8PB on boot;
it was smooth as batter on a 1GB box and still worked fine after heavy
anon memory pressure.
See below (8PB xswap device with almost no metadata overhead, the only
overhead comes from zswap so I reduced the tree number but that can be
easily merged into clusters as we discussed before):
### Before XSWAP
# free -m
total used free shared buff/cache available
Mem: 1464 405 756 1 544 1058
Swap: 0 0 0
### Create a XSWAP device, I hardcoded the max size in code to 8PB,
### and use fewer ZSWAP trees:
# echo 0 > /sys/kernel/mm/xswap/create
[ 140.289280] xswap: adding extendable swap type 0 (prio -1, init 733
clusters = 375295 pages, max 2199023255552 pages)
# free -m
total used free shared buff/cache available
Mem: 1464 407 755 1 545 1057
Swap: 1465 0 1465
### Lift the ceiling to 8PB:
# echo 4294967296 > /sys/kernel/debug/xswap/type0_cluster_limit
# free -m
total used free shared buff/cache available
Mem: 1464 403 756 1 547 1060
Swap: 8589934591 0 8589934591
### Run memhog:
# time memhog 12G
...
________________________________________________________
Executed in 4.36 secs fish external
usr time 0.46 secs 0.00 millis 0.46 secs
sys time 3.77 secs 3.80 millis 3.76 secs
### After memhog:
# free -m
total used free shared buff/cache available
Mem: 1464 336 1136 0 222 1127
Swap: 8589934591 31 8589934560
The only different from vswap now is that you just hides everything :)
(writeback is not hard to add)
> https://lore.kernel.org/all/CAKEwX=NYoMH8pTKeCvA=XHFmmNVMeDz3mxbhp5q6-PxSTJ5wOg@xxxxxxxxxxxxxx/
Right I saw that, but 64 bit of private id will make shadows really
awkward, not for SWAP but for file folios and file mappings, swap
table is actully fine since memcg_table is standaone, and we can
workaround the hieratical refault distance issue in other ways (e.g.
record the reclaim level instead of memcgid direct). I think 24 bit is
good for now? As I've never see anyone ran into issues
with even 16 bits in production.