Re: Virtual Swap Sync

From: Nhat Pham

Date: Fri Dec 04 2026 - 13:31:03 EST


On Tue, Dec 1, 2026 at 10:27 PM Chris Li <chrisl@xxxxxxxxxx> wrote:
>
> On Mon, Nov 30, 2026 at 4:26 AM Nhat Pham <nphamcs@xxxxxxxxx> wrote:
> > 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
>
> I think you and Kairui have different requirement and assumption in mind.
> You seem to want the maximum compression. (Max memory savings).
> Kairui's usage case cares about the consistency serving quality by
> limiting the total amount of swap (a bounded performance penalty
> caused by swap). My read is that, page faults have a much higher
> access latency than RAM. He is trading less memory saving for more
> consistent run time behavior. The compression ratio is determined by
> the workload, which lacks consistency from a job scheduling
> perspective; he does not want a high compression ratio if it causes
> too many page faults in the worst-case scenario, which would impact
> serving performance. It is OK to OOM there, because if you have too
> much swap, your worst-case performance is trashed anyway. In this case
> the solution is to increase RAM not increase the swap limit.
>
> Both requirements can be valid use cases.

Yes, my personal use case is closer to the second one (maximum
compression), but I'm actually describing both use cases here, and I
think static sizing interface seems wrong for both.

For the first use case, gating phys mem and gating swap size
separately is not the same as gating "logical memory footprint". It's
essentially the equivalent of using memory.max and memory.swap.max to
simulate memsw. It's not quite accurate tbh. That's is my point. The
user is only still using 4GB, logically speaking (1GB file and 3GB of
anon). We're violating that guarantee, because we give the host 2GB of
memory and 2G of offload capability, which fails to serve 4GB because
we incorrectly predict the split.

>
> > 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
>
> Yes, that is the desired behavior for him because you two have
> different constraints.
>
> > 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 see different usage requirements; there is no right or wrong there.

Ideally we should support both use case. I'm trying to think if there
is a better interface than swap sizing that can work for both.

Anyway, as I've said before - adding interface is easy. Removing
interface (whether because it's the wrong thing to do, or if there's a
better thing to do and that better thing might not be coherent with
the old knob), is way harder. We should be more conservative, and
expose as few knobs as possible in the beginning, then gradually
expose knobs on a careful consideration basis.