proxygen
|
#include <JemallocNodumpAllocator.h>
Public Types | |
enum | State { State::ENABLED, State::DISABLED } |
Public Member Functions | |
JemallocNodumpAllocator (State state=State::ENABLED) | |
void * | allocate (size_t size) |
void * | reallocate (void *p, size_t size) |
void | deallocate (void *p, size_t=0) |
unsigned | getArenaIndex () const |
int | getFlags () const |
Static Public Member Functions | |
static void | deallocate (void *p, void *userData) |
Private Member Functions | |
bool | extend_and_setup_arena () |
Private Attributes | |
unsigned | arena_index_ {0} |
int | flags_ {0} |
An allocator which uses Jemalloc to create an dedicated arena to allocate memory from. The only special property set on the allocated memory is that the memory is not dump-able.
This is done by setting MADV_DONTDUMP using the madvise
system call. A custom hook installed which is called when allocating a new chunk / extent of memory. All it does is call the original jemalloc hook to allocate the memory and then set the advise on it before returning the pointer to the allocated memory. Jemalloc does not use allocated chunks / extents across different arenas, without munmap
-ing them first, and the advises are not sticky i.e. they are unset if munmap
is done. Also this arena can't be used by any other part of the code by just calling malloc
.
If target system doesn't support MADV_DONTDUMP or jemalloc doesn't support custom arena hook, JemallocNodumpAllocator would fall back to using malloc / free. Such behavior can be identified by using !defined(FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED).
Similarly, if binary isn't linked with jemalloc, the logic would fall back to malloc / free.
Definition at line 68 of file JemallocNodumpAllocator.h.
|
strong |
Enumerator | |
---|---|
ENABLED | |
DISABLED |
Definition at line 70 of file JemallocNodumpAllocator.h.
|
explicit |
Definition at line 26 of file JemallocNodumpAllocator.cpp.
References arena_index_, ENABLED, extend_and_setup_arena(), and folly::INFO.
Referenced by folly::globalJemallocNodumpAllocator().
void * folly::JemallocNodumpAllocator::allocate | ( | size_t | size | ) |
Definition at line 107 of file JemallocNodumpAllocator.cpp.
References flags_, and mallocx.
Referenced by TEST().
|
static |
Definition at line 158 of file JemallocNodumpAllocator.cpp.
References dallocx, bm::free(), and uint64_t.
Referenced by TEST().
void folly::JemallocNodumpAllocator::deallocate | ( | void * | p, |
size_t | = 0 |
||
) |
Definition at line 154 of file JemallocNodumpAllocator.cpp.
References dallocx, flags_, and bm::free().
|
private |
Definition at line 32 of file JemallocNodumpAllocator.cpp.
References arena_index_, folly::errnoStr(), folly::FATAL, flags_, mallctl, MALLOCX_ARENA, and MALLOCX_TCACHE_NONE.
Referenced by getFlags(), and JemallocNodumpAllocator().
|
inline |
Definition at line 85 of file JemallocNodumpAllocator.h.
References arena_index_.
Referenced by TEST().
|
inline |
Definition at line 88 of file JemallocNodumpAllocator.h.
References extend_and_setup_arena(), and flags_.
void * folly::JemallocNodumpAllocator::reallocate | ( | void * | p, |
size_t | size | ||
) |
Definition at line 111 of file JemallocNodumpAllocator.cpp.
References folly::errnoStr(), flags_, rallocx, and folly::size().
|
private |
Definition at line 114 of file JemallocNodumpAllocator.h.
Referenced by extend_and_setup_arena(), getArenaIndex(), and JemallocNodumpAllocator().
|
private |
Definition at line 115 of file JemallocNodumpAllocator.h.
Referenced by allocate(), deallocate(), extend_and_setup_arena(), getFlags(), and reallocate().