Re: [PATCH] mm/memory: reuse the whole exclusive large folio on a write fault
From: Barry Song
Date: Fri Sep 18 2026 - 19:48:33 EST
On Sat, Sep 19, 2026 at 2:29 AM Yuan-Hao Hsu <aa9736195201@xxxxxxxxx> wrote:
>
> On Fri, 18 Sep 2026 14:14:11 +0200, David Hildenbrand (Arm) wrote:
>
> > There were previous discussions on this, in particular around how much
> > we should actually try operating around the target PTE.
>
> Yes, Barry's RFC from 2024 and your replies to it, where you were fine
> with contpte granularity and not convinced about anything bigger. That
> is why the description has the numbers for both: capped to 16 PTEs, the
> 1M and 2M cases take 5.4 ms instead of 3.9 ms, and the only pattern where
Hi Yuan-Hao,
I'm fine with your follow-up work, but I'd appreciate it if you could
mention the previous work and include the link in your changelog, along
with an explanation of how you address David's concerns.
> the cap wins is one store per 2M. If you would rather start with the
> contpte-sized version, that is a two-line change and I can send that
> version instead.
I think a major concern is that we may spend too much time scanning
PTEs to determine whether we can batch them. If we don't support
CONT-PTE, we may simply scan fewer PTEs; if we do support CONT-PTE, we
may end up scanning more PTEs. So we need to show that the scanning
cost is controlled and explain how it is bounded.
>
> > How did you use the LLM for coming up with this patch + description?
>
> I did the initial investigation and made the design decisions myself.
> Once I had a clear idea of the approach and the overall structure, I used
> an LLM to help with parts of the implementation and the test
> programs. I also used it to help with drafting the commit message.
>
> Before sending the patch, I went through it line by line and checked the
> test results and measurements to make sure they matched what the code was
> actually doing and that there were no obvious issues.
I also personally feel that both the changelog and the code are too
long to read. Could we somehow split the changes into smaller pieces
and describe how each of those concerns is addressed at a finer
granularity?
>
> Lorenzo, for your bot's question: the reuse decision in
> wp_can_reuse_anon_folio() is per folio. The patch applies it to the other
> PTEs of the folio within the same VMA and page table using the mprotect
> helpers (can_change_pte_writable() and modify_prot_*_ptes()), so
> soft-dirty, uffd-wp and NUMA hinting PTEs are handled the way mprotect()
> handles them, and the PTE that faulted is finished by wp_page_reuse() as
> before.
>
> The part I spent most of the time on was the measurements, including the
> cases where it does not help.
>
Best Regards
Barry