linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
@ 2026-03-30  3:57 Hao Li
  2026-03-30  8:28 ` Harry Yoo (Oracle)
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Hao Li @ 2026-03-30  3:57 UTC (permalink / raw)
  To: david, osalvador, akpm
  Cc: vbabka, harry.yoo, joshua.hahnjy, linux-mm, linux-kernel,
	linux-cxl, Hao Li

N_NORMAL_MEMORY is initialized from zone population at boot, but memory
hotplug currently only updates N_MEMORY. As a result, a node that gains
normal memory via hotplug can remain invisible to users iterating over
N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
incorrectly marked as such.

Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
offline_pages(). Set the bit when a node that currently lacks normal
memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
offlining removes the last present pages from zones <= ZONE_NORMAL.

This restores the intended semantics without bringing back the old
status_change_nid_normal notifier plumbing which was removed in
8d2882a8edb8.

Current users that benefit include list_lru, zswap, nfsd filecache,
hugetlb_cgroup, and has_normal_memory sysfs reporting.

Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
Signed-off-by: Hao Li <hao.li@linux.dev>
---
Changes: simplify the code. (Thanks Joshua and David)
---
 mm/memory_hotplug.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index bc805029da51..05a47953ef21 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1209,6 +1209,13 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
 
 	if (node_arg.nid >= 0)
 		node_set_state(nid, N_MEMORY);
+	/*
+	 * Check whether we are adding normal memory to the node for the first
+	 * time.
+	 */
+	if (!node_state(nid, N_NORMAL_MEMORY) && zone_idx(zone) <= ZONE_NORMAL)
+		node_set_state(nid, N_NORMAL_MEMORY);
+
 	if (need_zonelists_rebuild)
 		build_all_zonelists(NULL);
 
@@ -1908,6 +1915,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
 	unsigned long flags;
 	char *reason;
 	int ret;
+	unsigned long normal_pages = 0;
+	enum zone_type zt;
 
 	/*
 	 * {on,off}lining is constrained to full memory sections (or more
@@ -2055,6 +2064,17 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
 	/* reinitialise watermarks and update pcp limits */
 	init_per_zone_wmark_min();
 
+	/*
+	 * Check whether this operation removes the last normal memory from
+	 * the node. We do this before clearing N_MEMORY to avoid the possible
+	 * transient "!N_MEMORY && N_NORMAL_MEMORY" state.
+	 */
+	if (zone_idx(zone) <= ZONE_NORMAL) {
+		for (zt = 0; zt <= ZONE_NORMAL; zt++)
+			normal_pages += pgdat->node_zones[zt].present_pages;
+		if (!normal_pages)
+			node_clear_state(node, N_NORMAL_MEMORY);
+	}
 	/*
 	 * Make sure to mark the node as memory-less before rebuilding the zone
 	 * list. Otherwise this node would still appear in the fallback lists.
-- 
2.50.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30  3:57 [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug Hao Li
@ 2026-03-30  8:28 ` Harry Yoo (Oracle)
  2026-03-30  9:34   ` Hao Li
  2026-03-30 12:07 ` Vlastimil Babka (SUSE)
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Harry Yoo (Oracle) @ 2026-03-30  8:28 UTC (permalink / raw)
  To: Hao Li
  Cc: david, osalvador, akpm, vbabka, joshua.hahnjy, linux-mm,
	linux-kernel, linux-cxl

On Mon, Mar 30, 2026 at 11:57:49AM +0800, Hao Li wrote:
> N_NORMAL_MEMORY is initialized from zone population at boot, but memory
> hotplug currently only updates N_MEMORY. As a result, a node that gains
> normal memory via hotplug can remain invisible to users iterating over
> N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
> incorrectly marked as such.
> 
> Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
> offline_pages(). Set the bit when a node that currently lacks normal
> memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
> offlining removes the last present pages from zones <= ZONE_NORMAL.
> 
> This restores the intended semantics without bringing back the old
> status_change_nid_normal notifier plumbing which was removed in
> 8d2882a8edb8.
> 
> Current users that benefit include list_lru, zswap, nfsd filecache,
> hugetlb_cgroup, and has_normal_memory sysfs reporting.
> 
> Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")

The Fixes: tag indeed looks correct to me.

By the way, MM needs an explicit Cc: stable@vger.kernel.org for backporting.

Since this commit was introduced in v6.17 and we have v6.18 as LTS,
this should to be backported to v6.18.

> Signed-off-by: Hao Li <hao.li@linux.dev>
> ---

Otherwise looks good to me,
Reviewed-by: Harry Yoo (Oracle) <harry@kernel.org>

-- 
Cheers,
Harry / Hyeonggon


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30  8:28 ` Harry Yoo (Oracle)
@ 2026-03-30  9:34   ` Hao Li
  2026-03-30 21:46     ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Hao Li @ 2026-03-30  9:34 UTC (permalink / raw)
  To: Harry Yoo (Oracle)
  Cc: david, osalvador, akpm, vbabka, joshua.hahnjy, linux-mm,
	linux-kernel, linux-cxl

On Mon, Mar 30, 2026 at 05:28:34PM +0900, Harry Yoo (Oracle) wrote:
> On Mon, Mar 30, 2026 at 11:57:49AM +0800, Hao Li wrote:
> > N_NORMAL_MEMORY is initialized from zone population at boot, but memory
> > hotplug currently only updates N_MEMORY. As a result, a node that gains
> > normal memory via hotplug can remain invisible to users iterating over
> > N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
> > incorrectly marked as such.
> > 
> > Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
> > offline_pages(). Set the bit when a node that currently lacks normal
> > memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
> > offlining removes the last present pages from zones <= ZONE_NORMAL.
> > 
> > This restores the intended semantics without bringing back the old
> > status_change_nid_normal notifier plumbing which was removed in
> > 8d2882a8edb8.
> > 
> > Current users that benefit include list_lru, zswap, nfsd filecache,
> > hugetlb_cgroup, and has_normal_memory sysfs reporting.
> > 
> > Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
> 
> The Fixes: tag indeed looks correct to me.
> 
> By the way, MM needs an explicit Cc: stable@vger.kernel.org for backporting.
> 
> Since this commit was introduced in v6.17 and we have v6.18 as LTS,
> this should to be backported to v6.18.

I had gone back and forth on whether to add the Cc tag, but I'm happy to
include it now!

> 
> > Signed-off-by: Hao Li <hao.li@linux.dev>
> > ---
> 
> Otherwise looks good to me,
> Reviewed-by: Harry Yoo (Oracle) <harry@kernel.org>

Thanks for the review!

-- 
Thanks,
Hao


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30  3:57 [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug Hao Li
  2026-03-30  8:28 ` Harry Yoo (Oracle)
@ 2026-03-30 12:07 ` Vlastimil Babka (SUSE)
  2026-03-30 13:53 ` Joshua Hahn
  2026-03-30 14:20 ` David Hildenbrand (Arm)
  3 siblings, 0 replies; 10+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-03-30 12:07 UTC (permalink / raw)
  To: Hao Li, david, osalvador, akpm
  Cc: vbabka, harry.yoo, joshua.hahnjy, linux-mm, linux-kernel, linux-cxl

On 3/30/26 05:57, Hao Li wrote:
> N_NORMAL_MEMORY is initialized from zone population at boot, but memory
> hotplug currently only updates N_MEMORY. As a result, a node that gains
> normal memory via hotplug can remain invisible to users iterating over
> N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
> incorrectly marked as such.
> 
> Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
> offline_pages(). Set the bit when a node that currently lacks normal
> memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
> offlining removes the last present pages from zones <= ZONE_NORMAL.
> 
> This restores the intended semantics without bringing back the old
> status_change_nid_normal notifier plumbing which was removed in
> 8d2882a8edb8.
> 
> Current users that benefit include list_lru, zswap, nfsd filecache,
> hugetlb_cgroup, and has_normal_memory sysfs reporting.
> 
> Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
> Signed-off-by: Hao Li <hao.li@linux.dev>

Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>

Thanks!

> ---
> Changes: simplify the code. (Thanks Joshua and David)
> ---
>  mm/memory_hotplug.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index bc805029da51..05a47953ef21 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1209,6 +1209,13 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
>  
>  	if (node_arg.nid >= 0)
>  		node_set_state(nid, N_MEMORY);
> +	/*
> +	 * Check whether we are adding normal memory to the node for the first
> +	 * time.
> +	 */
> +	if (!node_state(nid, N_NORMAL_MEMORY) && zone_idx(zone) <= ZONE_NORMAL)
> +		node_set_state(nid, N_NORMAL_MEMORY);
> +
>  	if (need_zonelists_rebuild)
>  		build_all_zonelists(NULL);
>  
> @@ -1908,6 +1915,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
>  	unsigned long flags;
>  	char *reason;
>  	int ret;
> +	unsigned long normal_pages = 0;
> +	enum zone_type zt;
>  
>  	/*
>  	 * {on,off}lining is constrained to full memory sections (or more
> @@ -2055,6 +2064,17 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
>  	/* reinitialise watermarks and update pcp limits */
>  	init_per_zone_wmark_min();
>  
> +	/*
> +	 * Check whether this operation removes the last normal memory from
> +	 * the node. We do this before clearing N_MEMORY to avoid the possible
> +	 * transient "!N_MEMORY && N_NORMAL_MEMORY" state.
> +	 */
> +	if (zone_idx(zone) <= ZONE_NORMAL) {
> +		for (zt = 0; zt <= ZONE_NORMAL; zt++)
> +			normal_pages += pgdat->node_zones[zt].present_pages;
> +		if (!normal_pages)
> +			node_clear_state(node, N_NORMAL_MEMORY);
> +	}
>  	/*
>  	 * Make sure to mark the node as memory-less before rebuilding the zone
>  	 * list. Otherwise this node would still appear in the fallback lists.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30  3:57 [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug Hao Li
  2026-03-30  8:28 ` Harry Yoo (Oracle)
  2026-03-30 12:07 ` Vlastimil Babka (SUSE)
@ 2026-03-30 13:53 ` Joshua Hahn
  2026-03-30 14:20 ` David Hildenbrand (Arm)
  3 siblings, 0 replies; 10+ messages in thread
From: Joshua Hahn @ 2026-03-30 13:53 UTC (permalink / raw)
  To: Hao Li
  Cc: david, osalvador, akpm, vbabka, harry.yoo, joshua.hahnjy,
	linux-mm, linux-kernel, linux-cxl

On Mon, 30 Mar 2026 11:57:49 +0800 Hao Li <hao.li@linux.dev> wrote:

> N_NORMAL_MEMORY is initialized from zone population at boot, but memory
> hotplug currently only updates N_MEMORY. As a result, a node that gains
> normal memory via hotplug can remain invisible to users iterating over
> N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
> incorrectly marked as such.
> 
> Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
> offline_pages(). Set the bit when a node that currently lacks normal
> memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
> offlining removes the last present pages from zones <= ZONE_NORMAL.
> 
> This restores the intended semantics without bringing back the old
> status_change_nid_normal notifier plumbing which was removed in
> 8d2882a8edb8.
> 
> Current users that benefit include list_lru, zswap, nfsd filecache,
> hugetlb_cgroup, and has_normal_memory sysfs reporting.
> 
> Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
> Signed-off-by: Hao Li <hao.li@linux.dev>

LGTM, thanks for the new version Hao! I hope you have a great day : -)

Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>

> ---
> Changes: simplify the code. (Thanks Joshua and David)
> ---
>  mm/memory_hotplug.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index bc805029da51..05a47953ef21 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30  3:57 [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug Hao Li
                   ` (2 preceding siblings ...)
  2026-03-30 13:53 ` Joshua Hahn
@ 2026-03-30 14:20 ` David Hildenbrand (Arm)
  2026-03-31  4:14   ` Hao Li
  3 siblings, 1 reply; 10+ messages in thread
From: David Hildenbrand (Arm) @ 2026-03-30 14:20 UTC (permalink / raw)
  To: Hao Li, osalvador, akpm
  Cc: vbabka, harry.yoo, joshua.hahnjy, linux-mm, linux-kernel, linux-cxl

On 3/30/26 05:57, Hao Li wrote:
> N_NORMAL_MEMORY is initialized from zone population at boot, but memory
> hotplug currently only updates N_MEMORY. As a result, a node that gains
> normal memory via hotplug can remain invisible to users iterating over
> N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
> incorrectly marked as such.
> 
> Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
> offline_pages(). Set the bit when a node that currently lacks normal
> memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
> offlining removes the last present pages from zones <= ZONE_NORMAL.
> 
> This restores the intended semantics without bringing back the old
> status_change_nid_normal notifier plumbing which was removed in
> 8d2882a8edb8.
> 
> Current users that benefit include list_lru, zswap, nfsd filecache,
> hugetlb_cgroup, and has_normal_memory sysfs reporting.
> 
> Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")

Agreed on CCing stable.

> Signed-off-by: Hao Li <hao.li@linux.dev>
> ---
> Changes: simplify the code. (Thanks Joshua and David)
> ---
>  mm/memory_hotplug.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index bc805029da51..05a47953ef21 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1209,6 +1209,13 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
>  
>  	if (node_arg.nid >= 0)
>  		node_set_state(nid, N_MEMORY);
> +	/*
> +	 * Check whether we are adding normal memory to the node for the first
> +	 * time.
> +	 */
> +	if (!node_state(nid, N_NORMAL_MEMORY) && zone_idx(zone) <= ZONE_NORMAL)
> +		node_set_state(nid, N_NORMAL_MEMORY);
> +
>  	if (need_zonelists_rebuild)
>  		build_all_zonelists(NULL);
>  
> @@ -1908,6 +1915,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
>  	unsigned long flags;
>  	char *reason;
>  	int ret;
> +	unsigned long normal_pages = 0;
> +	enum zone_type zt;
>  
>  	/*
>  	 * {on,off}lining is constrained to full memory sections (or more
> @@ -2055,6 +2064,17 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
>  	/* reinitialise watermarks and update pcp limits */
>  	init_per_zone_wmark_min();
>  
> +	/*
> +	 * Check whether this operation removes the last normal memory from
> +	 * the node. We do this before clearing N_MEMORY to avoid the possible
> +	 * transient "!N_MEMORY && N_NORMAL_MEMORY" state.
> +	 */
> +	if (zone_idx(zone) <= ZONE_NORMAL) {
> +		for (zt = 0; zt <= ZONE_NORMAL; zt++)
> +			normal_pages += pgdat->node_zones[zt].present_pages;
> +		if (!normal_pages)
> +			node_clear_state(node, N_NORMAL_MEMORY);
> +	}

Was wondering whether we could just do an early exit, like:


for (zt = 0; zt <= ZONE_NORMAL; zt++) {
	if (pgdat->node_zones[zt].present_pages)
		break;
}
if (zt > ZONE_NORMAL)
	node_clear_state(node, N_NORMAL_MEMORY);

But ends up being harder to digest (incl. all variants I tried :) ), so

Acked-by: David Hildenbrand (Arm) <david@kernel.org>


-- 
Cheers,

David


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30  9:34   ` Hao Li
@ 2026-03-30 21:46     ` Andrew Morton
  2026-03-31  4:24       ` Hao Li
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2026-03-30 21:46 UTC (permalink / raw)
  To: Hao Li
  Cc: Harry Yoo (Oracle),
	david, osalvador, vbabka, joshua.hahnjy, linux-mm, linux-kernel,
	linux-cxl

On Mon, 30 Mar 2026 17:34:21 +0800 Hao Li <hao.li@linux.dev> wrote:

> > > Current users that benefit include list_lru, zswap, nfsd filecache,
> > > hugetlb_cgroup, and has_normal_memory sysfs reporting.
> > > 
> > > Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
> > 
> > The Fixes: tag indeed looks correct to me.
> > 
> > By the way, MM needs an explicit Cc: stable@vger.kernel.org for backporting.
> > 
> > Since this commit was introduced in v6.17 and we have v6.18 as LTS,
> > this should to be backported to v6.18.
> 
> I had gone back and forth on whether to add the Cc tag, but I'm happy to
> include it now!

That's OK, I'm very cc:stable-vigilant. Thanks,  I'll get this upstreamed during
this -rc cycle.

I do like our cc:stable patches to include a clear description of the
userspace-visible impacts of the bug.  Two reasons:

- To explain to -stable maintainers why we're requesting the
  backport.  If they care.  Heck, and to explain to me why I'm doing
  this!

- To help out someone who is using an older kernel (there are many)
  who is dealing with a bug report.  They're looking at this changelog
  thinking "hm, I wonder if this patch will fix that bug".  Let's add a
  few words in there to help out with their pattern matching.

So, and not for the first time ;), what are the userspace-visible
runtime effects of this bug?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30 14:20 ` David Hildenbrand (Arm)
@ 2026-03-31  4:14   ` Hao Li
  0 siblings, 0 replies; 10+ messages in thread
From: Hao Li @ 2026-03-31  4:14 UTC (permalink / raw)
  To: David Hildenbrand (Arm)
  Cc: osalvador, akpm, vbabka, harry.yoo, joshua.hahnjy, linux-mm,
	linux-kernel, linux-cxl

On Mon, Mar 30, 2026 at 04:20:23PM +0200, David Hildenbrand (Arm) wrote:
> On 3/30/26 05:57, Hao Li wrote:
> > N_NORMAL_MEMORY is initialized from zone population at boot, but memory
> > hotplug currently only updates N_MEMORY. As a result, a node that gains
> > normal memory via hotplug can remain invisible to users iterating over
> > N_NORMAL_MEMORY, while a node that loses its last normal memory can stay
> > incorrectly marked as such.
> > 
> > Restore N_NORMAL_MEMORY maintenance directly in online_pages() and
> > offline_pages(). Set the bit when a node that currently lacks normal
> > memory onlines pages into a zone <= ZONE_NORMAL, and clear it when
> > offlining removes the last present pages from zones <= ZONE_NORMAL.
> > 
> > This restores the intended semantics without bringing back the old
> > status_change_nid_normal notifier plumbing which was removed in
> > 8d2882a8edb8.
> > 
> > Current users that benefit include list_lru, zswap, nfsd filecache,
> > hugetlb_cgroup, and has_normal_memory sysfs reporting.
> > 
> > Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
> 
> Agreed on CCing stable.
> 
> > Signed-off-by: Hao Li <hao.li@linux.dev>
> > ---
> > Changes: simplify the code. (Thanks Joshua and David)
> > ---
> >  mm/memory_hotplug.c | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> > 
> > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> > index bc805029da51..05a47953ef21 100644
> > --- a/mm/memory_hotplug.c
> > +++ b/mm/memory_hotplug.c
> > @@ -1209,6 +1209,13 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
> >  
> >  	if (node_arg.nid >= 0)
> >  		node_set_state(nid, N_MEMORY);
> > +	/*
> > +	 * Check whether we are adding normal memory to the node for the first
> > +	 * time.
> > +	 */
> > +	if (!node_state(nid, N_NORMAL_MEMORY) && zone_idx(zone) <= ZONE_NORMAL)
> > +		node_set_state(nid, N_NORMAL_MEMORY);
> > +
> >  	if (need_zonelists_rebuild)
> >  		build_all_zonelists(NULL);
> >  
> > @@ -1908,6 +1915,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
> >  	unsigned long flags;
> >  	char *reason;
> >  	int ret;
> > +	unsigned long normal_pages = 0;
> > +	enum zone_type zt;
> >  
> >  	/*
> >  	 * {on,off}lining is constrained to full memory sections (or more
> > @@ -2055,6 +2064,17 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
> >  	/* reinitialise watermarks and update pcp limits */
> >  	init_per_zone_wmark_min();
> >  
> > +	/*
> > +	 * Check whether this operation removes the last normal memory from
> > +	 * the node. We do this before clearing N_MEMORY to avoid the possible
> > +	 * transient "!N_MEMORY && N_NORMAL_MEMORY" state.
> > +	 */
> > +	if (zone_idx(zone) <= ZONE_NORMAL) {
> > +		for (zt = 0; zt <= ZONE_NORMAL; zt++)
> > +			normal_pages += pgdat->node_zones[zt].present_pages;
> > +		if (!normal_pages)
> > +			node_clear_state(node, N_NORMAL_MEMORY);
> > +	}
> 
> Was wondering whether we could just do an early exit, like:
> 
> 
> for (zt = 0; zt <= ZONE_NORMAL; zt++) {
> 	if (pgdat->node_zones[zt].present_pages)
> 		break;
> }
> if (zt > ZONE_NORMAL)
> 	node_clear_state(node, N_NORMAL_MEMORY);
> 
> But ends up being harder to digest (incl. all variants I tried :) ), so

Thanks for exploring this.
Yeah, this looks like one of those cases where we have to make a bit of a
tradeoff for readability :)

> 
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>

Thanks for the Ack!

-- 
Thanks,
Hao


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-30 21:46     ` Andrew Morton
@ 2026-03-31  4:24       ` Hao Li
  2026-03-31  5:15         ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Hao Li @ 2026-03-31  4:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Harry Yoo (Oracle),
	david, osalvador, vbabka, joshua.hahnjy, linux-mm, linux-kernel,
	linux-cxl

On Mon, Mar 30, 2026 at 02:46:40PM -0700, Andrew Morton wrote:
> On Mon, 30 Mar 2026 17:34:21 +0800 Hao Li <hao.li@linux.dev> wrote:
> 
> > > > Current users that benefit include list_lru, zswap, nfsd filecache,
> > > > hugetlb_cgroup, and has_normal_memory sysfs reporting.
> > > > 
> > > > Fixes: 8d2882a8edb8 ("mm,memory_hotplug: remove status_change_nid_normal and update documentation")
> > > 
> > > The Fixes: tag indeed looks correct to me.
> > > 
> > > By the way, MM needs an explicit Cc: stable@vger.kernel.org for backporting.
> > > 
> > > Since this commit was introduced in v6.17 and we have v6.18 as LTS,
> > > this should to be backported to v6.18.
> > 
> > I had gone back and forth on whether to add the Cc tag, but I'm happy to
> > include it now!
> 
> That's OK, I'm very cc:stable-vigilant. Thanks,  I'll get this upstreamed during
> this -rc cycle.

Thanks!

> 
> I do like our cc:stable patches to include a clear description of the
> userspace-visible impacts of the bug.  Two reasons:
> 
> - To explain to -stable maintainers why we're requesting the
>   backport.  If they care.  Heck, and to explain to me why I'm doing
>   this!
> 
> - To help out someone who is using an older kernel (there are many)
>   who is dealing with a bug report.  They're looking at this changelog
>   thinking "hm, I wonder if this patch will fix that bug".  Let's add a
>   few words in there to help out with their pattern matching.

Agreed, and thanks for spelling out the rationale!

> 
> So, and not for the first time ;), what are the userspace-visible
> runtime effects of this bug?
> 

The most visible effect is that
/sys/devices/system/node/has_normal_memory does not report a node even
after that node has gained normal memory via hotplug.

Also, list_lru-based shrinkers can undercount objects on such a node and
may skip reclaim on that node entirely, which can lead to a higher memory
footprint than expected.

Feel free to fold the above into the changelog if useful :)

-- 
Thanks,
Hao


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
  2026-03-31  4:24       ` Hao Li
