Re: [RFC PATCH 0/4] zsmalloc: replace shrinker with deferred compaction

From: Sergey Senozhatsky

Date: Sun Dec 06 2026 - 01:38:10 EST


On (26/12/04 12:49), Sergey Senozhatsky wrote:
> On (26/12/04 10:55), Xueyuan Chen wrote:
> > On 2026-12-03 19:13 +0900, Sergey Senozhatsky wrote:
> > > This is a follow-up to Chris's shrinker removal patch [1] and Barry's
> > > Pixel 6 fragmentation numbers [2].
> > >
> > > Removing the shrinker avoids mid-swap compaction stalls, but without
> > > any automatic compaction we risk regressing memory footprint on systems
> > > that do not run a userspace compaction daemon, and on systems that do
> > > proactive swap-out without hitting memory pressure (no shrinker
> > > triggers).
> > >
> > > Replace shrinker callbacks (now removed) with deferred threshold-based
> > > compaction in zsmalloc (plus a runtime-tunable zram sysfs knob to
> > > configure or disable it).
> >
> > Hi Sergey,
> >
> > I wonder if we could also consider cross-class reuse to reduce the
> > need for compaction.
> >
> > In my Pixel 6 Pro workload, I observed that the 2048-byte class
> > grew by 3.5 MiB within a 2-second window while other size classes
> > had about 125 MiB of compactable memory.
> >
> > When a class runs out of free objects, could we try allocating from
> > an existing zspage in a slightly larger class before allocating
> > a new zspage?
> >
> > This would introduce some internal fragmentation, but might reduce
> > physical page allocations and object migration during compaction,
> > without changing the existing zspage layout or the allocation fast
> > path.
> >
> > What do you think about this trade-off?
>
> That idea did pop-up sometime in 2015-2017, but we were never sure
> about it. Borrowing free space from a higher size class comes with
> higher object padding overhead, potentially, so we never explored
> it in depth. This kind of changes zsmalloc design, from being slab-like
> to managing free spaces.

The last sentence in my previous email can be ignored, I don't
understand what I was trying to say there :)

Now, back to your numbers. I guess with threshold-based compaction
we won't be having a problem of wasted 125 MiB in some size classes.
So maybe rather than counting on possibility of lower size clasess
borrowing free space from upper classes, which they may not do and
then we just have wasted memory, we can just free unused memory.