[PATCH RFC 14/15] mm/khugepaged: consider workingset folios as referenced
Kairui Song <[email protected]> Tue, 04 Aug 2026 03:47:10 +0800
| Newsgroups | org.kernel.feeds.b4-sent,org.kernel.vger.cgroups,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
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 though, which should be OK.
Signed-off-by: Kairui Song <[email protected]>
---
mm/khugepaged.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b237f6e7662a..86c9b07dece6 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -809,7 +809,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++;
}
@@ -1767,7 +1767,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++;
}
@@ -2752,7 +2752,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.55.0