Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: sashiko-reviews@lists.linux.dev
Cc: 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>,
	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: Sun, 6 Dec 2026 15:06:23 +0900	[thread overview]
Message-ID: <axT6b0lHm44DuS7D@google.com> (raw)
In-Reply-To: <sashiko-outbox-249581@kernel.org>

On (26/12/04 10:14), sashiko-bot@kernel.org wrote:
> > 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.

Ditto.  These claims better be supported by evidence.
I can run some benchmarks

> 
> [ ... ]
> 
> > @@ -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.

No.  Release of a whole zspage is not considered a fragmentation event.

> [ ... ]
> 
> > +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.

I'd say no.  There is an exported API to trigger a compaction right
after threshold adjustment.

> > +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.

Maybe.


  reply	other threads:[~2026-12-06  6:06 UTC|newest]

Thread overview: 15+ 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-06  5:57     ` 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-04 10:14   ` sashiko-bot
2026-12-06  6:06     ` Sergey Senozhatsky [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-06  6:37     ` 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=axT6b0lHm44DuS7D@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-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=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