[PATCH RFC 12/32] mm/huge_memory: mark file folio as accessed more accurately on split

From: Kairui Song via B4 Relay

Date: Fri May 01 2026 - 17:07:56 EST


From: Kairui Song <kasong@xxxxxxxxxxx>

The behavior of updating the folio's access info isn't consistent for
huge mapping splitting or ordinary unmapping. Actually right now, there
is no huge mapping splitting for such folios, we simply unmap it, so the
page table's young flag has to be translated into folio's access info.

Right now it only check and set folio's referenced flag, which isn't
enough since folio flags update on access have its rules. For example,
ordinary unmapping (zapping) calls folio_mark_accessed(), and it also
checks if the VMA has recency to avoid false updates.

So use the right helper here and be consistent.

Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
mm/huge_memory.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 1f0d0b780943..87a2640e3396 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3023,8 +3023,8 @@ static void __split_huge_pud_locked(struct vm_area_struct *vma, pud_t *pud,

if (!folio_test_dirty(folio) && pud_dirty(old_pud))
folio_mark_dirty(folio);
- if (!folio_test_referenced(folio) && pud_young(old_pud))
- folio_set_referenced(folio);
+ if (pud_young(old_pud) && vma_has_recency(vma))
+ folio_mark_accessed(folio);
folio_remove_rmap_pud(folio, page, vma);
folio_put(folio);
add_mm_counter(vma->vm_mm, mm_counter_file(folio),
@@ -3141,8 +3141,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
folio = page_folio(page);
if (!folio_test_dirty(folio) && pmd_dirty(old_pmd))
folio_mark_dirty(folio);
- if (!folio_test_referenced(folio) && pmd_young(old_pmd))
- folio_set_referenced(folio);
+ if (pmd_young(old_pmd) && vma_has_recency(vma))
+ folio_mark_accessed(folio);
folio_remove_rmap_pmd(folio, page, vma);
folio_put(folio);
}

--
2.54.0