mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-24 13:53:11 +00:00
Extract postfork-child tcache list relink into tcache_arena_postfork_child
This commit is contained in:
@@ -73,6 +73,7 @@ void tcaches_destroy(tsd_t *tsd, unsigned ind);
|
|||||||
bool tcache_boot(tsdn_t *tsdn, base_t *base);
|
bool tcache_boot(tsdn_t *tsdn, base_t *base);
|
||||||
void tcache_arena_associate(
|
void tcache_arena_associate(
|
||||||
tsdn_t *tsdn, tcache_slow_t *tcache_slow, tcache_t *tcache, arena_t *arena);
|
tsdn_t *tsdn, tcache_slow_t *tcache_slow, tcache_t *tcache, arena_t *arena);
|
||||||
|
void tcache_arena_postfork_child(tsdn_t *tsdn, 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);
|
||||||
void tcache_postfork_child(tsdn_t *tsdn);
|
void tcache_postfork_child(tsdn_t *tsdn);
|
||||||
|
|||||||
16
src/arena.c
16
src/arena.c
@@ -2089,21 +2089,7 @@ arena_postfork_child(tsdn_t *tsdn, arena_t *arena) {
|
|||||||
if (tsd_iarena_get(tsdn_tsd(tsdn)) == arena) {
|
if (tsd_iarena_get(tsdn_tsd(tsdn)) == arena) {
|
||||||
arena_nthreads_inc(arena, true);
|
arena_nthreads_inc(arena, true);
|
||||||
}
|
}
|
||||||
if (config_stats) {
|
tcache_arena_postfork_child(tsdn, arena);
|
||||||
ql_new(&arena->tcache_ql);
|
|
||||||
ql_new(&arena->cache_bin_array_descriptor_ql);
|
|
||||||
tcache_slow_t *tcache_slow = tcache_slow_get(tsdn_tsd(tsdn));
|
|
||||||
if (tcache_slow != NULL && tcache_slow->arena == arena) {
|
|
||||||
tcache_t *tcache = tcache_slow->tcache;
|
|
||||||
ql_elm_new(tcache_slow, link);
|
|
||||||
ql_tail_insert(&arena->tcache_ql, tcache_slow, link);
|
|
||||||
cache_bin_array_descriptor_init(
|
|
||||||
&tcache_slow->cache_bin_array_descriptor,
|
|
||||||
tcache->bins);
|
|
||||||
ql_tail_insert(&arena->cache_bin_array_descriptor_ql,
|
|
||||||
&tcache_slow->cache_bin_array_descriptor, link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < nbins_total; i++) {
|
for (unsigned i = 0; i < nbins_total; i++) {
|
||||||
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
JEMALLOC_SUPPRESS_WARN_ON_USAGE(
|
||||||
|
|||||||
39
src/tcache.c
39
src/tcache.c
@@ -720,6 +720,22 @@ tcache_bin_ncached_max_read(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Insert tcache_slow into arena's tcache list. Caller must hold
|
||||||
|
* arena->tcache_ql_mtx, OR be in the postfork-child path (single-threaded,
|
||||||
|
* mutex re-init pending). config_stats must be true.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
tcache_arena_link(arena_t *arena, tcache_slow_t *tcache_slow,
|
||||||
|
tcache_t *tcache) {
|
||||||
|
ql_elm_new(tcache_slow, link);
|
||||||
|
ql_tail_insert(&arena->tcache_ql, tcache_slow, link);
|
||||||
|
cache_bin_array_descriptor_init(
|
||||||
|
&tcache_slow->cache_bin_array_descriptor, tcache->bins);
|
||||||
|
ql_tail_insert(&arena->cache_bin_array_descriptor_ql,
|
||||||
|
&tcache_slow->cache_bin_array_descriptor, link);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
tcache_arena_associate(tsdn_t *tsdn, tcache_slow_t *tcache_slow,
|
tcache_arena_associate(tsdn_t *tsdn, tcache_slow_t *tcache_slow,
|
||||||
tcache_t *tcache, arena_t *arena) {
|
tcache_t *tcache, arena_t *arena) {
|
||||||
@@ -727,16 +743,8 @@ tcache_arena_associate(tsdn_t *tsdn, tcache_slow_t *tcache_slow,
|
|||||||
tcache_slow->arena = arena;
|
tcache_slow->arena = arena;
|
||||||
|
|
||||||
if (config_stats) {
|
if (config_stats) {
|
||||||
/* Link into list of extant tcaches. */
|
|
||||||
malloc_mutex_lock(tsdn, &arena->tcache_ql_mtx);
|
malloc_mutex_lock(tsdn, &arena->tcache_ql_mtx);
|
||||||
|
tcache_arena_link(arena, tcache_slow, tcache);
|
||||||
ql_elm_new(tcache_slow, link);
|
|
||||||
ql_tail_insert(&arena->tcache_ql, tcache_slow, link);
|
|
||||||
cache_bin_array_descriptor_init(
|
|
||||||
&tcache_slow->cache_bin_array_descriptor, tcache->bins);
|
|
||||||
ql_tail_insert(&arena->cache_bin_array_descriptor_ql,
|
|
||||||
&tcache_slow->cache_bin_array_descriptor, link);
|
|
||||||
|
|
||||||
malloc_mutex_unlock(tsdn, &arena->tcache_ql_mtx);
|
malloc_mutex_unlock(tsdn, &arena->tcache_ql_mtx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -776,6 +784,19 @@ tcache_arena_reassociate(tsdn_t *tsdn, tcache_slow_t *tcache_slow,
|
|||||||
tcache_arena_associate(tsdn, tcache_slow, tcache, arena);
|
tcache_arena_associate(tsdn, tcache_slow, tcache, arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tcache_arena_postfork_child(tsdn_t *tsdn, arena_t *arena) {
|
||||||
|
if (!config_stats) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ql_new(&arena->tcache_ql);
|
||||||
|
ql_new(&arena->cache_bin_array_descriptor_ql);
|
||||||
|
tcache_slow_t *tcache_slow = tcache_slow_get(tsdn_tsd(tsdn));
|
||||||
|
if (tcache_slow != NULL && tcache_slow->arena == arena) {
|
||||||
|
tcache_arena_link(arena, tcache_slow, tcache_slow->tcache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tcache_default_settings_init(tcache_slow_t *tcache_slow) {
|
tcache_default_settings_init(tcache_slow_t *tcache_slow) {
|
||||||
assert(tcache_slow != NULL);
|
assert(tcache_slow != NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user