Re: [PATCH v6 15/18] mm/huge_memory: mark folio as accessed more accurately on split

From: Kairui Song

Date: Wed Nov 25 2026 - 08:13:22 EST


On Wed, Nov 25, 2026 at 6:09 PM David Hildenbrand (Arm)
<david@xxxxxxxxxx> wrote:
>
> On 11/23/26 19:53, Kairui Song via B4 Relay wrote:
> > From: Kairui Song <kasong@xxxxxxxxxxx>
> >
> > The behavior of updating the folio's access info isn't consistent for
> > huge mapping splitting or ordinary unmapping. The page table's young
> > flag has to be translated into folio's access info.
> >
> > Right now it only checks and sets the folio's referenced flag, which isn't
> > enough since folio flag updates on access have their own rules. Ordinary
> > unmapping (zapping) calls folio_mark_accessed(), and it also checks
> > if the VMA has recency to avoid false updates.
> >
> > So first just use the right helper here to be more consistent. Keep
> > accounting the young PTE as a cache access, sticking to the current
> > behavior.
> >
> > Tested-by: Zhao Zhenzhuo <zhaozhengzhuo@xxxxxxxxxxxxx>
> > Reviewed-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
> > Tested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> > 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 75e8641bf9ff..fa9f6d21e786 100644
> > --- a/mm/huge_memory.c
> > +++ b/mm/huge_memory.c
> > @@ -3122,8 +3122,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);
>
> Can we just have a helper that abstracts that? We pass in vma, folio and young
> state and it takes care of things?

I think we can have a folio_mark_accessed_vma(), and so it will be:

+ if (pud_young(old_pud))
+ folio_mark_accessed_vma(folio, vma);

Also converts a few other callsites too, also avoid touching too many
other folio_mark_accessed callers, there are a lot of them. We can
audit and see if folio_mark_accessed can benefit more by passing vma
from more places later.