Re: [PATCH v5 3/7] mm: Add batched versions of ptep_modify_prot_start/commit

From: Barry Song
Date: Sun Jul 20 2025 - 20:00:01 EST


On Fri, Jul 18, 2025 at 5:03 PM Dev Jain <dev.jain@xxxxxxx> wrote:
>
> Batch ptep_modify_prot_start/commit in preparation for optimizing mprotect,
> implementing them as a simple loop over the corresponding single pte
> helpers. Architecture may override these helpers.
>
> Signed-off-by: Dev Jain <dev.jain@xxxxxxx>

Reviewed-by: Barry Song <baohua@xxxxxxxxxx>

> ---
> include/linux/pgtable.h | 84 ++++++++++++++++++++++++++++++++++++++++-
> mm/mprotect.c | 4 +-
> 2 files changed, 85 insertions(+), 3 deletions(-)
>

[...]

> +#ifndef modify_prot_start_ptes
> +static inline pte_t modify_prot_start_ptes(struct vm_area_struct *vma,
> + unsigned long addr, pte_t *ptep, unsigned int nr)
> +{
> + pte_t pte, tmp_pte;
> +
> + pte = ptep_modify_prot_start(vma, addr, ptep);
> + while (--nr) {
> + ptep++;
> + addr += PAGE_SIZE;
> + tmp_pte = ptep_modify_prot_start(vma, addr, ptep);
> + if (pte_dirty(tmp_pte))
> + pte = pte_mkdirty(pte);
> + if (pte_young(tmp_pte))
> + pte = pte_mkyoung(pte);

It might be interesting to explore whether a similar optimization
could apply here as well:
https://lore.kernel.org/linux-mm/20250624152549.2647828-1-xavier.qyxia@xxxxxxxxx/
I suspect it would, but it's probably not worth including in this
patch.

> + }
> + return pte;
> +}
> +#endif
> +

Thanks
Barry