[Patch / 001](memory hotplug) fix some defects of memory notifer callback interface.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Current memory notifier has some defects yet. (Nothing uses it.)
This patch is to fix for them.

  - Add information of start_pfn and nr_pages for callback functions.
    They can't do anything without those information.
  - Add notification going-online status.
    It is necessary for creating per node structure before the node's
    pages are available.
  - Fix compile error of (un)register_memory_notifier().


Signed-off-by: Yasunori Goto <[email protected]>

---
 drivers/base/memory.c  |   10 +++++++---
 include/linux/memory.h |   16 ++++++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

Index: current/drivers/base/memory.c
===================================================================
--- current.orig/drivers/base/memory.c	2007-09-28 11:21:00.000000000 +0900
+++ current/drivers/base/memory.c	2007-09-28 11:23:46.000000000 +0900
@@ -155,10 +155,13 @@ memory_block_action(struct memory_block 
 	struct page *first_page;
 	int ret;
 	int old_state = mem->state;
+	struct memory_notify arg;
 
 	psection = mem->phys_index;
 	first_page = pfn_to_page(psection << PFN_SECTION_SHIFT);
 
+	arg.start_pfn = page_to_pfn(first_page);
+	arg.nr_pages = PAGES_PER_SECTION;
 	/*
 	 * The probe routines leave the pages reserved, just
 	 * as the bootmem code does.  Make sure they're still
@@ -178,12 +181,13 @@ memory_block_action(struct memory_block 
 
 	switch (action) {
 		case MEM_ONLINE:
+			memory_notify(MEM_GOING_ONLINE, &arg);
 			start_pfn = page_to_pfn(first_page);
 			ret = online_pages(start_pfn, PAGES_PER_SECTION);
 			break;
 		case MEM_OFFLINE:
 			mem->state = MEM_GOING_OFFLINE;
-			memory_notify(MEM_GOING_OFFLINE, NULL);
+			memory_notify(MEM_GOING_OFFLINE, &arg);
 			start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
 			ret = remove_memory(start_paddr,
 					    PAGES_PER_SECTION << PAGE_SHIFT);
@@ -191,7 +195,7 @@ memory_block_action(struct memory_block 
 				mem->state = old_state;
 				break;
 			}
-			memory_notify(MEM_MAPPING_INVALID, NULL);
+			memory_notify(MEM_MAPPING_INVALID, &arg);
 			break;
 		default:
 			printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n",
@@ -203,7 +207,7 @@ memory_block_action(struct memory_block 
 	 * For now, only notify on successful memory operations
 	 */
 	if (!ret)
-		memory_notify(action, NULL);
+		memory_notify(action, &arg);
 
 	return ret;
 }
Index: current/include/linux/memory.h
===================================================================
--- current.orig/include/linux/memory.h	2007-09-28 11:18:25.000000000 +0900
+++ current/include/linux/memory.h	2007-09-28 11:23:46.000000000 +0900
@@ -37,10 +37,16 @@ struct memory_block {
 	struct sys_device sysdev;
 };
 
+struct memory_notify {
+	unsigned long start_pfn;
+	unsigned long nr_pages;
+};
+
 /* These states are exposed to userspace as text strings in sysfs */
-#define	MEM_ONLINE		(1<<0) /* exposed to userspace */
-#define	MEM_GOING_OFFLINE	(1<<1) /* exposed to userspace */
-#define	MEM_OFFLINE		(1<<2) /* exposed to userspace */
+#define MEM_GOING_ONLINE	(1<<0) /* exposed to userspace */
+#define	MEM_ONLINE		(1<<1) /* exposed to userspace */
+#define	MEM_GOING_OFFLINE	(1<<2) /* exposed to userspace */
+#define	MEM_OFFLINE		(1<<3) /* exposed to userspace */
 
 /*
  * All of these states are currently kernel-internal for notifying
@@ -52,7 +58,7 @@ struct memory_block {
  * pfn_to_page() stop working.  Any notifiers that want to be called
  * after that should have priority <0.
  */
-#define	MEM_MAPPING_INVALID	(1<<3)
+#define	MEM_MAPPING_INVALID	(1<<4)
 
 struct notifier_block;
 struct mem_section;
@@ -70,6 +76,8 @@ static inline void unregister_memory_not
 {
 }
 #else
+extern int register_memory_notifier(struct notifier_block *nb);
+extern void unregister_memory_notifier(struct notifier_block *nb);
 extern int register_new_memory(struct mem_section *);
 extern int unregister_memory_section(struct mem_section *);
 extern int memory_dev_init(void);

-- 
Yasunori Goto 


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux