Skip to content

Commit

Permalink
Start jemalloc background threads manually after hugifyText
Browse files Browse the repository at this point in the history
Summary:
We cannot have threads running when remapping hottext, so don't create background threads automatically.

The background threads are only created for server mode, after hugefyText.  Script mode won't have it, which I think is fine.

When running against older versions of jemalloc (in some OSS builds), the mallctl will fail, and we log a line, but nothing bad happens.

Reviewed By: markw65

Differential Revision: D7054160

fbshipit-source-id: 3e7e8d2f093d683270959cd240a9fa21d4f7df53
  • Loading branch information
binliu19 authored and hhvm-bot committed Feb 24, 2018
1 parent e973358 commit cc86a98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions hphp/runtime/base/program-functions.cpp
Expand Up @@ -76,6 +76,7 @@
#include "hphp/runtime/vm/treadmill.h" #include "hphp/runtime/vm/treadmill.h"


#include "hphp/util/abi-cxx.h" #include "hphp/util/abi-cxx.h"
#include "hphp/util/alloc.h"
#include "hphp/util/arch.h" #include "hphp/util/arch.h"
#include "hphp/util/boot-stats.h" #include "hphp/util/boot-stats.h"
#include "hphp/util/build-info.h" #include "hphp/util/build-info.h"
Expand Down Expand Up @@ -2263,6 +2264,13 @@ void hphp_process_init() {
hphp_process_exit(); hphp_process_exit();
exit(0); exit(0);
} }

#if defined(USE_JEMALLOC) && (JEMALLOC_VERSION_MAJOR >= 5)
// jemalloc 5 has background threads, which handle purging asynchronously.
if (mallctlWrite("background_thread", true, /* errorOK */ true)) {
Logger::Warning("Failed to enable jemalloc background threads");
}
#endif
} }


static void handle_exception(bool& ret, ExecutionContext* context, static void handle_exception(bool& ret, ExecutionContext* context,
Expand Down
5 changes: 3 additions & 2 deletions hphp/util/alloc.cpp
Expand Up @@ -782,9 +782,10 @@ void thread_huge_tcache_destroy() {
extern "C" { extern "C" {
const char* malloc_conf = "narenas:1,lg_tcache_max:16" const char* malloc_conf = "narenas:1,lg_tcache_max:16"
#if (JEMALLOC_VERSION_MAJOR >= 5) #if (JEMALLOC_VERSION_MAJOR >= 5)
// FB-only as this feature does not exist in any jemalloc release as of ",background_thread:false"
// 2017-11-02 (latest: 5.0.1)
#ifdef FACEBOOK #ifdef FACEBOOK
// FB-only as this feature does not exist in any jemalloc release as of
// 2017-11-02 (latest: 5.0.1)
",metadata_thp:disabled" ",metadata_thp:disabled"
#endif #endif
#endif #endif
Expand Down

0 comments on commit cc86a98

Please sign in to comment.