Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support reset jemalloc arena name #12985

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/rocksdb/memory_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ struct JemallocAllocatorOptions {
// this setting can mitigate arena mutex contention. The value must be
// positive.
size_t num_arenas = 1;

// If "" then use default arena name.
// If not "" then use arena name with prefix, length <= 20.
// e.g arena_name_prefix:"rocksdb_", then arena name is "rocksdb_1", 1 is index of num_arenas.
std::string arena_name_prefix = "";
};

// Generate memory allocator which allocates through Jemalloc and utilize
Expand Down
23 changes: 23 additions & 0 deletions memory/jemalloc_nodump_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ uint32_t JemallocNodumpAllocator::GetArenaIndex() const {
tl_random.Next(), static_cast<uint32_t>(arena_indexes_.size()))];
}

static bool RenameArena(int arena_index, const char* new_arena_name) {
size_t mib[3];
size_t miblen = sizeof(mib) / sizeof(size_t);

// ref:https://github.com/jemalloc/jemalloc/blob/dev/test/unit/mallctl.c#L742
const std::string name_ctl = "arena." + std::to_string(arena_index) + ".name";
mallctlnametomib(name_ctl.c_str(), mib, &miblen);

int ret = mallctlbymib(mib, miblen, nullptr, nullptr, (void*)&new_arena_name, sizeof(new_arena_name));
if (ret != 0) {
std::cout << "mallctlbymib:" << ret << " " << strerror(errno);
return false;
}
return true;
}

Status JemallocNodumpAllocator::InitializeArenas() {
assert(!init_);
init_ = true;
Expand All @@ -145,6 +161,13 @@ Status JemallocNodumpAllocator::InitializeArenas() {
}
arena_indexes_.push_back(arena_index);

if (!options_.arena_name_prefix.empty() && options_.arena_name_prefix.size() <= 20) {
std::string new_arena_name = options_.arena_name_prefix + std::to_string(i);
if (!RenameArena(arena_index, new_arena_name.c_str())) {
return Status::Incomplete("Failed to rename arena." + new_arena_name);
}
}

// Read existing hooks.
std::string key =
"arena." + std::to_string(arena_indexes_[i]) + ".extent_hooks";
Expand Down