John Knight
John Knight

Reputation: 109

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.

Upvotes: 10

Views: 3901

Answers (1)

dho
dho

Reputation: 2360

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.

Upvotes: 8

Related Questions