From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356310; b=jADYHpXL/1xwj9KDNWd3qwU1qVhsxsNevMiX08b+pqsCLwLseg0795P5KpehxaM68fCl Q/Cq4FDR3V0WE0UAFVz2kbZFeUOkMkFV617Mk53U0JZbS5txgYBS/YyNY6rUpG4Lpl+Fy p4ruNrtUbmsSOmduJ93OBki7zyVeHR1j/4ttOJe/9oeyrc2MFfaFp7mImlFzj7z1UAZfh AVUKmSL5Ms2ggK01YSuXmHFHQRWPFtupiBO+laUfIQO1eZzNmsGoYcVZ/Yy+lgo645mWE E3+PFSKyf56vt/XnhTVeDVNWX6t/xGX0C73SN6ULfRksqVWRWj2kIUSYgG+MsSTkrJg== 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=Ftpre96P23HDknqLctaihOrtcTgLBFGw1Onk21JBQSdhnKuN3tCSy7eidaROc5EZzqPM uKin4y2imbVUNb60zCywV3+C6UlIPs5I9YUY+G4b/Nlenv3GAdTsRuXxXxuGmyNGAUuvp WSMVX8ygV8noXvEq8J1EpX4whExTgq2jhI1AjAk9qmIsDDReVtY6W5XtkHXj/xhpjOzjn R3oIQ+d1ww1xuinOTQzvau532mqmgMp/auAbd9QH5qLJH1W5RbUObwlsQjGkHF+3NxA3o 324YWW8xBis5/x3jjlAIOP8wnM1c6CwP1AnvFjIDv82mwSb1CXsyp4bryKOtbOpZ7oQ== 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.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 E45ED606A32F for ; Fri, 4 Dec 2026 03:51:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E45ED606A32F 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-f182.google.com with SMTP id 5a478bee46e88-38692f62b22so1010675eec.0 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=ACYNWgf7kAQh5uYNtAoplyR0epIcEujWev3MLjx0oK6wvu05iJoNQ7VqqhXGUfR1uB CNDdMoBYmzM1Z2iUK23iNHIdcYisUztd9xgl0Kbw4dAzCBemilUjVHn5BHb64+ZluaMy 5XsNZvqnZXENhE2v3TKEVba6ZqEh2G+8sHEszOzOaVGX10yUF5i52VZUB1X452/YtMsL WczwP6lYlLDPA4hOaeDuCDFbIukqf9IdnBYAthkSyrANSaTqk7X9Rl6SgWR7mUOdn9iN iuQ+NM2WPwtlaVeNbvwKxweOP9Ve+ws834ahXGaCOTlFqQEzaqsMrMlDBCiEEOIy4tif 34yA== X-Forwarded-Encrypted: i=1; AL+hErGR7uI+WTr6JKrplvbt7m1Th6nNiWTLqLKork92ZCePecxMP5928reN8VCCxU3C8n8wa6vbdwr1RhQMi9w=@vger.kernel.org X-Gm-Message-State: APuU4Z/hfihVWCj2y7qL7AC67hOHpR5SKtAbQJMwhqYv9bQTAtLe6OeE T5yd0kL7MM0CmhE4DidN1f2N1zkY8VnKIKor8q+SzS+TU8dMt9g2kwa5LQgNycLOVA== X-Gm-Gg: AZFdTZe4K/btfcWwdOg4aKlYIlIPM5xXaRMij8y1vvwEvjvTcwzw5YkT6dHW9Sr0hPW SoHdCCind+gQ17NnXWvpb1OxdEOy+Quruej71mjBm/LQYbrAQAcHIQlvcdPAPZ52RSVEWUN82WQ wT9/xmRmEGg0bespYjlMwUNACoX5c6Ig3Ij627bJJQkHIkMb/EAqR6Yr7SP3/yDfDwSSR7KzkNp Cw+mVdRhPIxhMGE5CiL9SHgjJFaSIvRfme5NxLU6g4M7cbCkA+uQwUv3ClFRX4qm/GkgaHYSaiC c5H5wFypTmpQdrPqzkVc/fsGhK7AAi5MPIocC3pDIZFjBocilb5cnhRHG/vF89DSID4mi1sT+0Z QjjZmWX6I1dqG5mEHYytDXP6Cz+Oj2lsRmMPBu+Y4xINYDhHmQ+tb5JDyCnFtGSi3/rHpDg+5sD iZk6o1vi11Bvp14yqtMvSOMtblJNbPJfatRoH1Qo5hrCUF5+Y2Fwml0AIIqZoKHyuJW9C9Oj9uk htSXuIefxqCChEW3dEk9NV0/alz0aDYayaGjtYMaIre8eHIi6Swx0ffR1vO2yf9kDPRfmc7wLrx cvl/K1n44ohNZreO9G4TsiOHm8aFOQZVc6hrbb6TgF0jAyiFmb8mSAkYd1t0OCtxeXpB 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-kernel@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