Re: [PATCH] mm/memory_hotplug: maintain N_NORMAL_MEMORY during hotplug
From: Hao Li
Date: Sat Mar 28 2026 - 00:03:59 EST
On Fri, Mar 27, 2026 at 09:35:54AM -0700, Joshua Hahn wrote:
> On Fri, 27 Mar 2026 15:44:18 +0100 "Vlastimil Babka (SUSE)" <vbabka@xxxxxxxxxx> wrote:
>
> > On 3/27/26 15:38, Joshua Hahn wrote:
> > > On Fri, 27 Mar 2026 20:42:47 +0800 Hao Li <hao.li@xxxxxxxxx> wrote:
> > >
> > > Hello Hao,
> > >
> > > I hope you are doing well, thank you for the patch!
> > >
> > >> 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.
> > >
> > > The second part feels more important than the second part, doing a quick
> > > glance through the code I can see a few N_NORMAL_MEMORY iterators that
> >
> > Note in practice it's unlikely that a node would hotplug normal memory,
> > start using it, and then manage to successfully hotremove it, due to
> > unmovable allocations. Most likely only ZONE_MOVABLE memory can get hotremoved.
>
> Hello Vlastimil! I hope you are doing well.
>
> Yup, makes sense : -)
Yes, indeed.
>
> > > are in some hot paths like shrink_memcg. Iterating over nodes that don't
> > > contain any NORMAL memory seems like an inefficiency rather than a bug
> > > though.
> >
> > Ignoring nodes that have normal memory, just because it was hotplugged, will
> > result also just in some form of inefficiency, or can the consequences be worse?
>
> Aaaahh yeah, seems like ignoring the hotplugged normal memory would be a bigger
> problem. struct zswap_entries allocated from slab allocator on hotplugged
> nodes would just get ignored by shrink_memcg, seems like a much bigger
> issue than iterating through extra nodes :P thanks for calling this out.
Yes, make sense to me. It could be more serious than just inefficiency. The
shrinkers might even fail to visit reclaimable objects on that node.
>
> > >> 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.
> >
> > But commit 8d2882a8edb8 didn't introduce the current state, or did it?
>
> I don't mean to speak on Hao's behalf, but as far as I can tell I think this
> would have been the commit to introduce the state, since
> node_states_check_changes_online would set status_change_nid_normal to nid,
> then nodes_states_set_node would come around and set it to N_NORMAL_MEMORY.
> Maybe I'm missing something? :0
Thanks for this analysis. I was thinking the same. N_NORMAL_MEMORY is no longer
updated after this commit.
>
> Thanks for the reply, Vlastimil. I hope you have a great day : -)
> Joshua
--
Thanks,
Hao