aboutsummaryrefslogtreecommitdiffstats
path: root/mm/memblock.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/memblock.c')
-rw-r--r--mm/memblock.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/mm/memblock.c b/mm/memblock.c
index 2f55f19b7c86..99f285599501 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -99,21 +99,21 @@ phys_addr_t __init_memblock memblock_find_in_range_node(phys_addr_t start,
99 phys_addr_t this_start, this_end, cand; 99 phys_addr_t this_start, this_end, cand;
100 u64 i; 100 u64 i;
101 101
102 /* align @size to avoid excessive fragmentation on reserved array */
103 size = round_up(size, align);
104
105 /* pump up @end */ 102 /* pump up @end */
106 if (end == MEMBLOCK_ALLOC_ACCESSIBLE) 103 if (end == MEMBLOCK_ALLOC_ACCESSIBLE)
107 end = memblock.current_limit; 104 end = memblock.current_limit;
108 105
109 /* adjust @start to avoid underflow and allocating the first page */ 106 /* avoid allocating the first page */
110 start = max3(start, size, (phys_addr_t)PAGE_SIZE); 107 start = max_t(phys_addr_t, start, PAGE_SIZE);
111 end = max(start, end); 108 end = max(start, end);
112 109
113 for_each_free_mem_range_reverse(i, nid, &this_start, &this_end, NULL) { 110 for_each_free_mem_range_reverse(i, nid, &this_start, &this_end, NULL) {
114 this_start = clamp(this_start, start, end); 111 this_start = clamp(this_start, start, end);
115 this_end = clamp(this_end, start, end); 112 this_end = clamp(this_end, start, end);
116 113
114 if (this_end < size)
115 continue;
116
117 cand = round_down(this_end - size, align); 117 cand = round_down(this_end - size, align);
118 if (cand >= this_start) 118 if (cand >= this_start)
119 return cand; 119 return cand;
@@ -728,6 +728,9 @@ static phys_addr_t __init memblock_alloc_base_nid(phys_addr_t size,
728{ 728{
729 phys_addr_t found; 729 phys_addr_t found;
730 730
731 /* align @size to avoid excessive fragmentation on reserved array */
732 size = round_up(size, align);
733
731 found = memblock_find_in_range_node(0, max_addr, size, align, nid); 734 found = memblock_find_in_range_node(0, max_addr, size, align, nid);
732 if (found && !memblock_reserve(found, size)) 735 if (found && !memblock_reserve(found, size))
733 return found; 736 return found;