Using SVID2/XPG interface to check heap memory.
before all: The GNU Allocator (The GNU C Library)
read this for a outline for gnu c
malloc
.
mallinfo
arena + hblkhd is the total size of malloced mem. More detailed, arena is the size of all heaps in all arenas, while hblkhd is the size of all mmapped regions.
fordblks is the key data for check memory fragmentation, this stands for size of all free chunks.
to check after a routine, if there got more allocated space, check arena + hblkhd
1 | /* malloc.h */ |
Malloc Tunable Parameters
1 | /* mallopt options that actually do something */ |
Appendix
Reference
MallocInternals - glibc wiki (sourceware.org): advanced specification.
The GNU Allocator (The GNU C Library): simple but enough
memory fragmentation
the most simple way is to limit the arena count
The M_AREANA_MAX,
This parameter sets the number of arenas to use regardless of the number of cores in the system.
The default value of this tunable is
0
, meaning that the limit on the number of arenas is determined by the number of CPU cores online. For 32-bit systems the limit is twice the number of cores online and on 64-bit systems, it is eight times the number of cores online. Note that the default value is not derived from the default value of M_ARENA_TEST and is computed independently.This parameter can also be set for the process at startup by setting the environment variable
MALLOC_ARENA_MAX
to the desired value.
If you known what you are doing, change ``M_MMAP_THRESHOLDshould also works. Since page size on x86_64 Linux are 4096(check from commands
$getconf PAGESIZE` ), all value greater or equal to this would make sense.
Code to understand mallinfo
1 |
|