Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/zsmalloc: remove shrinker
@ 2026-12-01 15:02 Chris Wiseman
  2026-12-01 16:45 ` Nhat Pham
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: Chris Wiseman @ 2026-12-01 15:02 UTC (permalink / raw)
  To: Andrew Morton, Minchan Kim, Sergey Senozhatsky
  Cc: Johannes Weiner, Yosry Ahmed, Nhat Pham, Chengming Zhou,
	Xueyuan Chen, Xueyuan Chen, Barry Song, Brian Geffon, linux-mm,
	linux-kernel, Chris Wiseman

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.

Remove the zsmalloc shrinker callbacks, registration, and header
include.  Because zs_register_shrinker() was the only remaining reader
of pool->name (zs_pool_stat_create() passes the name parameter directly
to debugfs), also remove pool->name and its kstrdup()/kfree()
allocation.

On arm64 defconfig (4K pages, Clang), this shrinks struct zs_pool from
2128 bytes (34 cachelines) to 2112 bytes (33 cachelines) via pahole and
reduces mm/zsmalloc.o object size (scripts/bloat-o-meter):

  arm64 defconfig (Clang):   30684 -> 30127 bytes (-557 bytes, -1.82%)
  x86_64 minimal (GCC):      12584 -> 12169 bytes (-415 bytes, -3.30%)

Link: https://lore.kernel.org/cover.1786003779.git.xueyuan.chen@vivo.com
Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Suggested-by: Yosry Ahmed <yosry@kernel.org>
Signed-off-by: Chris Wiseman <chriswiseman@google.com>
---
 mm/zsmalloc.c | 76 ---------------------------------------------------
 1 file changed, 76 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index f263bd2b8d46..17ef924f748b 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -38,7 +38,6 @@
 #include <linux/scatterlist.h>
 #include <linux/spinlock.h>
 #include <linux/sprintf.h>
-#include <linux/shrinker.h>
 #include <linux/types.h>
 #include <linux/debugfs.h>
 #include <linux/zsmalloc.h>
@@ -270,17 +269,12 @@ struct link_free {
 static struct kmem_cache *zspage_cachep;
 
 struct zs_pool {
-	const char *name;
-
 	struct size_class *size_class[ZS_SIZE_CLASSES];
 
 	atomic_long_t pages_allocated;
 
 	struct zs_pool_stats stats;
 
-	/* Compact classes */
-	struct shrinker *shrinker;
-
 	struct dentry *stat_dentry;
 #ifdef CONFIG_COMPACTION
 	struct work_struct free_work;
@@ -2115,62 +2109,6 @@ void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats)
 }
 EXPORT_SYMBOL_GPL(zs_pool_stats);
 
-static unsigned long zs_shrinker_scan(struct shrinker *shrinker,
-		struct shrink_control *sc)
-{
-	unsigned long pages_freed;
-	struct zs_pool *pool = shrinker->private_data;
-
-	/*
-	 * Compact classes and calculate compaction delta.
-	 * Can run concurrently with a manually triggered
-	 * (by user) compaction.
-	 */
-	pages_freed = zs_compact(pool);
-
-	return pages_freed ? pages_freed : SHRINK_STOP;
-}
-
-static unsigned long zs_shrinker_count(struct shrinker *shrinker,
-		struct shrink_control *sc)
-{
-	int i;
-	struct size_class *class;
-	unsigned long pages_to_free = 0;
-	struct zs_pool *pool = shrinker->private_data;
-
-	for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) {
-		class = pool->size_class[i];
-		if (class->index != i)
-			continue;
-
-		pages_to_free += zs_can_compact(class);
-	}
-
-	return pages_to_free;
-}
-
-static void zs_unregister_shrinker(struct zs_pool *pool)
-{
-	shrinker_free(pool->shrinker);
-}
-
-static int zs_register_shrinker(struct zs_pool *pool)
-{
-	pool->shrinker = shrinker_alloc(0, "mm-zspool:%s", pool->name);
-	if (!pool->shrinker)
-		return -ENOMEM;
-
-	pool->shrinker->scan_objects = zs_shrinker_scan;
-	pool->shrinker->count_objects = zs_shrinker_count;
-	pool->shrinker->batch = 0;
-	pool->shrinker->private_data = pool;
-
-	shrinker_register(pool->shrinker);
-
-	return 0;
-}
-
 static int calculate_zspage_chain_size(int class_size)
 {
 	int i, min_waste = INT_MAX;
@@ -2216,10 +2154,6 @@ struct zs_pool *zs_create_pool(const char *name)
 	rwlock_init(&pool->lock);
 	atomic_set(&pool->compaction_in_progress, 0);
 
-	pool->name = kstrdup(name, GFP_KERNEL);
-	if (!pool->name)
-		goto err;
-
 	/*
 	 * Iterate reversely, because, size of size_class that we want to use
 	 * for merging should be larger or equal to current size.
@@ -2297,14 +2231,6 @@ struct zs_pool *zs_create_pool(const char *name)
 	/* debug only, don't abort if it fails */
 	zs_pool_stat_create(pool, name);
 
-	/*
-	 * Not critical since shrinker is only used to trigger internal
-	 * defragmentation of the pool which is pretty optional thing.  If
-	 * registration fails we still can use the pool normally and user can
-	 * trigger compaction manually. Thus, ignore return code.
-	 */
-	zs_register_shrinker(pool);
-
 	return pool;
 
 err:
@@ -2317,7 +2243,6 @@ void zs_destroy_pool(struct zs_pool *pool)
 {
 	int i;
 
-	zs_unregister_shrinker(pool);
 	zs_flush_migration(pool);
 	zs_pool_stat_destroy(pool);
 
@@ -2341,7 +2266,6 @@ void zs_destroy_pool(struct zs_pool *pool)
 		kfree(class);
 	}
 
-	kfree(pool->name);
 	kfree(pool);
 }
 EXPORT_SYMBOL_GPL(zs_destroy_pool);

base-commit: d2e5fd43304200927d92c50ffa8bbe8420753f88
-- 
2.47.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-01 15:02 [PATCH] mm/zsmalloc: remove shrinker Chris Wiseman
@ 2026-12-01 16:45 ` Nhat Pham
  2026-12-01 16:53 ` Yosry Ahmed
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Nhat Pham @ 2026-12-01 16:45 UTC (permalink / raw)
  To: Chris Wiseman
  Cc: Andrew Morton, Minchan Kim, Sergey Senozhatsky, Johannes Weiner,
	Yosry Ahmed, Chengming Zhou, Xueyuan Chen, Xueyuan Chen,
	Barry Song, Brian Geffon, linux-mm, linux-kernel

On Tue, Dec 1, 2026 at 8:02 AM Chris Wiseman <chriswiseman@google.com> 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.
>
> Remove the zsmalloc shrinker callbacks, registration, and header
> include.  Because zs_register_shrinker() was the only remaining reader
> of pool->name (zs_pool_stat_create() passes the name parameter directly
> to debugfs), also remove pool->name and its kstrdup()/kfree()
> allocation.
>
> On arm64 defconfig (4K pages, Clang), this shrinks struct zs_pool from
> 2128 bytes (34 cachelines) to 2112 bytes (33 cachelines) via pahole and
> reduces mm/zsmalloc.o object size (scripts/bloat-o-meter):
>
>   arm64 defconfig (Clang):   30684 -> 30127 bytes (-557 bytes, -1.82%)
>   x86_64 minimal (GCC):      12584 -> 12169 bytes (-415 bytes, -3.30%)
>
> Link: https://lore.kernel.org/cover.1786003779.git.xueyuan.chen@vivo.com
> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Suggested-by: Yosry Ahmed <yosry@kernel.org>
> Signed-off-by: Chris Wiseman <chriswiseman@google.com>

Reviewed-by: Nhat Pham <nphamcs@gmail.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-01 15:02 [PATCH] mm/zsmalloc: remove shrinker Chris Wiseman
  2026-12-01 16:45 ` Nhat Pham
@ 2026-12-01 16:53 ` Yosry Ahmed
  2026-12-02  0:46 ` Xueyuan Chen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Yosry Ahmed @ 2026-12-01 16:53 UTC (permalink / raw)
  To: Chris Wiseman
  Cc: Andrew Morton, Minchan Kim, Sergey Senozhatsky, Johannes Weiner,
	Nhat Pham, Chengming Zhou, Xueyuan Chen, Xueyuan Chen, Barry Song,
	Brian Geffon, linux-mm, linux-kernel

On Tue, Dec 1, 2026 at 7:02 AM Chris Wiseman <chriswiseman@google.com> 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.
>
> Remove the zsmalloc shrinker callbacks, registration, and header
> include.  Because zs_register_shrinker() was the only remaining reader
> of pool->name (zs_pool_stat_create() passes the name parameter directly
> to debugfs), also remove pool->name and its kstrdup()/kfree()
> allocation.
>
> On arm64 defconfig (4K pages, Clang), this shrinks struct zs_pool from
> 2128 bytes (34 cachelines) to 2112 bytes (33 cachelines) via pahole and
> reduces mm/zsmalloc.o object size (scripts/bloat-o-meter):
>
>   arm64 defconfig (Clang):   30684 -> 30127 bytes (-557 bytes, -1.82%)
>   x86_64 minimal (GCC):      12584 -> 12169 bytes (-415 bytes, -3.30%)
>
> Link: https://lore.kernel.org/cover.1786003779.git.xueyuan.chen@vivo.com
> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Suggested-by: Yosry Ahmed <yosry@kernel.org>
> Signed-off-by: Chris Wiseman <chriswiseman@google.com>

Acked-by: Yosry Ahmed <yosry@kernel.org>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-01 15:02 [PATCH] mm/zsmalloc: remove shrinker Chris Wiseman
  2026-12-01 16:45 ` Nhat Pham
  2026-12-01 16:53 ` Yosry Ahmed
@ 2026-12-02  0:46 ` Xueyuan Chen
  2026-12-02  2:09 ` Sergey Senozhatsky
  2026-12-02  7:04 ` Barry Song
  4 siblings, 0 replies; 12+ messages in thread
From: Xueyuan Chen @ 2026-12-02  0:46 UTC (permalink / raw)
  To: Chris Wiseman
  Cc: Andrew Morton, Minchan Kim, Sergey Senozhatsky, Johannes Weiner,
	Yosry Ahmed, Nhat Pham, Chengming Zhou, Xueyuan Chen,
	Xueyuan Chen, Barry Song, Brian Geffon, linux-mm, linux-kernel

On 2026-12-01 15:02 +0000, Chris Wiseman 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.
> 
> Remove the zsmalloc shrinker callbacks, registration, and header
> include.  Because zs_register_shrinker() was the only remaining reader
> of pool->name (zs_pool_stat_create() passes the name parameter directly
> to debugfs), also remove pool->name and its kstrdup()/kfree()
> allocation.
> 
> On arm64 defconfig (4K pages, Clang), this shrinks struct zs_pool from
> 2128 bytes (34 cachelines) to 2112 bytes (33 cachelines) via pahole and
> reduces mm/zsmalloc.o object size (scripts/bloat-o-meter):
> 
>   arm64 defconfig (Clang):   30684 -> 30127 bytes (-557 bytes, -1.82%)
>   x86_64 minimal (GCC):      12584 -> 12169 bytes (-415 bytes, -3.30%)
> 
> Link: https://lore.kernel.org/cover.1786003779.git.xueyuan.chen@vivo.com
> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Suggested-by: Yosry Ahmed <yosry@kernel.org>
> Signed-off-by: Chris Wiseman <chriswiseman@google.com>
> ---
>  mm/zsmalloc.c | 76 ---------------------------------------------------
>  1 file changed, 76 deletions(-)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index f263bd2b8d46..17ef924f748b 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -38,7 +38,6 @@
>  #include <linux/scatterlist.h>
>  #include <linux/spinlock.h>
>  #include <linux/sprintf.h>
> -#include <linux/shrinker.h>
>  #include <linux/types.h>
>  #include <linux/debugfs.h>
>  #include <linux/zsmalloc.h>
> @@ -270,17 +269,12 @@ struct link_free {
>  static struct kmem_cache *zspage_cachep;
>  
>  struct zs_pool {
> -	const char *name;
> -
>  	struct size_class *size_class[ZS_SIZE_CLASSES];
>  
>  	atomic_long_t pages_allocated;
>  
>  	struct zs_pool_stats stats;
>  
> -	/* Compact classes */
> -	struct shrinker *shrinker;
> -
>  	struct dentry *stat_dentry;
>  #ifdef CONFIG_COMPACTION
>  	struct work_struct free_work;
> @@ -2115,62 +2109,6 @@ void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats)
>  }
>  EXPORT_SYMBOL_GPL(zs_pool_stats);
>  
> -static unsigned long zs_shrinker_scan(struct shrinker *shrinker,
> -		struct shrink_control *sc)
> -{
> -	unsigned long pages_freed;
> -	struct zs_pool *pool = shrinker->private_data;
> -
> -	/*
> -	 * Compact classes and calculate compaction delta.
> -	 * Can run concurrently with a manually triggered
> -	 * (by user) compaction.
> -	 */
> -	pages_freed = zs_compact(pool);
> -
> -	return pages_freed ? pages_freed : SHRINK_STOP;
> -}
> -
> -static unsigned long zs_shrinker_count(struct shrinker *shrinker,
> -		struct shrink_control *sc)
> -{
> -	int i;
> -	struct size_class *class;
> -	unsigned long pages_to_free = 0;
> -	struct zs_pool *pool = shrinker->private_data;
> -
> -	for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) {
> -		class = pool->size_class[i];
> -		if (class->index != i)
> -			continue;
> -
> -		pages_to_free += zs_can_compact(class);
> -	}
> -
> -	return pages_to_free;
> -}
> -
> -static void zs_unregister_shrinker(struct zs_pool *pool)
> -{
> -	shrinker_free(pool->shrinker);
> -}
> -
> -static int zs_register_shrinker(struct zs_pool *pool)
> -{
> -	pool->shrinker = shrinker_alloc(0, "mm-zspool:%s", pool->name);
> -	if (!pool->shrinker)
> -		return -ENOMEM;
> -
> -	pool->shrinker->scan_objects = zs_shrinker_scan;
> -	pool->shrinker->count_objects = zs_shrinker_count;
> -	pool->shrinker->batch = 0;
> -	pool->shrinker->private_data = pool;
> -
> -	shrinker_register(pool->shrinker);
> -
> -	return 0;
> -}
> -
>  static int calculate_zspage_chain_size(int class_size)
>  {
>  	int i, min_waste = INT_MAX;
> @@ -2216,10 +2154,6 @@ struct zs_pool *zs_create_pool(const char *name)
>  	rwlock_init(&pool->lock);
>  	atomic_set(&pool->compaction_in_progress, 0);
>  
> -	pool->name = kstrdup(name, GFP_KERNEL);
> -	if (!pool->name)
> -		goto err;
> -
>  	/*
>  	 * Iterate reversely, because, size of size_class that we want to use
>  	 * for merging should be larger or equal to current size.
> @@ -2297,14 +2231,6 @@ struct zs_pool *zs_create_pool(const char *name)
>  	/* debug only, don't abort if it fails */
>  	zs_pool_stat_create(pool, name);
>  
> -	/*
> -	 * Not critical since shrinker is only used to trigger internal
> -	 * defragmentation of the pool which is pretty optional thing.  If
> -	 * registration fails we still can use the pool normally and user can
> -	 * trigger compaction manually. Thus, ignore return code.
> -	 */
> -	zs_register_shrinker(pool);
> -
>  	return pool;
>  
>  err:
> @@ -2317,7 +2243,6 @@ void zs_destroy_pool(struct zs_pool *pool)
>  {
>  	int i;
>  
> -	zs_unregister_shrinker(pool);
>  	zs_flush_migration(pool);
>  	zs_pool_stat_destroy(pool);
>  
> @@ -2341,7 +2266,6 @@ void zs_destroy_pool(struct zs_pool *pool)
>  		kfree(class);
>  	}
>  
> -	kfree(pool->name);
>  	kfree(pool);
>  }
>  EXPORT_SYMBOL_GPL(zs_destroy_pool);
Reviewed-by: Xueyuan Chen <xueyuan.chen21@gmail.com>
> 
> base-commit: d2e5fd43304200927d92c50ffa8bbe8420753f88
> -- 
> 2.47.0
> 
> 




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-01 15:02 [PATCH] mm/zsmalloc: remove shrinker Chris Wiseman
                   ` (2 preceding siblings ...)
  2026-12-02  0:46 ` Xueyuan Chen
@ 2026-12-02  2:09 ` Sergey Senozhatsky
  2026-12-02  7:04 ` Barry Song
  4 siblings, 0 replies; 12+ messages in thread
From: Sergey Senozhatsky @ 2026-12-02  2:09 UTC (permalink / raw)
  To: Chris Wiseman
  Cc: Andrew Morton, Minchan Kim, Sergey Senozhatsky, Johannes Weiner,
	Yosry Ahmed, Nhat Pham, Chengming Zhou, Xueyuan Chen,
	Xueyuan Chen, Barry Song, Brian Geffon, linux-mm, linux-kernel

On (26/12/01 15:02), Chris Wiseman 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.
> 
> Remove the zsmalloc shrinker callbacks, registration, and header
> include.  Because zs_register_shrinker() was the only remaining reader
> of pool->name (zs_pool_stat_create() passes the name parameter directly
> to debugfs), also remove pool->name and its kstrdup()/kfree()
> allocation.
> 
> On arm64 defconfig (4K pages, Clang), this shrinks struct zs_pool from
> 2128 bytes (34 cachelines) to 2112 bytes (33 cachelines) via pahole and
> reduces mm/zsmalloc.o object size (scripts/bloat-o-meter):
> 
>   arm64 defconfig (Clang):   30684 -> 30127 bytes (-557 bytes, -1.82%)
>   x86_64 minimal (GCC):      12584 -> 12169 bytes (-415 bytes, -3.30%)
> 
> Link: https://lore.kernel.org/cover.1786003779.git.xueyuan.chen@vivo.com
> Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> Suggested-by: Yosry Ahmed <yosry@kernel.org>
> Signed-off-by: Chris Wiseman <chriswiseman@google.com>

Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-01 15:02 [PATCH] mm/zsmalloc: remove shrinker Chris Wiseman
                   ` (3 preceding siblings ...)
  2026-12-02  2:09 ` Sergey Senozhatsky
@ 2026-12-02  7:04 ` Barry Song
  2026-12-02  8:14   ` Sergey Senozhatsky
  4 siblings, 1 reply; 12+ messages in thread
From: Barry Song @ 2026-12-02  7:04 UTC (permalink / raw)
  To: Chris Wiseman
  Cc: Andrew Morton, Minchan Kim, Sergey Senozhatsky, Johannes Weiner,
	Yosry Ahmed, Nhat Pham, Chengming Zhou, Xueyuan Chen,
	Xueyuan Chen, Brian Geffon, linux-mm, linux-kernel

On Tue, Dec 1, 2026 at 11:02 PM Chris Wiseman <chriswiseman@google.com> 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 for zram on Android after
this patch? I mean, do you have any userspace code that triggers
compaction via /sys/block/zram<id>/compact?

Thanks,
Barry


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-02  7:04 ` Barry Song
@ 2026-12-02  8:14   ` Sergey Senozhatsky
  2026-12-02 10:21     ` Barry Song
  0 siblings, 1 reply; 12+ messages in thread
From: Sergey Senozhatsky @ 2026-12-02  8:14 UTC (permalink / raw)
  To: Barry Song
  Cc: Chris Wiseman, Andrew Morton, Minchan Kim, Sergey Senozhatsky,
	Johannes Weiner, Yosry Ahmed, Nhat Pham, Chengming Zhou,
	Xueyuan Chen, Xueyuan Chen, Brian Geffon, linux-mm, linux-kernel

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.)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-02  8:14   ` Sergey Senozhatsky
@ 2026-12-02 10:21     ` Barry Song
  2026-12-02 16:17       ` Chris Wiseman
  2026-12-03  3:08       ` Sergey Senozhatsky
  0 siblings, 2 replies; 12+ messages in thread
From: Barry Song @ 2026-12-02 10:21 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Chris Wiseman, Andrew Morton, Minchan Kim, Johannes Weiner,
	Yosry Ahmed, Nhat Pham, Chengming Zhou, Xueyuan Chen,
	Xueyuan Chen, Brian Geffon, linux-mm, linux-kernel

On Wed, Dec 2, 2026 at 4:14 PM Sergey Senozhatsky
<senozhatsky@chromium.org> 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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-02 10:21     ` Barry Song
@ 2026-12-02 16:17       ` Chris Wiseman
  2026-12-03  3:08       ` Sergey Senozhatsky
  1 sibling, 0 replies; 12+ messages in thread
From: Chris Wiseman @ 2026-12-02 16:17 UTC (permalink / raw)
  To: Barry Song, Sergey Senozhatsky, Chris Wiseman, Andrew Morton,
	Minchan Kim, Johannes Weiner, Yosry Ahmed, Nhat Pham,
	Chengming Zhou, Xueyuan Chen, Xueyuan Chen, Brian Geffon,
	linux-mm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 3867 bytes --]

Hi Barry,

Android's memory daemon (mmd) doesn't trigger /sys/block/zram<id>/compact
today - it only handles idle writeback and recompression. Compaction can
still help during quiet periods after swap-out stops (that's the ~10 MB
zram drop after manual compact in the commit log), it just hurts active
faults when run inside the reclaim shrinker. If field data shows
fragmentation lingering when idle, triggering it from userspace (e.g. mmd)
is the cleaner place to do it.

Thanks,
Chris

On Wed, Dec 2, 2026 at 10:21 AM Barry Song <baohua@kernel.org> wrote:

> On Wed, Dec 2, 2026 at 4:14 PM Sergey Senozhatsky
> <senozhatsky@chromium.org> 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

[-- Attachment #2: Type: text/html, Size: 4591 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-02 10:21     ` Barry Song
  2026-12-02 16:17       ` Chris Wiseman
@ 2026-12-03  3:08       ` Sergey Senozhatsky
  2026-12-03  3:24         ` Barry Song
  1 sibling, 1 reply; 12+ messages in thread
From: Sergey Senozhatsky @ 2026-12-03  3:08 UTC (permalink / raw)
  To: Barry Song
  Cc: Sergey Senozhatsky, Chris Wiseman, Andrew Morton, Minchan Kim,
	Johannes Weiner, Yosry Ahmed, Nhat Pham, Chengming Zhou,
	Xueyuan Chen, Xueyuan Chen, Brian Geffon, linux-mm, linux-kernel

Hi Barry,

On (26/12/02 18:21), Barry Song wrote:
> > > 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:

Oh, my bad!

> 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?

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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-03  3:08       ` Sergey Senozhatsky
@ 2026-12-03  3:24         ` Barry Song
  2026-12-03  3:37           ` Sergey Senozhatsky
  0 siblings, 1 reply; 12+ messages in thread
