By default, the malloc subsystem uses a single heap, or free memory pool. However, it also provides an optional multiheap capability to allow users to enable the use of multiple heaps of free memory, rather than just one.
The purpose of providing multiple heap capability in the malloc subsystem is to improve the performance of threaded applications running on multiprocessor systems. When the malloc subsystem is limited to using a single heap, simultaneous memory allocation requests received from threads running on separate processors are serialized, meaning that the malloc subsystem can only service one thread at a time. This can have a serious impact on multiprocessor system performance.
With malloc multiheap capability enabled, the malloc subsystem creates a fixed number of heaps for its use. It will begin to use multiple heaps after the second thread is started (process becomes multithreaded). Each memory allocation request will be serviced using one of the available heaps. The malloc subsystem can then process memory allocation requests in parallel, as long as the number of threads simultaneously requesting service is less than or equal to the number of heaps.
If the number of threads simultaneously requesting service exceeds the number of heaps, then additional simultaneous requests will be serialized. Unless this occurs on an ongoing basis, the overall performance of the malloc subsystem should be significantly improved when multiple threads are making calls to malloc() in a multiprocessor environment.
Activation and configuration of the malloc multiheap capability is available at process startup via the MALLOCMULTIHEAP environment variable. The maximum number of heaps available with malloc multiheap enabled is 32.
Malloc multiheap is not enabled by default. It is enabled and configured by setting the MALLOCMULTIHEAP environment variable.
To enable malloc multiheap with default settings, set the MALLOCMULTIHEAP environment variable to any non-null value, as follows:
Setting MALLOCMULTIHEAP in this manner will enable malloc multiheap in its default configuration, with all 32 heaps and the fast heap selection algorithm.
To enable malloc multiheap with user-specified configuration options, set the MALLOCMULTIHEAP environment variable as follows:
where options is a comma-separated list of one or more predefined configuration options, as described in the next section of this document.
MALLOCMULTIHEAP environment variable options are as follows:
Each of these options is described in detail later in this document.
The MALLOCMULTIHEAP environment variable is set using the following syntax:
MALLOCMULTIHEAP=[heaps:n] | [considersize]
One or both options can be specified in any order as long as options are comma-separated, as in the following example:
In the above example, malloc multiheap would be enabled with three heaps and a somewhat slower heap selection algorithm that tries to minimize process size.
Each configuration option should only be specified once when setting MALLOCMULTIHEAP. If a configuration option is specified more than once per setting, only the final instance will apply.
Each of the MALLOCMULTIHEAP options is described below:
System Memory Allocation Using the malloc Subsystem
malloc, free, realloc, calloc, mallopt, mallinfo, alloca, or valloc Subroutine in AIX 5L Version 5.1 Technical Reference: Base Operating System and Extensions Volume 1.