Re: [PATCH 1/2] mm/khugepaged: do synchronous writeback for MADV_COLLAPSE
From: Lorenzo Stoakes <hidden>
Date: 2025-11-10 22:04:10
Also in:
linux-mm, lkml
On Mon, Nov 10, 2025 at 04:56:37PM -0500, Zi Yan wrote:
On 10 Nov 2025, at 16:16, Lorenzo Stoakes wrote:quoted
OK ignore the past mail, I have managed to repro this locally and have a fix. Turns out the swap code is doing something quite insane... I will send fix-patches to the series shortly. Meanwhile I attach fix-patch! :) Cheers, Lorenzo ----8<---- From c705fd85a806f53017df31e6b072c4bfa839e3a2 Mon Sep 17 00:00:00 2001 From: Lorenzo Stoakes <redacted> Date: Mon, 10 Nov 2025 21:11:52 +0000 Subject: [PATCH] fix Signed-off-by: Lorenzo Stoakes <redacted> --- include/linux/leafops.h | 4 ++-- mm/swapfile.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-)diff --git a/include/linux/leafops.h b/include/linux/leafops.h index a464a7e08c76..c4cd36760ea0 100644 --- a/include/linux/leafops.h +++ b/include/linux/leafops.h@@ -56,7 +56,7 @@ static inline softleaf_t softleaf_from_pte(pte_t pte) { softleaf_t arch_entry; - if (pte_present(pte)) + if (pte_present(pte) || pte_none(pte)) return softleaf_mk_none(); pte = pte_swp_clear_flags(pte);@@ -95,7 +95,7 @@ static inline softleaf_t softleaf_from_pmd(pmd_t pmd) { softleaf_t arch_entry; - if (pmd_present(pmd)) + if (pmd_present(pmd) || pmd_none(pmd)) return softleaf_mk_none(); if (pmd_swp_soft_dirty(pmd))diff --git a/mm/swapfile.c b/mm/swapfile.c index fd23d9f7ae10..f0dcf261f652 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c@@ -3202,9 +3202,17 @@ static int claim_swapfile(struct swap_info_struct *si, struct inode *inode) */ unsigned long generic_max_swapfile_size(void) { - const softleaf_t entry = swp_entry(0, ~0UL); + softleaf_t entry = swp_entry(0, ~0UL); + const pte_t pte = softleaf_to_pte(entry); - return swp_offset(softleaf_from_pte(softleaf_to_pte(entry))) + 1; + /* + * Since the PTE can be an invalid swap entry (i.e. the none PTE), we doSo softleaf_from_pte() returns softleaf_mk_none() instead and causes the issue?
Yup :) fun! It's kinda crazy that on x86-64 at least we _intentionally_ generate an invalid swap entry but there we go.
quoted
+ * this manually. + */This comment is not aligned, in case you plan to send this patch as is. :)
Lol ugh, well I've split out this fix with fixes for all other raised points and plan to send a v3 of that series to make life easier. There's a bunch of conflicts that arise from the changes so that's easier for everyone.
quoted
+ entry = __pte_to_swp_entry(pte); + entry = swp_entry(__swp_type(entry), __swp_offset(entry)); + + return swp_offset(entry) + 1; } /* Can be overridden by an architecture for additional checks. */ -- 2.51.0This fix looks good to me. Thanks.
Thanks!
Best Regards, Yan, Zi
Cheers, Lorenzo