Re: [PATCH 4/4] mm/mprotect: special-case small folios when applying write permissions

From: Pedro Falcato

Date: Fri Mar 20 2026 - 06:38:57 EST


On Thu, Mar 19, 2026 at 10:43:35PM +0100, David Hildenbrand (Arm) wrote:
> On 3/19/26 19:31, Pedro Falcato wrote:
> > The common order-0 case is important enough to want its own branch, and
> > avoids the hairy, large loop logic that the CPU does not seem to handle
> > particularly well.
> >
> > Signed-off-by: Pedro Falcato <pfalcato@xxxxxxx>
> > ---
> > mm/mprotect.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/mm/mprotect.c b/mm/mprotect.c
> > index aa845f5bf14d..23a741f9a4c8 100644
> > --- a/mm/mprotect.c
> > +++ b/mm/mprotect.c
> > @@ -170,6 +170,13 @@ static __always_inline void commit_anon_folio_batch(struct vm_area_struct *vma,
> > int sub_batch_idx = 0;
> > int len;
> >
> > + /* Optimize for the common order-0 case. */
> > + if (likely(nr_ptes == 1)) {
> > + prot_commit_flush_ptes(vma, addr, ptep, oldpte, ptent, 1,
> > + 0, PageAnonExclusive(first_page), tlb);
> > + return;
> > + }
> > +
> > while (nr_ptes) {
> > expected_anon_exclusive = PageAnonExclusive(first_page + sub_batch_idx);
> > len = page_anon_exclusive_sub_batch(sub_batch_idx, nr_ptes,
>
> That should likely be squashed into patch #1, because only then the
> inline makes more sense.

Will do, thanks.

--
Pedro