[PATCH 08/22] mm/memory-tiers: restrict demotion topology to common memory

From: Gregory Price (Meta)

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


Memory outside N_MEMORY_COMMON is outside the ordinary allocation pool
and cannot be a generic demotion source or destination.

Build demotion paths and the default DRAM performance reference from
N_MEMORY_COMMON rather than every node that has memory, and do not
assign other nodes to a memory tier through the generic hotplug path.

Removing a node's memory already resets its demotion targets, so a node
that unplugs and returns outside N_MEMORY_COMMON keeps none.

All memory nodes currently carry N_MEMORY_COMMON, behavior is unchanged.

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

diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 7fc56a8c66518..97d5ecefd89f3 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -370,7 +370,8 @@ int next_demotion_node(int node, const nodemask_t *allowed_mask)
* closest demotion target.
*/
nodes_complement(mask, *allowed_mask);
- return find_next_best_node_in(node, &mask, &node_states[N_MEMORY]);
+ return find_next_best_node_in(node, &mask,
+ &node_states[N_MEMORY_COMMON]);
}

static void disable_all_demotion_targets(void)
@@ -405,7 +406,7 @@ static void dump_demotion_targets(void)
{
int node;

- for_each_node_state(node, N_MEMORY) {
+ for_each_node_state(node, N_MEMORY_COMMON) {
struct memory_tier *memtier = __node_get_memory_tier(node);
nodemask_t preferred = node_demotion[node].preferred;

@@ -441,7 +442,7 @@ static void establish_demotion_targets(void)

disable_all_demotion_targets();

- for_each_node_state(node, N_MEMORY) {
+ for_each_node_state(node, N_MEMORY_COMMON) {
best_distance = -1;
nd = &node_demotion[node];

@@ -459,7 +460,7 @@ static void establish_demotion_targets(void)
* nodelist to skip list so that we find the best node from the
* memtier nodelist.
*/
- nodes_andnot(tier_nodes, node_states[N_MEMORY], tier_nodes);
+ nodes_andnot(tier_nodes, node_states[N_MEMORY_COMMON], tier_nodes);

/*
* Find all the nodes in the memory tier node list of same best distance.
@@ -468,7 +469,7 @@ static void establish_demotion_targets(void)
*/
do {
target = find_next_best_node_in(node, &tier_nodes,
- &node_states[N_MEMORY]);
+ &node_states[N_MEMORY_COMMON]);
if (target == NUMA_NO_NODE)
break;

@@ -507,7 +508,7 @@ static void establish_demotion_targets(void)
* allocation to a set of nodes that is closer the above selected
* preferred node.
*/
- lower_tier = node_states[N_MEMORY];
+ lower_tier = node_states[N_MEMORY_COMMON];
list_for_each_entry(memtier, &memory_tiers, list) {
/*
* Keep removing current tier from lower_tier nodes,
@@ -554,7 +555,7 @@ static struct memory_tier *set_node_memory_tier(int node)

lockdep_assert_held_once(&memory_tier_lock);

- if (!node_state(node, N_MEMORY))
+ if (!node_state(node, N_MEMORY_COMMON))
return ERR_PTR(-EINVAL);

mt_calc_adistance(node, &adist);
@@ -706,8 +707,8 @@ static int __init memory_tier_late_init(void)
get_online_mems();
guard(mutex)(&memory_tier_lock);

- /* Assign each uninitialized N_MEMORY node to a memory tier. */
- for_each_node_state(nid, N_MEMORY) {
+ /* Assign each uninitialized common memory node to a memory tier. */
+ for_each_node_state(nid, N_MEMORY_COMMON) {
/*
* Some device drivers may have initialized
* memory tiers, potentially bringing memory nodes
@@ -929,8 +930,8 @@ static int __init memory_tier_init(void)
if (IS_ERR(default_dram_type))
panic("%s() failed to allocate default DRAM tier\n", __func__);

- /* Record nodes with memory and CPU to set default DRAM performance. */
- nodes_and(default_dram_nodes, node_states[N_MEMORY],
+ /* Record common-memory nodes with CPUs for default DRAM performance. */
+ nodes_and(default_dram_nodes, node_states[N_MEMORY_COMMON],
node_states[N_CPU]);

hotplug_node_notifier(memtier_hotplug_callback, MEMTIER_HOTPLUG_PRI);
--
2.53.1-Meta