Optimizing memory consumption with tcmalloc or jemalloc

When most of your memory is allocated in a large number of noncontiguous blocks (for example, small chunks of common data), memory fragmentation can cause resource starvation. To avoid resource starvation and optimize memory consumption and transactional throughput, try applying a different memory allocation library in your cluster. IBM® Spectrum Symphony is certified with tcmalloc (gperftools 2.2) and jemalloc (3.0.0).

Before you begin

You must download and compile the tcmalloc or jemalloc library on hosts in your cluster. Use these steps as a reference to compile either library.
  • Download and compile tcmalloc as follows:
    1. Download the gperftools-2.2.tar.gz package from https://github.com/gperftools/gperftools/releases/download/gperftools-2.2/gperftools-2.2.tar.gz and extract the files:
      # tar zxvf gperftools-2.2.tar.gz
    2. From the gperftools-2.2 directory, compile the library:
      # cd gperftools-2.2
      # ./configure --enable-frame-pointers
      # make
    3. Copy the .libs/libtcmalloc.so file to the ${SOAM_HOME}/version/EGO_machine_type/lib64 directory in your IBM Spectrum Symphony installation.
  • Download and compile jemalloc as follows:
    1. Download the jemalloc-3.0.0.tar.bz2 package from https://github.com/jemalloc/jemalloc/releases/download/3.0.0/jemalloc-3.0.0.tar.bz2 and extract the files:
      # tar xjf jemalloc-3.0.0.tar.bz2
    2. From the jemalloc-3.0.0 directory, compile the library:
      # cd jemalloc-3.0.0
      # ./configure 
      # make
    3. Copy the jemalloc-3.0.0/lib/libjemalloc.so.1 file to the ${SOAM_HOME}/version/EGO_machine_type/lib64 directory in your IBM Spectrum Symphony installation.

Procedure

After you download and compile the library, follow these steps to enable tcmalloc or jemalloc in your cluster:

  1. Edit your application profile to enable tcmalloc and jemalloc.
    • To enable tcmalloc, in the SOAM > SSM section of the application profile, define the LD_PRELOAD environment variable to the location of the libtcmalloc.so file, as follows:
      <env name="LD_PRELOAD">${SOAM_HOME}/version/EGO_machine_type/lib64/libtcmalloc.so</env>
    • To enable jemalloc, in the SOAM > SSM section of the application profile, define the LD_PRELOAD environment variable to the location of the libjemalloc.so.1 file, as follows:
      <env name="LD_PRELOAD">${SOAM_HOME}/version/EGO_machine_type/lib64/libjemalloc.so.1</env>
  2. Use the soamreg command to update your application with the new profile.
  3. Run workload.
  4. After the application SSM starts, use the lsof -p $SSM_PID | grep malloc command to check whether the library is loaded:
    • To check whether tcmalloc is loaded, use the lsof -p $SSM_PID | grep malloc command. For example:
      # lsof -p 22897 | grep malloc
      ssm  22897 root  mem  REG  253,0   2243669   20589001 
      /opt/sym/soam/version/linux2.6-glibc2.3-x86_64/lib64/libtcmalloc.so
    • To check whether jemalloc is loaded, use the lsof -p $SSM_PID | grep malloc command. For example:
      # lsof -p 11269 | grep malloc
      ssm   11269 root  mem  REG  253,0   1813245   20589000 
      /opt/sym/soam/version/linux2.6-glibc2.3
      -x86_64/lib64/libjemalloc.so.1

Results

The tcmalloc or jemalloc library is enabled for memory optimization in your cluster.