From: Xueyuan Chen <xueyuan.chen21@gmail.com>
To: nphamcs@gmail.com
Cc: ryncsn@gmail.com, haowenchao22@gmail.com,
akpm@linux-foundation.org, chengming.zhou@linux.dev,
axboe@kernel.dk, hannes@cmpxchg.org, minchan@kernel.org,
senozhatsky@chromium.org, yosry@kernel.org,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, baohua@kernel.org, xueyuan.chen21@gmail.com,
haowenchao@xiaomi.com
Subject: Re: [RFC PATCH v2 0/4] mm/zsmalloc: reduce zs_free() latency on swap release path
Date: Wed, 22 Apr 2026 08:34:12 +0800 [thread overview]
Message-ID: <20260422003412.11678-1-xueyuan.chen21@gmail.com> (raw)
In-Reply-To: <CAKEwX=P6L=CeJCXkC+cKbZKYk_ORho3pLy476c8=BbDianx=vg@mail.gmail.com>
On Tue, Apr 21, 2026 at 11:25:17AM -0700, Nhat Pham wrote:
[...]
>Hmm, free_zspage() and kmem_cache_free().
>
>* kmem_cache_free() is just handle freeing. Bulk-freeing?
>
>* free_zspage() looks like just ordinary teardown work :( Seems like
>we're not spinning any lock here - we just try lock the backing pages,
>and the rest is normal work. Not sure how to optimize this - perhaps
>deferring is the only way.
>
>
Hi Nhat,
Currently, free_zspage() is called while holding the class->lock.
However, free_zspage() eventually invokes folio_put(), which may acquire
the zone->lock.
This creates a nested lock dependency. If multiple CPUs contend for the
same class->lock and the current holder is stalled waiting for the
zone->lock, it significantly extends the hold time of the class->lock.
This causes other CPUs to wait much longer.
Here is the ftrace data showing the severe contention on class->lock.
Under contention, the time spent in queued_spin_lock_slowpath() jumps
from ~1.3us to over 30us, significantly increasing the total latency
of zs_free().
7) | zs_free() {
7) 0.220 us | _raw_read_lock();
7) | _raw_spin_lock() {
7) 1.320 us | queued_spin_lock_slowpath();
7) 1.820 us | }
7) 0.170 us | _raw_read_unlock();
7) 0.170 us | obj_free();
7) 0.190 us | fix_fullness_group();
7) 0.150 us | _raw_spin_unlock();
7) 0.170 us | kmem_cache_free();
7) 4.610 us | }
---------------------------------------------------------
7) | zs_free() {
7) 0.230 us | _raw_read_lock();
7) | _raw_spin_lock() {
7) + 30.100 us | queued_spin_lock_slowpath();
7) + 30.600 us | }
7) 0.200 us | _raw_read_unlock();
7) 0.170 us | obj_free();
7) 0.170 us | fix_fullness_group();
7) 0.170 us | _raw_spin_unlock();
7) 0.210 us | kmem_cache_free();
7) + 33.850 us | }
Best regards,
Xueyuan
prev parent reply other threads:[~2026-04-22 0:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 12:16 Wenchao Hao
2026-04-21 12:16 ` [RFC PATCH v2 1/4] mm:zsmalloc: drop class lock before freeing zspage Wenchao Hao
2026-04-21 12:16 ` [RFC PATCH v2 2/4] mm/zsmalloc: introduce zs_free_deferred() for async handle freeing Wenchao Hao
2026-04-21 19:46 ` Nhat Pham
2026-04-21 21:42 ` Barry Song
2026-04-21 12:16 ` [RFC PATCH v2 3/4] zram: defer zs_free() in swap slot free notification path Wenchao Hao
2026-04-21 12:16 ` [RFC PATCH v2 4/4] mm/zswap: defer zs_free() in zswap_invalidate() path Wenchao Hao
2026-04-21 17:03 ` Nhat Pham
2026-04-21 15:54 ` [RFC PATCH v2 0/4] mm/zsmalloc: reduce zs_free() latency on swap release path Nhat Pham
2026-04-21 17:17 ` Kairui Song
2026-04-21 18:07 ` Nhat Pham
2026-04-21 18:25 ` Nhat Pham
2026-04-22 0:34 ` Xueyuan Chen [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=20260422003412.11678-1-xueyuan.chen21@gmail.com \
--to=xueyuan.chen21@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=baohua@kernel.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=haowenchao22@gmail.com \
--cc=haowenchao@xiaomi.com \
--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=ryncsn@gmail.com \
--cc=senozhatsky@chromium.org \
--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