Initialize TSD tcache before enabling it

This commit is contained in:
Farid Zakaria
2026-07-06 11:03:42 -07:00
committed by Slobodan Predolac
parent 36f2017777
commit 54f22c83d8
3 changed files with 39 additions and 8 deletions

View File

@@ -1044,24 +1044,28 @@ tcache_create_explicit(tsd_t *tsd) {
bool
tsd_tcache_enabled_data_init(tsd_t *tsd) {
/* Called upon tsd initialization. */
tsd_tcache_enabled_set(tsd, opt_tcache);
/*
* tcache is not available yet, but we need to set up its tcache_nbins
* in advance.
*/
tcache_default_settings_init(tsd_tcache_slowp_get(tsd));
tsd_slow_update(tsd);
#if defined(JEMALLOC_JET) || defined(JEMALLOC_UNIT_TEST)
if (test_hooks_tsd_bootstrap_hook != NULL) {
test_hooks_tsd_bootstrap_hook();
}
#endif
bool err = false;
if (opt_tcache) {
/* Trigger tcache init. */
return tsd_tcache_data_init(
/* Initialize the bins before advertising the tcache. */
err = tsd_tcache_data_init(
tsd, NULL, tcache_get_default_ncached_max());
}
return false;
tsd_tcache_enabled_set(tsd, opt_tcache && !err);
tsd_slow_update(tsd);
return err;
}
void

View File

@@ -182,9 +182,7 @@ tsd_fetch_slow(tsd_t *tsd, bool minimal) {
tsd_slow_update(tsd);
/* Trigger cleanup handler registration. */
tsd_set(tsd);
tsd_pre_reentrancy_raw(tsd);
tsd_data_init(tsd);
tsd_post_reentrancy_raw(tsd);
}
} else {
tsd_state_set(tsd, tsd_state_minimal_initialized);
@@ -212,9 +210,9 @@ tsd_fetch_slow(tsd_t *tsd, bool minimal) {
/* Switch to fully initialized. */
tsd_state_set(tsd, tsd_state_nominal);
assert(*tsd_reentrancy_levelp_get(tsd) >= 1);
(*tsd_reentrancy_levelp_get(tsd))--;
tsd_slow_update(tsd);
tsd_data_init(tsd);
tsd_post_reentrancy_raw(tsd);
} else {
assert_tsd_data_cleanup_done(tsd);
}