[PATCH v3 15/26] mm/page_alloc: add support for freetypes with no freelist

From: Brendan Jackman

Date: Sun Jul 26 2026 - 18:24:43 EST


Freetypes are currently just a wrapper for migratetypes, but in a later
patch they will gain flags. The theoretically possible space of
freetypes will thus grow, but many freetypes will not actually be used
in practice.

To avoid bloating structures that contain arrays of freelists, mark
freetype_idx() as possibly returning -1, and add handling of this case
to code paths that will look up freelists by freetype (unless those
paths "know" that they're operating on a freetype that has a
valid freetype_idx).

It never actually returns -1 yet, this is just introduced as a separate
patch to make review easier.

Signed-off-by: Brendan Jackman <jackmanb@xxxxxxxxxx>
---
include/linux/freetype.h | 3 ++-
mm/page_alloc.c | 13 +++++++++++--
mm/page_isolation.c | 6 ++++++
3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/include/linux/freetype.h b/include/linux/freetype.h
index b16dcd58e184c..3b0d44023b6a1 100644
--- a/include/linux/freetype.h
+++ b/include/linux/freetype.h
@@ -73,7 +73,8 @@ typedef struct {
} freetype_t;

/*
- * Return a dense linear index for freetypes.
+ * Return a dense linear index for freetypes that have lists in the free area.
+ * Return -1 for other freetypes.
*/
static inline int freetype_idx(freetype_t freetype)
{
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 60aedd0e78b54..4965019dc2286 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1963,6 +1963,9 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order,
struct free_area *area;
struct page *page;

+ if (freetype_idx(freetype) < 0)
+ return NULL;
+
/* Find a page of the appropriate size in the preferred list */
for (current_order = order; current_order < NR_PAGE_ORDERS; ++current_order) {
enum migratetype migratetype = free_to_migratetype(freetype);
@@ -2406,6 +2409,9 @@ find_suitable_fallback(struct free_area *area, unsigned int order,
*/
freetype_t fallback_ft = freetype_with_migrate(freetype, fallback_mt);

+ if (freetype_idx(fallback_ft) < 0)
+ continue;
+
if (!free_area_empty(area, fallback_ft)) {
if (ft_out)
*ft_out = fallback_ft;
@@ -3642,6 +3648,8 @@ static void reserve_highatomic_pageblock(struct page *page, int order,
static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
bool force)
{
+ freetype_t ft_high = freetype_with_migrate(ac->freetype,
+ MIGRATE_HIGHATOMIC);
struct zonelist *zonelist = ac->zonelist;
struct zoneref *z;
struct zone *zone;
@@ -3649,6 +3657,9 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
int order;
int ret;

+ if (freetype_idx(ft_high) < 0)
+ return false;
+
for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx,
ac->nodemask) {
/*
@@ -3662,8 +3673,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac,
guard(spinlock_irqsave)(&zone->lock);
for (order = 0; order < NR_PAGE_ORDERS; order++) {
struct free_area *area = &(zone->free_area[order]);
- freetype_t ft_high = freetype_with_migrate(ac->freetype,
- MIGRATE_HIGHATOMIC);
unsigned long size;

page = get_page_from_free_area(area, ft_high);
diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index f81186431d3c3..e6bd227fbf1db 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -176,6 +176,7 @@ static int set_migratetype_isolate(struct page *page, enum pb_isolate_mode mode,
struct zone *zone = page_zone(page);
struct page *unmovable;
unsigned long check_unmovable_start, check_unmovable_end;
+ freetype_t ft_isolate;

if (PageUnaccepted(page))
accept_page(page);
@@ -189,6 +190,11 @@ static int set_migratetype_isolate(struct page *page, enum pb_isolate_mode mode,
if (is_migrate_isolate_page(page))
return -EBUSY;

+ /* Do not isolate unsupported freetypes. */
+ ft_isolate = freetype_with_migrate(get_pageblock_freetype(page), MIGRATE_ISOLATE);
+ if (freetype_idx(ft_isolate) < 0)
+ return -EINVAL;
+
/*
* FIXME: Now, memory hotplug doesn't call shrink_slab() by
* itself. We just check MOVABLE pages.

--
2.54.0