Skip to content

Commit b5318d3

Browse files
dilingerH. Peter Anvin
authored andcommitted
x86, olpc: Speed up device tree creation during boot
Calling alloc_bootmem() for tiny chunks of memory over and over is really slow; on an XO-1, it caused the time between when the kernel started booting and when the display came alive (post-lxfb probe) to increase to 44s. This patch optimizes the prom_early_alloc function by calling alloc_bootmem for 4k-sized blocks of memory, and handing out chunks of that to callers. With this patch, the time between kernel load and display initialization decreased to 23s. If there's a better way to do this early in the boot process, please let me know. (Note: increasing the chunk size to 16k didn't noticably affect boot time, and wasted 9k.) v4: clarify comment, requested by hpa v3: fix wasted memory buglet found by Milton Miller, and style fix. v2: reorder prom_early_alloc as suggested by Grant. Signed-off-by: Andres Salomon <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent c10d1e2 commit b5318d3

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

arch/x86/platform/olpc/olpc_dt.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,32 @@ static unsigned int prom_early_allocated __initdata;
126126

127127
void * __init prom_early_alloc(unsigned long size)
128128
{
129+
static u8 *mem;
130+
static size_t free_mem;
129131
void *res;
130132

131-
res = alloc_bootmem(size);
132-
if (res)
133-
memset(res, 0, size);
134-
135-
prom_early_allocated += size;
133+
if (free_mem < size) {
134+
const size_t chunk_size = max(PAGE_SIZE, size);
135+
136+
/*
137+
* To mimimize the number of allocations, grab at least
138+
* PAGE_SIZE of memory (that's an arbitrary choice that's
139+
* fast enough on the platforms we care about while minimizing
140+
* wasted bootmem) and hand off chunks of it to callers.
141+
*/
142+
res = alloc_bootmem(chunk_size);
143+
if (!res)
144+
return NULL;
145+
prom_early_allocated += chunk_size;
146+
memset(res, 0, chunk_size);
147+
free_mem = chunk_size;
148+
mem = res;
149+
}
136150

151+
/* allocate from the local cache */
152+
free_mem -= size;
153+
res = mem;
154+
mem += size;
137155
return res;
138156
}
139157

0 commit comments

Comments
 (0)