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

From: Xueyuan Chen

Date: Thu Dec 03 2026 - 21:55:35 EST


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?

>
> Link: https://lore.kernel.org/linux-kernel/18ed2967f99a2eff.3137322e32332e3235332e313736.2c2157.0000sendgmr@xxxxxxxxxx [1]
> Link: https://lore.kernel.org/linux-kernel/CAGsJ_4yoogQHpxGigawTfMPEKL_A6OkfEfsmJHzDHLPS3FCUQg@xxxxxxxxxxxxxx [2]
>
> Chris Wiseman (1):
> mm/zsmalloc: remove shrinker
>
> Sergey Senozhatsky (3):
> zsmalloc: introduce lockless zs_class_can_compact()
> zsmalloc: add deferred threshold compaction
> zram: add compact_threshold sysfs attribute
>
> Documentation/ABI/testing/sysfs-block-zram | 9 ++
> Documentation/admin-guide/blockdev/zram.rst | 2 +
> drivers/block/zram/zram_drv.c | 45 +++++++
> drivers/block/zram/zram_drv.h | 1 +
> include/linux/zsmalloc.h | 3 +
> mm/zsmalloc.c | 136 ++++++++++++--------
> 6 files changed, 142 insertions(+), 54 deletions(-)
>
> --
> 2.56.1.987.g2ec0ab4260-goog
>
>