powerpc: permanently include 8xx registers in reg.h
[linux-2.6-block.git] / mm / sparse.c
index 72f010d9bff5014a47fd0ff5703e73ce5be1cf48..bf32de9e666b5697f74cdbe319d4c783237065ab 100644 (file)
@@ -11,6 +11,8 @@
 #include <linux/export.h>
 #include <linux/spinlock.h>
 #include <linux/vmalloc.h>
+#include <linux/swap.h>
+#include <linux/swapops.h>
 
 #include "internal.h"
 #include <asm/dma.h>
@@ -470,6 +472,12 @@ struct page __init *__populate_section_memmap(unsigned long pfn,
 static void *sparsemap_buf __meminitdata;
 static void *sparsemap_buf_end __meminitdata;
 
+static inline void __meminit sparse_buffer_free(unsigned long size)
+{
+       WARN_ON(!sparsemap_buf || size == 0);
+       memblock_free_early(__pa(sparsemap_buf), size);
+}
+
 static void __init sparse_buffer_init(unsigned long size, int nid)
 {
        phys_addr_t addr = __pa(MAX_DMA_ADDRESS);
@@ -486,7 +494,7 @@ static void __init sparse_buffer_fini(void)
        unsigned long size = sparsemap_buf_end - sparsemap_buf;
 
        if (sparsemap_buf && size > 0)
-               memblock_free_early(__pa(sparsemap_buf), size);
+               sparse_buffer_free(size);
        sparsemap_buf = NULL;
 }
 
@@ -495,11 +503,15 @@ void * __meminit sparse_buffer_alloc(unsigned long size)
        void *ptr = NULL;
 
        if (sparsemap_buf) {
-               ptr = PTR_ALIGN(sparsemap_buf, size);
+               ptr = (void *) roundup((unsigned long)sparsemap_buf, size);
                if (ptr + size > sparsemap_buf_end)
                        ptr = NULL;
-               else
+               else {
+                       /* Free redundant aligned space */
+                       if ((unsigned long)(ptr - sparsemap_buf) > 0)
+                               sparse_buffer_free((unsigned long)(ptr - sparsemap_buf));
                        sparsemap_buf = ptr + size;
+               }
        }
        return ptr;
 }
@@ -867,7 +879,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn,
         */
        page_init_poison(pfn_to_page(start_pfn), sizeof(struct page) * nr_pages);
 
-       ms = __pfn_to_section(start_pfn);
+       ms = __nr_to_section(section_nr);
        set_section_nid(section_nr, nid);
        section_mark_present(ms);
 
@@ -884,9 +896,6 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
 {
        int i;
 
-       if (!memmap)
-               return;
-
        /*
         * A further optimization is to have per section refcounted
         * num_poisoned_pages.  But that would need more space per memmap, so
@@ -898,7 +907,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
 
        for (i = 0; i < nr_pages; i++) {
                if (PageHWPoison(&memmap[i])) {
-                       atomic_long_sub(1, &num_poisoned_pages);
+                       num_poisoned_pages_dec();
                        ClearPageHWPoison(&memmap[i]);
                }
        }