[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
AIX Versions 3.2 and 4 Performance Tuning Guide

Appendix F. Application Memory Management-malloc and realloc

AIX acquired a new memory-management algorithm in Version 3.2, which is retained in Version 4. The previous algorithm, which is widely used in UNIX systems, rounded up the size of all malloc requests to the next power of 2. The result was considerable virtual- and real-memory fragmentation and poor locality of reference. The Version 3.2 algorithm allocates exactly the amount of space requested and is more efficient about reclaiming previously used blocks of memory.

Unfortunately, a certain number of existing application programs depended inadvertently on the previous algorithm for acceptable performance or even for correct functioning. For example, if a program depends on the additional space provided by the rounding-up process because it actually overruns the end of an array, it will probably fail when used with the Version 3.2 malloc.

As another example, because of the inefficient space reclamation of the Version 3.1 routine, the application program almost always receives space that has been set to zeros (when a process touches a given page in its working segment for the first time, that page is set to zeros). Applications may depend on this side effect for correct execution. In fact, zeroing out of the allocated space is not a specified function of malloc and would result in an unnecessary performance penalty for programs that initialize only as required and possibly not to zeros. Because the Version 3.2 malloc is more aggressive about reusing space, programs that are dependent on receiving zeroed storage from malloc will probably fail in Version 3.2 or later systems.

Similarly, if a program continually reallocs a structure to a slightly greater size, in Version 3.1 realloc may not need to move the structure very often. In many cases realloc can make use of the extra space provided by the rounding. In Version 3.2, realloc will usually have to move the structure to a slightly larger area because something else has been malloced just above it. This has the appearance of a deterioration in realloc performance, when in fact it is the surfacing of a cost that is implicit in the application program's structure.

The possibility that existing AIX programs, and programs ported from other UNIX systems, might depend on side effects of the Version 3.1 malloc subroutine was foreseen. The Version 3.1 algorithm can be reinvoked by entering:

MALLOCTYPE=3.1; export MALLOCTYPE

Thereafter, all programs run by the shell will use the previous version of the malloc subroutine. Setting MALLOCTYPE to anything other than 3.1 causes the shell to revert to Version 3.2 behavior.

Related Information

The malloc subroutine, realloc subroutine.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]