[PATCH 46/60] mm: add N_MEMORY_RECLAIM node state

From: Gregory Price via B4 Relay

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


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

Add N_MEMORY_RECLAIM as an internal state for the nodes page reclaim
may operate on, and NODE_MEMORY_FEAT_RECLAIM for memory providers to
select it.

Reclaim frees order-0 pages and leaves high-order requests to
compaction, so a private node that permits reclaim must permit
compaction too.

Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
Documentation/mm/physical_memory.rst | 4 ++++
include/linux/nodemask.h | 11 +++++++++--
mm/page_alloc.c | 4 ++++
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/Documentation/mm/physical_memory.rst b/Documentation/mm/physical_memory.rst
index 5d0a69f6c23c..1bafe8c085a3 100644
--- a/Documentation/mm/physical_memory.rst
+++ b/Documentation/mm/physical_memory.rst
@@ -187,6 +187,9 @@ The following states are internal and not exported through sysfs:
``N_MEMORY_COMPACTION``
The kernel compacts the node on its own initiative (kcompactd, proactive
and explicit compaction).
+``N_MEMORY_RECLAIM``
+ The kernel reclaims the node on its own initiative (kswapd, memcg and
+ explicit reclaim).

For each node that has a property described above, the bit corresponding to the
node ID in the ``node_states[<property>]`` bitmask is set.
@@ -201,6 +204,7 @@ For example, for node 2 with normal memory and CPUs, bit 2 will be set in ::
node_states[N_MEMORY_COMMON]
node_states[N_CPU]
node_states[N_MEMORY_COMPACTION]
+ node_states[N_MEMORY_RECLAIM]

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 2757acffff2b..be5edbee2b22 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -413,6 +413,7 @@ enum node_states {
N_GENERIC_INITIATOR, /* The node has one or more Generic Initiators */
/* 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 */
NR_NODE_STATES
};

@@ -550,12 +551,15 @@ 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_ALL (NODE_MEMORY_FEAT_COMMON | \
- NODE_MEMORY_FEAT_COMPACTION)
+ NODE_MEMORY_FEAT_COMPACTION | \
+ NODE_MEMORY_FEAT_RECLAIM)

/*
* Common memory carries every feature. Private memory needs NUMA: node 0
- * holds all memory without it.
+ * holds all memory without it. Reclaim leaves high-order requests to
+ * compaction, so it requires compaction.
*/
static inline bool node_memory_features_valid(unsigned long features)
{
@@ -563,6 +567,9 @@ static inline bool node_memory_features_valid(unsigned long features)
return false;
if (features & NODE_MEMORY_FEAT_COMMON)
return features == NODE_MEMORY_FEAT_ALL;
+ if ((features & NODE_MEMORY_FEAT_RECLAIM) &&
+ !(features & NODE_MEMORY_FEAT_COMPACTION))
+ return false;
return IS_ENABLED(CONFIG_NUMA);
}

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 335ce73e645e..864da908a59b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -205,6 +205,7 @@ nodemask_t node_states[NR_NODE_STATES] __read_mostly = {
[N_MEMORY] = { { [0] = 1UL } },
[N_MEMORY_COMMON] = { { [0] = 1UL } },
[N_MEMORY_COMPACTION] = { { [0] = 1UL } },
+ [N_MEMORY_RECLAIM] = { { [0] = 1UL } },
[N_CPU] = { { [0] = 1UL } },
#endif /* NUMA */
};
@@ -221,10 +222,13 @@ void __meminit node_set_memory_state(int nid, unsigned long features)
node_set_state(nid, N_MEMORY_PRIVATE);
if (features & NODE_MEMORY_FEAT_COMPACTION)
node_set_state(nid, N_MEMORY_COMPACTION);
+ if (features & NODE_MEMORY_FEAT_RECLAIM)
+ node_set_state(nid, N_MEMORY_RECLAIM);
}

void __meminit node_clear_memory_state(int nid)
{
+ node_clear_state(nid, N_MEMORY_RECLAIM);
node_clear_state(nid, N_MEMORY_COMPACTION);
node_clear_state(nid, N_MEMORY_PRIVATE);
node_clear_state(nid, N_MEMORY_COMMON);

--
2.56.1