Re: Virtual Swap Sync
From: Kairui Song
Date: Sun Nov 29 2026 - 11:40:54 EST
On Sun, Nov 22, 2026 at 11:32 PM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
>
> On Thu, Nov 5, 2026 at 2:06 PM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> >
> > Hi folks,
> >
>
> Hi folks - thanks everyone for attending. :)
>
> I summarized the points we discussed below - please let me know if I
> missed anything or misunderstood a point.
>
> * Control interface: Google is interested in a knob to cease zswapping
> (which already exists and will still work in vswap world). Kairui has
> a use case for remapping all swapped-out pages.
>
> Vswap currently bypassed when zswap is off; per-cgroup selection could
> be added as concrete use case arises (for e.g migration/compaction).
>
> David objected that a virtual swap abstraction should not carry a
> swapoff interface per se. Folks also asked whether making vswap a
> mandatory layer would make the implementation cleaner (Nhat will
> explore this direction and follow up on this).
>
> * Virtual space sizing: We discussed using vm.overcommit_ratio and
> vm.overcommit_memory to limit the host's logical memory footprint. The
> exact sizing formula is still unclear - Nhat will follow up with
> Kairui on whether it is acceptable.
>
> (Kairui, if possible, can you respond here for your exact use case? Do
> you want to limit physical memory usage, or virtual? My understanding
> is you want to gate physical + swap, which would be closer to the
> latter).
Hi, Sorry for the a bit late response, got too busy with many other
things recently...
For this part, it's a bit tricky, it's the logical / virtual part,
basically like memsw but without cgroups. We need one host-global size
for the logical footprint, enforced by the OOM killer, I think it will
be easier to understand with the usage described below:
Lightweight VMs are very common and we have a similar situation, and
nowadays they are increasingly even more popular for AI agent
sandboxes. Basically, these VMs run without components like user
space oom killer or cgroup layouts inside.
In one of our use cases, we give the workload a fixed logical
footprint, e.g. on a 2G VM with 2G zram, so memset(region, 0xff, 4G)
will work, memset(region, 0xff, 4G + 2M) will OOM (NOTE, it's not
about same filled pages, just to demonstrate the usage, non same
filled pages with high compression rate are also very common. And yeah
it can't actually hold 4G that way but you know what I mean ;-) ).
The underlying memory can be compressed or swapped. That's fine.
However, letting the app use a much larger logical memory size would
cause unexpected CPU time overcommitment or hangs. And leaking apps
(especially nowadays with AI agents :P) are very common too. We do
want to kill them.
With cgroup v1 we have memsw. With lightweight VMs + zram, we set the
zram size + RAM size to a reasonable size to limit logical usage.
memory.swap.max stops being a logical limit anyway since vswap entries
aren't counted there. Alternative solutions like, reclaiming memory on
the host side, is not always doable, e.g., some hypervisors force
hugetlb, or we simply have no control on that side for some platform.
Problem with overcommit_ratio is that it is limiting the mmap size,
not memset size. xswap provided a size option here.
I really want to know more about the Android case here too, does
Android set a limited zram size for a similar reason?