[PATCH 28/60] mm: select memory features per node

From: Gregory Price via B4 Relay

Date: Fri Nov 20 2026 - 13:18:14 EST


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

Whether a node's memory is common or private is a property of the
memory, so record it per node.

Add a per-node memory feature mask (pgdat->memory_features) with a
single bit for common memory. Node states are published from the node's
features at boot and when memory is onlined. A node without the common
bit joins N_MEMORY_PRIVATE.

Ordinary System RAM carries every feature. Without NUMA, node 0 holds
all memory, so a mask without common memory is invalid.

Every node keeps the default mask, so all memory remains common.

Suggested-by: Dan J Williams <djbw@xxxxxxxxxx>
Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
include/linux/mmzone.h | 1 +
include/linux/nodemask.h | 12 ++++++++++++
mm/internal.h | 2 +-
mm/memory_hotplug.c | 2 +-
mm/mm_init.c | 7 ++++++-
mm/page_alloc.c | 9 +++++++--
6 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 6a2ad0cff795..d6c1a43c0bc8 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -1612,6 +1612,7 @@ typedef struct pglist_data {
#ifdef CONFIG_MEMORY_FAILURE
struct memory_failure_stats mf_stats;
#endif
+ unsigned long memory_features; /* NODE_MEMORY_FEAT_* mask */
} pg_data_t;

#define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages)
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index 5a9722d57701..02908ef23a62 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -542,6 +542,18 @@ static __always_inline int node_random(const nodemask_t *maskp)
#define for_each_online_node(node) for_each_node_state(node, N_ONLINE)
#define for_each_node_with_cpus(node) for_each_node_state(node, N_CPU)

+/* Private nodes omit NODE_MEMORY_FEAT_COMMON. */
+#define NODE_MEMORY_FEAT_COMMON BIT(0) /* add to fallback zonelist */
+#define NODE_MEMORY_FEAT_ALL NODE_MEMORY_FEAT_COMMON
+
+/* Private memory needs NUMA: node 0 holds all memory without it. */
+static inline bool node_memory_features_valid(unsigned long features)
+{
+ if (features & ~NODE_MEMORY_FEAT_ALL)
+ return false;
+ return IS_ENABLED(CONFIG_NUMA) || (features & NODE_MEMORY_FEAT_COMMON);
+}
+
/*
* For nodemask scratch area.
* NODEMASK_ALLOC(type, name) allocates an object with a specified type and
diff --git a/mm/internal.h b/mm/internal.h
index cd0562f0b68f..e89dd1153662 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -62,7 +62,7 @@ void lru_add_drain_cpu_zone(struct zone *zone);
void folio_deactivate(struct folio *folio);
void folio_mark_lazyfree(struct folio *folio);

-void node_set_memory_state(int nid);
+void node_set_memory_state(int nid, unsigned long features);
void node_clear_memory_state(int nid);

/*
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 6b6873cfbc5a..b4d94021d46e 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1197,7 +1197,7 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
adjust_present_page_count(pfn_to_page(pfn), group, nr_pages);

if (node_arg.nid >= 0)
- node_set_memory_state(nid);
+ node_set_memory_state(nid, NODE_DATA(nid)->memory_features);
/*
* Check whether we are adding normal memory to the node for the first
* time.
diff --git a/mm/mm_init.c b/mm/mm_init.c
index f21b3dbcc92a..99a45fd04ac5 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1585,6 +1585,9 @@ int __ref free_area_init_core_hotplug(struct pglist_data *pgdat)
pgdat->node_start_pfn = 0;
pgdat->node_present_pages = 0;

+ /* memory is common unless marked private */
+ pgdat->memory_features = NODE_MEMORY_FEAT_ALL;
+
/*
* Hot-unplug can leave per-cpu vmstat deltas unfolded (folders skip
* offline nodes) - reconcile this at online. Foreign access to counters
@@ -1743,6 +1746,8 @@ static void __init free_area_init_node(int nid)

pgdat->node_id = nid;
pgdat->node_start_pfn = start_pfn;
+ /* memory is common unless marked private */
+ pgdat->memory_features = NODE_MEMORY_FEAT_ALL;

if (start_pfn != end_pfn) {
pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,
@@ -1768,7 +1773,7 @@ static void __init check_for_memory(pg_data_t *pgdat)
{
enum zone_type zone_type;

- node_set_memory_state(pgdat->node_id);
+ node_set_memory_state(pgdat->node_id, pgdat->memory_features);

for (zone_type = 0; zone_type <= ZONE_MOVABLE - 1; zone_type++) {
struct zone *zone = &pgdat->node_zones[zone_type];
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 50336eb58edf..3a7c12fec906 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -209,10 +209,15 @@ nodemask_t node_states[NR_NODE_STATES] __read_mostly = {
};
EXPORT_SYMBOL(node_states);

-void __meminit node_set_memory_state(int nid)
+void __meminit node_set_memory_state(int nid, unsigned long features)
{
+ WARN_ON_ONCE(!node_memory_features_valid(features));
+
node_set_state(nid, N_MEMORY);
- node_set_state(nid, N_MEMORY_COMMON);
+ if (features & NODE_MEMORY_FEAT_COMMON)
+ node_set_state(nid, N_MEMORY_COMMON);
+ else
+ node_set_state(nid, N_MEMORY_PRIVATE);
}

void __meminit node_clear_memory_state(int nid)

--
2.56.1