[PATCH RFC 13/32] mm/khugepaged: consider workingset folios as referenced
From: Kairui Song via B4 Relay
Date: Fri May 01 2026 - 17:09:32 EST
From: Kairui Song <kasong@xxxxxxxxxxx>
The folio_test_referenced check here is clearly trying to test if the
folio was ever referenced. It was first introduced by commit
8ee53820edfd ("thp: mmu_notifier_test_young") as an supplement of the
young bit check.
Folios are marked as PG_referenced on first access, but following access
will clear their PG_referenced on second access. So checking only the referenced
flag is not accurate enough.
Switch to use the new helper, so we can cover the secondary and following
access from MGLRU side. For non-MGLRU, this will make it return positve
for workingset folios too, which should be OK.
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/khugepaged.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 7d48d4fbd5f3..af9217e19eac 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -815,7 +815,7 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma,
*/
if (cc->is_khugepaged &&
(pte_young(pteval) || folio_test_young(folio) ||
- folio_test_referenced(folio) ||
+ folio_is_referenced(folio) ||
mmu_notifier_test_young(vma->vm_mm, addr)))
referenced++;
}
@@ -1743,7 +1743,7 @@ static enum scan_result collapse_scan_pmd(struct mm_struct *mm,
*/
if (cc->is_khugepaged &&
(pte_young(pteval) || folio_test_young(folio) ||
- folio_test_referenced(folio) ||
+ folio_is_referenced(folio) ||
mmu_notifier_test_young(vma->vm_mm, addr)))
referenced++;
}
@@ -2729,7 +2729,7 @@ static enum scan_result collapse_scan_file(struct mm_struct *mm,
/*
* We probably should check if the folio is referenced
* here, but nobody would transfer pte_young() to
- * folio_test_referenced() for us. And rmap walk here
+ * folio_is_referenced() for us. And rmap walk here
* is just too costly...
*/
--
2.54.0