Break prof and tcache knowledge of b0.

This commit is contained in:
David T. Goldblatt 2020-02-17 14:09:29 -08:00 committed by David Goldblatt
parent a0c1f4ac57
commit 29436fa056
6 changed files with 26 additions and 23 deletions

View File

@ -93,7 +93,7 @@ bool prof_gdump_get(tsdn_t *tsdn);
bool prof_gdump_set(tsdn_t *tsdn, bool active); bool prof_gdump_set(tsdn_t *tsdn, bool active);
void prof_boot0(void); void prof_boot0(void);
void prof_boot1(void); void prof_boot1(void);
bool prof_boot2(tsd_t *tsd); bool prof_boot2(tsd_t *tsd, base_t *base);
void prof_prefork0(tsdn_t *tsdn); void prof_prefork0(tsdn_t *tsdn);
void prof_prefork1(tsdn_t *tsdn); void prof_prefork1(tsdn_t *tsdn);
void prof_postfork_parent(tsdn_t *tsdn); void prof_postfork_parent(tsdn_t *tsdn);

View File

@ -36,10 +36,10 @@ void tcache_arena_reassociate(tsdn_t *tsdn, tcache_t *tcache,
tcache_t *tcache_create_explicit(tsd_t *tsd); tcache_t *tcache_create_explicit(tsd_t *tsd);
void tcache_cleanup(tsd_t *tsd); void tcache_cleanup(tsd_t *tsd);
void tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena); void tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena);
bool tcaches_create(tsd_t *tsd, unsigned *r_ind); bool tcaches_create(tsd_t *tsd, base_t *base, unsigned *r_ind);
void tcaches_flush(tsd_t *tsd, unsigned ind); void tcaches_flush(tsd_t *tsd, unsigned ind);
void tcaches_destroy(tsd_t *tsd, unsigned ind); void tcaches_destroy(tsd_t *tsd, unsigned ind);
bool tcache_boot(tsdn_t *tsdn); bool tcache_boot(tsdn_t *tsdn, base_t *base);
void tcache_arena_associate(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena); void tcache_arena_associate(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena);
void tcache_prefork(tsdn_t *tsdn); void tcache_prefork(tsdn_t *tsdn);
void tcache_postfork_parent(tsdn_t *tsdn); void tcache_postfork_parent(tsdn_t *tsdn);

View File

