Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Johannes Weiner | 57cfc29 | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 2 | * bootmem - A boot-time physical memory allocator and configurator |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 1999 Ingo Molnar |
Johannes Weiner | 57cfc29 | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 5 | * 1999 Kanoj Sarcar, SGI |
| 6 | * 2008 Johannes Weiner |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Johannes Weiner | 57cfc29 | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 8 | * Access to this subsystem has to be serialized externally (which is true |
| 9 | * for the boot process anyway). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
Franck Bui-Huu | bbc7b92 | 2006-09-25 23:31:07 -0700 | [diff] [blame] | 12 | #include <linux/pfn.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Catalin Marinas | ec3a354 | 2009-07-07 10:33:01 +0100 | [diff] [blame] | 15 | #include <linux/kmemleak.h> |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 16 | #include <linux/range.h> |
Franck Bui-Huu | e786e86 | 2006-09-25 23:31:06 -0700 | [diff] [blame] | 17 | |
| 18 | #include <asm/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/io.h> |
Heiko Carstens | dfd54cb | 2006-09-25 23:31:33 -0700 | [diff] [blame] | 20 | #include <asm/processor.h> |
Franck Bui-Huu | e786e86 | 2006-09-25 23:31:06 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "internal.h" |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | unsigned long max_low_pfn; |
| 25 | unsigned long min_low_pfn; |
| 26 | unsigned long max_pfn; |
| 27 | |
Vivek Goyal | 92aa63a | 2005-06-25 14:58:18 -0700 | [diff] [blame] | 28 | #ifdef CONFIG_CRASH_DUMP |
| 29 | /* |
| 30 | * If we have booted due to a crash, max_pfn will be a very low value. We need |
| 31 | * to know the amount of memory that the previous kernel used. |
| 32 | */ |
| 33 | unsigned long saved_max_pfn; |
| 34 | #endif |
| 35 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 36 | #ifndef CONFIG_NO_BOOTMEM |
Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 37 | bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata; |
| 38 | |
Johannes Weiner | 636cc40 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 39 | static struct list_head bdata_list __initdata = LIST_HEAD_INIT(bdata_list); |
| 40 | |
Johannes Weiner | 2e5237d | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 41 | static int bootmem_debug; |
| 42 | |
| 43 | static int __init bootmem_debug_setup(char *buf) |
| 44 | { |
| 45 | bootmem_debug = 1; |
| 46 | return 0; |
| 47 | } |
| 48 | early_param("bootmem_debug", bootmem_debug_setup); |
| 49 | |
| 50 | #define bdebug(fmt, args...) ({ \ |
| 51 | if (unlikely(bootmem_debug)) \ |
| 52 | printk(KERN_INFO \ |
| 53 | "bootmem::%s " fmt, \ |
Harvey Harrison | 80a914d | 2008-10-15 22:01:25 -0700 | [diff] [blame] | 54 | __func__, ## args); \ |
Johannes Weiner | 2e5237d | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 55 | }) |
| 56 | |
Johannes Weiner | df049a5 | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 57 | static unsigned long __init bootmap_bytes(unsigned long pages) |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 58 | { |
Johannes Weiner | df049a5 | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 59 | unsigned long bytes = (pages + 7) / 8; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 60 | |
Johannes Weiner | df049a5 | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 61 | return ALIGN(bytes, sizeof(long)); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 64 | /** |
| 65 | * bootmem_bootmap_pages - calculate bitmap size in pages |
| 66 | * @pages: number of pages the bitmap has to represent |
| 67 | */ |
Franck Bui-Huu | f71bf0c | 2006-09-25 23:31:08 -0700 | [diff] [blame] | 68 | unsigned long __init bootmem_bootmap_pages(unsigned long pages) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Johannes Weiner | df049a5 | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 70 | unsigned long bytes = bootmap_bytes(pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Johannes Weiner | df049a5 | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 72 | return PAGE_ALIGN(bytes) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
Franck Bui-Huu | f71bf0c | 2006-09-25 23:31:08 -0700 | [diff] [blame] | 74 | |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 75 | /* |
| 76 | * link bdata in order |
| 77 | */ |
Franck Bui-Huu | 69d49e6 | 2006-09-25 23:31:04 -0700 | [diff] [blame] | 78 | static void __init link_bootmem(bootmem_data_t *bdata) |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 79 | { |
Johannes Weiner | 636cc40 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 80 | struct list_head *iter; |
Franck Bui-Huu | f71bf0c | 2006-09-25 23:31:08 -0700 | [diff] [blame] | 81 | |
Johannes Weiner | 636cc40 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 82 | list_for_each(iter, &bdata_list) { |
| 83 | bootmem_data_t *ent; |
| 84 | |
| 85 | ent = list_entry(iter, bootmem_data_t, list); |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 86 | if (bdata->node_min_pfn < ent->node_min_pfn) |
Johannes Weiner | 636cc40 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 87 | break; |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 88 | } |
Johannes Weiner | 636cc40 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 89 | list_add_tail(&bdata->list, iter); |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Franck Bui-Huu | bbc7b92 | 2006-09-25 23:31:07 -0700 | [diff] [blame] | 92 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | * Called once to set up the allocator itself. |
| 94 | */ |
Johannes Weiner | 8ae0446 | 2008-07-23 21:26:59 -0700 | [diff] [blame] | 95 | static unsigned long __init init_bootmem_core(bootmem_data_t *bdata, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | unsigned long mapstart, unsigned long start, unsigned long end) |
| 97 | { |
Franck Bui-Huu | bbc7b92 | 2006-09-25 23:31:07 -0700 | [diff] [blame] | 98 | unsigned long mapsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Mel Gorman | 2dbb51c | 2008-07-23 21:26:52 -0700 | [diff] [blame] | 100 | mminit_validate_memmodel_limits(&start, &end); |
Franck Bui-Huu | bbc7b92 | 2006-09-25 23:31:07 -0700 | [diff] [blame] | 101 | bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart)); |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 102 | bdata->node_min_pfn = start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | bdata->node_low_pfn = end; |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 104 | link_bootmem(bdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Initially all pages are reserved - setup_arch() has to |
| 108 | * register free RAM areas explicitly. |
| 109 | */ |
Johannes Weiner | df049a5 | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 110 | mapsize = bootmap_bytes(end - start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | memset(bdata->node_bootmem_map, 0xff, mapsize); |
| 112 | |
Johannes Weiner | 2e5237d | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 113 | bdebug("nid=%td start=%lx map=%lx end=%lx mapsize=%lx\n", |
| 114 | bdata - bootmem_node_data, start, mapstart, end, mapsize); |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return mapsize; |
| 117 | } |
| 118 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 119 | /** |
| 120 | * init_bootmem_node - register a node as boot memory |
| 121 | * @pgdat: node to register |
| 122 | * @freepfn: pfn where the bitmap for this node is to be placed |
| 123 | * @startpfn: first pfn on the node |
| 124 | * @endpfn: first pfn after the node |
| 125 | * |
| 126 | * Returns the number of bytes needed to hold the bitmap for this node. |
| 127 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 128 | unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn, |
| 129 | unsigned long startpfn, unsigned long endpfn) |
| 130 | { |
| 131 | return init_bootmem_core(pgdat->bdata, freepfn, startpfn, endpfn); |
| 132 | } |
| 133 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 134 | /** |
| 135 | * init_bootmem - register boot memory |
| 136 | * @start: pfn where the bitmap is to be placed |
| 137 | * @pages: number of available physical pages |
| 138 | * |
| 139 | * Returns the number of bytes needed to hold the bitmap. |
| 140 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 141 | unsigned long __init init_bootmem(unsigned long start, unsigned long pages) |
| 142 | { |
| 143 | max_low_pfn = pages; |
| 144 | min_low_pfn = start; |
| 145 | return init_bootmem_core(NODE_DATA(0)->bdata, start, 0, pages); |
| 146 | } |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 147 | #endif |
FUJITA Tomonori | 9f993ac | 2009-11-10 19:46:17 +0900 | [diff] [blame] | 148 | /* |
| 149 | * free_bootmem_late - free bootmem pages directly to page allocator |
| 150 | * @addr: starting address of the range |
| 151 | * @size: size of the range in bytes |
| 152 | * |
| 153 | * This is only useful when the bootmem allocator has already been torn |
| 154 | * down, but we are still initializing the system. Pages are given directly |
| 155 | * to the page allocator, no bootmem metadata is updated because it is gone. |
| 156 | */ |
| 157 | void __init free_bootmem_late(unsigned long addr, unsigned long size) |
| 158 | { |
| 159 | unsigned long cursor, end; |
| 160 | |
| 161 | kmemleak_free_part(__va(addr), size); |
| 162 | |
| 163 | cursor = PFN_UP(addr); |
| 164 | end = PFN_DOWN(addr + size); |
| 165 | |
| 166 | for (; cursor < end; cursor++) { |
| 167 | __free_pages_bootmem(pfn_to_page(cursor), 0); |
| 168 | totalram_pages++; |
| 169 | } |
| 170 | } |
| 171 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 172 | #ifdef CONFIG_NO_BOOTMEM |
| 173 | static void __init __free_pages_memory(unsigned long start, unsigned long end) |
| 174 | { |
| 175 | int i; |
| 176 | unsigned long start_aligned, end_aligned; |
| 177 | int order = ilog2(BITS_PER_LONG); |
| 178 | |
| 179 | start_aligned = (start + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1); |
| 180 | end_aligned = end & ~(BITS_PER_LONG - 1); |
| 181 | |
| 182 | if (end_aligned <= start_aligned) { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 183 | for (i = start; i < end; i++) |
| 184 | __free_pages_bootmem(pfn_to_page(i), 0); |
| 185 | |
| 186 | return; |
| 187 | } |
| 188 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 189 | for (i = start; i < start_aligned; i++) |
| 190 | __free_pages_bootmem(pfn_to_page(i), 0); |
| 191 | |
| 192 | for (i = start_aligned; i < end_aligned; i += BITS_PER_LONG) |
| 193 | __free_pages_bootmem(pfn_to_page(i), order); |
| 194 | |
| 195 | for (i = end_aligned; i < end; i++) |
| 196 | __free_pages_bootmem(pfn_to_page(i), 0); |
| 197 | } |
| 198 | |
| 199 | unsigned long __init free_all_memory_core_early(int nodeid) |
| 200 | { |
| 201 | int i; |
| 202 | u64 start, end; |
| 203 | unsigned long count = 0; |
| 204 | struct range *range = NULL; |
| 205 | int nr_range; |
| 206 | |
| 207 | nr_range = get_free_all_memory_range(&range, nodeid); |
| 208 | |
| 209 | for (i = 0; i < nr_range; i++) { |
| 210 | start = range[i].start; |
| 211 | end = range[i].end; |
| 212 | count += end - start; |
| 213 | __free_pages_memory(start, end); |
| 214 | } |
| 215 | |
| 216 | return count; |
| 217 | } |
| 218 | #else |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 219 | static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata) |
| 220 | { |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 221 | int aligned; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 222 | struct page *page; |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 223 | unsigned long start, end, pages, count = 0; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 224 | |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 225 | if (!bdata->node_bootmem_map) |
| 226 | return 0; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 227 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 228 | start = bdata->node_min_pfn; |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 229 | end = bdata->node_low_pfn; |
| 230 | |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 231 | /* |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 232 | * If the start is aligned to the machines wordsize, we might |
| 233 | * be able to free pages in bulks of that order. |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 234 | */ |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 235 | aligned = !(start & (BITS_PER_LONG - 1)); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 236 | |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 237 | bdebug("nid=%td start=%lx end=%lx aligned=%d\n", |
| 238 | bdata - bootmem_node_data, start, end, aligned); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 239 | |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 240 | while (start < end) { |
| 241 | unsigned long *map, idx, vec; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 242 | |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 243 | map = bdata->node_bootmem_map; |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 244 | idx = start - bdata->node_min_pfn; |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 245 | vec = ~map[idx / BITS_PER_LONG]; |
| 246 | |
| 247 | if (aligned && vec == ~0UL && start + BITS_PER_LONG < end) { |
| 248 | int order = ilog2(BITS_PER_LONG); |
| 249 | |
| 250 | __free_pages_bootmem(pfn_to_page(start), order); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 251 | count += BITS_PER_LONG; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 252 | } else { |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 253 | unsigned long off = 0; |
| 254 | |
| 255 | while (vec && off < BITS_PER_LONG) { |
| 256 | if (vec & 1) { |
| 257 | page = pfn_to_page(start + off); |
| 258 | __free_pages_bootmem(page, 0); |
| 259 | count++; |
| 260 | } |
| 261 | vec >>= 1; |
| 262 | off++; |
| 263 | } |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 264 | } |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 265 | start += BITS_PER_LONG; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 268 | page = virt_to_page(bdata->node_bootmem_map); |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 269 | pages = bdata->node_low_pfn - bdata->node_min_pfn; |
Johannes Weiner | 41546c1 | 2008-07-23 21:28:03 -0700 | [diff] [blame] | 270 | pages = bootmem_bootmap_pages(pages); |
| 271 | count += pages; |
| 272 | while (pages--) |
| 273 | __free_pages_bootmem(page++, 0); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 274 | |
Johannes Weiner | 2e5237d | 2008-07-23 21:28:02 -0700 | [diff] [blame] | 275 | bdebug("nid=%td released=%lx\n", bdata - bootmem_node_data, count); |
| 276 | |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 277 | return count; |
| 278 | } |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 279 | #endif |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 280 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 281 | /** |
| 282 | * free_all_bootmem_node - release a node's free pages to the buddy allocator |
| 283 | * @pgdat: node to be released |
| 284 | * |
| 285 | * Returns the number of pages actually released. |
| 286 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 287 | unsigned long __init free_all_bootmem_node(pg_data_t *pgdat) |
| 288 | { |
| 289 | register_page_bootmem_info_node(pgdat); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 290 | #ifdef CONFIG_NO_BOOTMEM |
| 291 | /* free_all_memory_core_early(MAX_NUMNODES) will be called later */ |
| 292 | return 0; |
| 293 | #else |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 294 | return free_all_bootmem_core(pgdat->bdata); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 295 | #endif |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 298 | /** |
| 299 | * free_all_bootmem - release free pages to the buddy allocator |
| 300 | * |
| 301 | * Returns the number of pages actually released. |
| 302 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 303 | unsigned long __init free_all_bootmem(void) |
| 304 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 305 | #ifdef CONFIG_NO_BOOTMEM |
Yinghai Lu | 3379985 | 2010-03-31 20:44:09 -0700 | [diff] [blame] | 306 | /* |
| 307 | * We need to use MAX_NUMNODES instead of NODE_DATA(0)->node_id |
| 308 | * because in some case like Node0 doesnt have RAM installed |
| 309 | * low ram will be on Node1 |
| 310 | * Use MAX_NUMNODES will make sure all ranges in early_node_map[] |
| 311 | * will be used instead of only Node0 related |
| 312 | */ |
| 313 | return free_all_memory_core_early(MAX_NUMNODES); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 314 | #else |
Yinghai Lu | aa235fc | 2010-03-31 20:45:27 -0700 | [diff] [blame^] | 315 | unsigned long total_pages = 0; |
| 316 | bootmem_data_t *bdata; |
| 317 | |
| 318 | list_for_each_entry(bdata, &bdata_list, list) |
| 319 | total_pages += free_all_bootmem_core(bdata); |
| 320 | |
| 321 | return total_pages; |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 322 | #endif |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 325 | #ifndef CONFIG_NO_BOOTMEM |
Johannes Weiner | d747fa4 | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 326 | static void __init __free(bootmem_data_t *bdata, |
| 327 | unsigned long sidx, unsigned long eidx) |
| 328 | { |
| 329 | unsigned long idx; |
| 330 | |
| 331 | bdebug("nid=%td start=%lx end=%lx\n", bdata - bootmem_node_data, |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 332 | sidx + bdata->node_min_pfn, |
| 333 | eidx + bdata->node_min_pfn); |
Johannes Weiner | d747fa4 | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 334 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 335 | if (bdata->hint_idx > sidx) |
| 336 | bdata->hint_idx = sidx; |
| 337 | |
Johannes Weiner | d747fa4 | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 338 | for (idx = sidx; idx < eidx; idx++) |
| 339 | if (!test_and_clear_bit(idx, bdata->node_bootmem_map)) |
| 340 | BUG(); |
| 341 | } |
| 342 | |
| 343 | static int __init __reserve(bootmem_data_t *bdata, unsigned long sidx, |
| 344 | unsigned long eidx, int flags) |
| 345 | { |
| 346 | unsigned long idx; |
| 347 | int exclusive = flags & BOOTMEM_EXCLUSIVE; |
| 348 | |
| 349 | bdebug("nid=%td start=%lx end=%lx flags=%x\n", |
| 350 | bdata - bootmem_node_data, |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 351 | sidx + bdata->node_min_pfn, |
| 352 | eidx + bdata->node_min_pfn, |
Johannes Weiner | d747fa4 | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 353 | flags); |
| 354 | |
| 355 | for (idx = sidx; idx < eidx; idx++) |
| 356 | if (test_and_set_bit(idx, bdata->node_bootmem_map)) { |
| 357 | if (exclusive) { |
| 358 | __free(bdata, sidx, idx); |
| 359 | return -EBUSY; |
| 360 | } |
| 361 | bdebug("silent double reserve of PFN %lx\n", |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 362 | idx + bdata->node_min_pfn); |
Johannes Weiner | d747fa4 | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 363 | } |
| 364 | return 0; |
| 365 | } |
| 366 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 367 | static int __init mark_bootmem_node(bootmem_data_t *bdata, |
| 368 | unsigned long start, unsigned long end, |
| 369 | int reserve, int flags) |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 370 | { |
| 371 | unsigned long sidx, eidx; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 372 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 373 | bdebug("nid=%td start=%lx end=%lx reserve=%d flags=%x\n", |
| 374 | bdata - bootmem_node_data, start, end, reserve, flags); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 375 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 376 | BUG_ON(start < bdata->node_min_pfn); |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 377 | BUG_ON(end > bdata->node_low_pfn); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 378 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 379 | sidx = start - bdata->node_min_pfn; |
| 380 | eidx = end - bdata->node_min_pfn; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 381 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 382 | if (reserve) |
| 383 | return __reserve(bdata, sidx, eidx, flags); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 384 | else |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 385 | __free(bdata, sidx, eidx); |
| 386 | return 0; |
| 387 | } |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 388 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 389 | static int __init mark_bootmem(unsigned long start, unsigned long end, |
| 390 | int reserve, int flags) |
| 391 | { |
| 392 | unsigned long pos; |
| 393 | bootmem_data_t *bdata; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 394 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 395 | pos = start; |
| 396 | list_for_each_entry(bdata, &bdata_list, list) { |
| 397 | int err; |
| 398 | unsigned long max; |
| 399 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 400 | if (pos < bdata->node_min_pfn || |
| 401 | pos >= bdata->node_low_pfn) { |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 402 | BUG_ON(pos != start); |
| 403 | continue; |
| 404 | } |
| 405 | |
| 406 | max = min(bdata->node_low_pfn, end); |
| 407 | |
| 408 | err = mark_bootmem_node(bdata, pos, max, reserve, flags); |
| 409 | if (reserve && err) { |
| 410 | mark_bootmem(start, pos, 0, 0); |
| 411 | return err; |
| 412 | } |
| 413 | |
| 414 | if (max == end) |
| 415 | return 0; |
| 416 | pos = bdata->node_low_pfn; |
| 417 | } |
| 418 | BUG(); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 419 | } |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 420 | #endif |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 421 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 422 | /** |
| 423 | * free_bootmem_node - mark a page range as usable |
| 424 | * @pgdat: node the range resides on |
| 425 | * @physaddr: starting address of the range |
| 426 | * @size: size of the range in bytes |
| 427 | * |
| 428 | * Partial pages will be considered reserved and left as they are. |
| 429 | * |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 430 | * The range must reside completely on the specified node. |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 431 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 432 | void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, |
| 433 | unsigned long size) |
| 434 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 435 | #ifdef CONFIG_NO_BOOTMEM |
| 436 | free_early(physaddr, physaddr + size); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 437 | #else |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 438 | unsigned long start, end; |
| 439 | |
Catalin Marinas | ec3a354 | 2009-07-07 10:33:01 +0100 | [diff] [blame] | 440 | kmemleak_free_part(__va(physaddr), size); |
| 441 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 442 | start = PFN_UP(physaddr); |
| 443 | end = PFN_DOWN(physaddr + size); |
| 444 | |
| 445 | mark_bootmem_node(pgdat->bdata, start, end, 0, 0); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 446 | #endif |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 449 | /** |
| 450 | * free_bootmem - mark a page range as usable |
| 451 | * @addr: starting address of the range |
| 452 | * @size: size of the range in bytes |
| 453 | * |
| 454 | * Partial pages will be considered reserved and left as they are. |
| 455 | * |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 456 | * The range must be contiguous but may span node boundaries. |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 457 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 458 | void __init free_bootmem(unsigned long addr, unsigned long size) |
| 459 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 460 | #ifdef CONFIG_NO_BOOTMEM |
| 461 | free_early(addr, addr + size); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 462 | #else |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 463 | unsigned long start, end; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 464 | |
Catalin Marinas | ec3a354 | 2009-07-07 10:33:01 +0100 | [diff] [blame] | 465 | kmemleak_free_part(__va(addr), size); |
| 466 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 467 | start = PFN_UP(addr); |
| 468 | end = PFN_DOWN(addr + size); |
Yinghai Lu | a5645a6 | 2008-03-18 12:49:12 -0700 | [diff] [blame] | 469 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 470 | mark_bootmem(start, end, 0, 0); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 471 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 474 | /** |
| 475 | * reserve_bootmem_node - mark a page range as reserved |
| 476 | * @pgdat: node the range resides on |
| 477 | * @physaddr: starting address of the range |
| 478 | * @size: size of the range in bytes |
| 479 | * @flags: reservation flags (see linux/bootmem.h) |
| 480 | * |
| 481 | * Partial pages will be reserved. |
| 482 | * |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 483 | * The range must reside completely on the specified node. |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 484 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 485 | int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, |
| 486 | unsigned long size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 488 | #ifdef CONFIG_NO_BOOTMEM |
| 489 | panic("no bootmem"); |
| 490 | return 0; |
| 491 | #else |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 492 | unsigned long start, end; |
Franck Bui-Huu | bbc7b92 | 2006-09-25 23:31:07 -0700 | [diff] [blame] | 493 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 494 | start = PFN_DOWN(physaddr); |
| 495 | end = PFN_UP(physaddr + size); |
| 496 | |
| 497 | return mark_bootmem_node(pgdat->bdata, start, end, 1, flags); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 498 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 501 | /** |
| 502 | * reserve_bootmem - mark a page range as usable |
| 503 | * @addr: starting address of the range |
| 504 | * @size: size of the range in bytes |
| 505 | * @flags: reservation flags (see linux/bootmem.h) |
| 506 | * |
| 507 | * Partial pages will be reserved. |
| 508 | * |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 509 | * The range must be contiguous but may span node boundaries. |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 510 | */ |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 511 | int __init reserve_bootmem(unsigned long addr, unsigned long size, |
| 512 | int flags) |
| 513 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 514 | #ifdef CONFIG_NO_BOOTMEM |
| 515 | panic("no bootmem"); |
| 516 | return 0; |
| 517 | #else |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 518 | unsigned long start, end; |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 519 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 520 | start = PFN_DOWN(addr); |
| 521 | end = PFN_UP(addr + size); |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 522 | |
Johannes Weiner | e2bf3ca | 2008-07-23 21:28:06 -0700 | [diff] [blame] | 523 | return mark_bootmem(start, end, 1, flags); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 524 | #endif |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 525 | } |
Johannes Weiner | 223e8dc | 2008-07-23 21:28:00 -0700 | [diff] [blame] | 526 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 527 | #ifndef CONFIG_NO_BOOTMEM |
Jan Beulich | 8aa043d | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 528 | static unsigned long __init align_idx(struct bootmem_data *bdata, |
| 529 | unsigned long idx, unsigned long step) |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 530 | { |
| 531 | unsigned long base = bdata->node_min_pfn; |
| 532 | |
| 533 | /* |
| 534 | * Align the index with respect to the node start so that the |
| 535 | * combination of both satisfies the requested alignment. |
| 536 | */ |
| 537 | |
| 538 | return ALIGN(base + idx, step) - base; |
| 539 | } |
| 540 | |
Jan Beulich | 8aa043d | 2009-12-14 17:59:46 -0800 | [diff] [blame] | 541 | static unsigned long __init align_off(struct bootmem_data *bdata, |
| 542 | unsigned long off, unsigned long align) |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 543 | { |
| 544 | unsigned long base = PFN_PHYS(bdata->node_min_pfn); |
| 545 | |
| 546 | /* Same as align_idx for byte offsets */ |
| 547 | |
| 548 | return ALIGN(base + off, align) - base; |
| 549 | } |
| 550 | |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 551 | static void * __init alloc_bootmem_core(struct bootmem_data *bdata, |
| 552 | unsigned long size, unsigned long align, |
| 553 | unsigned long goal, unsigned long limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 555 | unsigned long fallback = 0; |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 556 | unsigned long min, max, start, sidx, midx, step; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Johannes Weiner | 594fe1a | 2009-01-06 14:40:32 -0800 | [diff] [blame] | 558 | bdebug("nid=%td size=%lx [%lu pages] align=%lx goal=%lx limit=%lx\n", |
| 559 | bdata - bootmem_node_data, size, PAGE_ALIGN(size) >> PAGE_SHIFT, |
| 560 | align, goal, limit); |
| 561 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 562 | BUG_ON(!size); |
| 563 | BUG_ON(align & (align - 1)); |
| 564 | BUG_ON(limit && goal + size > limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Christian Krafft | 7c309a6 | 2006-12-06 20:32:41 -0800 | [diff] [blame] | 566 | if (!bdata->node_bootmem_map) |
| 567 | return NULL; |
| 568 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 569 | min = bdata->node_min_pfn; |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 570 | max = bdata->node_low_pfn; |
Yinghai Lu | 9a2dc04 | 2008-03-18 12:44:48 -0700 | [diff] [blame] | 571 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 572 | goal >>= PAGE_SHIFT; |
| 573 | limit >>= PAGE_SHIFT; |
| 574 | |
| 575 | if (limit && max > limit) |
| 576 | max = limit; |
| 577 | if (max <= min) |
Yinghai Lu | 9a2dc04 | 2008-03-18 12:44:48 -0700 | [diff] [blame] | 578 | return NULL; |
| 579 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 580 | step = max(align >> PAGE_SHIFT, 1UL); |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 581 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 582 | if (goal && min < goal && goal < max) |
| 583 | start = ALIGN(goal, step); |
| 584 | else |
| 585 | start = ALIGN(min, step); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 587 | sidx = start - bdata->node_min_pfn; |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 588 | midx = max - bdata->node_min_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 590 | if (bdata->hint_idx > sidx) { |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 591 | /* |
| 592 | * Handle the valid case of sidx being zero and still |
| 593 | * catch the fallback below. |
| 594 | */ |
| 595 | fallback = sidx + 1; |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 596 | sidx = align_idx(bdata, bdata->hint_idx, step); |
Yinghai Lu | ad09315 | 2008-03-10 23:23:42 -0700 | [diff] [blame] | 597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 599 | while (1) { |
| 600 | int merge; |
| 601 | void *region; |
| 602 | unsigned long eidx, i, start_off, end_off; |
| 603 | find_block: |
| 604 | sidx = find_next_zero_bit(bdata->node_bootmem_map, midx, sidx); |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 605 | sidx = align_idx(bdata, sidx, step); |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 606 | eidx = sidx + PFN_UP(size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 608 | if (sidx >= midx || eidx > midx) |
Haren Myneni | 66d43e9 | 2005-12-12 00:37:39 -0800 | [diff] [blame] | 609 | break; |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 610 | |
| 611 | for (i = sidx; i < eidx; i++) |
| 612 | if (test_bit(i, bdata->node_bootmem_map)) { |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 613 | sidx = align_idx(bdata, i, step); |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 614 | if (sidx == i) |
| 615 | sidx += step; |
| 616 | goto find_block; |
| 617 | } |
| 618 | |
Mikulas Patocka | 627240a | 2008-08-15 00:40:17 -0700 | [diff] [blame] | 619 | if (bdata->last_end_off & (PAGE_SIZE - 1) && |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 620 | PFN_DOWN(bdata->last_end_off) + 1 == sidx) |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 621 | start_off = align_off(bdata, bdata->last_end_off, align); |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 622 | else |
| 623 | start_off = PFN_PHYS(sidx); |
| 624 | |
| 625 | merge = PFN_DOWN(start_off) < sidx; |
| 626 | end_off = start_off + size; |
| 627 | |
| 628 | bdata->last_end_off = end_off; |
| 629 | bdata->hint_idx = PFN_UP(end_off); |
| 630 | |
| 631 | /* |
| 632 | * Reserve the area now: |
| 633 | */ |
Johannes Weiner | d747fa4 | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 634 | if (__reserve(bdata, PFN_DOWN(start_off) + merge, |
| 635 | PFN_UP(end_off), BOOTMEM_EXCLUSIVE)) |
| 636 | BUG(); |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 637 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 638 | region = phys_to_virt(PFN_PHYS(bdata->node_min_pfn) + |
| 639 | start_off); |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 640 | memset(region, 0, size); |
Catalin Marinas | 008139d | 2009-08-27 14:29:17 +0100 | [diff] [blame] | 641 | /* |
| 642 | * The min_count is set to 0 so that bootmem allocated blocks |
| 643 | * are never reported as leaks. |
| 644 | */ |
| 645 | kmemleak_alloc(region, size, 0, 0); |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 646 | return region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 649 | if (fallback) { |
Johannes Weiner | 481ebd0 | 2008-08-20 14:09:15 -0700 | [diff] [blame] | 650 | sidx = align_idx(bdata, fallback - 1, step); |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 651 | fallback = 0; |
| 652 | goto find_block; |
| 653 | } |
| 654 | |
| 655 | return NULL; |
| 656 | } |
| 657 | |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 658 | static void * __init alloc_arch_preferred_bootmem(bootmem_data_t *bdata, |
| 659 | unsigned long size, unsigned long align, |
| 660 | unsigned long goal, unsigned long limit) |
| 661 | { |
Pekka Enberg | 441c7e0 | 2009-06-10 20:05:53 +0300 | [diff] [blame] | 662 | if (WARN_ON_ONCE(slab_is_available())) |
| 663 | return kzalloc(size, GFP_NOWAIT); |
| 664 | |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 665 | #ifdef CONFIG_HAVE_ARCH_BOOTMEM |
Joe Perches | 433f13a | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 666 | { |
| 667 | bootmem_data_t *p_bdata; |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 668 | |
Joe Perches | 433f13a | 2009-06-18 16:48:58 -0700 | [diff] [blame] | 669 | p_bdata = bootmem_arch_preferred_node(bdata, size, align, |
| 670 | goal, limit); |
| 671 | if (p_bdata) |
| 672 | return alloc_bootmem_core(p_bdata, size, align, |
| 673 | goal, limit); |
| 674 | } |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 675 | #endif |
| 676 | return NULL; |
| 677 | } |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 678 | #endif |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 679 | |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 680 | static void * __init ___alloc_bootmem_nopanic(unsigned long size, |
| 681 | unsigned long align, |
| 682 | unsigned long goal, |
| 683 | unsigned long limit) |
| 684 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 685 | #ifdef CONFIG_NO_BOOTMEM |
| 686 | void *ptr; |
| 687 | |
| 688 | if (WARN_ON_ONCE(slab_is_available())) |
| 689 | return kzalloc(size, GFP_NOWAIT); |
| 690 | |
| 691 | restart: |
| 692 | |
| 693 | ptr = __alloc_memory_core_early(MAX_NUMNODES, size, align, goal, limit); |
| 694 | |
| 695 | if (ptr) |
| 696 | return ptr; |
| 697 | |
| 698 | if (goal != 0) { |
| 699 | goal = 0; |
| 700 | goto restart; |
| 701 | } |
| 702 | |
| 703 | return NULL; |
| 704 | #else |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 705 | bootmem_data_t *bdata; |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 706 | void *region; |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 707 | |
| 708 | restart: |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 709 | region = alloc_arch_preferred_bootmem(NULL, size, align, goal, limit); |
| 710 | if (region) |
| 711 | return region; |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 712 | |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 713 | list_for_each_entry(bdata, &bdata_list, list) { |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 714 | if (goal && bdata->node_low_pfn <= PFN_DOWN(goal)) |
| 715 | continue; |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 716 | if (limit && bdata->node_min_pfn >= PFN_DOWN(limit)) |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 717 | break; |
| 718 | |
| 719 | region = alloc_bootmem_core(bdata, size, align, goal, limit); |
| 720 | if (region) |
| 721 | return region; |
| 722 | } |
| 723 | |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 724 | if (goal) { |
| 725 | goal = 0; |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 726 | goto restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
Johannes Weiner | 5f2809e | 2008-07-23 21:28:05 -0700 | [diff] [blame] | 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | return NULL; |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 730 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 733 | /** |
| 734 | * __alloc_bootmem_nopanic - allocate boot memory without panicking |
| 735 | * @size: size of the request in bytes |
| 736 | * @align: alignment of the region |
| 737 | * @goal: preferred starting address of the region |
| 738 | * |
| 739 | * The goal is dropped if it can not be satisfied and the allocation will |
| 740 | * fall back to memory below @goal. |
| 741 | * |
| 742 | * Allocation may happen on any node in the system. |
| 743 | * |
| 744 | * Returns NULL on failure. |
| 745 | */ |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 746 | void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 747 | unsigned long goal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 749 | unsigned long limit = 0; |
| 750 | |
| 751 | #ifdef CONFIG_NO_BOOTMEM |
| 752 | limit = -1UL; |
| 753 | #endif |
| 754 | |
| 755 | return ___alloc_bootmem_nopanic(size, align, goal, limit); |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 756 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 758 | static void * __init ___alloc_bootmem(unsigned long size, unsigned long align, |
| 759 | unsigned long goal, unsigned long limit) |
| 760 | { |
| 761 | void *mem = ___alloc_bootmem_nopanic(size, align, goal, limit); |
| 762 | |
| 763 | if (mem) |
| 764 | return mem; |
| 765 | /* |
| 766 | * Whoops, we cannot satisfy the allocation request. |
| 767 | */ |
| 768 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); |
| 769 | panic("Out of memory"); |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 770 | return NULL; |
| 771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 773 | /** |
| 774 | * __alloc_bootmem - allocate boot memory |
| 775 | * @size: size of the request in bytes |
| 776 | * @align: alignment of the region |
| 777 | * @goal: preferred starting address of the region |
| 778 | * |
| 779 | * The goal is dropped if it can not be satisfied and the allocation will |
| 780 | * fall back to memory below @goal. |
| 781 | * |
| 782 | * Allocation may happen on any node in the system. |
| 783 | * |
| 784 | * The function panics if the request can not be satisfied. |
| 785 | */ |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 786 | void * __init __alloc_bootmem(unsigned long size, unsigned long align, |
| 787 | unsigned long goal) |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 788 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 789 | unsigned long limit = 0; |
| 790 | |
| 791 | #ifdef CONFIG_NO_BOOTMEM |
| 792 | limit = -1UL; |
| 793 | #endif |
| 794 | |
| 795 | return ___alloc_bootmem(size, align, goal, limit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 798 | #ifndef CONFIG_NO_BOOTMEM |
Johannes Weiner | 4cc278b | 2008-07-23 21:28:08 -0700 | [diff] [blame] | 799 | static void * __init ___alloc_bootmem_node(bootmem_data_t *bdata, |
| 800 | unsigned long size, unsigned long align, |
| 801 | unsigned long goal, unsigned long limit) |
| 802 | { |
| 803 | void *ptr; |
| 804 | |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 805 | ptr = alloc_arch_preferred_bootmem(bdata, size, align, goal, limit); |
| 806 | if (ptr) |
| 807 | return ptr; |
| 808 | |
Johannes Weiner | 4cc278b | 2008-07-23 21:28:08 -0700 | [diff] [blame] | 809 | ptr = alloc_bootmem_core(bdata, size, align, goal, limit); |
| 810 | if (ptr) |
| 811 | return ptr; |
| 812 | |
| 813 | return ___alloc_bootmem(size, align, goal, limit); |
| 814 | } |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 815 | #endif |
Johannes Weiner | 4cc278b | 2008-07-23 21:28:08 -0700 | [diff] [blame] | 816 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 817 | /** |
| 818 | * __alloc_bootmem_node - allocate boot memory from a specific node |
| 819 | * @pgdat: node to allocate from |
| 820 | * @size: size of the request in bytes |
| 821 | * @align: alignment of the region |
| 822 | * @goal: preferred starting address of the region |
| 823 | * |
| 824 | * The goal is dropped if it can not be satisfied and the allocation will |
| 825 | * fall back to memory below @goal. |
| 826 | * |
| 827 | * Allocation may fall back to any node in the system if the specified node |
| 828 | * can not hold the requested memory. |
| 829 | * |
| 830 | * The function panics if the request can not be satisfied. |
| 831 | */ |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 832 | void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, |
| 833 | unsigned long align, unsigned long goal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
Pekka Enberg | c91c477 | 2009-06-11 08:10:28 +0300 | [diff] [blame] | 835 | if (WARN_ON_ONCE(slab_is_available())) |
| 836 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 837 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 838 | #ifdef CONFIG_NO_BOOTMEM |
| 839 | return __alloc_memory_core_early(pgdat->node_id, size, align, |
| 840 | goal, -1ULL); |
| 841 | #else |
Johannes Weiner | 4cc278b | 2008-07-23 21:28:08 -0700 | [diff] [blame] | 842 | return ___alloc_bootmem_node(pgdat->bdata, size, align, goal, 0); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 843 | #endif |
| 844 | } |
| 845 | |
| 846 | void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size, |
| 847 | unsigned long align, unsigned long goal) |
| 848 | { |
| 849 | #ifdef MAX_DMA32_PFN |
| 850 | unsigned long end_pfn; |
| 851 | |
| 852 | if (WARN_ON_ONCE(slab_is_available())) |
| 853 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 854 | |
| 855 | /* update goal according ...MAX_DMA32_PFN */ |
| 856 | end_pfn = pgdat->node_start_pfn + pgdat->node_spanned_pages; |
| 857 | |
| 858 | if (end_pfn > MAX_DMA32_PFN + (128 >> (20 - PAGE_SHIFT)) && |
| 859 | (goal >> PAGE_SHIFT) < MAX_DMA32_PFN) { |
| 860 | void *ptr; |
| 861 | unsigned long new_goal; |
| 862 | |
| 863 | new_goal = MAX_DMA32_PFN << PAGE_SHIFT; |
| 864 | #ifdef CONFIG_NO_BOOTMEM |
| 865 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, |
| 866 | new_goal, -1ULL); |
| 867 | #else |
| 868 | ptr = alloc_bootmem_core(pgdat->bdata, size, align, |
| 869 | new_goal, 0); |
| 870 | #endif |
| 871 | if (ptr) |
| 872 | return ptr; |
| 873 | } |
| 874 | #endif |
| 875 | |
| 876 | return __alloc_bootmem_node(pgdat, size, align, goal); |
| 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Yasunori Goto | e70260a | 2008-04-28 02:13:32 -0700 | [diff] [blame] | 880 | #ifdef CONFIG_SPARSEMEM |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 881 | /** |
| 882 | * alloc_bootmem_section - allocate boot memory from a specific section |
| 883 | * @size: size of the request in bytes |
| 884 | * @section_nr: sparse map section to allocate from |
| 885 | * |
| 886 | * Return NULL on failure. |
| 887 | */ |
Yasunori Goto | e70260a | 2008-04-28 02:13:32 -0700 | [diff] [blame] | 888 | void * __init alloc_bootmem_section(unsigned long size, |
| 889 | unsigned long section_nr) |
| 890 | { |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 891 | #ifdef CONFIG_NO_BOOTMEM |
| 892 | unsigned long pfn, goal, limit; |
| 893 | |
| 894 | pfn = section_nr_to_pfn(section_nr); |
| 895 | goal = pfn << PAGE_SHIFT; |
| 896 | limit = section_nr_to_pfn(section_nr + 1) << PAGE_SHIFT; |
| 897 | |
| 898 | return __alloc_memory_core_early(early_pfn_to_nid(pfn), size, |
| 899 | SMP_CACHE_BYTES, goal, limit); |
| 900 | #else |
Johannes Weiner | 75a56cf | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 901 | bootmem_data_t *bdata; |
| 902 | unsigned long pfn, goal, limit; |
Yasunori Goto | e70260a | 2008-04-28 02:13:32 -0700 | [diff] [blame] | 903 | |
| 904 | pfn = section_nr_to_pfn(section_nr); |
Johannes Weiner | 75a56cf | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 905 | goal = pfn << PAGE_SHIFT; |
| 906 | limit = section_nr_to_pfn(section_nr + 1) << PAGE_SHIFT; |
| 907 | bdata = &bootmem_node_data[early_pfn_to_nid(pfn)]; |
Yasunori Goto | e70260a | 2008-04-28 02:13:32 -0700 | [diff] [blame] | 908 | |
Johannes Weiner | 75a56cf | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 909 | return alloc_bootmem_core(bdata, size, SMP_CACHE_BYTES, goal, limit); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 910 | #endif |
Yasunori Goto | e70260a | 2008-04-28 02:13:32 -0700 | [diff] [blame] | 911 | } |
| 912 | #endif |
| 913 | |
Andi Kleen | b54bbf7 | 2008-07-23 21:27:45 -0700 | [diff] [blame] | 914 | void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size, |
| 915 | unsigned long align, unsigned long goal) |
| 916 | { |
| 917 | void *ptr; |
| 918 | |
Pekka Enberg | c91c477 | 2009-06-11 08:10:28 +0300 | [diff] [blame] | 919 | if (WARN_ON_ONCE(slab_is_available())) |
| 920 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 921 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 922 | #ifdef CONFIG_NO_BOOTMEM |
| 923 | ptr = __alloc_memory_core_early(pgdat->node_id, size, align, |
| 924 | goal, -1ULL); |
| 925 | #else |
Tejun Heo | d0c4f57 | 2009-03-01 16:06:56 +0900 | [diff] [blame] | 926 | ptr = alloc_arch_preferred_bootmem(pgdat->bdata, size, align, goal, 0); |
| 927 | if (ptr) |
| 928 | return ptr; |
| 929 | |
Andi Kleen | b54bbf7 | 2008-07-23 21:27:45 -0700 | [diff] [blame] | 930 | ptr = alloc_bootmem_core(pgdat->bdata, size, align, goal, 0); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 931 | #endif |
Andi Kleen | b54bbf7 | 2008-07-23 21:27:45 -0700 | [diff] [blame] | 932 | if (ptr) |
| 933 | return ptr; |
| 934 | |
| 935 | return __alloc_bootmem_nopanic(size, align, goal); |
| 936 | } |
| 937 | |
Heiko Carstens | dfd54cb | 2006-09-25 23:31:33 -0700 | [diff] [blame] | 938 | #ifndef ARCH_LOW_ADDRESS_LIMIT |
| 939 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL |
| 940 | #endif |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 941 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 942 | /** |
| 943 | * __alloc_bootmem_low - allocate low boot memory |
| 944 | * @size: size of the request in bytes |
| 945 | * @align: alignment of the region |
| 946 | * @goal: preferred starting address of the region |
| 947 | * |
| 948 | * The goal is dropped if it can not be satisfied and the allocation will |
| 949 | * fall back to memory below @goal. |
| 950 | * |
| 951 | * Allocation may happen on any node in the system. |
| 952 | * |
| 953 | * The function panics if the request can not be satisfied. |
| 954 | */ |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 955 | void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, |
| 956 | unsigned long goal) |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 957 | { |
Johannes Weiner | 0f3caba | 2008-07-23 21:28:07 -0700 | [diff] [blame] | 958 | return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT); |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Johannes Weiner | a66fd7d | 2008-07-23 21:28:01 -0700 | [diff] [blame] | 961 | /** |
| 962 | * __alloc_bootmem_low_node - allocate low boot memory from a specific node |
| 963 | * @pgdat: node to allocate from |
| 964 | * @size: size of the request in bytes |
| 965 | * @align: alignment of the region |
| 966 | * @goal: preferred starting address of the region |
| 967 | * |
| 968 | * The goal is dropped if it can not be satisfied and the allocation will |
| 969 | * fall back to memory below @goal. |
| 970 | * |
| 971 | * Allocation may fall back to any node in the system if the specified node |
| 972 | * can not hold the requested memory. |
| 973 | * |
| 974 | * The function panics if the request can not be satisfied. |
| 975 | */ |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 976 | void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, |
| 977 | unsigned long align, unsigned long goal) |
| 978 | { |
Pekka Enberg | c91c477 | 2009-06-11 08:10:28 +0300 | [diff] [blame] | 979 | if (WARN_ON_ONCE(slab_is_available())) |
| 980 | return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id); |
| 981 | |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 982 | #ifdef CONFIG_NO_BOOTMEM |
| 983 | return __alloc_memory_core_early(pgdat->node_id, size, align, |
| 984 | goal, ARCH_LOW_ADDRESS_LIMIT); |
| 985 | #else |
Johannes Weiner | 4cc278b | 2008-07-23 21:28:08 -0700 | [diff] [blame] | 986 | return ___alloc_bootmem_node(pgdat->bdata, size, align, |
| 987 | goal, ARCH_LOW_ADDRESS_LIMIT); |
Yinghai Lu | 0867721 | 2010-02-10 01:20:20 -0800 | [diff] [blame] | 988 | #endif |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 989 | } |