Re: [RFC PATCH 00/16] mm: add in-memory compression of reclaimed pages
From: Nhat Pham
Date: Tue Nov 17 2026 - 17:57:49 EST
On Tue, Nov 17, 2026 at 8:12 AM nakixii <nakixii@xxxxxxxxx> wrote:
>
> On Mon, Nov 16, 2026 at 06:13:46AM -0800, Nhat Pham wrote:
> > What's the motivation of this line of work?
>
> It started as an attempt to get something like the Darwin memory
> compressor on Linux: keep reclaimed pages compressed in RAM, fault
> them back directly, and push cold data to disk only when needed.
Ohhh I see.
>
> Honestly, your virtual swap series already covers the core of that
> (zswap without a backing swapfile, no PTE walks when moving between
> backends), so I don't think a separate subsystem is justified.
>
> The parts I still think are worth looking at are restoring directly
> from the pool without going through the swap cache, and packing
> several compressed objects into one swap slot on writeback. Do you
> think the latter would fit as another backend type in vswap, or should
> it stay inside zswap writeback?
Ah interesting! In the future you should include the motivation in the
cover letter - either new use case your work will enable, or
performance improvements, or overhead reduction etc.
And yes, compressed writeback would be a good thing to explore! I was
thinking about compressed writeback sometimes ago, and I came up with
a slot-packing mechanism that is very similar to what you are
proposing here (IIUC). It gives you both LRU-ish ordering and good
storage density. Something along this line:
1. An in-memory staging area of "buffer(s)", where we pack slots to be
written-back (by LRU order).
2. Once the buffer is full, we can writeback the entire buffer.
3. Refault of any written-back buffer brings it back to the staging
area. We can use the same mechanism for defrag, compaction, etc.
(I'm not 100% sure how close this is to your idea - yours might be
vastly smarter. I'd need to spend time reading yours...)
But the challenge is the synchronization mechanism. Right now we rely
on the swap cache + folio lock as synchronization. We can't use that
here, as the whole point is we want to avoid decompression. We'd have
to add a backend lock *somewhere*.
Ideally I want this to be decoupled from zswap, i.e as a vswap
backend) We'd have to re-introduce a bit lock (almost similar to
SWAP_HAS_CACHE) - I don't know if it's ideal (Kairui, what do you
think?). Or maybe we can add a backend-specific lock, which pagefault
can block on at swap_read_folio() time...
The other option is we can re-use zsmalloc's internal synchronization.
We already move slots around for internal and external compaction. But
that would blow up zsmalloc - you'd have to implement the stuff above
inside of zsmalloc. And we might have to go for the pool_lock, which
is effectively a global lock...
>
> The numbers in the cover letter are from 6.12 and don't compare
> against vswap, so they don't say much about this yet. I'll redo them
> on a current tree first.
Yeah let's focus on compressed writeback. It's a concrete problem to solve :)