blob: 97db0e8e362b8541bac0f7aa9d8d39fb246cd379 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Johannes Weiner57cfc292008-07-23 21:28:00 -07003 * bootmem - A boot-time physical memory allocator and configurator
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Copyright (C) 1999 Ingo Molnar
Johannes Weiner57cfc292008-07-23 21:28:00 -07006 * 1999 Kanoj Sarcar, SGI
7 * 2008 Johannes Weiner
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Johannes Weiner57cfc292008-07-23 21:28:00 -07009 * Access to this subsystem has to be serialized externally (which is true
10 * for the boot process anyway).
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
Franck Bui-Huubbc7b922006-09-25 23:31:07 -070013#include <linux/pfn.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Paul Gortmakerb95f1b312011-10-16 02:01:52 -040015#include <linux/export.h>
Catalin Marinasec3a3542009-07-07 10:33:01 +010016#include <linux/kmemleak.h>
Yinghai Lu08677212010-02-10 01:20:20 -080017#include <linux/range.h>
Paul McQuaded85fbee2014-10-09 15:29:05 -070018#include <linux/bug.h>
19#include <linux/io.h>
zijun_hu1d8bf922016-10-07 16:59:27 -070020#include <linux/bootmem.h>
Franck Bui-Huue786e862006-09-25 23:31:06 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "internal.h"
23
Mike Rapoport58faef92018-06-30 17:55:00 +030024/**
25 * DOC: bootmem overview
26 *
27 * Bootmem is a boot-time physical memory allocator and configurator.
28 *
29 * It is used early in the boot process before the page allocator is
30 * set up.
31 *
32 * Bootmem is based on the most basic of allocators, a First Fit
33 * allocator which uses a bitmap to represent memory. If a bit is 1,
34 * the page is allocated and 0 if unallocated. To satisfy allocations
35 * of sizes smaller than a page, the allocator records the Page Frame
36 * Number (PFN) of the last allocation and the offset the allocation
37 * ended at. Subsequent small allocations are merged together and
38 * stored on the same page.
39 *
40 * The information used by the bootmem allocator is represented by
41 * :c:type:`struct bootmem_data`. An array to hold up to %MAX_NUMNODES
42 * such structures is statically allocated and then it is discarded
43 * when the system initialization completes. Each entry in this array
44 * corresponds to a node with memory. For UMA systems only entry 0 is
45 * used.
46 *
47 * The bootmem allocator is initialized during early architecture
48 * specific setup. Each architecture is required to supply a
49 * :c:func:`setup_arch` function which, among other tasks, is
50 * responsible for acquiring the necessary parameters to initialise
51 * the boot memory allocator. These parameters define limits of usable
52 * physical memory:
53 *
54 * * @min_low_pfn - the lowest PFN that is available in the system
55 * * @max_low_pfn - the highest PFN that may be addressed by low
56 * memory (%ZONE_NORMAL)
57 * * @max_pfn - the last PFN available to the system.
58 *
59 * After those limits are determined, the :c:func:`init_bootmem` or
60 * :c:func:`init_bootmem_node` function should be called to initialize
61 * the bootmem allocator. The UMA case should use the `init_bootmem`
62 * function. It will initialize ``contig_page_data`` structure that
63 * represents the only memory node in the system. In the NUMA case the
64 * `init_bootmem_node` function should be called to initialize the
65 * bootmem allocator for each node.
66 *
67 * Once the allocator is set up, it is possible to use either single
68 * node or NUMA variant of the allocation APIs.
69 */
70
Yinghai Lue782ab42011-02-24 14:43:06 +010071#ifndef CONFIG_NEED_MULTIPLE_NODES
72struct pglist_data __refdata contig_page_data = {
73 .bdata = &bootmem_node_data[0]
74};
75EXPORT_SYMBOL(contig_page_data);
76#endif
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078unsigned long max_low_pfn;
79unsigned long min_low_pfn;
80unsigned long max_pfn;
Igor Mammedov8dd33032015-12-04 14:07:05 +010081unsigned long long max_possible_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Johannes Weinerb61bfa32008-07-23 21:26:55 -070083bootmem_data_t bootmem_node_data[MAX_NUMNODES] __initdata;
84
Johannes Weiner636cc402008-07-23 21:28:03 -070085static struct list_head bdata_list __initdata = LIST_HEAD_INIT(bdata_list);
86
Johannes Weiner2e5237d2008-07-23 21:28:02 -070087static int bootmem_debug;
88
89static int __init bootmem_debug_setup(char *buf)
90{
91 bootmem_debug = 1;
92 return 0;
93}
94early_param("bootmem_debug", bootmem_debug_setup);
95
96#define bdebug(fmt, args...) ({ \
97 if (unlikely(bootmem_debug)) \
Joe Perches11705322016-03-17 14:19:50 -070098 pr_info("bootmem::%s " fmt, \
Harvey Harrison80a914d2008-10-15 22:01:25 -070099 __func__, ## args); \
Johannes Weiner2e5237d2008-07-23 21:28:02 -0700100})
101
Johannes Weinerdf049a52008-07-23 21:28:02 -0700102static unsigned long __init bootmap_bytes(unsigned long pages)
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700103{
Adygzhy Ondard3a9d7a32017-02-22 15:44:58 -0800104 unsigned long bytes = DIV_ROUND_UP(pages, BITS_PER_BYTE);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700105
Johannes Weinerdf049a52008-07-23 21:28:02 -0700106 return ALIGN(bytes, sizeof(long));
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700107}
108
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700109/**
110 * bootmem_bootmap_pages - calculate bitmap size in pages
111 * @pages: number of pages the bitmap has to represent
Mike Rapoport7c757202018-06-30 17:54:58 +0300112 *
113 * Return: the number of pages needed to hold the bitmap.
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700114 */
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700115unsigned long __init bootmem_bootmap_pages(unsigned long pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Johannes Weinerdf049a52008-07-23 21:28:02 -0700117 unsigned long bytes = bootmap_bytes(pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Johannes Weinerdf049a52008-07-23 21:28:02 -0700119 return PAGE_ALIGN(bytes) >> PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700121
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800122/*
123 * link bdata in order
124 */
Franck Bui-Huu69d49e62006-09-25 23:31:04 -0700125static void __init link_bootmem(bootmem_data_t *bdata)
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800126{
Gavin Shan5c2b8a12012-05-29 15:06:46 -0700127 bootmem_data_t *ent;
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700128
Gavin Shan5c2b8a12012-05-29 15:06:46 -0700129 list_for_each_entry(ent, &bdata_list, list) {
130 if (bdata->node_min_pfn < ent->node_min_pfn) {
131 list_add_tail(&bdata->list, &ent->list);
132 return;
133 }
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800134 }
Gavin Shan5c2b8a12012-05-29 15:06:46 -0700135
136 list_add_tail(&bdata->list, &bdata_list);
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800137}
138
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700139/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * Called once to set up the allocator itself.
141 */
Johannes Weiner8ae04462008-07-23 21:26:59 -0700142static unsigned long __init init_bootmem_core(bootmem_data_t *bdata,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 unsigned long mapstart, unsigned long start, unsigned long end)
144{
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700145 unsigned long mapsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Mel Gorman2dbb51c2008-07-23 21:26:52 -0700147 mminit_validate_memmodel_limits(&start, &end);
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700148 bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart));
Johannes Weiner3560e242008-07-23 21:28:09 -0700149 bdata->node_min_pfn = start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 bdata->node_low_pfn = end;
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800151 link_bootmem(bdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /*
154 * Initially all pages are reserved - setup_arch() has to
155 * register free RAM areas explicitly.
156 */
Johannes Weinerdf049a52008-07-23 21:28:02 -0700157 mapsize = bootmap_bytes(end - start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 memset(bdata->node_bootmem_map, 0xff, mapsize);
159
Johannes Weiner2e5237d2008-07-23 21:28:02 -0700160 bdebug("nid=%td start=%lx map=%lx end=%lx mapsize=%lx\n",
161 bdata - bootmem_node_data, start, mapstart, end, mapsize);
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return mapsize;
164}
165
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700166/**
167 * init_bootmem_node - register a node as boot memory
168 * @pgdat: node to register
169 * @freepfn: pfn where the bitmap for this node is to be placed
170 * @startpfn: first pfn on the node
171 * @endpfn: first pfn after the node
172 *
Mike Rapoport7c757202018-06-30 17:54:58 +0300173 * Return: the number of bytes needed to hold the bitmap for this node.
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700174 */
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700175unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn,
176 unsigned long startpfn, unsigned long endpfn)
177{
178 return init_bootmem_core(pgdat->bdata, freepfn, startpfn, endpfn);
179}
180
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700181/**
182 * init_bootmem - register boot memory
183 * @start: pfn where the bitmap is to be placed
184 * @pages: number of available physical pages
185 *
Mike Rapoport7c757202018-06-30 17:54:58 +0300186 * Return: the number of bytes needed to hold the bitmap.
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700187 */
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700188unsigned long __init init_bootmem(unsigned long start, unsigned long pages)
189{
190 max_low_pfn = pages;
191 min_low_pfn = start;
192 return init_bootmem_core(NODE_DATA(0)->bdata, start, 0, pages);
193}
Yinghai Lu09325872011-02-24 14:43:05 +0100194
Joonsoo Kim81df9bf2012-12-11 16:03:10 -0800195void __init free_bootmem_late(unsigned long physaddr, unsigned long size)
FUJITA Tomonori9f993ac2009-11-10 19:46:17 +0900196{
197 unsigned long cursor, end;
198
Catalin Marinas9099dae2016-10-11 13:55:11 -0700199 kmemleak_free_part_phys(physaddr, size);
FUJITA Tomonori9f993ac2009-11-10 19:46:17 +0900200
Joonsoo Kim81df9bf2012-12-11 16:03:10 -0800201 cursor = PFN_UP(physaddr);
202 end = PFN_DOWN(physaddr + size);
FUJITA Tomonori9f993ac2009-11-10 19:46:17 +0900203
204 for (; cursor < end; cursor++) {
Mel Gormand70ddd72015-06-30 14:56:52 -0700205 __free_pages_bootmem(pfn_to_page(cursor), cursor, 0);
FUJITA Tomonori9f993ac2009-11-10 19:46:17 +0900206 totalram_pages++;
207 }
208}
209
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700210static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
211{
212 struct page *page;
Mel Gormand70ddd72015-06-30 14:56:52 -0700213 unsigned long *map, start, end, pages, cur, count = 0;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700214
Johannes Weiner41546c12008-07-23 21:28:03 -0700215 if (!bdata->node_bootmem_map)
216 return 0;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700217
Daeseok Youn4a099fb2013-11-12 15:08:14 -0800218 map = bdata->node_bootmem_map;
Johannes Weiner3560e242008-07-23 21:28:09 -0700219 start = bdata->node_min_pfn;
Johannes Weiner41546c12008-07-23 21:28:03 -0700220 end = bdata->node_low_pfn;
221
Johannes Weiner799f9332012-01-10 15:08:15 -0800222 bdebug("nid=%td start=%lx end=%lx\n",
223 bdata - bootmem_node_data, start, end);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700224
Johannes Weiner41546c12008-07-23 21:28:03 -0700225 while (start < end) {
Daeseok Youn4a099fb2013-11-12 15:08:14 -0800226 unsigned long idx, vec;
Max Filippov10d73e62013-01-11 14:31:52 -0800227 unsigned shift;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700228
Johannes Weiner3560e242008-07-23 21:28:09 -0700229 idx = start - bdata->node_min_pfn;
Max Filippov10d73e62013-01-11 14:31:52 -0800230 shift = idx & (BITS_PER_LONG - 1);
231 /*
232 * vec holds at most BITS_PER_LONG map bits,
233 * bit 0 corresponds to start.
234 */
Johannes Weiner41546c12008-07-23 21:28:03 -0700235 vec = ~map[idx / BITS_PER_LONG];
Max Filippov10d73e62013-01-11 14:31:52 -0800236
237 if (shift) {
238 vec >>= shift;
239 if (end - start >= BITS_PER_LONG)
240 vec |= ~map[idx / BITS_PER_LONG + 1] <<
241 (BITS_PER_LONG - shift);
242 }
Johannes Weiner799f9332012-01-10 15:08:15 -0800243 /*
244 * If we have a properly aligned and fully unreserved
245 * BITS_PER_LONG block of pages in front of us, free
246 * it in one go.
247 */
248 if (IS_ALIGNED(start, BITS_PER_LONG) && vec == ~0UL) {
Johannes Weiner41546c12008-07-23 21:28:03 -0700249 int order = ilog2(BITS_PER_LONG);
250
Mel Gormand70ddd72015-06-30 14:56:52 -0700251 __free_pages_bootmem(pfn_to_page(start), start, order);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700252 count += BITS_PER_LONG;
Johannes Weiner799f9332012-01-10 15:08:15 -0800253 start += BITS_PER_LONG;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700254 } else {
Mel Gormand70ddd72015-06-30 14:56:52 -0700255 cur = start;
Johannes Weiner41546c12008-07-23 21:28:03 -0700256
Max Filippov10d73e62013-01-11 14:31:52 -0800257 start = ALIGN(start + 1, BITS_PER_LONG);
258 while (vec && cur != start) {
Johannes Weiner41546c12008-07-23 21:28:03 -0700259 if (vec & 1) {
Max Filippov10d73e62013-01-11 14:31:52 -0800260 page = pfn_to_page(cur);
Mel Gormand70ddd72015-06-30 14:56:52 -0700261 __free_pages_bootmem(page, cur, 0);
Johannes Weiner41546c12008-07-23 21:28:03 -0700262 count++;
263 }
264 vec >>= 1;
Max Filippov10d73e62013-01-11 14:31:52 -0800265 ++cur;
Johannes Weiner41546c12008-07-23 21:28:03 -0700266 }
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700267 }
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700268 }
269
Mel Gormand70ddd72015-06-30 14:56:52 -0700270 cur = bdata->node_min_pfn;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700271 page = virt_to_page(bdata->node_bootmem_map);
Johannes Weiner3560e242008-07-23 21:28:09 -0700272 pages = bdata->node_low_pfn - bdata->node_min_pfn;
Johannes Weiner41546c12008-07-23 21:28:03 -0700273 pages = bootmem_bootmap_pages(pages);
274 count += pages;
Andrew Morton55766462012-11-16 14:15:06 -0800275 while (pages--)
Mel Gormand70ddd72015-06-30 14:56:52 -0700276 __free_pages_bootmem(page++, cur++, 0);
Chris Metcalf1b4ace42015-09-08 15:02:12 -0700277 bdata->node_bootmem_map = NULL;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700278
Johannes Weiner2e5237d2008-07-23 21:28:02 -0700279 bdebug("nid=%td released=%lx\n", bdata - bootmem_node_data, count);
280
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700281 return count;
282}
283
Jiang Liu7b4b2a02013-07-03 15:03:11 -0700284static int reset_managed_pages_done __initdata;
285
Tang Chenf784a3f2014-11-13 15:19:39 -0800286void reset_node_managed_pages(pg_data_t *pgdat)
Jiang Liu9feedc92012-12-12 13:52:12 -0800287{
288 struct zone *z;
289
Jiang Liu9feedc92012-12-12 13:52:12 -0800290 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
Jiang Liu7b4b2a02013-07-03 15:03:11 -0700291 z->managed_pages = 0;
292}
293
294void __init reset_all_zones_managed_pages(void)
295{
296 struct pglist_data *pgdat;
297
Tang Chenf784a3f2014-11-13 15:19:39 -0800298 if (reset_managed_pages_done)
299 return;
300
Jiang Liu7b4b2a02013-07-03 15:03:11 -0700301 for_each_online_pgdat(pgdat)
302 reset_node_managed_pages(pgdat);
Tang Chenf784a3f2014-11-13 15:19:39 -0800303
Jiang Liu7b4b2a02013-07-03 15:03:11 -0700304 reset_managed_pages_done = 1;
Jiang Liu9feedc92012-12-12 13:52:12 -0800305}
306
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700307unsigned long __init free_all_bootmem(void)
308{
Yinghai Luaa235fc2010-03-31 20:45:27 -0700309 unsigned long total_pages = 0;
310 bootmem_data_t *bdata;
Jiang Liu9feedc92012-12-12 13:52:12 -0800311
Jiang Liu7b4b2a02013-07-03 15:03:11 -0700312 reset_all_zones_managed_pages();
Yinghai Luaa235fc2010-03-31 20:45:27 -0700313
314 list_for_each_entry(bdata, &bdata_list, list)
315 total_pages += free_all_bootmem_core(bdata);
316
Jiang Liu0c988532013-07-03 15:03:24 -0700317 totalram_pages += total_pages;
318
Yinghai Luaa235fc2010-03-31 20:45:27 -0700319 return total_pages;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700320}
321
Johannes Weinerd747fa42008-07-23 21:28:05 -0700322static void __init __free(bootmem_data_t *bdata,
323 unsigned long sidx, unsigned long eidx)
324{
325 unsigned long idx;
326
327 bdebug("nid=%td start=%lx end=%lx\n", bdata - bootmem_node_data,
Johannes Weiner3560e242008-07-23 21:28:09 -0700328 sidx + bdata->node_min_pfn,
329 eidx + bdata->node_min_pfn);
Johannes Weinerd747fa42008-07-23 21:28:05 -0700330
Chris Metcalf1b4ace42015-09-08 15:02:12 -0700331 if (WARN_ON(bdata->node_bootmem_map == NULL))
332 return;
333
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700334 if (bdata->hint_idx > sidx)
335 bdata->hint_idx = sidx;
336
Johannes Weinerd747fa42008-07-23 21:28:05 -0700337 for (idx = sidx; idx < eidx; idx++)
338 if (!test_and_clear_bit(idx, bdata->node_bootmem_map))
339 BUG();
340}
341
342static int __init __reserve(bootmem_data_t *bdata, unsigned long sidx,
343 unsigned long eidx, int flags)
344{
345 unsigned long idx;
346 int exclusive = flags & BOOTMEM_EXCLUSIVE;
347
348 bdebug("nid=%td start=%lx end=%lx flags=%x\n",
349 bdata - bootmem_node_data,
Johannes Weiner3560e242008-07-23 21:28:09 -0700350 sidx + bdata->node_min_pfn,
351 eidx + bdata->node_min_pfn,
Johannes Weinerd747fa42008-07-23 21:28:05 -0700352 flags);
353
Chris Metcalf1b4ace42015-09-08 15:02:12 -0700354 if (WARN_ON(bdata->node_bootmem_map == NULL))
355 return 0;
356
Johannes Weinerd747fa42008-07-23 21:28:05 -0700357 for (idx = sidx; idx < eidx; idx++)
358 if (test_and_set_bit(idx, bdata->node_bootmem_map)) {
359 if (exclusive) {
360 __free(bdata, sidx, idx);
361 return -EBUSY;
362 }
363 bdebug("silent double reserve of PFN %lx\n",
Johannes Weiner3560e242008-07-23 21:28:09 -0700364 idx + bdata->node_min_pfn);
Johannes Weinerd747fa42008-07-23 21:28:05 -0700365 }
366 return 0;
367}
368
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700369static int __init mark_bootmem_node(bootmem_data_t *bdata,
370 unsigned long start, unsigned long end,
371 int reserve, int flags)
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700372{
373 unsigned long sidx, eidx;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700374
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700375 bdebug("nid=%td start=%lx end=%lx reserve=%d flags=%x\n",
376 bdata - bootmem_node_data, start, end, reserve, flags);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700377
Johannes Weiner3560e242008-07-23 21:28:09 -0700378 BUG_ON(start < bdata->node_min_pfn);
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700379 BUG_ON(end > bdata->node_low_pfn);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700380
Johannes Weiner3560e242008-07-23 21:28:09 -0700381 sidx = start - bdata->node_min_pfn;
382 eidx = end - bdata->node_min_pfn;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700383
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700384 if (reserve)
385 return __reserve(bdata, sidx, eidx, flags);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700386 else
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700387 __free(bdata, sidx, eidx);
388 return 0;
389}
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700390
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700391static int __init mark_bootmem(unsigned long start, unsigned long end,
392 int reserve, int flags)
393{
394 unsigned long pos;
395 bootmem_data_t *bdata;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700396
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700397 pos = start;
398 list_for_each_entry(bdata, &bdata_list, list) {
399 int err;
400 unsigned long max;
401
Johannes Weiner3560e242008-07-23 21:28:09 -0700402 if (pos < bdata->node_min_pfn ||
403 pos >= bdata->node_low_pfn) {
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700404 BUG_ON(pos != start);
405 continue;
406 }
407
408 max = min(bdata->node_low_pfn, end);
409
410 err = mark_bootmem_node(bdata, pos, max, reserve, flags);
411 if (reserve && err) {
412 mark_bootmem(start, pos, 0, 0);
413 return err;
414 }
415
416 if (max == end)
417 return 0;
418 pos = bdata->node_low_pfn;
419 }
420 BUG();
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700421}
422
423void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
424 unsigned long size)
425{
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700426 unsigned long start, end;
427
Catalin Marinas9099dae2016-10-11 13:55:11 -0700428 kmemleak_free_part_phys(physaddr, size);
Catalin Marinasec3a3542009-07-07 10:33:01 +0100429
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700430 start = PFN_UP(physaddr);
431 end = PFN_DOWN(physaddr + size);
432
433 mark_bootmem_node(pgdat->bdata, start, end, 0, 0);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700434}
435
Joonsoo Kim81df9bf2012-12-11 16:03:10 -0800436void __init free_bootmem(unsigned long physaddr, unsigned long size)
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700437{
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700438 unsigned long start, end;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700439
Catalin Marinas9099dae2016-10-11 13:55:11 -0700440 kmemleak_free_part_phys(physaddr, size);
Catalin Marinasec3a3542009-07-07 10:33:01 +0100441
Joonsoo Kim81df9bf2012-12-11 16:03:10 -0800442 start = PFN_UP(physaddr);
443 end = PFN_DOWN(physaddr + size);
Yinghai Lua5645a62008-03-18 12:49:12 -0700444
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700445 mark_bootmem(start, end, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700448/**
449 * reserve_bootmem_node - mark a page range as reserved
450 * @pgdat: node the range resides on
451 * @physaddr: starting address of the range
452 * @size: size of the range in bytes
453 * @flags: reservation flags (see linux/bootmem.h)
454 *
455 * Partial pages will be reserved.
456 *
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700457 * The range must reside completely on the specified node.
Mike Rapoport7c757202018-06-30 17:54:58 +0300458 *
459 * Return: 0 on success, -errno on failure.
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700460 */
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700461int __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
462 unsigned long size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700464 unsigned long start, end;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700465
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700466 start = PFN_DOWN(physaddr);
467 end = PFN_UP(physaddr + size);
468
469 return mark_bootmem_node(pgdat->bdata, start, end, 1, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700472/**
Javi Merino0d4ba4d2012-08-24 18:09:31 +0100473 * reserve_bootmem - mark a page range as reserved
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700474 * @addr: starting address of the range
475 * @size: size of the range in bytes
476 * @flags: reservation flags (see linux/bootmem.h)
477 *
478 * Partial pages will be reserved.
479 *
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700480 * The range must be contiguous but may span node boundaries.
Mike Rapoport7c757202018-06-30 17:54:58 +0300481 *
482 * Return: 0 on success, -errno on failure.
Johannes Weinera66fd7d2008-07-23 21:28:01 -0700483 */
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700484int __init reserve_bootmem(unsigned long addr, unsigned long size,
485 int flags)
486{
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700487 unsigned long start, end;
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700488
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700489 start = PFN_DOWN(addr);
490 end = PFN_UP(addr + size);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700491
Johannes Weinere2bf3ca2008-07-23 21:28:06 -0700492 return mark_bootmem(start, end, 1, flags);
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700493}
Johannes Weiner223e8dc2008-07-23 21:28:00 -0700494
Jan Beulich8aa043d2009-12-14 17:59:46 -0800495static unsigned long __init align_idx(struct bootmem_data *bdata,
496 unsigned long idx, unsigned long step)
Johannes Weiner481ebd02008-08-20 14:09:15 -0700497{
498 unsigned long base = bdata->node_min_pfn;
499
500 /*
501 * Align the index with respect to the node start so that the
502 * combination of both satisfies the requested alignment.
503 */
504
505 return ALIGN(base + idx, step) - base;
506}
507
Jan Beulich8aa043d2009-12-14 17:59:46 -0800508static unsigned long __init align_off(struct bootmem_data *bdata,
509 unsigned long off, unsigned long align)
Johannes Weiner481ebd02008-08-20 14:09:15 -0700510{
511 unsigned long base = PFN_PHYS(bdata->node_min_pfn);
512
513 /* Same as align_idx for byte offsets */
514
515 return ALIGN(base + off, align) - base;
516}
517
Johannes Weinerc6785b62012-05-29 15:06:33 -0700518static void * __init alloc_bootmem_bdata(struct bootmem_data *bdata,
Tejun Heod0c4f572009-03-01 16:06:56 +0900519 unsigned long size, unsigned long align,
520 unsigned long goal, unsigned long limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700522 unsigned long fallback = 0;
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700523 unsigned long min, max, start, sidx, midx, step;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Johannes Weiner594fe1a2009-01-06 14:40:32 -0800525 bdebug("nid=%td size=%lx [%lu pages] align=%lx goal=%lx limit=%lx\n",
526 bdata - bootmem_node_data, size, PAGE_ALIGN(size) >> PAGE_SHIFT,
527 align, goal, limit);
528
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700529 BUG_ON(!size);
530 BUG_ON(align & (align - 1));
531 BUG_ON(limit && goal + size > limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Christian Krafft7c309a62006-12-06 20:32:41 -0800533 if (!bdata->node_bootmem_map)
534 return NULL;
535
Johannes Weiner3560e242008-07-23 21:28:09 -0700536 min = bdata->node_min_pfn;
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700537 max = bdata->node_low_pfn;
Yinghai Lu9a2dc042008-03-18 12:44:48 -0700538
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700539 goal >>= PAGE_SHIFT;
540 limit >>= PAGE_SHIFT;
541
542 if (limit && max > limit)
543 max = limit;
544 if (max <= min)
Yinghai Lu9a2dc042008-03-18 12:44:48 -0700545 return NULL;
546
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700547 step = max(align >> PAGE_SHIFT, 1UL);
Yasunori Goto281dd252005-10-19 15:52:18 -0700548
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700549 if (goal && min < goal && goal < max)
550 start = ALIGN(goal, step);
551 else
552 start = ALIGN(min, step);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Johannes Weiner481ebd02008-08-20 14:09:15 -0700554 sidx = start - bdata->node_min_pfn;
Johannes Weiner3560e242008-07-23 21:28:09 -0700555 midx = max - bdata->node_min_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700557 if (bdata->hint_idx > sidx) {
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700558 /*
559 * Handle the valid case of sidx being zero and still
560 * catch the fallback below.
561 */
562 fallback = sidx + 1;
Johannes Weiner481ebd02008-08-20 14:09:15 -0700563 sidx = align_idx(bdata, bdata->hint_idx, step);
Yinghai Luad093152008-03-10 23:23:42 -0700564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700566 while (1) {
567 int merge;
568 void *region;
569 unsigned long eidx, i, start_off, end_off;
570find_block:
571 sidx = find_next_zero_bit(bdata->node_bootmem_map, midx, sidx);
Johannes Weiner481ebd02008-08-20 14:09:15 -0700572 sidx = align_idx(bdata, sidx, step);
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700573 eidx = sidx + PFN_UP(size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700575 if (sidx >= midx || eidx > midx)
Haren Myneni66d43e92005-12-12 00:37:39 -0800576 break;
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700577
578 for (i = sidx; i < eidx; i++)
579 if (test_bit(i, bdata->node_bootmem_map)) {
Johannes Weiner481ebd02008-08-20 14:09:15 -0700580 sidx = align_idx(bdata, i, step);
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700581 if (sidx == i)
582 sidx += step;
583 goto find_block;
584 }
585
Mikulas Patocka627240a2008-08-15 00:40:17 -0700586 if (bdata->last_end_off & (PAGE_SIZE - 1) &&
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700587 PFN_DOWN(bdata->last_end_off) + 1 == sidx)
Johannes Weiner481ebd02008-08-20 14:09:15 -0700588 start_off = align_off(bdata, bdata->last_end_off, align);
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700589 else
590 start_off = PFN_PHYS(sidx);
591
592 merge = PFN_DOWN(start_off) < sidx;
593 end_off = start_off + size;
594
595 bdata->last_end_off = end_off;
596 bdata->hint_idx = PFN_UP(end_off);
597
598 /*
599 * Reserve the area now:
600 */
Johannes Weinerd747fa42008-07-23 21:28:05 -0700601 if (__reserve(bdata, PFN_DOWN(start_off) + merge,
602 PFN_UP(end_off), BOOTMEM_EXCLUSIVE))
603 BUG();
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700604
Johannes Weiner3560e242008-07-23 21:28:09 -0700605 region = phys_to_virt(PFN_PHYS(bdata->node_min_pfn) +
606 start_off);
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700607 memset(region, 0, size);
Catalin Marinas008139d2009-08-27 14:29:17 +0100608 /*
609 * The min_count is set to 0 so that bootmem allocated blocks
610 * are never reported as leaks.
611 */
612 kmemleak_alloc(region, size, 0, 0);
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700613 return region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700616 if (fallback) {
Johannes Weiner481ebd02008-08-20 14:09:15 -0700617 sidx = align_idx(bdata, fallback - 1, step);
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700618 fallback = 0;
619 goto find_block;
620 }
621
622 return NULL;
623}
624
Johannes Weinerc12ab502012-05-29 15:06:33 -0700625static void * __init alloc_bootmem_core(unsigned long size,
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700626 unsigned long align,
627 unsigned long goal,
628 unsigned long limit)
629{
630 bootmem_data_t *bdata;
Tejun Heod0c4f572009-03-01 16:06:56 +0900631 void *region;
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700632
Joonsoo Kim3f7dfe22012-12-12 13:50:43 -0800633 if (WARN_ON_ONCE(slab_is_available()))
634 return kzalloc(size, GFP_NOWAIT);
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700635
Tejun Heod0c4f572009-03-01 16:06:56 +0900636 list_for_each_entry(bdata, &bdata_list, list) {
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700637 if (goal && bdata->node_low_pfn <= PFN_DOWN(goal))
638 continue;
Johannes Weiner3560e242008-07-23 21:28:09 -0700639 if (limit && bdata->node_min_pfn >= PFN_DOWN(limit))
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700640 break;
641
Johannes Weinerc6785b62012-05-29 15:06:33 -0700642 region = alloc_bootmem_bdata(bdata, size, align, goal, limit);
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700643 if (region)
644 return region;
645 }
646
Johannes Weinerc12ab502012-05-29 15:06:33 -0700647 return NULL;
648}
649
650static void * __init ___alloc_bootmem_nopanic(unsigned long size,
651 unsigned long align,
652 unsigned long goal,
653 unsigned long limit)
654{
655 void *ptr;
656
657restart:
658 ptr = alloc_bootmem_core(size, align, goal, limit);
659 if (ptr)
660 return ptr;
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700661 if (goal) {
662 goal = 0;
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700663 goto restart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
Johannes Weiner5f2809e2008-07-23 21:28:05 -0700665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700669void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700670 unsigned long goal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
Yinghai Lu08677212010-02-10 01:20:20 -0800672 unsigned long limit = 0;
673
Yinghai Lu08677212010-02-10 01:20:20 -0800674 return ___alloc_bootmem_nopanic(size, align, goal, limit);
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700675}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700677static void * __init ___alloc_bootmem(unsigned long size, unsigned long align,
678 unsigned long goal, unsigned long limit)
679{
680 void *mem = ___alloc_bootmem_nopanic(size, align, goal, limit);
681
682 if (mem)
683 return mem;
684 /*
685 * Whoops, we cannot satisfy the allocation request.
686 */
Joe Perches11705322016-03-17 14:19:50 -0700687 pr_alert("bootmem alloc of %lu bytes failed!\n", size);
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700688 panic("Out of memory");
Andi Kleena8062232006-04-07 19:49:21 +0200689 return NULL;
690}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700692void * __init __alloc_bootmem(unsigned long size, unsigned long align,
693 unsigned long goal)
Andi Kleena8062232006-04-07 19:49:21 +0200694{
Yinghai Lu08677212010-02-10 01:20:20 -0800695 unsigned long limit = 0;
696
Yinghai Lu08677212010-02-10 01:20:20 -0800697 return ___alloc_bootmem(size, align, goal, limit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}
699
Yinghai Lu99ab7b12012-07-11 14:02:53 -0700700void * __init ___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
Johannes Weiner4cc278b2008-07-23 21:28:08 -0700701 unsigned long size, unsigned long align,
702 unsigned long goal, unsigned long limit)
703{
704 void *ptr;
705
Joonsoo Kim3f7dfe22012-12-12 13:50:43 -0800706 if (WARN_ON_ONCE(slab_is_available()))
zijun_hu1d8bf922016-10-07 16:59:27 -0700707 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
Johannes Weinerab381842012-05-29 15:06:34 -0700708again:
Tejun Heod0c4f572009-03-01 16:06:56 +0900709
Yinghai Luc8f4a2d2012-07-17 15:47:51 -0700710 /* do not panic in alloc_bootmem_bdata() */
711 if (limit && goal + size > limit)
712 limit = 0;
713
Johannes Weinere9079912012-05-29 15:06:36 -0700714 ptr = alloc_bootmem_bdata(pgdat->bdata, size, align, goal, limit);
Johannes Weiner4cc278b2008-07-23 21:28:08 -0700715 if (ptr)
716 return ptr;
717
Johannes Weinerab381842012-05-29 15:06:34 -0700718 ptr = alloc_bootmem_core(size, align, goal, limit);
719 if (ptr)
720 return ptr;
721
722 if (goal) {
723 goal = 0;
724 goto again;
725 }
726
Johannes Weiner421456e2012-05-29 15:06:34 -0700727 return NULL;
728}
729
730void * __init __alloc_bootmem_node_nopanic(pg_data_t *pgdat, unsigned long size,
731 unsigned long align, unsigned long goal)
732{
Johannes Weinere9079912012-05-29 15:06:36 -0700733 return ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0);
Johannes Weiner421456e2012-05-29 15:06:34 -0700734}
735
Johannes Weinere9079912012-05-29 15:06:36 -0700736void * __init ___alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
Johannes Weiner421456e2012-05-29 15:06:34 -0700737 unsigned long align, unsigned long goal,
738 unsigned long limit)
739{
740 void *ptr;
741
Johannes Weinere9079912012-05-29 15:06:36 -0700742 ptr = ___alloc_bootmem_node_nopanic(pgdat, size, align, goal, 0);
Johannes Weiner421456e2012-05-29 15:06:34 -0700743 if (ptr)
744 return ptr;
745
Joe Perches11705322016-03-17 14:19:50 -0700746 pr_alert("bootmem alloc of %lu bytes failed!\n", size);
Johannes Weinerab381842012-05-29 15:06:34 -0700747 panic("Out of memory");
748 return NULL;
Johannes Weiner4cc278b2008-07-23 21:28:08 -0700749}
750
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700751void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
752 unsigned long align, unsigned long goal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753{
Pekka Enbergc91c4772009-06-11 08:10:28 +0300754 if (WARN_ON_ONCE(slab_is_available()))
755 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
756
Johannes Weinere9079912012-05-29 15:06:36 -0700757 return ___alloc_bootmem_node(pgdat, size, align, goal, 0);
Yinghai Lu08677212010-02-10 01:20:20 -0800758}
759
760void * __init __alloc_bootmem_node_high(pg_data_t *pgdat, unsigned long size,
761 unsigned long align, unsigned long goal)
762{
763#ifdef MAX_DMA32_PFN
764 unsigned long end_pfn;
765
766 if (WARN_ON_ONCE(slab_is_available()))
767 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
768
769 /* update goal according ...MAX_DMA32_PFN */
Xishi Qiu83285c72013-11-12 15:07:19 -0800770 end_pfn = pgdat_end_pfn(pgdat);
Yinghai Lu08677212010-02-10 01:20:20 -0800771
772 if (end_pfn > MAX_DMA32_PFN + (128 >> (20 - PAGE_SHIFT)) &&
773 (goal >> PAGE_SHIFT) < MAX_DMA32_PFN) {
774 void *ptr;
775 unsigned long new_goal;
776
777 new_goal = MAX_DMA32_PFN << PAGE_SHIFT;
Johannes Weinerc6785b62012-05-29 15:06:33 -0700778 ptr = alloc_bootmem_bdata(pgdat->bdata, size, align,
Yinghai Lu08677212010-02-10 01:20:20 -0800779 new_goal, 0);
Yinghai Lu08677212010-02-10 01:20:20 -0800780 if (ptr)
781 return ptr;
782 }
783#endif
784
785 return __alloc_bootmem_node(pgdat, size, align, goal);
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787}
788
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700789void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
790 unsigned long goal)
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800791{
Johannes Weiner0f3caba2008-07-23 21:28:07 -0700792 return ___alloc_bootmem(size, align, goal, ARCH_LOW_ADDRESS_LIMIT);
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800793}
794
Yinghai Lu38fa4172013-01-24 12:20:15 -0800795void * __init __alloc_bootmem_low_nopanic(unsigned long size,
796 unsigned long align,
797 unsigned long goal)
798{
799 return ___alloc_bootmem_nopanic(size, align, goal,
800 ARCH_LOW_ADDRESS_LIMIT);
801}
802
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800803void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size,
804 unsigned long align, unsigned long goal)
805{
Pekka Enbergc91c4772009-06-11 08:10:28 +0300806 if (WARN_ON_ONCE(slab_is_available()))
807 return kzalloc_node(size, GFP_NOWAIT, pgdat->node_id);
808
Johannes Weinere9079912012-05-29 15:06:36 -0700809 return ___alloc_bootmem_node(pgdat, size, align,
810 goal, ARCH_LOW_ADDRESS_LIMIT);
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800811}