Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753334Ab3GXSlY (ORCPT ); Wed, 24 Jul 2013 14:41:24 -0400 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:51990 "EHLO e28smtp08.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752153Ab3GXSlX (ORCPT ); Wed, 24 Jul 2013 14:41:23 -0400 Message-ID: <51F01FC7.5040403@linux.vnet.ibm.com> Date: Wed, 24 Jul 2013 13:41:11 -0500 From: Nathan Fontenot User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: LKML , linux-mm , linuxppc-dev@lists.ozlabs.org CC: Greg Kroah-Hartman , isimatu.yasuaki@jp.fujitsu.com Subject: [PATCH 5/8] Add notifiers for memory hot add/remove References: <51F01E06.6090800@linux.vnet.ibm.com> In-Reply-To: <51F01E06.6090800@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13072418-2000-0000-0000-00000D057608 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5433 Lines: 167 In order to allow architectures or other subsystems to do any needed work prior to hot adding or hot removing memory the memory notifier chain should be updated to provide notifications of these events. This patch adds the notifications for memory hot add and hot remove. Signed-off-by: Nathan Fontenot -- Documentation/memory-hotplug.txt | 26 +++++++++++++++++++++++--- include/linux/memory.h | 6 ++++++ mm/memory_hotplug.c | 25 ++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 6 deletions(-) Index: linux/include/linux/memory.h =================================================================== --- linux.orig/include/linux/memory.h +++ linux/include/linux/memory.h @@ -50,6 +50,12 @@ int arch_get_memory_phys_device(unsigned #define MEM_GOING_ONLINE (1<<3) #define MEM_CANCEL_ONLINE (1<<4) #define MEM_CANCEL_OFFLINE (1<<5) +#define MEM_BEING_HOT_REMOVED (1<<6) +#define MEM_HOT_REMOVED (1<<7) +#define MEM_CANCEL_HOT_REMOVE (1<<8) +#define MEM_BEING_HOT_ADDED (1<<9) +#define MEM_HOT_ADDED (1<<10) +#define MEM_CANCEL_HOT_ADD (1<<11) struct memory_notify { unsigned long start_pfn; Index: linux/mm/memory_hotplug.c =================================================================== --- linux.orig/mm/memory_hotplug.c +++ linux/mm/memory_hotplug.c @@ -1073,17 +1073,25 @@ out: int __ref add_memory(int nid, u64 start, u64 size) { pg_data_t *pgdat = NULL; - bool new_pgdat; + bool new_pgdat = false; bool new_node; - struct resource *res; + struct resource *res = NULL; + struct memory_notify arg; int ret; lock_memory_hotplug(); + arg.start_pfn = start >> PAGE_SHIFT; + arg.nr_pages = size / PAGE_SIZE; + ret = memory_notify(MEM_BEING_HOT_ADDED, &arg); + ret = notifier_to_errno(ret); + if (ret) + goto error; + res = register_memory_resource(start, size); ret = -EEXIST; if (!res) - goto out; + goto error; { /* Stupid hack to suppress address-never-null warning */ void *p = NODE_DATA(nid); @@ -1119,9 +1127,12 @@ int __ref add_memory(int nid, u64 start, /* create new memmap entry */ firmware_map_add_hotplug(start, start + size, "System RAM"); + memory_notify(MEM_HOT_ADDED, &arg); goto out; error: + memory_notify(MEM_CANCEL_HOT_ADD, &arg); + /* rollback pgdat allocation and others */ if (new_pgdat) rollback_node_hotadd(nid, pgdat); @@ -1784,10 +1795,15 @@ EXPORT_SYMBOL(try_offline_node); void __ref remove_memory(int nid, u64 start, u64 size) { + struct memory_notify arg; int ret; lock_memory_hotplug(); + arg.start_pfn = start >> PAGE_SHIFT; + arg.nr_pages = size / PAGE_SIZE; + memory_notify(MEM_BEING_HOT_REMOVED, &arg); + /* * All memory blocks must be offlined before removing memory. Check * whether all memory blocks in question are offline and trigger a BUG() @@ -1796,6 +1812,7 @@ void __ref remove_memory(int nid, u64 st ret = walk_memory_range(PFN_DOWN(start), PFN_UP(start + size - 1), NULL, is_memblock_offlined_cb); if (ret) { + memory_notify(MEM_CANCEL_HOT_REMOVE, &arg); unlock_memory_hotplug(); BUG(); } @@ -1807,6 +1824,8 @@ void __ref remove_memory(int nid, u64 st try_offline_node(nid); + memory_notify(MEM_HOT_REMOVED, &arg); + unlock_memory_hotplug(); } EXPORT_SYMBOL_GPL(remove_memory); Index: linux/Documentation/memory-hotplug.txt =================================================================== --- linux.orig/Documentation/memory-hotplug.txt +++ linux/Documentation/memory-hotplug.txt @@ -371,7 +371,9 @@ Need more implementation yet.... -------------------------------- 8. Memory hotplug event notifier -------------------------------- -Memory hotplug has event notifier. There are 6 types of notification. +Memory hotplug has event notifier. There are 12 types of notification, the +first six relate to memory hotplug and the second six relate to memory hot +add/remove. MEMORY_GOING_ONLINE Generated before new memory becomes available in order to be able to @@ -398,6 +400,24 @@ MEMORY_CANCEL_OFFLINE MEMORY_OFFLINE Generated after offlining memory is complete. +MEMORY_BEING_HOT_REMOVED + Generated prior to the process of hot removing memory. + +MEMORY_CANCEL_HOT_REMOVE + Generated if MEMORY_BEING_HOT_REMOVED fails. + +MEMORY_HOT_REMOVED + Generated when memory has been successfully hot removed. + +MEMORY_BEING_HOT_ADDED + Generated prior to the process of hot adding memory. + +MEMORY_HOT_ADD_CANCEL + Generated if MEMORY_BEING_HOT_ADDED fails. + +MEMORY_HOT_ADDED + Generated when memory has successfully been hot added. + A callback routine can be registered by hotplug_memory_notifier(callback_func, priority) @@ -412,8 +432,8 @@ struct memory_notify { int status_change_nid; } -start_pfn is start_pfn of online/offline memory. -nr_pages is # of pages of online/offline memory. +start_pfn is start_pfn of online/offline/add/remove memory. +nr_pages is # of pages of online/offline/add/remove memory. status_change_nid_normal is set node id when N_NORMAL_MEMORY of nodemask is (will be) set/clear, if this is -1, then nodemask status is not changed. status_change_nid_high is set node id when N_HIGH_MEMORY of nodemask -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/