* [PATCH] mm/memory-tiers: reset demotion targets of nodes without memory
@ 2026-10-19 18:47 Gregory Price (Meta)
2026-10-19 19:04 ` Zi Yan
0 siblings, 1 reply; 3+ messages in thread
From: Gregory Price (Meta) @ 2026-10-19 18:47 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, kernel-team, akpm, david, gourry, ziy,
joshua.hahnjy, rakie.kim, ying.huang, weixugc, aneesh.kumar
When a node loses its last memory, offline_pages() clears N_MEMORY
before the memory-tier callback rebuilds the demotion targets.
disable_all_demotion_targets() resets only N_MEMORY nodes, so the node
keeps its old node_demotion[] entry while it has no memory. Before
6c542ab75714, the reset covered every online node.
A reclaimer reads the stale entry only between the node regaining memory
and its targets being rebuilt, and it filters the entry against the
current allowed targets, so there is no user-visible effect. To see it,
online and then offline a node's only DIMM: a debugger still finds the
lower-tier node in node_demotion[nid].preferred.
Reset the targets of every node.
Fixes: 6c542ab75714 ("mm/demotion: build demotion targets based on explicit memory tiers")
Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
---
mm/memory-tiers.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 25e121851b586..7197f1a67a340 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -378,7 +378,7 @@ static void disable_all_demotion_targets(void)
struct memory_tier *memtier;
int node;
- for_each_node_state(node, N_MEMORY) {
+ for_each_node(node) {
node_demotion[node].preferred = NODE_MASK_NONE;
/*
* We are holding memory_tier_lock, it is safe
--
2.53.0-Meta
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/memory-tiers: reset demotion targets of nodes without memory
2026-10-19 18:47 [PATCH] mm/memory-tiers: reset demotion targets of nodes without memory Gregory Price (Meta)
@ 2026-10-19 19:04 ` Zi Yan
2026-10-19 20:22 ` Gregory Price
0 siblings, 1 reply; 3+ messages in thread
From: Zi Yan @ 2026-10-19 19:04 UTC (permalink / raw)
To: Gregory Price (Meta), linux-mm
Cc: linux-kernel, kernel-team, akpm, david, joshua.hahnjy, rakie.kim,
ying.huang, weixugc, aneesh.kumar
On Mon Oct 19, 2026 at 2:47 PM EDT, Gregory Price (Meta) wrote:
> When a node loses its last memory, offline_pages() clears N_MEMORY
> before the memory-tier callback rebuilds the demotion targets.
> disable_all_demotion_targets() resets only N_MEMORY nodes, so the node
> keeps its old node_demotion[] entry while it has no memory. Before
> 6c542ab75714, the reset covered every online node.
establish_demotion_targets() uses for_each_node_state(node, N_MEMORY),
because the to-be-online node is already added into N_MEMORY?
>
> A reclaimer reads the stale entry only between the node regaining memory
> and its targets being rebuilt, and it filters the entry against the
> current allowed targets, so there is no user-visible effect. To see it,
> online and then offline a node's only DIMM: a debugger still finds the
> lower-tier node in node_demotion[nid].preferred.
>
> Reset the targets of every node.
>
> Fixes: 6c542ab75714 ("mm/demotion: build demotion targets based on explicit memory tiers")
> Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
> mm/memory-tiers.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
> index 25e121851b586..7197f1a67a340 100644
> --- a/mm/memory-tiers.c
> +++ b/mm/memory-tiers.c
> @@ -378,7 +378,7 @@ static void disable_all_demotion_targets(void)
> struct memory_tier *memtier;
> int node;
>
> - for_each_node_state(node, N_MEMORY) {
> + for_each_node(node) {
I think the above code deserves a comment explaining why for_each_node()
is needed instead of for_each_node_state(N_MEMORY), because when a node
is added or removed during memory hotadd or hotremove matters here.
> node_demotion[node].preferred = NODE_MASK_NONE;
> /*
> * We are holding memory_tier_lock, it is safe
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/memory-tiers: reset demotion targets of nodes without memory
2026-10-19 19:04 ` Zi Yan
@ 2026-10-19 20:22 ` Gregory Price
0 siblings, 0 replies; 3+ messages in thread
From: Gregory Price @ 2026-10-19 20:22 UTC (permalink / raw)
To: Zi Yan
Cc: linux-mm, linux-kernel, kernel-team, akpm, david, joshua.hahnjy,
rakie.kim, ying.huang, weixugc, aneesh.kumar
On Mon, Oct 19, 2026 at 03:04:45PM -0400, Zi Yan wrote:
> On Mon Oct 19, 2026 at 2:47 PM EDT, Gregory Price (Meta) wrote:
> > When a node loses its last memory, offline_pages() clears N_MEMORY
> > before the memory-tier callback rebuilds the demotion targets.
> > disable_all_demotion_targets() resets only N_MEMORY nodes, so the node
> > keeps its old node_demotion[] entry while it has no memory. Before
> > 6c542ab75714, the reset covered every online node.
>
> establish_demotion_targets() uses for_each_node_state(node, N_MEMORY),
> because the to-be-online node is already added into N_MEMORY?
>
NODE_ADDED_FIRST_MEMORY happens after the memory is already added
(though not necessarily online).
NODE_REMOVED_LAST_MEMORY happens after the last memory block is removed
(and therefore N_MEMORY is gone).
slightly different timing for each event. There isn't a reasonable
change we can make otherwise.
> >
> > A reclaimer reads the stale entry only between the node regaining memory
> > and its targets being rebuilt, and it filters the entry against the
> > current allowed targets, so there is no user-visible effect. To see it,
> > online and then offline a node's only DIMM: a debugger still finds the
> > lower-tier node in node_demotion[nid].preferred.
> >
> > Reset the targets of every node.
> >
> > Fixes: 6c542ab75714 ("mm/demotion: build demotion targets based on explicit memory tiers")
> > Signed-off-by: Gregory Price (Meta) <gourry@gourry.net>
> > ---
> > mm/memory-tiers.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
> > index 25e121851b586..7197f1a67a340 100644
> > --- a/mm/memory-tiers.c
> > +++ b/mm/memory-tiers.c
> > @@ -378,7 +378,7 @@ static void disable_all_demotion_targets(void)
> > struct memory_tier *memtier;
> > int node;
> >
> > - for_each_node_state(node, N_MEMORY) {
> > + for_each_node(node) {
>
> I think the above code deserves a comment explaining why for_each_node()
> is needed instead of for_each_node_state(N_MEMORY), because when a node
> is added or removed during memory hotadd or hotremove matters here.
>
Sure. Will respin tomorrow and give others a chance to look at it.
~Gregory
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-19 20:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 18:47 [PATCH] mm/memory-tiers: reset demotion targets of nodes without memory Gregory Price (Meta)
2026-10-19 19:04 ` Zi Yan
2026-10-19 20:22 ` Gregory Price
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.