22 #include <glog/logging.h> 33 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED 41 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_CHUNK
55 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_CHUNK 57 folly::to<std::string>(
"arena.",
arena_index_,
".chunk_hooks");
61 if (
auto ret =
mallctl(key.c_str(), &hooks, &len,
nullptr, 0)) {
64 if (original_alloc_ ==
nullptr) {
65 original_alloc_ = hooks.alloc;
67 DCHECK_EQ(original_alloc_, hooks.alloc);
71 hooks.alloc = &JemallocNodumpAllocator::alloc;
73 mallctl(key.c_str(),
nullptr,
nullptr, &hooks,
sizeof(hooks))) {
78 folly::to<std::string>(
"arena.",
arena_index_,
".extent_hooks");
82 if (
auto ret =
mallctl(key.c_str(), &hooks, &len,
nullptr, 0)) {
85 if (original_alloc_ ==
nullptr) {
86 original_alloc_ = hooks->alloc;
88 DCHECK_EQ(original_alloc_, hooks->alloc);
92 extent_hooks_ = *hooks;
93 extent_hooks_.alloc = &JemallocNodumpAllocator::alloc;
96 key.c_str(),
nullptr,
nullptr, &new_hooks,
sizeof(new_hooks))) {
102 #else // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED 104 #endif // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED 115 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED 117 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_CHUNK 118 chunk_alloc_t* JemallocNodumpAllocator::original_alloc_ =
nullptr;
119 void* JemallocNodumpAllocator::alloc(
123 extent_alloc_t* JemallocNodumpAllocator::original_alloc_ =
nullptr;
124 void* JemallocNodumpAllocator::alloc(
132 unsigned arena_ind) {
133 void* result = original_alloc_(
134 JEMALLOC_CHUNK_OR_EXTENT,
135 #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_EXTENT
143 if (result !=
nullptr) {
144 if (
auto ret = madvise(result, size, MADV_DONTDUMP)) {
145 VLOG(1) <<
"Unable to madvise(MADV_DONTDUMP): " <<
errnoStr(ret);
152 #endif // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED void(* dallocx)(void *, int)
JemallocNodumpAllocator(State state=State::ENABLED)
—— Concurrent Priority Queue Implementation ——
bool extend_and_setup_arena()
constexpr auto size(C const &c) -> decltype(c.size())
int(* mallctl)(const char *, void *, size_t *, void *, size_t)
void * reallocate(void *p, size_t size)
fbstring errnoStr(int err)
void * allocate(size_t size)
void *(* mallocx)(size_t, int)
static void deallocate(void *p, void *userData)
JemallocNodumpAllocator & globalJemallocNodumpAllocator()
void *( extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, bool *, bool *, unsigned)
void *(* rallocx)(void *, size_t, int)
#define MALLOCX_TCACHE_NONE