[PATCH v2 20/25] mm: Make prep_transhuge_page return its argument
From: Matthew Wilcox
Date: Tue Feb 11 2020 - 23:18:52 EST
From: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx>
By permitting NULL or order-0 pages as an argument, and returning the
argument, callers can write:
return prep_transhuge_page(alloc_pages(...));
instead of assigning the result to a temporary variable and conditionally
passing that to prep_transhuge_page().
Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>
Acked-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
---
include/linux/huge_mm.h | 7 +++++--
mm/huge_memory.c | 9 +++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 3de788ee25bd..865b9c16c99c 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -158,7 +158,7 @@ extern unsigned long thp_get_unmapped_area(struct file *filp,
unsigned long addr, unsigned long len, unsigned long pgoff,
unsigned long flags);
-extern void prep_transhuge_page(struct page *page);
+extern struct page *prep_transhuge_page(struct page *page);
extern void free_transhuge_page(struct page *page);
bool is_transparent_hugepage(struct page *page);
@@ -307,7 +307,10 @@ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
return false;
}
-static inline void prep_transhuge_page(struct page *page) {}
+static inline struct page *prep_transhuge_page(struct page *page)
+{
+ return page;
+}
static inline bool is_transparent_hugepage(struct page *page)
{
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index b08b199f9a11..b52e007f0856 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -508,15 +508,20 @@ static inline struct deferred_split *get_deferred_split_queue(struct page *page)
}
#endif
-void prep_transhuge_page(struct page *page)
+struct page *prep_transhuge_page(struct page *page)
{
+ if (!page || compound_order(page) == 0)
+ return page;
/*
- * we use page->mapping and page->indexlru in second tail page
+ * we use page->mapping and page->index in second tail page
* as list_head: assuming THP order >= 2
*/
+ BUG_ON(compound_order(page) == 1);
INIT_LIST_HEAD(page_deferred_list(page));
set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR);
+
+ return page;
}
bool is_transparent_hugepage(struct page *page)
--
2.25.0