Custom Arenas ?

Jason Evans jasone at canonware.com
Tue Dec 3 10:54:36 PST 2013


On Dec 3, 2013, at 10:15 AM, Eduardo Silva <edsiper at gmail.com> wrote:
> i am wondering if Jemalloc support to have custom arenas, despites the arenas it spawn on startup i would like to know if i can create a specific arena and force it usage on specific modules of my application, on that way i can track and get stats from specific parts of my application. Is that possible ?

Yes, that is possible starting with jemalloc 3.1.0, though there's an important related bugfix in 3.4.1.  You can use the "arenas.extend" mallctl to create an additional arena that is not otherwise used by jemalloc, and then use the *allocm() API with the ALLOCM_ARENA() flag set to refer to your arena.  Two caveats:

- You could use the "thread.arena" mallctl to assign the calling thread to your arena, but I recommend against that for short-term arena selection.  I tentatively plan to change thread<-->arena association logic in 4.0.0 such that arena selection is optionally based on current CPU rather than being a fixed assignment; that functionality may interact poorly with explicit thread<-->arena association.
- You need to specify ALLOCM_ARENA() to dallocm() in order to bypass thread caching.  If you don't do so, a subsequent malloc() call may end up getting a cached region that came from your arena.

Jason


More information about the jemalloc-discuss mailing list