[uClinux-dev] The Power of 2

Robin Getz rgetz at blackfin.uclinux.org
Fri Oct 14 22:27:35 EDT 2005

I was poking around looking at where stack was, when an end user was 
discussing what they thought was a stack problem (it wasn't), and noticed 
that between the BSS section, and the end of stack, there was a large gap - 
depending on the size of the application.

Here are some examples.

APP      size   TEXT     DATA        BSS         GAP      STACK       MEM
-------- ------ -------- ----------- ----------- -------- ----------- -----
uname     1928  44-  584   588-  668   668-  698 ( 2280d)   f80- 1ffc (  8k)
version  16068  44- 35a4  35a8- 3be8  3be8- 4c08 ( 9083d)  6f83- 7ffc ( 32k)
ifconfig 57796  44- 9fa4  9fa8- cca8  cca8- f118 (65129d) 1ef81-1fffc (132k)
dhcpcd   69648  44- ca84  ca88- f4d8  f4d8-12c38 (49997d) 1ef85-1fffc (132k)
thdm     84816  44- d184  d188-131a8 131a8-175e8 (31137d) 1ef89-1fffc (132k)

size is size in the ramfs
TEXT is the location of the text section
DATA is the location of the data section
BSS  is the location of the bss section
GAP  is the size of the gap between the end of the BSS section, and the end 
of the stack.
STACK is the location of the stack.
MEM  is the memory footprint in the system.
All values in hex, except GAP and MEM.

Loading up an application like ifconfig, where there is a 64k gap is kind 
of silly in an embedded application, where memory is a precious resource.

I figured out this must be the power of 2 allocator in the kernel, and went 
looking for page_alloc2 or kmalloc2 per David McCullough's article at:

But I could not find them. I found versions for the 2.4

Any pointers to where what to do for the 2.6 kernel? This seemed to be in 
some linux 2.5.44-ac trees, but not in 2.5.45 Can anyone who was paying 
attention provide any history?


BTW - I also noticed in linux-2.6.x/fs/binfmt_flat.c

         /* zero the BSS,  BRK and stack areas */
         memset((void*)(datapos + data_len), 0, bss_len +
                         (memp + ksize((void *) memp) - stack_len -      /* 
end brk */
                         libinfo->lib_list[id].start_brk) +              /* 
start brk */

Why does the BRK (the GAP), and stack need to be cleared to zero?


More information about the uClinux-dev mailing list