@@ -1286,6 +1286,37 @@ int offline_memory(u64 start, u64 size)
return 0;
}
+/* offline the node if all memory sections of this node are removed */
+static void try_offline_node(int nid)
+{
+ unsigned long start_pfn = NODE_DATA(nid)->node_start_pfn;
+ unsigned long end_pfn = start_pfn + NODE_DATA(nid)->node_spanned_pages;
+ unsigned long pfn;
+
+ for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
+ unsigned long section_nr = pfn_to_section_nr(pfn);
+
+ if (!present_section_nr(section_nr))
+ continue;
+
+ if (pfn_to_nid(pfn) != nid)
+ continue;
+
+ /*
+ * some memory sections of this node are not removed, and we
+ * can't offline node now.
+ */
+ return;
+ }
+
+ /*
+ * all memory sections of this node are removed, we can offline this
+ * node now.
+ */
+ node_set_offline(nid);
+ unregister_one_node(nid);
+}
+
int __ref remove_memory(int nid, u64 start, u64 size)
{
int ret = 0;
@@ -1306,6 +1337,8 @@ int __ref remove_memory(int nid, u64 start, u64 size)
firmware_map_remove(start, start + size, "System RAM");
arch_remove_memory(start, size);
+
+ try_offline_node(nid);
out:
unlock_memory_hotplug();
return ret;