mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes
@ 2026-11-30  6:37 Qiliang Yuan
  2026-11-30 10:54 ` David Hildenbrand (Arm)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qiliang Yuan @ 2026-11-30  6:37 UTC (permalink / raw)
  To: David Hildenbrand, Oscar Salvador, Andrew Morton
  Cc: linux-mm, linux-cxl, linux-kernel, Qiliang Yuan

cpu_up() calls try_online_node() for the node of every CPU it brings up,
so that a CPU on a memoryless node that is not online yet gets its node
onlined first. try_online_node() takes mem_hotplug_lock for write with
mem_hotplug_begin() before it checks whether the node is online.

mem_hotplug_lock is a percpu rwsem, and taking it for write waits for an
RCU grace period unless another writer released it shortly before.
Bringing a CPU online through sysfs, as done when hot-adding vCPUs to a
VM, therefore waits for a grace period although the node of the CPU is
almost always online already.

Check node_online() before taking the lock. A node with present CPUs is
never offlined, see try_offline_node(), so the node of the CPU being
brought up cannot go offline concurrently.

Onlining CPUs of a 32-vCPU VM through sysfs, base and patched kernels
alternating over 4 rounds of 5 runs, median of the 20 runs and
interquartile range in parentheses; "single" onlines one CPU 0.3 s after
taking it offline, "16 in a row" onlines CPUs 16-31 back to back:

  case                 before (ms)           after (ms)   change
  single          24.8 (24.2-25.9)     16.7 (15.9-17.3)     -33%
  16 in a row  143.1 (139.8-147.2)  130.0 (127.3-133.7)      -9%

Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 mm/memory_hotplug.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 944ea6fd88562..eb50d6e0fe48d 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -1299,6 +1299,14 @@ int try_online_node(int nid)
 {
 	int ret;
 
+	/*
+	 * A node with present CPUs is never offlined, see try_offline_node().
+	 * Skip mem_hotplug_begin(), which waits for an RCU grace period, when
+	 * the node is already online.
+	 */
+	if (node_online(nid))
+		return 0;
+
 	mem_hotplug_begin();
 	ret =  __try_online_node(nid, true);
 	mem_hotplug_done();

---
base-commit: 2fffa854b7babdaf17e9722636015dacd205039f
change-id: 20261130-feat-memhp-try-online-node-469994f7344c

Best regards,
-- 
Qiliang Yuan <qiliang.yuan@linux.dev>


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

* Re: [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes
  2026-11-30  6:37 [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes Qiliang Yuan
@ 2026-11-30 10:54 ` David Hildenbrand (Arm)
  2026-11-30 10:56 ` David Hildenbrand
  2026-11-30 19:04 ` Oscar Salvador (SUSE)
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-30 10:54 UTC (permalink / raw)
  To: Qiliang Yuan, Oscar Salvador, Andrew Morton
  Cc: linux-mm, linux-cxl, linux-kernel

On 11/30/26 07:37, Qiliang Yuan wrote:
> cpu_up() calls try_online_node() for the node of every CPU it brings up,
> so that a CPU on a memoryless node that is not online yet gets its node
> onlined first. try_online_node() takes mem_hotplug_lock for write with
> mem_hotplug_begin() before it checks whether the node is online.
> 
> mem_hotplug_lock is a percpu rwsem, and taking it for write waits for an
> RCU grace period unless another writer released it shortly before.
> Bringing a CPU online through sysfs, as done when hot-adding vCPUs to a
> VM, therefore waits for a grace period although the node of the CPU is
> almost always online already.
> 
> Check node_online() before taking the lock. A node with present CPUs is
> never offlined, see try_offline_node(), so the node of the CPU being
> brought up cannot go offline concurrently.
> 
> Onlining CPUs of a 32-vCPU VM through sysfs, base and patched kernels
> alternating over 4 rounds of 5 runs, median of the 20 runs and
> interquartile range in parentheses; "single" onlines one CPU 0.3 s after
> taking it offline, "16 in a row" onlines CPUs 16-31 back to back:
> 
>   case                 before (ms)           after (ms)   change
>   single          24.8 (24.2-25.9)     16.7 (15.9-17.3)     -33%
>   16 in a row  143.1 (139.8-147.2)  130.0 (127.3-133.7)      -9%
> 
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
> ---

