Lines Matching +full:reserved +full:- +full:memory

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Procedures for maintaining information about logical memory blocks.
39 * Memblock is a method of managing memory regions during the early
40 * boot period when the usual kernel memory allocators are not up and
43 * Memblock views the system memory as collections of contiguous
46 * * ``memory`` - describes the physical memory available to the
47 * kernel; this may differ from the actual physical memory installed
48 * in the system, for instance when the memory is restricted with
50 * * ``reserved`` - describes the regions that were allocated
51 * * ``physmem`` - describes the actual physical memory available during
52 * boot regardless of the possible restrictions and memory hot(un)plug;
57 * systems. Every memory type is described by the struct memblock_type
58 * which contains an array of memory regions along with
59 * the allocator metadata. The "memory" and "reserved" types are nicely
62 * %INIT_MEMBLOCK_MEMORY_REGIONS for "memory" and
63 * %INIT_MEMBLOCK_RESERVED_REGIONS for "reserved". The region array
67 * with care so that memory allocated for the region array will not
68 * overlap with areas that should be reserved, for example initrd.
71 * memory layout is by using memblock_add() or memblock_add_node()
78 * Once memblock is setup the memory can be allocated using one of the
81 * * memblock_phys_alloc*() - these functions return the **physical**
82 * address of the allocated memory
83 * * memblock_alloc*() - these functions return the **virtual** address
84 * of the allocated memory.
87 * memory ranges and the fallback methods. Consult the documentation
92 * function frees all the memory to the buddy page allocator.
116 .memory.regions = memblock_memory_init_regions,
117 .memory.cnt = 1, /* empty dummy entry */
118 .memory.max = INIT_MEMBLOCK_MEMORY_REGIONS,
119 .memory.name = "memory",
121 .reserved.regions = memblock_reserved_init_regions,
122 .reserved.cnt = 1, /* empty dummy entry */
123 .reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS,
124 .reserved.name = "reserved",
140 * keep a pointer to &memblock.memory in the text section to use it in
145 static __refdata struct memblock_type *memblock_memory = &memblock.memory;
148 for (i = 0, rgn = &memblock_type->regions[0]; \
149 i < memblock_type->cnt; \
150 i++, rgn = &memblock_type->regions[i])
172 return *size = min(*size, PHYS_ADDR_MAX - base); in memblock_cap_size()
191 for (i = 0; i < type->cnt; i++) in memblock_overlaps_region()
192 if (memblock_addrs_overlap(base, size, type->regions[i].base, in memblock_overlaps_region()
193 type->regions[i].size)) in memblock_overlaps_region()
195 return i < type->cnt; in memblock_overlaps_region()
199 * __memblock_find_range_bottom_up - find free area utility in bottom-up
206 * @flags: pick from blocks based on memory attributes
208 * Utility called from memblock_find_in_range_node(), find free area bottom-up.
226 if (cand < this_end && this_end - cand >= size) in __memblock_find_range_bottom_up()
234 * __memblock_find_range_top_down - find free area utility, in top-down
241 * @flags: pick from blocks based on memory attributes
243 * Utility called from memblock_find_in_range_node(), find free area top-down.
264 cand = round_down(this_end - size, align); in __memblock_find_range_top_down()
273 * memblock_find_in_range_node - find free area in given range and node
280 * @flags: pick from blocks based on memory attributes
310 * memblock_find_in_range - find free area in given range
334 pr_warn_ratelimited("Could not allocate %pap bytes of mirrored memory\n", in memblock_find_in_range()
345 type->total_size -= type->regions[r].size; in memblock_remove_region()
346 memmove(&type->regions[r], &type->regions[r + 1], in memblock_remove_region()
347 (type->cnt - (r + 1)) * sizeof(type->regions[r])); in memblock_remove_region()
348 type->cnt--; in memblock_remove_region()
351 if (type->cnt == 0) { in memblock_remove_region()
352 WARN_ON(type->total_size != 0); in memblock_remove_region()
353 type->cnt = 1; in memblock_remove_region()
354 type->regions[0].base = 0; in memblock_remove_region()
355 type->regions[0].size = 0; in memblock_remove_region()
356 type->regions[0].flags = 0; in memblock_remove_region()
357 memblock_set_region_node(&type->regions[0], MAX_NUMNODES); in memblock_remove_region()
363 * memblock_discard - discard memory and reserved arrays if they were allocated
369 if (memblock.reserved.regions != memblock_reserved_init_regions) { in memblock_discard()
370 addr = __pa(memblock.reserved.regions); in memblock_discard()
372 memblock.reserved.max); in memblock_discard()
374 kfree(memblock.reserved.regions); in memblock_discard()
379 if (memblock.memory.regions != memblock_memory_init_regions) { in memblock_discard()
380 addr = __pa(memblock.memory.regions); in memblock_discard()
382 memblock.memory.max); in memblock_discard()
384 kfree(memblock.memory.regions); in memblock_discard()
394 * memblock_double_array - double the size of the memblock regions array
396 * @new_area_start: starting address of memory range to avoid overlap with
397 * @new_area_size: size of memory range to avoid overlap with
400 * allocate memory for a new reserved regions array and there is a previously
401 * allocated memory range [@new_area_start, @new_area_start + @new_area_size]
402 * waiting to be reserved, ensure the memory used by the new array does
406 * 0 on success, -1 on failure.
418 /* We don't allow resizing until we know about the reserved regions in memblock_double_array()
419 * of memory that aren't suitable for allocation in memblock_double_array()
422 return -1; in memblock_double_array()
425 old_size = type->max * sizeof(struct memblock_region); in memblock_double_array()
435 if (type == &memblock.memory) in memblock_double_array()
445 /* only exclude range when trying to double reserved.regions */ in memblock_double_array()
446 if (type != &memblock.reserved) in memblock_double_array()
461 type->name, type->max, type->max * 2); in memblock_double_array()
462 return -1; in memblock_double_array()
465 new_end = addr + new_size - 1; in memblock_double_array()
466 memblock_dbg("memblock: %s is doubled to %ld at [%pa-%pa]", in memblock_double_array()
467 type->name, type->max * 2, &addr, &new_end); in memblock_double_array()
471 * reserved region since it may be our reserved array itself that is in memblock_double_array()
474 memcpy(new_array, type->regions, old_size); in memblock_double_array()
475 memset(new_array + type->max, 0, old_size); in memblock_double_array()
476 old_array = type->regions; in memblock_double_array()
477 type->regions = new_array; in memblock_double_array()
478 type->max <<= 1; in memblock_double_array()
501 * memblock_merge_regions - merge neighboring compatible regions
511 while (i < type->cnt - 1) { in memblock_merge_regions()
512 struct memblock_region *this = &type->regions[i]; in memblock_merge_regions()
513 struct memblock_region *next = &type->regions[i + 1]; in memblock_merge_regions()
515 if (this->base + this->size != next->base || in memblock_merge_regions()
518 this->flags != next->flags) { in memblock_merge_regions()
519 BUG_ON(this->base + this->size > next->base); in memblock_merge_regions()
524 this->size += next->size; in memblock_merge_regions()
526 memmove(next, next + 1, (type->cnt - (i + 2)) * sizeof(*next)); in memblock_merge_regions()
527 type->cnt--; in memblock_merge_regions()
532 * memblock_insert_region - insert new memblock region
549 struct memblock_region *rgn = &type->regions[idx]; in memblock_insert_region()
551 BUG_ON(type->cnt >= type->max); in memblock_insert_region()
552 memmove(rgn + 1, rgn, (type->cnt - idx) * sizeof(*rgn)); in memblock_insert_region()
553 rgn->base = base; in memblock_insert_region()
554 rgn->size = size; in memblock_insert_region()
555 rgn->flags = flags; in memblock_insert_region()
557 type->cnt++; in memblock_insert_region()
558 type->total_size += size; in memblock_insert_region()
562 * memblock_add_range - add new memblock region
570 * is allowed to overlap with existing ones - overlaps don't affect already
575 * 0 on success, -errno on failure.
591 if (type->regions[0].size == 0) { in memblock_add_range()
592 WARN_ON(type->cnt != 1 || type->total_size); in memblock_add_range()
593 type->regions[0].base = base; in memblock_add_range()
594 type->regions[0].size = size; in memblock_add_range()
595 type->regions[0].flags = flags; in memblock_add_range()
596 memblock_set_region_node(&type->regions[0], nid); in memblock_add_range()
597 type->total_size = size; in memblock_add_range()
603 * then we'll need type->cnt + 1 empty regions in @type. So if in memblock_add_range()
604 * type->cnt * 2 + 1 is less than type->max, we know in memblock_add_range()
608 if (type->cnt * 2 + 1 < type->max) in memblock_add_range()
621 phys_addr_t rbase = rgn->base; in memblock_add_range()
622 phys_addr_t rend = rbase + rgn->size; in memblock_add_range()
636 WARN_ON(flags != rgn->flags); in memblock_add_range()
640 rbase - base, nid, in memblock_add_range()
651 memblock_insert_region(type, idx, base, end - base, in memblock_add_range()
663 while (type->cnt + nr_new > type->max) in memblock_add_range()
665 return -ENOMEM; in memblock_add_range()
675 * memblock_add_node - add new memblock region within a NUMA node
681 * Add new memblock region [@base, @base + @size) to the "memory"
685 * 0 on success, -errno on failure.
690 phys_addr_t end = base + size - 1; in memblock_add_node()
692 memblock_dbg("%s: [%pa-%pa] nid=%d flags=%x %pS\n", __func__, in memblock_add_node()
695 return memblock_add_range(&memblock.memory, base, size, nid, flags); in memblock_add_node()
699 * memblock_add - add new memblock region
703 * Add new memblock region [@base, @base + @size) to the "memory"
707 * 0 on success, -errno on failure.
711 phys_addr_t end = base + size - 1; in memblock_add()
713 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_add()
716 return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0); in memblock_add()
720 * memblock_isolate_range - isolate given range into disjoint memblocks
733 * 0 on success, -errno on failure.
749 while (type->cnt + 2 > type->max) in memblock_isolate_range()
751 return -ENOMEM; in memblock_isolate_range()
754 phys_addr_t rbase = rgn->base; in memblock_isolate_range()
755 phys_addr_t rend = rbase + rgn->size; in memblock_isolate_range()
765 * to process the next region - the new top half. in memblock_isolate_range()
767 rgn->base = base; in memblock_isolate_range()
768 rgn->size -= base - rbase; in memblock_isolate_range()
769 type->total_size -= base - rbase; in memblock_isolate_range()
770 memblock_insert_region(type, idx, rbase, base - rbase, in memblock_isolate_range()
772 rgn->flags); in memblock_isolate_range()
776 * current region - the new bottom half. in memblock_isolate_range()
778 rgn->base = end; in memblock_isolate_range()
779 rgn->size -= end - rbase; in memblock_isolate_range()
780 type->total_size -= end - rbase; in memblock_isolate_range()
781 memblock_insert_region(type, idx--, rbase, end - rbase, in memblock_isolate_range()
783 rgn->flags); in memblock_isolate_range()
805 for (i = end_rgn - 1; i >= start_rgn; i--) in memblock_remove_range()
812 phys_addr_t end = base + size - 1; in memblock_remove()
814 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_remove()
817 return memblock_remove_range(&memblock.memory, base, size); in memblock_remove()
821 * memblock_free - free boot memory allocation
822 * @ptr: starting address of the boot memory allocation
823 * @size: size of the boot memory block in bytes
825 * Free boot memory block previously allocated by memblock_alloc_xx() API.
826 * The freeing memory will not be released to the buddy allocator.
835 * memblock_phys_free - free boot memory block
836 * @base: phys starting address of the boot memory block
837 * @size: size of the boot memory block in bytes
839 * Free boot memory block previously allocated by memblock_alloc_xx() API.
840 * The freeing memory will not be released to the buddy allocator.
844 phys_addr_t end = base + size - 1; in memblock_phys_free()
846 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_phys_free()
850 return memblock_remove_range(&memblock.reserved, base, size); in memblock_phys_free()
855 phys_addr_t end = base + size - 1; in memblock_reserve()
857 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_reserve()
860 return memblock_add_range(&memblock.reserved, base, size, MAX_NUMNODES, 0); in memblock_reserve()
866 phys_addr_t end = base + size - 1; in memblock_physmem_add()
868 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_physmem_add()
876 * memblock_setclr_flag - set or clear flag for a memory region
884 * Return: 0 on success, -errno on failure.
889 struct memblock_type *type = &memblock.memory; in memblock_setclr_flag()
897 struct memblock_region *r = &type->regions[i]; in memblock_setclr_flag()
900 r->flags |= flag; in memblock_setclr_flag()
902 r->flags &= ~flag; in memblock_setclr_flag()
910 * memblock_mark_hotplug - Mark hotpluggable memory with flag MEMBLOCK_HOTPLUG.
914 * Return: 0 on success, -errno on failure.
922 * memblock_clear_hotplug - Clear flag MEMBLOCK_HOTPLUG for a specified region.
926 * Return: 0 on success, -errno on failure.
934 * memblock_mark_mirror - Mark mirrored memory with flag MEMBLOCK_MIRROR.
938 * Return: 0 on success, -errno on failure.
951 * memblock_mark_nomap - Mark a memory region with flag MEMBLOCK_NOMAP.
955 * The memory regions marked with %MEMBLOCK_NOMAP will not be added to the
956 * direct mapping of the physical memory. These regions will still be
957 * covered by the memory map. The struct page representing NOMAP memory
958 * frames in the memory map will be PageReserved()
960 * Note: if the memory being marked %MEMBLOCK_NOMAP was allocated from
961 * memblock, the caller must inform kmemleak to ignore that memory
963 * Return: 0 on success, -errno on failure.
971 * memblock_clear_nomap - Clear flag MEMBLOCK_NOMAP for a specified region.
975 * Return: 0 on success, -errno on failure.
988 /* we never skip regions when iterating memblock.reserved or physmem */ in should_skip_region()
992 /* only memory regions are associated with nodes, check it */ in should_skip_region()
996 /* skip hotpluggable memory regions if needed */ in should_skip_region()
1001 /* if we want mirror memory skip non-mirror memory regions */ in should_skip_region()
1005 /* skip nomap memory unless we were asked for it explicitly */ in should_skip_region()
1009 /* skip driver-managed memory unless we were asked for it explicitly */ in should_skip_region()
1017 * __next_mem_range - next function for for_each_free_mem_range() etc.
1020 * @flags: pick from blocks based on memory attributes
1022 * @type_b: pointer to memblock_type which excludes memory from being taken
1033 * 0:[0-16), 1:[32-48), 2:[128-130)
1037 * 0:[0-0), 1:[16-32), 2:[48-128), 3:[130-MAX)
1054 for (; idx_a < type_a->cnt; idx_a++) { in __next_mem_range()
1055 struct memblock_region *m = &type_a->regions[idx_a]; in __next_mem_range()
1057 phys_addr_t m_start = m->base; in __next_mem_range()
1058 phys_addr_t m_end = m->base + m->size; in __next_mem_range()
1077 for (; idx_b < type_b->cnt + 1; idx_b++) { in __next_mem_range()
1082 r = &type_b->regions[idx_b]; in __next_mem_range()
1083 r_start = idx_b ? r[-1].base + r[-1].size : 0; in __next_mem_range()
1084 r_end = idx_b < type_b->cnt ? in __next_mem_range()
1085 r->base : PHYS_ADDR_MAX; in __next_mem_range()
1121 * __next_mem_range_rev - generic next function for for_each_*_range_rev()
1125 * @flags: pick from blocks based on memory attributes
1127 * @type_b: pointer to memblock_type which excludes memory from being taken
1151 idx_a = type_a->cnt - 1; in __next_mem_range_rev()
1153 idx_b = type_b->cnt; in __next_mem_range_rev()
1158 for (; idx_a >= 0; idx_a--) { in __next_mem_range_rev()
1159 struct memblock_region *m = &type_a->regions[idx_a]; in __next_mem_range_rev()
1161 phys_addr_t m_start = m->base; in __next_mem_range_rev()
1162 phys_addr_t m_end = m->base + m->size; in __next_mem_range_rev()
1175 idx_a--; in __next_mem_range_rev()
1181 for (; idx_b >= 0; idx_b--) { in __next_mem_range_rev()
1186 r = &type_b->regions[idx_b]; in __next_mem_range_rev()
1187 r_start = idx_b ? r[-1].base + r[-1].size : 0; in __next_mem_range_rev()
1188 r_end = idx_b < type_b->cnt ? in __next_mem_range_rev()
1189 r->base : PHYS_ADDR_MAX; in __next_mem_range_rev()
1206 idx_a--; in __next_mem_range_rev()
1208 idx_b--; in __next_mem_range_rev()
1225 struct memblock_type *type = &memblock.memory; in __next_mem_pfn_range()
1229 while (++*idx < type->cnt) { in __next_mem_pfn_range()
1230 r = &type->regions[*idx]; in __next_mem_pfn_range()
1233 if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size)) in __next_mem_pfn_range()
1238 if (*idx >= type->cnt) { in __next_mem_pfn_range()
1239 *idx = -1; in __next_mem_pfn_range()
1244 *out_start_pfn = PFN_UP(r->base); in __next_mem_pfn_range()
1246 *out_end_pfn = PFN_DOWN(r->base + r->size); in __next_mem_pfn_range()
1252 * memblock_set_node - set node ID on memblock regions
1262 * 0 on success, -errno on failure.
1276 memblock_set_region_node(&type->regions[i], nid); in memblock_set_node()
1285 * __next_mem_pfn_range_in_zone - iterator for for_each_*_range_in_zone()
1288 * @zone: zone in which all of the memory blocks reside
1294 * deferred memory init routines and as such we were duplicating much of
1307 &memblock.memory, &memblock.reserved, in __next_mem_pfn_range_in_zone()
1318 if (zone->zone_start_pfn < epfn && spfn < epfn) { in __next_mem_pfn_range_in_zone()
1326 *out_spfn = max(zone->zone_start_pfn, spfn); in __next_mem_pfn_range_in_zone()
1334 &memblock.memory, &memblock.reserved, in __next_mem_pfn_range_in_zone()
1348 * memblock_alloc_range_nid - allocate boot memory block
1349 * @size: size of memory block to be allocated in bytes
1351 * @start: the lower bound of the memory region to allocate (phys address)
1352 * @end: the upper bound of the memory region to allocate (phys address)
1356 * The allocation is performed from memory region limited by
1359 * If the specified node can not hold the requested memory and @exact_nid
1362 * For systems with memory mirroring, the allocation is attempted first
1364 * memory region.
1367 * memory block, it is never reported as leaks.
1370 * Physical address of allocated memory block on success, %0 on failure.
1405 pr_warn_ratelimited("Could not allocate %pap bytes of mirrored memory\n", in memblock_alloc_range_nid()
1430 * memblock_phys_alloc_range - allocate a memory block inside specified range
1431 * @size: size of memory block to be allocated in bytes
1433 * @start: the lower bound of the memory region to allocate (physical address)
1434 * @end: the upper bound of the memory region to allocate (physical address)
1438 * Return: physical address of the allocated memory block on success,
1454 * memblock_phys_alloc_try_nid - allocate a memory block from specified NUMA node
1455 * @size: size of memory block to be allocated in bytes
1459 * Allocates memory block from the specified NUMA node. If the node
1460 * has no available memory, attempts to allocated from any node in the
1463 * Return: physical address of the allocated memory block on success,
1473 * memblock_alloc_internal - allocate boot memory block
1474 * @size: size of memory block to be allocated in bytes
1476 * @min_addr: the lower bound of the memory region to allocate (phys address)
1477 * @max_addr: the upper bound of the memory region to allocate (phys address)
1481 * Allocates memory block using memblock_alloc_range_nid() and
1485 * will fall back to memory below @min_addr. Other constraints, such
1486 * as node and mirrored memory will be handled again in
1490 * Virtual address of allocated memory block on success, NULL on failure.
1525 * memblock_alloc_exact_nid_raw - allocate boot memory block on the exact node
1526 * without zeroing memory
1527 * @size: size of memory block to be allocated in bytes
1529 * @min_addr: the lower bound of the memory region from where the allocation
1531 * @max_addr: the upper bound of the memory region from where the allocation
1533 * allocate only from memory limited by memblock.current_limit value
1537 * info), if enabled. Does not zero allocated memory.
1540 * Virtual address of allocated memory block on success, NULL on failure.
1556 * memblock_alloc_try_nid_raw - allocate boot memory block without zeroing
1557 * memory and without panicking
1558 * @size: size of memory block to be allocated in bytes
1560 * @min_addr: the lower bound of the memory region from where the allocation
1562 * @max_addr: the upper bound of the memory region from where the allocation
1564 * allocate only from memory limited by memblock.current_limit value
1568 * info), if enabled. Does not zero allocated memory, does not panic if request
1572 * Virtual address of allocated memory block on success, NULL on failure.
1588 * memblock_alloc_try_nid - allocate boot memory block
1589 * @size: size of memory block to be allocated in bytes
1591 * @min_addr: the lower bound of the memory region from where the allocation
1593 * @max_addr: the upper bound of the memory region from where the allocation
1595 * allocate only from memory limited by memblock.current_limit value
1599 * info), if enabled. This function zeroes the allocated memory.
1602 * Virtual address of allocated memory block on success, NULL on failure.
1623 * memblock_free_late - free pages directly to buddy allocator
1624 * @base: phys starting address of the boot memory block
1625 * @size: size of the boot memory block in bytes
1635 end = base + size - 1; in memblock_free_late()
1636 memblock_dbg("%s: [%pa-%pa] %pS\n", in memblock_free_late()
1654 return memblock.memory.total_size; in memblock_phys_mem_size()
1659 return memblock.reserved.total_size; in memblock_reserved_size()
1665 return memblock.memory.regions[0].base; in memblock_start_of_DRAM()
1670 int idx = memblock.memory.cnt - 1; in memblock_end_of_DRAM()
1672 return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size); in memblock_end_of_DRAM()
1681 * translate the memory @limit size into the max address within one of in __find_max_addr()
1682 * the memory memblock regions, if the @limit exceeds the total size in __find_max_addr()
1686 if (limit <= r->size) { in __find_max_addr()
1687 max_addr = r->base + limit; in __find_max_addr()
1690 limit -= r->size; in __find_max_addr()
1705 /* @limit exceeds the total size of the memory, do nothing */ in memblock_enforce_memory_limit()
1709 /* truncate both memory and reserved regions */ in memblock_enforce_memory_limit()
1710 memblock_remove_range(&memblock.memory, max_addr, in memblock_enforce_memory_limit()
1712 memblock_remove_range(&memblock.reserved, max_addr, in memblock_enforce_memory_limit()
1724 if (!memblock_memory->total_size) { in memblock_cap_memory_range()
1725 pr_warn("%s: No memory registered yet\n", __func__); in memblock_cap_memory_range()
1729 ret = memblock_isolate_range(&memblock.memory, base, size, in memblock_cap_memory_range()
1735 for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) in memblock_cap_memory_range()
1736 if (!memblock_is_nomap(&memblock.memory.regions[i])) in memblock_cap_memory_range()
1737 memblock_remove_region(&memblock.memory, i); in memblock_cap_memory_range()
1739 for (i = start_rgn - 1; i >= 0; i--) in memblock_cap_memory_range()
1740 if (!memblock_is_nomap(&memblock.memory.regions[i])) in memblock_cap_memory_range()
1741 memblock_remove_region(&memblock.memory, i); in memblock_cap_memory_range()
1743 /* truncate the reserved regions */ in memblock_cap_memory_range()
1744 memblock_remove_range(&memblock.reserved, 0, base); in memblock_cap_memory_range()
1745 memblock_remove_range(&memblock.reserved, in memblock_cap_memory_range()
1758 /* @limit exceeds the total size of the memory, do nothing */ in memblock_mem_limit_remove_map()
1767 unsigned int left = 0, right = type->cnt; in memblock_search()
1772 if (addr < type->regions[mid].base) in memblock_search()
1774 else if (addr >= (type->regions[mid].base + in memblock_search()
1775 type->regions[mid].size)) in memblock_search()
1780 return -1; in memblock_search()
1785 return memblock_search(&memblock.reserved, addr) != -1; in memblock_is_reserved()
1790 return memblock_search(&memblock.memory, addr) != -1; in memblock_is_memory()
1795 int i = memblock_search(&memblock.memory, addr); in memblock_is_map_memory()
1797 if (i == -1) in memblock_is_map_memory()
1799 return !memblock_is_nomap(&memblock.memory.regions[i]); in memblock_is_map_memory()
1805 struct memblock_type *type = &memblock.memory; in memblock_search_pfn_nid()
1808 if (mid == -1) in memblock_search_pfn_nid()
1809 return -1; in memblock_search_pfn_nid()
1811 *start_pfn = PFN_DOWN(type->regions[mid].base); in memblock_search_pfn_nid()
1812 *end_pfn = PFN_DOWN(type->regions[mid].base + type->regions[mid].size); in memblock_search_pfn_nid()
1814 return memblock_get_region_node(&type->regions[mid]); in memblock_search_pfn_nid()
1818 * memblock_is_region_memory - check if a region is a subset of memory
1822 * Check if the region [@base, @base + @size) is a subset of a memory block.
1825 * 0 if false, non-zero if true
1829 int idx = memblock_search(&memblock.memory, base); in memblock_is_region_memory()
1832 if (idx == -1) in memblock_is_region_memory()
1834 return (memblock.memory.regions[idx].base + in memblock_is_region_memory()
1835 memblock.memory.regions[idx].size) >= end; in memblock_is_region_memory()
1839 * memblock_is_region_reserved - check if a region intersects reserved memory
1843 * Check if the region [@base, @base + @size) intersects a reserved
1844 * memory block.
1851 return memblock_overlaps_region(&memblock.reserved, base, size); in memblock_is_region_reserved()
1860 orig_start = r->base; in memblock_trim_memory()
1861 orig_end = r->base + r->size; in memblock_trim_memory()
1869 r->base = start; in memblock_trim_memory()
1870 r->size = end - start; in memblock_trim_memory()
1872 memblock_remove_region(&memblock.memory, in memblock_trim_memory()
1873 r - memblock.memory.regions); in memblock_trim_memory()
1874 r--; in memblock_trim_memory()
1896 pr_info(" %s.cnt = 0x%lx\n", type->name, type->cnt); in memblock_dump()
1901 base = rgn->base; in memblock_dump()
1902 size = rgn->size; in memblock_dump()
1903 end = base + size - 1; in memblock_dump()
1904 flags = rgn->flags; in memblock_dump()
1910 pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n", in memblock_dump()
1911 type->name, idx, &base, &end, &size, nid_buf, flags); in memblock_dump()
1918 pr_info(" memory size = %pa reserved size = %pa\n", in __memblock_dump_all()
1919 &memblock.memory.total_size, in __memblock_dump_all()
1920 &memblock.reserved.total_size); in __memblock_dump_all()
1922 memblock_dump(&memblock.memory); in __memblock_dump_all()
1923 memblock_dump(&memblock.reserved); in __memblock_dump_all()
1956 start_pg = pfn_to_page(start_pfn - 1) + 1; in free_memmap()
1957 end_pg = pfn_to_page(end_pfn - 1) + 1; in free_memmap()
1971 memblock_phys_free(pg, pgend - pg); in free_memmap()
1975 * The mem_map array can get very big. Free the unused area of the memory map.
2000 * presume that there are no holes in the memory map inside in free_unused_memmap()
2014 * presume that there are no holes in the memory map inside in free_unused_memmap()
2033 order = min(MAX_ORDER - 1UL, __ffs(start)); in __free_pages_memory()
2036 order--; in __free_pages_memory()
2056 return end_pfn - start_pfn; in __free_memory_core()
2065 /* initialize struct pages for the reserved regions */ in memmap_init_reserved_pages()
2072 start = region->base; in memmap_init_reserved_pages()
2073 end = start + region->size; in memmap_init_reserved_pages()
2085 memblock_clear_hotplug(0, -1); in free_low_memory_core_early()
2090 * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id in free_low_memory_core_early()
2107 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) in reset_node_managed_pages()
2108 atomic_long_set(&z->managed_pages, 0); in reset_node_managed_pages()
2125 * memblock_free_all - release free pages to the buddy allocator
2142 struct memblock_type *type = m->private; in memblock_debug_show()
2147 for (i = 0; i < type->cnt; i++) { in memblock_debug_show()
2148 reg = &type->regions[i]; in memblock_debug_show()
2149 end = reg->base + reg->size - 1; in memblock_debug_show()
2152 seq_printf(m, "%pa..%pa\n", &reg->base, &end); in memblock_debug_show()
2162 debugfs_create_file("memory", 0444, root, in memblock_init_debugfs()
2163 &memblock.memory, &memblock_debug_fops); in memblock_init_debugfs()
2164 debugfs_create_file("reserved", 0444, root, in memblock_init_debugfs()
2165 &memblock.reserved, &memblock_debug_fops); in memblock_init_debugfs()