Re: [PATCH] mm/zsmalloc: remove shrinker

From: Sergey Senozhatsky

Date: Wed Dec 02 2026 - 22:37:15 EST


On (26/12/03 11:24), Barry Song wrote:
[..]
> > I suppose compaction will be beneficial after a huge app swap-in, e.g.
> > bringing back a web browser with (usual) million tabs. Or after a huge
> > app kill/termination, if the app had swap presence. Both of these
> > release memory from zsmalloc and create fragmentation, so we might
> > benefit from doing a de-fragmentation.
>
> Right. I had Nanzhe(Cc-ed) test this patch on Pixel 6 phones by repeatedly
> launching apps in a loop. We observed some negative results with
> this patch in the absence of proactive compaction.
>
> Nanzhe collected the time series of (mem_used_total - compr_data_size).
> Without the patch, the median was 32 MB. With the patch, it increased
> to 182 MB, peaking at 622 MB.
>
> The median memory overhead due to fragmentation increased from
> 2.5% without the patch to 16.87% with the patch.

Hmm that's a high number...

> So it seems that while mid-swap compaction is undesirable from a
> performance perspective, it does help reduce the memory footprint
> on phones.

A bit of problem is that you need memory pressure to trigger compaction.
On a device, which does proactive per-app swap outs w/o hitting memory
pressure, the fragmentation footprint just sits there (and maybe even
grows).

I wonder if we should consider some sort of a background compaction
triggered by zram instead of shrinker callback. E.g. when zram observes
that mem_used_total to compr_data_size ration goes above some run-time
configurable threshold (e.g. 5%).