From 5872168de5d5c1f69a2efcf80e331c32aa08ec9a Mon Sep 17 00:00:00 2001 From: Lorenzo Stoakes Date: Fri, 10 Jul 2026 21:16:59 +0100 Subject: mm/vma: use vma_start_pgoff(), linear_page_index() in mm code There are many instances in which linear_page_index() (as well as linear_page_delta()) is open-coded, which is confusing and inconsistent. Additionally, vma->vm_pgoff doesn't necessarily make it clear that this is the page offset of the start of the VMA range. Doing so also aids greppability. So use vma_start_pgoff() in favour of directly accessing vma->vm_pgoff, and linear_page_index() where we can. This also lays the ground for future changes which will add an anonymous page offset in order to be able to index MAP_PRIVATE-file backed anon folios in terms of their virtual page offset. No functional change intended. Link: https://lore.kernel.org/20260710-b4-pre-scalable-cow-v2-18-2a5aa403d977@kernel.org Signed-off-by: Lorenzo Stoakes Reviewed-by: Gregory Price Reviewed-by: SJ Park Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka (SUSE) Cc: Ackerley Tng Cc: David Hildenbrand (Arm) Cc: Kai Huang Cc: Marek Szyprowski Cc: Thomas Zimmermann Cc: Liam R. Howlett (Oracle) Cc: Zi Yan Signed-off-by: Andrew Morton --- include/linux/huge_mm.h | 1 + include/linux/hugetlb.h | 3 +-- include/linux/pagemap.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 19a7bfce279e..cae97c307280 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -230,6 +230,7 @@ static inline bool thp_vma_suitable_order(struct vm_area_struct *vma, /* Don't have to check pgoff for anonymous vma */ if (!vma_is_anonymous(vma)) { + /* vma_start_pgoff() in mm.h so not available. */ if (!IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, hpage_size >> PAGE_SHIFT)) return false; diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 95b1b6ee1f96..6ca232a61643 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -801,8 +801,7 @@ static inline pgoff_t hugetlb_linear_page_index(struct vm_area_struct *vma, { struct hstate *h = hstate_vma(vma); - return ((address - vma->vm_start) >> huge_page_shift(h)) + - (vma->vm_pgoff >> huge_page_order(h)); + return linear_page_index(vma, address) >> huge_page_order(h); } static inline bool order_is_gigantic(unsigned int order) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index a950070b045f..c6fc783aaee5 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1097,7 +1097,7 @@ static inline pgoff_t linear_page_index(const struct vm_area_struct *vma, pgoff_t pgoff; pgoff = linear_page_delta(vma, address); - pgoff += vma->vm_pgoff; + pgoff += vma_start_pgoff(vma); return pgoff; } -- cgit v1.2.3