From: Barry Song <21cnbao@gmail.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>,
Liam.Howlett@oracle.com, akpm@linux-foundation.org,
catalin.marinas@arm.com, dev.jain@arm.com, harry.yoo@oracle.com,
jannh@google.com, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
lorenzo.stoakes@oracle.com, mhocko@suse.com, riel@surriel.com,
rppt@kernel.org, ryan.roberts@arm.com, surenb@google.com,
vbabka@suse.cz, will@kernel.org, willy@infradead.org
Subject: Re: [PATCH] mm: rmap: skip batched unmapping for UFFD vmas
Date: Mon, 9 Feb 2026 18:49:01 +0800 [thread overview]
Message-ID: <CAGsJ_4w95tTGfanb0NdG5B+ajOUA4LaH7uh+Uxcq0ZNVaqK-Vg@mail.gmail.com> (raw)
In-Reply-To: <e5175f66-56fd-437b-a183-b2ccc3f54f94@kernel.org>
On Mon, Feb 9, 2026 at 5:54 PM David Hildenbrand (Arm) <david@kernel.org> wrote:
>
> On 1/16/26 17:26, Baolin Wang wrote:
> > As Dev reported[1], it's not ready to support batched unmapping for uffd case.
> > Let's still fallback to per-page unmapping for the uffd case.
> >
> > [1] https://lore.kernel.org/linux-mm/20260116082721.275178-1-dev.jain@arm.com/
> > Reported-by: Dev Jain <dev.jain@arm.com>
> > Suggested-by: Barry Song <baohua@kernel.org>
> > Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> > ---
> > mm/rmap.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/rmap.c b/mm/rmap.c
> > index f13480cb9f2e..172643092dcf 100644
> > --- a/mm/rmap.c
> > +++ b/mm/rmap.c
> > @@ -1953,6 +1953,9 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
> > if (pte_unused(pte))
> > return 1;
> >
> > + if (userfaultfd_wp(vma))
> > + return 1;
> > +
>
> Interesting. I was just wondering why we didn't run into that with lazyfree folios.
>
> Staring at pte_install_uffd_wp_if_needed(), we never set the marker for
> anonymous VMAs.
>
> So, yeah, if one sets lazyfree on a uffd-wp PTE, the uffd-wp bit will just get
> zapped alongside. Just like MADV_DONTNEED.
>
>
> I'm fine with that temporary fix. But I guess the non-hacky way to handle this would be:
>
>
> From 53d016d6e6f624425dbdbc2fb1dec7c91fbef15c Mon Sep 17 00:00:00 2001
> From: "David Hildenbrand (Arm)" <david@kernel.org>
> Date: Mon, 9 Feb 2026 10:52:59 +0100
> Subject: [PATCH] tmp
>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> ---
> include/linux/mm_inline.h | 15 ++++++---------
> mm/memory.c | 21 +--------------------
> mm/rmap.c | 2 +-
> 3 files changed, 8 insertions(+), 30 deletions(-)
>
> diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h
> index fa2d6ba811b5..8a9a2c5f5ee3 100644
> --- a/include/linux/mm_inline.h
> +++ b/include/linux/mm_inline.h
> @@ -566,9 +566,8 @@ static inline pte_marker copy_pte_marker(
> *
> * Returns true if an uffd-wp pte was installed, false otherwise.
> */
> -static inline bool
> -pte_install_uffd_wp_if_needed(struct vm_area_struct *vma, unsigned long addr,
> - pte_t *pte, pte_t pteval)
> +static inline bool install_uffd_wp_ptes_if_needed(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *pte, unsigned int nr, pte_t pteval)
> {
> bool arm_uffd_pte = false;
>
> @@ -598,13 +597,11 @@ pte_install_uffd_wp_if_needed(struct vm_area_struct *vma, unsigned long addr,
> if (unlikely(pte_swp_uffd_wp_any(pteval)))
> arm_uffd_pte = true;
>
> - if (unlikely(arm_uffd_pte)) {
> - set_pte_at(vma->vm_mm, addr, pte,
> - make_pte_marker(PTE_MARKER_UFFD_WP));
> - return true;
> - }
> + if (likely(!arm_uffd_pte))
> + return false;
>
> - return false;
> + set_ptes(vma->vm_mm, addr, pte, make_pte_marker(PTE_MARKER_UFFD_WP), nr);
> + return true;
> }
>
> static inline bool vma_has_recency(const struct vm_area_struct *vma)
> diff --git a/mm/memory.c b/mm/memory.c
> index da360a6eb8a4..0a87d02a9a69 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -1592,29 +1592,10 @@ zap_install_uffd_wp_if_needed(struct vm_area_struct *vma,
> unsigned long addr, pte_t *pte, int nr,
> struct zap_details *details, pte_t pteval)
> {
> - bool was_installed = false;
> -
> - if (!uffd_supports_wp_marker())
> - return false;
> -
> - /* Zap on anonymous always means dropping everything */
> - if (vma_is_anonymous(vma))
> - return false;
> -
> if (zap_drop_markers(details))
> return false;
>
> - for (;;) {
> - /* the PFN in the PTE is irrelevant. */
> - if (pte_install_uffd_wp_if_needed(vma, addr, pte, pteval))
> - was_installed = true;
> - if (--nr == 0)
> - break;
> - pte++;
> - addr += PAGE_SIZE;
> - }
> -
> - return was_installed;
> + return install_uffd_wp_ptes_if_needed(vma, addr, pte, nr, pteval);
> }
>
> static __always_inline void zap_present_folio_ptes(struct mmu_gather *tlb,
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 7b9879ef442d..f71aacf35925 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2061,7 +2061,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> * we may want to replace a none pte with a marker pte if
> * it's file-backed, so we don't lose the tracking info.
> */
> - pte_install_uffd_wp_if_needed(vma, address, pvmw.pte, pteval);
> + install_uffd_wp_ptes_if_needed(vma, address, pvmw.pte, nr_pages, pteval);
>
> /* Update high watermark before we lower rss */
> update_hiwater_rss(mm);
> --
> 2.43.0
>
>
>
> Does somebody have time to look into that? We should also adjust the doc of pte_install_uffd_wp_if_needed()
> and turn it into some proper kerneldoc.
I'd nominate Dev, if he has the time, as he has been working on
related changes and is already familiar with this area :-)
https://lore.kernel.org/linux-mm/20260116082721.275178-1-dev.jain@arm.com/
I assume this could be treated as a separate optimization, as
the current temporary fix seems acceptable?
Thanks
Barry
next prev parent reply other threads:[~2026-02-09 10:49 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-26 6:07 [PATCH v5 0/5] support batch checking of references and unmapping for large folios Baolin Wang
2025-12-26 6:07 ` [PATCH v5 1/5] mm: rmap: support batched checks of the references " Baolin Wang
2026-01-07 6:01 ` Harry Yoo
2026-02-09 8:49 ` David Hildenbrand (Arm)
2026-02-09 9:14 ` Baolin Wang
2026-02-09 9:20 ` David Hildenbrand (Arm)
2026-02-09 9:25 ` Baolin Wang
2025-12-26 6:07 ` [PATCH v5 2/5] arm64: mm: factor out the address and ptep alignment into a new helper Baolin Wang
2026-02-09 8:50 ` David Hildenbrand (Arm)
2025-12-26 6:07 ` [PATCH v5 3/5] arm64: mm: support batch clearing of the young flag for large folios Baolin Wang
2026-01-02 12:21 ` Ryan Roberts
2026-02-09 9:02 ` David Hildenbrand (Arm)
2025-12-26 6:07 ` [PATCH v5 4/5] arm64: mm: implement the architecture-specific clear_flush_young_ptes() Baolin Wang
2026-01-28 11:47 ` Chris Mason
2026-01-29 1:42 ` Baolin Wang
2026-02-09 9:09 ` David Hildenbrand (Arm)
2026-02-09 9:36 ` Baolin Wang
2026-02-09 9:55 ` David Hildenbrand (Arm)
2026-02-09 10:13 ` Baolin Wang
2026-02-16 0:24 ` Alistair Popple
2025-12-26 6:07 ` [PATCH v5 5/5] mm: rmap: support batched unmapping for file large folios Baolin Wang
2026-01-06 13:22 ` Wei Yang
2026-01-06 21:29 ` Barry Song
2026-01-07 1:46 ` Wei Yang
2026-01-07 2:21 ` Barry Song
2026-01-07 2:29 ` Baolin Wang
2026-01-07 3:31 ` Wei Yang
2026-01-16 9:53 ` Dev Jain
2026-01-16 11:14 ` Lorenzo Stoakes
2026-01-16 14:28 ` Barry Song
2026-01-16 15:23 ` Barry Song
2026-01-16 15:49 ` Baolin Wang
2026-01-18 5:46 ` Dev Jain
2026-01-19 5:50 ` Baolin Wang
2026-01-19 6:36 ` Dev Jain
2026-01-19 7:22 ` Baolin Wang
2026-01-16 15:14 ` Barry Song
2026-01-18 5:48 ` Dev Jain
2026-01-07 6:54 ` Harry Yoo
2026-01-16 8:42 ` Lorenzo Stoakes
2026-01-16 16:26 ` [PATCH] mm: rmap: skip batched unmapping for UFFD vmas Baolin Wang
2026-02-09 9:54 ` David Hildenbrand (Arm)
2026-02-09 10:49 ` Barry Song [this message]
2026-02-09 10:58 ` David Hildenbrand (Arm)
2026-02-10 12:01 ` Dev Jain
2026-02-09 9:38 ` [PATCH v5 5/5] mm: rmap: support batched unmapping for file large folios David Hildenbrand (Arm)
2026-02-09 9:43 ` Baolin Wang
2026-02-13 5:19 ` Barry Song
2026-02-18 12:26 ` Dev Jain
2026-01-16 8:41 ` [PATCH v5 0/5] support batch checking of references and unmapping for " Lorenzo Stoakes
2026-01-16 10:53 ` David Hildenbrand (Red Hat)
2026-01-16 10:52 ` David Hildenbrand (Red Hat)
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_4w95tTGfanb0NdG5B+ajOUA4LaH7uh+Uxcq0ZNVaqK-Vg@mail.gmail.com \
--to=21cnbao@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=catalin.marinas@arm.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=harry.yoo@oracle.com \
--cc=jannh@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=will@kernel.org \
--cc=willy@infradead.org \
/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