[PATCH v2 3/3] mm/hugetlb: Use a folio in hugetlb_fault()

Peng Zhang posted 3 patches 2 years, 8 months ago
[PATCH v2 3/3] mm/hugetlb: Use a folio in hugetlb_fault()
Posted by Peng Zhang 2 years, 8 months ago
From: ZhangPeng <zhangpeng362@huawei.com>

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

Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
 mm/hugetlb.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index e58f8001fd92..e34329e25abe 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -6062,7 +6062,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	vm_fault_t ret;
 	u32 hash;
 	pgoff_t idx;
-	struct page *page = NULL;
+	struct folio *folio = NULL;
 	struct folio *pagecache_folio = NULL;
 	struct hstate *h = hstate_vma(vma);
 	struct address_space *mapping;
@@ -6181,14 +6181,14 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	 * pagecache_folio, so here we need take the former one
 	 * when page != pagecache_folio or !pagecache_folio.
 	 */
-	page = pte_page(entry);
-	if (page_folio(page) != pagecache_folio)
-		if (!trylock_page(page)) {
+	folio = page_folio(pte_page(entry));
+	if (folio != pagecache_folio)
+		if (!folio_trylock(folio)) {
 			need_wait_lock = 1;
 			goto out_ptl;
 		}
 
-	get_page(page);
+	folio_get(folio);
 
 	if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) {
 		if (!huge_pte_write(entry)) {
@@ -6204,9 +6204,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 						flags & FAULT_FLAG_WRITE))
 		update_mmu_cache(vma, haddr, ptep);
 out_put_page:
-	if (page_folio(page) != pagecache_folio)
-		unlock_page(page);
-	put_page(page);
+	if (folio != pagecache_folio)
+		folio_unlock(folio);
+	folio_put(folio);
 out_ptl:
 	spin_unlock(ptl);
 
@@ -6225,7 +6225,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
 	 * here without taking refcount.
 	 */
 	if (need_wait_lock)
-		wait_on_page_locked(page);
+		folio_wait_locked(folio);
 	return ret;
 }
 
-- 
2.25.1
Re: [PATCH v2 3/3] mm/hugetlb: Use a folio in hugetlb_fault()
Posted by Muchun Song 2 years, 8 months ago

> On Jun 6, 2023, at 14:20, Peng Zhang <zhangpeng362@huawei.com> wrote:
> 
> From: ZhangPeng <zhangpeng362@huawei.com>
> 
> We can replace seven implicit calls to compound_head() with one by using
> folio.
> 
> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com <mailto:zhangpeng362@huawei.com>>

Reviewed-by: Muchun Song <songmuchun@bytedance.com>

Thanks.
Re: [PATCH v2 3/3] mm/hugetlb: Use a folio in hugetlb_fault()
Posted by Matthew Wilcox 2 years, 8 months ago
On Tue, Jun 06, 2023 at 02:20:13PM +0800, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@huawei.com>
> 
> We can replace seven implicit calls to compound_head() with one by using
> folio.
> 
> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Re: [PATCH v2 3/3] mm/hugetlb: Use a folio in hugetlb_fault()
Posted by Sidhartha Kumar 2 years, 8 months ago
On 6/5/23 11:20 PM, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@huawei.com>
> 
> We can replace seven implicit calls to compound_head() with one by using
> folio.
> 
> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
> ---
>   mm/hugetlb.c | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index e58f8001fd92..e34329e25abe 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -6062,7 +6062,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>   	vm_fault_t ret;
>   	u32 hash;
>   	pgoff_t idx;
> -	struct page *page = NULL;
> +	struct folio *folio = NULL;
>   	struct folio *pagecache_folio = NULL;
>   	struct hstate *h = hstate_vma(vma);
>   	struct address_space *mapping;
> @@ -6181,14 +6181,14 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>   	 * pagecache_folio, so here we need take the former one
>   	 * when page != pagecache_folio or !pagecache_folio.
>   	 */

This comment should also be updated as page is no longer a variable in 
this function.

> -	page = pte_page(entry);
> -	if (page_folio(page) != pagecache_folio)
> -		if (!trylock_page(page)) {
> +	folio = page_folio(pte_page(entry));
> +	if (folio != pagecache_folio)
> +		if (!folio_trylock(folio)) {
>   			need_wait_lock = 1;
>   			goto out_ptl;
>   		}
>   
> -	get_page(page);
> +	folio_get(folio);
>   
>   	if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) {
>   		if (!huge_pte_write(entry)) {
> @@ -6204,9 +6204,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>   						flags & FAULT_FLAG_WRITE))
>   		update_mmu_cache(vma, haddr, ptep);
>   out_put_page:
> -	if (page_folio(page) != pagecache_folio)
> -		unlock_page(page);
> -	put_page(page);
> +	if (folio != pagecache_folio)
> +		folio_unlock(folio);
> +	folio_put(folio);
>   out_ptl:
>   	spin_unlock(ptl);
>   
> @@ -6225,7 +6225,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
>   	 * here without taking refcount.
>   	 */
>   	if (need_wait_lock)
> -		wait_on_page_locked(page);
> +		folio_wait_locked(folio);
>   	return ret;
>   }
>   

Besides updating the comment.
Reviewed-by Sidhartha Kumar <sidhartha.kumar@oracle.com>