From: Kairui Song <ryncsn@gmail.com>
To: albin_yang@163.com
Cc: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com,
nphamcs@gmail.com, shikemeng@huaweicloud.com,
baoquan.he@linux.dev, baohua@kernel.org, youngjun.park@lge.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
albinwyang@tencent.com
Subject: Re: [PATCH] mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard()
Date: Fri, 4 Dec 2026 01:15:20 +0800 [thread overview]
Message-ID: <axGdI7_BgsQhC54b@KASONG-MC4> (raw)
In-Reply-To: <20261128134810.3203203-1-albin_yang@163.com>
On Sat, Nov 28, 2026 at 09:48:10PM +0800, albin_yang@163.com wrote:
> From: Wei Yang <albinwyang@tencent.com>
>
> swap_sync_discard() walks swap_active_head and, for every device, drops
> and re-takes the global swap_lock and does a get/put_swap_device()
> round trip. A device without SWP_PAGE_DISCARD can never make this
> function return true, because swap_do_scheduled_discard() is only
> reached under that flag. For such devices all of that work is pure
> overhead.
>
> Skip them without dropping swap_lock. A skipped device cannot affect
> ret or any global state, so folio_alloc_swap() behaves identically.
> Holding the lock keeps 'next' on the list (plist_del() takes the same
> lock), so the plist_node_empty() re-check below is unnecessary here;
> visited devices still unlock/relock and re-validate as before.
> SWP_PAGE_DISCARD is only set or cleared at swapon/swapoff time.
>
> We backported the upstream swap sync-discard changes into our 6.6-based
> kernel. LTP/stress-ng swap stress testing then drove swap 100% full
> and triggered a hung_task panic: the vmcore showed 17 of 256 CPUs
> spinning on swap_lock here, with 25 active devices and none carrying
> SWP_PAGE_DISCARD, while the mmap_read_lock holder starved on block
> tags.
>
> With swap full, each failed folio_alloc_swap() on an order-0,
> non-swapcache folio walks all N devices, costing 1+N+N+1 global
> swap_lock operations plus N get/put round trips. The walk is over
> swap_active_head, so an empty avail list no longer lets it exit early.
> The same code is present in current mainline.
>
> 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.
>
> Fixes: 9fb749cd1507 ("mm, swap: do not perform synchronous discard during allocation")
Hi, Thanks for the report and fix!
Maybe should be f9e82f99b377? The per-device lock churn came from 9fb749cd1507, but
that version walked swap_avail_head, and full devices are removed from it, so with
swap 100% full it iterated zero times. The reported hang needs the
start_over/plist_node_empty() restart that f9e82f99b377 added IIUC.
And maybe need Cc stable?
prev parent reply other threads:[~2026-12-03 17:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 13:48 [PATCH] mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard() albin_yang
2026-12-03 17:15 ` Kairui Song [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=axGdI7_BgsQhC54b@KASONG-MC4 \
--to=ryncsn@gmail.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=shikemeng@huaweicloud.com \
--cc=youngjun.park@lge.com \
/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