vma_hugecache_offset() converts a hugetlb VMA address into a mapping offset in hugepage units. While the helper is small, its name is not very clear, and the resulting code is harder to follow than using the common MM helper directly. Use linear_page_index() instead, with an explicit conversion from PAGE_SIZE units to hugepage units at each call site, and remove vma_hugecache_offset(). Signed-off-by: Jane Chu --- mm/hugetlb.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b41e7b8df094..a677ea774143 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1001,17 +1001,6 @@ static long region_count(struct resv_map *resv, long f, long t) return chg; } -/* - * Convert the address within this vma to the page offset within - * the mapping, huge page units here. - */ -static pgoff_t vma_hugecache_offset(struct hstate *h, - struct vm_area_struct *vma, unsigned long address) -{ - return ((address - vma->vm_start) >> huge_page_shift(h)) + - (vma->vm_pgoff >> huge_page_order(h)); -} - /* * Flags for MAP_PRIVATE reservations. These are stored in the bottom * bits of the reservation map pointer, which are always clear due to @@ -2437,7 +2426,9 @@ static long __vma_reservation_common(struct hstate *h, if (!resv) return 1; - idx = vma_hugecache_offset(h, vma, addr); + idx = linear_page_index(vma, addr); + idx >>= huge_page_order(h); + switch (mode) { case VMA_NEEDS_RESV: ret = region_chg(resv, idx, idx + 1, &dummy_out_regions_needed); @@ -4693,8 +4684,10 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma) if (!resv || !is_vma_resv_set(vma, HPAGE_RESV_OWNER)) return; - start = vma_hugecache_offset(h, vma, vma->vm_start); - end = vma_hugecache_offset(h, vma, vma->vm_end); + start = linear_page_index(vma, vma->vm_start); + start >>= huge_page_order(h); + end = linear_page_index(vma, vma->vm_end); + end >>= huge_page_order(h); reserve = (end - start) - region_count(resv, start, end); hugetlb_cgroup_uncharge_counter(resv, start, end); -- 2.43.5