diff mbox series

[2/7] khugepaged: Convert alloc_charge_hpage to alloc_charge_folio

Message ID 20240403171838.1445826-3-willy@infradead.org (mailing list archive)
State New
Headers show
Series khugepaged folio conversions | expand

Commit Message

Matthew Wilcox (Oracle) April 3, 2024, 5:18 p.m. UTC
Both callers want to deal with a folio, so return a folio from
this function.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 mm/khugepaged.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Vishal Moola April 5, 2024, 9:14 p.m. UTC | #1
On Wed, Apr 03, 2024 at 06:18:31PM +0100, Matthew Wilcox (Oracle) wrote:  
> @@ -1789,7 +1789,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
>  	struct page *hpage;
>  	struct page *page;
>  	struct page *tmp;
> -	struct folio *folio;
> +	struct folio *folio, *new_folio;

Would it make more sense to introduce new_folio in patch 5 where
you convert the rest of the function to use new_folio? I think it
might make the commit history easier to read.
Matthew Wilcox (Oracle) April 7, 2024, 3:44 a.m. UTC | #2
On Fri, Apr 05, 2024 at 02:14:10PM -0700, Vishal Moola wrote:
> On Wed, Apr 03, 2024 at 06:18:31PM +0100, Matthew Wilcox (Oracle) wrote:  
> > @@ -1789,7 +1789,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
> >  	struct page *hpage;
> >  	struct page *page;
> >  	struct page *tmp;
> > -	struct folio *folio;
> > +	struct folio *folio, *new_folio;
> 
> Would it make more sense to introduce new_folio in patch 5 where
> you convert the rest of the function to use new_folio? I think it
> might make the commit history easier to read. 

I went back and forth on that a few times.  I ended up deciding that
it didn't really help.
diff mbox series

Patch

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index ad16dd8b26a8..2f1dacd65d12 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1045,7 +1045,7 @@  static int __collapse_huge_page_swapin(struct mm_struct *mm,
 	return result;
 }
 
-static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm,
+static int alloc_charge_folio(struct folio **foliop, struct mm_struct *mm,
 			      struct collapse_control *cc)
 {
 	gfp_t gfp = (cc->is_khugepaged ? alloc_hugepage_khugepaged_gfpmask() :
@@ -1055,7 +1055,7 @@  static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm,
 
 	folio = __folio_alloc(gfp, HPAGE_PMD_ORDER, node, &cc->alloc_nmask);
 	if (!folio) {
-		*hpage = NULL;
+		*foliop = NULL;
 		count_vm_event(THP_COLLAPSE_ALLOC_FAILED);
 		return SCAN_ALLOC_HUGE_PAGE_FAIL;
 	}
@@ -1063,13 +1063,13 @@  static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm,
 	count_vm_event(THP_COLLAPSE_ALLOC);
 	if (unlikely(mem_cgroup_charge(folio, mm, gfp))) {
 		folio_put(folio);
-		*hpage = NULL;
+		*foliop = NULL;
 		return SCAN_CGROUP_CHARGE_FAIL;
 	}
 
 	count_memcg_folio_events(folio, THP_COLLAPSE_ALLOC, 1);
 
-	*hpage = folio_page(folio, 0);
+	*foliop = folio;
 	return SCAN_SUCCEED;
 }
 
@@ -1098,7 +1098,8 @@  static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
 	 */
 	mmap_read_unlock(mm);
 
-	result = alloc_charge_hpage(&hpage, mm, cc);
+	result = alloc_charge_folio(&folio, mm, cc);
+	hpage = &folio->page;
 	if (result != SCAN_SUCCEED)
 		goto out_nolock;
 
@@ -1204,7 +1205,6 @@  static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
 	if (unlikely(result != SCAN_SUCCEED))
 		goto out_up_write;
 
-	folio = page_folio(hpage);
 	/*
 	 * The smp_wmb() inside __folio_mark_uptodate() ensures the
 	 * copy_huge_page writes become visible before the set_pmd_at()
@@ -1789,7 +1789,7 @@  static int collapse_file(struct mm_struct *mm, unsigned long addr,
 	struct page *hpage;
 	struct page *page;
 	struct page *tmp;
-	struct folio *folio;
+	struct folio *folio, *new_folio;
 	pgoff_t index = 0, end = start + HPAGE_PMD_NR;
 	LIST_HEAD(pagelist);
 	XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
@@ -1800,7 +1800,8 @@  static int collapse_file(struct mm_struct *mm, unsigned long addr,
 	VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
 	VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
 
-	result = alloc_charge_hpage(&hpage, mm, cc);
+	result = alloc_charge_folio(&new_folio, mm, cc);
+	hpage = &new_folio->page;
 	if (result != SCAN_SUCCEED)
 		goto out;