1

I installed tcmalloc on Ubuntu 14.0 using apt-get install libtcmalloc-minimal4

I did following steps:

ln -s libtcmalloc_minimal.so.4.1.2 libtcmalloc_minimal.so
linked my executable with -ltcmalloc_minimal

After running the code, I can not see any performance difference.

I tried to run with HEAPCHECK to check if tcmalloc is being used, but did not found any warnings associated with HEAPCHECK.

My programs contains malloc calls and openMP. Is there any thing else I need to do? How can I check to make sure that tcmalloc is being used by my program?

komal dedhia
  • 217
  • 1
  • 3
  • 8
  • It gives "not a dynamic executable". I am using make file and it did not gave any error as I have linked the library using -L . As per what I have read, malloc will get converted to tcmalloc. I dont have to do any changes in my program. Correct me if I am wrong. – komal dedhia Oct 11 '15 at 23:05
  • Right way of linking library is via -ltcmalloc_minimal – Aliaksei Kandratsenka Oct 13 '15 at 03:20
  • Thanks Aliaksei, your reply on google-perftool group did help my query. – komal dedhia Oct 13 '15 at 05:27
  • I've had to use this workaround in Uubntu 16.04 as well, so the issue is not yet fixed. Note that I symlinked to libtcmalloc_minimal.so.4, so that any minor-version upgrades to the library would not break my symlink. – Isac Casapu Dec 28 '16 at 13:28

3 Answers3

2

I did following steps: ln -s libtcmalloc_minimal.so.4.1.2 libtcmalloc_minimal.so linked my executable with -ltcmalloc_minimal

In general, it should never be necessary to symlink a library like that. The fact that you had to do that tells me that you did not install correct (development) package.

ldd gives "not a dynamic executable".

In that case, your executable is guaranteed to not have been linked with libtcmalloc_minimal.so.

I have linked the library using -L <path to .so>

That does not link your executable to any specific library, it merely tell your linker to look in <path to .so> directory for libraries. You need to actually ask the linker to look for libtcmalloc_minimal, with -ltcmalloc_minimal flag.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
1

Got following response from google-perftool group to check if tcmalloc is being used by my program:

Setting environment variable MALLOCSTATS to 1 or 2 should print some tcmalloc statistics at the end.

E.g. MALLOCSTATS=2 ./myprogram

komal dedhia
  • 217
  • 1
  • 3
  • 8
1

You could put a breakpoint at malloc(), e.g. in GDB:

(gdb) break malloc
Breakpoint 2 at 0x7ffff72b2130 (3 locations)

If TC-Malloc is being used, you'll see the following when a dynamic allocaiton is made:

Breakpoint 2, 0x00007ffff7ba8c20 in tc_malloc () from  /lib64/libtcmalloc_minimal.so.4
(gdb) bt
#0  0x00007ffff7ba8c20 in tc_malloc () from /lib64/libtcmalloc_minimal.so.4
#1  0x00007ffff729e45d in __fopen_internal () from /lib64/libc.so.6
Isac Casapu
  • 1,163
  • 13
  • 21