From: Qi Wang Date: Mon, 5 Jun 2017 19:45:43 +0000 (-0700) Subject: Fix JemallocNodumpAllocator destructor w/ jemalloc 5.0. X-Git-Tag: v2017.06.12.00~43 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=028e9512812ffc80654f17641d750f6ef57a4ef1;p=folly.git 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 --- diff --git a/folly/experimental/JemallocNodumpAllocator.cpp b/folly/experimental/JemallocNodumpAllocator.cpp index 8d29dbc8..77d9724b 100644 --- a/folly/experimental/JemallocNodumpAllocator.cpp +++ b/folly/experimental/JemallocNodumpAllocator.cpp @@ -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("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() { #ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED if (mallctl == nullptr) { @@ -91,8 +104,9 @@ bool JemallocNodumpAllocator::extend_and_setup_arena() { // Set the custom hook extent_hooks_ = *hooks; extent_hooks_.alloc = &JemallocNodumpAllocator::alloc; - if (auto ret = - mallctl(key.c_str(), nullptr, nullptr, &hooks, sizeof(hooks))) { + extent_hooks_t* new_hooks = &extent_hooks_; + if (auto ret = mallctl( + key.c_str(), nullptr, nullptr, &new_hooks, sizeof(new_hooks))) { LOG(FATAL) << "Unable to set the hooks: " << errnoStr(ret); } #endif diff --git a/folly/experimental/JemallocNodumpAllocator.h b/folly/experimental/JemallocNodumpAllocator.h index a87161f0..40ebe99e 100644 --- a/folly/experimental/JemallocNodumpAllocator.h +++ b/folly/experimental/JemallocNodumpAllocator.h @@ -76,6 +76,7 @@ class JemallocNodumpAllocator { static void deallocate(void* p, void* userData); explicit JemallocNodumpAllocator(State state = State::ENABLED); + ~JemallocNodumpAllocator(); void* allocate(size_t size); void* reallocate(void* p, size_t size);