MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / jemalloc_prefork

Function jemalloc_prefork

deps/memkind/src/jemalloc/src/jemalloc.c:3018–3085  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3016
3017#ifndef JEMALLOC_MUTEX_INIT_CB
3018void
3019jemalloc_prefork(void)
3020#else
3021JEMALLOC_EXPORT void
3022_malloc_prefork(void)
3023#endif
3024{
3025 tsd_t *tsd;
3026 unsigned i, j, narenas;
3027 arena_t *arena;
3028
3029#ifdef JEMALLOC_MUTEX_INIT_CB
3030 if (!malloc_initialized()) {
3031 return;
3032 }
3033#endif
3034 assert(malloc_initialized());
3035
3036 tsd = tsd_fetch();
3037
3038 narenas = narenas_total_get();
3039
3040 witness_prefork(tsd_witness_tsdp_get(tsd));
3041 /* Acquire all mutexes in a safe order. */
3042 ctl_prefork(tsd_tsdn(tsd));
3043 tcache_prefork(tsd_tsdn(tsd));
3044 malloc_mutex_prefork(tsd_tsdn(tsd), &arenas_lock);
3045 if (have_background_thread) {
3046 background_thread_prefork0(tsd_tsdn(tsd));
3047 }
3048 prof_prefork0(tsd_tsdn(tsd));
3049 if (have_background_thread) {
3050 background_thread_prefork1(tsd_tsdn(tsd));
3051 }
3052 /* Break arena prefork into stages to preserve lock order. */
3053 for (i = 0; i < 7; i++) {
3054 for (j = 0; j < narenas; j++) {
3055 if ((arena = arena_get(tsd_tsdn(tsd), j, false)) !=
3056 NULL) {
3057 switch (i) {
3058 case 0:
3059 arena_prefork0(tsd_tsdn(tsd), arena);
3060 break;
3061 case 1:
3062 arena_prefork1(tsd_tsdn(tsd), arena);
3063 break;
3064 case 2:
3065 arena_prefork2(tsd_tsdn(tsd), arena);
3066 break;
3067 case 3:
3068 arena_prefork3(tsd_tsdn(tsd), arena);
3069 break;
3070 case 4:
3071 arena_prefork4(tsd_tsdn(tsd), arena);
3072 break;
3073 case 5:
3074 arena_prefork5(tsd_tsdn(tsd), arena);
3075 break;

Callers 1

zone_force_lockFunction · 0.70

Calls 15

malloc_initializedFunction · 0.70
narenas_total_getFunction · 0.70
witness_preforkFunction · 0.70
ctl_preforkFunction · 0.70
tcache_preforkFunction · 0.70
malloc_mutex_preforkFunction · 0.70
prof_prefork0Function · 0.70
arena_prefork0Function · 0.70
arena_prefork1Function · 0.70
arena_prefork2Function · 0.70

Tested by

no test coverage detected