Commit 061e62e8 authored by ZhangPeng's avatar ZhangPeng Committed by Andrew Morton

mm/hugetlb: use a folio in hugetlb_fault()

We can replace seven implicit calls to compound_head() with one by using
folio.

[akpm@linux-foundation.org: update comment, per Sidhartha]
Link: https://lkml.kernel.org/r/20230606062013.2947002-4-zhangpeng362@huawei.comSigned-off-by: default avatarZhangPeng <zhangpeng362@huawei.com>
Reviewed-by Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarMuchun Song <songmuchun@bytedance.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Nanyong Sun <sunnanyong@huawei.com>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 959a78b6
...@@ -6062,7 +6062,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -6062,7 +6062,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
vm_fault_t ret; vm_fault_t ret;
u32 hash; u32 hash;
pgoff_t idx; pgoff_t idx;
struct page *page = NULL; struct folio *folio = NULL;
struct folio *pagecache_folio = NULL; struct folio *pagecache_folio = NULL;
struct hstate *h = hstate_vma(vma); struct hstate *h = hstate_vma(vma);
struct address_space *mapping; struct address_space *mapping;
...@@ -6179,16 +6179,16 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -6179,16 +6179,16 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
/* /*
* hugetlb_wp() requires page locks of pte_page(entry) and * hugetlb_wp() requires page locks of pte_page(entry) and
* pagecache_folio, so here we need take the former one * pagecache_folio, so here we need take the former one
* when page != pagecache_folio or !pagecache_folio. * when folio != pagecache_folio or !pagecache_folio.
*/ */
page = pte_page(entry); folio = page_folio(pte_page(entry));
if (page_folio(page) != pagecache_folio) if (folio != pagecache_folio)
if (!trylock_page(page)) { if (!folio_trylock(folio)) {
need_wait_lock = 1; need_wait_lock = 1;
goto out_ptl; goto out_ptl;
} }
get_page(page); folio_get(folio);
if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) { if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) {
if (!huge_pte_write(entry)) { if (!huge_pte_write(entry)) {
...@@ -6204,9 +6204,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -6204,9 +6204,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
flags & FAULT_FLAG_WRITE)) flags & FAULT_FLAG_WRITE))
update_mmu_cache(vma, haddr, ptep); update_mmu_cache(vma, haddr, ptep);
out_put_page: out_put_page:
if (page_folio(page) != pagecache_folio) if (folio != pagecache_folio)
unlock_page(page); folio_unlock(folio);
put_page(page); folio_put(folio);
out_ptl: out_ptl:
spin_unlock(ptl); spin_unlock(ptl);
...@@ -6225,7 +6225,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, ...@@ -6225,7 +6225,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
* here without taking refcount. * here without taking refcount.
*/ */
if (need_wait_lock) if (need_wait_lock)
wait_on_page_locked(page); folio_wait_locked(folio);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment