Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tcmalloc/jemalloc with custom memory pool manager

I would like to use a high performance general purpose allocator like jemalloc/tcmalloc with a memory pool. Is there a guide for doing this? I don't want to use jemalloc/tcmalloc as a drop-in replacement for malloc.

I have memory pool that uses libarena and carves a largish memory area (2GB). I want to create fixed size objects pool like gslice on this arena for say 1 GB. (like the Bonwick slab allocator) and want to use the rest of the memory for variable sized general purpose allocation. I would like to have jemalloc/tcmalloc use this memory area. Is this possible? Any ideas as to how I can proceed? If there is an alternate library, I would like to hear about it as well.

like image 745
John Knight Avatar asked Jun 05 '13 06:06

John Knight


1 Answers

This is an old question, but there's finally a positive answer, at least where jemalloc is concerned. Since jemalloc version 4.0.0, you can use mallctl to set hooks for where chunked allocations get memory by using the arena.<i>.chunk_hooks interface. These hooks are well documented in the jemalloc manpage, including a number of cross-references.

I'm unaware as to any similar interface in tcmalloc; I do not use it.

I answered a similar question semi-recently; there may be useful information there, as well.

like image 178
dho Avatar answered Sep 19 '22 03:09

dho