From: Barry Song <21cnbao@gmail.com>
To: Lance Yang <ioworker0@gmail.com>
Cc: akpm@linux-foundation.org, ryan.roberts@arm.com,
dev.jain@arm.com, david@redhat.com, shy828301@gmail.com,
ziy@nvidia.com, libang.li@antgroup.com,
baolin.wang@linux.alibaba.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Mingzhe Yang <mingzhe.yang@ly.com>
Subject: Re: [RFC 2/2] mm/mthp: relax anon mTHP PTE Mapping restrictions
Date: Mon, 20 Jan 2025 15:15:00 +1300 [thread overview]
Message-ID: <CAGsJ_4wdbUb-LAdA-+KC8zQhf4CPp3=_9YRLWMQkr71OXUehJw@mail.gmail.com> (raw)
In-Reply-To: <20250120012230.3343-3-ioworker0@gmail.com>
On Mon, Jan 20, 2025 at 2:23 PM Lance Yang <ioworker0@gmail.com> wrote:
>
> Previously, mTHP could only be mapped to PTEs where all entries were none.
> With this change, PTEs within the range mapping the demand-zero page can
> now be treated as `pte_none` and remapped to a new mTHP, providing more
> opportunities to take advantage of mTHP.
>
> Signed-off-by: Mingzhe Yang <mingzhe.yang@ly.com>
> Signed-off-by: Lance Yang <ioworker0@gmail.com>
> ---
> mm/memory.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 4e148309b3e0..99ec75c6f0fe 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -4815,7 +4815,8 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf)
> order = highest_order(orders);
> while (orders) {
> addr = ALIGN_DOWN(vmf->address, PAGE_SIZE << order);
> - if (pte_range_none(pte + pte_index(addr), 1 << order))
> + if (pte_range_none_or_zeropfn(pte + pte_index(addr), 1 << order,
> + NULL))
> break;
> order = next_order(&orders, order);
> }
> @@ -4867,6 +4868,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
> {
> struct vm_area_struct *vma = vmf->vma;
> unsigned long addr = vmf->address;
> + bool any_zeropfn = false;
> struct folio *folio;
> vm_fault_t ret = 0;
> int nr_pages = 1;
> @@ -4939,7 +4941,8 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
> if (nr_pages == 1 && vmf_pte_changed(vmf)) {
> update_mmu_tlb(vma, addr, vmf->pte);
> goto release;
> - } else if (nr_pages > 1 && !pte_range_none(vmf->pte, nr_pages)) {
> + } else if (nr_pages > 1 && !pte_range_none_or_zeropfn(
> + vmf->pte, nr_pages, &any_zeropfn)) {
> update_mmu_tlb_range(vma, addr, vmf->pte, nr_pages);
> goto release;
> }
> @@ -4965,6 +4968,10 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
> entry = pte_mkuffd_wp(entry);
> set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr_pages);
>
> + /* At least one PTE was mapped to the zero page */
> + if (nr_pages > 1 && any_zeropfn)
> + flush_tlb_range(vma, addr, addr + (nr_pages * PAGE_SIZE));
Do we also need mmu_notifier?
mmu_notifier_range_init(...)
mmu_notifier_invalidate_range_start(&range);
By the way, this is getting much more complex, but are we seeing any real
benefits? I’ve tested this before, and it seems that zeropfn-mapped
anonymous folios are quite rare.
> +
> /* No need to invalidate - it was non-present before */
> update_mmu_cache_range(vmf, vma, addr, vmf->pte, nr_pages);
> unlock:
> --
> 2.45.2
>
Thanks
Barry
next prev parent reply other threads:[~2025-01-20 2:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-20 1:22 [RFC 0/2] " Lance Yang
2025-01-20 1:22 ` [RFC 1/2] mm/mthp: add pte_range_none_or_zeropfn() helper Lance Yang
2025-01-20 1:22 ` [RFC 2/2] mm/mthp: relax anon mTHP PTE Mapping restrictions Lance Yang
2025-01-20 2:15 ` Barry Song [this message]
2025-01-20 13:20 ` Lance Yang
2025-01-20 13:38 ` David Hildenbrand
2025-01-21 12:57 ` Lance Yang
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='CAGsJ_4wdbUb-LAdA-+KC8zQhf4CPp3=_9YRLWMQkr71OXUehJw@mail.gmail.com' \
--to=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=ioworker0@gmail.com \
--cc=libang.li@antgroup.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingzhe.yang@ly.com \
--cc=ryan.roberts@arm.com \
--cc=shy828301@gmail.com \
--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