All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,yosry@kernel.org,xueyuan.chen@vivo.com,
	xueyuan.chen21@gmail.com,senozhatsky@chromium.org,nphamcs@gmail.com,
	minchan@kernel.org,hannes@cmpxchg.org,chengming.zhou@linux.dev,
	bgeffon@google.com,baohua@kernel.org,chriswiseman@google.com,
	akpm@linux-foundation.org
Subject: + mm-zsmalloc-remove-shrinker.patch added to mm-new branch
Date: Tue, 01 Dec 2026 18:22:53 -0800	[thread overview]
Message-ID: <20261202022253.6D4BF1F000C1@smtp.kernel.org> (raw)
In-Reply-To: <18ed2967f99a2eff.3137322e32332e3235332e313736.2c2157.0000sendgmr@google.com>


The patch titled
     Subject: mm/zsmalloc: remove shrinker
has been added to the -mm mm-new branch.  Its filename is
     mm-zsmalloc-remove-shrinker.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-zsmalloc-remove-shrinker.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

The mm-new branch of mm.git is not included in linux-next

If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Chris Wiseman <chriswiseman@google.com>
Subject: mm/zsmalloc: remove shrinker
Date: Tue, 01 Dec 2026 15:02:30 +0000

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://patch.msgid.link/18ed2967f99a2eff.3137322e32332e3235332e313736.2c2157.0000sendgmr@google.com
Link: https://lore.kernel.org/cover.1786003779.git.xueyuan.chen@vivo.com
Signed-off-by: Chris Wiseman <chriswiseman@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Suggested-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Suggested-by: Yosry Ahmed <yosry@kernel.org>
Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Xueyuan Chen <xueyuan.chen21@gmail.com>
Reviewed-by: Nhat Pham <nphamcs@gmail.com>
Acked-by: Yosry Ahmed <yosry@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Xueyuan Chen <xueyuan.chen@vivo.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Brian Geffon <bgeffon@google.com>

 mm/zsmalloc.c |   76 ------------------------------------------------
 1 file changed, 76 deletions(-)

--- a/mm/zsmalloc.c~mm-zsmalloc-remove-shrinker
+++ a/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,
 }
 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 cha
 	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 cha
 	/* 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 *poo
 {
 	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 *poo
 		kfree(class);
 	}
 
-	kfree(pool->name);
 	kfree(pool);
 }
 EXPORT_SYMBOL_GPL(zs_destroy_pool);
_

Patches currently in -mm which might be from chriswiseman@google.com are

percpu-skip-sidelined-slot-in-pcpu_balance_populated.patch
mm-zsmalloc-remove-shrinker.patch


      parent reply	other threads:[~2026-12-02  2:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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  2:22 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202022253.6D4BF1F000C1@smtp.kernel.org \
    --to=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=bgeffon@google.com \
    --cc=chengming.zhou@linux.dev \
    --cc=chriswiseman@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=minchan@kernel.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=xueyuan.chen21@gmail.com \
    --cc=xueyuan.chen@vivo.com \
    --cc=yosry@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.