From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Zi Yan <ziy@nvidia.com>, Johannes Weiner <hannes@cmpxchg.org>
Cc: akpm@linux-foundation.org, willy@infradead.org, david@redhat.com,
21cnbao@gmail.com, ryan.roberts@arm.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] mm: huge_memory: add folio_mark_accessed() when zapping file THP
Date: Wed, 9 Apr 2025 08:52:08 +0800 [thread overview]
Message-ID: <0b668098-5623-4062-b219-605dc91c0877@linux.alibaba.com> (raw)
In-Reply-To: <2C391CDE-0C6D-4ECD-9EDF-5CC165999EA2@nvidia.com>
On 2025/4/9 00:12, Zi Yan wrote:
> On 8 Apr 2025, at 12:02, Johannes Weiner wrote:
>
>> On Tue, Apr 08, 2025 at 11:29:43AM -0400, Zi Yan wrote:
>>> On 8 Apr 2025, at 9:16, Baolin Wang 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
>>
>> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Thanks for taking a look.
>>> How likely will the system get PMD-sized file folios when it is under
>>> memory pressure? Johannes’ recent patch increases THP allocation successful
>>> rate, maybe it was not happening before but will be after the patch?
>>
>> It's not so much about whether the refault can construct a THP again,
>> but whether we should have evicted this data under pressure to begin
>> with. It's more about IO and paging. And it's the same consideration
>> why we transfer the young bit for base pages.
>
> Got it. It clarifies things a lot.
>
>>
>> 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.
Yes, that's what I also understand. Thanks for the explanation.
> So folio_mark_accessed() will prevent the folio from going down in
> the LRU lists, when PTE access information is transferred to the folio.
> The addition of folio_mark_accessed() makes sense to me now.
>
> Baolin, can you include Johannes’s explanation in your commit log?
Sure. Will do.
>
> Feel free to add Acked-by: Zi Yan <ziy@nvidia.com>
Thanks for reviewing.
>>>> added for PMD-sized file folios?
>>>
>>> Do you see any performance change after your patch?
Not yet, just some theoretical analysis from code inspection.
>>>> Signed-off-by: Baolin Wang <baolin.wang@linux.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);
>>>> }
>>>>
>>>> spin_unlock(ptl);
>>>> --
>>>> 2.43.5
>
>
> Best Regards,
> Yan, Zi
next prev parent reply other threads:[~2025-04-09 0:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-08 13:16 Baolin Wang
2025-04-08 15:29 ` Zi Yan
2025-04-08 16:02 ` Johannes Weiner
2025-04-08 16:12 ` Zi Yan
2025-04-09 0:52 ` Baolin Wang [this message]
2025-04-10 8:14 ` Barry Song
2025-04-10 9:05 ` Baolin Wang
2025-04-10 10:29 ` Barry Song
2025-04-10 15:13 ` Zi Yan
2025-04-10 21:56 ` Barry Song
2025-04-11 1:20 ` Baolin Wang
2025-04-11 2:32 ` Barry Song
2025-04-11 8:42 ` David Hildenbrand
2025-04-11 11:51 ` Barry Song
2025-04-11 14:44 ` Zi Yan
2025-04-12 9:02 ` Barry Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0b668098-5623-4062-b219-605dc91c0877@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox