Merge branch 'x86-bootmem-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 Mar 2010 16:15:05 +0000 (08:15 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 3 Mar 2010 16:15:05 +0000 (08:15 -0800)
* 'x86-bootmem-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (30 commits)
  early_res: Need to save the allocation name in drop_range_partial()
  sparsemem: Fix compilation on PowerPC
  early_res: Add free_early_partial()
  x86: Fix non-bootmem compilation on PowerPC
  core: Move early_res from arch/x86 to kernel/
  x86: Add find_fw_memmap_area
  Move round_up/down to kernel.h
  x86: Make 32bit support NO_BOOTMEM
  early_res: Enhance check_and_double_early_res
  x86: Move back find_e820_area to e820.c
  x86: Add find_early_area_size
  x86: Separate early_res related code from e820.c
  x86: Move bios page reserve early to head32/64.c
  sparsemem: Put mem map for one node together.
  sparsemem: Put usemap for one node together
  x86: Make 64 bit use early_res instead of bootmem before slab
  x86: Only call dma32_reserve_bootmem 64bit !CONFIG_NUMA
  x86: Make early_node_mem get mem > 4 GB if possible
  x86: Dynamically increase early_res array size
  x86: Introduce max_early_res and early_res_count
  ...

13 files changed:
1  2 
arch/x86/Kconfig
arch/x86/kernel/setup.c
arch/x86/mm/init_32.c
arch/x86/mm/numa_64.c
arch/x86/pci/bus_numa.c
arch/x86/pci/bus_numa.h
arch/x86/pci/i386.c
include/linux/kernel.h
include/linux/mm.h
include/linux/mmzone.h
kernel/Makefile
mm/Kconfig
mm/page_alloc.c

diff --combined arch/x86/Kconfig
@@@ -45,7 -45,6 +45,7 @@@ config X8
        select HAVE_GENERIC_DMA_COHERENT if X86_32
        select HAVE_EFFICIENT_UNALIGNED_ACCESS
        select USER_STACKTRACE_SUPPORT
 +      select HAVE_REGS_AND_STACK_ACCESS_API
        select HAVE_DMA_API_DEBUG
        select HAVE_KERNEL_GZIP
        select HAVE_KERNEL_BZIP2
@@@ -184,6 -183,9 +184,9 @@@ config ARCH_SUPPORTS_OPTIMIZED_INLININ
  config ARCH_SUPPORTS_DEBUG_PAGEALLOC
        def_bool y
  
+ config HAVE_EARLY_RES
+       def_bool y
  config HAVE_INTEL_TXT
        def_bool y
        depends on EXPERIMENTAL && DMAR && ACPI
@@@ -569,6 -571,18 +572,18 @@@ config PARAVIRT_DEBU
          Enable to debug paravirt_ops internals.  Specifically, BUG if
          a paravirt_op is missing when it is called.
  
+ config NO_BOOTMEM
+       default y
+       bool "Disable Bootmem code"
+       ---help---
+         Use early_res directly instead of bootmem before slab is ready.
+               - allocator (buddy) [generic]
+               - early allocator (bootmem) [generic]
+               - very early allocator (reserve_early*()) [x86]
+               - very very early allocator (early brk model) [x86]
+         So reduce one layer between early allocator to final allocator
  config MEMTEST
        bool "Memtest"
        ---help---
diff --combined arch/x86/kernel/setup.c
  unsigned long max_low_pfn_mapped;
  unsigned long max_pfn_mapped;
  
 +#ifdef CONFIG_DMI
  RESERVE_BRK(dmi_alloc, 65536);
 +#endif
  
  unsigned int boot_cpu_id __read_mostly;
  
@@@ -969,15 -967,11 +969,11 @@@ void __init setup_arch(char **cmdline_p
  #endif
  
        initmem_init(0, max_pfn, acpi, k8);
+ #ifndef CONFIG_NO_BOOTMEM
+       early_res_to_bootmem(0, max_low_pfn<<PAGE_SHIFT);
+ #endif
  
- #ifdef CONFIG_X86_64
-       /*
-        * dma32_reserve_bootmem() allocates bootmem which may conflict
-        * with the crashkernel command line, so do that after
-        * reserve_crashkernel()
-        */
        dma32_reserve_bootmem();
- #endif
  
        reserve_ibft_region();
  
diff --combined arch/x86/mm/init_32.c
@@@ -241,7 -241,6 +241,7 @@@ kernel_physical_mapping_init(unsigned l
                             unsigned long page_size_mask)
  {
        int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
 +      unsigned long last_map_addr = end;
        unsigned long start_pfn, end_pfn;
        pgd_t *pgd_base = swapper_pg_dir;
        int pgd_idx, pmd_idx, pte_ofs;
@@@ -342,10 -341,9 +342,10 @@@ repeat
                                        prot = PAGE_KERNEL_EXEC;
  
                                pages_4k++;
 -                              if (mapping_iter == 1)
 +                              if (mapping_iter == 1) {
                                        set_pte(pte, pfn_pte(pfn, init_prot));
 -                              else
 +                                      last_map_addr = (pfn << PAGE_SHIFT) + PAGE_SIZE;
 +                              } else
                                        set_pte(pte, pfn_pte(pfn, prot));
                        }
                }
                mapping_iter = 2;
                goto repeat;
        }
 -      return 0;
 +      return last_map_addr;
  }
  
  pte_t *kmap_pte;
@@@ -750,6 -748,7 +750,7 @@@ static void __init zone_sizes_init(void
        free_area_init_nodes(max_zone_pfns);
  }
  
+ #ifndef CONFIG_NO_BOOTMEM
  static unsigned long __init setup_node_bootmem(int nodeid,
                                 unsigned long start_pfn,
                                 unsigned long end_pfn,
        printk(KERN_INFO "  node %d bootmap %08lx - %08lx\n",
                 nodeid, bootmap, bootmap + bootmap_size);
        free_bootmem_with_active_regions(nodeid, end_pfn);
-       early_res_to_bootmem(start_pfn<<PAGE_SHIFT, end_pfn<<PAGE_SHIFT);
  
        return bootmap + bootmap_size;
  }
