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

From: Gregory Price (Meta)

Date: Sat Nov 14 2026 - 02:11:07 EST


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 use reuse the code to build
a local-only zonelist for nodes outside the N_MEMORY_COMMON set later.

Every node with memory is common, and a memoryless node has no zones to
list, so the zonelists are unchanged.

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 6ffa972811462..580feeb608b7a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5906,17 +5906,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;
}
@@ -5960,8 +5957,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.53.1-Meta