Everywhere else in MM, the page fault vmf->pgoff is in PAGE_SIZE granularity, except in hugetlbfs, it's in hugepagesize granularity. This is really unnecessary. Suggested-by: Matthew Wilcox Signed-off-by: Jane Chu --- mm/hugetlb.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4b80b167cc9c..3255f6b762c9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5654,6 +5654,8 @@ static inline vm_fault_t hugetlb_handle_userfault(struct vm_fault *vmf, unsigned long reason) { u32 hash; + struct hstate *h = hstate_vma(vmf->vma); + pgoff_t idx = vmf->pgoff >> huge_page_order(h); /* * vma_lock and hugetlb_fault_mutex must be dropped before handling @@ -5661,7 +5663,7 @@ static inline vm_fault_t hugetlb_handle_userfault(struct vm_fault *vmf, * userfault, any vma operation should be careful from here. */ hugetlb_vma_unlock_read(vmf->vma); - hash = hugetlb_fault_mutex_hash(mapping, vmf->pgoff); + hash = hugetlb_fault_mutex_hash(mapping, idx); mutex_unlock(&hugetlb_fault_mutex_table[hash]); return handle_userfault(vmf, reason); } @@ -5686,7 +5688,7 @@ static bool hugetlb_pte_stable(struct hstate *h, struct mm_struct *mm, unsigned static vm_fault_t hugetlb_no_page(struct address_space *mapping, struct vm_fault *vmf) { - u32 hash = hugetlb_fault_mutex_hash(mapping, vmf->pgoff); + u32 hash; bool new_folio, new_anon_folio = false; struct vm_area_struct *vma = vmf->vma; struct mm_struct *mm = vma->vm_mm; @@ -5696,6 +5698,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, struct folio *folio; unsigned long size; pte_t new_pte; + pgoff_t idx = vmf->pgoff >> huge_page_order(h); /* * Currently, we are forced to kill the process in the event the @@ -5714,9 +5717,9 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, * before we get page_table_lock. */ new_folio = false; - folio = filemap_lock_hugetlb_folio(h, mapping, vmf->pgoff); + folio = filemap_lock_hugetlb_folio(h, mapping, idx); if (IS_ERR(folio)) { - size = i_size_read(mapping->host) >> huge_page_shift(h); + size = i_size_read(mapping->host) >> PAGE_SHIFT; if (vmf->pgoff >= size) goto out; /* Check for page in userfault range */ @@ -5778,8 +5781,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, new_folio = true; if (vma->vm_flags & VM_MAYSHARE) { - int err = hugetlb_add_to_page_cache(folio, mapping, - vmf->pgoff); + int err = hugetlb_add_to_page_cache(folio, mapping, idx); if (err) { /* * err can't be -EEXIST which implies someone @@ -5894,6 +5896,7 @@ static vm_fault_t hugetlb_no_page(struct address_space *mapping, if (unlikely(ret & VM_FAULT_RETRY)) vma_end_read(vma); + hash = hugetlb_fault_mutex_hash(mapping, idx); mutex_unlock(&hugetlb_fault_mutex_table[hash]); return ret; @@ -5947,8 +5950,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, .address = address & huge_page_mask(h), .real_address = address, .flags = flags, - .pgoff = vma_hugecache_offset(h, vma, - address & huge_page_mask(h)), + .pgoff = linear_page_index(vma, address), /* TODO: Track hugetlb faults using vm_fault */ /* @@ -5963,7 +5965,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, * the same page in the page cache. */ mapping = vma->vm_file->f_mapping; - hash = hugetlb_fault_mutex_hash(mapping, vmf.pgoff); + hash = hugetlb_fault_mutex_hash(mapping, vmf.pgoff >> huge_page_order(h)); mutex_lock(&hugetlb_fault_mutex_table[hash]); /* -- 2.43.5