+ #endif
  
  void __init setup_bootmem_allocator(void)
  {
+ #ifndef CONFIG_NO_BOOTMEM
        int nodeid;
        unsigned long bootmap_size, bootmap;
        /*
        if (bootmap == -1L)
                panic("Cannot find bootmem map of size %ld\n", bootmap_size);
        reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
+ #endif
  
        printk(KERN_INFO "  mapped low ram: 0 - %08lx\n",
                 max_pfn_mapped<<PAGE_SHIFT);
        printk(KERN_INFO "  low ram: 0 - %08lx\n", max_low_pfn<<PAGE_SHIFT);
  
+ #ifndef CONFIG_NO_BOOTMEM
        for_each_online_node(nodeid) {
                 unsigned long start_pfn, end_pfn;
  
                bootmap = setup_node_bootmem(nodeid, start_pfn, end_pfn,
                                                 bootmap);
        }
+ #endif
  
        after_bootmem = 1;
  }
diff --combined arch/x86/mm/numa_64.c
@@@ -163,30 -163,48 +163,48 @@@ static void * __init early_node_mem(in
                                    unsigned long end, unsigned long size,
                                    unsigned long align)
  {
-       unsigned long mem = find_e820_area(start, end, size, align);
-       void *ptr;
+       unsigned long mem;
  
+       /*
+        * put it on high as possible
+        * something will go with NODE_DATA
+        */
+       if (start < (MAX_DMA_PFN<<PAGE_SHIFT))
+               start = MAX_DMA_PFN<<PAGE_SHIFT;
+       if (start < (MAX_DMA32_PFN<<PAGE_SHIFT) &&
+           end > (MAX_DMA32_PFN<<PAGE_SHIFT))
+               start = MAX_DMA32_PFN<<PAGE_SHIFT;
+       mem = find_e820_area(start, end, size, align);
+       if (mem != -1L)
+               return __va(mem);
+       /* extend the search scope */
+       end = max_pfn_mapped << PAGE_SHIFT;
+       if (end > (MAX_DMA32_PFN<<PAGE_SHIFT))
+               start = MAX_DMA32_PFN<<PAGE_SHIFT;
+       else
+               start = MAX_DMA_PFN<<PAGE_SHIFT;
+       mem = find_e820_area(start, end, size, align);
        if (mem != -1L)
                return __va(mem);
  
-       ptr = __alloc_bootmem_nopanic(size, align, __pa(MAX_DMA_ADDRESS));
-       if (ptr == NULL) {
-               printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
+       printk(KERN_ERR "Cannot find %lu bytes in node %d\n",
                       size, nodeid);
-               return NULL;
-       }
-       return ptr;
+       return NULL;
  }
  
  /* Initialize bootmem allocator for a node */
  void __init
  setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
  {
-       unsigned long start_pfn, last_pfn, bootmap_pages, bootmap_size;
+       unsigned long start_pfn, last_pfn, nodedata_phys;
        const int pgdat_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
-       unsigned long bootmap_start, nodedata_phys;
-       void *bootmap;
        int nid;
+ #ifndef CONFIG_NO_BOOTMEM
+       unsigned long bootmap_start, bootmap_pages, bootmap_size;
+       void *bootmap;
+ #endif
  
        if (!end)
                return;
  
        start = roundup(start, ZONE_ALIGN);
  
-       printk(KERN_INFO "Bootmem setup node %d %016lx-%016lx\n", nodeid,
+       printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n", nodeid,
               start, end);
  
        start_pfn = start >> PAGE_SHIFT;
        if (node_data[nodeid] == NULL)
                return;
        nodedata_phys = __pa(node_data[nodeid]);
+       reserve_early(nodedata_phys, nodedata_phys + pgdat_size, "NODE_DATA");
        printk(KERN_INFO "  NODE_DATA [%016lx - %016lx]\n", nodedata_phys,
                nodedata_phys + pgdat_size - 1);
+       nid = phys_to_nid(nodedata_phys);
+       if (nid != nodeid)
+               printk(KERN_INFO "    NODE_DATA(%d) on node %d\n", nodeid, nid);
  
        memset(NODE_DATA(nodeid), 0, sizeof(pg_data_t));
-       NODE_DATA(nodeid)->bdata = &bootmem_node_data[nodeid];
+       NODE_DATA(nodeid)->node_id = nodeid;
        NODE_DATA(nodeid)->node_start_pfn = start_pfn;
        NODE_DATA(nodeid)->node_spanned_pages = last_pfn - start_pfn;
  
+ #ifndef CONFIG_NO_BOOTMEM
+       NODE_DATA(nodeid)->bdata = &bootmem_node_data[nodeid];
        /*
         * Find a place for the bootmem map
         * nodedata_phys could be on other nodes by alloc_bootmem,
         * of alloc_bootmem, that could clash with reserved range
         */
        bootmap_pages = bootmem_bootmap_pages(last_pfn - start_pfn);
-       nid = phys_to_nid(nodedata_phys);
-       if (nid == nodeid)
-               bootmap_start = roundup(nodedata_phys + pgdat_size, PAGE_SIZE);
-       else
-               bootmap_start = roundup(start, PAGE_SIZE);
+       bootmap_start = roundup(nodedata_phys + pgdat_size, PAGE_SIZE);
        /*
         * SMP_CACHE_BYTES could be enough, but init_bootmem_node like
         * to use that to align to PAGE_SIZE
        bootmap = early_node_mem(nodeid, bootmap_start, end,
                                 bootmap_pages<<PAGE_SHIFT, PAGE_SIZE);
        if (bootmap == NULL)  {
-               if (nodedata_phys < start || nodedata_phys >= end) {
-                       /*
-                        * only need to free it if it is from other node
-                        * bootmem
-                        */
-                       if (nid != nodeid)
-                               free_bootmem(nodedata_phys, pgdat_size);
-               }
+               free_early(nodedata_phys, nodedata_phys + pgdat_size);
                node_data[nodeid] = NULL;
                return;
        }
        bootmap_start = __pa(bootmap);
+       reserve_early(bootmap_start, bootmap_start+(bootmap_pages<<PAGE_SHIFT),
+                       "BOOTMAP");
  
        bootmap_size = init_bootmem_node(NODE_DATA(nodeid),
                                         bootmap_start >> PAGE_SHIFT,
        printk(KERN_INFO "  bootmap [%016lx -  %016lx] pages %lx\n",
                 bootmap_start, bootmap_start + bootmap_size - 1,
                 bootmap_pages);
-       free_bootmem_with_active_regions(nodeid, end);
-       /*
-        * convert early reserve to bootmem reserve earlier
-        * otherwise early_node_mem could use early reserved mem
-        * on previous node
-        */
-       early_res_to_bootmem(start, end);
-       /*
-        * in some case early_node_mem could use alloc_bootmem
-        * to get range on other node, don't reserve that again
-        */
-       if (nid != nodeid)
-               printk(KERN_INFO "    NODE_DATA(%d) on node %d\n", nodeid, nid);
-       else
-               reserve_bootmem_node(NODE_DATA(nodeid), nodedata_phys,
-                                       pgdat_size, BOOTMEM_DEFAULT);
        nid = phys_to_nid(bootmap_start);
        if (nid != nodeid)
                printk(KERN_INFO "    bootmap(%d) on node %d\n", nodeid, nid);
-       else
-               reserve_bootmem_node(NODE_DATA(nodeid), bootmap_start,
-                                bootmap_pages<<PAGE_SHIFT, BOOTMEM_DEFAULT);
+       free_bootmem_with_active_regions(nodeid, end);
+ #endif
  
        node_set_online(nodeid);
  }
@@@ -427,7 -424,7 +424,7 @@@ static int __init split_nodes_interleav
         * Calculate the number of big nodes that can be allocated as a result
         * of consolidating the remainder.
         */
 -      big = ((size & ~FAKE_NODE_MIN_HASH_MASK) & nr_nodes) /
 +      big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * nr_nodes) /
                FAKE_NODE_MIN_SIZE;
  
        size &= FAKE_NODE_MIN_HASH_MASK;
  }
  
  /*
 - * Splits num_nodes nodes up equally starting at node_start.  The return value
 - * is the number of nodes split up and addr is adjusted to be at the end of the
 - * last node allocated.
 + * Returns the end address of a node so that there is at least `size' amount of
 + * non-reserved memory or `max_addr' is reached.
   */
 -static int __init split_nodes_equally(u64 *addr, u64 max_addr, int node_start,
 -                                    int num_nodes)
 +static u64 __init find_end_of_node(u64 start, u64 max_addr, u64 size)
  {
 -      unsigned int big;
 -      u64 size;
 -      int i;
 -
 -      if (num_nodes <= 0)
 -              return -1;
 -      if (num_nodes > MAX_NUMNODES)
 -              num_nodes = MAX_NUMNODES;
 -      size = (max_addr - *addr - e820_hole_size(*addr, max_addr)) /
 -             num_nodes;
 -      /*
 -       * Calculate the number of big nodes that can be allocated as a result
 -       * of consolidating the leftovers.
 -       */
 -      big = ((size & ~FAKE_NODE_MIN_HASH_MASK) * num_nodes) /
 -            FAKE_NODE_MIN_SIZE;
 -
 -      /* Round down to nearest FAKE_NODE_MIN_SIZE. */
 -      size &= FAKE_NODE_MIN_HASH_MASK;
 -      if (!size) {
 -              printk(KERN_ERR "Not enough memory for each node.  "
 -                     "NUMA emulation disabled.\n");
 -              return -1;
 -      }
 -
 -      for (i = node_start; i < num_nodes + node_start; i++) {
 -              u64 end = *addr + size;
 +      u64 end = start + size;
  
 -              if (i < big)
 -                      end += FAKE_NODE_MIN_SIZE;
 -              /*
 -               * The final node can have the remaining system RAM.  Other
 -               * nodes receive roughly the same amount of available pages.
 -               */
 -              if (i == num_nodes + node_start - 1)
 +      while (end - start - e820_hole_size(start, end) < size) {
 +              end += FAKE_NODE_MIN_SIZE;
 +              if (end > max_addr) {
                        end = max_addr;
 -              else
 -                      while (end - *addr - e820_hole_size(*addr, end) <
 -                             size) {
 -                              end += FAKE_NODE_MIN_SIZE;
 -                              if (end > max_addr) {
 -                                      end = max_addr;
 -                                      break;
 -                              }
 -                      }
 -              if (setup_node_range(i, addr, end - *addr, max_addr) < 0)
                        break;
 +              }
        }
 -      return i - node_start + 1;
 +      return end;
  }
  
  /*
 - * Splits the remaining system RAM into chunks of size.  The remaining memory is
 - * always assigned to a final node and can be asymmetric.  Returns the number of
 - * nodes split.
 + * Sets up fake nodes of `size' interleaved over physical nodes ranging from
 + * `addr' to `max_addr'.  The return value is the number of nodes allocated.
   */
 -static int __init split_nodes_by_size(u64 *addr, u64 max_addr, int node_start,
 -                                    u64 size)
 +static int __init split_nodes_size_interleave(u64 addr, u64 max_addr, u64 size)
  {
 -      int i = node_start;
 -      size = (size << 20) & FAKE_NODE_MIN_HASH_MASK;
 -      while (!setup_node_range(i++, addr, size, max_addr))
 -              ;
 -      return i - node_start;
 +      nodemask_t physnode_mask = NODE_MASK_NONE;
 +      u64 min_size;
 +      int ret = 0;
 +      int i;
 +
 +      if (!size)
 +              return -1;
 +      /*
 +       * The limit on emulated nodes is MAX_NUMNODES, so the size per node is
 +       * increased accordingly if the requested size is too small.  This
 +       * creates a uniform distribution of node sizes across the entire
 +       * machine (but not necessarily over physical nodes).
 +       */
 +      min_size = (max_addr - addr - e820_hole_size(addr, max_addr)) /
 +                                              MAX_NUMNODES;
 +      min_size = max(min_size, FAKE_NODE_MIN_SIZE);
 +      if ((min_size & FAKE_NODE_MIN_HASH_MASK) < min_size)
 +              min_size = (min_size + FAKE_NODE_MIN_SIZE) &
 +                                              FAKE_NODE_MIN_HASH_MASK;
 +      if (size < min_size) {
 +              pr_err("Fake node size %LuMB too small, increasing to %LuMB\n",
 +                      size >> 20, min_size >> 20);
 +              size = min_size;
 +      }
 +      size &= FAKE_NODE_MIN_HASH_MASK;
 +
 +      for (i = 0; i < MAX_NUMNODES; i++)
 +              if (physnodes[i].start != physnodes[i].end)
 +                      node_set(i, physnode_mask);
 +      /*
 +       * Fill physical nodes with fake nodes of size until there is no memory
 +       * left on any of them.
 +       */
 +      while (nodes_weight(physnode_mask)) {
 +              for_each_node_mask(i, physnode_mask) {
 +                      u64 dma32_end = MAX_DMA32_PFN << PAGE_SHIFT;
 +                      u64 end;
 +
 +                      end = find_end_of_node(physnodes[i].start,
 +                                              physnodes[i].end, size);
 +                      /*
 +                       * If there won't be at least FAKE_NODE_MIN_SIZE of
 +                       * non-reserved memory in ZONE_DMA32 for the next node,
 +                       * this one must extend to the boundary.
 +                       */
 +                      if (end < dma32_end && dma32_end - end -
 +                          e820_hole_size(end, dma32_end) < FAKE_NODE_MIN_SIZE)
 +                              end = dma32_end;
 +
 +                      /*
 +                       * If there won't be enough non-reserved memory for the
 +                       * next node, this one must extend to the end of the
 +                       * physical node.
 +                       */
 +                      if (physnodes[i].end - end -
 +                          e820_hole_size(end, physnodes[i].end) < size)
 +                              end = physnodes[i].end;
 +
 +                      /*
 +                       * Setup the fake node that will be allocated as bootmem
 +                       * later.  If setup_node_range() returns non-zero, there
 +                       * is no more memory available on this physical node.
 +                       */
 +                      if (setup_node_range(ret++, &physnodes[i].start,
 +                                              end - physnodes[i].start,
 +                                              physnodes[i].end) < 0)
 +                              node_clear(i, physnode_mask);
 +              }
 +      }
 +      return ret;
  }
  
  /*
  static int __init numa_emulation(unsigned long start_pfn,
                        unsigned long last_pfn, int acpi, int k8)
  {
 -      u64 size, addr = start_pfn << PAGE_SHIFT;
 +      u64 addr = start_pfn << PAGE_SHIFT;
        u64 max_addr = last_pfn << PAGE_SHIFT;
 -      int num_nodes = 0, num = 0, coeff_flag, coeff = -1, i;
        int num_phys_nodes;
 +      int num_nodes;
 +      int i;
  
        num_phys_nodes = setup_physnodes(addr, max_addr, acpi, k8);
        /*
 -       * If the numa=fake command-line is just a single number N, split the
 -       * system RAM into N fake nodes.
 +       * If the numa=fake command-line contains a 'M' or 'G', it represents
 +       * the fixed node size.  Otherwise, if it is just a single number N,
 +       * split the system RAM into N fake nodes.
         */
 -      if (!strchr(cmdline, '*') && !strchr(cmdline, ',')) {
 -              long n = simple_strtol(cmdline, NULL, 0);
 -
 -              num_nodes = split_nodes_interleave(addr, max_addr,
 -                                                      num_phys_nodes, n);
 -              if (num_nodes < 0)
 -                      return num_nodes;
 -              goto out;
 -      }
 +      if (strchr(cmdline, 'M') || strchr(cmdline, 'G')) {
 +              u64 size;
  
 -      /* Parse the command line. */
 -      for (coeff_flag = 0; ; cmdline++) {
 -              if (*cmdline && isdigit(*cmdline)) {
 -                      num = num * 10 + *cmdline - '0';
 -                      continue;
 -              }
 -              if (*cmdline == '*') {
 -                      if (num > 0)
 -                              coeff = num;
 -                      coeff_flag = 1;
 -              }
 -              if (!*cmdline || *cmdline == ',') {
 -                      if (!coeff_flag)
 -                              coeff = 1;
 -                      /*
 -                       * Round down to the nearest FAKE_NODE_MIN_SIZE.
 -                       * Command-line coefficients are in megabytes.
 -                       */
 -                      size = ((u64)num << 20) & FAKE_NODE_MIN_HASH_MASK;
 -                      if (size)
 -                              for (i = 0; i < coeff; i++, num_nodes++)
 -                                      if (setup_node_range(num_nodes, &addr,
 -                                              size, max_addr) < 0)
 -                                              goto done;
 -                      if (!*cmdline)
 -                              break;
 -                      coeff_flag = 0;
 -                      coeff = -1;
 -              }
 -              num = 0;
 -      }
 -done:
 -      if (!num_nodes)
 -              return -1;
 -      /* Fill remainder of system RAM, if appropriate. */
 -      if (addr < max_addr) {
 -              if (coeff_flag && coeff < 0) {
 -                      /* Split remaining nodes into num-sized chunks */
 -                      num_nodes += split_nodes_by_size(&addr, max_addr,
 -                                                       num_nodes, num);
 -                      goto out;
 -              }
 -              switch (*(cmdline - 1)) {
 -              case '*':
 -                      /* Split remaining nodes into coeff chunks */
 -                      if (coeff <= 0)
 -                              break;
 -                      num_nodes += split_nodes_equally(&addr, max_addr,
 -                                                       num_nodes, coeff);
 -                      break;
 -              case ',':
 -                      /* Do not allocate remaining system RAM */
 -                      break;
 -              default:
 -                      /* Give one final node */
 -                      setup_node_range(num_nodes, &addr, max_addr - addr,
 -                                       max_addr);
 -                      num_nodes++;
 -              }
 +              size = memparse(cmdline, &cmdline);
 +              num_nodes = split_nodes_size_interleave(addr, max_addr, size);
 +      } else {
 +              unsigned long n;
 +
 +              n = simple_strtoul(cmdline, NULL, 0);
 +              num_nodes = split_nodes_interleave(addr, max_addr, num_phys_nodes, n);
        }
 -out:
 +
 +      if (num_nodes < 0)
 +              return num_nodes;
        memnode_shift = compute_hash_shift(nodes, num_nodes, NULL);
        if (memnode_shift < 0) {
                memnode_shift = 0;
@@@ -709,6 -739,10 +706,10 @@@ unsigned long __init numa_free_all_boot
        for_each_online_node(i)
                pages += free_all_bootmem_node(NODE_DATA(i));
  
+ #ifdef CONFIG_NO_BOOTMEM
+       pages += free_all_memory_core_early(MAX_NUMNODES);
+ #endif
        return pages;
  }
  
diff --combined arch/x86/pci/bus_numa.c
@@@ -1,11 -1,11 +1,11 @@@
  #include <linux/init.h>
  #include <linux/pci.h>
+ #include <linux/range.h>
  
  #include "bus_numa.h"
  
  int pci_root_num;
  struct pci_root_info pci_root_info[PCI_ROOT_NR];
- int found_all_numa_early;
  
  void x86_pci_root_bus_res_quirks(struct pci_bus *b)
  {
        if (!pci_root_num)
                return;
  
-       /* for amd, if only one root bus, don't need to do anything */
-       if (pci_root_num < 2 && found_all_numa_early)
-               return;
        for (i = 0; i < pci_root_num; i++) {
                if (pci_root_info[i].bus_min == b->number)
                        break;
        printk(KERN_DEBUG "PCI: peer root bus %02x res updated from pci conf\n",
                        b->number);
  
 +      pci_bus_remove_resources(b);
        info = &pci_root_info[i];
        for (j = 0; j < info->res_num; j++) {
                struct resource *res;
                struct resource *root;
  
                res = &info->res[j];
 -              b->resource[j] = res;
 +              pci_bus_add_resource(b, res, 0);
                if (res->flags & IORESOURCE_IO)
                        root = &ioport_resource;
                else
@@@ -52,8 -47,8 +48,8 @@@
        }
  }
  
- void __devinit update_res(struct pci_root_info *info, size_t start,
-                             size_t end, unsigned long flags, int merge)
+ void __devinit update_res(struct pci_root_info *info, resource_size_t start,
+                         resource_size_t end, unsigned long flags, int merge)
  {
        int i;
        struct resource *res;
        if (start > end)
                return;
  
+       if (start == MAX_RESOURCE)
+               return;
        if (!merge)
                goto addit;
  
        /* try to merge it with old one */
        for (i = 0; i < info->res_num; i++) {
-               size_t final_start, final_end;
-               size_t common_start, common_end;
+               resource_size_t final_start, final_end;
+               resource_size_t common_start, common_end;
  
                res = &info->res[i];
                if (res->flags != flags)
                        continue;
  
-               common_start = max((size_t)res->start, start);
-               common_end = min((size_t)res->end, end);
+               common_start = max(res->start, start);
+               common_end = min(res->end, end);
                if (common_start > common_end + 1)
                        continue;
  
-               final_start = min((size_t)res->start, start);
-               final_end = max((size_t)res->end, end);
+               final_start = min(res->start, start);
+               final_end = max(res->end, end);
  
                res->start = final_start;
                res->end = final_end;
diff --combined arch/x86/pci/bus_numa.h
@@@ -1,8 -1,9 +1,8 @@@
- #ifdef CONFIG_X86_64
+ #ifndef __BUS_NUMA_H
+ #define __BUS_NUMA_H
  /*
   * sub bus (transparent) will use entres from 3 to store extra from
 - * root, so need to make sure we have enough slot there, Should we
 - * increase PCI_BUS_NUM_RESOURCES?
 + * root, so need to make sure we have enough slot there.
   */
  #define RES_NUM 16
  struct pci_root_info {
@@@ -19,8 -20,7 +19,7 @@@
  #define PCI_ROOT_NR 4
  extern int pci_root_num;
  extern struct pci_root_info pci_root_info[PCI_ROOT_NR];
- extern int found_all_numa_early;
  
- extern void update_res(struct pci_root_info *info, size_t start,
-                             size_t end, unsigned long flags, int merge);
+ extern void update_res(struct pci_root_info *info, resource_size_t start,
+                     resource_size_t end, unsigned long flags, int merge);
  #endif
diff --combined arch/x86/pci/i386.c
@@@ -60,20 -60,22 +60,20 @@@ skip_isa_ioresource_align(struct pci_de
   * but we want to try to avoid allocating at 0x2900-0x2bff
   * which might have be mirrored at 0x0100-0x03ff..
   */
 -void
 -pcibios_align_resource(void *data, struct resource *res,
 +resource_size_t
 +pcibios_align_resource(void *data, const struct resource *res,
                        resource_size_t size, resource_size_t align)
  {
        struct pci_dev *dev = data;
 +      resource_size_t start = res->start;
  
        if (res->flags & IORESOURCE_IO) {
 -              resource_size_t start = res->start;
 -
                if (skip_isa_ioresource_align(dev))
 -                      return;
 -              if (start & 0x300) {
 +                      return start;
 +              if (start & 0x300)
                        start = (start + 0x3ff) & ~0x3ff;
 -                      res->start = start;
 -              }
        }
 +      return start;
  }
  EXPORT_SYMBOL(pcibios_align_resource);
  
@@@ -255,10 -257,6 +255,6 @@@ void __init pcibios_resource_survey(voi
   */
  fs_initcall(pcibios_assign_resources);
  
- void __weak x86_pci_root_bus_res_quirks(struct pci_bus *b)
- {
- }
  /*
   *  If we set up a device for bus mastering, we need to check the latency
   *  timer as certain crappy BIOSes forget to set it properly.
diff --combined include/linux/kernel.h
@@@ -44,6 -44,16 +44,16 @@@ extern const char linux_proc_banner[]
  
  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
  
+ /*
+  * This looks more complex than it should be. But we need to
+  * get the type for the ~ right in round_down (it needs to be
+  * as wide as the result!), and we want to evaluate the macro
+  * arguments just once each.
+  */
+ #define __round_mask(x, y) ((__typeof__(x))((y)-1))
+ #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+ #define round_down(x, y) ((x) & ~__round_mask(x, y))
  #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
  #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
@@@ -124,7 -134,7 +134,7 @@@ extern int _cond_resched(void)
  #endif
  
  #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
 -  void __might_sleep(char *file, int line, int preempt_offset);
 +  void __might_sleep(const char *file, int line, int preempt_offset);
  /**
   * might_sleep - annotation for functions that can sleep
   *
  # define might_sleep() \
        do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  #else
 -  static inline void __might_sleep(char *file, int line, int preempt_offset) { }
 +  static inline void __might_sleep(const char *file, int line,
 +                                 int preempt_offset) { }
  # define might_sleep() do { might_resched(); } while (0)
  #endif
  
diff --combined include/linux/mm.h
@@@ -12,6 -12,7 +12,7 @@@
  #include <linux/prio_tree.h>
  #include <linux/debug_locks.h>
  #include <linux/mm_types.h>
+ #include <linux/range.h>
  
  struct mempolicy;
  struct anon_vma;
@@@ -1049,6 -1050,10 +1050,10 @@@ extern void get_pfn_range_for_nid(unsig
  extern unsigned long find_min_pfn_with_active_regions(void);
  extern void free_bootmem_with_active_regions(int nid,
                                                unsigned long max_low_pfn);
+ int add_from_early_node_map(struct range *range, int az,
+                                  int nr_range, int nid);
+ void *__alloc_memory_core_early(int nodeid, u64 size, u64 align,
+                                u64 goal, u64 limit);
  typedef int (*work_fn_t)(unsigned long, unsigned long, void *);
  extern void work_with_active_regions(int nid, work_fn_t work_fn, void *data);
  extern void sparse_memory_present_with_active_regions(int nid);
@@@ -1081,7 -1086,11 +1086,7 @@@ extern void si_meminfo(struct sysinfo 
  extern void si_meminfo_node(struct sysinfo *val, int nid);
  extern int after_bootmem;
  
 -#ifdef CONFIG_NUMA
  extern void setup_per_cpu_pageset(void);
 -#else
 -static inline void setup_per_cpu_pageset(void) {}
 -#endif
  
  extern void zone_pcp_update(struct zone *zone);
  
@@@ -1317,12 -1326,19 +1322,19 @@@ extern int randomize_va_space
  const char * arch_vma_name(struct vm_area_struct *vma);
  void print_vma_addr(char *prefix, unsigned long rip);
  
+ void sparse_mem_maps_populate_node(struct page **map_map,
+                                  unsigned long pnum_begin,
+                                  unsigned long pnum_end,
+                                  unsigned long map_count,
+                                  int nodeid);
  struct page *sparse_mem_map_populate(unsigned long pnum, int nid);
  pgd_t *vmemmap_pgd_populate(unsigned long addr, int node);
  pud_t *vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node);
  pmd_t *vmemmap_pmd_populate(pud_t *pud, unsigned long addr, int node);
  pte_t *vmemmap_pte_populate(pmd_t *pmd, unsigned long addr, int node);
  void *vmemmap_alloc_block(unsigned long size, int node);
+ void *vmemmap_alloc_block_buf(unsigned long size, int node);
  void vmemmap_verify(pte_t *, int, unsigned long, unsigned long);
  int vmemmap_populate_basepages(struct page *start_page,
                                                unsigned long pages, int node);
diff --combined include/linux/mmzone.h
@@@ -184,7 -184,13 +184,7 @@@ struct per_cpu_pageset 
        s8 stat_threshold;
        s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];
  #endif
 -} ____cacheline_aligned_in_smp;
 -
 -#ifdef CONFIG_NUMA
 -#define zone_pcp(__z, __cpu) ((__z)->pageset[(__cpu)])
 -#else
 -#define zone_pcp(__z, __cpu) (&(__z)->pageset[(__cpu)])
 -#endif
 +};
  
  #endif /* !__GENERATING_BOUNDS.H */
  
@@@ -300,8 -306,10 +300,8 @@@ struct zone 
         */
        unsigned long           min_unmapped_pages;
        unsigned long           min_slab_pages;
 -      struct per_cpu_pageset  *pageset[NR_CPUS];
 -#else
 -      struct per_cpu_pageset  pageset[NR_CPUS];
  #endif
 +      struct per_cpu_pageset __percpu *pageset;
        /*
         * free areas of different sizes
         */
@@@ -612,7 -620,9 +612,9 @@@ typedef struct pglist_data 
        struct page_cgroup *node_page_cgroup;
  #endif
  #endif
+ #ifndef CONFIG_NO_BOOTMEM
        struct bootmem_data *bdata;
+ #endif
  #ifdef CONFIG_MEMORY_HOTPLUG
        /*
         * Must be held any time you expect node_start_pfn, node_present_pages
diff --combined kernel/Makefile
@@@ -10,7 -10,8 +10,8 @@@ obj-y     = sched.o fork.o exec_domain.
            kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
            hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
            notifier.o ksysfs.o pm_qos_params.o sched_clock.o cred.o \
-           async.o
+           async.o range.o
+ obj-$(CONFIG_HAVE_EARLY_RES) += early_res.o
  obj-y += groups.o
  
  ifdef CONFIG_FUNCTION_TRACER
@@@ -100,7 -101,6 +101,7 @@@ obj-$(CONFIG_SLOW_WORK_DEBUG) += slow-w
  obj-$(CONFIG_PERF_EVENTS) += perf_event.o
  obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
  obj-$(CONFIG_USER_RETURN_NOTIFIER) += user-return-notifier.o
 +obj-$(CONFIG_PADATA) += padata.o
  
  ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
  # According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
diff --combined mm/Kconfig
@@@ -115,6 -115,10 +115,10 @@@ config SPARSEMEM_EXTREM
  config SPARSEMEM_VMEMMAP_ENABLE
        bool
  
+ config SPARSEMEM_ALLOC_MEM_MAP_TOGETHER
+       def_bool y
+       depends on SPARSEMEM && X86_64
  config SPARSEMEM_VMEMMAP
        bool "Sparse Memory virtual memmap"
        depends on SPARSEMEM && SPARSEMEM_VMEMMAP_ENABLE
@@@ -195,7 -199,7 +199,7 @@@ config BOUNC
  config NR_QUICK
        int
        depends on QUICKLIST
 -      default "2" if SUPERH || AVR32
 +      default "2" if AVR32
        default "1"
  
  config VIRT_TO_BUS
diff --combined mm/page_alloc.c
@@@ -1009,10 -1009,10 +1009,10 @@@ static void drain_pages(unsigned int cp
                struct per_cpu_pageset *pset;
                struct per_cpu_pages *pcp;
  
 -              pset = zone_pcp(zone, cpu);
 +              local_irq_save(flags);
 +              pset = per_cpu_ptr(zone->pageset, cpu);
  
                pcp = &pset->pcp;
 -              local_irq_save(flags);
                free_pcppages_bulk(zone, pcp->count, pcp);
                pcp->count = 0;
                local_irq_restore(flags);
@@@ -1096,6 -1096,7 +1096,6 @@@ static void free_hot_cold_page(struct p
        arch_free_page(page, 0);
        kernel_map_pages(page, 1, 0);
  
 -      pcp = &zone_pcp(zone, get_cpu())->pcp;
        migratetype = get_pageblock_migratetype(page);
        set_page_private(page, migratetype);
        local_irq_save(flags);
                migratetype = MIGRATE_MOVABLE;
        }
  
 +      pcp = &this_cpu_ptr(zone->pageset)->pcp;
        if (cold)
                list_add_tail(&page->lru, &pcp->lists[migratetype]);
        else
  
  out:
        local_irq_restore(flags);
 -      put_cpu();
  }
  
  void free_hot_page(struct page *page)
@@@ -1180,15 -1181,17 +1180,15 @@@ struct page *buffered_rmqueue(struct zo
        unsigned long flags;
        struct page *page;
        int cold = !!(gfp_flags & __GFP_COLD);
 -      int cpu;
  
  again:
 -      cpu  = get_cpu();
        if (likely(order == 0)) {
                struct per_cpu_pages *pcp;
                struct list_head *list;
  
 -              pcp = &zone_pcp(zone, cpu)->pcp;
 -              list = &pcp->lists[migratetype];
                local_irq_save(flags);
 +              pcp = &this_cpu_ptr(zone->pageset)->pcp;
 +              list = &pcp->lists[migratetype];
                if (list_empty(list)) {
                        pcp->count += rmqueue_bulk(zone, 0,
                                        pcp->batch, list,
        __count_zone_vm_events(PGALLOC, zone, 1 << order);
        zone_statistics(preferred_zone, zone);
        local_irq_restore(flags);
 -      put_cpu();
  
        VM_BUG_ON(bad_range(zone, page));
        if (prep_new_page(page, order, gfp_flags))
  
  failed:
        local_irq_restore(flags);
 -      put_cpu();
        return NULL;
  }
  
@@@ -2175,7 -2180,7 +2175,7 @@@ void show_free_areas(void
                for_each_online_cpu(cpu) {
                        struct per_cpu_pageset *pageset;
  
 -                      pageset = zone_pcp(zone, cpu);
 +                      pageset = per_cpu_ptr(zone->pageset, cpu);
  
                        printk("CPU %4d: hi:%5d, btch:%4d usd:%4d\n",
                               cpu, pageset->pcp.high,
@@@ -2740,29 -2745,10 +2740,29 @@@ static void build_zonelist_cache(pg_dat
  
  #endif        /* CONFIG_NUMA */
  
 +/*
 + * Boot pageset table. One per cpu which is going to be used for all
 + * zones and all nodes. The parameters will be set in such a way
 + * that an item put on a list will immediately be handed over to
 + * the buddy list. This is safe since pageset manipulation is done
 + * with interrupts disabled.
 + *
 + * The boot_pagesets must be kept even after bootup is complete for
 + * unused processors and/or zones. They do play a role for bootstrapping
 + * hotplugged processors.
 + *
 + * zoneinfo_show() and maybe other functions do
 + * not check if the processor is online before following the pageset pointer.
 + * Other parts of the kernel may not check if the zone is available.
 + */
 +static void setup_pageset(struct per_cpu_pageset *p, unsigned long batch);
 +static DEFINE_PER_CPU(struct per_cpu_pageset, boot_pageset);
 +
  /* return values int ....just for stop_machine() */
  static int __build_all_zonelists(void *dummy)
  {
        int nid;
 +      int cpu;
  
  #ifdef CONFIG_NUMA
        memset(node_load, 0, sizeof(node_load));
                build_zonelists(pgdat);
                build_zonelist_cache(pgdat);
        }
 +
 +      /*
 +       * Initialize the boot_pagesets that are going to be used
 +       * for bootstrapping processors. The real pagesets for
 +       * each zone will be allocated later when the per cpu
 +       * allocator is available.
 +       *
 +       * boot_pagesets are used also for bootstrapping offline
 +       * cpus if the system is already booted because the pagesets
 +       * are needed to initialize allocators on a specific cpu too.
 +       * F.e. the percpu allocator needs the page allocator which
 +       * needs the percpu allocator in order to allocate its pagesets
 +       * (a chicken-egg dilemma).
 +       */
 +      for_each_possible_cpu(cpu)
 +              setup_pageset(&per_cpu(boot_pageset, cpu), 0);
 +
        return 0;
  }
  
@@@ -3127,33 -3096,121 +3127,33 @@@ static void setup_pagelist_highmark(str
                pcp->batch = PAGE_SHIFT * 8;
  }
  
 -
 -#ifdef CONFIG_NUMA
 -/*
 - * Boot pageset table. One per cpu which is going to be used for all
 - * zones and all nodes. The parameters will be set in such a way
 - * that an item put on a list will immediately be handed over to
 - * the buddy list. This is safe since pageset manipulation is done
 - * with interrupts disabled.
 - *
 - * Some NUMA counter updates may also be caught by the boot pagesets.
 - *
 - * The boot_pagesets must be kept even after bootup is complete for
 - * unused processors and/or zones. They do play a role for bootstrapping
 - * hotplugged processors.
 - *
 - * zoneinfo_show() and maybe other functions do
 - * not check if the processor is online before following the pageset pointer.
 - * Other parts of the kernel may not check if the zone is available.
 - */
 -static struct per_cpu_pageset boot_pageset[NR_CPUS];
 -
  /*
 - * Dynamically allocate memory for the
 - * per cpu pageset array in struct zone.
 + * Allocate per cpu pagesets and initialize them.
 + * Before this call only boot pagesets were available.
 + * Boot pagesets will no longer be used by this processorr
 + * after setup_per_cpu_pageset().
   */
 -static int __cpuinit process_zones(int cpu)
 +void __init setup_per_cpu_pageset(void)
  {
 -      struct zone *zone, *dzone;
 -      int node = cpu_to_node(cpu);
 -
 -      node_set_state(node, N_CPU);    /* this node has a cpu */
 +      struct zone *zone;
 +      int cpu;
  
        for_each_populated_zone(zone) {
 -              zone_pcp(zone, cpu) = kmalloc_node(sizeof(struct per_cpu_pageset),
 -                                       GFP_KERNEL, node);
 -              if (!zone_pcp(zone, cpu))
 -                      goto bad;
 -
 -              setup_pageset(zone_pcp(zone, cpu), zone_batchsize(zone));
 -
 -              if (percpu_pagelist_fraction)
 -                      setup_pagelist_highmark(zone_pcp(zone, cpu),
 -                          (zone->present_pages / percpu_pagelist_fraction));
 -      }
 -
 -      return 0;
 -bad:
 -      for_each_zone(dzone) {
 -              if (!populated_zone(dzone))
 -                      continue;
 -              if (dzone == zone)
 -                      break;
 -              kfree(zone_pcp(dzone, cpu));
 -              zone_pcp(dzone, cpu) = &boot_pageset[cpu];
 -      }
 -      return -ENOMEM;
 -}
 +              zone->pageset = alloc_percpu(struct per_cpu_pageset);
  
 -static inline void free_zone_pagesets(int cpu)
 -{
 -      struct zone *zone;
 -
 -      for_each_zone(zone) {
 -              struct per_cpu_pageset *pset = zone_pcp(zone, cpu);
 +              for_each_possible_cpu(cpu) {
 +                      struct per_cpu_pageset *pcp = per_cpu_ptr(zone->pageset, cpu);
  
 -              /* Free per_cpu_pageset if it is slab allocated */
 -              if (pset != &boot_pageset[cpu])
 -                      kfree(pset);
 -              zone_pcp(zone, cpu) = &boot_pageset[cpu];
 -      }
 -}
 +                      setup_pageset(pcp, zone_batchsize(zone));
  
 -static int __cpuinit pageset_cpuup_callback(struct notifier_block *nfb,
 -              unsigned long action,
 -              void *hcpu)
 -{
 -      int cpu = (long)hcpu;
 -      int ret = NOTIFY_OK;
 -
 -      switch (action) {
 -      case CPU_UP_PREPARE:
 -      case CPU_UP_PREPARE_FROZEN:
 -              if (process_zones(cpu))
 -                      ret = NOTIFY_BAD;
 -              break;
 -      case CPU_UP_CANCELED:
 -      case CPU_UP_CANCELED_FROZEN:
 -      case CPU_DEAD:
 -      case CPU_DEAD_FROZEN:
 -              free_zone_pagesets(cpu);
 -              break;
 -      default:
 -              break;
 +                      if (percpu_pagelist_fraction)
 +                              setup_pagelist_highmark(pcp,
 +                                      (zone->present_pages /
 +                                              percpu_pagelist_fraction));
 +              }
        }
 -      return ret;
  }
  
 -static struct notifier_block __cpuinitdata pageset_notifier =
 -      { &pageset_cpuup_callback, NULL, 0 };
 -
 -void __init setup_per_cpu_pageset(void)
 -{
 -      int err;
 -
 -      /* Initialize per_cpu_pageset for cpu 0.
 -       * A cpuup callback will do this for every cpu
 -       * as it comes online
 -       */
 -      err = process_zones(smp_processor_id());
 -      BUG_ON(err);
 -      register_cpu_notifier(&pageset_notifier);
 -}
 -
 -#endif
 -
  static noinline __init_refok
  int zone_wait_table_init(struct zone *zone, unsigned long zone_size_pages)
  {
@@@ -3207,7 -3264,7 +3207,7 @@@ static int __zone_pcp_update(void *data
                struct per_cpu_pageset *pset;
                struct per_cpu_pages *pcp;
  
 -              pset = zone_pcp(zone, cpu);
 +              pset = per_cpu_ptr(zone->pageset, cpu);
                pcp = &pset->pcp;
  
                local_irq_save(flags);
@@@ -3225,17 -3282,21 +3225,17 @@@ void zone_pcp_update(struct zone *zone
  
  static __meminit void zone_pcp_init(struct zone *zone)
  {
 -      int cpu;
 -      unsigned long batch = zone_batchsize(zone);
 +      /*
 +       * per cpu subsystem is not up at this point. The following code
 +       * relies on the ability of the linker to provide the
 +       * offset of a (static) per cpu variable into the per cpu area.
 +       */
 +      zone->pageset = &boot_pageset;
  
 -      for (cpu = 0; cpu < NR_CPUS; cpu++) {
 -#ifdef CONFIG_NUMA
 -              /* Early boot. Slab allocator not functional yet */
 -              zone_pcp(zone, cpu) = &boot_pageset[cpu];
 -              setup_pageset(&boot_pageset[cpu],0);
 -#else
 -              setup_pageset(zone_pcp(zone,cpu), batch);
 -#endif
 -      }
        if (zone->present_pages)
 -              printk(KERN_DEBUG "  %s zone: %lu pages, LIFO batch:%lu\n",
 -                      zone->name, zone->present_pages, batch);
 +              printk(KERN_DEBUG "  %s zone: %lu pages, LIFO batch:%u\n",
 +                      zone->name, zone->present_pages,
 +                                       zone_batchsize(zone));
  }
  
  __meminit int init_currently_empty_zone(struct zone *zone,
@@@ -3374,6 -3435,61 +3374,61 @@@ void __init free_bootmem_with_active_re
        }
  }
  
+ int __init add_from_early_node_map(struct range *range, int az,
+                                  int nr_range, int nid)
+ {
+       int i;
+       u64 start, end;
+       /* need to go over early_node_map to find out good range for node */
+       for_each_active_range_index_in_nid(i, nid) {
+               start = early_node_map[i].start_pfn;
+               end = early_node_map[i].end_pfn;
+               nr_range = add_range(range, az, nr_range, start, end);
+       }
+       return nr_range;
+ }
+ #ifdef CONFIG_NO_BOOTMEM
+ void * __init __alloc_memory_core_early(int nid, u64 size, u64 align,
+                                       u64 goal, u64 limit)
+ {
+       int i;
+       void *ptr;
+       /* need to go over early_node_map to find out good range for node */
+       for_each_active_range_index_in_nid(i, nid) {
+               u64 addr;
+               u64 ei_start, ei_last;
+               ei_last = early_node_map[i].end_pfn;
+               ei_last <<= PAGE_SHIFT;
+               ei_start = early_node_map[i].start_pfn;
+               ei_start <<= PAGE_SHIFT;
+               addr = find_early_area(ei_start, ei_last,
+                                        goal, limit, size, align);
+               if (addr == -1ULL)
+                       continue;
+ #if 0
+               printk(KERN_DEBUG "alloc (nid=%d %llx - %llx) (%llx - %llx) %llx %llx => %llx\n",
+                               nid,
+                               ei_start, ei_last, goal, limit, size,
+                               align, addr);
+ #endif
+               ptr = phys_to_virt(addr);
+               memset(ptr, 0, size);
+               reserve_early_without_check(addr, addr + size, "BOOTMEM");
+               return ptr;
+       }
+       return NULL;
+ }
+ #endif
  void __init work_with_active_regions(int nid, work_fn_t work_fn, void *data)
  {
        int i;
@@@ -4406,7 -4522,11 +4461,11 @@@ void __init set_dma_reserve(unsigned lo
  }
  
  #ifndef CONFIG_NEED_MULTIPLE_NODES
- struct pglist_data __refdata contig_page_data = { .bdata = &bootmem_node_data[0] };
+ struct pglist_data __refdata contig_page_data = {
+ #ifndef CONFIG_NO_BOOTMEM
+  .bdata = &bootmem_node_data[0]
+ #endif
+  };
  EXPORT_SYMBOL(contig_page_data);
  #endif
  
@@@ -4749,11 -4869,10 +4808,11 @@@ int percpu_pagelist_fraction_sysctl_han
        if (!write || (ret == -EINVAL))
                return ret;
        for_each_populated_zone(zone) {
 -              for_each_online_cpu(cpu) {
 +              for_each_possible_cpu(cpu) {
                        unsigned long  high;
                        high = zone->present_pages / percpu_pagelist_fraction;
 -                      setup_pagelist_highmark(zone_pcp(zone, cpu), high);
 +                      setup_pagelist_highmark(
 +                              per_cpu_ptr(zone->pageset, cpu), high);
                }
        }
        return 0;