From 3383af6c2dcc23a423b395a1a17eba9b24ecb200 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Thu, 11 Feb 2010 08:59:06 -0800 Subject: [PATCH] Fix a profiling bootstrap bug. Bootstrap profiling in three stages, so that it is usable by the time the first application allocation occurs. --- jemalloc/src/internal/prof.h | 1 + jemalloc/src/jemalloc.c | 20 ++++++++++++-------- jemalloc/src/prof.c | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/jemalloc/src/internal/prof.h b/jemalloc/src/internal/prof.h index 1721ad8b..1d562071 100644 --- a/jemalloc/src/internal/prof.h +++ b/jemalloc/src/internal/prof.h @@ -135,6 +135,7 @@ void prof_mdump(void); void prof_udump(void); void prof_boot0(void); bool prof_boot1(void); +void prof_boot2(void); #endif /* JEMALLOC_H_EXTERNS */ /******************************************************************************/ diff --git a/jemalloc/src/jemalloc.c b/jemalloc/src/jemalloc.c index f035d23d..6a3f53e5 100644 --- a/jemalloc/src/jemalloc.c +++ b/jemalloc/src/jemalloc.c @@ -636,10 +636,6 @@ MALLOC_OUT: } } -#ifdef JEMALLOC_PROF - prof_boot0(); -#endif - /* Register fork handlers. */ if (pthread_atfork(jemalloc_prefork, jemalloc_postfork, jemalloc_postfork) != 0) { @@ -682,6 +678,10 @@ MALLOC_OUT: return (true); } +#ifdef JEMALLOC_PROF + prof_boot0(); +#endif + if (arena_boot()) { malloc_mutex_unlock(&init_lock); return (true); @@ -725,6 +725,13 @@ MALLOC_OUT: malloc_mutex_init(&arenas_lock); +#ifdef JEMALLOC_PROF + if (prof_boot1()) { + malloc_mutex_unlock(&init_lock); + return (true); + } +#endif + /* Get number of CPUs. */ malloc_initializer = pthread_self(); malloc_mutex_unlock(&init_lock); @@ -816,10 +823,7 @@ MALLOC_OUT: #endif #ifdef JEMALLOC_PROF - if (prof_boot1()) { - malloc_mutex_unlock(&init_lock); - return (true); - } + prof_boot2(); #endif /* Allocate and initialize arenas. */ diff --git a/jemalloc/src/prof.c b/jemalloc/src/prof.c index db56659b..85b70203 100644 --- a/jemalloc/src/prof.c +++ b/jemalloc/src/prof.c @@ -1043,11 +1043,6 @@ prof_boot1(void) { if (opt_prof) { - /* - * Finish initializing prof_interval, now that narenas is set. - */ - prof_interval /= narenas; - if (ckh_new(&bt2ctx, PROF_CKH_MINITEMS, prof_bt_hash, prof_bt_keycomp)) return (true); @@ -1090,5 +1085,17 @@ prof_boot1(void) return (false); } +void +prof_boot2(void) +{ + + if (opt_prof) { + /* + * Finish initializing prof_interval, now that narenas is set. + */ + prof_interval /= narenas; + } +} + /******************************************************************************/ #endif /* JEMALLOC_PROF */