Example of using jemalloc to manage a given memory space?

Jason Evans jasone at canonware.com
Wed Jun 8 17:26:06 PDT 2016


On Jun 4, 2016, at 3:22 PM, Bill O'Hara <billtohara at gmail.com> wrote:
> I see various hints that it's possible to use jemalloc to manage a given memory space. That is, given a pointer to say 16GB of byte addressable memory, use jemalloc to manage it as a heap.
> 
> 1) Can someone point me in the direction of a simple example, or hints on how to configure jemalloc to do this?

Here's the relevant documentation:

	http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arena.i.chunk_hooks

Here's a test case that gives a basic example of how to use the chunk hooks API:

	https://github.com/jemalloc/jemalloc/blob/master/test/integration/chunk.c

> 2) Further -- is it possible to get jemalloc to put it's own data structures entirely within the given 16GB space, so that if the process restarts that the heap can be reattached?

No, there are lots of places where jemalloc uses static data, and it's generally important to performance to do so.  As of 4.2.0, application-created arenas (see http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arenas.extend) put all their metadata in one of the automatically multiplexed arenas so that it's possible to discard the contents of an arena with a single call (http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arena.i.reset), which is sort of the opposite of what you want.

Jason


More information about the jemalloc-discuss mailing list