HP-UX Reference (11i v3 07/02) - 3 Library Functions A-M (vol 6)

m
malloc(3C) malloc(3C)
$ export _M_ARENA_OPTS = 16:8
This means that the number of arenas is 16, and the expansion size is 8*4096 bytes. In general, the more
arenas you use, the smaller the expansion factor should be, and vice versa.
_M_SBA_OPTS is used to turn on the small block allocator, and to set up parameters for the small block
allocator, namely, maxfast, grain, and numlblks. Applications with small block allocator turned on usually
run faster than with it turned off. Small block allocator can be turned on through
mallopt(); however,
it is not early enough for C++/Java applications. The environment variable turns it on before the applica-
tion starts. The
mallopt() call can still be used the same way. If the environment variable is set, and
no small block allocator has been used, the subsequent
mallopt() calls can still overwrite whatever is
set through
_M_SBA_OPTS . If the environment variable is set, and small block allocator has been used,
then mallopt() will have no effect.
To use this environment variable,
$ export _M_SBA_OPTS = 512:100:16
This means that the maxfast size is 512, the number of small blocks is 100, and the grain size is 16. You
have to supply all 3 values, and in that order. If not, the default values will be used instead.
Three new global variables, __hp_malloc_maxfast
, __hp_malloc_num_smallblocks
, and
__hp_malloc_grain
are introduced for Itanium-based systems to over-ride the _M_SBA_OPTS
environment option. When these three variables are initialized within an application, _M_SBA_OPTS has
no effect. This way, a finely tuned application can lock in performance across different user environments.
However, as _M_ARENA_OPTS, a subsequent call to
mallopt() before any block of memory was allo-
cated will change the
malloc() behavior. By default, these three variables will be initialized to zero at
start up. It is the same as setting them to
extern int __hp_malloc_maxfast=512;
extern int __hp_malloc_num_smallblocks=100;
extern int __hp_malloc_grain=16;
By default, SBA (Small Block Allocation) is turned on for Itanium-based systems. This may contribute to
better application performance. A user can set
extern int __hp_malloc_maxfast=-1;
This will turn off SBA.
For all other possible values, please refer to mallopt().
_M_CACHE_OPTS is used to turn on the thread local cache. Turning this option on sets up a private cache
for each thread to which access is effectively non-threaded, so there is less contention on the arenas. For
some multi-threaded applications this can give a significant performance improvement.
The thread local cache saves blocks of sizes that have previously been used, and thus may be requested
again. The size of the cache is configurable. The cache is organized in buckets of sizes that are powers of
two; that is, there is a bucket for all blocks in the size range 64-127 bytes, another for 128-255 bytes, and so
on.
Thread Local Cache can be tuned by setting the _M_CACHE_OPTS
environment variable as follows:
_M_CACHE_OPTS=bucket_size:buckets:retirement_age:
max_cache_misses:num_global_slots
The values must be supplied in the exact order indicated. The first three parameters are mandatory, and
the last two are optional.
bucket_size denotes the number of pointers cached per bucket. If bucket_size is 0, then thread
local cache is disabled. The maximum value for bucket_size is 32768.
buckets is an indication of the number of buckets. The maximum block size that will be cached is
buckets. buckets can range between 8 and 32.
retirement_age is an indication in minutes of after how long blocks in an unused cache will be
released to the arena. retirement_age is only a hint, so caches may or may not be retired after the
specified time period. If retirement_age is 0, retirement is disabled. The maximum value for
retirement_age is 1440 (that is, 24 hours).
max_cache_misses enables cached blocks to be exchanged among threads. A thread that heavily allo-
cates blocks of a certain size is soon bound to run out of blocks in its private cache. The exchange allows
778 Hewlett-Packard Company 4 HP-UX 11i Version 3: February 2007