Tuning Memory Allocation

Use _M_ARENA_OPTS and _M_SBA_OPTS to tune malloc() performance.

_M_ARENA_OPTS

Memory is dynamically allocated in threaded applications using arenas. You can adjust the number of arenas and how memory expands within the arenas with the environment variable, _M_ARENA_OPTS. 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 SAP Sybase IQ use multiple arenas by default. The default behavior is for memory requests by different threads to be handled by different arenas. For SAP Sybase IQ, it may be best to have a single arena so that all threads share a single memory allocation pool.

To use _M_ARENA_OPTS:

$ export _M_ARENA_OPTS = 1:4096

M_SBA_OPTS

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 SAP 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 SAP 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.

Default Values

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

  • maxfast - The algorithm allocates all blocks below the size of maxfast in large groups, then doles them out very quickly. The default value for maxfast is zero.
  • numblks - The above mentioned “large groups” each contain numlblks blocks. The default value for numlblks is 100 and the value of numlblks must be greater than 1.
  • grain - The sizes of all blocks smaller than maxfast are rounded up to the nearest multiple of grain. The default value of grain is the smallest number of bytes that can accommodate alignment of any data type. The value of grain must be greater than zero.

To use this environment variable:

$ export _M_SBA_OPTS = 65536:50:256
Related concepts
Controlling Syslog Messages