From fadfe565253af0b19b3909bd10ef030a5eefce6c Mon Sep 17 00:00:00 2001 From: "Matthew Wilcox (Oracle)" Date: Tue, 14 Jun 2022 16:47:57 -0400 Subject: [PATCH] mm/page_alloc: Add __alloc_frozen_pages() Defer the initialisation of the page refcount to the new __alloc_pages() wrapper and turn the old __alloc_pages() into __alloc_frozen_pages(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/internal.h | 2 ++ mm/page_alloc.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index e74441b4cca0b..66ea73fbb5b99 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -382,6 +382,8 @@ extern void post_alloc_hook(struct page *page, unsigned int order, gfp_t gfp_flags); extern int user_min_free_kbytes; +struct page *__alloc_frozen_pages(gfp_t, unsigned int order, int nid, + nodemask_t *); void free_frozen_pages(struct page *, unsigned int order); void free_unref_page_list(struct list_head *list); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 810990618186d..7314679d0b7a3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5513,8 +5513,8 @@ EXPORT_SYMBOL_GPL(__alloc_pages_bulk); /* * This is the 'heart' of the zoned buddy allocator. */ -struct page *__alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid, - nodemask_t *nodemask) +struct page *__alloc_frozen_pages(gfp_t gfp, unsigned int order, + int preferred_nid, nodemask_t *nodemask) { struct page *page; unsigned int alloc_flags = ALLOC_WMARK_LOW; @@ -5570,14 +5570,23 @@ out: free_frozen_pages(page, order); page = NULL; } - if (page) - set_page_refcounted(page); trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype); kmsan_alloc_page(page, order, alloc_gfp); return page; } + +struct page *__alloc_pages(gfp_t gfp, unsigned int order, int preferred_nid, + nodemask_t *nodemask) +{ + struct page *page; + + page = __alloc_frozen_pages(gfp, order, preferred_nid, nodemask); + if (page) + set_page_refcounted(page); + return page; +} EXPORT_SYMBOL(__alloc_pages); struct folio *__folio_alloc(gfp_t gfp, unsigned int order, int preferred_nid, -- 2.50.1