Analyzing malloc usage under AIX
This appendix describes the optimization and tuning of the POWER7 processor-based server by using the AIX malloc subroutine. It covers the following topics:
Introduction
There is a simple methodology on AIX to collect useful information about how an application uses the C heap. That information can then be used to choose and tune the appropriate malloc settings. The type of information that typically must be collected is:
The distribution of malloc allocation sizes that are used by an application, which shows if AIX MALLOCOPTIONS, such as pool and buckets, are expected to perform well. This information can be used to fine-tune bucket sizes.
The steady state size of the heap, which shows how to size the pool option.
Additional information about thread counts, malloc usage per thread, and so on, can be useful, but the information that is presented here presents a basic view.
How to collect malloc usage information
To discover the distribution of allocation sizes, set the following environment variable:
export MALLOCOPTIONS=buckets,bucket_statistics:stdout
Run an application. When the application completes, a summary of the malloc activity is output. Example A-1 shows a sample output from a simple test program.
Example A-1 Output from a simple test program
==================================
Malloc buckets statistical summary
==================================
Configuration values:
Number of buckets: 16
Bucket sizing factor: 32
Blocks per bucket: 1024
Allocation request totals:
Buckets allocator: 118870654
Default allocator: 343383
Total for process: 119214037
Allocation requests by bucket
Bucket Maximum Number of
Number Block Size Allocations
----- ---------- -----------
0 32 104906782
1 64 9658271
2 96 1838903
3 128 880723
4 160 300990
5 192 422310
6 224 143923
7 256 126939
8 288 157459
9 320 72162
10 352 87108
11 384 56136
12 416 63137
13 448 66160
14 480 45571
15 512 44080
Allocation requests by heap
Heap Buckets Default
Number Allocator Allocator
----- ----------- -----------
0 118870654 343383
This environment variable causes the program to produce a histogram of allocation sizes when it terminates. The number of allocation requests satisfied by the default allocator indicates the fraction of requests that are too large for the buckets allocator (larger than 512 bytes, in this example). By modifying some of the malloc buckets configuration options, you can, for example, obtain more details about larger allocation sizes.
To discover the steady state size of the heap, set the following environment variable:
export MALLOCDEBUG=log
Run an application to a steady state point, attach it by running dbx, and then run malloc. Example A-2 shows a sample output.
Example A-2 Sample output from the malloc subroutine
(dbx) malloc
The following options are enabled:
Implementation Algorithm........ Default Allocator (Yorktown)
Malloc Log
Stack Depth............. 4
Statistical Report on the Malloc Subsystem:
Heap 0
heap lock held by................ pthread ID 0x20023358
bytes acquired from sbrk()....... 5309664
bytes in the freespace tree...... 334032
bytes held by the user........... 4975632
allocations currently active..... 76102
allocations since process start.. 20999785
The Process Heap
Initial process brk value........ 0x20013850
current process brk value........ 0x214924c0
sbrk()s called by malloc......... 78
The bytes held by the user value indicates how much heap space is allocated. By stopping multiple times when you run dbx and then running malloc, you can get a good estimate of the heap space needed by the application.
For more information, see System Memory Allocation Using the malloc Subsystem,
available at:
 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset