linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Fontenot <nfont@linux.vnet.ibm.com>
To: LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	linuxppc-dev@lists.ozlabs.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	isimatu.yasuaki@jp.fujitsu.com
Subject: [PATCH 5/8] Add notifiers for memory hot add/remove
Date: Wed, 24 Jul 2013 13:41:11 -0500	[thread overview]
Message-ID: <51F01FC7.5040403@linux.vnet.ibm.com> (raw)
In-Reply-To: <51F01E06.6090800@linux.vnet.ibm.com>

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 <nfont@linux.vnet.ibm.com>
--
 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, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2013-07-24 18:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-24 18:33 [PATCH 0/8] Correct memory hot add/remove for powerpc Nathan Fontenot
2013-07-24 18:35 ` [PATCH 1/8] register bootmem pages for powerpc when sparse vmemmap is not defined Nathan Fontenot
2013-08-02  2:27   ` Michael Ellerman
2013-08-02 19:04     ` Nathan Fontenot
2013-07-24 18:36 ` [PATCH 2/8] Mark powerpc memory resources as busy Nathan Fontenot
2013-08-02  2:28   ` Michael Ellerman
2013-08-02 19:05     ` Nathan Fontenot
2013-08-05  3:11       ` Michael Ellerman
2013-07-24 18:37 ` [PATCH 3/8] Add all memory via sysfs probe interface at once Nathan Fontenot
2013-08-02  2:32   ` Michael Ellerman
2013-08-02 19:13     ` Nathan Fontenot
2013-08-05  3:13       ` Michael Ellerman
2013-08-06 20:44         ` Nathan Fontenot
2013-08-09  7:16           ` Benjamin Herrenschmidt
2013-07-24 18:39 ` [PATCH 4/8] Create a sysfs release file for hot removing memory Nathan Fontenot
2013-07-24 18:41 ` Nathan Fontenot [this message]
2013-07-24 18:44 ` [PATCH 6/8] Update the powerpc arch specific memory add/remove handlers Nathan Fontenot
2013-07-24 18:45 ` [PATCH 7/8] Add memory hot add/remove notifier handlers for pwoerpc Nathan Fontenot
2013-07-24 18:47 ` [PATCH 8/8] Remove no longer needed powerpc memory node update handler Nathan Fontenot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51F01FC7.5040403@linux.vnet.ibm.com \
    --to=nfont@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=isimatu.yasuaki@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox