Skip to contentSkip to conversation

Cleanup for khugepaged

PATCH Applied Miaohe Lin 2 participants 5 messages Mar 25, 2021

Subsystems (2)
lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

cover Cleanup for khugepaged

Hi all,
This series contains cleanups to remove unnecessary out label and meaningless !pte_present() check. Also use helper function to simplify the code. More details can be found in the respective changelogs. Thanks!

Miaohe Lin (3):
khugepaged: use helper function range_in_vma() in
collapse_pte_mapped_thp()
khugepaged: remove unnecessary out label in collapse_huge_page()
khugepaged: remove meaningless !pte_present() check in
khugepaged_scan_pmd()

 mm/khugepaged.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 1/3 khugepaged: use helper function range_in_vma() in collapse_pte_mapped_thp()

We could use helper function range_in_vma() to check whether the desired range is inside the vma to simplify the code.

---
 mm/khugepaged.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/khugepaged.c +1 -1
index b81521dfbb1a..ad0444f3f487 100644
@@ -1446,7 +1446,7 @@ void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr)
 	int i;
 
 	if (!vma || !vma->vm_file ||
-	    vma->vm_start > haddr || vma->vm_end < haddr + HPAGE_PMD_SIZE)
+	    !range_in_vma(vma, haddr, haddr + HPAGE_PMD_SIZE))
 		return;
 
 	/*
Signature · 1 line
2.19.1
author
#2 lore raw

PATCH 2/3 khugepaged: remove unnecessary out label in collapse_huge_page()

In reply to Miaohe Lin

The out label here is unneeded because it just goes to out_up_write label. Remove it to make code more concise.

---
 mm/khugepaged.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
mm/khugepaged.c +3 -5
index ad0444f3f487..58466af69e70 100644
@@ -1128,10 +1128,10 @@ static void collapse_huge_page(struct mm_struct *mm,
 	mmap_write_lock(mm);
 	result = hugepage_vma_revalidate(mm, address, &vma);
 	if (result)
-		goto out;
+		goto out_up_write;
 	/* check if the pmd is still valid */
 	if (mm_find_pmd(mm, address) != pmd)
-		goto out;
+		goto out_up_write;
 
 	anon_vma_lock_write(vma->anon_vma);
 
@@ -1171,7 +1171,7 @@ static void collapse_huge_page(struct mm_struct *mm,
 		spin_unlock(pmd_ptl);
 		anon_vma_unlock_write(vma->anon_vma);
 		result = SCAN_FAIL;
-		goto out;
+		goto out_up_write;
 	}
 
 	/*
@@ -1215,8 +1215,6 @@ static void collapse_huge_page(struct mm_struct *mm,
 		mem_cgroup_uncharge(*hpage);
 	trace_mm_collapse_huge_page(mm, isolated, result);
 	return;
-out:
-	goto out_up_write;
 }
 
 static int khugepaged_scan_pmd(struct mm_struct *mm,
Signature · 1 line
2.19.1
author
#3 lore raw

PATCH 3/3 khugepaged: remove meaningless !pte_present() check in khugepaged_scan_pmd()

In reply to Miaohe Lin

We know it must meet the !is_swap_pte() and !pte_none() condition if we reach here. Since !is_swap_pte() indicates pte_none() or pte_present() is met, it's guaranteed that pte must be present here.

---
 mm/khugepaged.c | 4 ----
 1 file changed, 4 deletions(-)
mm/khugepaged.c +0 -4
index 58466af69e70..01c2d0ed9abd 100644
@@ -1271,10 +1271,6 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,
 				goto out_unmap;
 			}
 		}
-		if (!pte_present(pteval)) {
-			result = SCAN_PTE_NON_PRESENT;
-			goto out_unmap;
-		}
 		if (pte_uffd_wp(pteval)) {
 			/*
 			 * Don't collapse the page if any of the small
Signature · 1 line
2.19.1
Reviewed-by on the v1 series
#4 lore raw
In reply to Miaohe Lin
Quoted 13 lines · Miaohe Lin

Hi all,
This series contains cleanups to remove unnecessary out label and meaningless !pte_present() check. Also use helper function to simplify the code. More details can be found in the respective changelogs. Thanks!

Miaohe Lin (3):
khugepaged: use helper function range_in_vma() in
collapse_pte_mapped_thp()
khugepaged: remove unnecessary out label in collapse_huge_page()
khugepaged: remove meaningless !pte_present() check in
khugepaged_scan_pmd()

Quoted 2 lines
 mm/khugepaged.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

All looks good to me. Thanks.

—
Best Regards,
Yan Zi