mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 01:54:01 +02:00
Support jemalloc as the default allocator on Linux (#7250)
Add jemalloc as an alternative malloc implementation for the Verilator binary. When both tcmalloc and jemalloc are available, jemalloc is preferred due to its better performance on RTLMeter. The new --enable-jemalloc flag (default=check) mirrors the existing --enable-tcmalloc behavior: auto-detected at configure time, supports both static and dynamic linking, and is disabled when --enable-dev-asan is active.
This commit is contained in:
@@ -57,6 +57,9 @@ VL_DEFINE_DEBUG_FUNCTIONS;
|
||||
#ifdef HAVE_TCMALLOC
|
||||
#include <gperftools/malloc_extension.h>
|
||||
#endif
|
||||
#ifdef HAVE_JEMALLOC
|
||||
#include <jemalloc/jemalloc.h>
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
@@ -413,6 +416,18 @@ void V3Os::releaseMemory() {
|
||||
#ifdef HAVE_TCMALLOC
|
||||
MallocExtension::instance()->ReleaseFreeMemory();
|
||||
#endif
|
||||
#ifdef HAVE_JEMALLOC
|
||||
// Purge all unused dirty pages across all arenas
|
||||
unsigned narenas = 0;
|
||||
size_t sz = sizeof(narenas);
|
||||
if (mallctl("arenas.narenas", &narenas, &sz, nullptr, 0)) {
|
||||
return; // Failed to get number of arenas, give up
|
||||
}
|
||||
char buf[64];
|
||||
// Index equal to narenas represents all arenas
|
||||
VL_SNPRINTF(buf, sizeof(buf), "arena.%u.purge", narenas);
|
||||
mallctl(buf, nullptr, nullptr, nullptr, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
|
||||
Reference in New Issue
Block a user