study on source code of Tcmalloc
2012-07-19 20:37
387 查看
This night, I downloaded the source code of Tcmalloc after supper, and studied it for several hours. I am recording some findings here in case that I forget them tommorow.
1. File libc_override_gcc_and_weak.h does override malloc routines (malloc, free, realloc, and so on) on systems that define the memory allocation routines to be weak symbols in their libc (almost all unix-based systems are like this), on gcc, which supports the 'alias' attribute.
2. tc_malloc in tcmalloc.cc is the entry for malloc defined in Tcmalloc tool which call do_malloc finally.
3. Here is the basic idea of do_malloc.
http://goog-perftools.sourceforge.net/doc/tcmalloc.html
or
doc\tcmalloc
4. When allocating several pages for large objects, it calls TCMalloc_SystemAlloc in system_alloc.cc. It abstracts system allocator, and provides two kinds of system allocator, MmapSysAllocator and SbrkSysAllocator. There is a comment in the code."In 64-bit debug mode, place the mmap allocator first since it
allocates pointers that do not fit in 32 bits and therefore gives us better testing of code's 64-bit correctness. It also leads to less false negatives in heap-checking code."
5. NOTE: TCMalloc currently does not return any memory to the system. So it cannot solve the issue that memory usage keep increasing when a job is running.
PS: The source code is clear and elegant.
1. File libc_override_gcc_and_weak.h does override malloc routines (malloc, free, realloc, and so on) on systems that define the memory allocation routines to be weak symbols in their libc (almost all unix-based systems are like this), on gcc, which supports the 'alias' attribute.
2. tc_malloc in tcmalloc.cc is the entry for malloc defined in Tcmalloc tool which call do_malloc finally.
3. Here is the basic idea of do_malloc.
http://goog-perftools.sourceforge.net/doc/tcmalloc.html
or
doc\tcmalloc
4. When allocating several pages for large objects, it calls TCMalloc_SystemAlloc in system_alloc.cc. It abstracts system allocator, and provides two kinds of system allocator, MmapSysAllocator and SbrkSysAllocator. There is a comment in the code."In 64-bit debug mode, place the mmap allocator first since it
allocates pointers that do not fit in 32 bits and therefore gives us better testing of code's 64-bit correctness. It also leads to less false negatives in heap-checking code."
5. NOTE: TCMalloc currently does not return any memory to the system. So it cannot solve the issue that memory usage keep increasing when a job is running.
PS: The source code is clear and elegant.
相关文章推荐
- How to Get Source Code of a Linux Command on CentOS
- The study of Tomcat Source Code -- Party II
- The Attack of the Clones: A Study of the Impact of Shared Code on Vulnerability Patching
- Use of Legacy Source Code
- -fembed-bitcode is not supported on versions of iOS prior to 6.0
- why separate the source code of a codec into two p
- How to get the source code of the chromium of the specified revision
- Install Source Code Pro on Ubuntu
- JSP 出现 “Cannot switch on a value of type String for source level below 1.7” 的解决方法
- Study from open source code -- brk() & sbrk() (2)
- -fembed-bitcode is not supported on versions of iOS prior to 6.0
- Current content index of Study node of Gcc-3.4.6 source
- why separate the source code of a codec into two p
- -fembed-bitcode is not supported on versions of iOS prior to 6.0 iOS
- An error occurred during the execution of xp_cmdshell. A call to 'LogonUserW' failed with error code: '1385'
- How to get the source code of the chromium of the specified revision
- Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- 在Linux上编译OpenJDK7源码 | Compile OpenJDK7 source code on CentOS 6.5
- 20 issues of porting C++ code on the 64-bit platform
- ISSUE:-fembed-bitcode is not supported on versions of iOS prior to 6.0