[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4yPxoF5P87WdXbXVb8BqovVvxhKg40YVddkEQmFjFsRYw@mail.gmail.com>
Date: Thu, 10 Apr 2025 22:29:27 +1200
From: Barry Song <21cnbao@...il.com>
To: Baolin Wang <baolin.wang@...ux.alibaba.com>
Cc: akpm@...ux-foundation.org, willy@...radead.org, david@...hat.com,
ryan.roberts@....com, ziy@...dia.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH] mm: huge_memory: add folio_mark_accessed() when
zapping file THP
On Thu, Apr 10, 2025 at 9:05 PM Baolin Wang
<baolin.wang@...ux.alibaba.com> wrote:
>
>
>
> On 2025/4/10 16:14, Barry Song wrote:
> > On Wed, Apr 9, 2025 at 1:16 AM Baolin Wang
> > <baolin.wang@...ux.alibaba.com> wrote:
> >>
> >> 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 more frequent refaults of PMD-sized file folios under memory
> >> pressure. Therefore, I am unsure whether the folio_mark_accessed() should be
> >> added for PMD-sized file folios?
> >>
> >> Signed-off-by: Baolin Wang <baolin.wang@...ux.alibaba.com>
> >> ---
> >> mm/huge_memory.c | 4 ++++
> >> 1 file changed, 4 insertions(+)
> >>
> >> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> >> index 6ac6d468af0d..b3ade7ac5bbf 100644
> >> --- a/mm/huge_memory.c
> >> +++ b/mm/huge_memory.c
> >> @@ -2262,6 +2262,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);
> >
> > Acked-by: Barry Song <baohua@...nel.org>
>
> Thanks.
>
> > I also came across an interesting observation: on a memory-limited system,
> > demoting unmapped file folios in the LRU—specifically when their mapcount
> > drops from 1 to 0—can actually improve performance.
>
> These file folios are used only once? Can folio_set_dropbehind() be used
> to optimize it, which can avoid the LRU activity movement in
> folio_mark_accessed()?
For instance, when a process, such as a game, just exits, it can be expected
that it won't be used again in the near future. As a result, demoting
its previously
unmapped file pages can improve performance.
Of course, for file folios mapped by multiple processes, such as
common .so files,
it's a different story. Typically, their mapcounts are always high.
>
> > If others have observed the same behavior, we might not need to mark them
> > as accessed in that scenario.
> >
> >> }
> >>
> >> spin_unlock(ptl);
> >> --
> >> 2.43.5
> >>
> >
Thanks
Barry
Powered by blists - more mailing lists