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.
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;
55 * Each region is represented by struct memblock_region that
56 * defines the region extents, its attributes and NUMA node id on NUMA
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
61 * initialized at build time. The region arrays are initially sized to
62 * %INIT_MEMBLOCK_MEMORY_REGIONS for "memory" and
63 * %INIT_MEMBLOCK_RESERVED_REGIONS for "reserved". The region array
65 * The memblock_allow_resize() enables automatic resizing of the region
67 * with care so that memory allocated for the region array will not
71 * memory layout is by using memblock_add() or memblock_add_node()
72 * functions. The first function does not assign the region to a NUMA
74 * use it on NUMA systems as well and assign the region to a NUMA 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.max = INIT_MEMBLOCK_MEMORY_REGIONS,
118 .memory.name = "memory",
137 * keep a pointer to &memblock.memory in the text section to use it in
142 static __refdata struct memblock_type *memblock_memory = &memblock.memory;
145 for (i = 0, rgn = &memblock_type->regions[0]; \
146 i < memblock_type->cnt; \
147 i++, rgn = &memblock_type->regions[i])
174 return *size = min(*size, PHYS_ADDR_MAX - base); in memblock_cap_size()
194 for (i = 0; i < type->cnt; i++) in memblock_overlaps_region()
195 if (memblock_addrs_overlap(base, size, type->regions[i].base, in memblock_overlaps_region()
196 type->regions[i].size)) in memblock_overlaps_region()
202 * __memblock_find_range_bottom_up - find free area utility in bottom-up
209 * @flags: pick from blocks based on memory attributes
211 * Utility called from memblock_find_in_range_node(), find free area bottom-up.
229 if (cand < this_end && this_end - cand >= size) in __memblock_find_range_bottom_up()
237 * __memblock_find_range_top_down - find free area utility, in top-down
244 * @flags: pick from blocks based on memory attributes
246 * Utility called from memblock_find_in_range_node(), find free area top-down.
267 cand = round_down(this_end - size, align); in __memblock_find_range_top_down()
276 * memblock_find_in_range_node - find free area in given range and node
283 * @flags: pick from blocks based on memory attributes
313 * memblock_find_in_range - find free area in given range
337 pr_warn_ratelimited("Could not allocate %pap bytes of mirrored memory\n", in memblock_find_in_range()
348 type->total_size -= type->regions[r].size; in memblock_remove_region()
349 memmove(&type->regions[r], &type->regions[r + 1], in memblock_remove_region()
350 (type->cnt - (r + 1)) * sizeof(type->regions[r])); in memblock_remove_region()
351 type->cnt--; in memblock_remove_region()
354 if (type->cnt == 0) { in memblock_remove_region()
355 WARN_ON(type->total_size != 0); in memblock_remove_region()
356 type->regions[0].base = 0; in memblock_remove_region()
357 type->regions[0].size = 0; in memblock_remove_region()
358 type->regions[0].flags = 0; in memblock_remove_region()
359 memblock_set_region_node(&type->regions[0], MAX_NUMNODES); in memblock_remove_region()
365 * memblock_discard - discard memory and reserved arrays if they were allocated
381 if (memblock.memory.regions != memblock_memory_init_regions) { in memblock_discard()
382 addr = __pa(memblock.memory.regions); in memblock_discard()
384 memblock.memory.max); in memblock_discard()
386 kfree(memblock.memory.regions); in memblock_discard()
396 * memblock_double_array - double the size of the memblock regions array
398 * @new_area_start: starting address of memory range to avoid overlap with
399 * @new_area_size: size of memory range to avoid overlap with
402 * allocate memory for a new reserved regions array and there is a previously
403 * allocated memory range [@new_area_start, @new_area_start + @new_area_size]
404 * waiting to be reserved, ensure the memory used by the new array does
408 * 0 on success, -1 on failure.
421 * of memory that aren't suitable for allocation in memblock_double_array()
424 panic("memblock: cannot resize %s array\n", type->name); in memblock_double_array()
427 old_size = type->max * sizeof(struct memblock_region); in memblock_double_array()
437 if (type == &memblock.memory) in memblock_double_array()
463 type->name, type->max, type->max * 2); in memblock_double_array()
464 return -1; in memblock_double_array()
467 new_end = addr + new_size - 1; in memblock_double_array()
468 memblock_dbg("memblock: %s is doubled to %ld at [%pa-%pa]", in memblock_double_array()
469 type->name, type->max * 2, &addr, &new_end); in memblock_double_array()
473 * reserved region since it may be our reserved array itself that is in memblock_double_array()
476 memcpy(new_array, type->regions, old_size); in memblock_double_array()
477 memset(new_array + type->max, 0, old_size); in memblock_double_array()
478 old_array = type->regions; in memblock_double_array()
479 type->regions = new_array; in memblock_double_array()
480 type->max <<= 1; in memblock_double_array()
503 * memblock_merge_regions - merge neighboring compatible regions
505 * @start_rgn: start scanning from (@start_rgn - 1)
506 * @end_rgn: end scanning at (@end_rgn - 1)
507 * Scan @type and merge neighboring compatible regions in [@start_rgn - 1, @end_rgn)
515 i = start_rgn - 1; in memblock_merge_regions()
516 end_rgn = min(end_rgn, type->cnt - 1); in memblock_merge_regions()
518 struct memblock_region *this = &type->regions[i]; in memblock_merge_regions()
519 struct memblock_region *next = &type->regions[i + 1]; in memblock_merge_regions()
521 if (this->base + this->size != next->base || in memblock_merge_regions()
524 this->flags != next->flags) { in memblock_merge_regions()
525 BUG_ON(this->base + this->size > next->base); in memblock_merge_regions()
530 this->size += next->size; in memblock_merge_regions()
532 memmove(next, next + 1, (type->cnt - (i + 2)) * sizeof(*next)); in memblock_merge_regions()
533 type->cnt--; in memblock_merge_regions()
534 end_rgn--; in memblock_merge_regions()
539 * memblock_insert_region - insert new memblock region
542 * @base: base address of the new region
543 * @size: size of the new region
544 * @nid: node id of the new region
545 * @flags: flags of the new region
547 * Insert new memblock region [@base, @base + @size) into @type at @idx.
548 * @type must already have extra room to accommodate the new region.
556 struct memblock_region *rgn = &type->regions[idx]; in memblock_insert_region()
558 BUG_ON(type->cnt >= type->max); in memblock_insert_region()
559 memmove(rgn + 1, rgn, (type->cnt - idx) * sizeof(*rgn)); in memblock_insert_region()
560 rgn->base = base; in memblock_insert_region()
561 rgn->size = size; in memblock_insert_region()
562 rgn->flags = flags; in memblock_insert_region()
564 type->cnt++; in memblock_insert_region()
565 type->total_size += size; in memblock_insert_region()
569 * memblock_add_range - add new memblock region
570 * @type: memblock type to add new region into
571 * @base: base address of the new region
572 * @size: size of the new region
573 * @nid: nid of the new region
574 * @flags: flags of the new region
576 * Add new memblock region [@base, @base + @size) into @type. The new region
577 * is allowed to overlap with existing ones - overlaps don't affect already
582 * 0 on success, -errno on failure.
591 int idx, nr_new, start_rgn = -1, end_rgn; in memblock_add_range()
598 if (type->regions[0].size == 0) { in memblock_add_range()
599 WARN_ON(type->cnt != 0 || type->total_size); in memblock_add_range()
600 type->regions[0].base = base; in memblock_add_range()
601 type->regions[0].size = size; in memblock_add_range()
602 type->regions[0].flags = flags; in memblock_add_range()
603 memblock_set_region_node(&type->regions[0], nid); in memblock_add_range()
604 type->total_size = size; in memblock_add_range()
605 type->cnt = 1; in memblock_add_range()
611 * then we'll need type->cnt + 1 empty regions in @type. So if in memblock_add_range()
612 * type->cnt * 2 + 1 is less than or equal to type->max, we know in memblock_add_range()
616 if (type->cnt * 2 + 1 <= type->max) in memblock_add_range()
629 phys_addr_t rbase = rgn->base; in memblock_add_range()
630 phys_addr_t rend = rbase + rgn->size; in memblock_add_range()
644 WARN_ON(flags != rgn->flags); in memblock_add_range()
647 if (start_rgn == -1) in memblock_add_range()
651 rbase - base, nid, in memblock_add_range()
663 if (start_rgn == -1) in memblock_add_range()
666 memblock_insert_region(type, idx, base, end - base, in memblock_add_range()
679 while (type->cnt + nr_new > type->max) in memblock_add_range()
681 return -ENOMEM; in memblock_add_range()
691 * memblock_add_node - add new memblock region within a NUMA node
692 * @base: base address of the new region
693 * @size: size of the new region
694 * @nid: nid of the new region
695 * @flags: flags of the new region
697 * Add new memblock region [@base, @base + @size) to the "memory"
701 * 0 on success, -errno on failure.
706 phys_addr_t end = base + size - 1; in memblock_add_node()
708 memblock_dbg("%s: [%pa-%pa] nid=%d flags=%x %pS\n", __func__, in memblock_add_node()
711 return memblock_add_range(&memblock.memory, base, size, nid, flags); in memblock_add_node()
715 * memblock_add - add new memblock region
716 * @base: base address of the new region
717 * @size: size of the new region
719 * Add new memblock region [@base, @base + @size) to the "memory"
723 * 0 on success, -errno on failure.
727 phys_addr_t end = base + size - 1; in memblock_add()
729 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_add()
732 return memblock_add_range(&memblock.memory, base, size, MAX_NUMNODES, 0); in memblock_add()
736 * memblock_validate_numa_coverage - check if amount of memory with
741 * A buggy firmware may report memory that does not belong to any node.
742 * Check if amount of such memory is below @threshold_bytes.
755 nr_pages += end_pfn - start_pfn; in memblock_validate_numa_coverage()
770 * memblock_isolate_range - isolate given range into disjoint memblocks
774 * @start_rgn: out parameter for the start of isolated region
775 * @end_rgn: out parameter for the end of isolated region
780 * region inside the range is returned in *@start_rgn and the index of the
781 * first region after the range is returned in *@end_rgn.
784 * 0 on success, -errno on failure.
800 while (type->cnt + 2 > type->max) in memblock_isolate_range()
802 return -ENOMEM; in memblock_isolate_range()
805 phys_addr_t rbase = rgn->base; in memblock_isolate_range()
806 phys_addr_t rend = rbase + rgn->size; in memblock_isolate_range()
816 * to process the next region - the new top half. in memblock_isolate_range()
818 rgn->base = base; in memblock_isolate_range()
819 rgn->size -= base - rbase; in memblock_isolate_range()
820 type->total_size -= base - rbase; in memblock_isolate_range()
821 memblock_insert_region(type, idx, rbase, base - rbase, in memblock_isolate_range()
823 rgn->flags); in memblock_isolate_range()
827 * current region - the new bottom half. in memblock_isolate_range()
829 rgn->base = end; in memblock_isolate_range()
830 rgn->size -= end - rbase; in memblock_isolate_range()
831 type->total_size -= end - rbase; in memblock_isolate_range()
832 memblock_insert_region(type, idx--, rbase, end - rbase, in memblock_isolate_range()
834 rgn->flags); in memblock_isolate_range()
856 for (i = end_rgn - 1; i >= start_rgn; i--) in memblock_remove_range()
863 phys_addr_t end = base + size - 1; in memblock_remove()
865 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_remove()
868 return memblock_remove_range(&memblock.memory, base, size); in memblock_remove()
872 * memblock_free - free boot memory allocation
873 * @ptr: starting address of the boot memory allocation
874 * @size: size of the boot memory block in bytes
876 * Free boot memory block previously allocated by memblock_alloc_xx() API.
877 * The freeing memory will not be released to the buddy allocator.
886 * memblock_phys_free - free boot memory block
887 * @base: phys starting address of the boot memory block
888 * @size: size of the boot memory block in bytes
890 * Free boot memory block previously allocated by memblock_phys_alloc_xx() API.
891 * The freeing memory will not be released to the buddy allocator.
895 phys_addr_t end = base + size - 1; in memblock_phys_free()
897 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_phys_free()
906 phys_addr_t end = base + size - 1; in memblock_reserve()
908 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_reserve()
917 phys_addr_t end = base + size - 1; in memblock_physmem_add()
919 memblock_dbg("%s: [%pa-%pa] %pS\n", __func__, in memblock_physmem_add()
927 * memblock_setclr_flag - set or clear flag for a memory region
929 * @base: base address of the region
930 * @size: size of the region
934 * This function isolates region [@base, @base + @size), and sets/clears flag
936 * Return: 0 on success, -errno on failure.
948 struct memblock_region *r = &type->regions[i]; in memblock_setclr_flag()
951 r->flags |= flag; in memblock_setclr_flag()
953 r->flags &= ~flag; in memblock_setclr_flag()
961 * memblock_mark_hotplug - Mark hotpluggable memory with flag MEMBLOCK_HOTPLUG.
962 * @base: the base phys addr of the region
963 * @size: the size of the region
965 * Return: 0 on success, -errno on failure.
969 return memblock_setclr_flag(&memblock.memory, base, size, 1, MEMBLOCK_HOTPLUG); in memblock_mark_hotplug()
973 * memblock_clear_hotplug - Clear flag MEMBLOCK_HOTPLUG for a specified region.
974 * @base: the base phys addr of the region
975 * @size: the size of the region
977 * Return: 0 on success, -errno on failure.
981 return memblock_setclr_flag(&memblock.memory, base, size, 0, MEMBLOCK_HOTPLUG); in memblock_clear_hotplug()
985 * memblock_mark_mirror - Mark mirrored memory with flag MEMBLOCK_MIRROR.
986 * @base: the base phys addr of the region
987 * @size: the size of the region
989 * Return: 0 on success, -errno on failure.
998 return memblock_setclr_flag(&memblock.memory, base, size, 1, MEMBLOCK_MIRROR); in memblock_mark_mirror()
1002 * memblock_mark_nomap - Mark a memory region with flag MEMBLOCK_NOMAP.
1003 * @base: the base phys addr of the region
1004 * @size: the size of the region
1006 * The memory regions marked with %MEMBLOCK_NOMAP will not be added to the
1007 * direct mapping of the physical memory. These regions will still be
1008 * covered by the memory map. The struct page representing NOMAP memory
1009 * frames in the memory map will be PageReserved()
1011 * Note: if the memory being marked %MEMBLOCK_NOMAP was allocated from
1012 * memblock, the caller must inform kmemleak to ignore that memory
1014 * Return: 0 on success, -errno on failure.
1018 return memblock_setclr_flag(&memblock.memory, base, size, 1, MEMBLOCK_NOMAP); in memblock_mark_nomap()
1022 * memblock_clear_nomap - Clear flag MEMBLOCK_NOMAP for a specified region.
1023 * @base: the base phys addr of the region
1024 * @size: the size of the region
1026 * Return: 0 on success, -errno on failure.
1030 return memblock_setclr_flag(&memblock.memory, base, size, 0, MEMBLOCK_NOMAP); in memblock_clear_nomap()
1034 * memblock_reserved_mark_noinit - Mark a reserved memory region with flag
1036 * for this region.
1037 * @base: the base phys addr of the region
1038 * @size: the size of the region
1040 * struct pages will not be initialized for reserved memory regions marked with
1043 * Return: 0 on success, -errno on failure.
1061 /* only memory regions are associated with nodes, check it */ in should_skip_region()
1065 /* skip hotpluggable memory regions if needed */ in should_skip_region()
1070 /* if we want mirror memory skip non-mirror memory regions */ in should_skip_region()
1074 /* skip nomap memory unless we were asked for it explicitly */ in should_skip_region()
1078 /* skip driver-managed memory unless we were asked for it explicitly */ in should_skip_region()
1086 * __next_mem_range - next function for for_each_free_mem_range() etc.
1089 * @flags: pick from blocks based on memory attributes
1091 * @type_b: pointer to memblock_type which excludes memory from being taken
1099 * areas before each region in type_b. For example, if type_b regions
1102 * 0:[0-16), 1:[32-48), 2:[128-130)
1106 * 0:[0-0), 1:[16-32), 2:[48-128), 3:[130-MAX)
1108 * As both region arrays are sorted, the function advances the two indices
1119 for (; idx_a < type_a->cnt; idx_a++) { in __next_mem_range()
1120 struct memblock_region *m = &type_a->regions[idx_a]; in __next_mem_range()
1122 phys_addr_t m_start = m->base; in __next_mem_range()
1123 phys_addr_t m_end = m->base + m->size; in __next_mem_range()
1142 for (; idx_b < type_b->cnt + 1; idx_b++) { in __next_mem_range()
1147 r = &type_b->regions[idx_b]; in __next_mem_range()
1148 r_start = idx_b ? r[-1].base + r[-1].size : 0; in __next_mem_range()
1149 r_end = idx_b < type_b->cnt ? in __next_mem_range()
1150 r->base : PHYS_ADDR_MAX; in __next_mem_range()
1168 * The region which ends first is in __next_mem_range()
1186 * __next_mem_range_rev - generic next function for for_each_*_range_rev()
1190 * @flags: pick from blocks based on memory attributes
1192 * @type_b: pointer to memblock_type which excludes memory from being taken
1213 idx_a = type_a->cnt - 1; in __next_mem_range_rev()
1215 idx_b = type_b->cnt; in __next_mem_range_rev()
1220 for (; idx_a >= 0; idx_a--) { in __next_mem_range_rev()
1221 struct memblock_region *m = &type_a->regions[idx_a]; in __next_mem_range_rev()
1223 phys_addr_t m_start = m->base; in __next_mem_range_rev()
1224 phys_addr_t m_end = m->base + m->size; in __next_mem_range_rev()
1237 idx_a--; in __next_mem_range_rev()
1243 for (; idx_b >= 0; idx_b--) { in __next_mem_range_rev()
1248 r = &type_b->regions[idx_b]; in __next_mem_range_rev()
1249 r_start = idx_b ? r[-1].base + r[-1].size : 0; in __next_mem_range_rev()
1250 r_end = idx_b < type_b->cnt ? in __next_mem_range_rev()
1251 r->base : PHYS_ADDR_MAX; in __next_mem_range_rev()
1268 idx_a--; in __next_mem_range_rev()
1270 idx_b--; in __next_mem_range_rev()
1287 struct memblock_type *type = &memblock.memory; in __next_mem_pfn_range()
1291 while (++*idx < type->cnt) { in __next_mem_pfn_range()
1292 r = &type->regions[*idx]; in __next_mem_pfn_range()
1295 if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size)) in __next_mem_pfn_range()
1300 if (*idx >= type->cnt) { in __next_mem_pfn_range()
1301 *idx = -1; in __next_mem_pfn_range()
1306 *out_start_pfn = PFN_UP(r->base); in __next_mem_pfn_range()
1308 *out_end_pfn = PFN_DOWN(r->base + r->size); in __next_mem_pfn_range()
1314 * memblock_set_node - set node ID on memblock regions
1324 * 0 on success, -errno on failure.
1338 memblock_set_region_node(&type->regions[i], nid); in memblock_set_node()
1347 * __next_mem_pfn_range_in_zone - iterator for for_each_*_range_in_zone()
1350 * @zone: zone in which all of the memory blocks reside
1356 * deferred memory init routines and as such we were duplicating much of
1369 &memblock.memory, &memblock.reserved, in __next_mem_pfn_range_in_zone()
1380 if (zone->zone_start_pfn < epfn && spfn < epfn) { in __next_mem_pfn_range_in_zone()
1388 *out_spfn = max(zone->zone_start_pfn, spfn); in __next_mem_pfn_range_in_zone()
1396 &memblock.memory, &memblock.reserved, in __next_mem_pfn_range_in_zone()
1410 * memblock_alloc_range_nid - allocate boot memory block
1411 * @size: size of memory block to be allocated in bytes
1412 * @align: alignment of the region and block's size
1413 * @start: the lower bound of the memory region to allocate (phys address)
1414 * @end: the upper bound of the memory region to allocate (phys address)
1418 * The allocation is performed from memory region limited by
1421 * If the specified node can not hold the requested memory and @exact_nid
1424 * For systems with memory mirroring, the allocation is attempted first
1426 * memory region.
1429 * memory block, it is never reported as leaks.
1432 * Physical address of allocated memory block on success, %0 on failure.
1475 pr_warn_ratelimited("Could not allocate %pap bytes of mirrored memory\n", in memblock_alloc_range_nid()
1497 * Some Virtual Machine platforms, such as Intel TDX or AMD SEV-SNP, in memblock_alloc_range_nid()
1498 * require memory to be accepted before it can be used by the in memblock_alloc_range_nid()
1501 * Accept the memory of the allocated buffer. in memblock_alloc_range_nid()
1509 * memblock_phys_alloc_range - allocate a memory block inside specified range
1510 * @size: size of memory block to be allocated in bytes
1511 * @align: alignment of the region and block's size
1512 * @start: the lower bound of the memory region to allocate (physical address)
1513 * @end: the upper bound of the memory region to allocate (physical address)
1517 * Return: physical address of the allocated memory block on success,
1533 * memblock_phys_alloc_try_nid - allocate a memory block from specified NUMA node
1534 * @size: size of memory block to be allocated in bytes
1535 * @align: alignment of the region and block's size
1538 * Allocates memory block from the specified NUMA node. If the node
1539 * has no available memory, attempts to allocated from any node in the
1542 * Return: physical address of the allocated memory block on success,
1552 * memblock_alloc_internal - allocate boot memory block
1553 * @size: size of memory block to be allocated in bytes
1554 * @align: alignment of the region and block's size
1555 * @min_addr: the lower bound of the memory region to allocate (phys address)
1556 * @max_addr: the upper bound of the memory region to allocate (phys address)
1560 * Allocates memory block using memblock_alloc_range_nid() and
1564 * will fall back to memory below @min_addr. Other constraints, such
1565 * as node and mirrored memory will be handled again in
1569 * Virtual address of allocated memory block on success, NULL on failure.
1597 * memblock_alloc_exact_nid_raw - allocate boot memory block on the exact node
1598 * without zeroing memory
1599 * @size: size of memory block to be allocated in bytes
1600 * @align: alignment of the region and block's size
1601 * @min_addr: the lower bound of the memory region from where the allocation
1603 * @max_addr: the upper bound of the memory region from where the allocation
1605 * allocate only from memory limited by memblock.current_limit value
1609 * info), if enabled. Does not zero allocated memory.
1612 * Virtual address of allocated memory block on success, NULL on failure.
1628 * memblock_alloc_try_nid_raw - allocate boot memory block without zeroing
1629 * memory and without panicking
1630 * @size: size of memory block to be allocated in bytes
1631 * @align: alignment of the region and block's size
1632 * @min_addr: the lower bound of the memory region from where the allocation
1634 * @max_addr: the upper bound of the memory region from where the allocation
1636 * allocate only from memory limited by memblock.current_limit value
1640 * info), if enabled. Does not zero allocated memory, does not panic if request
1644 * Virtual address of allocated memory block on success, NULL on failure.
1660 * memblock_alloc_try_nid - allocate boot memory block
1661 * @size: size of memory block to be allocated in bytes
1662 * @align: alignment of the region and block's size
1663 * @min_addr: the lower bound of the memory region from where the allocation
1665 * @max_addr: the upper bound of the memory region from where the allocation
1667 * allocate only from memory limited by memblock.current_limit value
1671 * info), if enabled. This function zeroes the allocated memory.
1674 * Virtual address of allocated memory block on success, NULL on failure.
1695 * memblock_free_late - free pages directly to buddy allocator
1696 * @base: phys starting address of the boot memory block
1697 * @size: size of the boot memory block in bytes
1707 end = base + size - 1; in memblock_free_late()
1708 memblock_dbg("%s: [%pa-%pa] %pS\n", in memblock_free_late()
1726 return memblock.memory.total_size; in memblock_phys_mem_size()
1735 * memblock_estimated_nr_free_pages - return estimated number of free pages
1748 return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size()); in memblock_estimated_nr_free_pages()
1754 return memblock.memory.regions[0].base; in memblock_start_of_DRAM()
1759 int idx = memblock.memory.cnt - 1; in memblock_end_of_DRAM()
1761 return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size); in memblock_end_of_DRAM()
1770 * translate the memory @limit size into the max address within one of in __find_max_addr()
1771 * the memory memblock regions, if the @limit exceeds the total size in __find_max_addr()
1775 if (limit <= r->size) { in __find_max_addr()
1776 max_addr = r->base + limit; in __find_max_addr()
1779 limit -= r->size; in __find_max_addr()
1794 /* @limit exceeds the total size of the memory, do nothing */ in memblock_enforce_memory_limit()
1798 /* truncate both memory and reserved regions */ in memblock_enforce_memory_limit()
1799 memblock_remove_range(&memblock.memory, max_addr, in memblock_enforce_memory_limit()
1813 if (!memblock_memory->total_size) { in memblock_cap_memory_range()
1814 pr_warn("%s: No memory registered yet\n", __func__); in memblock_cap_memory_range()
1818 ret = memblock_isolate_range(&memblock.memory, base, size, in memblock_cap_memory_range()
1824 for (i = memblock.memory.cnt - 1; i >= end_rgn; i--) in memblock_cap_memory_range()
1825 if (!memblock_is_nomap(&memblock.memory.regions[i])) in memblock_cap_memory_range()
1826 memblock_remove_region(&memblock.memory, i); in memblock_cap_memory_range()
1828 for (i = start_rgn - 1; i >= 0; i--) in memblock_cap_memory_range()
1829 if (!memblock_is_nomap(&memblock.memory.regions[i])) in memblock_cap_memory_range()
1830 memblock_remove_region(&memblock.memory, i); in memblock_cap_memory_range()
1847 /* @limit exceeds the total size of the memory, do nothing */ in memblock_mem_limit_remove_map()
1856 unsigned int left = 0, right = type->cnt; in memblock_search()
1861 if (addr < type->regions[mid].base) in memblock_search()
1863 else if (addr >= (type->regions[mid].base + in memblock_search()
1864 type->regions[mid].size)) in memblock_search()
1869 return -1; in memblock_search()
1874 return memblock_search(&memblock.reserved, addr) != -1; in memblock_is_reserved()
1879 return memblock_search(&memblock.memory, addr) != -1; in memblock_is_memory()
1884 int i = memblock_search(&memblock.memory, addr); in memblock_is_map_memory()
1886 if (i == -1) in memblock_is_map_memory()
1888 return !memblock_is_nomap(&memblock.memory.regions[i]); in memblock_is_map_memory()
1894 struct memblock_type *type = &memblock.memory; in memblock_search_pfn_nid()
1897 if (mid == -1) in memblock_search_pfn_nid()
1900 *start_pfn = PFN_DOWN(type->regions[mid].base); in memblock_search_pfn_nid()
1901 *end_pfn = PFN_DOWN(type->regions[mid].base + type->regions[mid].size); in memblock_search_pfn_nid()
1903 return memblock_get_region_node(&type->regions[mid]); in memblock_search_pfn_nid()
1907 * memblock_is_region_memory - check if a region is a subset of memory
1908 * @base: base of region to check
1909 * @size: size of region to check
1911 * Check if the region [@base, @base + @size) is a subset of a memory block.
1914 * 0 if false, non-zero if true
1918 int idx = memblock_search(&memblock.memory, base); in memblock_is_region_memory()
1921 if (idx == -1) in memblock_is_region_memory()
1923 return (memblock.memory.regions[idx].base + in memblock_is_region_memory()
1924 memblock.memory.regions[idx].size) >= end; in memblock_is_region_memory()
1928 * memblock_is_region_reserved - check if a region intersects reserved memory
1929 * @base: base of region to check
1930 * @size: size of region to check
1932 * Check if the region [@base, @base + @size) intersects a reserved
1933 * memory block.
1949 orig_start = r->base; in memblock_trim_memory()
1950 orig_end = r->base + r->size; in memblock_trim_memory()
1958 r->base = start; in memblock_trim_memory()
1959 r->size = end - start; in memblock_trim_memory()
1961 memblock_remove_region(&memblock.memory, in memblock_trim_memory()
1962 r - memblock.memory.regions); in memblock_trim_memory()
1963 r--; in memblock_trim_memory()
1985 pr_info(" %s.cnt = 0x%lx\n", type->name, type->cnt); in memblock_dump()
1990 base = rgn->base; in memblock_dump()
1991 size = rgn->size; in memblock_dump()
1992 end = base + size - 1; in memblock_dump()
1993 flags = rgn->flags; in memblock_dump()
1999 pr_info(" %s[%#x]\t[%pa-%pa], %pa bytes%s flags: %#x\n", in memblock_dump()
2000 type->name, idx, &base, &end, &size, nid_buf, flags); in memblock_dump()
2007 pr_info(" memory size = %pa reserved size = %pa\n", in __memblock_dump_all()
2008 &memblock.memory.total_size, in __memblock_dump_all()
2011 memblock_dump(&memblock.memory); in __memblock_dump_all()
2045 start_pg = pfn_to_page(start_pfn - 1) + 1; in free_memmap()
2046 end_pg = pfn_to_page(end_pfn - 1) + 1; in free_memmap()
2060 memblock_phys_free(pg, pgend - pg); in free_memmap()
2064 * The mem_map array can get very big. Free the unused area of the memory map.
2089 * presume that there are no holes in the memory map inside in free_unused_memmap()
2103 * presume that there are no holes in the memory map inside in free_unused_memmap()
2126 * MAX_PAGE_ORDER-aligned, set order to MAX_PAGE_ORDER for in __free_pages_memory()
2135 order--; in __free_pages_memory()
2155 return end_pfn - start_pfn; in __free_memory_core()
2160 struct memblock_region *region; in memmap_init_reserved_pages() local
2168 for_each_mem_region(region) { in memmap_init_reserved_pages()
2169 nid = memblock_get_region_node(region); in memmap_init_reserved_pages()
2170 start = region->base; in memmap_init_reserved_pages()
2171 end = start + region->size; in memmap_init_reserved_pages()
2173 if (memblock_is_nomap(region)) in memmap_init_reserved_pages()
2183 for_each_reserved_mem_region(region) { in memmap_init_reserved_pages()
2184 if (!memblock_is_reserved_noinit(region)) { in memmap_init_reserved_pages()
2185 nid = memblock_get_region_node(region); in memmap_init_reserved_pages()
2186 start = region->base; in memmap_init_reserved_pages()
2187 end = start + region->size; in memmap_init_reserved_pages()
2203 memblock_clear_hotplug(0, -1); in free_low_memory_core_early()
2208 * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id in free_low_memory_core_early()
2225 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) in reset_node_managed_pages()
2226 atomic_long_set(&z->managed_pages, 0); in reset_node_managed_pages()
2243 * memblock_free_all - release free pages to the buddy allocator
2256 /* Keep a table to reserve named memory */
2267 /* Add wildcard region with a lookup name */
2274 map->start = start; in reserved_mem_add()
2275 map->size = size; in reserved_mem_add()
2276 strscpy(map->name, name); in reserved_mem_add()
2280 * reserve_mem_find_by_name - Find reserved memory region with a given name
2281 * @name: The name that is attached to a reserved memory region
2296 if (!map->size) in reserve_mem_find_by_name()
2298 if (strcmp(name, map->name) == 0) { in reserve_mem_find_by_name()
2299 *start = map->start; in reserve_mem_find_by_name()
2300 *size = map->size; in reserve_mem_find_by_name()
2319 return -EINVAL; in reserve_mem()
2321 /* Check if there's room for more reserved memory */ in reserve_mem()
2323 return -EBUSY; in reserve_mem()
2328 return -EINVAL; in reserve_mem()
2331 return -EINVAL; in reserve_mem()
2335 return -EINVAL; in reserve_mem()
2349 return -EINVAL; in reserve_mem()
2357 return -EINVAL; in reserve_mem()
2361 return -EBUSY; in reserve_mem()
2365 return -ENOMEM; in reserve_mem()
2384 struct memblock_type *type = m->private; in memblock_debug_show()
2390 for (i = 0; i < type->cnt; i++) { in memblock_debug_show()
2391 reg = &type->regions[i]; in memblock_debug_show()
2392 end = reg->base + reg->size - 1; in memblock_debug_show()
2396 seq_printf(m, "%pa..%pa ", &reg->base, &end); in memblock_debug_show()
2401 if (reg->flags) { in memblock_debug_show()
2403 if (reg->flags & (1U << j)) { in memblock_debug_show()
2422 debugfs_create_file("memory", 0444, root, in memblock_init_debugfs()
2423 &memblock.memory, &memblock_debug_fops); in memblock_init_debugfs()