From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356310; b=HTeBeS4ry55Oz1jJLY/XdkEPaicUjP7YK3/Iv9kIZh/NJESQEuc12/jvwmi2x3CRIL/g fsBnvnNMVTZW/i0qPMu+vVsM8E3+mGzyDmRFeuXuXAAC2ah9HMlLRfWK24mIOpoPt/DoS 40lb17ElAFIGeODPbin9TqriI4sRqs6iPGdFNCPy+/Vg3UwqJ8tAHYTlrbsdJoxzDR6Oo P0bliE86fcG0LxtlvgrQibRTNB1Ze+qOcBWXBYJpDRgaFw7NCS0hbWTO4b9bdvL1MxHiO ViEnC+vAx4GAl6EEki3rQOTO+JZ9KMRUcAkHgfBfXvJDwgBvXYtHMEDBdBVQK46NOwA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356310; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=Lyj2+O67vSBW7GeCffjXHbE8xo1dTMJuNyR/k4r0qSc=; b=tAgCvu0HaVe9IB3R7WLuiYdaUZFScU0fPcKwnTde+/9MXoAT6UzP5HdrpN91E1Cnm5DC gm+wVbG6kWgEiZsqtX34MokgsG9FArKaGox8k/Lj2Oay0LK8td4Gfh5Jcpic2Okj2XYVI m1wOHbXIFb4jKcPITCSkdxRjCMR0mmC3tHo8XA70qy7E+fBG+xA8LjPxqRBfoUSG/haaT evWJlsHfpFk8KWMrMqZue2J6PaH2HKxfZZgB3S3I018I0O58PYk9FGzwQ1rhToofy0kol q2wWp8J8UYzyyJr/eBAFwrm/mHr50tmebYPNkTxnOYfRbbp4MxCU39ArSH6q+kn/Zzw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=T4rYJh9o; arc=none smtp.remote-ip=74.125.82.172 Received: from mail-dy1-f172.google.com (mail-dy1-f172.google.com [74.125.82.172]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1B86606A32D for ; Fri, 4 Dec 2026 03:51:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E1B86606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=T4rYJh9o Received: by mail-dy1-f172.google.com with SMTP id 5a478bee46e88-385c497bf94so1048590eec.1 for ; Thu, 03 Dec 2026 19:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796356309; x=1796961109; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Lyj2+O67vSBW7GeCffjXHbE8xo1dTMJuNyR/k4r0qSc=; b=T4rYJh9oByMooY6Jkj1e38fY6eA0NVOgjGep9MAor7FUppNpc0yMVl+5DHKVHLp6WT 1pplw+R2llt/ByZKFNyPQDW+pHOjVHX+QIgg8ChsWkpAJQOIu4PulhVBpZnbO/5p+OGu SYatsb+Hpe7qMoN4uNJcQsuUf2g/xP7cRN58M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796356309; x=1796961109; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Lyj2+O67vSBW7GeCffjXHbE8xo1dTMJuNyR/k4r0qSc=; b=tq0lnrGCdWH7K+SWD3DJgJxkF/eaAmNPUHDBN2Q+vQY9e8y1UR9L7xiqIDBjI2zgZN 6R6KOpxpJNZOnwdMb+wbh26FkDlw1ftoln3gVSWXfaM8qVpRpkSkCpMt8ebq1RxGmztF dJxc1DhIwAu8CootSoKn/xHueWo2QNTC/BZcDQgF+p0zBODd1bORzLwvaYORjl/41x8Z K3PLj3pivVV8l+QLdPmuEH+Rxnz+RZEU6jRNKxpuWAgJkTeWRFoOkwM2O0cnopMPsU3W z4yBqjpXx91hSuXNU2qkYvlIXUNHBQiBoXVXxeYGDHz0fLNpX/tj2Aff4XcANJNZ45qm xh+w== X-Forwarded-Encrypted: i=1; AL+hErEJGiRZFF+QX67ZfBBoXJGP8yKnl5tSAiv4DB63TAXbQ377h2UD8OfohFg+vILu9JBfSbqSX/DOuokb5Q==@vger.kernel.org X-Gm-Message-State: APuU4Z8IGW1ltR+SV8Veu3hNBnODvrPlBlw81+8BdLWa+oMnjxRb3t1Z kpREsLsu/L+FH7tiHZQAmxyUZfbKW1Jtuq7iHyb2MkxdQjMxvP5MaJNLvsg9Z1kG1w== X-Gm-Gg: AZFdTZdgbnSEOWK8Z1TFkL9048hhShPmvAnw+KhjWdk7INxK3NZ6uevAsjipGvb9qie Fg3lci7KuDT6rFdzhL8YpL9dOiEeg9xMnUopZVCXGfH9IPwjpjvvDdaPKPFQScUWhjldWFGugO5 5VKYwrMWnlNZMhPu5GMZSLbgGFDT1zMyAYo/aRBK2ysQ4+e9H01kdHneRfvZyzjmAOvZCmGxK8e /peuwLW6nZZqZVyYzDKHA2KvlfghPqYG9PyUR+CpUQFUw6lxopaRqnryqCxy4rKqcJEP7Nfugug vn7uVvyjFiVuGiBbCW7s07S6oBRNmut12JdLtNEvgKoWvKYbhqGv0iR7BF8qTJ6hM6rQk1SuAvC BtsTVWYE3HA8RRNjrmkDsZZA6djsppW6XY/5uCBEr6EZdrricTkscSFjscClhSAXCYu0NEf3yHn aGVpClu6Ef3eBfaNo46ihFxBFRQNh+cYb2Vaany+hBZl9FDy9RTQ4DxcARwsTGHpLalK29ndki2 A08mf17N5TysXT408wBrnsuJ2QqX4Qm1tV9QBg3Ne/C6LYWHYSgAtu5yvxcXwRZ/e7QDce7CmTK OWrbCDsBMF8N2WfCU6H1MaeyRYjD9aQmYRPowVoByqfHlCTpRbdOBJ4DWs6bmejEUsqp X-Received: by 2002:a05:7301:6198:b0:386:954f:7c18 with SMTP id 5a478bee46e88-387521e5467mr726778eec.31.1796356308858; Thu, 03 Dec 2026 19:51:48 -0800 (PST) Received: from google.com ([2a00:79e0:2031:6:b1d8:8dc2:95bf:66b9]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521c102esm2519587eec.13.2026.12.03.19.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 19:51:48 -0800 (PST) Date: Fri, 4 Dec 2026 12:51:44 +0900 From: Sergey Senozhatsky To: Sergey Senozhatsky Cc: Andrew Morton , Yosry Ahmed , Nhat Pham , Barry Song , Brian Geffon , Minchan Kim , Richard Chang , Johannes Weiner , Chengming Zhou , Xueyuan Chen , Xueyuan Chen , Nanzhe Zhao , 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 Message-ID: References: <20261203101411.3609533-1-senozhatsky@chromium.org> X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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