Commit 028e9512 authored by Qi Wang's avatar Qi Wang Committed by Facebook Github Bot

Fix JemallocNodumpAllocator destructor w/ jemalloc 5.0.

Summary: Destroy created arena which has extent_hooks linked.

Reviewed By: jasone

Differential Revision: D5177535

fbshipit-source-id: 7d75f4276fc174c4d4ce1102dfb8ec8c27c1f56d
parent 4ce8cc70
...@@ -29,6 +29,19 @@ JemallocNodumpAllocator::JemallocNodumpAllocator(State state) { ...@@ -29,6 +29,19 @@ JemallocNodumpAllocator::JemallocNodumpAllocator(State state) {
} }
} }
JemallocNodumpAllocator::~JemallocNodumpAllocator() {
#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_EXTENT
if (arena_index_ != 0) {
// Destroy the arena because the hooks are linked to us.
const auto key = folly::to<std::string>("arena.", arena_index_, ".destroy");
if (auto ret = mallctl(key.c_str(), nullptr, 0, nullptr, 0)) {
LOG(FATAL) << "Unable to destroy arena: " << errnoStr(ret);
}
LOG(INFO) << "Destroy arena: " << arena_index_;
}
#endif
}
bool JemallocNodumpAllocator::extend_and_setup_arena() { bool JemallocNodumpAllocator::extend_and_setup_arena() {
#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
if (mallctl == nullptr) { if (mallctl == nullptr) {
...@@ -91,8 +104,9 @@ bool JemallocNodumpAllocator::extend_and_setup_arena() { ...@@ -91,8 +104,9 @@ bool JemallocNodumpAllocator::extend_and_setup_arena() {
// Set the custom hook // Set the custom hook
extent_hooks_ = *hooks; extent_hooks_ = *hooks;
extent_hooks_.alloc = &JemallocNodumpAllocator::alloc; extent_hooks_.alloc = &JemallocNodumpAllocator::alloc;
if (auto ret = extent_hooks_t* new_hooks = &extent_hooks_;
mallctl(key.c_str(), nullptr, nullptr, &hooks, sizeof(hooks))) { if (auto ret = mallctl(
key.c_str(), nullptr, nullptr, &new_hooks, sizeof(new_hooks))) {
LOG(FATAL) << "Unable to set the hooks: " << errnoStr(ret); LOG(FATAL) << "Unable to set the hooks: " << errnoStr(ret);
} }
#endif #endif
......
...@@ -76,6 +76,7 @@ class JemallocNodumpAllocator { ...@@ -76,6 +76,7 @@ class JemallocNodumpAllocator {
static void deallocate(void* p, void* userData); static void deallocate(void* p, void* userData);
explicit JemallocNodumpAllocator(State state = State::ENABLED); explicit JemallocNodumpAllocator(State state = State::ENABLED);
~JemallocNodumpAllocator();
void* allocate(size_t size); void* allocate(size_t size);
void* reallocate(void* p, size_t size); void* reallocate(void* p, size_t size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment