[PATCH v22 3/6] mm/page_alloc: make alloc_frozen_pages() available outside of mm

From: Andreas Hindborg

Date: Wed Nov 18 2026 - 11:20:57 EST


alloc_frozen_pages() and free_frozen_pages() are declared in the private
header mm/page_alloc.h, and free_frozen_pages() is not exported. Thus,
frozen pages cannot be allocated outside of mm, and not from modules.

The Rust page abstractions need frozen pages. The reference count of a
frozen page is zero and references to it cannot be taken, so the caller
that allocates a frozen page is guaranteed by mm to be its only owner.
The Rust abstractions rely on this to hand out the data of a page as a
Rust reference.

Move the declarations of alloc_frozen_pages(),
alloc_frozen_pages_noprof() and free_frozen_pages() to
include/linux/gfp.h, and export alloc_frozen_pages_noprof() and
free_frozen_pages() with EXPORT_SYMBOL_GPL().

For !CONFIG_NUMA, alloc_frozen_pages_noprof() is a static inline function
that passes ALLOC_DEFAULT to __alloc_frozen_pages_noprof(). ALLOC_DEFAULT
is private to mm, so the function cannot move to the public header as it
is. Move it out of line to mm/page_alloc.c instead. This adds a function
call to the existing callers in mm/slub.c on !CONFIG_NUMA kernels.

Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
---
include/linux/gfp.h | 9 +++++++++
mm/mempolicy.c | 1 +
mm/page_alloc.c | 10 ++++++++++
mm/page_alloc.h | 14 --------------
4 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 63a7654c725f..7e1f24658f9e 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -302,6 +302,15 @@ static inline struct folio *vma_alloc_folio_noprof(gfp_t gfp, int order,

#define alloc_page(gfp_mask) alloc_pages(gfp_mask, 0)

+/*
+ * Allocate frozen pages. The reference count of a frozen page is zero, and
+ * references to it cannot be taken. The caller owns the pages and frees them
+ * with free_frozen_pages().
+ */
+struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order);
+#define alloc_frozen_pages(...) alloc_hooks(alloc_frozen_pages_noprof(__VA_ARGS__))
+void free_frozen_pages(struct page *page, unsigned int order);
+
static inline struct page *alloc_page_vma_noprof(gfp_t gfp,
struct vm_area_struct *vma, unsigned long addr)
{
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 0cb6da1c47a4..6d872db9fc6a 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2582,6 +2582,7 @@ struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned order)
return alloc_pages_mpol(gfp, order, pol, NO_INTERLEAVE_INDEX,
numa_node_id());
}
+EXPORT_SYMBOL_GPL(alloc_frozen_pages_noprof);

/**
* alloc_pages - Allocate pages.
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index eb4f02617f53..d6284cf965cf 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2993,6 +2993,7 @@ void free_frozen_pages(struct page *page, unsigned int order)
{
__free_frozen_pages(page, order, FPI_NONE);
}
+EXPORT_SYMBOL_GPL(free_frozen_pages);

void free_frozen_pages_nolock(struct page *page, unsigned int order)
{
@@ -5491,6 +5492,15 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,
}
EXPORT_SYMBOL(__alloc_frozen_pages_noprof);

+#ifndef CONFIG_NUMA
+struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order)
+{
+ return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL,
+ ALLOC_DEFAULT);
+}
+EXPORT_SYMBOL_GPL(alloc_frozen_pages_noprof);
+#endif
+
struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order,
int preferred_nid, nodemask_t *nodemask, unsigned int alloc_flags)
{
diff --git a/mm/page_alloc.h b/mm/page_alloc.h
index 7097ea1805f6..541fa8b3f532 100644
--- a/mm/page_alloc.h
+++ b/mm/page_alloc.h
@@ -237,22 +237,8 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, int nid,
nodemask_t *nodemask, unsigned int alloc_flags);
#define __alloc_frozen_pages(...) \
alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__))
-void free_frozen_pages(struct page *page, unsigned int order);
void free_unref_folios(struct folio_batch *fbatch);

-#ifdef CONFIG_NUMA
-struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order);
-#else
-static inline struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order)
-{
- return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL,
- ALLOC_DEFAULT);
-}
-#endif
-
-#define alloc_frozen_pages(...) \
- alloc_hooks(alloc_frozen_pages_noprof(__VA_ARGS__))
-
struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order);
#define alloc_frozen_pages_nolock(...) \
alloc_hooks(alloc_frozen_pages_nolock_noprof(__VA_ARGS__))

--
2.54.0