* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
[not found] <cover.1786003779.git.xueyuan.chen@vivo.com>
@ 2026-08-07 3:56 ` Sergey Senozhatsky
2026-08-07 10:57 ` Xueyuan Chen
0 siblings, 1 reply; 7+ messages in thread
From: Sergey Senozhatsky @ 2026-08-07 3:56 UTC (permalink / raw)
To: xueyuan.chen
Cc: Minchan Kim, Sergey Senozhatsky, Andrew Morton, linux-mm,
linux-kernel, xueyuan.chen21
On (26/08/06 16:27), xueyuan.chen@vivo.com wrote:
> On an Android device with 12 GB of RAM, observed zsmalloc compaction
> durations had a p95 of 38.86 ms and a maximum of 269.68 ms, motivating a
> per-scan reclaim goal.
Would it be possible to give a little more data? What was the
fragmentation ratio, how much memory was saved during that
auto-compaction, etc. If possible.
Somewhere in the back of my mind I was thinking about, maybe,
disabling (removing) zsmalloc shrinker callbacks, in other words
disabling auto-compaction. We have a sysfs knob for pool compaction
for system that still want to run compaction. So I'm leaning towards
removal of shrinker callbacks from zsmalloc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
2026-08-07 3:56 ` [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware Sergey Senozhatsky
@ 2026-08-07 10:57 ` Xueyuan Chen
2026-08-07 12:12 ` Sergey Senozhatsky
0 siblings, 1 reply; 7+ messages in thread
From: Xueyuan Chen @ 2026-08-07 10:57 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Minchan Kim, Andrew Morton, linux-mm, linux-kernel, xueyuan.chen21
Hi Sergey,
Here is some additional data:
I used the following definitions:
compactable ratio = freeable_pages / total_pages
memory reclaimed = pages_freed * PAGE_SIZE
freeable_pages is the estimate before compaction, based on the same
calculation as zs_shrinker_count(), while pages_freed is the actual
number of backing pages released.
There were 264 callbacks in the trace:
callback elapsed time:
median: 5.77 ms
p95: 55.82 ms
maximum: 271.36 ms
compactable ratio before compaction:
median: 0.32%
p95: 2.86%
maximum: 8.33%
memory reclaimed per callback:
median: 3.80 MiB
p95: 30.45 MiB
maximum: 92.73 MiB
The longest callback took 271.36 ms. Its compactable ratio was 3.25%,
and it released 7,650 pages, or about 29.88 MiB.
There was also a 241.91 ms callback (with 30 schedule-outs) with a
compactable ratio of 0.44%. It released 1,019 pages, or about
3.98 MiB.
Based on this data, it seems better to remove the shrinker.
Would you prefer that I change v2 to remove the zsmalloc shrinker
callbacks directly?
Thanks,
Xueyuan
On 8/7/2026 11:56 AM, Sergey Senozhatsky wrote:
> On (26/08/06 16:27), xueyuan.chen@vivo.com wrote:
>> On an Android device with 12 GB of RAM, observed zsmalloc compaction
>> durations had a p95 of 38.86 ms and a maximum of 269.68 ms, motivating a
>> per-scan reclaim goal.
> Would it be possible to give a little more data? What was the
> fragmentation ratio, how much memory was saved during that
> auto-compaction, etc. If possible.
>
> Somewhere in the back of my mind I was thinking about, maybe,
> disabling (removing) zsmalloc shrinker callbacks, in other words
> disabling auto-compaction. We have a sysfs knob for pool compaction
> for system that still want to run compaction. So I'm leaning towards
> removal of shrinker callbacks from zsmalloc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
2026-08-07 10:57 ` Xueyuan Chen
@ 2026-08-07 12:12 ` Sergey Senozhatsky
2026-08-07 16:25 ` Nhat Pham
0 siblings, 1 reply; 7+ messages in thread
From: Sergey Senozhatsky @ 2026-08-07 12:12 UTC (permalink / raw)
To: Xueyuan Chen, Nhat Pham, Barry Song, Yosry Ahmed,
Johannes Weiner, Brian Geffon
Cc: Sergey Senozhatsky, Minchan Kim, Andrew Morton, linux-mm,
linux-kernel, xueyuan.chen21
On (26/08/07 18:57), Xueyuan Chen wrote:
> Hi Sergey,
>
> Here is some additional data:
>
> I used the following definitions:
> compactable ratio = freeable_pages / total_pages
> memory reclaimed = pages_freed * PAGE_SIZE
>
> freeable_pages is the estimate before compaction, based on the same
> calculation as zs_shrinker_count(), while pages_freed is the actual
> number of backing pages released.
>
> There were 264 callbacks in the trace:
> callback elapsed time:
> median: 5.77 ms
> p95: 55.82 ms
> maximum: 271.36 ms
>
> compactable ratio before compaction:
> median: 0.32%
> p95: 2.86%
> maximum: 8.33%
>
> memory reclaimed per callback:
> median: 3.80 MiB
> p95: 30.45 MiB
> maximum: 92.73 MiB
>
> The longest callback took 271.36 ms. Its compactable ratio was 3.25%,
> and it released 7,650 pages, or about 29.88 MiB.
>
> There was also a 241.91 ms callback (with 30 schedule-outs) with a
> compactable ratio of 0.44%. It released 1,019 pages, or about
> 3.98 MiB.
>
> Based on this data, it seems better to remove the shrinker.
>
> Would you prefer that I change v2 to remove the zsmalloc shrinker
> callbacks directly?
Let's bring in heavy artillery to this discussion, in addition to Andrew
and Minchan, adding Nhat, Yosry, Barry, Johannes, Brian (random order).
Folks, I'm bullish on removal of zsmalloc shrinker callbacks.
I don't think those buy us much apart from memcpy-s and lock
contention. Systems that want to compact zsmalloc have a sysfs
knob (and API) to do so (based on zram mm_stat numbers).
Any thoughts?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
2026-08-07 12:12 ` Sergey Senozhatsky
@ 2026-08-07 16:25 ` Nhat Pham
2026-08-11 9:03 ` Xueyuan Chen
0 siblings, 1 reply; 7+ messages in thread
From: Nhat Pham @ 2026-08-07 16:25 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Xueyuan Chen, Barry Song, Yosry Ahmed, Johannes Weiner,
Brian Geffon, Minchan Kim, Andrew Morton, linux-mm, linux-kernel,
xueyuan.chen21
On Fri, Aug 7, 2026 at 5:12 AM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> On (26/08/07 18:57), Xueyuan Chen wrote:
> > Hi Sergey,
> >
> > Here is some additional data:
> >
> > I used the following definitions:
> > compactable ratio = freeable_pages / total_pages
> > memory reclaimed = pages_freed * PAGE_SIZE
> >
> > freeable_pages is the estimate before compaction, based on the same
> > calculation as zs_shrinker_count(), while pages_freed is the actual
> > number of backing pages released.
> >
> > There were 264 callbacks in the trace:
> > callback elapsed time:
> > median: 5.77 ms
> > p95: 55.82 ms
> > maximum: 271.36 ms
> >
> > compactable ratio before compaction:
> > median: 0.32%
> > p95: 2.86%
> > maximum: 8.33%
> >
> > memory reclaimed per callback:
> > median: 3.80 MiB
> > p95: 30.45 MiB
> > maximum: 92.73 MiB
> >
> > The longest callback took 271.36 ms. Its compactable ratio was 3.25%,
> > and it released 7,650 pages, or about 29.88 MiB.
> >
> > There was also a 241.91 ms callback (with 30 schedule-outs) with a
> > compactable ratio of 0.44%. It released 1,019 pages, or about
> > 3.98 MiB.
> >
> > Based on this data, it seems better to remove the shrinker.
> >
> > Would you prefer that I change v2 to remove the zsmalloc shrinker
> > callbacks directly?
>
> Let's bring in heavy artillery to this discussion, in addition to Andrew
> and Minchan, adding Nhat, Yosry, Barry, Johannes, Brian (random order).
>
> Folks, I'm bullish on removal of zsmalloc shrinker callbacks.
> I don't think those buy us much apart from memcpy-s and lock
> contention. Systems that want to compact zsmalloc have a sysfs
> knob (and API) to do so (based on zram mm_stat numbers).
Hmm we'd need to collect more data in our workloads to determine, but
if we can compute compactable ratio (freeable_pages / total_pages) on
a per size class basis, can we just skip the size class whose ratio is
too bad? Would that at least cut down on the vast majority of
fruitless memcpys and lock acquisitions etc?
I'm always a bit hesitant to over-rely on userspace, especially when
kernel has information to do something smart about it. It might not
react in time, and many proactive reclaiming schemes back off under
heavy memory pressure.
>
> Any thoughts?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
2026-08-07 16:25 ` Nhat Pham
@ 2026-08-11 9:03 ` Xueyuan Chen
2026-08-11 16:25 ` Nhat Pham
0 siblings, 1 reply; 7+ messages in thread
From: Xueyuan Chen @ 2026-08-11 9:03 UTC (permalink / raw)
To: Nhat Pham, Sergey Senozhatsky
Cc: Barry Song, Yosry Ahmed, Johannes Weiner, Brian Geffon,
Minchan Kim, Andrew Morton, linux-mm, linux-kernel,
xueyuan.chen21
On 8/8/2026 12:25 AM, Nhat Pham wrote:
> On Fri, Aug 7, 2026 at 5:12 AM Sergey Senozhatsky
> <senozhatsky@chromium.org> wrote:
>> On (26/08/07 18:57), Xueyuan Chen wrote:
>>> Hi Sergey,
>>>
>>> Here is some additional data:
>>>
>>> I used the following definitions:
>>> compactable ratio = freeable_pages / total_pages
>>> memory reclaimed = pages_freed * PAGE_SIZE
>>>
>>> freeable_pages is the estimate before compaction, based on the same
>>> calculation as zs_shrinker_count(), while pages_freed is the actual
>>> number of backing pages released.
>>>
>>> There were 264 callbacks in the trace:
>>> callback elapsed time:
>>> median: 5.77 ms
>>> p95: 55.82 ms
>>> maximum: 271.36 ms
>>>
>>> compactable ratio before compaction:
>>> median: 0.32%
>>> p95: 2.86%
>>> maximum: 8.33%
>>>
>>> memory reclaimed per callback:
>>> median: 3.80 MiB
>>> p95: 30.45 MiB
>>> maximum: 92.73 MiB
>>>
>>> The longest callback took 271.36 ms. Its compactable ratio was 3.25%,
>>> and it released 7,650 pages, or about 29.88 MiB.
>>>
>>> There was also a 241.91 ms callback (with 30 schedule-outs) with a
>>> compactable ratio of 0.44%. It released 1,019 pages, or about
>>> 3.98 MiB.
>>>
>>> Based on this data, it seems better to remove the shrinker.
>>>
>>> Would you prefer that I change v2 to remove the zsmalloc shrinker
>>> callbacks directly?
>> Let's bring in heavy artillery to this discussion, in addition to Andrew
>> and Minchan, adding Nhat, Yosry, Barry, Johannes, Brian (random order).
>>
>> Folks, I'm bullish on removal of zsmalloc shrinker callbacks.
>> I don't think those buy us much apart from memcpy-s and lock
>> contention. Systems that want to compact zsmalloc have a sysfs
>> knob (and API) to do so (based on zram mm_stat numbers).
> Hmm we'd need to collect more data in our workloads to determine, but
> if we can compute compactable ratio (freeable_pages / total_pages) on
> a per size class basis, can we just skip the size class whose ratio is
> too bad? Would that at least cut down on the vast majority of
> fruitless memcpys and lock acquisitions etc?
>
> I'm always a bit hesitant to over-rely on userspace, especially when
> kernel has information to do something smart about it. It might not
> react in time, and many proactive reclaiming schemes back off under
> heavy memory pressure.
Hi Nhat,
I collected per size-class data. 53.7% of size classes have freeable==0,
so skipping them saves some time. However, 94.7% of zs_compact() time is
spent on classes where freeable > 0 — meaning the cost is dominated by
the actual compaction work, not by scanning empty classes.
That said, skipping freeable == 0 classes is still a worthwhile
optimization on its own — it avoids unnecessary write_lock,spin_lock.
But it would not meaningfully reduce the worst-case latency.
Thanks,
Xueyuan
>> Any thoughts?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
2026-08-11 9:03 ` Xueyuan Chen
@ 2026-08-11 16:25 ` Nhat Pham
2026-08-14 16:50 ` Xueyuan Chen
0 siblings, 1 reply; 7+ messages in thread
From: Nhat Pham @ 2026-08-11 16:25 UTC (permalink / raw)
To: Xueyuan Chen
Cc: Sergey Senozhatsky, Barry Song, Yosry Ahmed, Johannes Weiner,
Brian Geffon, Minchan Kim, Andrew Morton, linux-mm, linux-kernel,
xueyuan.chen21
On Tue, Aug 11, 2026 at 2:04 AM Xueyuan Chen <xueyuan.chen@vivo.com> wrote:
>
>
> On 8/8/2026 12:25 AM, Nhat Pham wrote:
> > On Fri, Aug 7, 2026 at 5:12 AM Sergey Senozhatsky
> > <senozhatsky@chromium.org> wrote:
> >> On (26/08/07 18:57), Xueyuan Chen wrote:
> >>> Hi Sergey,
> >>>
> >>> Here is some additional data:
> >>>
> >>> I used the following definitions:
> >>> compactable ratio = freeable_pages / total_pages
> >>> memory reclaimed = pages_freed * PAGE_SIZE
> >>>
> >>> freeable_pages is the estimate before compaction, based on the same
> >>> calculation as zs_shrinker_count(), while pages_freed is the actual
> >>> number of backing pages released.
> >>>
> >>> There were 264 callbacks in the trace:
> >>> callback elapsed time:
> >>> median: 5.77 ms
> >>> p95: 55.82 ms
> >>> maximum: 271.36 ms
> >>>
> >>> compactable ratio before compaction:
> >>> median: 0.32%
> >>> p95: 2.86%
> >>> maximum: 8.33%
> >>>
> >>> memory reclaimed per callback:
> >>> median: 3.80 MiB
> >>> p95: 30.45 MiB
> >>> maximum: 92.73 MiB
> >>>
> >>> The longest callback took 271.36 ms. Its compactable ratio was 3.25%,
> >>> and it released 7,650 pages, or about 29.88 MiB.
> >>>
> >>> There was also a 241.91 ms callback (with 30 schedule-outs) with a
> >>> compactable ratio of 0.44%. It released 1,019 pages, or about
> >>> 3.98 MiB.
> >>>
> >>> Based on this data, it seems better to remove the shrinker.
> >>>
> >>> Would you prefer that I change v2 to remove the zsmalloc shrinker
> >>> callbacks directly?
> >> Let's bring in heavy artillery to this discussion, in addition to Andrew
> >> and Minchan, adding Nhat, Yosry, Barry, Johannes, Brian (random order).
> >>
> >> Folks, I'm bullish on removal of zsmalloc shrinker callbacks.
> >> I don't think those buy us much apart from memcpy-s and lock
> >> contention. Systems that want to compact zsmalloc have a sysfs
> >> knob (and API) to do so (based on zram mm_stat numbers).
> > Hmm we'd need to collect more data in our workloads to determine, but
> > if we can compute compactable ratio (freeable_pages / total_pages) on
> > a per size class basis, can we just skip the size class whose ratio is
> > too bad? Would that at least cut down on the vast majority of
> > fruitless memcpys and lock acquisitions etc?
> >
> > I'm always a bit hesitant to over-rely on userspace, especially when
> > kernel has information to do something smart about it. It might not
> > react in time, and many proactive reclaiming schemes back off under
> > heavy memory pressure.
>
> Hi Nhat,
>
> I collected per size-class data. 53.7% of size classes have freeable==0,
> so skipping them saves some time. However, 94.7% of zs_compact() time is
> spent on classes where freeable > 0 — meaning the cost is dominated by
> the actual compaction work, not by scanning empty classes.
What's the distribution of these? Say if I were to skip all size class
with compactable ratio below 20%, or those where we can free at least
one full zspage? (IIUC, we only free any memory at all if a zspage got
freed up from our internal compaction, correct?).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware
2026-08-11 16:25 ` Nhat Pham
@ 2026-08-14 16:50 ` Xueyuan Chen
0 siblings, 0 replies; 7+ messages in thread
From: Xueyuan Chen @ 2026-08-14 16:50 UTC (permalink / raw)
To: Nhat Pham
Cc: Xueyuan Chen, Sergey Senozhatsky, Barry Song, Yosry Ahmed,
Johannes Weiner, Brian Geffon, Minchan Kim, Andrew Morton,
linux-mm, linux-kernel
On Wed, Aug 12, 2026 at 12:25 AM Nhat Pham <nphamcs@gmail.com> wrote:
>
> On Tue, Aug 11, 2026 at 2:04 AM Xueyuan Chen <xueyuan.chen@vivo.com> wrote:
> >
> >
> > On 8/8/2026 12:25 AM, Nhat Pham wrote:
> > > On Fri, Aug 7, 2026 at 5:12 AM Sergey Senozhatsky
> > > <senozhatsky@chromium.org> wrote:
> > >> On (26/08/07 18:57), Xueyuan Chen wrote:
> > >>> Hi Sergey,
> > >>>
> > >>> Here is some additional data:
> > >>>
> > >>> I used the following definitions:
> > >>> compactable ratio = freeable_pages / total_pages
> > >>> memory reclaimed = pages_freed * PAGE_SIZE
> > >>>
> > >>> freeable_pages is the estimate before compaction, based on the same
> > >>> calculation as zs_shrinker_count(), while pages_freed is the actual
> > >>> number of backing pages released.
> > >>>
> > >>> There were 264 callbacks in the trace:
> > >>> callback elapsed time:
> > >>> median: 5.77 ms
> > >>> p95: 55.82 ms
> > >>> maximum: 271.36 ms
> > >>>
> > >>> compactable ratio before compaction:
> > >>> median: 0.32%
> > >>> p95: 2.86%
> > >>> maximum: 8.33%
> > >>>
> > >>> memory reclaimed per callback:
> > >>> median: 3.80 MiB
> > >>> p95: 30.45 MiB
> > >>> maximum: 92.73 MiB
> > >>>
> > >>> The longest callback took 271.36 ms. Its compactable ratio was 3.25%,
> > >>> and it released 7,650 pages, or about 29.88 MiB.
> > >>>
> > >>> There was also a 241.91 ms callback (with 30 schedule-outs) with a
> > >>> compactable ratio of 0.44%. It released 1,019 pages, or about
> > >>> 3.98 MiB.
> > >>>
> > >>> Based on this data, it seems better to remove the shrinker.
> > >>>
> > >>> Would you prefer that I change v2 to remove the zsmalloc shrinker
> > >>> callbacks directly?
> > >> Let's bring in heavy artillery to this discussion, in addition to Andrew
> > >> and Minchan, adding Nhat, Yosry, Barry, Johannes, Brian (random order).
> > >>
> > >> Folks, I'm bullish on removal of zsmalloc shrinker callbacks.
> > >> I don't think those buy us much apart from memcpy-s and lock
> > >> contention. Systems that want to compact zsmalloc have a sysfs
> > >> knob (and API) to do so (based on zram mm_stat numbers).
> > > Hmm we'd need to collect more data in our workloads to determine, but
> > > if we can compute compactable ratio (freeable_pages / total_pages) on
> > > a per size class basis, can we just skip the size class whose ratio is
> > > too bad? Would that at least cut down on the vast majority of
> > > fruitless memcpys and lock acquisitions etc?
> > >
> > > I'm always a bit hesitant to over-rely on userspace, especially when
> > > kernel has information to do something smart about it. It might not
> > > react in time, and many proactive reclaiming schemes back off under
> > > heavy memory pressure.
> >
> > Hi Nhat,
> >
> > I collected per size-class data. 53.7% of size classes have freeable==0,
> > so skipping them saves some time. However, 94.7% of zs_compact() time is
> > spent on classes where freeable > 0 — meaning the cost is dominated by
> > the actual compaction work, not by scanning empty classes.
>
Hi Nhat,
Sorry for the late reply.
> What's the distribution of these? Say if I were to skip all size class
> with compactable ratio below 20%, or those where we can free at least
> one full zspage? (IIUC, we only free any memory at all if a zspage got
> freed up from our internal compaction, correct?).
You are right, we only free the backing pages when a full zspage is emptied
by compaction.
My test device had some problems, I need some time to collect new data.
The good news is the per-size-class distribution should be ready next week.
Thanks
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-08-14 16:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <cover.1786003779.git.xueyuan.chen@vivo.com>
2026-08-07 3:56 ` [RFC PATCH 0/2] mm: zsmalloc: make shrinker compaction budget-aware Sergey Senozhatsky
2026-08-07 10:57 ` Xueyuan Chen
2026-08-07 12:12 ` Sergey Senozhatsky
2026-08-07 16:25 ` Nhat Pham
2026-08-11 9:03 ` Xueyuan Chen
2026-08-11 16:25 ` Nhat Pham
2026-08-14 16:50 ` Xueyuan Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®