[PATCH 50/60] mm: add N_MEMORY_MEMPOLICY node state
From: Gregory Price via B4 Relay
Date: Fri Nov 20 2026 - 13:22:14 EST
From: "Gregory Price (Meta)" <gourry@xxxxxxxxxx>
Add N_MEMORY_MEMPOLICY as an internal state for the nodes that memory
policy interfaces and explicit migration may target, and
NODE_MEMORY_FEAT_MEMPOLICY for memory providers to select it.
Userspace placement lets ordinary processes use the node like any other
memory. That assumes the node is reclaimed and compacted, so the feature
requires both.
Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
Documentation/mm/physical_memory.rst | 3 +++
include/linux/nodemask.h | 11 +++++++++--
mm/page_alloc.c | 4 ++++
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/Documentation/mm/physical_memory.rst b/Documentation/mm/physical_memory.rst
index 1bafe8c085a3..75752c3a5694 100644
--- a/Documentation/mm/physical_memory.rst
+++ b/Documentation/mm/physical_memory.rst
@@ -190,6 +190,8 @@ The following states are internal and not exported through sysfs:
``N_MEMORY_RECLAIM``
The kernel reclaims the node on its own initiative (kswapd, memcg and
explicit reclaim).
+``N_MEMORY_MEMPOLICY``
+ Memory-policy interfaces and explicit migration may target the node.
For each node that has a property described above, the bit corresponding to the
node ID in the ``node_states[<property>]`` bitmask is set.
@@ -205,6 +207,7 @@ For example, for node 2 with normal memory and CPUs, bit 2 will be set in ::
node_states[N_CPU]
node_states[N_MEMORY_COMPACTION]
node_states[N_MEMORY_RECLAIM]
+ node_states[N_MEMORY_MEMPOLICY]
For various operations possible with nodemasks please refer to
``include/linux/nodemask.h``.
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index be5edbee2b22..c7a1800d9171 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -414,6 +414,7 @@ enum node_states {
/* Internal states, not exported through sysfs */
N_MEMORY_COMPACTION, /* mm compaction may operate on the node */
N_MEMORY_RECLAIM, /* mm reclaim may operate on the node */
+ N_MEMORY_MEMPOLICY, /* memory policy may target the node */
NR_NODE_STATES
};
@@ -552,14 +553,17 @@ static __always_inline int node_random(const nodemask_t *maskp)
#define NODE_MEMORY_FEAT_COMMON BIT(0) /* add to fallback zonelist */
#define NODE_MEMORY_FEAT_COMPACTION BIT(1) /* mm compaction */
#define NODE_MEMORY_FEAT_RECLAIM BIT(2) /* mm reclaim */
+#define NODE_MEMORY_FEAT_MEMPOLICY BIT(3) /* userspace NUMA controls */
#define NODE_MEMORY_FEAT_ALL (NODE_MEMORY_FEAT_COMMON | \
NODE_MEMORY_FEAT_COMPACTION | \
- NODE_MEMORY_FEAT_RECLAIM)
+ NODE_MEMORY_FEAT_RECLAIM | \
+ NODE_MEMORY_FEAT_MEMPOLICY)
/*
* Common memory carries every feature. Private memory needs NUMA: node 0
* holds all memory without it. Reclaim leaves high-order requests to
- * compaction, so it requires compaction.
+ * compaction, so it requires compaction. Userspace placement assumes the
+ * node is reclaimed and compacted like any other memory.
*/
static inline bool node_memory_features_valid(unsigned long features)
{
@@ -570,6 +574,9 @@ static inline bool node_memory_features_valid(unsigned long features)
if ((features & NODE_MEMORY_FEAT_RECLAIM) &&
!(features & NODE_MEMORY_FEAT_COMPACTION))
return false;
+ if ((features & NODE_MEMORY_FEAT_MEMPOLICY) &&
+ !(features & NODE_MEMORY_FEAT_RECLAIM))
+ return false;
return IS_ENABLED(CONFIG_NUMA);
}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index cc70e1b45322..eff9c3d8251f 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -206,6 +206,7 @@ nodemask_t node_states[NR_NODE_STATES] __read_mostly = {
[N_MEMORY_COMMON] = { { [0] = 1UL } },
[N_MEMORY_COMPACTION] = { { [0] = 1UL } },
[N_MEMORY_RECLAIM] = { { [0] = 1UL } },
+ [N_MEMORY_MEMPOLICY] = { { [0] = 1UL } },
[N_CPU] = { { [0] = 1UL } },
#endif /* NUMA */
};
@@ -224,10 +225,13 @@ void __meminit node_set_memory_state(int nid, unsigned long features)
node_set_state(nid, N_MEMORY_COMPACTION);
if (features & NODE_MEMORY_FEAT_RECLAIM)
node_set_state(nid, N_MEMORY_RECLAIM);
+ if (features & NODE_MEMORY_FEAT_MEMPOLICY)
+ node_set_state(nid, N_MEMORY_MEMPOLICY);
}
void __meminit node_clear_memory_state(int nid)
{
+ node_clear_state(nid, N_MEMORY_MEMPOLICY);
node_clear_state(nid, N_MEMORY_RECLAIM);
node_clear_state(nid, N_MEMORY_COMPACTION);
node_clear_state(nid, N_MEMORY_PRIVATE);
--
2.56.1