Makes sense to me

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

-- 
Cheers,

David

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

* Re: [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes
  2026-11-30  6:37 [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes Qiliang Yuan
  2026-11-30 10:54 ` David Hildenbrand (Arm)
@ 2026-11-30 10:56 ` David Hildenbrand
  2026-11-30 19:04 ` Oscar Salvador (SUSE)
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2026-11-30 10:56 UTC (permalink / raw)
  To: David Hildenbrand, Oscar Salvador, Andrew Morton, Qiliang Yuan
  Cc: linux-mm, linux-cxl, linux-kernel

On Mon, 30 Nov 2026 01:37:51 -0500, Qiliang Yuan wrote:
> cpu_up() calls try_online_node() for the node of every CPU it brings up,
> so that a CPU on a memoryless node that is not online yet gets its node
> onlined first. try_online_node() takes mem_hotplug_lock for write with
> mem_hotplug_begin() before it checks whether the node is online.
> 
> mem_hotplug_lock is a percpu rwsem, and taking it for write waits for an
> RCU grace period unless another writer released it shortly before.
> Bringing a CPU online through sysfs, as done when hot-adding vCPUs to a
> VM, therefore waits for a grace period although the node of the CPU is
> almost always online already.
> 
> [...]

Applied, thanks!

tree: mm/core.git
branch: memhp-7.5.misc

Applied patches will appear soon in mm-next, followed by linux-next.

Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.

It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.

[1/1] mm/memory_hotplug: return early from try_online_node() for online nodes
      https://git.kernel.org/mm/core/c/1a4211ca

-- 
Cheers,

David


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

* Re: [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes
  2026-11-30  6:37 [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes Qiliang Yuan
  2026-11-30 10:54 ` David Hildenbrand (Arm)
  2026-11-30 10:56 ` David Hildenbrand
@ 2026-11-30 19:04 ` Oscar Salvador (SUSE)
  2 siblings, 0 replies; 4+ messages in thread
From: Oscar Salvador (SUSE) @ 2026-11-30 19:04 UTC (permalink / raw)
  To: Qiliang Yuan
  Cc: David Hildenbrand, Oscar Salvador, Andrew Morton, linux-mm,
	linux-cxl, linux-kernel

On Mon, Nov 30, 2026 at 01:37:51AM -0500, Qiliang Yuan wrote:
> cpu_up() calls try_online_node() for the node of every CPU it brings up,
> so that a CPU on a memoryless node that is not online yet gets its node
> onlined first. try_online_node() takes mem_hotplug_lock for write with
> mem_hotplug_begin() before it checks whether the node is online.
> 
> mem_hotplug_lock is a percpu rwsem, and taking it for write waits for an
> RCU grace period unless another writer released it shortly before.
> Bringing a CPU online through sysfs, as done when hot-adding vCPUs to a
> VM, therefore waits for a grace period although the node of the CPU is
> almost always online already.
> 
> Check node_online() before taking the lock. A node with present CPUs is
> never offlined, see try_offline_node(), so the node of the CPU being
> brought up cannot go offline concurrently.
> 
> Onlining CPUs of a 32-vCPU VM through sysfs, base and patched kernels
> alternating over 4 rounds of 5 runs, median of the 20 runs and
> interquartile range in parentheses; "single" onlines one CPU 0.3 s after
> taking it offline, "16 in a row" onlines CPUs 16-31 back to back:
> 
>   case                 before (ms)           after (ms)   change
>   single          24.8 (24.2-25.9)     16.7 (15.9-17.3)     -33%
>   16 in a row  143.1 (139.8-147.2)  130.0 (127.3-133.7)      -9%
> 
> Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>

Acked-by: Oscar Salvador (SUSE) <osalvador@kernel.org>

 

-- 
Oscar Salvador
SUSE Labs

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

end of thread, other threads:[~2026-11-30 19:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  6:37 [PATCH] mm/memory_hotplug: return early from try_online_node() for online nodes Qiliang Yuan
2026-11-30 10:54 ` David Hildenbrand (Arm)
2026-11-30 10:56 ` David Hildenbrand
2026-11-30 19:04 ` Oscar Salvador (SUSE)

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

all inboxes | Powered by JetHome®