OLD | NEW |
(Empty) | |
| 1 Notes about the Chrome port of tcmalloc & jemalloc. |
| 2 |
| 3 Background |
| 4 ---------- |
| 5 We use this library as a generic way to fork into any of several allocators. |
| 6 Currently we can, at runtime, switch between: |
| 7 the default windows allocator |
| 8 the windows low-fragmentation-heap |
| 9 tcmalloc |
| 10 jemalloc (the heap used most notably within Mozilla Firefox) |
| 11 |
| 12 The mechanism for hooking LIBCMT in windows is rather tricky. The core |
| 13 problem is that by default, the windows library does not declare malloc and |
| 14 free as weak symbols. Because of this, they cannot be overriden. To work |
| 15 around this, we start with the LIBCMT.LIB, and manually remove all allocator |
| 16 related functions from it using the visual studio library tool. Once removed, |
| 17 we can now link against the library and provide custom versions of the |
| 18 allocator related functionality. |
| 19 |
| 20 |
| 21 Source code |
| 22 ----------- |
| 23 Everything within the directory tcmalloc/tcmalloc is pulled directly from the |
| 24 google-perftools repository. For the most part, tcmalloc is a stock build |
| 25 from there. |
| 26 |
| 27 We have forked a few files. We always push our changes upstream, so over |
| 28 time the forked files should disappear. Currently forked files include: |
| 29 page_heap.cc |
| 30 port.cc |
| 31 system-alloc.cc |
| 32 system-alloc.h |
| 33 tcmalloc.cc |
| 34 |
| 35 Adding a new allocator requires definition of the following five functions: |
| 36 extern "C" { |
| 37 bool init(); |
| 38 void* malloc(size_t s); |
| 39 void* realloc(void* p, size_t s); |
| 40 void free(void* s); |
| 41 size_t msize(void* p); |
| 42 } |
| 43 |
| 44 All other allocation related functions (new/delete/calloc/etc) have been |
| 45 implemented generically to work across all allocators. |
| 46 |
| 47 |
| 48 Usage |
| 49 ----- |
| 50 You can use the different allocators by setting the environment variable |
| 51 CHROME_ALLOCATOR to: |
| 52 "tcmalloc" - TC Malloc (default) |
| 53 "jemalloc" - JE Malloc |
| 54 "winheap" - Windows default heap |
| 55 "winlfh" - Windows Low-Fragmentation heap |
| 56 |
| 57 |
| 58 Local modifications |
| 59 ------------------- |
| 60 jemalloc has been modified slightly to work within the Chromium build. |
OLD | NEW |