Commit 309d0b39 authored by Robin Holt's avatar Robin Holt Committed by Linus Torvalds

mm/nobootmem.c: have __free_pages_memory() free in larger chunks.

On large memory machines it can take a few minutes to get through

Currently, when free_all_bootmem() calls __free_pages_memory(), the number
of contiguous pages that __free_pages_memory() passes to the buddy
allocator is limited to BITS_PER_LONG.  BITS_PER_LONG was originally
chosen to keep things similar to mm/nobootmem.c.  But it is more efficient
to limit it to MAX_ORDER.

       base   new  change
8TB    202s  172s   30s
16TB   401s  351s   50s

That is around 1%-3% improvement on total boot time.

This patch was spun off from the boot time rfc Robin and I had been
working on.
Signed-off-by: default avatarRobin Holt <>
Signed-off-by: default avatarNathan Zimmer <>
Cc: Robin Holt <>
Cc: "H. Peter Anvin" <>
Cc: Ingo Molnar <>
Cc: Mike Travis <>
Cc: Yinghai Lu <>
Cc: Mel Gorman <>
Acked-by: default avatarJohannes Weiner <>
Reviewed-by: default avatarWanpeng Li <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent b9921ecd
......@@ -82,27 +82,18 @@ void __init free_bootmem_late(unsigned long addr, unsigned long size)
static void __init __free_pages_memory(unsigned long start, unsigned long end)
unsigned long i, start_aligned, end_aligned;
int order = ilog2(BITS_PER_LONG);
int order;
start_aligned = (start + (BITS_PER_LONG - 1)) & ~(BITS_PER_LONG - 1);
end_aligned = end & ~(BITS_PER_LONG - 1);
while (start < end) {
order = min(MAX_ORDER - 1UL, __ffs(start));
if (end_aligned <= start_aligned) {
for (i = start; i < end; i++)
__free_pages_bootmem(pfn_to_page(i), 0);
while (start + (1UL << order) > end)
for (i = start; i < start_aligned; i++)
__free_pages_bootmem(pfn_to_page(i), 0);
__free_pages_bootmem(pfn_to_page(start), order);
for (i = start_aligned; i < end_aligned; i += BITS_PER_LONG)
__free_pages_bootmem(pfn_to_page(i), order);
for (i = end_aligned; i < end; i++)
__free_pages_bootmem(pfn_to_page(i), 0);
start += (1UL << order);
static unsigned long __init __free_memory_core(phys_addr_t start,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment