Re: [RFC PATCH 0/4] zsmalloc: replace shrinker with deferred compaction
From: Sergey Senozhatsky
Date: Thu Dec 03 2026 - 22:49:18 EST
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.