@ 2026-03-31  5:15         ` Andrew Morton
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2026-03-31  5:15 UTC (permalink / raw)
  To: Hao Li
  Cc: Harry Yoo (Oracle),
	david, osalvador, vbabka, joshua.hahnjy, linux-mm, linux-kernel,
	linux-cxl

On Tue, 31 Mar 2026 12:24:46 +0800 Hao Li <hao.li@linux.dev> wrote:

> The most visible effect is that
> /sys/devices/system/node/has_normal_memory does not report a node even
> after that node has gained normal memory via hotplug.
> 
> Also, list_lru-based shrinkers can undercount objects on such a node and
> may skip reclaim on that node entirely, which can lead to a higher memory
> footprint than expected.
> 
> Feel free to fold the above into the changelog if useful :)

Very useful.  Added, thanks!


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-03-31  5:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30  3:57 [PATCH v2] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug Hao Li
2026-03-30  8:28 ` Harry Yoo (Oracle)
2026-03-30  9:34   ` Hao Li
2026-03-30 21:46     ` Andrew Morton
2026-03-31  4:24       ` Hao Li
2026-03-31  5:15         ` Andrew Morton
2026-03-30 12:07 ` Vlastimil Babka (SUSE)
2026-03-30 13:53 ` Joshua Hahn
2026-03-30 14:20 ` David Hildenbrand (Arm)
2026-03-31  4:14   ` Hao Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox