adding option to disable thp on linux/android.

This commit is contained in:
David Carlier
2024-05-17 22:12:25 +01:00
parent 955f44b6c3
commit 565e92b6cc
2 changed files with 12 additions and 0 deletions

View File

@@ -2095,6 +2095,11 @@ rpmalloc_initialize(rpmalloc_interface_t* memory_interface) {
if (global_config.enable_huge_pages || global_config.page_size > (256 * 1024))
global_config.disable_decommit = 1;
#if defined(__linux__) || defined(__ANDROID__)
if (global_config.disable_thp)
(void)prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
#endif
#ifdef _WIN32
fls_key = FlsAlloc(&rpmalloc_thread_destructor);
#else

View File

@@ -187,6 +187,13 @@ typedef struct rpmalloc_config_t {
// when process exits, but if using rpmalloc in a dynamic library you might want to unmap
// all pages when the dynamic library unloads to avoid process memory leaks and bloat.
int unmap_on_finalize;
#if defined(__linux__) || defined(__ANDROID__)
///! Allows to disable the Transparent Huge Page feature on Linux on a process basis,
/// rather than enabling/disabling system-wise (done via /sys/kernel/mm/transparent_hugepage/enabled).
/// It can possibly improve performance and reduced allocation overhead in some contexts, albeit
/// THP is usually enabled by default.
int disable_thp;
#endif
} rpmalloc_config_t;
//! Initialize allocator