From: Barry Song @ 2026-12-03  3:24 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Chris Wiseman, Andrew Morton, Minchan Kim, Johannes Weiner,
	Yosry Ahmed, Nhat Pham, Chengming Zhou, Xueyuan Chen,
	Xueyuan Chen, Brian Geffon, linux-mm, linux-kernel, Nanzhe Zhao

On Thu, Dec 3, 2026 at 11:08 AM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> Hi Barry,
>
> On (26/12/02 18:21), Barry Song wrote:
> > > > 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:
>
> Oh, my bad!
>
> > 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?
>
> 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.

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

I agree that once we remove mid-swap compaction, we should trigger
compaction from userspace, either after killing some apps or after
proactive swap-out.

Thanks,
Barry


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/zsmalloc: remove shrinker
  2026-12-03  3:24         ` Barry Song
@ 2026-12-03  3:37           ` Sergey Senozhatsky
  0 siblings, 0 replies; 12+ messages in thread
From: Sergey Senozhatsky @ 2026-12-03  3:37 UTC (permalink / raw)
  To: Barry Song
  Cc: Sergey Senozhatsky, Chris Wiseman, Andrew Morton, Minchan Kim,
	Johannes Weiner, Yosry Ahmed, Nhat Pham, Chengming Zhou,
	Xueyuan Chen, Xueyuan Chen, Brian Geffon, linux-mm, linux-kernel,
	Nanzhe Zhao

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%).


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-12-03  3:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 15:02 [PATCH] mm/zsmalloc: remove shrinker Chris Wiseman
2026-12-01 16:45 ` Nhat Pham
2026-12-01 16:53 ` Yosry Ahmed
2026-12-02  0:46 ` Xueyuan Chen
2026-12-02  2:09 ` Sergey Senozhatsky
2026-12-02  7:04 ` Barry Song
2026-12-02  8:14   ` Sergey Senozhatsky
2026-12-02 10:21     ` Barry Song
2026-12-02 16:17       ` Chris Wiseman
2026-12-03  3:08       ` Sergey Senozhatsky
2026-12-03  3:24         ` Barry Song
2026-12-03  3:37           ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox