Blame view

mm/bootmem.c 19.8 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  /*
57cfc29ef   Johannes Weiner   bootmem: clean up...
3
   *  bootmem - A boot-time physical memory allocator and configurator
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
   *
   *  Copyright (C) 1999 Ingo Molnar
57cfc29ef   Johannes Weiner   bootmem: clean up...
6
7
   *                1999 Kanoj Sarcar, SGI
   *                2008 Johannes Weiner
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
   *
57cfc29ef   Johannes Weiner   bootmem: clean up...
9
10
   * Access to this subsystem has to be serialized externally (which is true
   * for the boot process anyway).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
  #include <linux/init.h>
bbc7b92e3   Franck Bui-Huu   [PATCH] bootmem: ...
13
  #include <linux/pfn.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
14
  #include <linux/slab.h>
b95f1b31b   Paul Gortmaker   mm: Map most file...
15
  #include <linux/export.h>
ec3a354bd   Catalin Marinas   kmemleak: Add cal...
16
  #include <linux/kmemleak.h>
08677214e   Yinghai Lu   x86: Make 64 bit ...
17
  #include <linux/range.h>
d85fbee89   Paul McQuade   mm/bootmem.c: use...
18
19
  #include <linux/bug.h>
  #include <linux/io.h>
1d8bf926f   zijun_hu   mm/bootmem.c: rep...
20
  #include <linux/bootmem.h>
e786e86a5   Franck Bui-Huu   [PATCH] bootmem: ...
21

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #include "internal.h"
58faef932   Mike Rapoport   docs/mm: bootmem:...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  /**
   * DOC: bootmem overview
   *
   * Bootmem is a boot-time physical memory allocator and configurator.
   *
   * It is used early in the boot process before the page allocator is
   * set up.
   *
   * Bootmem is based on the most basic of allocators, a First Fit
   * allocator which uses a bitmap to represent memory. If a bit is 1,
   * the page is allocated and 0 if unallocated. To satisfy allocations
   * of sizes smaller than a page, the allocator records the Page Frame
   * Number (PFN) of the last allocation and the offset the allocation
   * ended at. Subsequent small allocations are merged together and
   * stored on the same page.
   *
   * The information used by the bootmem allocator is represented by
   * :c:type:`struct bootmem_data`. An array to hold up to %MAX_NUMNODES
   * such structures is statically allocated and then it is discarded
   * when the system initialization completes. Each entry in this array
   * corresponds to a node with memory. For UMA systems only entry 0 is
   * used.
   *
   * The bootmem allocator is initialized during early architecture
   * specific setup. Each architecture is required to supply a
   * :c:func:`setup_arch` function which, among other tasks, is
   * responsible for acquiring the necessary parameters to initialise
   * the boot memory allocator. These parameters define limits of usable
   * physical memory:
   *
   * * @min_low_pfn - the lowest PFN that is available in the system
   * * @max_low_pfn - the highest PFN that may be addressed by low
   *   memory (%ZONE_NORMAL)
   * * @max_pfn - the last PFN available to the system.
   *
   * After those limits are determined, the :c:func:`init_bootmem` or
   * :c:func:`init_bootmem_node` function should be called to initialize
   * the bootmem allocator. The UMA case should use the `init_bootmem`
   * function. It will initialize ``contig_page_data`` structure that
   * represents the only memory node in the system. In the NUMA case the
   * `init_bootmem_node` function should be called to initialize the
   * bootmem allocator for each node.
   *
   * Once the allocator is set up, it is possible to use either single
   * node or NUMA variant of the allocation APIs.
   */
e782ab421   Yinghai Lu   bootmem: Move con...
69
70
71
72
73
74
  #ifndef CONFIG_NEED_MULTIPLE_NODES
  struct pglist_data __refdata contig_page_data = {
  	.bdata = &bootmem_node_data[0]
  };
  EXPORT_SYMBOL(contig_page_data);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
76
77
  unsigned long max_low_pfn;
  unsigned long min_low_pfn;
  unsigned long max_pfn;
8dd330300   Igor Mammedov   x86/mm: Introduce...
78
  unsigned long long max_possible_pfn;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79

b61bfa3c4   Johannes Weiner   mm: move bootmem ...
80
  bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata;
636cc40cb   Johannes Weiner   bootmem: revisit ...
81
  static struct list_head bdata_list __initdata = LIST_HEAD_INIT(bdata_list);
2e5237daf   Johannes Weiner   bootmem: add debu...
82
83
84
85
86
87
88
89
90
91
92
  static int bootmem_debug;
  
  static int __init bootmem_debug_setup(char *buf)
  {
  	bootmem_debug = 1;
  	return 0;
  }
  early_param("bootmem_debug", bootmem_debug_setup);
  
  #define bdebug(fmt, args...) ({				\
  	if (unlikely(bootmem_debug))			\
1170532bb   Joe Perches   mm: convert print...
93
  		pr_info("bootmem::%s " fmt,		\
80a914dc0   Harvey Harrison   misc: replace __F...
94
  			__func__, ## args);		\
2e5237daf   Johannes Weiner   bootmem: add debu...
95
  })
df049a5f4   Johannes Weiner   bootmem: revisit ...
96
  static unsigned long __init bootmap_bytes(unsigned long pages)
223e8dc92   Johannes Weiner   bootmem: reorder ...
97
  {
d3a9d7a37   Adygzhy Ondar   mm/bootmem.c: cos...
98
  	unsigned long bytes = DIV_ROUND_UP(pages, BITS_PER_BYTE);
223e8dc92   Johannes Weiner   bootmem: reorder ...
99

df049a5f4   Johannes Weiner   bootmem: revisit ...
100
  	return ALIGN(bytes, sizeof(long));
223e8dc92   Johannes Weiner   bootmem: reorder ...
101
  }
a66fd7dae   Johannes Weiner   bootmem: add docu...
102
103
104
  /**
   * bootmem_bootmap_pages - calculate bitmap size in pages
   * @pages: number of pages the bitmap has to represent
7c757207f   Mike Rapoport   docs/mm: bootmem:...
105
106
   *
   * Return: the number of pages needed to hold the bitmap.
a66fd7dae   Johannes Weiner   bootmem: add docu...
107
   */
f71bf0cac   Franck Bui-Huu   [PATCH] bootmem: ...
108
  unsigned long __init bootmem_bootmap_pages(unsigned long pages)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  {
df049a5f4   Johannes Weiner   bootmem: revisit ...
110
  	unsigned long bytes = bootmap_bytes(pages);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111

df049a5f4   Johannes Weiner   bootmem: revisit ...
112
  	return PAGE_ALIGN(bytes) >> PAGE_SHIFT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
  }
f71bf0cac   Franck Bui-Huu   [PATCH] bootmem: ...
114

679bc9fbb   KAMEZAWA Hiroyuki   [PATCH] for_each_...
115
116
117
  /*
   * link bdata in order
   */
69d49e681   Franck Bui-Huu   [PATCH] bootmem: ...
118
  static void __init link_bootmem(bootmem_data_t *bdata)
679bc9fbb   KAMEZAWA Hiroyuki   [PATCH] for_each_...
119
  {
5c2b8a162   Gavin Shan   mm/bootmem.c: cle...
120
  	bootmem_data_t *ent;
f71bf0cac   Franck Bui-Huu   [PATCH] bootmem: ...
121

5c2b8a162   Gavin Shan   mm/bootmem.c: cle...
122
123
124
125
126
  	list_for_each_entry(ent, &bdata_list, list) {
  		if (bdata->node_min_pfn < ent->node_min_pfn) {
  			list_add_tail(&bdata->list, &ent->list);
  			return;
  		}
679bc9fbb   KAMEZAWA Hiroyuki   [PATCH] for_each_...
127
  	}
5c2b8a162   Gavin Shan   mm/bootmem.c: cle...
128
129
  
  	list_add_tail(&bdata->list, &bdata_list);
679bc9fbb   KAMEZAWA Hiroyuki   [PATCH] for_each_...
130
  }
bbc7b92e3   Franck Bui-Huu   [PATCH] bootmem: ...
131
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
133
   * Called once to set up the allocator itself.
   */
8ae044630   Johannes Weiner   mm: normalize int...
134
  static unsigned long __init init_bootmem_core(bootmem_data_t *bdata,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
  	unsigned long mapstart, unsigned long start, unsigned long end)
  {
bbc7b92e3   Franck Bui-Huu   [PATCH] bootmem: ...
137
  	unsigned long mapsize;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138

2dbb51c49   Mel Gorman   mm: make defensiv...
139
  	mminit_validate_memmodel_limits(&start, &end);
bbc7b92e3   Franck Bui-Huu   [PATCH] bootmem: ...
140
  	bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart));
3560e249a   Johannes Weiner   bootmem: replace ...
141
  	bdata->node_min_pfn = start;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
  	bdata->node_low_pfn = end;
679bc9fbb   KAMEZAWA Hiroyuki   [PATCH] for_each_...
143
  	link_bootmem(bdata);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144
145
146
147
148
  
  	/*
  	 * Initially all pages are reserved - setup_arch() has to
  	 * register free RAM areas explicitly.
  	 */
df049a5f4   Johannes Weiner   bootmem: revisit ...
149
  	mapsize = bootmap_bytes(end - start);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
  	memset(bdata->node_bootmem_map, 0xff, mapsize);
2e5237daf   Johannes Weiner   bootmem: add debu...
151
152
153
  	bdebug("nid=%td start=%lx map=%lx end=%lx mapsize=%lx
  ",
  		bdata - bootmem_node_data, start, mapstart, end, mapsize);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154
155
  	return mapsize;
  }
a66fd7dae   Johannes Weiner   bootmem: add docu...
156
157
158
159
160
161
162
  /**
   * init_bootmem_node - register a node as boot memory
   * @pgdat: node to register
   * @freepfn: pfn where the bitmap for this node is to be placed
   * @startpfn: first pfn on the node
   * @endpfn: first pfn after the node
   *
7c757207f   Mike Rapoport   docs/mm: bootmem:...
163
   * Return: the number of bytes needed to hold the bitmap for this node.
a66fd7dae   Johannes Weiner   bootmem: add docu...
164
   */
223e8dc92   Johannes Weiner   bootmem: reorder ...
165
166
167
168
169
  unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn,
  				unsigned long startpfn, unsigned long endpfn)
  {
  	return init_bootmem_core(pgdat->bdata, freepfn, startpfn, endpfn);
  }
a66fd7dae   Johannes Weiner   bootmem: add docu...
170
171
172
173
174
  /**
   * init_bootmem - register boot memory
   * @start: pfn where the bitmap is to be placed
   * @pages: number of available physical pages
   *
7c757207f   Mike Rapoport   docs/mm: bootmem:...
175
   * Return: the number of bytes needed to hold the bitmap.
a66fd7dae   Johannes Weiner   bootmem: add docu...
176
   */
223e8dc92   Johannes Weiner   bootmem: reorder ...
177
178
179
180
181
182
  unsigned long __init init_bootmem(unsigned long start, unsigned long pages)
  {
  	max_low_pfn = pages;
  	min_low_pfn = start;
  	return init_bootmem_core(NODE_DATA(0)->bdata, start, 0, pages);
  }
093258732   Yinghai Lu   bootmem: Separate...
183

81df9bff2   Joonsoo Kim   bootmem: fix wron...
184
  void __init free_bootmem_late(unsigned long physaddr, unsigned long size)
9f993ac3f   FUJITA Tomonori   bootmem: Add free...
185
186
  {
  	unsigned long cursor, end;
9099daed9   Catalin Marinas   mm: kmemleak: avo...
187
  	kmemleak_free_part_phys(physaddr, size);
9f993ac3f   FUJITA Tomonori   bootmem: Add free...
188

81df9bff2   Joonsoo Kim   bootmem: fix wron...
189
190
  	cursor = PFN_UP(physaddr);
  	end = PFN_DOWN(physaddr + size);
9f993ac3f   FUJITA Tomonori   bootmem: Add free...
191
192
  
  	for (; cursor < end; cursor++) {
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
193
  		__free_pages_bootmem(pfn_to_page(cursor), cursor, 0);
9f993ac3f   FUJITA Tomonori   bootmem: Add free...
194
195
196
  		totalram_pages++;
  	}
  }
223e8dc92   Johannes Weiner   bootmem: reorder ...
197
198
199
  static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
  {
  	struct page *page;
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
200
  	unsigned long *map, start, end, pages, cur, count = 0;
41546c174   Johannes Weiner   bootmem: clean up...
201
202
203
  
  	if (!bdata->node_bootmem_map)
  		return 0;
4a099fb4b   Daeseok Youn   mm/bootmem.c: rem...
204
  	map = bdata->node_bootmem_map;
3560e249a   Johannes Weiner   bootmem: replace ...
205
  	start = bdata->node_min_pfn;
41546c174   Johannes Weiner   bootmem: clean up...
206
  	end = bdata->node_low_pfn;
799f933a8   Johannes Weiner   mm: bootmem: try ...
207
208
209
  	bdebug("nid=%td start=%lx end=%lx
  ",
  		bdata - bootmem_node_data, start, end);
223e8dc92   Johannes Weiner   bootmem: reorder ...
210

41546c174   Johannes Weiner   bootmem: clean up...
211
  	while (start < end) {
4a099fb4b   Daeseok Youn   mm/bootmem.c: rem...
212
  		unsigned long idx, vec;
10d73e655   Max Filippov   mm: bootmem: fix ...
213
  		unsigned shift;
223e8dc92   Johannes Weiner   bootmem: reorder ...
214

3560e249a   Johannes Weiner   bootmem: replace ...
215
  		idx = start - bdata->node_min_pfn;
10d73e655   Max Filippov   mm: bootmem: fix ...
216
217
218
219
220
  		shift = idx & (BITS_PER_LONG - 1);
  		/*
  		 * vec holds at most BITS_PER_LONG map bits,
  		 * bit 0 corresponds to start.
  		 */
41546c174   Johannes Weiner   bootmem: clean up...
221
  		vec = ~map[idx / BITS_PER_LONG];
10d73e655   Max Filippov   mm: bootmem: fix ...
222
223
224
225
226
227
228
  
  		if (shift) {
  			vec >>= shift;
  			if (end - start >= BITS_PER_LONG)
  				vec |= ~map[idx / BITS_PER_LONG + 1] <<
  					(BITS_PER_LONG - shift);
  		}
799f933a8   Johannes Weiner   mm: bootmem: try ...
229
230
231
232
233
234
  		/*
  		 * If we have a properly aligned and fully unreserved
  		 * BITS_PER_LONG block of pages in front of us, free
  		 * it in one go.
  		 */
  		if (IS_ALIGNED(start, BITS_PER_LONG) && vec == ~0UL) {
41546c174   Johannes Weiner   bootmem: clean up...
235
  			int order = ilog2(BITS_PER_LONG);
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
236
  			__free_pages_bootmem(pfn_to_page(start), start, order);
223e8dc92   Johannes Weiner   bootmem: reorder ...
237
  			count += BITS_PER_LONG;
799f933a8   Johannes Weiner   mm: bootmem: try ...
238
  			start += BITS_PER_LONG;
41546c174   Johannes Weiner   bootmem: clean up...
239
  		} else {
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
240
  			cur = start;
41546c174   Johannes Weiner   bootmem: clean up...
241

10d73e655   Max Filippov   mm: bootmem: fix ...
242
243
  			start = ALIGN(start + 1, BITS_PER_LONG);
  			while (vec && cur != start) {
41546c174   Johannes Weiner   bootmem: clean up...
244
  				if (vec & 1) {
10d73e655   Max Filippov   mm: bootmem: fix ...
245
  					page = pfn_to_page(cur);
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
246
  					__free_pages_bootmem(page, cur, 0);
41546c174   Johannes Weiner   bootmem: clean up...
247
  					count++;
223e8dc92   Johannes Weiner   bootmem: reorder ...
248
  				}
41546c174   Johannes Weiner   bootmem: clean up...
249
  				vec >>= 1;
10d73e655   Max Filippov   mm: bootmem: fix ...
250
  				++cur;
223e8dc92   Johannes Weiner   bootmem: reorder ...
251
  			}
223e8dc92   Johannes Weiner   bootmem: reorder ...
252
  		}
223e8dc92   Johannes Weiner   bootmem: reorder ...
253
  	}
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
254
  	cur = bdata->node_min_pfn;
223e8dc92   Johannes Weiner   bootmem: reorder ...
255
  	page = virt_to_page(bdata->node_bootmem_map);
3560e249a   Johannes Weiner   bootmem: replace ...
256
  	pages = bdata->node_low_pfn - bdata->node_min_pfn;
41546c174   Johannes Weiner   bootmem: clean up...
257
258
  	pages = bootmem_bootmap_pages(pages);
  	count += pages;
5576646f3   Andrew Morton   revert "mm: fix-u...
259
  	while (pages--)
d70ddd7a5   Mel Gorman   mm: page_alloc: p...
260
  		__free_pages_bootmem(page++, cur++, 0);
1b4ace414   Chris Metcalf   bootmem: avoid fr...
261
  	bdata->node_bootmem_map = NULL;
223e8dc92   Johannes Weiner   bootmem: reorder ...
262

2e5237daf   Johannes Weiner   bootmem: add debu...
263
264
  	bdebug("nid=%td released=%lx
  ", bdata - bootmem_node_data, count);
223e8dc92   Johannes Weiner   bootmem: reorder ...
265
266
  	return count;
  }
7b4b2a0d6   Jiang Liu   mm: accurately ca...
267
  static int reset_managed_pages_done __initdata;
f784a3f19   Tang Chen   mem-hotplug: rese...
268
  void reset_node_managed_pages(pg_data_t *pgdat)
9feedc9d8   Jiang Liu   mm: introduce new...
269
270
  {
  	struct zone *z;
9feedc9d8   Jiang Liu   mm: introduce new...
271
  	for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
7b4b2a0d6   Jiang Liu   mm: accurately ca...
272
273
274
275
276
277
  		z->managed_pages = 0;
  }
  
  void __init reset_all_zones_managed_pages(void)
  {
  	struct pglist_data *pgdat;
f784a3f19   Tang Chen   mem-hotplug: rese...
278
279
  	if (reset_managed_pages_done)
  		return;
7b4b2a0d6   Jiang Liu   mm: accurately ca...
280
281
  	for_each_online_pgdat(pgdat)
  		reset_node_managed_pages(pgdat);
f784a3f19   Tang Chen   mem-hotplug: rese...
282

7b4b2a0d6   Jiang Liu   mm: accurately ca...
283
  	reset_managed_pages_done = 1;
9feedc9d8   Jiang Liu   mm: introduce new...
284
  }
223e8dc92   Johannes Weiner   bootmem: reorder ...
285
286
  unsigned long __init free_all_bootmem(void)
  {
aa235fc71   Yinghai Lu   bootmem, x86: Fix...
287
288
  	unsigned long total_pages = 0;
  	bootmem_data_t *bdata;
9feedc9d8   Jiang Liu   mm: introduce new...
289

7b4b2a0d6   Jiang Liu   mm: accurately ca...
290
  	reset_all_zones_managed_pages();
aa235fc71   Yinghai Lu   bootmem, x86: Fix...
291
292
293
  
  	list_for_each_entry(bdata, &bdata_list, list)
  		total_pages += free_all_bootmem_core(bdata);
0c9885347   Jiang Liu   mm: concentrate m...
294
  	totalram_pages += total_pages;
aa235fc71   Yinghai Lu   bootmem, x86: Fix...
295
  	return total_pages;
223e8dc92   Johannes Weiner   bootmem: reorder ...
296
  }
d747fa4bc   Johannes Weiner   bootmem: free/res...
297
298
299
300
301
302
303
  static void __init __free(bootmem_data_t *bdata,
  			unsigned long sidx, unsigned long eidx)
  {
  	unsigned long idx;
  
  	bdebug("nid=%td start=%lx end=%lx
  ", bdata - bootmem_node_data,
3560e249a   Johannes Weiner   bootmem: replace ...
304
305
  		sidx + bdata->node_min_pfn,
  		eidx + bdata->node_min_pfn);
d747fa4bc   Johannes Weiner   bootmem: free/res...
306

1b4ace414   Chris Metcalf   bootmem: avoid fr...
307
308
  	if (WARN_ON(bdata->node_bootmem_map == NULL))
  		return;
e2bf3cae5   Johannes Weiner   bootmem: factor o...
309
310
  	if (bdata->hint_idx > sidx)
  		bdata->hint_idx = sidx;
d747fa4bc   Johannes Weiner   bootmem: free/res...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
  	for (idx = sidx; idx < eidx; idx++)
  		if (!test_and_clear_bit(idx, bdata->node_bootmem_map))
  			BUG();
  }
  
  static int __init __reserve(bootmem_data_t *bdata, unsigned long sidx,
  			unsigned long eidx, int flags)
  {
  	unsigned long idx;
  	int exclusive = flags & BOOTMEM_EXCLUSIVE;
  
  	bdebug("nid=%td start=%lx end=%lx flags=%x
  ",
  		bdata - bootmem_node_data,
3560e249a   Johannes Weiner   bootmem: replace ...
325
326
  		sidx + bdata->node_min_pfn,
  		eidx + bdata->node_min_pfn,
d747fa4bc   Johannes Weiner   bootmem: free/res...
327
  		flags);
1b4ace414   Chris Metcalf   bootmem: avoid fr...
328
329
  	if (WARN_ON(bdata->node_bootmem_map == NULL))
  		return 0;
d747fa4bc   Johannes Weiner   bootmem: free/res...
330
331
332
333
334
335
336
337
  	for (idx = sidx; idx < eidx; idx++)
  		if (test_and_set_bit(idx, bdata->node_bootmem_map)) {
  			if (exclusive) {
  				__free(bdata, sidx, idx);
  				return -EBUSY;
  			}
  			bdebug("silent double reserve of PFN %lx
  ",
3560e249a   Johannes Weiner   bootmem: replace ...
338
  				idx + bdata->node_min_pfn);
d747fa4bc   Johannes Weiner   bootmem: free/res...
339
340
341
  		}
  	return 0;
  }
e2bf3cae5   Johannes Weiner   bootmem: factor o...
342
343
344
  static int __init mark_bootmem_node(bootmem_data_t *bdata,
  				unsigned long start, unsigned long end,
  				int reserve, int flags)
223e8dc92   Johannes Weiner   bootmem: reorder ...
345
346
  {
  	unsigned long sidx, eidx;
223e8dc92   Johannes Weiner   bootmem: reorder ...
347

e2bf3cae5   Johannes Weiner   bootmem: factor o...
348
349
350
  	bdebug("nid=%td start=%lx end=%lx reserve=%d flags=%x
  ",
  		bdata - bootmem_node_data, start, end, reserve, flags);
223e8dc92   Johannes Weiner   bootmem: reorder ...
351

3560e249a   Johannes Weiner   bootmem: replace ...
352
  	BUG_ON(start < bdata->node_min_pfn);
e2bf3cae5   Johannes Weiner   bootmem: factor o...
353
  	BUG_ON(end > bdata->node_low_pfn);
223e8dc92   Johannes Weiner   bootmem: reorder ...
354

3560e249a   Johannes Weiner   bootmem: replace ...
355
356
  	sidx = start - bdata->node_min_pfn;
  	eidx = end - bdata->node_min_pfn;
223e8dc92   Johannes Weiner   bootmem: reorder ...
357

e2bf3cae5   Johannes Weiner   bootmem: factor o...
358
359
  	if (reserve)
  		return __reserve(bdata, sidx, eidx, flags);
223e8dc92   Johannes Weiner   bootmem: reorder ...
360
  	else
e2bf3cae5   Johannes Weiner   bootmem: factor o...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
  		__free(bdata, sidx, eidx);
  	return 0;
  }
  
  static int __init mark_bootmem(unsigned long start, unsigned long end,
  				int reserve, int flags)
  {
  	unsigned long pos;
  	bootmem_data_t *bdata;
  
  	pos = start;
  	list_for_each_entry(bdata, &bdata_list, list) {
  		int err;
  		unsigned long max;
3560e249a   Johannes Weiner   bootmem: replace ...
375
376
  		if (pos < bdata->node_min_pfn ||
  		    pos >= bdata->node_low_pfn) {
e2bf3cae5   Johannes Weiner   bootmem: factor o...
377
378
379
380
381
  			BUG_ON(pos != start);
  			continue;
  		}
  
  		max = min(bdata->node_low_pfn, end);
223e8dc92   Johannes Weiner   bootmem: reorder ...
382

e2bf3cae5   Johannes Weiner   bootmem: factor o...
383
384
385
386
387
  		err = mark_bootmem_node(bdata, pos, max, reserve, flags);
  		if (reserve && err) {
  			mark_bootmem(start, pos, 0, 0);
  			return err;
  		}
223e8dc92   Johannes Weiner   bootmem: reorder ...
388

e2bf3cae5   Johannes Weiner   bootmem: factor o...
389
390
391
392
393
  		if (max == end)
  			return 0;
  		pos = bdata->node_low_pfn;
  	}
  	BUG();
223e8dc92   Johannes Weiner   bootmem: reorder ...
394
395
396
397
398
  }
  
  void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
  			      unsigned long size)
  {
e2bf3cae5   Johannes Weiner   bootmem: factor o...
399
  	unsigned long start, end;
9099daed9   Catalin Marinas   mm: kmemleak: avo...
400
  	kmemleak_free_part_phys(physaddr, size);
ec3a354bd   Catalin Marinas   kmemleak: Add cal...
401

e2bf3cae5   Johannes Weiner   bootmem: factor o...
402
403
404
405
  	start = PFN_UP(physaddr);
  	end = PFN_DOWN(physaddr + size);
  
  	mark_bootmem_node(pgdat->bdata, start, end, 0, 0);
223e8dc92   Johannes Weiner   bootmem: reorder ...
406
  }
81df9bff2   Joonsoo Kim   bootmem: fix wron...
407
  void __init free_bootmem(unsigned long physaddr, unsigned long size)
223e8dc92   Johannes Weiner   bootmem: reorder ...
408
  {
e2bf3cae5   Johannes Weiner   bootmem: factor o...
409
  	unsigned long start, end;
a5645a61b   Yinghai Lu   mm: allow reserve...
410

9099daed9   Catalin Marinas   mm: kmemleak: avo...
411
  	kmemleak_free_part_phys(physaddr, size);
ec3a354bd   Catalin Marinas   kmemleak: Add cal...
412

81df9bff2   Joonsoo Kim   bootmem: fix wron...
413
414
  	start = PFN_UP(physaddr);
  	end = PFN_DOWN(physaddr + size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
415

e2bf3cae5   Johannes Weiner   bootmem: factor o...
416
  	mark_bootmem(start, end, 0, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
  }
a66fd7dae   Johannes Weiner   bootmem: add docu...
418
419
420
421
422
423
424
425
426
  /**
   * reserve_bootmem_node - mark a page range as reserved
   * @pgdat: node the range resides on
   * @physaddr: starting address of the range
   * @size: size of the range in bytes
   * @flags: reservation flags (see linux/bootmem.h)
   *
   * Partial pages will be reserved.
   *
e2bf3cae5   Johannes Weiner   bootmem: factor o...
427
   * The range must reside completely on the specified node.
7c757207f   Mike Rapoport   docs/mm: bootmem:...
428
429
   *
   * Return: 0 on success, -errno on failure.
a66fd7dae   Johannes Weiner   bootmem: add docu...
430
   */
223e8dc92   Johannes Weiner   bootmem: reorder ...
431
432
  int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
  				 unsigned long size, int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
433
  {
e2bf3cae5   Johannes Weiner   bootmem: factor o...
434
  	unsigned long start, end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
435

e2bf3cae5   Johannes Weiner   bootmem: factor o...
436
437
438
439
  	start = PFN_DOWN(physaddr);
  	end = PFN_UP(physaddr + size);
  
  	return mark_bootmem_node(pgdat->bdata, start, end, 1, flags);
223e8dc92   Johannes Weiner   bootmem: reorder ...
440
  }
5a982cbc7   Yinghai Lu   mm: fix boundary ...
441

a66fd7dae   Johannes Weiner   bootmem: add docu...
442
  /**
0d4ba4d7b   Javi Merino   bootmem: Fix the ...
443
   * reserve_bootmem - mark a page range as reserved
a66fd7dae   Johannes Weiner   bootmem: add docu...
444
445
446
447
448
449
   * @addr: starting address of the range
   * @size: size of the range in bytes
   * @flags: reservation flags (see linux/bootmem.h)
   *
   * Partial pages will be reserved.
   *
e2bf3cae5   Johannes Weiner   bootmem: factor o...
450
   * The range must be contiguous but may span node boundaries.
7c757207f   Mike Rapoport   docs/mm: bootmem:...
451
452
   *
   * Return: 0 on success, -errno on failure.
a66fd7dae   Johannes Weiner   bootmem: add docu...
453
   */
223e8dc92   Johannes Weiner   bootmem: reorder ...
454
455
456
  int __init reserve_bootmem(unsigned long addr, unsigned long size,
  			    int flags)
  {
e2bf3cae5   Johannes Weiner   bootmem: factor o...
457
  	unsigned long start, end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
458

e2bf3cae5   Johannes Weiner   bootmem: factor o...
459
460
  	start = PFN_DOWN(addr);
  	end = PFN_UP(addr + size);
223e8dc92   Johannes Weiner   bootmem: reorder ...
461

e2bf3cae5   Johannes Weiner   bootmem: factor o...
462
  	return mark_bootmem(start, end, 1, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
463
  }
8aa043d74   Jan Beulich   mm/bootmem.c: pro...
464
465
  static unsigned long __init align_idx(struct bootmem_data *bdata,
  				      unsigned long idx, unsigned long step)
481ebd0d7   Johannes Weiner   bootmem: fix alig...
466
467
468
469
470
471
472
473
474
475
  {
  	unsigned long base = bdata->node_min_pfn;
  
  	/*
  	 * Align the index with respect to the node start so that the
  	 * combination of both satisfies the requested alignment.
  	 */
  
  	return ALIGN(base + idx, step) - base;
  }
8aa043d74   Jan Beulich   mm/bootmem.c: pro...
476
477
  static unsigned long __init align_off(struct bootmem_data *bdata,
  				      unsigned long off, unsigned long align)
481ebd0d7   Johannes Weiner   bootmem: fix alig...
478
479
480
481
482
483
484
  {
  	unsigned long base = PFN_PHYS(bdata->node_min_pfn);
  
  	/* Same as align_idx for byte offsets */
  
  	return ALIGN(base + off, align) - base;
  }
c6785b6bf   Johannes Weiner   mm: bootmem: rena...
485
  static void * __init alloc_bootmem_bdata(struct bootmem_data *bdata,
d0c4f5702   Tejun Heo   bootmem, x86: fur...
486
487
  					unsigned long size, unsigned long align,
  					unsigned long goal, unsigned long limit)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
488
  {
0f3caba21   Johannes Weiner   bootmem: respect ...
489
  	unsigned long fallback = 0;
5f2809e69   Johannes Weiner   bootmem: clean up...
490
  	unsigned long min, max, start, sidx, midx, step;
594fe1a04   Johannes Weiner   bootmem: print re...
491
492
493
494
  	bdebug("nid=%td size=%lx [%lu pages] align=%lx goal=%lx limit=%lx
  ",
  		bdata - bootmem_node_data, size, PAGE_ALIGN(size) >> PAGE_SHIFT,
  		align, goal, limit);
5f2809e69   Johannes Weiner   bootmem: clean up...
495
496
497
  	BUG_ON(!size);
  	BUG_ON(align & (align - 1));
  	BUG_ON(limit && goal + size > limit);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
498

7c309a64d   Christian Krafft   [PATCH] enable bo...
499
500
  	if (!bdata->node_bootmem_map)
  		return NULL;
3560e249a   Johannes Weiner   bootmem: replace ...
501
  	min = bdata->node_min_pfn;
5f2809e69   Johannes Weiner   bootmem: clean up...
502
  	max = bdata->node_low_pfn;
9a2dc04cf   Yinghai Lu   mm: offset align ...
503

5f2809e69   Johannes Weiner   bootmem: clean up...
504
505
506
507
508
509
  	goal >>= PAGE_SHIFT;
  	limit >>= PAGE_SHIFT;
  
  	if (limit && max > limit)
  		max = limit;
  	if (max <= min)
9a2dc04cf   Yinghai Lu   mm: offset align ...
510
  		return NULL;
5f2809e69   Johannes Weiner   bootmem: clean up...
511
  	step = max(align >> PAGE_SHIFT, 1UL);
281dd25cd   Yasunori Goto   [PATCH] swiotlb: ...
512

5f2809e69   Johannes Weiner   bootmem: clean up...
513
514
515
516
  	if (goal && min < goal && goal < max)
  		start = ALIGN(goal, step);
  	else
  		start = ALIGN(min, step);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517

481ebd0d7   Johannes Weiner   bootmem: fix alig...
518
  	sidx = start - bdata->node_min_pfn;
3560e249a   Johannes Weiner   bootmem: replace ...
519
  	midx = max - bdata->node_min_pfn;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
520

5f2809e69   Johannes Weiner   bootmem: clean up...
521
  	if (bdata->hint_idx > sidx) {
0f3caba21   Johannes Weiner   bootmem: respect ...
522
523
524
525
526
  		/*
  		 * Handle the valid case of sidx being zero and still
  		 * catch the fallback below.
  		 */
  		fallback = sidx + 1;
481ebd0d7   Johannes Weiner   bootmem: fix alig...
527
  		sidx = align_idx(bdata, bdata->hint_idx, step);
5f2809e69   Johannes Weiner   bootmem: clean up...
528
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
529

5f2809e69   Johannes Weiner   bootmem: clean up...
530
531
532
533
534
535
  	while (1) {
  		int merge;
  		void *region;
  		unsigned long eidx, i, start_off, end_off;
  find_block:
  		sidx = find_next_zero_bit(bdata->node_bootmem_map, midx, sidx);
481ebd0d7   Johannes Weiner   bootmem: fix alig...
536
  		sidx = align_idx(bdata, sidx, step);
5f2809e69   Johannes Weiner   bootmem: clean up...
537
  		eidx = sidx + PFN_UP(size);
ad09315ca   Yinghai Lu   mm: fix alloc_boo...
538

5f2809e69   Johannes Weiner   bootmem: clean up...
539
  		if (sidx >= midx || eidx > midx)
66d43e98e   Haren Myneni   [PATCH] fix in __...
540
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
541

5f2809e69   Johannes Weiner   bootmem: clean up...
542
543
  		for (i = sidx; i < eidx; i++)
  			if (test_bit(i, bdata->node_bootmem_map)) {
481ebd0d7   Johannes Weiner   bootmem: fix alig...
544
  				sidx = align_idx(bdata, i, step);
5f2809e69   Johannes Weiner   bootmem: clean up...
545
546
547
548
  				if (sidx == i)
  					sidx += step;
  				goto find_block;
  			}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
549

627240aaa   Mikulas Patocka   bootmem allocator...
550
  		if (bdata->last_end_off & (PAGE_SIZE - 1) &&
5f2809e69   Johannes Weiner   bootmem: clean up...
551
  				PFN_DOWN(bdata->last_end_off) + 1 == sidx)
481ebd0d7   Johannes Weiner   bootmem: fix alig...
552
  			start_off = align_off(bdata, bdata->last_end_off, align);
5f2809e69   Johannes Weiner   bootmem: clean up...
553
554
555
556
557
558
559
560
561
562
563
564
  		else
  			start_off = PFN_PHYS(sidx);
  
  		merge = PFN_DOWN(start_off) < sidx;
  		end_off = start_off + size;
  
  		bdata->last_end_off = end_off;
  		bdata->hint_idx = PFN_UP(end_off);
  
  		/*
  		 * Reserve the area now:
  		 */
d747fa4bc   Johannes Weiner   bootmem: free/res...
565
566
567
  		if (__reserve(bdata, PFN_DOWN(start_off) + merge,
  				PFN_UP(end_off), BOOTMEM_EXCLUSIVE))
  			BUG();
5f2809e69   Johannes Weiner   bootmem: clean up...
568

3560e249a   Johannes Weiner   bootmem: replace ...
569
570
  		region = phys_to_virt(PFN_PHYS(bdata->node_min_pfn) +
  				start_off);
5f2809e69   Johannes Weiner   bootmem: clean up...
571
  		memset(region, 0, size);
008139d91   Catalin Marinas   kmemleak: Do not ...
572
573
574
575
576
  		/*
  		 * The min_count is set to 0 so that bootmem allocated blocks
  		 * are never reported as leaks.
  		 */
  		kmemleak_alloc(region, size, 0, 0);
5f2809e69   Johannes Weiner   bootmem: clean up...
577
  		return region;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
578
  	}
0f3caba21   Johannes Weiner   bootmem: respect ...
579
  	if (fallback) {
481ebd0d7   Johannes Weiner   bootmem: fix alig...
580
  		sidx = align_idx(bdata, fallback - 1, step);
0f3caba21   Johannes Weiner   bootmem: respect ...
581
582
583
584
585
586
  		fallback = 0;
  		goto find_block;
  	}
  
  	return NULL;
  }
c12ab504a   Johannes Weiner   mm: bootmem: spli...
587
  static void * __init alloc_bootmem_core(unsigned long size,
0f3caba21   Johannes Weiner   bootmem: respect ...
588
589
590
591
592
  					unsigned long align,
  					unsigned long goal,
  					unsigned long limit)
  {
  	bootmem_data_t *bdata;
d0c4f5702   Tejun Heo   bootmem, x86: fur...
593
  	void *region;
0f3caba21   Johannes Weiner   bootmem: respect ...
594

3f7dfe24b   Joonsoo Kim   bootmem: remove a...
595
596
  	if (WARN_ON_ONCE(slab_is_available()))
  		return kzalloc(size, GFP_NOWAIT);
0f3caba21   Johannes Weiner   bootmem: respect ...
597

d0c4f5702   Tejun Heo   bootmem, x86: fur...
598
  	list_for_each_entry(bdata, &bdata_list, list) {
0f3caba21   Johannes Weiner   bootmem: respect ...
599
600
  		if (goal && bdata->node_low_pfn <= PFN_DOWN(goal))
  			continue;
3560e249a   Johannes Weiner   bootmem: replace ...
601
  		if (limit && bdata->node_min_pfn >= PFN_DOWN(limit))
0f3caba21   Johannes Weiner   bootmem: respect ...
602
  			break;
c6785b6bf   Johannes Weiner   mm: bootmem: rena...
603
  		region = alloc_bootmem_bdata(bdata, size, align, goal, limit);
0f3caba21   Johannes Weiner   bootmem: respect ...
604
605
606
  		if (region)
  			return region;
  	}
c12ab504a   Johannes Weiner   mm: bootmem: spli...
607
608
609
610
611
612
613
614
615
616
617
618
619
620
  	return NULL;
  }
  
  static void * __init ___alloc_bootmem_nopanic(unsigned long size,
  					      unsigned long align,
  					      unsigned long goal,
  					      unsigned long limit)
  {
  	void *ptr;
  
  restart:
  	ptr = alloc_bootmem_core(size, align, goal, limit);
  	if (ptr)
  		return ptr;
5f2809e69   Johannes Weiner   bootmem: clean up...
621
622
  	if (goal) {
  		goal = 0;
0f3caba21   Johannes Weiner   bootmem: respect ...
623
  		goto restart;
5f2809e69   Johannes Weiner   bootmem: clean up...
624
  	}
2e5237daf   Johannes Weiner   bootmem: add debu...
625

5f2809e69   Johannes Weiner   bootmem: clean up...
626
  	return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
627
  }
bb0923a66   Franck Bui-Huu   [PATCH] bootmem: ...
628
  void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
0f3caba21   Johannes Weiner   bootmem: respect ...
629
  					unsigned long goal)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
  {
08677214e   Yinghai Lu   x86: Make 64 bit ...
631
  	unsigned long limit = 0;
08677214e   Yinghai Lu   x86: Make 64 bit ...
632
  	return ___alloc_bootmem_nopanic(size, align, goal, limit);
0f3caba21   Johannes Weiner   bootmem: respect ...
633
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634

0f3caba21   Johannes Weiner   bootmem: respect ...
635
636
637
638
639
640
641
642
643
644
  static void * __init ___alloc_bootmem(unsigned long size, unsigned long align,
  					unsigned long goal, unsigned long limit)
  {
  	void *mem = ___alloc_bootmem_nopanic(size, align, goal, limit);
  
  	if (mem)
  		return mem;
  	/*
  	 * Whoops, we cannot satisfy the allocation request.
  	 */
1170532bb   Joe Perches   mm: convert print...
645
646
  	pr_alert("bootmem alloc of %lu bytes failed!
  ", size);
0f3caba21   Johannes Weiner   bootmem: respect ...
647
  	panic("Out of memory");
a8062231d   Andi Kleen   [PATCH] x86_64: H...
648
649
  	return NULL;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
650

bb0923a66   Franck Bui-Huu   [PATCH] bootmem: ...
651
652
  void * __init __alloc_bootmem(unsigned long size, unsigned long align,
  			      unsigned long goal)
a8062231d   Andi Kleen   [PATCH] x86_64: H...
653
  {
08677214e   Yinghai Lu   x86: Make 64 bit ...
654
  	unsigned long limit = 0;
08677214e   Yinghai Lu   x86: Make 64 bit ...
655
  	return ___alloc_bootmem(size, align, goal, limit);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
656
  }
99ab7b194   Yinghai Lu   mm: sparse: fix u...
657
  void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
4cc278b72   Johannes Weiner   bootmem: Make __a...
658
659
660
661
  				unsigned long size, unsigned long align,
  				unsigned long goal, unsigned long limit)
  {
  	void *ptr;
3f7dfe24b   Joonsoo Kim   bootmem: remove a...
662
  	if (WARN_ON_ONCE(slab_is_available()))
1d8bf926f   zijun_hu   mm/bootmem.c: rep...
663
  		return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
ab3818432   Johannes Weiner   mm: bootmem: allo...
664
  again:
d0c4f5702   Tejun Heo   bootmem, x86: fur...
665

c8f4a2d09   Yinghai Lu   bootmem: make ___...
666
667
668
  	/* do not panic in alloc_bootmem_bdata() */
  	if (limit && goal + size > limit)
  		limit = 0;
e9079911e   Johannes Weiner   mm: bootmem: pass...
669
  	ptr = alloc_bootmem_bdata(pgdat->bdata, size, align, goal, limit);
4cc278b72   Johannes Weiner   bootmem: Make __a...
670
671
  	if (ptr)
  		return ptr;
ab3818432   Johannes Weiner   mm: bootmem: allo...
672
673
674
675
676
677
678
679
  	ptr = alloc_bootmem_core(size, align, goal, limit);
  	if (ptr)
  		return ptr;
  
  	if (goal) {
  		goal = 0;
  		goto again;
  	}
421456edd   Johannes Weiner   mm: bootmem: unif...
680
681
682
683
684
685
  	return NULL;
  }
  
  void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size,
  				   unsigned long align, unsigned long goal)
  {
e9079911e   Johannes Weiner   mm: bootmem: pass...
686
  	return ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0);
421456edd   Johannes Weiner   mm: bootmem: unif...
687
  }
e9079911e   Johannes Weiner   mm: bootmem: pass...
688
  void * __init ___alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
421456edd   Johannes Weiner   mm: bootmem: unif...
689
690
691
692
  				    unsigned long align, unsigned long goal,
  				    unsigned long limit)
  {
  	void *ptr;
e9079911e   Johannes Weiner   mm: bootmem: pass...
693
  	ptr = ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0);
421456edd   Johannes Weiner   mm: bootmem: unif...
694
695
  	if (ptr)
  		return ptr;
1170532bb   Joe Perches   mm: convert print...
696
697
  	pr_alert("bootmem alloc of %lu bytes failed!
  ", size);
ab3818432   Johannes Weiner   mm: bootmem: allo...
698
699
  	panic("Out of memory");
  	return NULL;
4cc278b72   Johannes Weiner   bootmem: Make __a...
700
  }
bb0923a66   Franck Bui-Huu   [PATCH] bootmem: ...
701
702
  void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
  				   unsigned long align, unsigned long goal)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
703
  {
c91c4773b   Pekka Enberg   bootmem: fix slab...
704
705
  	if (WARN_ON_ONCE(slab_is_available()))
  		return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
e9079911e   Johannes Weiner   mm: bootmem: pass...
706
  	return  ___alloc_bootmem_node(pgdat, size, align, goal, 0);
08677214e   Yinghai Lu   x86: Make 64 bit ...
707
708
709
710
711
712
713
714
715
716
717
718
  }
  
  void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size,
  				   unsigned long align, unsigned long goal)
  {
  #ifdef MAX_DMA32_PFN
  	unsigned long end_pfn;
  
  	if (WARN_ON_ONCE(slab_is_available()))
  		return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
  
  	/* update goal according ...MAX_DMA32_PFN */
83285c72e   Xishi Qiu   mm: use pgdat_end...
719
  	end_pfn = pgdat_end_pfn(pgdat);
08677214e   Yinghai Lu   x86: Make 64 bit ...
720
721
722
723
724
725
726
  
  	if (end_pfn > MAX_DMA32_PFN + (128 >> (20 - PAGE_SHIFT)) &&
  	    (goal >> PAGE_SHIFT) < MAX_DMA32_PFN) {
  		void *ptr;
  		unsigned long new_goal;
  
  		new_goal = MAX_DMA32_PFN << PAGE_SHIFT;
c6785b6bf   Johannes Weiner   mm: bootmem: rena...
727
  		ptr = alloc_bootmem_bdata(pgdat->bdata, size, align,
08677214e   Yinghai Lu   x86: Make 64 bit ...
728
  						 new_goal, 0);
08677214e   Yinghai Lu   x86: Make 64 bit ...
729
730
731
732
733
734
  		if (ptr)
  			return ptr;
  	}
  #endif
  
  	return __alloc_bootmem_node(pgdat, size, align, goal);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
735
  }
bb0923a66   Franck Bui-Huu   [PATCH] bootmem: ...
736
737
  void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
  				  unsigned long goal)
008857c1a   Ravikiran G Thirumalai   [PATCH] Cleanup b...
738
  {
0f3caba21   Johannes Weiner   bootmem: respect ...
739
  	return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT);
008857c1a   Ravikiran G Thirumalai   [PATCH] Cleanup b...
740
  }
38fa4175e   Yinghai Lu   mm: Add alloc_boo...
741
742
743
744
745
746
747
  void * __init __alloc_bootmem_low_nopanic(unsigned long size,
  					  unsigned long align,
  					  unsigned long goal)
  {
  	return ___alloc_bootmem_nopanic(size, align, goal,
  					ARCH_LOW_ADDRESS_LIMIT);
  }
008857c1a   Ravikiran G Thirumalai   [PATCH] Cleanup b...
748
749
750
  void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size,
  				       unsigned long align, unsigned long goal)
  {
c91c4773b   Pekka Enberg   bootmem: fix slab...
751
752
  	if (WARN_ON_ONCE(slab_is_available()))
  		return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
e9079911e   Johannes Weiner   mm: bootmem: pass...
753
754
  	return ___alloc_bootmem_node(pgdat, size, align,
  				     goal, ARCH_LOW_ADDRESS_LIMIT);
008857c1a   Ravikiran G Thirumalai   [PATCH] Cleanup b...
755
  }