Re: Virtual Swap Sync

From: Nhat Pham

Date: Thu Nov 26 2026 - 12:30:45 EST


On Wed, Nov 25, 2026 at 11:03 PM Baoquan He <baoquan.he@xxxxxxxxx> wrote:
>
> On 11/22/26 at 08:31am, Nhat Pham 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).
> >
> > * Priority and multiple swapfiles: should not be added for now.
> > No good use case for swap priority was identified.
> > Multiple swapfiles were used in the past to work around swapfile
> > lock contention, but it is unclear whether they are still needed with
> > Kairui's new cluster-based allocator. If contention remains a problem,
> > we should fix it in the kernel before putting that burden on
> > userspace.
> >
> > * Proposed phase split and charging (from Nhat):
> >
> > - Phase 1 - initial foundation:
> > - Decoupled zswap: Let zswap operate without reserving disk swap
> > for every virtual entry.
> > - Physical backing and writeback: Keep disk swap available as a
> > backend, including when zswap cannot store a page or an entry needs
> > writeback.
> > - Charging: Retain memsw charging for virtual entries; keep
> > virtual-slot usage out of memory.swap.max. Actual physical swap usage
> > keeps its resource charging.
> > - Usage counter: Expose vswap usage so users can monitor
> > virtual-space consumption separately from physical swap usage.
> > Essentially this gives you a method to estimate the logical footprint
> > (memory.current - swapcached + vswap).
> >
> > - Subsequent phase(s) - further support and controls:
> > - VM_SPARSE: Add VM_SPARSE as an optimization after the
> > first-phase foundation.
> > - Runtime controls (added as use cases arise):
> > - Host-wide runtime disablement knob (and remapping of swapped out data).
> > - Per-cgroup vswap control (for e.g, if some cgroups want
> > migrations/physical swapfile compaction).
> >
> > - Orthogonal use cases and concerns:
> > - Cgroup-level logical memory limits in cgroupv2 (memsw?) - swap
> > developers will follow up with memcg maintainers.
> > - Static sizing: Define the host-sizing formula and decide whether
> > another interface is needed.
> > - Swap tiering for cgroups: Explore backend selection when a
> > concrete workload needs it.
>
> Youngjun's swap tier comes from concrete use case of his company, it's
> been v11, he presented this in LSF and LPC.
>
> [RFC PATCH v11 0/4] mm/swap: priority-based swap tiers with per-cgroup selection
> https://lore.kernel.org/all/20260916183437.2946306-1-youngjun.park@xxxxxxx/T/#u
>
> This is xswap road map I shared with you when we discussed about working
> together. I also mentioned swap tier in road map because Swap tier is a
> very important feature we swap developers plan to add.
>
> https://lore.kernel.org/all/al8ohWshSSZ64AtT@MiWiFi-R3L-srv/
>
> I thought you had read them.

I put this as "orthogonal" because I don't think swap tiering should
block virtual swap development. It's probably the other way around -
swap tiering makes a lot less sense without a virtual swap layer.

If you want my opinions on swap tiering, you could search on lore :)

https://lore.kernel.org/linux-mm/CAKEwX=O-_OZ8x0UC96a_k+0eZfAE+mWMWDdn68uy1LHRq=JC0w@xxxxxxxxxxxxxx/
https://lore.kernel.org/linux-mm/CAKEwX=N2XcMHN1jatppOk6wnmz-Shab5XMtTtzgYOzRvU_6YFw@xxxxxxxxxxxxxx/
https://lore.kernel.org/all/CAKEwX=NfSy0XiD_UMsDOHGCwpE7sYmBmhV4Y9vk_cbnnr6J6PQ@xxxxxxxxxxxxxx/
https://lore.kernel.org/all/CAKEwX=NfSy0XiD_UMsDOHGCwpE7sYmBmhV4Y9vk_cbnnr6J6PQ@xxxxxxxxxxxxxx/

I did review Youngjun's code, pointing out some deficiencies we needed
to fix eventually, but I did not nack anything.

The problem with that series is that the memcg maintainers are not
satisfied with the proposed interface, and the lack of writeback
support (i.e data transfer between tier).

I also raised a similar concern in one of those comments. And it's not
just a nice-to-have either. We can get into LRU inversion scenario
because of it.

FWIW, virtual swap IS a step to resolve that problem. It provides an
indirection layer that allow you to change the backend without having
to do PT walk to update the backend, or repeating the logic at every
backend level. The "V" in VFS, so to speak.

Similar with the other items on the list - memsw for e.g. I made a
best effort attempt at least to make vswap work with memsw, but memsw
in cgroupv2 is its own conversation.

>
> I don't know why I couldn't join meeting last time, I tried at 8:05am at
> my side, kept waiting for people to approve me until 8:30am I was
> added. Not sure if you guys also talked about this.

Hmm maybe I missed that notifications? Apologies if that's the case -
I do remember letting you in but I wasn't sure at which time. But you
were eventually in right? I remember you commenting on some
overcommiting stuff.

Feel free to comment on this summary if you disagree with any points
:) And how do you feel about the proposal?