[PATCH 04/60] mm/page_alloc: build zonelists from common memory

From: Gregory Price via B4 Relay

Date: Fri Nov 20 2026 - 13:10:50 EST


From: "Gregory Price (Meta)" <gourry@xxxxxxxxxx>

Zonelists decide which nodes an allocation can reach.

The fallback lists hold every node in N_MEMORY, and a node's
__GFP_THISNODE list holds its own zones whatever the node's state.

Ordinary allocations should reach only common (general purpose) memory.

Build the fallback zonelists from N_MEMORY_COMMON, and __GFP_THISNODE
zonelists only for a common node.

The build_local_zonelist() refactor lets us reuse the code to build
a local-only zonelist for nodes outside the N_MEMORY_COMMON set later.

Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
mm/page_alloc.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index ddb04b72a160..0448d04e048a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5947,17 +5947,14 @@ int find_next_best_node_in(int node, nodemask_t *used_node_mask,
}


-/*
- * Build __GFP_THISNODE zonelists
- */
-static void build_thisnode_zonelists(pg_data_t *pgdat)
+/* Build a local-only zonelist when this node is eligible. */
+static void build_local_zonelist(pg_data_t *pgdat, int zlidx, bool eligible)
{
- struct zoneref *zonerefs;
- int nr_zones;
+ struct zoneref *zonerefs =
+ pgdat->node_zonelists[zlidx]._zonerefs;

- zonerefs = pgdat->node_zonelists[ZONELIST_NOFALLBACK]._zonerefs;
- nr_zones = build_zonerefs_node(pgdat, zonerefs);
- zonerefs += nr_zones;
+ if (eligible)
+ zonerefs += build_zonerefs_node(pgdat, zonerefs);
zonerefs->zone = NULL;
zonerefs->zone_idx = 0;
}
@@ -6001,8 +5998,12 @@ static void build_node_zonelist(pg_data_t *pgdat, const nodemask_t *candidates,

static void build_zonelists(pg_data_t *pgdat)
{
- build_node_zonelist(pgdat, &node_states[N_MEMORY], ZONELIST_FALLBACK);
- build_thisnode_zonelists(pgdat);
+ int nid = pgdat->node_id;
+
+ build_node_zonelist(pgdat, &node_states[N_MEMORY_COMMON],
+ ZONELIST_FALLBACK);
+ build_local_zonelist(pgdat, ZONELIST_NOFALLBACK,
+ node_state(nid, N_MEMORY_COMMON));
}

#ifdef CONFIG_HAVE_MEMORYLESS_NODES

--
2.56.1