[PATCH] memory hotplug: move section_mem_map alloc to sparse.c
authorDave Hansen <haveblue@us.ibm.com>
Sun, 30 Oct 2005 01:16:55 +0000 (18:16 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 30 Oct 2005 04:40:44 +0000 (21:40 -0700)
This basically keeps up from having to extern __kmalloc_section_memmap().

The vaddr_in_vmalloc_area() helper could go in a vmalloc header, but that
header gets hard to work with, because it needs some arch-specific macros.
Just stick it in here for now, instead of creating another header.

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Lion Vollnhals <webmaster@schiggl.de>
Signed-off-by: Jiri Slaby <xslaby@fi.muni.cz>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/acpi/acpi_memhotplug.c
drivers/base/memory.c
mm/memory_hotplug.c
mm/sparse.c

index 01a1bd239263bcaa416050ae8184482e1ebbc9e8..2143609d29362f0b7896c7e5dc07dadfba8a64aa 100644 (file)
@@ -200,8 +200,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
         * Note: Assume that this function returns zero on success
         */
        result = add_memory(mem_device->start_addr,
-                           (mem_device->end_addr - mem_device->start_addr) + 1,
-                           mem_device->read_write_attribute);
+                           (mem_device->end_addr - mem_device->start_addr) + 1);
        if (result) {
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "\nadd_memory failed\n"));
                mem_device->state = MEMORY_INVALID_STATE;
@@ -259,7 +258,7 @@ static int acpi_memory_disable_device(struct acpi_memory_device *mem_device)
         * Ask the VM to offline this memory range.
         * Note: Assume that this function returns zero on success
         */
-       result = remove_memory(start, len, attr);
+       result = remove_memory(start, len);
        if (result) {
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Hot-Remove failed.\n"));
                return_VALUE(result);
index 785cb6e6b91c6d71606cab20055260b6f0da6572..b7ddd651d664ecf76da5f620bd06b0e6d01ba837 100644 (file)
@@ -340,15 +340,12 @@ static int memory_probe_init(void)
 static int add_memory_block(unsigned long node_id, struct mem_section *section,
                     unsigned long state, int phys_device)
 {
-       size_t size = sizeof(struct memory_block);
-       struct memory_block *mem = kmalloc(size, GFP_KERNEL);
+       struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL);
        int ret = 0;
 
        if (!mem)
                return -ENOMEM;
 
-       memset(mem, 0, size);
-
        mem->phys_index = __section_nr(section);
        mem->state = state;
        init_MUTEX(&mem->state_sem);
index 855e0fc928b3cc6b1685b07a98231ff9077215ab..2e916c308ae6278c4fc05aab3591d785e173131d 100644 (file)
 
 #include <asm/tlbflush.h>
 
-static struct page *__kmalloc_section_memmap(unsigned long nr_pages)
-{
-       struct page *page, *ret;
-       unsigned long memmap_size = sizeof(struct page) * nr_pages;
-
-       page = alloc_pages(GFP_KERNEL, get_order(memmap_size));
-       if (page)
-               goto got_map_page;
-
-       ret = vmalloc(memmap_size);
-       if (ret)
-               goto got_map_ptr;
-
-       return NULL;
-got_map_page:
-       ret = (struct page *)pfn_to_kaddr(page_to_pfn(page));
-got_map_ptr:
-       memset(ret, 0, memmap_size);
-
-       return ret;
-}
-
 extern void zonetable_add(struct zone *zone, int nid, int zid, unsigned long pfn,
                          unsigned long size);
 static void __add_zone(struct zone *zone, unsigned long phys_start_pfn)
@@ -60,35 +38,15 @@ static void __add_zone(struct zone *zone, unsigned long phys_start_pfn)
        zonetable_add(zone, nid, zone_type, phys_start_pfn, nr_pages);
 }
 
-extern int sparse_add_one_section(struct zone *, unsigned long,
-                                 struct page *mem_map);
+extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
+                                 int nr_pages);
 static int __add_section(struct zone *zone, unsigned long phys_start_pfn)
 {
        struct pglist_data *pgdat = zone->zone_pgdat;
        int nr_pages = PAGES_PER_SECTION;
-       struct page *memmap;
        int ret;
 
-       /*
-        * This can potentially allocate memory, and does its own
-        * internal locking.
-        */
-       sparse_index_init(pfn_to_section_nr(phys_start_pfn), pgdat->node_id);
-
-       pgdat_resize_lock(pgdat, &flags);
-       memmap = __kmalloc_section_memmap(nr_pages);
-       ret = sparse_add_one_section(zone, phys_start_pfn, memmap);
-       pgdat_resize_unlock(pgdat, &flags);
-
-       if (ret <= 0) {
-               /* the mem_map didn't get used */
-               if (memmap >= (struct page *)VMALLOC_START &&
-                   memmap < (struct page *)VMALLOC_END)
-                       vfree(memmap);
-               else
-                       free_pages((unsigned long)memmap,
-                                  get_order(sizeof(struct page) * nr_pages));
-       }
+       ret = sparse_add_one_section(zone, phys_start_pfn, nr_pages);
 
        if (ret < 0)
                return ret;
index 0d3bd4bf3aaa1a76c28106b3776b3fd304c7ab99..72079b538e2dac74c136bcebfa47bca7dceb0daa 100644 (file)
@@ -5,8 +5,10 @@
 #include <linux/mm.h>
 #include <linux/mmzone.h>
 #include <linux/bootmem.h>
+#include <linux/highmem.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
+#include <linux/vmalloc.h>
 #include <asm/dma.h>
 
 /*
@@ -187,6 +189,45 @@ static struct page *sparse_early_mem_map_alloc(unsigned long pnum)
        return NULL;
 }
 
+static struct page *__kmalloc_section_memmap(unsigned long nr_pages)
+{
+       struct page *page, *ret;
+       unsigned long memmap_size = sizeof(struct page) * nr_pages;
+
+       page = alloc_pages(GFP_KERNEL, get_order(memmap_size));
+       if (page)
+               goto got_map_page;
+
+       ret = vmalloc(memmap_size);
+       if (ret)
+               goto got_map_ptr;
+
+       return NULL;
+got_map_page:
+       ret = (struct page *)pfn_to_kaddr(page_to_pfn(page));
+got_map_ptr:
+       memset(ret, 0, memmap_size);
+
+       return ret;
+}
+
+static int vaddr_in_vmalloc_area(void *addr)
+{
+       if (addr >= (void *)VMALLOC_START &&
+           addr < (void *)VMALLOC_END)
+               return 1;
+       return 0;
+}
+
+static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
+{
+       if (vaddr_in_vmalloc_area(memmap))
+               vfree(memmap);
+       else
+               free_pages((unsigned long)memmap,
+                          get_order(sizeof(struct page) * nr_pages));
+}
+
 /*
  * Allocate the accumulated non-linear sections, allocate a mem_map
  * for each and record the physical to section mapping.
@@ -212,14 +253,37 @@ void sparse_init(void)
  * set.  If this is <=0, then that means that the passed-in
  * map was not consumed and must be freed.
  */
-int sparse_add_one_section(unsigned long start_pfn, int nr_pages, struct page *map)
+int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
+                          int nr_pages)
 {
-       struct mem_section *ms = __pfn_to_section(start_pfn);
+       unsigned long section_nr = pfn_to_section_nr(start_pfn);
+       struct pglist_data *pgdat = zone->zone_pgdat;
+       struct mem_section *ms;
+       struct page *memmap;
+       unsigned long flags;
+       int ret;
 
-       if (ms->section_mem_map & SECTION_MARKED_PRESENT)
-               return -EEXIST;
+       /*
+        * no locking for this, because it does its own
+        * plus, it does a kmalloc
+        */
+       sparse_index_init(section_nr, pgdat->node_id);
+       memmap = __kmalloc_section_memmap(nr_pages);
+
+       pgdat_resize_lock(pgdat, &flags);
 
+       ms = __pfn_to_section(start_pfn);
+       if (ms->section_mem_map & SECTION_MARKED_PRESENT) {
+               ret = -EEXIST;
+               goto out;
+       }
        ms->section_mem_map |= SECTION_MARKED_PRESENT;
 
-       return sparse_init_one_section(ms, pfn_to_section_nr(start_pfn), map);
+       ret = sparse_init_one_section(ms, section_nr, memmap);
+
+       if (ret <= 0)
+               __kfree_section_memmap(memmap, nr_pages);
+out:
+       pgdat_resize_unlock(pgdat, &flags);
+       return ret;
 }