mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Youngjun Park <youngjun.park@lge.com>
To: albin_yang@163.com
Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com,
	nphamcs@gmail.com, baoquan.he@linux.dev, baohua@kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	albinwyang@tencent.com, stable@vger.kernel.org
Subject: Re: [PATCH v2] mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard()
Date: Fri, 4 Dec 2026 13:52:06 +0900	[thread overview]
Message-ID: <axJG9m93sTXfrYmU@yjaykim-PowerEdge-T330> (raw)
In-Reply-To: <20261204024446.3612318-1-albin_yang@163.com>

On Fri, Dec 04, 2026 at 10:44:46AM +0800, albin_yang@163.com wrote:
> From: Wei Yang <albinwyang@tencent.com>

Hi Wei

> Measured on v7.4-rc4, strictly paired on the same machine (26 x 256MB
> swap devices, 16 concurrent workers, 512MB MADV_PAGEOUT chunks, swap
> 100% full), unpatched vs patched:
> 
>   folio_alloc_swap avg      32.745 us  ->  1.505 us   (21.8x)
>   allocations in 30s         916,734   ->  6,216,609  (6.8x)
>   per-page                   30.2 us   ->  4.0 us     (7.6x)
>   spinlock slowpath/alloc     27.1     ->  1.87       (14.5x lower)
> 
> The per-allocation cost used to grow linearly with the device count
> and is now independent of it.
> 
> Semantics are unchanged: swap stayed 100% full in both runs, so
> allocation outcomes were identical, and swap_do_scheduled_discard()
> had 0 hits.  A separate test with 25 no-flag devices plus one enabled
> with --discard=pages confirmed that flag-bearing devices still take
> the original path: swap_do_scheduled_discard() was called once per
> folio_alloc_swap() call, with no hung tasks or regression.

Looking at your use case, there seems to be no discard device at all.

What about counting SWP_PAGE_DISCARD devices like nr_rotate_swap, so we
can skip the walk (and swap_lock) entirely when it's zero? Might be a
bit local, but swap on discard devices isn't that common.
It is just opinion for curios about your thought. no serious consideration plz :)

> Fixes: f9e82f99b377 ("mm/swapfile: fix list iteration when next node is removed during discard")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wei Yang <albinwyang@tencent.com>
> ---
> Changes in v2:
>   - Point Fixes at f9e82f99b377 (Kairui Song)
>   - Add Cc: stable (Kairui Song)
> 
> v1: https://lore.kernel.org/r/20261128134810.3203203-1-albin_yang@163.com
> 
>  mm/swapfile.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 226230dda0aa..e553bd2c20a7 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1509,6 +1509,8 @@ static bool swap_sync_discard(void)
>  	spin_lock(&swap_lock);
>  start_over:
>  	plist_for_each_entry_safe(si, next, &swap_active_head, list) {
> +		if (!(si->flags & SWP_PAGE_DISCARD))
> +			continue;
>  		spin_unlock(&swap_lock);
>  		if (get_swap_device_info(si)) {
>  			if (si->flags & SWP_PAGE_DISCARD)

This inner check should be redundant now, right? Can we drop it?

Thanks,
Youngjun

  reply	other threads:[~2026-12-04  4:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:44 albin_yang
2026-12-04  4:52 ` Youngjun Park [this message]
2026-12-05  2:55   ` albin_yang

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=axJG9m93sTXfrYmU@yjaykim-PowerEdge-T330 \
    --to=youngjun.park@lge.com \
    --cc=akpm@linux-foundation.org \
    --cc=albin_yang@163.com \
    --cc=albinwyang@tencent.com \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®