Questions tagged [tcmalloc]

TCMalloc is a malloc library developed by Google. It is faster than the glibc 2.3 malloc (ptmalloc2), which takes approximately 300ns to execute a malloc/free pair on a 2.8GHz P4 (for small objects). TCMalloc takes approximately 50ns for the same operation pair. It also reduces lock contention for multi-threaded programs. For small objects, there is virtually zero contention. Another benefit is space-efficient representation of small objects.

Introduction

TCMalloc (Thread-Caching malloc) is a (memory allocation) library developed by Google. It is part of the gperftools (Google Performance Tools) project. Other tools in the same project include a heap checker (detecting memory leaks), a heap profiler (getting statistics for memory usage) and a CPU profiler (getting statistics for CPU usage).

Official Introduction by Sanjay Ghemawat

TCMalloc is faster than the glibc 2.3 malloc (available as a separate library called ptmalloc2) and other mallocs that I have tested. ptmalloc2 takes approximately 300 nanoseconds to execute a malloc/free pair on a 2.8 GHz P4 (for small objects). The TCMalloc implementation takes approximately 50 nanoseconds for the same operation pair. Speed is important for a malloc implementation because if malloc is not fast enough, application writers are inclined to write their own custom free lists on top of malloc. This can lead to extra complexity, and more memory usage unless the application writer is very careful to appropriately size the free lists and scavenge idle objects out of the free list.

TCMalloc also reduces lock contention for multi-threaded programs. For small objects, there is virtually zero contention. For large objects, TCMalloc tries to use fine grained and efficient spinlocks. ptmalloc2 also reduces lock contention by using per-thread arenas but there is a big problem with ptmalloc2's use of per-thread arenas. In ptmalloc2 memory can never move from one arena to another. This can lead to huge amounts of wasted space. For example, in one Google application, the first phase would allocate approximately 300MB of memory for its URL canonicalization data structures. When the first phase finished, a second phase would be started in the same address space. If this second phase was assigned a different arena than the one used by the first phase, this phase would not reuse any of the memory left after the first phase and would add another 300MB to the address space. Similar memory blowup problems were also noticed in other applications.

Another benefit of TCMalloc is space-efficient representation of small objects. For example, N 8-byte objects can be allocated while using space approximately 8N * 1.01 bytes. I.e., a one-percent space overhead. ptmalloc2 uses a four-byte header for each object and (I think) rounds up the size to a multiple of 8 bytes and ends up using 16N bytes.

Links

Related Tags

98 questions
1
vote
0 answers

Interpreting tcmalloc's MALLOCSTATS output

I am trying to fix performance problem with a multi threaded application which uses tcmalloc. Each threads creates large number of objects and my analysis is that thread caches in tcmalloc are not able to allocate memory and often tries to fetch…
Jithin
  • 1,108
  • 2
  • 12
  • 26
0
votes
1 answer

function wrapping in c - sbrk for tcmalloc

I am trying to port tcmalloc to uclibc. Tcmalloc has a definition for sbrk function, which in turn calls the __sbrk from libc. Uclibc on the other hand does not have __sbrk function, but has sbrk. Any ideas about how I can call uclibc sbrk from…
l.thee.a
  • 3,231
  • 6
  • 25
  • 28
0
votes
0 answers

Configuring HugePages on Google's TCMalloc

I had earlier raised a query on the github.com/google/tcmalloc regarding how I can force tcmalloc to back memory with hugetlbfs instead of using Transparent Huge Pages. I have attached the link to my query below. Please let me know if there is any…
0
votes
0 answers

need consult using memory allocation TCMalloc replaces the default Glibc in MySQL

Please consult the experienced pro using memory allocation TCMalloc replaces the default Glibc in MySQL. What are the disadvantages of TCMalloc? Is it compatible with all versions of MySQL 8.0 Are not? because we want to deploy TCMalloc on multiple…
Thi Dang
  • 1
  • 1
0
votes
0 answers

How to avoid CMake writting full path of objects to the static library?

The original issue is here. After a few days, I find the problem is here. I tried to use the following CMakeLists.txt to build tcmalloc_minimal_static.lib: #... # https://github.com/gperftools/gperftools/blob/master/CMakeLists.txt#L593 if(MINGW OR…
Duke M
  • 1
0
votes
1 answer

tcmalloc allocation failures when there is free memory

I am using libtcmalloc_minimal.so.4.5.3 on Ubuntu 20. I am seeing a lot of allocation failures in the log of the form: src/central_freelist.cc:333] tcmalloc: allocation failed 8192 However, there is 290GB of free memory on the system according to…
Logan
  • 1
  • 2
0
votes
0 answers

Benchmarking redis with different allocators is no effect

I need to find out which of the libraries (libcmalloc, jemalloc, tcmalloc) is more productive using Redis. I compile redis from source with various libraries and run the benchmark (shown below), but the results are almost…
0
votes
0 answers

How do I build libtcmalloc.a?

I'd like to build libtcmalloc.a from the latest version of tcmalloc but can't figure out how. I'm using the bazel docker image and following tcmalloc quickstart and all the commands work but it doesn't produce the library that I need. The…
dromodel
  • 9,581
  • 12
  • 47
  • 65
0
votes
0 answers

tcmalloc in gperftools crash the programm

Connecting conan-package gperftools sometimes causes this core dump. tcmalloc dynamically linked to gperftools and gperftools dynamically linked to project. Seems like problem with allocation. Does anyone know why it happens? #0 0x00007f8f087ec532…
Endorel
  • 1
  • 1
0
votes
0 answers

Grpc service fails to allocate memory within kubernetes pod

I have a grpc service deployed at kubernetes, all the memory allocation goes through tcmalloc. I frequently find the out-of-memory issue within pod. Stacktrace here: terminate called after throwing an instance of 'std::length_error' what(): …
Tinyden
  • 524
  • 4
  • 13
0
votes
0 answers

How to make pprof for tcmalloc show all allocated memory instead of only the difference to the previous dump?

I'm using libtcmalloc.so with LD_PRELOAD on some executable and it works fine. The problem is, that the output only contains the difference compared to the previous file. But I would like to see all allocated memory (and not freed) since the start…
Frank Puck
  • 467
  • 1
  • 11
0
votes
0 answers

which version of tcmalloc is used in gpertools-2.10

tcmalloc is one part of gperftools. I discover the version of tcmalloc used in gperftools laest version(currently 2.10) entirely different from tcmalloc from github: https://github.com/google/tcmalloc. Anyone tells me the differenece between…
Wu Jo
  • 1
0
votes
1 answer

How tcamalloc gets linked to the main program

I want to know how malloc gets linked to the main program.Basically I have a program which uses several static and dynamic libraries.I am including all these in my makefile using option "-llibName1 -llibName2". The documentation of TCmalloc says…
pjain
  • 1,149
  • 2
  • 14
  • 28
0
votes
1 answer

TCmalloc CPUPROFILE has no output

I am currently interested in user-level memory allocator and TCmalloc from google. I saw this page that shows some evaluation to comparing PTmalloc2 and TCmalloc. I want to rebuild that experiment in my environment. So, I installed TCmalloc from an…
Js Choi
  • 1
  • 1
0
votes
1 answer

How to check if a pre-compiled libtcmalloc.so is compiled without libunwind?

I do not know where to even start, apologies for the noob question but seems there's nothing on this specific case in SO unless there's more generic terms I do not know.
mlj
  • 13
  • 2