[PATCH v8 15/19] mm: factor out folio_mark_accessed_vma()

From: Kairui Song via B4 Relay

Date: Thu Dec 03 2026 - 12:04:16 EST


From: Kairui Song <kasong@xxxxxxxxxxx>

The zap paths translate a young page table entry into folio hotness with
folio_mark_accessed(), but only for a VMA with recency: vma_has_recency()
is false for VM_SEQ_READ, VM_RAND_READ and FMODE_NOREUSE areas, where an
access carries no recency info by definition. [1]

Factor that rule out into folio_mark_accessed_vma(), so it lives in one
place instead of in every page table walk that feeds the LRU, and convert
the two zap paths. The huge mapping split paths will follow.

No functional change.

Link: https://lore.kernel.org/linux-mm/awXABa3dYhEN0YEt@KASONG-MC4/ [1]
Signed-off-by: Kairui Song <kasong@xxxxxxxxxxx>
---
include/linux/mm_inline.h | 12 ++++++++++++
mm/huge_memory.c | 5 ++---
mm/memory.c | 4 ++--
3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
index 799082111e8a..11fb6001d795 100644
--- a/include/linux/mm_inline.h
+++ b/include/linux/mm_inline.h
@@ -792,6 +792,18 @@ static inline bool vma_has_recency(const struct vm_area_struct *vma)

return true;
}
+
+/*
+ * Mark a folio accessed if the VMA has recency: accesses to a VM_SEQ_READ,
+ * VM_RAND_READ or FMODE_NOREUSE mapping do not predict reuse, so bumping
+ * the folio's LRU refs for them may even hurt the performance.
+ */
+static inline void folio_mark_accessed_vma(struct folio *folio,
+ const struct vm_area_struct *vma)
+{
+ if (likely(vma_has_recency(vma)))
+ folio_mark_accessed(folio);
+}
#endif

/**
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 129e37e2db3e..415df65c14bd 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2525,9 +2525,8 @@ static void zap_huge_pmd_folio(struct mmu_gather *tlb, struct vm_area_struct *vm
mapping_can_writeback(vma->vm_file->f_mapping))
delay_rmap = tlb_can_delay_rmap();
}
- if (is_present && pmd_young(pmdval) &&
- likely(vma_has_recency(vma)))
- folio_mark_accessed(folio);
+ if (is_present && pmd_young(pmdval))
+ folio_mark_accessed_vma(folio, vma);
}

if (!is_present && !is_device_private)
diff --git a/mm/memory.c b/mm/memory.c
index 90fc7c395124..94b0b1921f54 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1762,8 +1762,8 @@ static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb,
*force_flush = true;
}
}
- if (pte_young(ptent) && likely(vma_has_recency(vma)))
- folio_mark_accessed(folio);
+ if (pte_young(ptent))
+ folio_mark_accessed_vma(folio, vma);
rss[mm_counter(folio)] -= nr;
} else {
/* We don't need up-to-date accessed/dirty bits. */

--
2.56.1