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

Function jemalloc_prefork

deps/jemalloc/src/jemalloc.c:3780–3851  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3778
3779#ifndef JEMALLOC_MUTEX_INIT_CB
3780void
3781jemalloc_prefork(void)
3782#else
3783JEMALLOC_EXPORT void
3784_malloc_prefork(void)
3785#endif
3786{
3787 tsd_t *tsd;
3788 unsigned i, j, narenas;
3789 arena_t *arena;
3790
3791#ifdef JEMALLOC_MUTEX_INIT_CB
3792 if (!malloc_initialized()) {
3793 return;
3794 }
3795#endif
3796 assert(malloc_initialized());
3797
3798 tsd = tsd_fetch();
3799
3800 narenas = narenas_total_get();
3801
3802 witness_prefork(tsd_witness_tsdp_get(tsd));
3803 /* Acquire all mutexes in a safe order. */
3804 ctl_prefork(tsd_tsdn(tsd));
3805 tcache_prefork(tsd_tsdn(tsd));
3806 malloc_mutex_prefork(tsd_tsdn(tsd), &arenas_lock);
3807 if (have_background_thread) {
3808 background_thread_prefork0(tsd_tsdn(tsd));
3809 }
3810 prof_prefork0(tsd_tsdn(tsd));
3811 if (have_background_thread) {
3812 background_thread_prefork1(tsd_tsdn(tsd));
3813 }
3814 /* Break arena prefork into stages to preserve lock order. */
3815 for (i = 0; i < 8; i++) {
3816 for (j = 0; j < narenas; j++) {
3817 if ((arena = arena_get(tsd_tsdn(tsd), j, false)) !=
3818 NULL) {
3819 switch (i) {
3820 case 0:
3821 arena_prefork0(tsd_tsdn(tsd), arena);
3822 break;
3823 case 1:
3824 arena_prefork1(tsd_tsdn(tsd), arena);
3825 break;
3826 case 2:
3827 arena_prefork2(tsd_tsdn(tsd), arena);
3828 break;
3829 case 3:
3830 arena_prefork3(tsd_tsdn(tsd), arena);
3831 break;
3832 case 4:
3833 arena_prefork4(tsd_tsdn(tsd), arena);
3834 break;
3835 case 5:
3836 arena_prefork5(tsd_tsdn(tsd), arena);
3837 break;

Callers 1

zone_force_lockFunction · 0.70

Calls 15

arena_prefork7Function · 0.85
tsd_preforkFunction · 0.85
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

Tested by

no test coverage detected