Skip to content

Commit

Permalink
core: use malloc instead of region allocator in procedure name cache
Browse files Browse the repository at this point in the history
The procedure name cache uses a region for hash table entry allocation, but
the cache is a thread local variable, while the `region` uses a `slab`
allocator the lifetime of which is bounded by `main`, while thread locals
are destroyed after `main`: use the `malloc` allocator instead.

Benchmark from #7207 shows that this change does not effect performance.

Closes #8777

NO_CHANGELOG=<leak does not affect users>
NO_DOC=bugfix
NO_TEST=<detected by ASAN>

(cherry picked from commit 7135910)
  • Loading branch information
CuriousGeorgiy authored and locker committed Jun 23, 2023
1 parent 9351a09 commit 95cdf5a
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/lib/core/proc_name_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@ struct ProcNameCache final {
}

mh_i64ptr_t *proc_name_cache;
region proc_name_cache_entry_region;

private:
ProcNameCache() noexcept : proc_name_cache{mh_i64ptr_new()},
proc_name_cache_entry_region{}
ProcNameCache() noexcept : proc_name_cache{mh_i64ptr_new()}
{
region_create(&proc_name_cache_entry_region, &cord()->slabc);
}

~ProcNameCache()
{
region_destroy(&proc_name_cache_entry_region);
mh_int_t i;
mh_foreach(proc_name_cache, i)
free(mh_i64ptr_node(proc_name_cache, i)->val);
mh_i64ptr_delete(proc_name_cache);
}
};
Expand All @@ -71,14 +70,8 @@ proc_name_cache_find(unw_word_t ip, unw_word_t *offs)
void
proc_name_cache_insert(unw_word_t ip, const char *name, unw_word_t offs)
{
region *proc_name_cache_entry_region =
&ProcNameCache::instance().proc_name_cache_entry_region;
size_t sz;
proc_name_cache_entry *entry =
region_alloc_object(proc_name_cache_entry_region,
typeof(*entry), &sz);
if (unlikely(entry == nullptr))
return;
auto entry = static_cast<proc_name_cache_entry *>(xmalloc(
sizeof(proc_name_cache_entry)));
entry->offset = offs;
strlcpy(entry->name, name, PROC_NAME_MAX);
mh_i64ptr_node_t node = {ip, entry};
Expand Down

0 comments on commit 95cdf5a

Please sign in to comment.