diff options
author | David Goldblatt <davidgoldblatt@fb.com> | 2017-04-01 02:59:45 (GMT) |
---|---|---|
committer | David Goldblatt <davidtgoldblatt@gmail.com> | 2017-04-07 21:10:27 (GMT) |
commit | b407a65401bca5828760c8fd5e940e91475a2b3e (patch) | |
tree | a1bbd2e2fccd51153f126a228a07491259b44730 /include/jemalloc | |
parent | 0a0fcd3e6a0816f0a56fa852416d0ece861c0abb (diff) | |
download | jemalloc-b407a65401bca5828760c8fd5e940e91475a2b3e.zip jemalloc-b407a65401bca5828760c8fd5e940e91475a2b3e.tar.gz jemalloc-b407a65401bca5828760c8fd5e940e91475a2b3e.tar.bz2 |
Add basic reentrancy-checking support, and allow arena_new to reenter.
This checks whether or not we're reentrant using thread-local data, and, if we
are, moves certain internal allocations to use arena 0 (which should be properly
initialized after bootstrapping).
The immediate thing this allows is spinning up threads in arena_new, which will
enable spinning up background threads there.
Diffstat (limited to 'include/jemalloc')
-rw-r--r-- | include/jemalloc/internal/hooks.h | 4 | ||||
-rw-r--r-- | include/jemalloc/internal/jemalloc_internal.h.in | 9 | ||||
-rw-r--r-- | include/jemalloc/internal/private_symbols.txt | 4 | ||||
-rw-r--r-- | include/jemalloc/internal/tsd_structs.h | 6 |
4 files changed, 18 insertions, 5 deletions
diff --git a/include/jemalloc/internal/hooks.h b/include/jemalloc/internal/hooks.h index 608b268..cd49afc 100644 --- a/include/jemalloc/internal/hooks.h +++ b/include/jemalloc/internal/hooks.h @@ -1,8 +1,8 @@ #ifndef JEMALLOC_INTERNAL_HOOKS_H #define JEMALLOC_INTERNAL_HOOKS_H -extern void (*hooks_arena_new_hook)(); -extern void (*hooks_libc_hook)(); +extern JEMALLOC_EXPORT void (*hooks_arena_new_hook)(); +extern JEMALLOC_EXPORT void (*hooks_libc_hook)(); #define JEMALLOC_HOOK(fn, hook) ((void)(hook != NULL && (hook(), 0)), fn) diff --git a/include/jemalloc/internal/jemalloc_internal.h.in b/include/jemalloc/internal/jemalloc_internal.h.in index 1c0bf43..62dae0c 100644 --- a/include/jemalloc/internal/jemalloc_internal.h.in +++ b/include/jemalloc/internal/jemalloc_internal.h.in @@ -1013,6 +1013,11 @@ arena_choose_impl(tsd_t *tsd, arena_t *arena, bool internal) { return arena; } + /* During reentrancy, arena 0 is the safest bet. */ + if (*tsd_reentrancy_levelp_get(tsd) > 1) { + return arena_get(tsd_tsdn(tsd), 0, true); + } + ret = internal ? tsd_iarena_get(tsd) : tsd_arena_get(tsd); if (unlikely(ret == NULL)) { ret = arena_choose_hard(tsd, internal); @@ -1193,7 +1198,9 @@ idalloctm(tsdn_t *tsdn, void *ptr, tcache_t *tcache, bool is_internal, if (config_stats && is_internal) { arena_internal_sub(iaalloc(tsdn, ptr), isalloc(tsdn, ptr)); } - + if (!is_internal && *tsd_reentrancy_levelp_get(tsdn_tsd(tsdn)) != 0) { + tcache = NULL; + } arena_dalloc(tsdn, ptr, tcache, slow_path); } diff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt index deae824..4931d48 100644 --- a/include/jemalloc/internal/private_symbols.txt +++ b/include/jemalloc/internal/private_symbols.txt @@ -232,6 +232,7 @@ hash_rotl_64 hash_x64_128 hash_x86_128 hash_x86_32 +hooks_arena_new_hook hooks_libc_hook iaalloc ialloc @@ -537,6 +538,9 @@ tsd_init_head tsd_narenas_tdata_get tsd_narenas_tdata_set tsd_narenas_tdatap_get +tsd_reentrancy_level_get +tsd_reentrancy_level_set +tsd_reentrancy_levelp_get tsd_wrapper_get tsd_wrapper_set tsd_nominal diff --git a/include/jemalloc/internal/tsd_structs.h b/include/jemalloc/internal/tsd_structs.h index 2dca0bd..12df63d 100644 --- a/include/jemalloc/internal/tsd_structs.h +++ b/include/jemalloc/internal/tsd_structs.h @@ -65,7 +65,8 @@ struct tsd_init_head_s { O(witnesses, witness_list_t, no, no, yes) \ O(rtree_leaf_elm_witnesses, rtree_leaf_elm_witness_tsd_t, \ no, no, no) \ - O(witness_fork, bool, yes, no, no) + O(witness_fork, bool, yes, no, no) \ + O(reentrancy_level, int, no, no, no) #define TSD_INITIALIZER { \ tsd_state_uninitialized, \ @@ -82,7 +83,8 @@ struct tsd_init_head_s { TCACHE_ZERO_INITIALIZER, \ ql_head_initializer(witnesses), \ RTREE_ELM_WITNESS_TSD_INITIALIZER, \ - false \ + false, \ + 0 \ } struct tsd_s { |