···165extern void put_page_bootmem(struct page *page);166#endif167168+/*169+ * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug170+ * notifier will be called under this. 2) offline/online/add/remove memory171+ * will not run simultaneously.172+ */173+174void lock_memory_hotplug(void);175void unlock_memory_hotplug(void);176
+4
mm/memory_hotplug.c
···409 int ret;410 struct memory_notify arg;4110412 arg.start_pfn = pfn;413 arg.nr_pages = nr_pages;414 arg.status_change_nid = -1;···422 ret = notifier_to_errno(ret);423 if (ret) {424 memory_notify(MEM_CANCEL_ONLINE, &arg);0425 return ret;426 }427 /*···447 printk(KERN_DEBUG "online_pages %lx at %lx failed\n",448 nr_pages, pfn);449 memory_notify(MEM_CANCEL_ONLINE, &arg);0450 return ret;451 }452···472473 if (onlined_pages)474 memory_notify(MEM_ONLINE, &arg);0475476 return 0;477}
···409 int ret;410 struct memory_notify arg;411412+ lock_memory_hotplug();413 arg.start_pfn = pfn;414 arg.nr_pages = nr_pages;415 arg.status_change_nid = -1;···421 ret = notifier_to_errno(ret);422 if (ret) {423 memory_notify(MEM_CANCEL_ONLINE, &arg);424+ unlock_memory_hotplug();425 return ret;426 }427 /*···445 printk(KERN_DEBUG "online_pages %lx at %lx failed\n",446 nr_pages, pfn);447 memory_notify(MEM_CANCEL_ONLINE, &arg);448+ unlock_memory_hotplug();449 return ret;450 }451···469470 if (onlined_pages)471 memory_notify(MEM_ONLINE, &arg);472+ unlock_memory_hotplug();473474 return 0;475}