Re: Virtual Swap Sync
From: Nhat Pham
Date: Mon Nov 30 2026 - 07:26:36 EST
On Sun, Nov 29, 2026 at 9:40 AM Kairui Song <ryncsn@xxxxxxxxx> wrote:
>
> 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.
Ah I see. It's logical footprint, but enforced on an allocation/used
basis rather than mapping (i.e address space reservation, which
existing vm.overcommit modes regulate).
I think swap sizing is still the wrong interface for this. IMHO, it's
a crude emulation, with some downsides:
Say the desired logical memory limit is 4GB. We have 2GB of physical
memory limit, so we emulate that by setting swap size to 2GB. Now say
I have a hot file cache of 1GB, and 3GB of cold anon. That should be
allowed, but you'd thrash prematurely or OOM because you can only
offload 2GB of anon, and compressed anon + 1GB of uncompressed anon +
1GB of file cache does not fit in that 2GB limit. If we can just
compressed a bit more all would be good, but this requires knowing
apriori compression ratio to properly set this limit right.
It also limits the offloading potential of the system. On a system
that relies on proactive guest-side reclaim to overcommit VMs, we
could have offloaded 3GB, but instead had to stop at 2. This adds up.
Unironically host-wide memsw is correct semantics here: physical
memory usage + anon offloaded ("swap"), but irregardless of split. I
think this calls for a new interface. If we're going to design
interfaces, why not go for the right one?
>
> I really want to know more about the Android case here too, does
> Android set a limited zram size for a similar reason?
Zram just presents itself like a physical swapfile, so I don't think
there's even an option to make it unlimited?