Skip to contentSkip to conversation

mm/thp: make set_huge_zero_page() return void

PATCH NAK Ralph Campbell 2 participants 3 messages Sep 30, 2019 – Oct 1, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/thp: make set_huge_zero_page() return void

The return value from set_huge_zero_page() is never checked so simplify the code by making it return void.

---
 mm/huge_memory.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/huge_memory.c +2 -4
index c5cb6dcd6c69..6cf0ee65538d 100644
@@ -686,20 +686,18 @@ static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma)
 }
 
 /* Caller must hold page table lock. */
-static bool set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
+static void set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
 		struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd,
 		struct page *zero_page)
 {
 	pmd_t entry;
-	if (!pmd_none(*pmd))
-		return false;
+
 	entry = mk_pmd(zero_page, vma->vm_page_prot);
 	entry = pmd_mkhuge(entry);
 	if (pgtable)
 		pgtable_trans_huge_deposit(mm, pmd, pgtable);
 	set_pmd_at(mm, haddr, pmd, entry);
 	mm_inc_nr_ptes(mm);
-	return true;
 }
 
 vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
Signature · 1 line
2.20.1
#1 lore raw
Quoted 15 lines · Ralph Campbell

The return value from set_huge_zero_page() is never checked so simplify the code by making it return void.

---
 mm/huge_memory.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/huge_memory.c +0 -0
index c5cb6dcd6c69..6cf0ee65538d 100644
@@ -686,20 +686,18 @@ static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma)
 }
 

mm/huge_memory.c static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma) · line 694

Quoted 10 lines
mm/huge_memory.c +2 -3
 /* Caller must hold page table lock. */
-static bool set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
+static void set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
 		struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd,
 		struct page *zero_page)
 {
 	pmd_t entry;
-	if (!pmd_none(*pmd))
-		return false;
+

Wat? So you just bindly overwrite whatever is there?

NAK.

Quoted 14 lines
mm/huge_memory.c +0 -1
 	entry = mk_pmd(zero_page, vma->vm_page_prot);
 	entry = pmd_mkhuge(entry);
 	if (pgtable)
 		pgtable_trans_huge_deposit(mm, pmd, pgtable);
 	set_pmd_at(mm, haddr, pmd, entry);
 	mm_inc_nr_ptes(mm);
-	return true;
 }
 
 vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
Signature · 1 line
2.20.1
Signature · 1 line
 Kirill A. Shutemov
#2 lore raw
Quoted 29 lines · Kirill A. Shutemov
Quoted 15 lines · Ralph Campbell

The return value from set_huge_zero_page() is never checked so simplify the code by making it return void.

---
  mm/huge_memory.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
mm/huge_memory.c +0 -0
index c5cb6dcd6c69..6cf0ee65538d 100644
@@ -686,20 +686,18 @@ static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma)
  }
 

mm/huge_memory.c static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma) · line 694

Quoted 10 lines
mm/huge_memory.c +2 -3
  /* Caller must hold page table lock. */
-static bool set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
+static void set_huge_zero_page(pgtable_t pgtable, struct mm_struct *mm,
  		struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd,
  		struct page *zero_page)
  {
  	pmd_t entry;
-	if (!pmd_none(*pmd))
-		return false;
+

Wat? So you just bindly overwrite whatever is there?

Quoted 1 line

NAK.

No, the only two places it is called from are do_huge_pmd_anonymous_page() which has the pmd_lock() and already checked pmd_none() is true and
copy_huge_pmd() where the destination page table
is being filled in with no other threads accessing it.
I guess I should have put this analysis in the changelog.

Still, I guess putting a pmd_none() check in copy_huge_pmd() as future proofing new callers of copy_huge_pmd() would make sense.

Quoted 15 lines
Quoted 14 lines
mm/huge_memory.c +0 -1
  	entry = mk_pmd(zero_page, vma->vm_page_prot);
  	entry = pmd_mkhuge(entry);
  	if (pgtable)
  		pgtable_trans_huge_deposit(mm, pmd, pgtable);
  	set_pmd_at(mm, haddr, pmd, entry);
  	mm_inc_nr_ptes(mm);
-	return true;
  }
 
  vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
Signature · 1 line
2.20.1