Re: [PATCH] mm/zsmalloc: remove shrinker
From: Barry Song
Date: Thu Dec 03 2026 - 00:10:49 EST
On Thu, Dec 3, 2026 at 12:52 PM Sergey Senozhatsky
<senozhatsky@xxxxxxxxxxxx> wrote:
>
> On (26/12/03 13:24), Sergey Senozhatsky wrote:
> [..]
>
> static void __init zs_stat_init(void)
> @@ -1461,6 +1471,7 @@ void zs_free(struct zs_pool *pool, struct zs_handle *handle)
> struct size_class *class;
> int fullness;
> struct zspage *zspage_to_free = NULL;
> + bool kick_compact = false;
>
> if (!zs_handle_is_allocated(handle))
> return;
> @@ -1481,6 +1492,10 @@ void zs_free(struct zs_pool *pool, struct zs_handle *handle)
> } else {
> kick_deferred_free(pool);
> }
> + } else if (READ_ONCE(pool->compact_threshold) &&
> + !delayed_work_pending(&pool->compact_work) &&
> + zs_class_can_compact(class)) {
> + kick_compact = true;
> }
>
> spin_unlock(&class->lock);
> @@ -1488,6 +1503,8 @@ void zs_free(struct zs_pool *pool, struct zs_handle *handle)
> if (zspage_to_free) {
> __free_zspage_lockless(zspage_to_free);
> atomic_long_sub(class->pages_per_zspage, &pool->pages_allocated);
> + } else if (kick_compact) {
> + kick_deferred_compact(pool);
> }
> }
Hi Sergey,
Thanks very much for the quick patch! I'm always amazed by how
quickly you come up with patches :-)
For both zram and zsmalloc deferred compaction, the kick is currently
in the free path (zs_free() or slot_free()). I wonder whether we
also need to kick compaction from the allocation path.
For example, if userspace triggers proactive swap-out but no swap-in
has occurred yet, would we miss the opportunity to kick compaction?
I think compaction after proactive swap-out (e.g., when an app moves
to the background) could be quite beneficial. It could also help
reduce future memory pressure by freeing physical pages earlier,
rather than deferring all automatic compaction until memory pressure
arises, as we currently do in mainline.
Thanks,
Barry