[PATCH 10/22] mm/khugepaged: restrict collapse to common memory
From: Gregory Price (Meta)
Date: Sat Nov 14 2026 - 02:11:41 EST
Collapse is an opportunistic MM service and should operate only on
common memory. The anonymous scan and isolation paths already filter
zone device for the same reason.
Replace the zone_device check with page_is_common_memory().
collapse_scan_file() gains a folio_is_common_memory() check. Page-cache
folios are never ZONE_DEVICE, so there it only filters memory outside
N_MEMORY_COMMON.
All memory is common at this point, so behavior is unchanged.
Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
mm/khugepaged.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 4bbe319ef86fa..b4bd29f25c145 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -628,7 +628,7 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma,
goto out;
}
page = vm_normal_page(vma, addr, pteval);
- if (unlikely(!page) || unlikely(is_zone_device_page(page))) {
+ if (unlikely(!page) || unlikely(!page_is_common_memory(page))) {
result = SCAN_PAGE_NULL;
goto out;
}
@@ -1673,7 +1673,7 @@ static enum scan_result collapse_scan_anon(struct vm_area_struct *vma,
}
page = vm_normal_page(vma, addr, pteval);
- if (unlikely(!page) || unlikely(is_zone_device_page(page))) {
+ if (unlikely(!page) || unlikely(!page_is_common_memory(page))) {
result = SCAN_PAGE_NULL;
goto out_unmap;
}
@@ -2741,6 +2741,12 @@ static enum scan_result collapse_scan_file(struct mm_struct *mm,
break;
}
+ if (unlikely(!folio_is_common_memory(folio))) {
+ result = SCAN_PAGE_NULL;
+ failed_pfn = folio_pfn(folio);
+ folio_put(folio);
+ break;
+ }
node = folio_nid(folio);
if (collapse_scan_abort(node, cc)) {
result = SCAN_SCAN_ABORT;
--
2.53.1-Meta