From: H. Peter Anvin Date: Mon, 25 Apr 2011 23:37:24 +0000 (-0700) Subject: core: dynamically size the heap X-Git-Tag: syslinux-4.10-pre6~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05fc41096ac07358660e96e138890999bcab89df;p=platform%2Fupstream%2Fsyslinux.git core: dynamically size the heap Dynamically size the heap to 1/16 of available high memory. Signed-off-by: H. Peter Anvin --- diff --git a/core/com32.inc b/core/com32.inc index 111590c..ff18fde 100644 --- a/core/com32.inc +++ b/core/com32.inc @@ -123,7 +123,7 @@ not_com32r_msg db ': not a COM32R image', CR, LF, 0 ; ; Danger, Will Robinson: it's not clear the use of ; core_xfer_buf is safe here. - global __entry_esp, __com32 + global __entry_esp, __com32, HighMemSize alignz 4 __entry_esp: dd 0 ; Dummy to avoid _exit issues diff --git a/core/configinit.inc b/core/configinit.inc index 915e77f..6320a0d 100644 --- a/core/configinit.inc +++ b/core/configinit.inc @@ -20,8 +20,6 @@ section .text16 reset_config: - call highmemsize - ; Initialize the .config section xor eax,eax mov si,__config_lma @@ -45,7 +43,7 @@ mkkeymap: stosb inc al loop mkkeymap - mov eax,[HighMemSize] + mov eax,[MallocStart] mov [VKernelEnd],eax ret diff --git a/core/extern.inc b/core/extern.inc index 816659b..b40d849 100644 --- a/core/extern.inc +++ b/core/extern.inc @@ -24,6 +24,9 @@ ; newconfig.c extern pm_is_config_file + ; mem/init.c + extern MallocStart, mem_init + %if IS_PXELINUX ; pxe.c extern unload_pxe, reset_pxe diff --git a/core/fs/fs.c b/core/fs/fs.c index ad2fb37..5409986 100644 --- a/core/fs/fs.c +++ b/core/fs/fs.c @@ -429,9 +429,6 @@ void fs_init(com32sys_t *regs) /* ops is a ptr list for several fs_ops */ const struct fs_ops **ops = (const struct fs_ops **)regs->eax.l; - /* Initialize malloc() */ - mem_init(); - /* Default name for the root directory */ fs.cwd_name[0] = '/'; diff --git a/core/init.inc b/core/init.inc index e06ca96..97889ca 100644 --- a/core/init.inc +++ b/core/init.inc @@ -29,6 +29,12 @@ common_init: jne kaboom ; +; Initialize the malloc arena +; + call highmemsize + pm_call mem_init + +; ; Initialize timer ; call timer_init diff --git a/core/mem/init.c b/core/mem/init.c index 487bbb3..87e4cdd 100644 --- a/core/mem/init.c +++ b/core/mem/init.c @@ -5,14 +5,16 @@ struct free_arena_header __malloc_head[NHEAP]; -static __hugebss char main_heap[128 << 10]; extern char __lowmem_heap[]; +size_t __bss16 MallocStart; +extern size_t HighMemSize; void mem_init(void) { struct free_arena_header *fp; int i; uint16_t *bios_free_mem = (uint16_t *)0x413; + size_t main_heap_size; /* Initialize the head nodes */ @@ -24,10 +26,14 @@ void mem_init(void) fp++; } - /* Initialize the main heap */ - fp = (struct free_arena_header *)main_heap; + /* Initialize the main heap; give it 1/16 of high memory */ + main_heap_size = (HighMemSize - 0x100000) >> 4; + MallocStart = (HighMemSize - main_heap_size) & ~4095; + main_heap_size = (HighMemSize - MallocStart) & ARENA_SIZE_MASK; + + fp = (struct free_arena_header *)MallocStart; fp->a.attrs = ARENA_TYPE_USED | (HEAP_MAIN << ARENA_HEAP_POS); - ARENA_SIZE_SET(fp->a.attrs, sizeof main_heap); + ARENA_SIZE_SET(fp->a.attrs, main_heap_size); __inject_free_block(fp); /* Initialize the lowmem heap */ diff --git a/core/ui.inc b/core/ui.inc index 0a4bb56..36b6c6e 100644 --- a/core/ui.inc +++ b/core/ui.inc @@ -154,7 +154,7 @@ display_labels: mov cx,di sub cx,command_line call crlf - mov esi,[HighMemSize] ; Start from top of memory + mov esi,[MallocStart] ; Start from top of memory .scan: cmp esi,[VKernelEnd] jbe .not_vk @@ -360,7 +360,7 @@ clin_opt_ok: ; Now check if it is a "virtual kernel" ; vk_check: - mov esi,[HighMemSize] ; Start from top of memory + mov esi,[MallocStart] ; Start from top of memory .scan: cmp esi,[VKernelEnd] jbe .not_vk