From: Kairui Song 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 --- 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 d3f0c29ac340..65bf16503b8b 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -797,6 +797,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 4fc888ddfb69..7c535d3bc501 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 82e1ec8e44e7..a6b15a4b7ca9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1761,8 +1761,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