Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Yosry Ahmed <yosry@kernel.org>, Nhat Pham <nphamcs@gmail.com>,
	Barry Song <baohua@kernel.org>,
	 Brian Geffon <bgeffon@google.com>,
	Minchan Kim <minchan@kernel.org>,
	 Richard Chang <richardycc@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Chengming Zhou <chengming.zhou@linux.dev>,
	Xueyuan Chen <xueyuan.chen21@gmail.com>,
	 Xueyuan Chen <xueyuan.chen@vivo.com>,
	Nanzhe Zhao <nzzhao@126.com>,
	linux-kernel@vger.kernel.org,  linux-block@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [RFC PATCH 0/4] zsmalloc: replace shrinker with deferred compaction
Date: Fri, 4 Dec 2026 12:51:44 +0900	[thread overview]
Message-ID: <axI4Om3xVmMSG9R7@google.com> (raw)
In-Reply-To: <20261203101411.3609533-1-senozhatsky@chromium.org>

On (26/12/03 19:13), Sergey Senozhatsky wrote:
> This is a follow-up to Chris's shrinker removal patch [1] and Barry's
> Pixel 6 fragmentation numbers [2].
> 
> Removing the shrinker avoids mid-swap compaction stalls, but without
> any automatic compaction we risk regressing memory footprint on systems
> that do not run a userspace compaction daemon, and on systems that do
> proactive swap-out without hitting memory pressure (no shrinker
> triggers).
> 
> Replace shrinker callbacks (now removed) with deferred threshold-based
> compaction in zsmalloc (plus a runtime-tunable zram sysfs knob to
> configure or disable it).
> 
> Link: https://lore.kernel.org/linux-kernel/18ed2967f99a2eff.3137322e32332e3235332e313736.2c2157.0000sendgmr@google.com [1]
> Link: https://lore.kernel.org/linux-kernel/CAGsJ_4yoogQHpxGigawTfMPEKL_A6OkfEfsmJHzDHLPS3FCUQg@mail.gmail.com [2]
> 
> Chris Wiseman (1):
>   mm/zsmalloc: remove shrinker
> 
> Sergey Senozhatsky (3):
>   zsmalloc: introduce lockless zs_class_can_compact()
>   zsmalloc: add deferred threshold compaction
>   zram: add compact_threshold sysfs attribute

And just as a follow-up, here is the current compaction timeout
exponential backoff patch, which replaces a static 10s delay with
a dynamic delay in the range of 5s to 80s.

---
 mm/zsmalloc.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 920ac07443ae..72c4152c65d7 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -42,7 +42,8 @@
 #include "zpdesc.h"
 
 #define ZSPAGE_MAGIC	0x58
-#define ZS_COMPACT_DELAY	(10 * HZ)
+#define ZS_COMPACT_DELAY		(5 * HZ)
+#define ZS_COMPACT_MAX_DEFER_SHIFT	4
 
 /*
  * This must be power of 2 and greater than or equal to sizeof(link_free).
@@ -273,6 +274,7 @@ struct zs_pool {
 
 	struct dentry *stat_dentry;
 	unsigned int compact_threshold;
+	unsigned int compact_defer_shift;
 	struct delayed_work compact_work;
 #ifdef CONFIG_COMPACTION
 	struct work_struct free_work;
@@ -2156,26 +2158,39 @@ static void async_compact_pool(struct work_struct *work)
 	struct zs_pool *pool = container_of(work, struct zs_pool,
 					    compact_work.work);
 	unsigned int threshold = READ_ONCE(pool->compact_threshold);
+	unsigned int shift = READ_ONCE(pool->compact_defer_shift);
 	unsigned long total_pages;
 	unsigned long pages_to_free;
 
-	if (!threshold || atomic_read(&pool->compaction_in_progress))
+	if (!threshold)
 		return;
 
+	if (atomic_read(&pool->compaction_in_progress))
+		goto backoff;
+
 	total_pages = zs_get_total_pages(pool);
 	if (!total_pages)
-		return;
+		goto backoff;
 
 	pages_to_free = zs_pool_can_compact(pool);
 	if ((u64)pages_to_free * 100 < (u64)total_pages * threshold)
+		goto backoff;
+
+	if (zs_compact(pool)) {
+		WRITE_ONCE(pool->compact_defer_shift, 0);
 		return;
+	}
 
-	zs_compact(pool);
+backoff:
+	if (shift < ZS_COMPACT_MAX_DEFER_SHIFT)
+		WRITE_ONCE(pool->compact_defer_shift, shift + 1);
 }
 
 static void maybe_schedule_compact(struct zs_pool *pool,
 				   struct size_class *class)
 {
+	unsigned long delay;
+
 	if (!READ_ONCE(pool->compact_threshold))
 		return;
 	if (delayed_work_pending(&pool->compact_work))
@@ -2183,8 +2198,8 @@ static void maybe_schedule_compact(struct zs_pool *pool,
 	if (!zs_class_can_compact(class))
 		return;
 
-	queue_delayed_work(system_dfl_long_wq, &pool->compact_work,
-			   ZS_COMPACT_DELAY);
+	delay = ZS_COMPACT_DELAY << READ_ONCE(pool->compact_defer_shift);
+	queue_delayed_work(system_dfl_long_wq, &pool->compact_work, delay);
 }
 
 static void init_deferred_compact(struct zs_pool *pool)
@@ -2199,6 +2214,7 @@ int zs_set_compact_threshold(struct zs_pool *pool, unsigned int threshold)
 		return -EINVAL;
 
 	WRITE_ONCE(pool->compact_threshold, threshold);
+	WRITE_ONCE(pool->compact_defer_shift, 0);
 	if (!threshold)
 		cancel_delayed_work_sync(&pool->compact_work);
 	return 0;
-- 
2.56.1.987.g2ec0ab4260-goog



      parent reply	other threads:[~2026-12-04  3:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:13 [RFC PATCH 0/4] zsmalloc: replace shrinker with deferred compaction Sergey Senozhatsky
2026-12-03 10:13 ` [RFC PATCH 1/4] mm/zsmalloc: remove shrinker Sergey Senozhatsky
2026-12-03 10:13 ` [RFC PATCH 2/4] zsmalloc: introduce lockless zs_class_can_compact() Sergey Senozhatsky
2026-12-03 10:13 ` [RFC PATCH 3/4] zsmalloc: add deferred threshold compaction Sergey Senozhatsky
2026-12-03 10:13 ` [RFC PATCH 4/4] zram: add compact_threshold sysfs attribute Sergey Senozhatsky
2026-12-04  2:55 ` [RFC PATCH 0/4] zsmalloc: replace shrinker with deferred compaction Xueyuan Chen
2026-12-04  3:49   ` Sergey Senozhatsky
2026-12-04  3:51 ` Sergey Senozhatsky [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=axI4Om3xVmMSG9R7@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=bgeffon@google.com \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=nzzhao@126.com \
    --cc=richardycc@google.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox