Re: [PATCH 1/2] mm,memory_hotplug: Implement numa node notifier

Harry Yoo
2025-04-01T14:19:32Z

On Tue, Apr 01, 2025 at 11:27:15AM +0200, Oscar Salvador wrote:
> There are at least four consumers of hotplug_memory_notifier that what they
> really are interested in is whether any numa node changed its state, e.g: going
> from being memory aware to becoming memoryless.
>
> Implement a specific notifier for numa nodes when their state gets changed,
> and have those consumers that only care about numa node state changes use it.
>
> Signed-off-by: Oscar Salvador <osalvador@suse.de>
> ---

Hi Oscar,

Please Cc harry.yoo@oracle.com instead of 42.hyeyoo@gmail.com
in the future—I recently changed my email.

FWIW, I reviewed this patch and it looks good to me:

Reviewed-by: Harry Yoo <harry.yoo@oracle.com>

> drivers/acpi/numa/hmat.c | 6 +--
> drivers/base/node.c | 19 +++++++++
> drivers/cxl/core/region.c | 14 +++----
> drivers/cxl/cxl.h | 4 +-
> include/linux/memory.h | 38 ++++++++++++++++++
> kernel/cgroup/cpuset.c | 2 +-
> mm/memory-tiers.c | 8 ++--
> mm/memory_hotplug.c | 84 +++++++++++++++++++++++++++++----------
> mm/slub.c | 22 +++++-----
> 9 files changed, 148 insertions(+), 49 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 75401866fb76..4bb9ff282ec9 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -1963,7 +1987,9 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
> unsigned long pfn, managed_pages, system_ram_pages = 0;
> const int node = zone_to_nid(zone);
> unsigned long flags;
> - struct memory_notify arg;
> + struct memory_notify mem_arg;
> + struct node_notify node_arg;
> + bool cancel_mem_notifier_on_err = false, cancel_node_notifier_on_err = false;
> char *reason;
> int ret;
>

[...]

> + if (node_arg.status_change_nid >= 0) {
> kcompactd_stop(node);
> kswapd_stop(node);
> + /*Node went memoryless. Notifiy interested consumers */
> + node_notify(NODE_BECAME_MEMORYLESS, &node_arg);
> }

nit: /* Node went memoryless. ... */
^ a whitespace omitted.

> writeback_set_ratelimit();
>
> - memory_notify(MEM_OFFLINE, &arg);
> + memory_notify(MEM_OFFLINE, &mem_arg);
> remove_pfn_range_from_zone(zone, start_pfn, nr_pages);
> return 0;

> diff --git a/mm/slub.c b/mm/slub.c
> index 184fd2b14758..74350f6c8ddd 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5928,10 +5928,10 @@ static int slab_mem_going_offline_callback(void *arg)
>
> static void slab_mem_offline_callback(void *arg)
> {
> - struct memory_notify *marg = arg;
> + struct node_notify *narg = arg;
> int offline_node;
>
> - offline_node = marg->status_change_nid_normal;
> + offline_node = narg->status_change_nid_normal;
>
> /*
> * If the node still has available memory. we need kmem_cache_node

I was wondering if this offline_node check is still necessary after
this patch, but as SLUB is still notified for N_HIGH_MEMORY-only nodes,
it is necessary.

--
Cheers,
Harry (formerly known as Hyeonggon)