From 79ab7c63d7e86a063f547b72549a05c73e03b841 Mon Sep 17 00:00:00 2001 From: Daan Date: Sat, 20 Apr 2024 16:37:09 -0700 Subject: [PATCH] disable transparent huge pages for a process too if the allow_large_os_pages option is set to false --- src/prim/unix/prim.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/prim/unix/prim.c b/src/prim/unix/prim.c index 9c4ecd4b..a7812cb6 100644 --- a/src/prim/unix/prim.c +++ b/src/prim/unix/prim.c @@ -148,13 +148,20 @@ void _mi_prim_mem_init( mi_os_mem_config_t* config ) config->has_virtual_reserve = true; // todo: check if this true for NetBSD? (for anonymous mmap with PROT_NONE) // disable transparent huge pages for this process? - #if defined(MI_NO_THP) && (defined(__linux__) || defined(__ANDROID__)) - int val = 0; - if (prctl(PR_GET_THP_DISABLE, &val, 0, 0, 0) != 0) { - // Most likely since distros often come with always/madvise settings. - val = 1; - // Disabling only for mimalloc process rather than touching system wide settings - (void)prctl(PR_SET_THP_DISABLE, &val, 0, 0, 0); + #if (defined(__linux__) || defined(__ANDROID__)) && defined(PR_GET_THP_DISABLE) + #if defined(MI_NO_THP) + if (true) + #else + if (!mi_option_is_enabled(mi_option_allow_large_os_pages)) // disable THP also if large OS pages are not allowed in the options + #endif + { + int val = 0; + if (prctl(PR_GET_THP_DISABLE, &val, 0, 0, 0) != 0) { + // Most likely since distros often come with always/madvise settings. + val = 1; + // Disabling only for mimalloc process rather than touching system wide settings + (void)prctl(PR_SET_THP_DISABLE, &val, 0, 0, 0); + } } #endif }