Re: [PATCH v2 1/7] mm: factor out generic PTE batch detection from swap_pte_batch()

From: David Hildenbrand (Arm)

Date: Thu Aug 13 2026 - 06:08:20 EST


On 8/13/26 06:23, Shivank Garg wrote:
> Factor out the generic PTE batch detection logic from swap_pte_batch()
> into softleaf_pte_batch() helper, so that it can be reused by upcoming
> patch that adds restore-side batching of migration entries.
>
> swap_pte_batch() now keeps only its swap-specific concerns and
> delegates the batch detection to softleaf_pte_batch().
>
> No functional changes intended.
>
> Signed-off-by: Shivank Garg <shivankg@xxxxxxx>
> ---
> mm/internal.h | 36 +++++++++++++++++++++---------------
> 1 file changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/mm/internal.h b/mm/internal.h
> index a5d0488a54dc..1e1ab53b642e 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -560,6 +560,26 @@ static inline void set_softleaf_ptes(struct mm_struct *mm, unsigned long addr,
> }
> }
>
> +static inline int softleaf_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
> +{
> + pte_t expected_pte = pte_next_softleaf_offset(pte);
> + const pte_t *end_ptep = start_ptep + max_nr;
> + pte_t *ptep = start_ptep + 1;
> +

Wouldn't we want some way to make sure that the softleaf entries actually carry
offsets or pfns of sorts?

> + VM_WARN_ON(max_nr < 1);
> +
> + while (ptep < end_ptep) {
> + pte = ptep_get(ptep);
> +
> + if (!pte_same(pte, expected_pte))
> + break;
> + expected_pte = pte_next_softleaf_offset(expected_pte);
> + ptep++;
> + }
> +
> + return ptep - start_ptep;
> +}
> +
> /**
> * swap_pte_batch - detect a PTE batch for a set of contiguous swap entries
> * @start_ptep: Page table pointer for the first entry.
> @@ -577,23 +597,9 @@ static inline void set_softleaf_ptes(struct mm_struct *mm, unsigned long addr,
> */
> static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte)
> {
> - pte_t expected_pte = pte_next_softleaf_offset(pte);
> - const pte_t *end_ptep = start_ptep + max_nr;
> - pte_t *ptep = start_ptep + 1;
> -
> - VM_WARN_ON(max_nr < 1);
> VM_WARN_ON(!softleaf_is_swap(softleaf_from_pte(pte)));

Any reason we cannot simply rename this thing and drop the VM_WARN_ON? I mean, a
caller can just do that.

--
Cheers,

David