Re: [PATCH] mm/zsmalloc: remove shrinker

From: Barry Song

Date: Wed Dec 02 2026 - 05:21:53 EST


On Wed, Dec 2, 2026 at 4:14 PM Sergey Senozhatsky
<senozhatsky@xxxxxxxxxxxx> wrote:
>
> On (26/12/02 15:04), Barry Song wrote:
> > > zsmalloc registers a shrinker to run automatic pool compaction under
> > > memory pressure. Because zs_shrinker_scan() calls zs_compact(), it
> > > ignores sc->nr_to_scan and compacts every size class, taking
> > > write_lock(&pool->lock) and per-class locks (dropping them only when a
> > > destination zspage fills or pool->lock is contended). During active
> > > memory pressure, swap-out allocates concurrently from the same size
> > > classes, so physical pages freed by mid-swap compaction are immediately
> > > reallocated. Incoming swap-out refills free slots on its own, while
> > > shrinker compaction contends with page faults and swap-out.
> > >
> > > In the RFC discussion, Xueyuan Chen reported compaction stalls up to
> > > 269.68 ms (p95 38.86 ms) on a 12 GB Android device. Testing on ARM64
> > > QEMU shows that removing the shrinker eliminates mid-swap compaction
> > > churn without increasing active pool memory usage for either zram or
> > > zswap, and cuts zswap page-fault latency under active swap-out:
> > >
> > > ARM64 QEMU (Linux 7.3.0+, zram0, 16 boots per config, ~240 MB swap-out):
> > >
> > > Before After
> > > Pages compacted mid-swap 2,218 0
> > > zram mem_used_total (mid-swap) 121.0 MB 120.9 MB
> > > zram mem_used_total (post-compact) 111.2 MB 110.9 MB
> > >
> > > ARM64 QEMU (Linux 7.3.0+, 4 vCPUs, zswap lz4):
> > >
> > > Before After
> > > Active swap-out pool size 95.9 MB 95.1 MB
> > > Active swap-out p50 fault 3,262 us 2,414 us (-26%)
> > > After swap-out stops (holes held) 44.2 MB 65.1 MB (+20.9 MB)
> > >
> > > For zram, userspace can still trigger compaction explicitly via
> > > /sys/block/zram<id>/compact (zs_compact()), and mm_stat's
> > > pages_compacted now reflects manual compaction only. For zswap, the
> > > shrinker only reduced pool size after new swap-outs stopped; as
> > > discussed on the RFC thread, reclaim-time compaction hurts active fault
> > > latency without reducing active pool size, and any proactive compaction
> > > interface for zswap can be evaluated separately.
> >
> > Hi Chris, Xueyuan and all,
> >
> > Thanks for the patch and the report. Just curious, do we need
> > userspace-triggered proactive compaction
>
> Wouldn't hurt to keep it around, I guess. But maybe can NOOP it
> in the future (removing zram device attributes is a bit difficult,
> we usually give around 3-5 years of deprecation cooldown period
> before removal.)

Hi Sergey,

Thanks for your reply. Sorry, I might not have expressed my question
clearly. Here is what I meant:

We used to have automatic compaction through the shrinker. Now that
we have removed it, do we still expect compaction to be triggered,
either automatically or manually by writing to the zram sysfs
attribute?

I know the changelog already says:

" Testing on ARM64 QEMU shows that removing the shrinker eliminates
mid-swap compaction churn without increasing active pool memory
usage for either zram or zswap."

But what about periods when swap-out is not active? Would compaction
still be beneficial in those cases?

Thanks,
Barry