[PATCH 5/5] mm/huge_memory: turn the swapcache-with-mapping error case into an assert
From: Kiryl Shutsemau
Date: Wed Aug 26 2026 - 12:22:30 EST
From: "Kiryl Shutsemau (Meta)" <kas@xxxxxxxxxx>
A folio in the swapcache has no mapping.
__folio_freeze_and_split_unmapped() tests the combination after the freeze
and returns -EINVAL. It leaves the folio frozen. It is not a real
recovery.
Assert the condition with VM_WARN_ON_ONCE_FOLIO() upfront, and do not
pretend to recover from an impossible state.
PG_swapcache is protected by the folio lock and stable from the start of
the function.
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Kiryl Shutsemau (Meta) <kas@xxxxxxxxxx>
---
mm/huge_memory.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 001d89c57fa2..8fc844ba67a1 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3936,6 +3936,7 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n
int ret = 0;
VM_WARN_ON_ONCE(!mapping && end);
+ VM_WARN_ON_ONCE_FOLIO(mapping && folio_test_swapcache(folio), folio);
if (!folio_ref_freeze(folio, folio_cache_ref_count(folio) + 1))
return -EAGAIN;
@@ -3965,14 +3966,8 @@ static int __folio_freeze_and_split_unmapped(struct folio *folio, unsigned int n
lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr);
}
- if (folio_test_swapcache(folio)) {
- if (mapping) {
- VM_WARN_ON_ONCE_FOLIO(mapping, folio);
- return -EINVAL;
- }
-
+ if (folio_test_swapcache(folio))
ci = swap_cluster_get_and_lock(folio);
- }
/* lock lru list/PageCompound, ref frozen by page_ref_freeze */
if (do_lru)
--
2.54.0