All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oscar Salvador <osalvador@suse.de>
To: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Harry Yoo <harry.yoo@oracle.com>, Rakie Kim <rakie.kim@sk.com>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 03/10] mm,memory_hotplug: Implement numa node notifier
Date: Mon, 16 Jun 2025 14:32:54 +0200	[thread overview]
Message-ID: <aFAO9igZQ7yP1m7A@localhost.localdomain> (raw)
In-Reply-To: <23431108-b5b8-4c8a-8869-8f994371e7a5@redhat.com>

On Mon, Jun 16, 2025 at 02:21:02PM +0200, David Hildenbrand wrote:
> Exactly. I recall I checked some of them in the past as well, when I
> stumbled over this behavior.

Now, about simplying the cancel_{mem,node}_notifier_on_err.
It would look like this:

 diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
 index d6df85452c72..ff887f10b114 100644
 --- a/mm/memory_hotplug.c
 +++ b/mm/memory_hotplug.c
 @@ -1150,11 +1150,16 @@ void mhp_deinit_memmap_on_memory(unsigned long pfn, unsigned long nr_pages)
  int online_pages(unsigned long pfn, unsigned long nr_pages,
  		       struct zone *zone, struct memory_group *group)
  {
 -	bool cancel_mem_notifier_on_err = false, cancel_node_notifier_on_err = false;
  	const int nid = zone_to_nid(zone);
  	int need_zonelists_rebuild = 0;
 -	struct memory_notify mem_arg;
 -	struct node_notify node_arg;
 +	struct memory_notify mem_arg = {
 +		.start_pfn = pfn,
 +		.nr_pages = nr_pages,
 +		.status_change_nid = NUMA_NO_NODE,
 +	};
 +	struct node_notify node_arg = {
 +		.nid = NUMA_NO_NODE,
 +	};
  	unsigned long flags;
  	int ret;
 
 @@ -1173,21 +1178,16 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
  	/* associate pfn range with the zone */
  	move_pfn_range_to_zone(zone, pfn, nr_pages, NULL, MIGRATE_ISOLATE);
 
 -	node_arg.nid = NUMA_NO_NODE;
  	if (!node_state(nid, N_MEMORY)) {
  		/* Adding memory to the node for the first time */
 -		cancel_node_notifier_on_err = true;
  		node_arg.nid = nid;
 +		mem_arg.status_change_nid = nid;
  		ret = node_notify(NODE_ADDING_FIRST_MEMORY, &node_arg);
  		ret = notifier_to_errno(ret);
  		if (ret)
  			goto failed_addition;
  	}
 
 -	mem_arg.start_pfn = pfn;
 -	mem_arg.nr_pages = nr_pages;
 -	mem_arg.status_change_nid = node_arg.nid;
 -	cancel_mem_notifier_on_err = true;
  	ret = memory_notify(MEM_GOING_ONLINE, &mem_arg);
  	ret = notifier_to_errno(ret);
  	if (ret)
 @@ -1249,9 +1249,8 @@ int online_pages(unsigned long pfn, unsigned long nr_pages,
  	pr_debug("online_pages [mem %#010llx-%#010llx] failed\n",
  		 (unsigned long long) pfn << PAGE_SHIFT,
  		 (((unsigned long long) pfn + nr_pages) << PAGE_SHIFT) - 1);
 -	if (cancel_mem_notifier_on_err)
 -		memory_notify(MEM_CANCEL_ONLINE, &mem_arg);
 -	if (cancel_node_notifier_on_err)
 +	memory_notify(MEM_CANCEL_ONLINE, &mem_arg);
 +	if (node_arg.nid != NUMA_NO_NODE)
  		node_notify(NODE_CANCEL_ADDING_FIRST_MEMORY, &node_arg);
  	remove_pfn_range_from_zone(zone, pfn, nr_pages);
  	return ret;
 @@ -1899,13 +1898,18 @@ static int count_system_ram_pages_cb(unsigned long start_pfn,
  int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
  			struct zone *zone, struct memory_group *group)
  {
 -	bool cancel_mem_notifier_on_err = false, cancel_node_notifier_on_err = false;
  	unsigned long pfn, managed_pages, system_ram_pages = 0;
  	const unsigned long end_pfn = start_pfn + nr_pages;
  	struct pglist_data *pgdat = zone->zone_pgdat;
  	const int node = zone_to_nid(zone);
 -	struct memory_notify mem_arg;
 -	struct node_notify node_arg;
 +	struct memory_notify mem_arg = {
 +		.start_pfn = pfn,
 +		.nr_pages = nr_pages,
 +		.status_change_nid = NUMA_NO_NODE,
 +	};
 +	struct node_notify node_arg = {
 +		.nid = NUMA_NO_NODE,
 +	};
  	unsigned long flags;
  	char *reason;
  	int ret;
 @@ -1970,20 +1974,15 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
  	 * 'nr_pages' more. If so, we know that the node will become empty, and
  	 * so we will clear N_MEMORY for it.
  	 */
 -	node_arg.nid = NUMA_NO_NODE;
  	if (nr_pages >= pgdat->node_present_pages) {
  		node_arg.nid = node;
 -		cancel_node_notifier_on_err = true;
 +		mem_arg.status_change_nid = node;
  		ret = node_notify(NODE_REMOVING_LAST_MEMORY, &node_arg);
  		ret = notifier_to_errno(ret);
  		if (ret)
  			goto failed_removal_isolated;
  	}
 
 -	mem_arg.start_pfn = start_pfn;
 -	mem_arg.nr_pages = nr_pages;
 -	mem_arg.status_change_nid = node_arg.nid;
 -	cancel_mem_notifier_on_err = true;
  	ret = memory_notify(MEM_GOING_OFFLINE, &mem_arg);
  	ret = notifier_to_errno(ret);
  	if (ret) {
 @@ -2087,9 +2086,8 @@ int offline_pages(unsigned long start_pfn, unsigned long nr_pages,
  failed_removal_isolated:
  	/* pushback to free area */
  	undo_isolate_page_range(start_pfn, end_pfn, MIGRATE_MOVABLE);
 -	if (cancel_mem_notifier_on_err)
 -		memory_notify(MEM_CANCEL_OFFLINE, &mem_arg);
 -	if (cancel_node_notifier_on_err)
 +	memory_notify(MEM_CANCEL_OFFLINE, &mem_arg);
 +	if (node_arg.nid != NUMA_NO_NODE)
  		node_notify(NODE_CANCEL_REMOVING_LAST_MEMORY, &node_arg);
  failed_removal_pcplists_disabled:
  	lru_cache_enable();


Not sure if I like keeping the cancel_* stuff.
Strong opinion here? Feelings? :-)

 

-- 
Oscar Salvador
SUSE Labs


  reply	other threads:[~2025-06-16 12:33 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-09  9:21 [PATCH v6 00/10] Implement numa node notifier Oscar Salvador
2025-06-09  9:21 ` [PATCH v6 01/10] mm,slub: Do not special case N_NORMAL nodes for slab_nodes Oscar Salvador
2025-06-09  9:21 ` [PATCH v6 02/10] mm,memory_hotplug: Remove status_change_nid_normal and update documentation Oscar Salvador
2025-06-09  9:21 ` [PATCH v6 03/10] mm,memory_hotplug: Implement numa node notifier Oscar Salvador
2025-06-10  8:10   ` David Hildenbrand
2025-06-16  8:30     ` Oscar Salvador
2025-06-16  8:39       ` David Hildenbrand
2025-06-16  8:50         ` Oscar Salvador
2025-06-16  8:52           ` David Hildenbrand
2025-06-16 11:45             ` Oscar Salvador
2025-06-16 12:21               ` David Hildenbrand
2025-06-16 12:32                 ` Oscar Salvador [this message]
2025-06-16 12:35                   ` David Hildenbrand
2025-06-16 12:55                     ` Oscar Salvador
2025-06-09  9:21 ` [PATCH v6 04/10] mm,slub: Use node-notifier instead of memory-notifier Oscar Salvador
2025-06-10  7:50   ` David Hildenbrand
2025-06-09  9:21 ` [PATCH v6 05/10] mm,memory-tiers: " Oscar Salvador
2025-06-10  7:51   ` David Hildenbrand
2025-06-09  9:21 ` [PATCH v6 06/10] drivers,cxl: " Oscar Salvador
2025-06-10  7:51   ` David Hildenbrand
2025-06-09  9:21 ` [PATCH v6 07/10] drivers,hmat: " Oscar Salvador
2025-06-10  7:52   ` David Hildenbrand
2025-06-09  9:21 ` [PATCH v6 08/10] kernel,cpuset: " Oscar Salvador
2025-06-09  9:21 ` [PATCH v6 09/10] mm,mempolicy: " Oscar Salvador
2025-06-10  7:52   ` David Hildenbrand
2025-06-09  9:21 ` [PATCH v6 10/10] mm,memory_hotplug: Drop status_change_nid parameter from memory_notify Oscar Salvador
2025-06-10  7:55   ` David Hildenbrand
2025-06-10  8:02     ` Oscar Salvador

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aFAO9igZQ7yP1m7A@localhost.localdomain \
    --to=osalvador@suse.de \
    --cc=42.hyeyoo@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=harry.yoo@oracle.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rakie.kim@sk.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.