@ -2040,7 +2040,7 @@ tcache_create_ctl(tsd_t *tsd, const size_t *mib, size_t miblen,
unsigned tcache_ind; unsigned tcache_ind;
READONLY(); READONLY();
if (tcaches_create(tsd, &tcache_ind)) { if (tcaches_create(tsd, b0get(), &tcache_ind)) {
ret = EFAULT; ret = EFAULT;
goto label_return; goto label_return;
} }

View File

@ -1586,7 +1586,7 @@ malloc_init_hard_a0_locked() {
prof_boot1(); prof_boot1();
} }
arena_boot(&sc_data); arena_boot(&sc_data);
if (tcache_boot(TSDN_NULL)) { if (tcache_boot(TSDN_NULL, b0get())) {
return true; return true;
} }
if (malloc_mutex_init(&arenas_lock, "arenas", WITNESS_RANK_ARENAS, if (malloc_mutex_init(&arenas_lock, "arenas", WITNESS_RANK_ARENAS,
@ -1823,7 +1823,7 @@ malloc_init_hard(void) {
if (malloc_init_narenas() || background_thread_boot1(tsd_tsdn(tsd))) { if (malloc_init_narenas() || background_thread_boot1(tsd_tsdn(tsd))) {
UNLOCK_RETURN(tsd_tsdn(tsd), true, true) UNLOCK_RETURN(tsd_tsdn(tsd), true, true)
} }
if (config_prof && prof_boot2(tsd)) { if (config_prof && prof_boot2(tsd, b0get())) {
UNLOCK_RETURN(tsd_tsdn(tsd), true, true) UNLOCK_RETURN(tsd_tsdn(tsd), true, true)
} }

View File

@ -91,6 +91,9 @@ static uint64_t prof_dump_iseq;
static uint64_t prof_dump_mseq; static uint64_t prof_dump_mseq;
static uint64_t prof_dump_useq; static uint64_t prof_dump_useq;
/* The fallback allocator profiling functionality will use. */
base_t *prof_base;
malloc_mutex_t prof_dump_mtx; malloc_mutex_t prof_dump_mtx;
static char *prof_dump_prefix = NULL; static char *prof_dump_prefix = NULL;
@ -584,8 +587,8 @@ prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix) {
if (prof_dump_prefix == NULL) { if (prof_dump_prefix == NULL) {
malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx); malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx);
/* Everything is still guarded by ctl_mtx. */ /* Everything is still guarded by ctl_mtx. */
char *buffer = base_alloc(tsdn, b0get(), PROF_DUMP_FILENAME_LEN, char *buffer = base_alloc(tsdn, prof_base,
QUANTUM); PROF_DUMP_FILENAME_LEN, QUANTUM);
if (buffer == NULL) { if (buffer == NULL) {
return true; return true;
} }
@ -944,7 +947,7 @@ prof_boot1(void) {
} }
bool bool
prof_boot2(tsd_t *tsd) { prof_boot2(tsd_t *tsd, base_t *base) {
cassert(config_prof); cassert(config_prof);
if (opt_prof) { if (opt_prof) {
@ -1017,9 +1020,10 @@ prof_boot2(tsd_t *tsd) {
return true; return true;
} }
gctx_locks = (malloc_mutex_t *)base_alloc(tsd_tsdn(tsd), prof_base = base;
b0get(), PROF_NCTX_LOCKS * sizeof(malloc_mutex_t),
CACHELINE); gctx_locks = (malloc_mutex_t *)base_alloc(tsd_tsdn(tsd), base,
PROF_NCTX_LOCKS * sizeof(malloc_mutex_t), CACHELINE);
if (gctx_locks == NULL) { if (gctx_locks == NULL) {
return true; return true;
} }
@ -1031,9 +1035,8 @@ prof_boot2(tsd_t *tsd) {
} }
} }
tdata_locks = (malloc_mutex_t *)base_alloc(tsd_tsdn(tsd), tdata_locks = (malloc_mutex_t *)base_alloc(tsd_tsdn(tsd), base,
b0get(), PROF_NTDATA_LOCKS * sizeof(malloc_mutex_t), PROF_NTDATA_LOCKS * sizeof(malloc_mutex_t), CACHELINE);
CACHELINE);
if (tdata_locks == NULL) { if (tdata_locks == NULL) {
return true; return true;
} }

View File

@ -664,14 +664,14 @@ tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena) {
} }
static bool static bool
tcaches_create_prep(tsd_t *tsd) { tcaches_create_prep(tsd_t *tsd, base_t *base) {
bool err; bool err;
malloc_mutex_lock(tsd_tsdn(tsd), &tcaches_mtx); malloc_mutex_lock(tsd_tsdn(tsd), &tcaches_mtx);
if (tcaches == NULL) { if (tcaches == NULL) {
tcaches = base_alloc(tsd_tsdn(tsd), b0get(), sizeof(tcache_t *) tcaches = base_alloc(tsd_tsdn(tsd), base,
* (MALLOCX_TCACHE_MAX+1), CACHELINE); sizeof(tcache_t *) * (MALLOCX_TCACHE_MAX+1), CACHELINE);
if (tcaches == NULL) { if (tcaches == NULL) {
err = true; err = true;
goto label_return; goto label_return;
@ -690,12 +690,12 @@ label_return:
} }
bool bool
tcaches_create(tsd_t *tsd, unsigned *r_ind) { tcaches_create(tsd_t *tsd, base_t *base, unsigned *r_ind) {
witness_assert_depth(tsdn_witness_tsdp_get(tsd_tsdn(tsd)), 0); witness_assert_depth(tsdn_witness_tsdp_get(tsd_tsdn(tsd)), 0);
bool err; bool err;
if (tcaches_create_prep(tsd)) { if (tcaches_create_prep(tsd, base)) {
err = true; err = true;
goto label_return; goto label_return;
} }
@ -772,7 +772,7 @@ tcaches_destroy(tsd_t *tsd, unsigned ind) {
} }
bool bool
tcache_boot(tsdn_t *tsdn) { tcache_boot(tsdn_t *tsdn, base_t *base) {
/* If necessary, clamp opt_lg_tcache_max. */ /* If necessary, clamp opt_lg_tcache_max. */
if (opt_lg_tcache_max < 0 || (ZU(1) << opt_lg_tcache_max) < if (opt_lg_tcache_max < 0 || (ZU(1) << opt_lg_tcache_max) <
SC_SMALL_MAXCLASS) { SC_SMALL_MAXCLASS) {
@ -789,8 +789,8 @@ tcache_boot(tsdn_t *tsdn) {
nhbins = sz_size2index(tcache_maxclass) + 1; nhbins = sz_size2index(tcache_maxclass) + 1;
/* Initialize tcache_bin_info. */ /* Initialize tcache_bin_info. */
tcache_bin_info = (cache_bin_info_t *)base_alloc(tsdn, b0get(), nhbins tcache_bin_info = (cache_bin_info_t *)base_alloc(tsdn, base,
* sizeof(cache_bin_info_t), CACHELINE); nhbins * sizeof(cache_bin_info_t), CACHELINE);
if (tcache_bin_info == NULL) { if (tcache_bin_info == NULL) {
return true; return true;
} }