Commit 0f1cfe9d authored by Toshi Kani's avatar Toshi Kani Committed by Linus Torvalds
Browse files

mm/hotplug: remove stop_machine() from try_offline_node()

lock_device_hotplug() serializes hotplug & online/offline operations.  The
lock is held in common sysfs online/offline interfaces and ACPI hotplug
code paths.

And here are the code paths:

- CPU & Mem online/offline via sysfs online

- Mem online via sysfs state:

- ACPI CPU & Mem hot-add:

- ACPI CPU & Mem hot-delete:

try_offline_node() off-lines a node if all memory sections and cpus are
removed on the node.  It is called from acpi_processor_remove() and
acpi_memory_remove_memory()->remove_memory() paths, both of which are in
the ACPI hotplug code.

try_offline_node() calls stop_machine() to stop all cpus while checking
all cpu status with the assumption that the caller is not protected from
CPU hotplug or CPU online/offline operations.  However, the caller is
always serialized with lock_device_hotplug().  Also, the code needs to be
properly serialized with a lock, not by stopping all cpus at a random
place with stop_machine().

This patch removes the use of stop_machine() in try_offline_node() and
adds comments to try_offline_node() and remove_memory() that
lock_device_hotplug() is required.
Signed-off-by: default avatarToshi Kani <>
Acked-by: default avatarRafael J. Wysocki <>
Cc: KOSAKI Motohiro <>
Cc: KAMEZAWA Hiroyuki <>
Cc: Tang Chen <>
Cc: Yasuaki Ishimatsu <>
Cc: Wanpeng Li <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 27356f54
......@@ -1695,9 +1695,8 @@ static int is_memblock_offlined_cb(struct memory_block *mem, void *arg)
return ret;
static int check_cpu_on_node(void *data)
static int check_cpu_on_node(pg_data_t *pgdat)
struct pglist_data *pgdat = data;
int cpu;
for_each_present_cpu(cpu) {
......@@ -1712,10 +1711,9 @@ static int check_cpu_on_node(void *data)
return 0;
static void unmap_cpu_on_node(void *data)
static void unmap_cpu_on_node(pg_data_t *pgdat)
struct pglist_data *pgdat = data;
int cpu;
......@@ -1724,10 +1722,11 @@ static void unmap_cpu_on_node(void *data)
static int check_and_unmap_cpu_on_node(void *data)
static int check_and_unmap_cpu_on_node(pg_data_t *pgdat)
int ret = check_cpu_on_node(data);
int ret;
ret = check_cpu_on_node(pgdat);
if (ret)
return ret;
......@@ -1736,11 +1735,18 @@ static int check_and_unmap_cpu_on_node(void *data)
* the cpu_to_node() now.
return 0;
/* offline the node if all memory sections of this node are removed */
* try_offline_node
* Offline a node if all memory sections and cpus of the node are removed.
* NOTE: The caller must call lock_device_hotplug() to serialize hotplug
* and online/offline operations before this call.
void try_offline_node(int nid)
pg_data_t *pgdat = NODE_DATA(nid);
......@@ -1766,7 +1772,7 @@ void try_offline_node(int nid)
if (stop_machine(check_and_unmap_cpu_on_node, pgdat, NULL))
if (check_and_unmap_cpu_on_node(pgdat))
......@@ -1803,6 +1809,13 @@ void try_offline_node(int nid)
* remove_memory
* NOTE: The caller must call lock_device_hotplug() to serialize hotplug
* and online/offline operations before this call, as required by
* try_offline_node().
void __ref remove_memory(int nid, u64 start, u64 size)
int ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment