I was planning to write some notes about ptmalloc, tcmalloc and jemalloc. Well, it is impossible for sure. So I decide to read jemalloc first, because this is the first malloc library that I learned while reading redis source code.
Abbreviations:
TSD, tsd: thread specific data
TLS, tls: thread local storage
Jemalloc is a general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support. For further information please check the links down below. I will focus on je_malloc, the main function overriding libc malloc.
The version I am reading is in HEAD commit fb56766ca9b398d07e2def5ead75a021fc08da03 due to a new implementation for performance improvement in je_malloc.
To enable static linking with glibc, there must be a jemalloc specific malloc function implementation. The entry point is in jemalloc.c.
Tracking into je_malloc. Current je_malloc in this dev branch is not the same as released. They add some code to improve performance which is based on these concepts:
caching by tcache (thread cache)
tail-calling the old je_malloc
Misc
tsd_get_allocates
This function return bool value based on platform information. So do tsd_boot0 tsd_boot1, tsd_boot, tsd_booted_get, tsd_get_allocates, tsd_get, and tsd_set.
unlikely, likely
These functions are used for static branch prediction. Compiler would try to place instructions followed by a branch or not according to whether the branch is likely or unlikely to be taken.