2017-04-11 09:17:55 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_preamble.h"
|
|
|
|
#include "jemalloc/internal/jemalloc_internal_includes.h"
|
|
|
|
|
2019-09-10 11:18:41 +08:00
|
|
|
#include "jemalloc/internal/ctl.h"
|
2017-04-12 05:43:12 +08:00
|
|
|
#include "jemalloc/internal/assert.h"
|
2017-05-24 03:28:19 +08:00
|
|
|
#include "jemalloc/internal/mutex.h"
|
2020-01-24 05:18:04 +08:00
|
|
|
#include "jemalloc/internal/counter.h"
|
2019-12-23 12:02:28 +08:00
|
|
|
#include "jemalloc/internal/prof_data.h"
|
|
|
|
#include "jemalloc/internal/prof_log.h"
|
2019-12-19 05:38:14 +08:00
|
|
|
#include "jemalloc/internal/prof_recent.h"
|
2020-12-19 09:14:59 +08:00
|
|
|
#include "jemalloc/internal/prof_stats.h"
|
2020-04-01 00:02:55 +08:00
|
|
|
#include "jemalloc/internal/prof_sys.h"
|
2019-09-04 06:04:48 +08:00
|
|
|
#include "jemalloc/internal/thread_event.h"
|
2017-04-12 04:06:31 +08:00
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
/*
|
|
|
|
* This file implements the profiling "APIs" needed by other parts of jemalloc,
|
|
|
|
* and also manages the relevant "operational" data, mainly options and mutexes;
|
|
|
|
* the core profiling data structures are encapsulated in prof_data.c.
|
|
|
|
*/
|
|
|
|
|
2010-02-11 02:37:56 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
/* Data. */
|
|
|
|
|
2019-12-07 01:45:40 +08:00
|
|
|
bool opt_prof = false;
|
|
|
|
bool opt_prof_active = true;
|
|
|
|
bool opt_prof_thread_active_init = true;
|
|
|
|
size_t opt_lg_prof_sample = LG_PROF_SAMPLE_DEFAULT;
|
|
|
|
ssize_t opt_lg_prof_interval = LG_PROF_INTERVAL_DEFAULT;
|
|
|
|
bool opt_prof_gdump = false;
|
|
|
|
bool opt_prof_final = false;
|
|
|
|
bool opt_prof_leak = false;
|
|
|
|
bool opt_prof_accum = false;
|
|
|
|
char opt_prof_prefix[PROF_DUMP_FILENAME_LEN];
|
2020-06-20 06:16:53 +08:00
|
|
|
bool opt_prof_sys_thread_name = false;
|
2020-08-04 04:05:34 +08:00
|
|
|
bool opt_prof_unbias = true;
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2020-04-18 01:38:06 +08:00
|
|
|
/* Accessed via prof_sample_event_handler(). */
|
2020-01-24 05:18:04 +08:00
|
|
|
static counter_accum_t prof_idump_accumulated;
|
2019-10-15 00:35:51 +08:00
|
|
|
|
2014-10-04 14:25:30 +08:00
|
|
|
/*
|
|
|
|
* Initialized as opt_prof_active, and accessed via
|
|
|
|
* prof_active_[gs]et{_unlocked,}().
|
|
|
|
*/
|
2019-12-07 01:45:40 +08:00
|
|
|
bool prof_active;
|
|
|
|
static malloc_mutex_t prof_active_mtx;
|
2014-10-04 14:25:30 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialized as opt_prof_thread_active_init, and accessed via
|
|
|
|
* prof_thread_active_init_[gs]et().
|
|
|
|
*/
|
2019-12-07 01:45:40 +08:00
|
|
|
static bool prof_thread_active_init;
|
|
|
|
static malloc_mutex_t prof_thread_active_init_mtx;
|
2014-10-04 14:25:30 +08:00
|
|
|
|
2015-01-26 13:16:57 +08:00
|
|
|
/*
|
|
|
|
* Initialized as opt_prof_gdump, and accessed via
|
|
|
|
* prof_gdump_[gs]et{_unlocked,}().
|
|
|
|
*/
|
2019-12-07 01:45:40 +08:00
|
|
|
bool prof_gdump_val;
|
|
|
|
static malloc_mutex_t prof_gdump_mtx;
|
2015-01-26 13:16:57 +08:00
|
|
|
|
2019-12-07 01:45:40 +08:00
|
|
|
uint64_t prof_interval = 0;
|
2010-02-12 05:19:21 +08:00
|
|
|
|
2019-12-07 01:45:40 +08:00
|
|
|
size_t lg_prof_sample;
|
2014-08-19 07:22:13 +08:00
|
|
|
|
2019-12-07 01:45:40 +08:00
|
|
|
static uint64_t next_thr_uid;
|
|
|
|
static malloc_mutex_t next_thr_uid_mtx;
|
2010-03-02 12:15:26 +08:00
|
|
|
|
2010-02-11 02:37:56 +08:00
|
|
|
/* Do not dump any profiles until bootstrapping is complete. */
|
2019-12-07 01:45:40 +08:00
|
|
|
bool prof_booted = false;
|
2010-02-11 02:37:56 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-08-19 07:22:13 +08:00
|
|
|
|
2014-09-10 10:37:26 +08:00
|
|
|
void
|
2020-03-10 06:49:15 +08:00
|
|
|
prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx) {
|
2014-09-10 10:37:26 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2019-10-04 04:01:12 +08:00
|
|
|
if (tsd_reentrancy_level_get(tsd) > 0) {
|
|
|
|
assert((uintptr_t)tctx == (uintptr_t)1U);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-10 10:37:26 +08:00
|
|
|
if ((uintptr_t)tctx > (uintptr_t)1U) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), tctx->tdata->lock);
|
2014-09-10 10:37:26 +08:00
|
|
|
tctx->prepared = false;
|
2019-12-11 02:46:31 +08:00
|
|
|
prof_tctx_try_destroy(tsd, tctx);
|
2014-09-10 10:37:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 07:22:13 +08:00
|
|
|
void
|
2020-01-10 02:20:34 +08:00
|
|
|
prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t size,
|
|
|
|
size_t usize, prof_tctx_t *tctx) {
|
2020-08-22 06:33:50 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2020-06-20 06:16:53 +08:00
|
|
|
if (opt_prof_sys_thread_name) {
|
|
|
|
prof_sys_thread_name_fetch(tsd);
|
2020-03-25 08:53:41 +08:00
|
|
|
}
|
|
|
|
|
2020-03-15 01:49:34 +08:00
|
|
|
edata_t *edata = emap_edata_lookup(tsd_tsdn(tsd), &arena_emap_global,
|
|
|
|
ptr);
|
2020-08-22 02:31:53 +08:00
|
|
|
prof_info_set(tsd, edata, tctx, size);
|
2018-07-06 01:56:33 +08:00
|
|
|
|
2020-08-27 05:52:25 +08:00
|
|
|
szind_t szind = sz_size2index(usize);
|
2020-08-04 04:05:34 +08:00
|
|
|
|
2019-11-23 03:42:01 +08:00
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), tctx->tdata->lock);
|
2020-08-04 04:05:34 +08:00
|
|
|
/*
|
|
|
|
* We need to do these map lookups while holding the lock, to avoid the
|
|
|
|
* possibility of races with prof_reset calls, which update the map and
|
|
|
|
* then acquire the lock. This actually still leaves a data race on the
|
|
|
|
* contents of the unbias map, but we have not yet gone through and
|
|
|
|
* atomic-ified the prof module, and compilers are not yet causing us
|
|
|
|
* issues. The key thing is to make sure that, if we read garbage data,
|
|
|
|
* the prof_reset call is about to mark our tctx as expired before any
|
|
|
|
* dumping of our corrupted output is attempted.
|
|
|
|
*/
|
|
|
|
size_t shifted_unbiased_cnt = prof_shifted_unbiased_cnt[szind];
|
|
|
|
size_t unbiased_bytes = prof_unbiased_sz[szind];
|
2014-08-19 07:22:13 +08:00
|
|
|
tctx->cnts.curobjs++;
|
2020-08-04 04:05:34 +08:00
|
|
|
tctx->cnts.curobjs_shifted_unbiased += shifted_unbiased_cnt;
|
2014-08-19 07:22:13 +08:00
|
|
|
tctx->cnts.curbytes += usize;
|
2020-08-04 04:05:34 +08:00
|
|
|
tctx->cnts.curbytes_unbiased += unbiased_bytes;
|
2014-08-19 07:22:13 +08:00
|
|
|
if (opt_prof_accum) {
|
|
|
|
tctx->cnts.accumobjs++;
|
2020-08-04 04:05:34 +08:00
|
|
|
tctx->cnts.accumobjs_shifted_unbiased += shifted_unbiased_cnt;
|
2014-08-19 07:22:13 +08:00
|
|
|
tctx->cnts.accumbytes += usize;
|
2020-08-04 04:05:34 +08:00
|
|
|
tctx->cnts.accumbytes_unbiased += unbiased_bytes;
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
2019-12-19 05:38:14 +08:00
|
|
|
bool record_recent = prof_recent_alloc_prepare(tsd, tctx);
|
2014-09-10 10:37:26 +08:00
|
|
|
tctx->prepared = false;
|
2019-11-23 03:42:01 +08:00
|
|
|
malloc_mutex_unlock(tsd_tsdn(tsd), tctx->tdata->lock);
|
2019-12-19 05:38:14 +08:00
|
|
|
if (record_recent) {
|
|
|
|
assert(tctx == edata_prof_tctx_get(edata));
|
2020-08-12 06:35:41 +08:00
|
|
|
prof_recent_alloc(tsd, edata, size, usize);
|
2019-12-19 05:38:14 +08:00
|
|
|
}
|
2020-12-19 09:14:59 +08:00
|
|
|
|
|
|
|
if (opt_prof_stats) {
|
|
|
|
prof_stats_inc(tsd, szind, size);
|
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-11-20 08:24:57 +08:00
|
|
|
prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info) {
|
2020-08-22 06:33:50 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2019-11-20 08:24:57 +08:00
|
|
|
assert(prof_info != NULL);
|
2019-12-06 07:35:12 +08:00
|
|
|
prof_tctx_t *tctx = prof_info->alloc_tctx;
|
2019-11-20 08:24:57 +08:00
|
|
|
assert((uintptr_t)tctx > (uintptr_t)1U);
|
|
|
|
|
2020-08-04 04:05:34 +08:00
|
|
|
szind_t szind = sz_size2index(usize);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsd_tsdn(tsd), tctx->tdata->lock);
|
2018-07-06 01:56:33 +08:00
|
|
|
|
2014-08-19 07:22:13 +08:00
|
|
|
assert(tctx->cnts.curobjs > 0);
|
|
|
|
assert(tctx->cnts.curbytes >= usize);
|
2020-08-04 04:05:34 +08:00
|
|
|
/*
|
|
|
|
* It's not correct to do equivalent asserts for unbiased bytes, because
|
|
|
|
* of the potential for races with prof.reset calls. The map contents
|
|
|
|
* should really be atomic, but we have not atomic-ified the prof module
|
|
|
|
* yet.
|
|
|
|
*/
|
2014-08-19 07:22:13 +08:00
|
|
|
tctx->cnts.curobjs--;
|
2020-08-04 04:05:34 +08:00
|
|
|
tctx->cnts.curobjs_shifted_unbiased -= prof_shifted_unbiased_cnt[szind];
|
2014-08-19 07:22:13 +08:00
|
|
|
tctx->cnts.curbytes -= usize;
|
2020-08-04 04:05:34 +08:00
|
|
|
tctx->cnts.curbytes_unbiased -= prof_unbiased_sz[szind];
|
2014-08-19 07:22:13 +08:00
|
|
|
|
2019-11-20 08:24:57 +08:00
|
|
|
prof_try_log(tsd, usize, prof_info);
|
2018-07-06 01:56:33 +08:00
|
|
|
|
2019-12-11 02:46:31 +08:00
|
|
|
prof_tctx_try_destroy(tsd, tctx);
|
2020-12-19 09:14:59 +08:00
|
|
|
|
|
|
|
if (opt_prof_stats) {
|
|
|
|
prof_stats_dec(tsd, szind, prof_info->alloc_size);
|
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
2014-08-17 03:58:55 +08:00
|
|
|
|
2020-04-04 02:19:51 +08:00
|
|
|
prof_tctx_t *
|
|
|
|
prof_tctx_create(tsd_t *tsd) {
|
|
|
|
if (!tsd_nominal(tsd) || tsd_reentrancy_level_get(tsd) > 0) {
|
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-02-11 12:22:09 +08:00
|
|
|
|
2020-04-04 02:19:51 +08:00
|
|
|
prof_tdata_t *tdata = prof_tdata_get(tsd, true);
|
|
|
|
if (tdata == NULL) {
|
|
|
|
return NULL;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2020-04-04 02:19:51 +08:00
|
|
|
prof_bt_t bt;
|
|
|
|
bt_init(&bt, tdata->vec);
|
|
|
|
prof_backtrace(tsd, &bt);
|
|
|
|
return prof_lookup(tsd, &bt);
|
2019-09-04 08:11:06 +08:00
|
|
|
}
|
|
|
|
|
2016-05-05 03:14:36 +08:00
|
|
|
/*
|
|
|
|
* The bodies of this function and prof_leakcheck() are compiled out unless heap
|
|
|
|
* profiling is enabled, so that it is possible to compile jemalloc with
|
|
|
|
* floating point support completely disabled. Avoiding floating point code is
|
|
|
|
* important on memory-constrained systems, but it also enables a workaround for
|
|
|
|
* versions of glibc that don't properly save/restore floating point registers
|
|
|
|
* during dynamic lazy symbol loading (which internally calls into whatever
|
|
|
|
* malloc implementation happens to be integrated into the application). Note
|
|
|
|
* that some compilers (e.g. gcc 4.8) may use floating point registers for fast
|
|
|
|
* memory moves, so jemalloc must be compiled with such optimizations disabled
|
|
|
|
* (e.g.
|
|
|
|
* -mno-sse) in order for the workaround to be complete.
|
|
|
|
*/
|
2020-04-16 01:49:08 +08:00
|
|
|
uint64_t
|
|
|
|
prof_sample_new_event_wait(tsd_t *tsd) {
|
2014-04-16 04:47:13 +08:00
|
|
|
#ifdef JEMALLOC_PROF
|
2014-08-19 07:22:13 +08:00
|
|
|
if (lg_prof_sample == 0) {
|
2020-04-16 01:49:08 +08:00
|
|
|
return TE_MIN_START_WAIT;
|
2014-04-16 04:47:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-08-19 07:22:13 +08:00
|
|
|
* Compute sample interval as a geometrically distributed random
|
|
|
|
* variable with mean (2^lg_prof_sample).
|
2014-04-16 04:47:13 +08:00
|
|
|
*
|
2019-09-04 06:04:48 +08:00
|
|
|
* __ __
|
|
|
|
* | log(u) | 1
|
|
|
|
* bytes_until_sample = | -------- |, where p = ---------------
|
|
|
|
* | log(1-p) | lg_prof_sample
|
|
|
|
* 2
|
2014-04-16 04:47:13 +08:00
|
|
|
*
|
|
|
|
* For more information on the math, see:
|
|
|
|
*
|
|
|
|
* Non-Uniform Random Variate Generation
|
|
|
|
* Luc Devroye
|
|
|
|
* Springer-Verlag, New York, 1986
|
|
|
|
* pp 500
|
|
|
|
* (http://luc.devroye.org/rnbookindex.html)
|
2020-03-05 02:27:30 +08:00
|
|
|
*
|
|
|
|
* In the actual computation, there's a non-zero probability that our
|
|
|
|
* pseudo random number generator generates an exact 0, and to avoid
|
|
|
|
* log(0), we set u to 1.0 in case r is 0. Therefore u effectively is
|
|
|
|
* uniformly distributed in (0, 1] instead of [0, 1). Further, rather
|
|
|
|
* than taking the ceiling, we take the floor and then add 1, since
|
|
|
|
* otherwise bytes_until_sample would be 0 if u is exactly 1.0.
|
2014-04-16 04:47:13 +08:00
|
|
|
*/
|
2019-11-05 09:22:25 +08:00
|
|
|
uint64_t r = prng_lg_range_u64(tsd_prng_statep_get(tsd), 53);
|
2020-03-05 02:27:30 +08:00
|
|
|
double u = (r == 0U) ? 1.0 : (double)r * (1.0/9007199254740992.0L);
|
2020-04-16 01:49:08 +08:00
|
|
|
return (uint64_t)(log(u) /
|
2014-08-19 07:22:13 +08:00
|
|
|
log(1.0 - (1.0 / (double)((uint64_t)1U << lg_prof_sample))))
|
2014-04-16 04:47:13 +08:00
|
|
|
+ (uint64_t)1U;
|
2020-04-16 01:49:08 +08:00
|
|
|
#else
|
|
|
|
not_reached();
|
|
|
|
return TE_MAX_START_WAIT;
|
2014-04-16 04:47:13 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-17 04:33:56 +08:00
|
|
|
uint64_t
|
|
|
|
prof_sample_postponed_event_wait(tsd_t *tsd) {
|
2020-04-17 04:37:19 +08:00
|
|
|
/*
|
|
|
|
* The postponed wait time for prof sample event is computed as if we
|
|
|
|
* want a new wait time (i.e. as if the event were triggered). If we
|
|
|
|
* instead postpone to the immediate next allocation, like how we're
|
|
|
|
* handling the other events, then we can have sampling bias, if e.g.
|
|
|
|
* the allocation immediately following a reentrancy always comes from
|
|
|
|
* the same stack trace.
|
|
|
|
*/
|
|
|
|
return prof_sample_new_event_wait(tsd);
|
2020-04-17 04:33:56 +08:00
|
|
|
}
|
|
|
|
|
2020-04-18 01:38:06 +08:00
|
|
|
void
|
|
|
|
prof_sample_event_handler(tsd_t *tsd, uint64_t elapsed) {
|
|
|
|
cassert(config_prof);
|
|
|
|
assert(elapsed > 0 && elapsed != TE_INVALID_ELAPSED);
|
|
|
|
if (prof_interval == 0 || !prof_active_get_unlocked()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (counter_accum(tsd_tsdn(tsd), &prof_idump_accumulated, elapsed)) {
|
|
|
|
prof_idump(tsd_tsdn(tsd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
static void
|
|
|
|
prof_fdump(void) {
|
|
|
|
tsd_t *tsd;
|
2016-04-14 14:36:15 +08:00
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
cassert(config_prof);
|
2019-07-18 06:52:50 +08:00
|
|
|
assert(opt_prof_final);
|
2015-03-15 05:01:35 +08:00
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
if (!prof_booted) {
|
|
|
|
return;
|
2010-02-12 05:19:21 +08:00
|
|
|
}
|
2019-07-18 06:52:50 +08:00
|
|
|
tsd = tsd_fetch();
|
|
|
|
assert(tsd_reentrancy_level_get(tsd) == 0);
|
2019-07-30 05:09:20 +08:00
|
|
|
|
2020-04-03 07:20:01 +08:00
|
|
|
prof_fdump_impl(tsd);
|
2019-07-30 05:09:20 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 03:21:38 +08:00
|
|
|
static bool
|
|
|
|
prof_idump_accum_init(void) {
|
2019-07-30 05:09:20 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2020-01-24 05:18:04 +08:00
|
|
|
return counter_accum_init(&prof_idump_accumulated, prof_interval);
|
2019-07-30 05:09:20 +08:00
|
|
|
}
|
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
void
|
|
|
|
prof_idump(tsdn_t *tsdn) {
|
|
|
|
tsd_t *tsd;
|
|
|
|
prof_tdata_t *tdata;
|
2019-07-30 05:09:20 +08:00
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
cassert(config_prof);
|
2019-07-30 05:09:20 +08:00
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
if (!prof_booted || tsdn_null(tsdn) || !prof_active_get_unlocked()) {
|
2019-07-30 05:09:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
tsd = tsdn_tsd(tsdn);
|
|
|
|
if (tsd_reentrancy_level_get(tsd) > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-15 00:35:51 +08:00
|
|
|
tdata = prof_tdata_get(tsd, true);
|
2019-07-30 05:09:20 +08:00
|
|
|
if (tdata == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tdata->enq) {
|
|
|
|
tdata->enq_idump = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-03 07:20:01 +08:00
|
|
|
prof_idump_impl(tsd);
|
2019-07-30 05:09:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
prof_mdump(tsd_t *tsd, const char *filename) {
|
|
|
|
cassert(config_prof);
|
|
|
|
assert(tsd_reentrancy_level_get(tsd) == 0);
|
|
|
|
|
|
|
|
if (!opt_prof || !prof_booted) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2020-04-03 07:20:01 +08:00
|
|
|
|
|
|
|
return prof_mdump_impl(tsd, filename);
|
2010-02-11 02:37:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_gdump(tsdn_t *tsdn) {
|
2016-05-11 13:21:10 +08:00
|
|
|
tsd_t *tsd;
|
2014-08-19 07:22:13 +08:00
|
|
|
prof_tdata_t *tdata;
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2018-04-07 04:45:37 +08:00
|
|
|
if (!prof_booted || tsdn_null(tsdn) || !prof_active_get_unlocked()) {
|
2010-02-11 02:37:56 +08:00
|
|
|
return;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-11 13:21:10 +08:00
|
|
|
tsd = tsdn_tsd(tsdn);
|
2017-04-27 09:37:44 +08:00
|
|
|
if (tsd_reentrancy_level_get(tsd) > 0) {
|
2017-04-25 09:14:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-23 12:09:23 +08:00
|
|
|
tdata = prof_tdata_get(tsd, false);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (tdata == NULL) {
|
2012-04-23 07:00:11 +08:00
|
|
|
return;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
if (tdata->enq) {
|
|
|
|
tdata->enq_gdump = true;
|
2010-02-11 02:37:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-03 07:20:01 +08:00
|
|
|
prof_gdump_impl(tsd);
|
2010-02-11 02:37:56 +08:00
|
|
|
}
|
|
|
|
|
2017-04-22 00:37:34 +08:00
|
|
|
static uint64_t
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thr_uid_alloc(tsdn_t *tsdn) {
|
2014-09-12 09:06:30 +08:00
|
|
|
uint64_t thr_uid;
|
2014-08-19 07:22:13 +08:00
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &next_thr_uid_mtx);
|
2014-09-12 09:06:30 +08:00
|
|
|
thr_uid = next_thr_uid;
|
|
|
|
next_thr_uid++;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &next_thr_uid_mtx);
|
2014-09-12 09:06:30 +08:00
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return thr_uid;
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
prof_tdata_t *
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_tdata_init(tsd_t *tsd) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return prof_tdata_init_impl(tsd, prof_thr_uid_alloc(tsd_tsdn(tsd)), 0,
|
2020-03-24 05:58:33 +08:00
|
|
|
NULL, prof_thread_active_init_get(tsd_tsdn(tsd)));
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
2014-10-03 14:01:10 +08:00
|
|
|
prof_tdata_t *
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_tdata_reinit(tsd_t *tsd, prof_tdata_t *tdata) {
|
2014-10-03 14:01:10 +08:00
|
|
|
uint64_t thr_uid = tdata->thr_uid;
|
|
|
|
uint64_t thr_discrim = tdata->thr_discrim + 1;
|
2014-10-04 14:25:30 +08:00
|
|
|
char *thread_name = (tdata->thread_name != NULL) ?
|
2020-04-01 01:43:04 +08:00
|
|
|
prof_thread_name_alloc(tsd, tdata->thread_name) : NULL;
|
2014-10-04 14:25:30 +08:00
|
|
|
bool active = tdata->active;
|
2012-04-23 07:00:11 +08:00
|
|
|
|
2014-10-03 14:01:10 +08:00
|
|
|
prof_tdata_detach(tsd, tdata);
|
2017-01-20 10:15:45 +08:00
|
|
|
return prof_tdata_init_impl(tsd, thr_uid, thr_discrim, thread_name,
|
2020-03-24 05:58:33 +08:00
|
|
|
active);
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
2010-10-21 10:05:59 +08:00
|
|
|
|
2012-03-22 09:33:03 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_tdata_cleanup(tsd_t *tsd) {
|
2014-09-23 12:09:23 +08:00
|
|
|
prof_tdata_t *tdata;
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
if (!config_prof) {
|
2014-09-23 12:09:23 +08:00
|
|
|
return;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-02-11 12:22:09 +08:00
|
|
|
|
2014-09-23 12:09:23 +08:00
|
|
|
tdata = tsd_prof_tdata_get(tsd);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (tdata != NULL) {
|
2014-09-23 12:09:23 +08:00
|
|
|
prof_tdata_detach(tsd, tdata);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-10-03 13:38:14 +08:00
|
|
|
}
|
|
|
|
|
2014-10-04 14:25:30 +08:00
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_active_get(tsdn_t *tsdn) {
|
2014-10-04 14:25:30 +08:00
|
|
|
bool prof_active_current;
|
|
|
|
|
2019-08-28 05:42:14 +08:00
|
|
|
prof_active_assert();
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &prof_active_mtx);
|
2014-10-04 14:25:30 +08:00
|
|
|
prof_active_current = prof_active;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &prof_active_mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return prof_active_current;
|
2014-10-04 14:25:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_active_set(tsdn_t *tsdn, bool active) {
|
2014-10-04 14:25:30 +08:00
|
|
|
bool prof_active_old;
|
|
|
|
|
2019-08-28 05:42:14 +08:00
|
|
|
prof_active_assert();
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &prof_active_mtx);
|
2014-10-04 14:25:30 +08:00
|
|
|
prof_active_old = prof_active;
|
|
|
|
prof_active = active;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &prof_active_mtx);
|
2019-08-28 05:42:14 +08:00
|
|
|
prof_active_assert();
|
2017-01-20 10:15:45 +08:00
|
|
|
return prof_active_old;
|
2014-10-04 14:25:30 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 07:22:13 +08:00
|
|
|
const char *
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thread_name_get(tsd_t *tsd) {
|
2019-10-04 04:01:12 +08:00
|
|
|
assert(tsd_reentrancy_level_get(tsd) == 0);
|
|
|
|
|
2014-09-23 12:09:23 +08:00
|
|
|
prof_tdata_t *tdata;
|
|
|
|
|
|
|
|
tdata = prof_tdata_get(tsd, true);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (tdata == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return "";
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-10-04 14:25:30 +08:00
|
|
|
return (tdata->thread_name != NULL ? tdata->thread_name : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thread_name_set(tsd_t *tsd, const char *thread_name) {
|
2020-06-20 06:16:53 +08:00
|
|
|
if (opt_prof_sys_thread_name) {
|
2020-03-25 08:53:41 +08:00
|
|
|
return ENOENT;
|
|
|
|
} else {
|
|
|
|
return prof_thread_name_set_impl(tsd, thread_name);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thread_active_get(tsd_t *tsd) {
|
2019-10-04 04:01:12 +08:00
|
|
|
assert(tsd_reentrancy_level_get(tsd) == 0);
|
|
|
|
|
2014-09-23 12:09:23 +08:00
|
|
|
prof_tdata_t *tdata;
|
|
|
|
|
|
|
|
tdata = prof_tdata_get(tsd, true);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (tdata == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2017-01-20 10:15:45 +08:00
|
|
|
return tdata->active;
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thread_active_set(tsd_t *tsd, bool active) {
|
2019-10-04 04:01:12 +08:00
|
|
|
assert(tsd_reentrancy_level_get(tsd) == 0);
|
|
|
|
|
2014-08-19 07:22:13 +08:00
|
|
|
prof_tdata_t *tdata;
|
|
|
|
|
2014-09-23 12:09:23 +08:00
|
|
|
tdata = prof_tdata_get(tsd, true);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (tdata == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
tdata->active = active;
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
2014-10-04 14:25:30 +08:00
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thread_active_init_get(tsdn_t *tsdn) {
|
2014-10-04 14:25:30 +08:00
|
|
|
bool active_init;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &prof_thread_active_init_mtx);
|
2014-10-04 14:25:30 +08:00
|
|
|
active_init = prof_thread_active_init;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &prof_thread_active_init_mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return active_init;
|
2014-10-04 14:25:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_thread_active_init_set(tsdn_t *tsdn, bool active_init) {
|
2014-10-04 14:25:30 +08:00
|
|
|
bool active_init_old;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &prof_thread_active_init_mtx);
|
2014-10-04 14:25:30 +08:00
|
|
|
active_init_old = prof_thread_active_init;
|
|
|
|
prof_thread_active_init = active_init;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &prof_thread_active_init_mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return active_init_old;
|
2014-10-04 14:25:30 +08:00
|
|
|
}
|
|
|
|
|
2015-01-26 13:16:57 +08:00
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_gdump_get(tsdn_t *tsdn) {
|
2015-01-26 13:16:57 +08:00
|
|
|
bool prof_gdump_current;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &prof_gdump_mtx);
|
2015-01-26 13:16:57 +08:00
|
|
|
prof_gdump_current = prof_gdump_val;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &prof_gdump_mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return prof_gdump_current;
|
2015-01-26 13:16:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_gdump_set(tsdn_t *tsdn, bool gdump) {
|
2015-01-26 13:16:57 +08:00
|
|
|
bool prof_gdump_old;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_lock(tsdn, &prof_gdump_mtx);
|
2015-01-26 13:16:57 +08:00
|
|
|
prof_gdump_old = prof_gdump_val;
|
|
|
|
prof_gdump_val = gdump;
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_unlock(tsdn, &prof_gdump_mtx);
|
2017-01-20 10:15:45 +08:00
|
|
|
return prof_gdump_old;
|
2015-01-26 13:16:57 +08:00
|
|
|
}
|
|
|
|
|
2010-02-11 02:37:56 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_boot0(void) {
|
2012-02-11 12:22:09 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2010-10-24 09:37:06 +08:00
|
|
|
memcpy(opt_prof_prefix, PROF_PREFIX_DEFAULT,
|
|
|
|
sizeof(PROF_PREFIX_DEFAULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_boot1(void) {
|
2012-02-11 12:22:09 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2010-02-11 02:37:56 +08:00
|
|
|
/*
|
2014-04-12 05:24:51 +08:00
|
|
|
* opt_prof must be in its final state before any arenas are
|
|
|
|
* initialized, so this function must be executed early.
|
2010-02-11 02:37:56 +08:00
|
|
|
*/
|
|
|
|
|
2014-10-04 01:16:09 +08:00
|
|
|
if (opt_prof_leak && !opt_prof) {
|
2010-02-11 02:37:56 +08:00
|
|
|
/*
|
|
|
|
* Enable opt_prof, but in such a way that profiles are never
|
|
|
|
* automatically dumped.
|
|
|
|
*/
|
|
|
|
opt_prof = true;
|
2010-10-24 09:37:06 +08:00
|
|
|
opt_prof_gdump = false;
|
2010-04-01 08:35:51 +08:00
|
|
|
} else if (opt_prof) {
|
|
|
|
if (opt_lg_prof_interval >= 0) {
|
|
|
|
prof_interval = (((uint64_t)1U) <<
|
|
|
|
opt_lg_prof_interval);
|
2012-11-14 04:56:27 +08:00
|
|
|
}
|
2010-04-01 08:35:51 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-02-18 06:09:29 +08:00
|
|
|
prof_boot2(tsd_t *tsd, base_t *base) {
|
2012-02-11 12:22:09 +08:00
|
|
|
cassert(config_prof);
|
|
|
|
|
2010-02-11 02:37:56 +08:00
|
|
|
if (opt_prof) {
|
2012-03-24 09:05:51 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2014-08-19 07:22:13 +08:00
|
|
|
lg_prof_sample = opt_lg_prof_sample;
|
2020-08-04 04:05:34 +08:00
|
|
|
prof_unbias_map_init();
|
2014-08-19 07:22:13 +08:00
|
|
|
|
2014-10-04 14:25:30 +08:00
|
|
|
prof_active = opt_prof_active;
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&prof_active_mtx, "prof_active",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_ACTIVE, malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-10-04 14:25:30 +08:00
|
|
|
|
2015-01-26 13:16:57 +08:00
|
|
|
prof_gdump_val = opt_prof_gdump;
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&prof_gdump_mtx, "prof_gdump",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_GDUMP, malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2015-01-26 13:16:57 +08:00
|
|
|
|
2014-10-04 14:25:30 +08:00
|
|
|
prof_thread_active_init = opt_prof_thread_active_init;
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&prof_thread_active_init_mtx,
|
|
|
|
"prof_thread_active_init",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_THREAD_ACTIVE_INIT,
|
|
|
|
malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-10-04 14:25:30 +08:00
|
|
|
|
2019-07-18 06:52:50 +08:00
|
|
|
if (prof_data_init(tsd)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2019-07-18 06:52:50 +08:00
|
|
|
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&bt2gctx_mtx, "prof_bt2gctx",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_BT2GCTX, malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&tdatas_mtx, "prof_tdatas",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_TDATAS, malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
|
|
|
|
next_thr_uid = 0;
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&next_thr_uid_mtx, "prof_next_thr_uid",
|
2020-12-19 09:14:59 +08:00
|
|
|
WITNESS_RANK_PROF_NEXT_THR_UID,
|
|
|
|
malloc_mutex_rank_exclusive)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (malloc_mutex_init(&prof_stats_mtx, "prof_stats",
|
|
|
|
WITNESS_RANK_PROF_STATS, malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
|
2020-04-16 03:21:38 +08:00
|
|
|
if (prof_idump_accum_init()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-19 09:14:59 +08:00
|
|
|
if (malloc_mutex_init(&prof_dump_filename_mtx,
|
|
|
|
"prof_dump_filename", WITNESS_RANK_PROF_DUMP_FILENAME,
|
|
|
|
malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&prof_dump_mtx, "prof_dump",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_DUMP, malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
|
2014-10-09 08:57:19 +08:00
|
|
|
if (opt_prof_final && opt_prof_prefix[0] != '\0' &&
|
|
|
|
atexit(prof_fdump) != 0) {
|
2010-03-04 09:45:38 +08:00
|
|
|
malloc_write("<jemalloc>: Error in atexit()\n");
|
2017-01-16 08:56:30 +08:00
|
|
|
if (opt_abort) {
|
2010-02-11 02:37:56 +08:00
|
|
|
abort();
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
}
|
2012-03-24 09:05:51 +08:00
|
|
|
|
2019-07-13 07:37:37 +08:00
|
|
|
if (prof_log_init(tsd)) {
|
2018-07-06 01:56:33 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-19 05:38:14 +08:00
|
|
|
if (prof_recent_init()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-18 06:09:29 +08:00
|
|
|
prof_base = base;
|
|
|
|
|
|
|
|
gctx_locks = (malloc_mutex_t *)base_alloc(tsd_tsdn(tsd), base,
|
|
|
|
PROF_NCTX_LOCKS * sizeof(malloc_mutex_t), CACHELINE);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (gctx_locks == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-03-24 09:05:51 +08:00
|
|
|
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&gctx_locks[i], "prof_gctx",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_GCTX,
|
|
|
|
malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
}
|
|
|
|
|
2020-02-18 06:09:29 +08:00
|
|
|
tdata_locks = (malloc_mutex_t *)base_alloc(tsd_tsdn(tsd), base,
|
|
|
|
PROF_NTDATA_LOCKS * sizeof(malloc_mutex_t), CACHELINE);
|
2017-01-16 08:56:30 +08:00
|
|
|
if (tdata_locks == NULL) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-08-19 07:22:13 +08:00
|
|
|
for (i = 0; i < PROF_NTDATA_LOCKS; i++) {
|
2016-04-14 14:36:15 +08:00
|
|
|
if (malloc_mutex_init(&tdata_locks[i], "prof_tdata",
|
2017-05-16 06:38:15 +08:00
|
|
|
WITNESS_RANK_PROF_TDATA,
|
|
|
|
malloc_mutex_rank_exclusive)) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return true;
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2012-03-24 09:05:51 +08:00
|
|
|
}
|
2020-04-04 02:19:51 +08:00
|
|
|
|
|
|
|
prof_unwind_init();
|
2019-02-20 07:58:13 +08:00
|
|
|
}
|
2010-02-11 02:37:56 +08:00
|
|
|
prof_booted = true;
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return false;
|
2010-02-11 02:37:56 +08:00
|
|
|
}
|
|
|
|
|
2012-10-10 05:46:22 +08:00
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_prefork0(tsdn_t *tsdn) {
|
2017-01-30 09:35:57 +08:00
|
|
|
if (config_prof && opt_prof) {
|
2012-10-10 05:46:22 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &prof_dump_mtx);
|
|
|
|
malloc_mutex_prefork(tsdn, &bt2gctx_mtx);
|
|
|
|
malloc_mutex_prefork(tsdn, &tdatas_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < PROF_NTDATA_LOCKS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &tdata_locks[i]);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2019-12-21 02:38:05 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &log_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &gctx_locks[i]);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2020-04-14 03:05:51 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &prof_recent_dump_mtx);
|
2016-04-26 14:14:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_prefork1(tsdn_t *tsdn) {
|
2017-01-30 09:35:57 +08:00
|
|
|
if (config_prof && opt_prof) {
|
2020-04-16 05:58:58 +08:00
|
|
|
counter_prefork(tsdn, &prof_idump_accumulated);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &prof_active_mtx);
|
2019-09-10 11:04:18 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &prof_dump_filename_mtx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &prof_gdump_mtx);
|
2020-12-19 09:14:59 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &prof_recent_alloc_mtx);
|
|
|
|
malloc_mutex_prefork(tsdn, &prof_stats_mtx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_prefork(tsdn, &next_thr_uid_mtx);
|
|
|
|
malloc_mutex_prefork(tsdn, &prof_thread_active_init_mtx);
|
2012-10-10 05:46:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_postfork_parent(tsdn_t *tsdn) {
|
2017-01-30 09:35:57 +08:00
|
|
|
if (config_prof && opt_prof) {
|
2012-10-10 05:46:22 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn,
|
|
|
|
&prof_thread_active_init_mtx);
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &next_thr_uid_mtx);
|
2020-12-19 09:14:59 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_stats_mtx);
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_recent_alloc_mtx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_gdump_mtx);
|
2019-09-10 11:04:18 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_dump_filename_mtx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_active_mtx);
|
2020-04-16 05:58:58 +08:00
|
|
|
counter_postfork_parent(tsdn, &prof_idump_accumulated);
|
2020-04-14 03:05:51 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_recent_dump_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &gctx_locks[i]);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2019-12-21 02:38:05 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &log_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < PROF_NTDATA_LOCKS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &tdata_locks[i]);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_parent(tsdn, &tdatas_mtx);
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &bt2gctx_mtx);
|
|
|
|
malloc_mutex_postfork_parent(tsdn, &prof_dump_mtx);
|
2012-10-10 05:46:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_postfork_child(tsdn_t *tsdn) {
|
2017-01-30 09:35:57 +08:00
|
|
|
if (config_prof && opt_prof) {
|
2012-10-10 05:46:22 +08:00
|
|
|
unsigned i;
|
|
|
|
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_thread_active_init_mtx);
|
|
|
|
malloc_mutex_postfork_child(tsdn, &next_thr_uid_mtx);
|
2020-12-19 09:14:59 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_stats_mtx);
|
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_recent_alloc_mtx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_gdump_mtx);
|
2019-09-10 11:04:18 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_dump_filename_mtx);
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_active_mtx);
|
2020-04-16 05:58:58 +08:00
|
|
|
counter_postfork_child(tsdn, &prof_idump_accumulated);
|
2020-04-14 03:05:51 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_recent_dump_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < PROF_NCTX_LOCKS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &gctx_locks[i]);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2019-12-21 02:38:05 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &log_mtx);
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < PROF_NTDATA_LOCKS; i++) {
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &tdata_locks[i]);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2016-05-11 13:21:10 +08:00
|
|
|
malloc_mutex_postfork_child(tsdn, &tdatas_mtx);
|
|
|
|
malloc_mutex_postfork_child(tsdn, &bt2gctx_mtx);
|
|
|
|
malloc_mutex_postfork_child(tsdn, &prof_dump_mtx);
|
2012-10-10 05:46:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-11 02:37:56 +08:00
|
|
|
/******************************************************************************/
|