IBM Power7 Optimization And Tuning Manual page 120

Table of Contents

Advertisement

Usage
To use TCMalloc, link TCMalloc into your application by using the -ltcmalloc linker flag by
running the following command:
$ gcc [...] -ltcmalloc
You can also use TCMalloc in applications that you did not compile yourself by using
LD_PRELOAD as follows:
$ LD_PRELOAD="/usr/lib/libtcmalloc.so"
These examples assume that the TCMalloc library is in /usr/lib. With the Advance Toolchain
5.0.4, the 32-bit and 64-bit libraries are in /opt/at5.0/lib and /opt/at5.0/lib64.
Using TCMalloc with hugepages
To use large pages with TCMalloc, complete the following steps:
1. Set the environment variables for libhugetlbfs.
2. Allocate the number of large pages from the system.
3. Set up the libugetlbfs mount point.
4. Monitor large pages usage.
TCmalloc backs up the heap allocation on the large pages only.
Here are a more detailed version of these steps:
1. Set the environment variables for libhugetlbfs by running the following commands:
– # export TCMALLOC_MEMFS_MALLOC_PATH=/libhugetlbfs/
– # export HUGETLB_ELFMAP=RW
– # export HUGETLB_MORECORE=yes
Where:
– TCMALLOC_MEMFS_MALLOC_PATH=/libhugetlbfs/ defines the libhugetlbfs mount point.
– HUGETLB_ELFMAP=RW allocates both RSS and BSS (text/code and data) segments on the
large pages, which is useful for codes that have large static arrays, such as
Fortran programs.
– HUGETLB_MORECORE=yes makes heap usage on the large pages.
2. Allocate the number of large pages from the system by running one of the
following commands:
– # echo N > /proc/sys/vm/nr_hugepages
– # echo N > /proc/sys/vm/nr_overcommit_hugepages
Where:
– N is the number of large pages to be reserved. A peak usage of 4 GB by your program
requires 256 large pages (4096/16).
– nr_hugepages is the static pool. The kernel reserves N * 16 MB of memory from the
static pool to be used exclusively by the large pages allocation.
– nr_overcommit_hugepages is the dynamic pool. The kernel sets a maximum usage of
large pages and dynamically allocates or deallocates these large pages.
3. Set up the libhugetlbfs mount point by running the following commands:
– # mkdir -p /libhugetlbfs
– # mount -t hugetlbfs hugetlbfs /libhugetlbfs
104
POWER7 and POWER7+ Optimization and Tuning Guide
N

Advertisement

Table of Contents
loading

This manual is also suitable for:

Power7+

Table of Contents