Re: [PATCH v2 01/15] mm/vma: introduce VMA virtual page offset field and add helpers

From: xu.xin16

Date: Sat Jul 25 2026 - 04:09:11 EST


> This patch establishes fields within the vm_area_struct type to store the
> virtual page offset of VMAs.
>
> The virtual page offset of a VMA is equal to vma->vm_start >> PAGE_SHIFT if
> they are unfaulted or were not remapped, otherwise it is equal to this
> value at the point of first fault.
>
> Currently, anonymous folios belonging to CoW'd MAP_PRIVATE-mapped
> file-backed VMAs are tracked by their file offset. By adding virtual offset
> as a property of VMAs, we can now track them by their virtual page offset
> instead.
>
> By tracking this, we provide the means by which to eliminate this
> inconsistency, and more importantly lay the foundations for future work for
> the scalable CoW anonymous rmap rework.
>
> This patch simply adds the fields and some simple helpers. Subsequent
> patches will update mm code to make use of these fields correctly.
>
> The fields chosen are packed in the VMA such that, for 64-bit kernel
> builds, no additional space is taken up.
>
> The first field is present on cacheline 0 containing key VMA fields, and
> the second on cacheline 3, which contains file-backed reverse mapping
> fields.
>
> Given the relative time spent accessing reverse mapping fields as well as
> updating them, there shouldn't be any performance impact here from false
> sharing.
>
> Update the VMA userland tests to account for this change.
>
> No callsites are updated yet, so no functional change intended.
>
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> ---
> include/linux/mm.h | 59 +++++++++++++++++++++++++++++++++++++++++
> include/linux/mm_types.h | 12 +++++++++
> mm/vma.h | 14 ++++++++++
> mm/vma_init.c | 1 +
> tools/testing/vma/include/dup.h | 26 ++++++++++++++++++
> 5 files changed, 112 insertions(+)
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 87feaa5a2b78..59b98cc60402 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -4393,6 +4393,65 @@ static inline pgoff_t vma_last_pgoff(const struct vm_area_struct *vma)
> return vma_end_pgoff(vma) - 1;
> }
>
> +/**
> + * vma_start_virt_pgoff() - Get the virtual page offset of the start of @vma
> + * @vma: The VMA whose virtual page offset is required.
> + *
> + * If unfaulted, then this is vma->vm_start >> PAGE_SHIFT, if faulted then the
> + * virtual page offset at the time of first fault.
> + *
> + * If the VMA is anonymous, this returns the same value as vma_start_pgoff().
> + *
> + * This value is used for tracking MAP_PRIVATE file-backed mappings by their
> + * virtual page offset.
> + *
> + * Returns: The virtual page offset of the start of @vma.
> + */

Thanks. These looks much better to me.

Reviewed-by: Xu Xin <xu.xin16@xxxxxxxxxx>