Lines Matching +full:memory +full:- +full:region

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Procedures for maintaining information about logical memory blocks.
35 * Memblock is a method of managing memory regions during the early
36 * boot period when the usual kernel memory allocators are not up and
39 * Memblock views the system memory as collections of contiguous
42 * * ``memory`` - describes the physical memory available to the
43 * kernel; this may differ from the actual physical memory installed
44 * in the system, for instance when the memory is restricted with
46 * * ``reserved`` - describes the regions that were allocated
47 * * ``physmem`` - describes the actual physical memory available during
48 * boot regardless of the possible restrictions and memory hot(un)plug;
51 * Each region is represented by struct memblock_region that
52 * defines the region extents, its attributes and NUMA node id on NUMA
53 * systems. Every memory type is described by the struct memblock_type
54 * which contains an array of memory regions along with
55 * the allocator metadata. The "memory" and "reserved" types are nicely
57 * initialized at build time. The region arrays are initially sized to
58 * %INIT_MEMBLOCK_REGIONS for "memory" and %INIT_MEMBLOCK_RESERVED_REGIONS
59 * for "reserved". The region array for "physmem" is initially sized to
61 * The memblock_allow_resize() enables automatic resizing of the region
63 * with care so that memory allocated for the region array will not
67 * memory layout is by using memblock_add() or memblock_add_node()
68 * functions. The first function does not assign the region to a NUMA
70 * use it on NUMA systems as well and assign the region to a NUMA node
74 * Once memblock is setup the memory can be allocated using one of the
77 * * memblock_phys_alloc*() - these functions return the **physical**
78 * address of the allocated memory
79 * * memblock_alloc*() - these functions return the **virtual** address
80 * of the allocated memory.
83 * memory ranges and the fallback methods. Consult the documentation
88 * function frees all the memory to the buddy page allocator.
112 .memory.regions = memblock_memory_init_regions,
113 .memory.cnt = 1, /* empty dummy entry */
114 .memory.max = INIT_MEMBLOCK_REGIONS,
115 .memory.name = "memory",
136 * keep a pointer to &memblock.memory in the text section to use it in
141 static __refdata struct memblock_type *memblock_memory = &memblock.memory;
144 for (i = 0, rgn = &memblock_type->regions[0]; \
145 i < memblock_type->cnt; \
146 i++, rgn = &memblock_type->regions[i])
168 return *size = min(*size, PHYS_ADDR_MAX - base); in memblock_cap_size()
185 for (i = 0; i < type->cnt; i++) in memblock_overlaps_region()
186 if (memblock_addrs_overlap(base, size, type->regions[i].base, in memblock_overlaps_region()
187 type->regions[i].size)) in memblock_overlaps_region()
189 return i < type->cnt; in memblock_overlaps_region()
193 * __memblock_find_range_bottom_up - find free area utility in bottom-up
200 * @flags: pick from blocks based on memory attributes
202 * Utility called from memblock_find_in_range_node(), find free area bottom-up.
220 if (cand < this_end && this_end - cand >= size) in __memblock_find_range_bottom_up()
228 * __memblock_find_range_top_down - find free area utility, in top-down
235 * @flags: pick from blocks based on memory attributes
237 * Utility called from memblock_find_in_range_node(), find free area top-down.
258 cand = round_down(this_end - size, align); in __memblock_find_range_top_down()
267 * memblock_find_in_range_node - find free area in given range and node
274 * @flags: pick from blocks based on memory attributes
278 * When allocation direction is bottom-up, the @start should be greater
280 * reason is that we want the bottom-up allocation just near the kernel
281 * image so it is highly likely that the allocated memory and the kernel
284 * If bottom-up allocation failed, will try to allocate memory top-down.
307 * try bottom-up allocation only when bottom-up mode in memblock_find_in_range_node()
316 /* ok, try bottom-up allocation first */ in memblock_find_in_range_node()
323 * we always limit bottom-up allocation above the kernel, in memblock_find_in_range_node()
324 * but top-down allocation doesn't have the limit, so in memblock_find_in_range_node()
325 * retrying top-down allocation may succeed when bottom-up in memblock_find_in_range_node()
328 * bottom-up allocation is expected to be fail very rarely, in memblock_find_in_range_node()
333 "memblock: bottom-up allocation failed, memory hotremove may be affected\n"); in memblock_find_in_range_node()
341 * memblock_find_in_range - find free area in given range
365 pr_warn("Could not allocate %pap bytes of mirrored memory\n", in memblock_find_in_range()
376 type->total_size -= type->regions[r].size; in memblock_remove_region()
377 memmove(&type->regions[r], &type->regions[r + 1], in memblock_remove_region()
378 (type->cnt - (r + 1)) * sizeof(type->regions[r])); in memblock_remove_region()
379 type->cnt--; in memblock_remove_region()
382 if (type->cnt == 0) { in memblock_remove_region()
383 WARN_ON(type->total_size != 0); in memblock_remove_region()
384 type->cnt = 1; in memblock_remove_region()
385 type->regions[0].base = 0; in memblock_remove_region()
386 type->regions[0].size = 0; in memblock_remove_region()
387 type->regions[0].flags = 0; in memblock_remove_region()
388 memblock_set_region_node(&type->regions[0], MAX_NUMNODES); in memblock_remove_region()
394 * memblock_discard - discard memory and reserved arrays if they were allocated
407 if (memblock.memory.regions != memblock_memory_init_regions) { in memblock_discard()
408 addr = __pa(memblock.memory.regions); in memblock_discard()
410 memblock.memory.max); in memblock_discard()
419 * memblock_double_array - double the size of the memblock regions array
421 * @new_area_start: starting address of memory range to avoid overlap with
422 * @new_area_size: size of memory range to avoid overlap with
425 * allocate memory for a new reserved regions array and there is a previously
426 * allocated memory range [@new_area_start, @new_area_start + @new_area_size]
427 * waiting to be reserved, ensure the memory used by the new array does
431 * 0 on success, -1 on failure.
444 * of memory that aren't suitable for allocation in memblock_double_array()
447 return -1; in memblock_double_array()
450 old_size = type->max * sizeof(struct memblock_region); in memblock_double_array()
460 if (type == &memblock.memory) in memblock_double_array()
486 type->name, type->max, type->max * 2); in memblock_double_array()
487 return -1; in memblock_double_array()
490 new_end = addr + new_size - 1; in memblock_double_array()
491 memblock_dbg("memblock: %s is doubled to %ld at [%pa-%pa]", in memblock_double_array()
492 type->name, type->max * 2, &addr, &new_end); in memblock_double_array()
496 * reserved region since it may be our reserved array itself that is in memblock_double_array()
499 memcpy(new_array, type->regions, old_size); in memblock_double_array()
500 memset(new_array + type->max, 0, old_size); in memblock_double_array()
501 old_array = type->regions; in memblock_double_array()
502 type->regions = new_array; in memblock_double_array()
503 type->max <<= 1; in memblock_double_array()
526 * memblock_merge_regions - merge neighboring compatible regions
536 while (i < type->cnt - 1) { in memblock_merge_regions()
537 struct memblock_region *this = &type->regions[i]; in memblock_merge_regions()
538 struct memblock_region *next = &type->regions[i + 1]; in memblock_merge_regions()
540 if (this->base + this->size != next->base || in memblock_merge_regions()
543 this->flags != next->flags) { in memblock_merge_regions()
544 BUG_ON(this->base + this->size > next->base); in memblock_merge_regions()
549 this->size += next->size; in memblock_merge_regions()
551 memmove(next, next + 1, (type->cnt - (i + 2)) * sizeof(*next)); in memblock_merge_regions()
552 type->cnt--; in memblock_merge_regions()
557 * memblock_insert_region - insert new memblock region
560 * @base: base address of the new region
561 * @size: size of the new region
562 * @nid: node id of the new region
563 * @flags: flags of the new region
565 * Insert new memblock region [@base, @base + @size) into @type at @idx.
566 * @type must already have extra room to accommodate the new region.
574 struct memblock_region *rgn = &type->regions[idx]; in memblock_insert_region()
576 BUG_ON(type->cnt >= type->max); in memblock_insert_region()
577 memmove(rgn + 1, rgn, (type->cnt - idx) * sizeof(*rgn)); in memblock_insert_region()
578 rgn->base = base; in memblock_insert_region()
579 rgn->size = size; in memblock_insert_region()
580 rgn->flags = flags; in memblock_insert_region()
582 type->cnt++; in memblock_insert_region()
583 type->total_size += size; in memblock_insert_region()
587 * memblock_add_range - add new memblock region
588 * @type: memblock type to add new region into
589 * @base: base address of the new region
590 * @size: size of the new region
591 * @nid: nid of the new region
592 * @flags: flags of the new region
594 * Add new memblock region [@base, @base + @size) into @type. The new region
595 * is allowed to overlap with existing ones - overlaps don't affect already
600 * 0 on success, -errno on failure.
616 if (type->regions[0].size == 0) { in memblock_add_range()
617 WARN_ON(type->cnt != 1 || type->total_size); in memblock_add_range()
618 type->regions[0].base = base; in memblock_add_range()
619 type->regions[0].size = size; in memblock_add_range()
620 type->regions[0].flags = flags; in memblock_add_range()
621 memblock_set_region_node(&type->regions[0], nid); in memblock_add_range()
622 type->total_size = size; in memblock_add_range()
635 phys_addr_t rbase = rgn->base; in memblock_add_range()
636 phys_addr_t rend = rbase + rgn->size; in memblock_add_range()
650 WARN_ON(flags != rgn->flags); in memblock_add_range()
654 rbase - base, nid, in memblock_add_range()
665 memblock_insert_region(type, idx, base, end - base, in memblock_add_range()
677 while (type->cnt + nr_new > type->max) in memblock_add_range()
679 return -ENOMEM; in memblock_add_range()
689 * memblock_add_node - add new memblock region within a NUMA node
690 * @base: base address of the new region
691 * @size: size of the new region
692 * @nid: nid of the new region
694 * Add new memblock region [@base, @base + @size) to the "memory"
698 * 0 on success, -errno on failure.
703 return memblock_add_range(&memblock.memory, base, size, nid, 0); in memblock_add_node()
707 * memblock_add - add new memblock region
708 * @base: base address of the new region
709 * @size: size of the new region
711 * Add new memblock region [@base, @base + @size) to the "memory"
715 * 0 on success, -errno on failure.
719 phys_addr_t end = base + size - 1; in memblock_add()
721 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_add()
724 return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0); in memblock_add()
728 * memblock_isolate_range - isolate given range into disjoint memblocks
732 * @start_rgn: out parameter for the start of isolated region
733 * @end_rgn: out parameter for the end of isolated region
738 * region inside the range is returned in *@start_rgn and end in *@end_rgn.
741 * 0 on success, -errno on failure.
757 while (type->cnt + 2 > type->max) in memblock_isolate_range()
759 return -ENOMEM; in memblock_isolate_range()
762 phys_addr_t rbase = rgn->base; in memblock_isolate_range()
763 phys_addr_t rend = rbase + rgn->size; in memblock_isolate_range()
773 * to process the next region - the new top half. in memblock_isolate_range()
775 rgn->base = base; in memblock_isolate_range()
776 rgn->size -= base - rbase; in memblock_isolate_range()
777 type->total_size -= base - rbase; in memblock_isolate_range()
778 memblock_insert_region(type, idx, rbase, base - rbase, in memblock_isolate_range()
780 rgn->flags); in memblock_isolate_range()
784 * current region - the new bottom half. in memblock_isolate_range()
786 rgn->base = end; in memblock_isolate_range()
787 rgn->size -= end - rbase; in memblock_isolate_range()
788 type->total_size -= end - rbase; in memblock_isolate_range()
789 memblock_insert_region(type, idx--, rbase, end - rbase, in memblock_isolate_range()
791 rgn->flags); in memblock_isolate_range()
813 for (i = end_rgn - 1; i >= start_rgn; i--) in memblock_remove_range()
820 phys_addr_t end = base + size - 1; in memblock_remove()
822 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_remove()
825 return memblock_remove_range(&memblock.memory, base, size); in memblock_remove()
829 * memblock_free - free boot memory block
830 * @base: phys starting address of the boot memory block
831 * @size: size of the boot memory block in bytes
833 * Free boot memory block previously allocated by memblock_alloc_xx() API.
834 * The freeing memory will not be released to the buddy allocator.
838 phys_addr_t end = base + size - 1; in memblock_free()
840 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_free()
849 phys_addr_t end = base + size - 1; in memblock_reserve()
851 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_reserve()
860 phys_addr_t end = base + size - 1; in memblock_physmem_add()
862 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_physmem_add()
870 * memblock_setclr_flag - set or clear flag for a memory region
871 * @base: base address of the region
872 * @size: size of the region
876 * This function isolates region [@base, @base + @size), and sets/clears flag
878 * Return: 0 on success, -errno on failure.
883 struct memblock_type *type = &memblock.memory; in memblock_setclr_flag()
891 struct memblock_region *r = &type->regions[i]; in memblock_setclr_flag()
894 r->flags |= flag; in memblock_setclr_flag()
896 r->flags &= ~flag; in memblock_setclr_flag()
904 * memblock_mark_hotplug - Mark hotpluggable memory with flag MEMBLOCK_HOTPLUG.
905 * @base: the base phys addr of the region
906 * @size: the size of the region
908 * Return: 0 on success, -errno on failure.
916 * memblock_clear_hotplug - Clear flag MEMBLOCK_HOTPLUG for a specified region.
917 * @base: the base phys addr of the region
918 * @size: the size of the region
920 * Return: 0 on success, -errno on failure.
928 * memblock_mark_mirror - Mark mirrored memory with flag MEMBLOCK_MIRROR.
929 * @base: the base phys addr of the region
930 * @size: the size of the region
932 * Return: 0 on success, -errno on failure.
942 * memblock_mark_nomap - Mark a memory region with flag MEMBLOCK_NOMAP.
943 * @base: the base phys addr of the region
944 * @size: the size of the region
946 * Return: 0 on success, -errno on failure.
954 * memblock_clear_nomap - Clear flag MEMBLOCK_NOMAP for a specified region.
955 * @base: the base phys addr of the region
956 * @size: the size of the region
958 * Return: 0 on success, -errno on failure.
975 /* only memory regions are associated with nodes, check it */ in should_skip_region()
979 /* skip hotpluggable memory regions if needed */ in should_skip_region()
983 /* if we want mirror memory skip non-mirror memory regions */ in should_skip_region()
987 /* skip nomap memory unless we were asked for it explicitly */ in should_skip_region()
995 * __next_mem_range - next function for for_each_free_mem_range() etc.
998 * @flags: pick from blocks based on memory attributes
1000 * @type_b: pointer to memblock_type which excludes memory from being taken
1008 * areas before each region in type_b. For example, if type_b regions
1011 * 0:[0-16), 1:[32-48), 2:[128-130)
1015 * 0:[0-0), 1:[16-32), 2:[48-128), 3:[130-MAX)
1017 * As both region arrays are sorted, the function advances the two indices
1032 for (; idx_a < type_a->cnt; idx_a++) { in __next_mem_range()
1033 struct memblock_region *m = &type_a->regions[idx_a]; in __next_mem_range()
1035 phys_addr_t m_start = m->base; in __next_mem_range()
1036 phys_addr_t m_end = m->base + m->size; in __next_mem_range()
1055 for (; idx_b < type_b->cnt + 1; idx_b++) { in __next_mem_range()
1060 r = &type_b->regions[idx_b]; in __next_mem_range()
1061 r_start = idx_b ? r[-1].base + r[-1].size : 0; in __next_mem_range()
1062 r_end = idx_b < type_b->cnt ? in __next_mem_range()
1063 r->base : PHYS_ADDR_MAX; in __next_mem_range()
1081 * The region which ends first is in __next_mem_range()
1099 * __next_mem_range_rev - generic next function for for_each_*_range_rev()
1103 * @flags: pick from blocks based on memory attributes
1105 * @type_b: pointer to memblock_type which excludes memory from being taken
1129 idx_a = type_a->cnt - 1; in __next_mem_range_rev()
1131 idx_b = type_b->cnt; in __next_mem_range_rev()
1136 for (; idx_a >= 0; idx_a--) { in __next_mem_range_rev()
1137 struct memblock_region *m = &type_a->regions[idx_a]; in __next_mem_range_rev()
1139 phys_addr_t m_start = m->base; in __next_mem_range_rev()
1140 phys_addr_t m_end = m->base + m->size; in __next_mem_range_rev()
1153 idx_a--; in __next_mem_range_rev()
1159 for (; idx_b >= 0; idx_b--) { in __next_mem_range_rev()
1164 r = &type_b->regions[idx_b]; in __next_mem_range_rev()
1165 r_start = idx_b ? r[-1].base + r[-1].size : 0; in __next_mem_range_rev()
1166 r_end = idx_b < type_b->cnt ? in __next_mem_range_rev()
1167 r->base : PHYS_ADDR_MAX; in __next_mem_range_rev()
1184 idx_a--; in __next_mem_range_rev()
1186 idx_b--; in __next_mem_range_rev()
1203 struct memblock_type *type = &memblock.memory; in __next_mem_pfn_range()
1207 while (++*idx < type->cnt) { in __next_mem_pfn_range()
1208 r = &type->regions[*idx]; in __next_mem_pfn_range()
1211 if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size)) in __next_mem_pfn_range()
1216 if (*idx >= type->cnt) { in __next_mem_pfn_range()
1217 *idx = -1; in __next_mem_pfn_range()
1222 *out_start_pfn = PFN_UP(r->base); in __next_mem_pfn_range()
1224 *out_end_pfn = PFN_DOWN(r->base + r->size); in __next_mem_pfn_range()
1230 * memblock_set_node - set node ID on memblock regions
1240 * 0 on success, -errno on failure.
1254 memblock_set_region_node(&type->regions[i], nid); in memblock_set_node()
1263 * __next_mem_pfn_range_in_zone - iterator for for_each_*_range_in_zone()
1266 * @zone: zone in which all of the memory blocks reside
1272 * deferred memory init routines and as such we were duplicating much of
1286 &memblock.memory, &memblock.reserved, in __next_mem_pfn_range_in_zone()
1297 if (zone->zone_start_pfn < epfn && spfn < epfn) { in __next_mem_pfn_range_in_zone()
1305 *out_spfn = max(zone->zone_start_pfn, spfn); in __next_mem_pfn_range_in_zone()
1313 &memblock.memory, &memblock.reserved, in __next_mem_pfn_range_in_zone()
1327 * memblock_alloc_range_nid - allocate boot memory block
1328 * @size: size of memory block to be allocated in bytes
1329 * @align: alignment of the region and block's size
1330 * @start: the lower bound of the memory region to allocate (phys address)
1331 * @end: the upper bound of the memory region to allocate (phys address)
1335 * The allocation is performed from memory region limited by
1338 * If the specified node can not hold the requested memory and @exact_nid
1341 * For systems with memory mirroring, the allocation is attempted first
1343 * memory region.
1346 * allocated boot memory block, so that it is never reported as leaks.
1349 * Physical address of allocated memory block on success, %0 on failure.
1384 pr_warn("Could not allocate %pap bytes of mirrored memory\n", in memblock_alloc_range_nid()
1406 * memblock_phys_alloc_range - allocate a memory block inside specified range
1407 * @size: size of memory block to be allocated in bytes
1408 * @align: alignment of the region and block's size
1409 * @start: the lower bound of the memory region to allocate (physical address)
1410 * @end: the upper bound of the memory region to allocate (physical address)
1414 * Return: physical address of the allocated memory block on success,
1427 * memblock_phys_alloc_try_nid - allocate a memory block from specified MUMA node
1428 * @size: size of memory block to be allocated in bytes
1429 * @align: alignment of the region and block's size
1432 * Allocates memory block from the specified NUMA node. If the node
1433 * has no available memory, attempts to allocated from any node in the
1436 * Return: physical address of the allocated memory block on success,
1446 * memblock_alloc_internal - allocate boot memory block
1447 * @size: size of memory block to be allocated in bytes
1448 * @align: alignment of the region and block's size
1449 * @min_addr: the lower bound of the memory region to allocate (phys address)
1450 * @max_addr: the upper bound of the memory region to allocate (phys address)
1454 * Allocates memory block using memblock_alloc_range_nid() and
1458 * will fall back to memory below @min_addr. Other constraints, such
1459 * as node and mirrored memory will be handled again in
1463 * Virtual address of allocated memory block on success, NULL on failure.
1498 * memblock_alloc_exact_nid_raw - allocate boot memory block on the exact node
1499 * without zeroing memory
1500 * @size: size of memory block to be allocated in bytes
1501 * @align: alignment of the region and block's size
1502 * @min_addr: the lower bound of the memory region from where the allocation
1504 * @max_addr: the upper bound of the memory region from where the allocation
1506 * allocate only from memory limited by memblock.current_limit value
1510 * info), if enabled. Does not zero allocated memory.
1513 * Virtual address of allocated memory block on success, NULL on failure.
1535 * memblock_alloc_try_nid_raw - allocate boot memory block without zeroing
1536 * memory and without panicking
1537 * @size: size of memory block to be allocated in bytes
1538 * @align: alignment of the region and block's size
1539 * @min_addr: the lower bound of the memory region from where the allocation
1541 * @max_addr: the upper bound of the memory region from where the allocation
1543 * allocate only from memory limited by memblock.current_limit value
1547 * info), if enabled. Does not zero allocated memory, does not panic if request
1551 * Virtual address of allocated memory block on success, NULL on failure.
1573 * memblock_alloc_try_nid - allocate boot memory block
1574 * @size: size of memory block to be allocated in bytes
1575 * @align: alignment of the region and block's size
1576 * @min_addr: the lower bound of the memory region from where the allocation
1578 * @max_addr: the upper bound of the memory region from where the allocation
1580 * allocate only from memory limited by memblock.current_limit value
1584 * info), if enabled. This function zeroes the allocated memory.
1587 * Virtual address of allocated memory block on success, NULL on failure.
1608 * __memblock_free_late - free pages directly to buddy allocator
1609 * @base: phys starting address of the boot memory block
1610 * @size: size of the boot memory block in bytes
1620 end = base + size - 1; in __memblock_free_late()
1621 memblock_dbg("%s: [%pa-%pa] %pS\n", in __memblock_free_late()
1639 return memblock.memory.total_size; in memblock_phys_mem_size()
1650 return memblock.memory.regions[0].base; in memblock_start_of_DRAM()
1655 int idx = memblock.memory.cnt - 1; in memblock_end_of_DRAM()
1657 return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size); in memblock_end_of_DRAM()
1666 * translate the memory @limit size into the max address within one of in __find_max_addr()
1667 * the memory memblock regions, if the @limit exceeds the total size in __find_max_addr()
1671 if (limit <= r->size) { in __find_max_addr()
1672 max_addr = r->base + limit; in __find_max_addr()
1675 limit -= r->size; in __find_max_addr()
1690 /* @limit exceeds the total size of the memory, do nothing */ in memblock_enforce_memory_limit()
1694 /* truncate both memory and reserved regions */ in memblock_enforce_memory_limit()
1695 memblock_remove_range(&memblock.memory, max_addr, in memblock_enforce_memory_limit()
1709 ret = memblock_isolate_range(&memblock.memory, base, size, in memblock_cap_memory_range()
1715 for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) in memblock_cap_memory_range()
1716 if (!memblock_is_nomap(&memblock.memory.regions[i])) in memblock_cap_memory_range()
1717 memblock_remove_region(&memblock.memory, i); in memblock_cap_memory_range()
1719 for (i = start_rgn - 1; i >= 0; i--) in memblock_cap_memory_range()
1720 if (!memblock_is_nomap(&memblock.memory.regions[i])) in memblock_cap_memory_range()
1721 memblock_remove_region(&memblock.memory, i); in memblock_cap_memory_range()
1738 /* @limit exceeds the total size of the memory, do nothing */ in memblock_mem_limit_remove_map()
1747 unsigned int left = 0, right = type->cnt; in memblock_search()
1752 if (addr < type->regions[mid].base) in memblock_search()
1754 else if (addr >= (type->regions[mid].base + in memblock_search()
1755 type->regions[mid].size)) in memblock_search()
1760 return -1; in memblock_search()
1765 return memblock_search(&memblock.reserved, addr) != -1; in memblock_is_reserved()
1770 return memblock_search(&memblock.memory, addr) != -1; in memblock_is_memory()
1775 int i = memblock_search(&memblock.memory, addr); in memblock_is_map_memory()
1777 if (i == -1) in memblock_is_map_memory()
1779 return !memblock_is_nomap(&memblock.memory.regions[i]); in memblock_is_map_memory()
1785 struct memblock_type *type = &memblock.memory; in memblock_search_pfn_nid()
1788 if (mid == -1) in memblock_search_pfn_nid()
1789 return -1; in memblock_search_pfn_nid()
1791 *start_pfn = PFN_DOWN(type->regions[mid].base); in memblock_search_pfn_nid()
1792 *end_pfn = PFN_DOWN(type->regions[mid].base + type->regions[mid].size); in memblock_search_pfn_nid()
1794 return memblock_get_region_node(&type->regions[mid]); in memblock_search_pfn_nid()
1798 * memblock_is_region_memory - check if a region is a subset of memory
1799 * @base: base of region to check
1800 * @size: size of region to check
1802 * Check if the region [@base, @base + @size) is a subset of a memory block.
1805 * 0 if false, non-zero if true
1809 int idx = memblock_search(&memblock.memory, base); in memblock_is_region_memory()
1812 if (idx == -1) in memblock_is_region_memory()
1814 return (memblock.memory.regions[idx].base + in memblock_is_region_memory()
1815 memblock.memory.regions[idx].size) >= end; in memblock_is_region_memory()
1819 * memblock_is_region_reserved - check if a region intersects reserved memory
1820 * @base: base of region to check
1821 * @size: size of region to check
1823 * Check if the region [@base, @base + @size) intersects a reserved
1824 * memory block.
1841 orig_start = r->base; in memblock_trim_memory()
1842 orig_end = r->base + r->size; in memblock_trim_memory()
1850 r->base = start; in memblock_trim_memory()
1851 r->size = end - start; in memblock_trim_memory()
1853 memblock_remove_region(&memblock.memory, in memblock_trim_memory()
1854 r - memblock.memory.regions); in memblock_trim_memory()
1855 r--; in memblock_trim_memory()
1877 pr_info(" %s.cnt = 0x%lx\n", type->name, type->cnt); in memblock_dump()
1882 base = rgn->base; in memblock_dump()
1883 size = rgn->size; in memblock_dump()
1884 end = base + size - 1; in memblock_dump()
1885 flags = rgn->flags; in memblock_dump()
1891 pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n", in memblock_dump()
1892 type->name, idx, &base, &end, &size, nid_buf, flags); in memblock_dump()
1899 pr_info(" memory size = %pa reserved size = %pa\n", in __memblock_dump_all()
1900 &memblock.memory.total_size, in __memblock_dump_all()
1903 memblock_dump(&memblock.memory); in __memblock_dump_all()
1934 order = min(MAX_ORDER - 1UL, __ffs(start)); in __free_pages_memory()
1937 order--; in __free_pages_memory()
1957 return end_pfn - start_pfn; in __free_memory_core()
1966 memblock_clear_hotplug(0, -1); in free_low_memory_core_early()
1972 * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id in free_low_memory_core_early()
1989 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) in reset_node_managed_pages()
1990 atomic_long_set(&z->managed_pages, 0); in reset_node_managed_pages()
2007 * memblock_free_all - release free pages to the buddy allocator
2027 struct memblock_type *type = m->private; in memblock_debug_show()
2032 for (i = 0; i < type->cnt; i++) { in memblock_debug_show()
2033 reg = &type->regions[i]; in memblock_debug_show()
2034 end = reg->base + reg->size - 1; in memblock_debug_show()
2037 seq_printf(m, "%pa..%pa\n", &reg->base, &end); in memblock_debug_show()
2047 debugfs_create_file("memory", 0444, root, in memblock_init_debugfs()
2048 &memblock.memory, &memblock_debug_fops); in memblock_init_debugfs()