Skip to contentSkip to conversation

Convert __unmap_hugepage_range() to folios

PATCH In review Vishal Moola (Oracle) 2 participants 4 messages May 20, 2024 – Jun 3, 2024

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

PATCH 1/1 Convert __unmap_hugepage_range() to folios

Replaces 4 calls to compound_head() with one. Also converts unmap_hugepage_range() and unmap_ref_private() to take in folios.

---
 include/linux/hugetlb.h |  6 ++---
 mm/hugetlb.c            | 50 ++++++++++++++++++++---------------------
 2 files changed, 28 insertions(+), 28 deletions(-)
include/linux/hugetlb.h +3 -3
index 68244bb3637a..6c7ce8679950 100644
@@ -137,12 +137,12 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma,
 				      unsigned long address, unsigned int flags,
 				      unsigned int *page_mask);
 void unmap_hugepage_range(struct vm_area_struct *,
-			  unsigned long, unsigned long, struct page *,
+			  unsigned long, unsigned long, struct folio *,
 			  zap_flags_t);
 void __unmap_hugepage_range(struct mmu_gather *tlb,
 			  struct vm_area_struct *vma,
 			  unsigned long start, unsigned long end,
-			  struct page *ref_page, zap_flags_t zap_flags);
+			  struct folio *ref_folio, zap_flags_t zap_flags);
 void hugetlb_report_meminfo(struct seq_file *);
 int hugetlb_report_node_meminfo(char *buf, int len, int nid);
 void hugetlb_show_meminfo_node(int nid);
@@ -458,7 +458,7 @@ static inline long hugetlb_change_protection(
 
 static inline void __unmap_hugepage_range(struct mmu_gather *tlb,
 			struct vm_area_struct *vma, unsigned long start,
-			unsigned long end, struct page *ref_page,
+			unsigned long end, struct folio *ref_folio,
 			zap_flags_t zap_flags)
 {
 	BUG();
mm/hugetlb.c +25 -25

142 lines not on this page · raw message

Signature · 1 line
2.45.0
#1 lore raw
Quoted 2 lines · Vishal Moola (Oracle)

Replaces 4 calls to compound_head() with one. Also converts unmap_hugepage_range() and unmap_ref_private() to take in folios.

This is great!

Quoted 4 lines

void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,

mm/hugetlb.c +1 -1
 			    unsigned long start, unsigned long end,
-			    struct page *ref_page, zap_flags_t zap_flags)
+			    struct folio *ref_folio, zap_flags_t zap_flags)

mm/hugetlb.c int move_hugetlb_page_tables(struct vm_area_struct *vma, · line 5655

Quoted 10 lines
mm/hugetlb.c +1 -1
 {
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long address;
 	pte_t *ptep;
 	pte_t pte;
 	spinlock_t *ptl;
-	struct page *page;
+	struct folio *folio;
 	struct hstate *h = hstate_vma(vma);
 	unsigned long sz = huge_page_size(h);

I would appreciate some further cleanup ...

	size_t sz = folio_size(folio);

I think there are further cleanups along those lines, eg pages_per_huge_page(), hugetlb_mask_last_page(), huge_page_mask().

#2 lore raw
Quoted 22 lines · Matthew Wilcox
Quoted 2 lines · Vishal Moola (Oracle)

Replaces 4 calls to compound_head() with one. Also converts unmap_hugepage_range() and unmap_ref_private() to take in folios.

This is great!

Quoted 4 lines

void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
unsigned long start, unsigned long end,

mm/hugetlb.c +1 -1
-                         struct page *ref_page, zap_flags_t zap_flags)
+                         struct folio *ref_folio, zap_flags_t zap_flags)

mm/hugetlb.c int move_hugetlb_page_tables(struct vm_area_struct *vma, · line 5655

Quoted 10 lines
mm/hugetlb.c +1 -1
 {
      struct mm_struct *mm = vma->vm_mm;
      unsigned long address;
      pte_t *ptep;
      pte_t pte;
      spinlock_t *ptl;
-     struct page *page;
+     struct folio *folio;
      struct hstate *h = hstate_vma(vma);
      unsigned long sz = huge_page_size(h);
Quoted 7 lines

I would appreciate some further cleanup ...

        size_t sz = folio_size(folio);

I think there are further cleanups along those lines, eg pages_per_huge_page(), hugetlb_mask_last_page(), huge_page_mask().

Gotcha, I'll look into those and change them in v2.

#3 lore raw
Quoted 26 lines · Vishal Moola
Quoted 24 lines · Matthew Wilcox
Quoted 2 lines · Vishal Moola (Oracle)

Replaces 4 calls to compound_head() with one. Also converts unmap_hugepage_range() and unmap_ref_private() to take in folios.

This is great!

Quoted 4 lines

void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
unsigned long start, unsigned long end,

mm/hugetlb.c +1 -1
-                         struct page *ref_page, zap_flags_t zap_flags)
+                         struct folio *ref_folio, zap_flags_t zap_flags)

mm/hugetlb.c int move_hugetlb_page_tables(struct vm_area_struct *vma, · line 5655

Quoted 10 lines
mm/hugetlb.c +1 -1
 {
      struct mm_struct *mm = vma->vm_mm;
      unsigned long address;
      pte_t *ptep;
      pte_t pte;
      spinlock_t *ptl;
-     struct page *page;
+     struct folio *folio;
      struct hstate *h = hstate_vma(vma);
      unsigned long sz = huge_page_size(h);

I would appreciate some further cleanup ...

Quoted 7 lines
Quoted 5 lines
        size_t sz = folio_size(folio);

I think there are further cleanups along those lines, eg pages_per_huge_page(), hugetlb_mask_last_page(), huge_page_mask().

Gotcha, I'll look into those and change them in v2.

I took a closer look at your suggestions for cleanups here. Most callers of unmap_hugepage_range() pass NULL as ref_folio - meaning we want to unmap all pages in the range. This means alot of the preparatory work is likely done without
a reference to a folio, so using folio_size() is unsafe.

For when we later have a reference to a folio, I think we should continue to use the
hstate-defined values since using the folio in one place and hstate in another makes
things harder to change (if we ever want to).