5. Using MTS on IBM AIX

5.1 Introduction

This chapter contains information specific to the IBM AIX platform. For general information on MTS, see Chapter 2. MTS Basics. For information on building and executing the MTS demo programs, see Appendix A. Building the MTS Demo Programs

MTS has been tested to work with IBM AIX version 5.3 and above.

5.2 Release Contents

MTS for AIX consists of the following files:

Filename Description
release_notes Information on this release of MTS
Makefile Makefile for creating the demos
demo.cc MTS demo program
mts.h Header file for directly invoking MTS functions
MTSPoolObject.H C++ wrapper for the MTS Pool allocator compatible with the C++ std::allocator interface
libmts64.so MTS allocator shared library, 64-bit
libmts64.a MTS allocator static library, 64-bit
UserGuide/ This manual
index.html The entry point for this manual.

5.3 Enabling MTS Without Relinking

AIX supports runtime linking of a custom allocator via the MALLOCTYPE and LIBPATH environment variables.

To use the MALLOCTYPE environment variable, the archive containing the user defined memory subsystem is specified by setting MALLOCTYPE to user:<archive_name> where <archive_name> is in the application’s libpath or the path is specified in the LIBPATH environment variable.

$ LIBPATH=path/to/mts_install:$LIBPATH MALLOCTYPE=user:libmts64.so /path/to/application

See the following IBM AIX documentation for more details: https://www.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.genprogc/malloc_replace.htm

5.4 Linking to MTS

To link an application to MTS, include the appropriate MTS library as the first library on the link line. For example, the link line for the demo program that uses the multithreaded MTS fast allocator shared library is:

gcc -maix64 -pthread demo.c mtsinstall/libstsm64.so

Note the use of the -pthread flag instead of -lpthread. It tells gcc to use the correct preprocessor flags. In the sample above, replace mtsinstall with the directory that contains the MTS libraries.

5.5 Platform Specific Notes

To maximize the amount of memory available to a 32-bit application on AIX, either the -bmaxdata linking option needs to be used or the LDR_CNTRL=MAXDATA environment variable. To use the -bmaxdata environment variable, add -bmaxdata:80000000 to the link line of the application. To use the environment variable, set the LDR_CNTRL environment variable to MAXDATA=0x80000000. For example, export LDR CNTRL=MAXDATA=0x80000000

5.6 Tracking Memory Usage

On AIX, MTS uses a hybrid allocation technique that combines calls to sbrk and mmap. Specifically, sbrk is used until it can not allocate more memory at which mmap will be used to allocate all remaining available memory. On AIX 32-bit executables, sbrk is limited to only eight 256MB segments for a total of just under 2 GB of memory. After sbrk fails, MTS switches to mmap because it can allocate another three 256MB segments using mmap. That brings the maximum memory consumption to about 2.7GB. For tracking the memory consumption, sbrk can be tracked using ps v <pid>. The RSS column gives an accurate reading on the memory that is currently allocated. This works for applications using less than 2GB. As soon as your application gets bigger than 2GB, MTS will switch to mmap and ps can not see the mmap’d memory. For the mmap’d regions, vmstat can see the memory under its avm column (Active Virtual Memory.)

5.7 Using MTS Within C++ Applications (g++)

The C++ compiler within GCC (g++) uses a custom allocator by default which pools memory allocated by the Standard C++ Library. The custom allocator does not use MTS by default. To redirect the custom allocator to MTS for improved application performance and scalability, define the GLIBCPP_FORCE_NEW environment variable before running the application linked to MTS if using a version of GCC prior to 3.4 or GLIBCXX_FORCE_NEW otherwise.

A permanent redirection of operator new to malloc() has to be done by overriding the default allocator for the Standard C++ Library containers or structures in use within the application. For more information regarding this topic, please see:

https://gcc.gnu.org/onlinedocs/libstdc++/manual/memory.html