From: sashiko-bot@kernel.org
To: "Sergey Senozhatsky" <senozhatsky@chromium.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Yosry Ahmed" <yosry@kernel.org>, "Nhat Pham" <nphamcs@gmail.com>,
"Barry Song" <baohua@kernel.org>
Cc: "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-mm@kvack.org
Subject: Re: [RFC PATCH 3/4] zsmalloc: add deferred threshold compaction
Date: Fri, 04 Dec 2026 10:14:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-249581@kernel.org> (raw)
In-Reply-To: <20261203101411.3609533-4-senozhatsky@chromium.org>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] zsmalloc: zs_set_compact_threshold() never schedules
compaction on idle pool
- [Medium] zsmalloc: freeing whole zspages shrinks total_pages without
scheduling compact
- [Medium] zsmalloc: false sharing between pages_allocated and
compact_threshold/work
- [Low] zsmalloc: zs_set_compact_threshold() lacks kernel-doc and
changelog coverage
--
commit 6c8a6f9143072a471636aef6ee685db38822eec1
Author: Sergey Senozhatsky <senozhatsky@chromium.org>
zsmalloc: add deferred threshold compaction
This commit adds per-pool delayed compaction work queued after partial
zs_free() calls to compact pools whose reclaimable pages exceed a
configurable percentage threshold. It also exports
zs_set_compact_threshold() to adjust or disable the threshold at runtime.
Link: https://lore.kernel.org/linux-kernel/CAGsJ_4yoogQHpxGigawTfMPEKL_A6OkfEfsmJHzDHLPS3FCUQg@mail.gmail.com [1]
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index c0bad8214853f..6c9211d1fae09 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
[ ... ]
> @@ -276,6 +278,8 @@ struct zs_pool {
> struct zs_pool_stats stats;
>
> struct dentry *stat_dentry;
> + unsigned int compact_threshold;
> + struct delayed_work compact_work;
> #ifdef CONFIG_COMPACTION
> struct work_struct free_work;
> #endif
[Severity: Medium]
Can placing compact_threshold and compact_work here cause cacheline false
sharing with pages_allocated on 64-bit 8K, 16K, and 64K page kernels?
On those configurations ZS_SIZE_CLASSES is 256 (8K) or 257 (16K/64K),
putting pages_allocated, compact_threshold, and compact_work.work.data in
the same 64-byte cacheline (offsets 2048..2111).
Every partial zs_free() now reads compact_threshold and
compact_work.work.data via maybe_schedule_compact(), bouncing that
cacheline against concurrent atomic updates to pages_allocated in
zs_store() and full-zspage zs_free() even when compact_threshold is 0.
Aligning compact_threshold and compact_work (or pages_allocated) to a
separate cacheline would avoid the contention.
[ ... ]
> @@ -1498,6 +1505,10 @@ void zs_free(struct zs_pool *pool, struct zs_handle *handle)
> __free_zspage_lockless(zspage_to_free);
> atomic_long_sub(class->pages_per_zspage, &pool->pages_allocated);
> }
> +
> + /* Created a hole in a partial zspage, check if compaction is needed */
> + if (fullness != ZS_INUSE_RATIO_0)
> + maybe_schedule_compact(pool, class);
> }
[Severity: Medium]
Can skipping maybe_schedule_compact() when fullness == ZS_INUSE_RATIO_0
leave pool fragmentation above compact_threshold indefinitely?
async_compact_pool() checks the pool-wide ratio pages_to_free * 100 >=
total_pages * threshold, so freeing whole zspages shrinks total_pages and
can push existing waste in other classes above the threshold.
If fragmented non-huge classes sit below 5% alongside many huge-class
objects (objs_per_zspage == 1), freeing the huge objects always hits
ZS_INUSE_RATIO_0 and never queues compact_work; maybe_schedule_compact()
only checks the freed class anyway, stranding pages until a partial free.
[ ... ]
> +int zs_set_compact_threshold(struct zs_pool *pool, unsigned int threshold)
> +{
> + if (WARN_ON_ONCE(threshold >= 100))
> + return -EINVAL;
> +
> + WRITE_ONCE(pool->compact_threshold, threshold);
> + if (!threshold)
> + cancel_delayed_work_sync(&pool->compact_work);
> + return 0;
> +}
[Severity: Medium]
Should zs_set_compact_threshold() schedule compact_work when enabling or
lowering threshold on an already-fragmented pool?
Because maybe_schedule_compact() is only called from partial zs_free(),
enabling deferred compaction (0 to non-zero) or tightening the threshold
on an idle pool leaves existing fragmentation above the new threshold
indefinitely until a future partial free happens.
> +EXPORT_SYMBOL_GPL(zs_set_compact_threshold);
[Severity: Low]
Should zs_set_compact_threshold() have a kernel-doc comment documenting
its parameter semantics (0 disables, 1..99 is the pool-wide percentage,
>= 100 returns -EINVAL) and its sleeping contract?
When threshold is 0, cancel_delayed_work_sync() sleeps and cannot be
called from atomic context or while holding locks taken by
async_compact_pool(). The commit message also omits the new
zs_set_compact_threshold() API and ZS_DEFAULT_COMPACT_THRESHOLD constant.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203101411.3609533-1-senozhatsky@chromium.org?part=3
next prev parent reply other threads:[~2026-12-04 10:14 UTC|newest]
Thread overview: 12+ 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-04 10:14 ` sashiko-bot
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-04 10:14 ` sashiko-bot [this message]
2026-12-03 10:13 ` [RFC PATCH 4/4] zram: add compact_threshold sysfs attribute Sergey Senozhatsky
2026-12-04 10:14 ` sashiko-bot
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
2026-12-05 8:57 ` Nanzhe Zhao
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=sashiko-outbox-249581@kernel.org \
--to=sashiko-bot@kernel.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-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=nphamcs@gmail.com \
--cc=nzzhao@126.com \
--cc=richardycc@google.com \
--cc=sashiko-reviews@lists.linux.dev \
--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.