zoukankan      html  css  js  c++  java
  • study on source code of Tcmalloc

    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.

  • 相关阅读:
    京东分页
    相册分类列表页
    在线运行Javascript,Jquery,HTML,CSS代码
    点击事件后动画提示
    一些广告代码
    爱可有—之最经典
    爱可有网络社区需要定义
    鼠标移动时缩小图片显示说明
    Flask-RESTful 快速入门
    Sequelize 关系模型简介
  • 原文地址:https://www.cnblogs.com/Torstan/p/2599942.html
Copyright © 2011-2022 走看看