Re: [PATCH v1 2/4] mm: Cleanup apply_to_pte_range() routine

Alexander Gordeev
2025-04-14T14:18:21Z

On Fri, Apr 11, 2025 at 04:46:58PM +1000, Nicholas Piggin wrote:
> On Tue Apr 8, 2025 at 1:11 AM AEST, Alexander Gordeev wrote:
> > Reverse 'create' vs 'mm == &init_mm' conditions and move
> > page table mask modification out of the atomic context.
> >
> > Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> > ---
> > mm/memory.c | 28 +++++++++++++++++-----------
> > 1 file changed, 17 insertions(+), 11 deletions(-)
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 2d8c265fc7d6..f0201c8ec1ce 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -2915,24 +2915,28 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
> > pte_fn_t fn, void *data, bool create,
> > pgtbl_mod_mask *mask)
> > {
> > + int err = create ? -ENOMEM : -EINVAL;
>
> Could you make this a new variable instead of reusing
> existing err? 'const int pte_err' or something?

Will do, when/if repost.

...

> > @@ -2944,12 +2948,14 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
> > }
> > } while (addr += PAGE_SIZE, addr != end);
> > }
> > - *mask |= PGTBL_PTE_MODIFIED;
> >
> > arch_leave_lazy_mmu_mode();
> >
> > if (mm != &init_mm)
> > pte_unmap_unlock(mapped_pte, ptl);
> > +
> > + *mask |= PGTBL_PTE_MODIFIED;
>
> This is done just because we might as well? Less work in critical
> section?

Yes.

Thanks!