From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796454082; b=n/SpMwmispkAGZBhBrcHVuAf5wBGpFFKvSP3Whvbidjgqj9U7pGRf/P5cEwfihZlVFVx hVKBMJlVw+fVXn7rQlS05WrGN3VpMJHcJUYgT1shOaA9Ena2I51TA464fY8XkU9K3BmOM +yeVb3uUUcr+NMAE5G/WW7XH741wBqH6Z/Ha2tRe7V5VG6TAUSCg1cx0R4Adb7nTW6xJO Pitl9lnB/iVFI7DGvLAnhU9LQSGF8FnFoBMiJnCeFxteOE+nHiuy9Iz8eD6j+o+vc7ElS jqSoUnhrVUDKxaTugQiHZ/7TcLXxhtax6UOxVj3RjAvhxLTBi7KYopWpiIow5WcsQ3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796454082; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=UYtKYwxvpEXq6JZDZiv2WEZIgxkqvasNP8NKa4TvgN0=; b=HVo3YXCLdoLhxseoD27ItN/xPGeIJthQ1aVSajlS515fkahpIM1vDjdHbOhTdk6ZEmSX HjpL8emHAYjjC8FWTI1He1OSVoew8gNo3loCwDmj8JjMAGn6vzgrEY/8dKYb46Jsf5A0r KH4XzeEOv3nLj9F/tpQslw+jWrCca/UKqWMtxURDEJ4kqjr1+0wNxXlVdDu7Zxw5FyrlY 0WtZH8MVZR018KSYd2izNyBPzTzRRlGfj2rIUPj8tSAZmaAq0xsreoylqBXOlONLgYYQc CzGKkZdyeks5KBu1K1zNCA6qoiIVxq4wFN95jLlhwDbFVN44kmD0iNmGLcKc7t5BD6g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=iB+fpGwW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21295606A322; Sat, 5 Dec 2026 07:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=iB+fpGwW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EC581F0092B; Sat, 5 Dec 2026 07:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796454081; bh=UYtKYwxvpEXq6JZDZiv2WEZIgxkqvasNP8NKa4TvgN0=; h=Date:To:From:In-Reply-To:References:Subject; b=iB+fpGwWjHkRmPkwuL1Y71zcWty4v8Pnhaqta/5m0mYnmTA+7Yff3B2E6kOViO2a0 PXJuF8n7jmrdM10udmehMdIj1bwBYrMG3ysI5q7bAZg4lrRTvERXQP4VRUzjnsNLJp aY5dMiRPSTpRUlmXKZ0o7z7yyyaunqi+92bYDWZI= Date: Fri, 04 Dec 2026 23:01:21 -0800 To: mm-commits@vger.kernel.org,youngjun.park@lge.com,stable@vger.kernel.org, nphamcs@gmail.com,kasong@tencent.com,chrisl@kernel.org,baoquan.he@linux.dev, baohua@kernel.org,albinwyang@tencent.com,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261205031449.319131-1-albin_yang@163.com> References: <20261205031449.319131-1-albin_yang@163.com> Subject: + mm-swap-skip-devices-without-swp_page_discard-in-swap_sync_discard.patch added to mm-new branch Message-Id: <20261205070121.8EC581F0092B@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard() has been added to the -mm mm-new branch. Its filename is mm-swap-skip-devices-without-swp_page_discard-in-swap_sync_discard.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-swap-skip-devices-without-swp_page_discard-in-swap_sync_discard.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Wei Yang Subject: mm/swap: skip devices without SWP_PAGE_DISCARD in swap_sync_discard() Date: Sat, 5 Dec 2026 11:14:49 +0800 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. The inner check after spin_unlock() is redundant, so drop it as well. 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. Link: https://patch.msgid.link/20261205031449.319131-1-albin_yang@163.com Fixes: f9e82f99b377 ("mm/swapfile: fix list iteration when next node is removed during discard") Signed-off-by: Wei Yang Signed-off-by: Andrew Morton Reviewed-by: Barry Song Cc: Christopher Li Cc: Kairui Song Cc: Nhat Pham Cc: Baoquan He Cc: Youngjun Park Cc: mm/swapfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/swapfile.c~mm-swap-skip-devices-without-swp_page_discard-in-swap_sync_discard +++ a/mm/swapfile.c @@ -1509,10 +1509,11 @@ 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) - ret = swap_do_scheduled_discard(si); + ret = swap_do_scheduled_discard(si); put_swap_device(si); } if (ret) _ Patches currently in -mm which might be from albinwyang@tencent.com are mm-swap-skip-devices-without-swp_page_discard-in-swap_sync_discard.patch