overhead for an empty heap arena overhead for an empty heap arena linux linux

overhead for an empty heap arena


struct malloc_state (aka mstate, aka arena descriptor) have size

glibc-2.2 (256+18)*4 bytes =~ 1 KB for 32 bit mode and ~2 KB for 64 bit mode. glibc-2.3 (256+256/32+11+NFASTBINS)*4 =~ 1.1-1.2 KB in 32bit and 2.4-2.5 KB for 64bit

See glibc-x.x.x/malloc/malloc.c file, struct malloc_state


Destruction of arenas... I don't know yet, but there is such text (briefly - it says NO to the possibility of destruction/trimming memory ) from analysis http://www.citi.umich.edu/techreports/reports/citi-tr-00-5.pdf from 2000 (*a bit outdated). Please name your glibc version.

Ptmalloc maintains a linked list of subheaps. To re-duce lock contention, ptmalloc searchs for the firstunlocked subheap and grabs memory from it to fulfilla malloc() request. If ptmalloc doesn’t find anunlocked heap, it creates a new one. This is a simpleway to grow the number of subheaps as appropriatewithout adding complicated schemes for hashing onthread or processor ID, or maintaining workload sta-tistics. However, there is no facility to shrink the sub-heap list and nothing stops the heap list from growingwithout bound. 


from malloc.c (glibc 2.3.5) line 1546

/*  -------------------- Internal data structures --------------------   All internal state is held in an instance of malloc_state defined   below.  ...   Beware of lots of tricks that minimize the total bookkeeping space   requirements. **The result is a little over 1K bytes** (for 4byte   pointers and size_t.)*/

The same result as I got for 32-bit mode. The result is a little over 1K bytes