Tuning memory allocation

The performance of the malloc() family can be tuned via two environment variables, _M_ARENA_OPTS and _M_SBA_OPTS. For more information see the malloc(3C) man page.

Memory is dynamically allocated in threaded applications using arenas. The environment variable _M_ARENA_OPTS can be used to adjust the number of arenas and the how memory expands within the arenas. The number of arenas can be from 1 to 64 for threaded applications, the default number is 8.

Each time an arena expands itself, it grows by the number of pages (the expansion factor) defined by the _M_ARENA_OPTS.

The following setting is recommended:

_M_ARENA_OPTS=1:4096

The first number determines the number of arenas to be used. The second number determines the expansion factor or how much the arena will be incremented (in 4096 byte pages) as memory allocations are performed to expand the heap. The expansion factor has a default value of 32 and has a valid range from 1 to 4096.

In the recommended setting, the number of arenas is 1 and expansion is 4096 pages. The default page size in HP-UX is 4096 bytes so the expansion size is 4096 pages * 4096 bytes or 16MB.

Threaded applications like Sybase IQ use multiple arenas by default. The default behavior is for memory requests by different threads to be handled by different arenas. For Sybase IQ, it may be best to have a single arena so that all threads share a single memory allocation pool.

Here is an example of how to use _M_ARENA_OPTS,

$ export _M_ARENA_OPTS = 1:4096

The _M_SBA_OPTS environment variable turns on the SBA (Small Block Allocator) and sets the parameters maxfast, grain and numlblks. For the SBA to take effect, you must set the environment variable before starting the Sybase IQ Server. Once the first small block is allocated, you cannot change the values. The SBA uses a different strategy to make small block allocations more efficient. It handles malloc requests smaller than M_MXFAST bytes by allocating large groups of those small blocks and then allocating and releasing those smaller blocks within the groups of the same size. This strategy can speed up malloc/free. It can also reduce fragmentation caused when small blocks get in between large free blocks and prevent them from being coalesced for a large request.

The default behavior is for the SBA to be set on for Itanium-based systems and set off for PA-RISC systems running HP-UX. The SBA can be disabled as follows:

export _M_SBA_OPTS=0:0:0

The following SBA setting is recommended for Sybase IQ:

_M_SBA_OPTS=65536:50:256
65536 maxfast size, 50 small blocks, 256 grain size

This means that the maxfast size is 65536, the number of small blocks (numblks) is 50, and the grain size is 256.

If you do not supply all three values, default values are used instead, as follows:

To use this environment variable:

$ export _M_SBA_OPTS = 65536:50:256