Red Hat Training
A Red Hat training course is available for Red Hat Enterprise Linux
Appendix A. Appendix
malloptis a library call that allows a program to change the behavior of the malloc memory allocator.
Example A.1. Allocator heuristics
An allocator has heuristics to determine long versus short lived objects. For the former, it attempts to allocate with
mmap. For the later, it attempts to allocate with
In order to override these heuristics, set
In multi-threaded applications, the allocator creates multiple arenas in response to lock contention in existing arenas. This can improve the performance significantly for some multi-threaded applications at the cost of an increase in memory usage. To keep this under control, limit the number of arenas that can be created by using the
The allocator has limits on the number of arenas it can create. For 32bit targets, it will create 2 * # core arenas; for 64bit targets, it will create 8 * # core arenas.
malloptallows the developer to override those limits.
To ensure no more than eight arenas are created, issue the following library call:
mallopt (M_ARENA_MAX, 8);
The first argument for
Specific definitions for the above can be found at http://www.makelinux.net/man/3/M/mallopt.
malloc_trimis a library call that requests the allocator return any unused memory back to the operating system. This is normally automatic when an object is freed. However, in some cases when freeing small objects,
glibcmight not immediately release the memory back to the operating system. It does this so that the free memory can be used to satisfy upcoming memory allocation requests as it is expensive to allocate from and release memory back to the operating system.
malloc_statsis used to dump information about the allocator's internal state to
mallinfois similar to this, but it places the state into a structure instead.
More information on
malloptcan be found at http://www.makelinux.net/man/3/M/mallopt and http://www.gnu.org/software/libc/manual/html_node/Malloc-Tunable-Parameters.html.