linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: huge_memory: add folio_mark_accessed() when zapping file THP
@ 2025-04-09  9:38 Baolin Wang
  2025-04-09  9:46 ` David Hildenbrand
  2025-04-10  8:45 ` Oscar Salvador
  0 siblings, 2 replies; 7+ messages in thread
From: Baolin Wang @ 2025-04-09  9:38 UTC (permalink / raw)
  To: akpm
  Cc: willy, david, hannes, 21cnbao, ryan.roberts, ziy, baolin.wang,
	linux-mm, linux-kernel

When investigating performance issues during file folio unmap, I noticed some
behavioral differences in handling non-PMD-sized folios and PMD-sized folios.
For non-PMD-sized file folios, it will call folio_mark_accessed() to mark the
folio as having seen activity, but this is not done for PMD-sized folios.

This might not cause obvious issues, but a potential problem could be that,
it might lead to reclaim hot file folios under memory pressure, as quoted
from Johannes:

"
Sometimes file contents are only accessed through relatively short-lived
mappings. But they can nevertheless be accessed a lot and be hot. It's
important to not lose that information on unmap, and end up kicking out a
frequently used cache page.
"

Therefore, we should also add folio_mark_accessed() for PMD-sized file
folios when unmapping.

Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Zi Yan <ziy@nvidia.com>
---
Changes from RFC:
 - Update the commit message, per Johannes.
 - Collect Acked tags from Johannes and Zi. Thanks.
---
 mm/huge_memory.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 2a47682d1ab7..955781b4e946 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -2260,6 +2260,10 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
 				zap_deposited_table(tlb->mm, pmd);
 			add_mm_counter(tlb->mm, mm_counter_file(folio),
 				       -HPAGE_PMD_NR);
+
+			if (flush_needed && pmd_young(orig_pmd) &&
+			    likely(vma_has_recency(vma)))
+				folio_mark_accessed(folio);
 		}
 
 		spin_unlock(ptl);
-- 
2.43.5



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-04-11  3:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-09  9:38 [PATCH] mm: huge_memory: add folio_mark_accessed() when zapping file THP Baolin Wang
2025-04-09  9:46 ` David Hildenbrand
2025-04-09  9:49   ` Baolin Wang
2025-04-09  9:53     ` David Hildenbrand
2025-04-10  8:45 ` Oscar Salvador
2025-04-11  1:07   ` Baolin Wang
2025-04-11  3:14     ` Oscar Salvador

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox