<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 8, 2016 at 5:26 PM, Jason Evans <span dir="ltr"><<a href="mailto:jasone@canonware.com" target="_blank">jasone@canonware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Jun 4, 2016, at 3:22 PM, Bill O'Hara <<a href="mailto:billtohara@gmail.com">billtohara@gmail.com</a>> wrote:<br>
> 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.<br>
><br>
> 1) Can someone point me in the direction of a simple example, or hints on how to configure jemalloc to do this?<br>
<br>
</span>Here's the relevant documentation:<br>
<br>
        <a href="http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arena.i.chunk_hooks" rel="noreferrer" target="_blank">http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arena.i.chunk_hooks</a><br>
<br>
Here's a test case that gives a basic example of how to use the chunk hooks API:<br>
<br>
        <a href="https://github.com/jemalloc/jemalloc/blob/master/test/integration/chunk.c" rel="noreferrer" target="_blank">https://github.com/jemalloc/jemalloc/blob/master/test/integration/chunk.c</a></blockquote><div><br></div><div><br></div><div>Thank you Jason, after some fiddling, I got my existing code rebased on top of a jemalloc managed arena. Perf looks great.</div><div><br></div><div>Thanks also for the clear answer on the second part.</div><div><br></div><div>Bill</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> 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?<br>
<br>
</span>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 <a href="http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arenas.extend" rel="noreferrer" target="_blank">http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arenas.extend</a>) 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 (<a href="http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arena.i.reset" rel="noreferrer" target="_blank">http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html#arena.i.reset</a>), which is sort of the opposite of what you want.<br>
<span class="HOEnZb"><font color="#888888"><br>
Jason</font></span></blockquote></div><br></div></div>