diff options
author | Qi Wang <interwq@gwu.edu> | 2017-06-15 23:53:22 (GMT) |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2017-06-16 00:55:53 (GMT) |
commit | 9b1befabbb7a7105501d27843873d14e1c2de54b (patch) | |
tree | df765e619c0a342cab8c2e9bbc1edc4d4fda1667 /src/jemalloc.c | |
parent | ae93fb08e21284f025871e9f5daccf3d0329b99b (diff) | |
download | jemalloc-9b1befabbb7a7105501d27843873d14e1c2de54b.zip jemalloc-9b1befabbb7a7105501d27843873d14e1c2de54b.tar.gz jemalloc-9b1befabbb7a7105501d27843873d14e1c2de54b.tar.bz2 |
Add minimal initialized TSD.
We use the minimal_initilized tsd (which requires no cleanup) for free()
specifically, if tsd hasn't been initialized yet.
Any other activity will transit the state from minimal to normal. This is to
workaround the case where a thread has no malloc calls in its lifetime until
during thread termination, free() happens after tls destructors.
Diffstat (limited to 'src/jemalloc.c')
-rw-r--r-- | src/jemalloc.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/jemalloc.c b/src/jemalloc.c index 52c86aa..c773cc4 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -2264,7 +2264,15 @@ JEMALLOC_EXPORT void JEMALLOC_NOTHROW je_free(void *ptr) { UTRACE(ptr, 0, 0); if (likely(ptr != NULL)) { - tsd_t *tsd = tsd_fetch(); + /* + * We avoid setting up tsd fully (e.g. tcache, arena binding) + * based on only free() calls -- other activities trigger the + * minimal to full transition. This is because free() may + * happen during thread shutdown after tls deallocation: if a + * thread never had any malloc activities until then, a + * fully-setup tsd won't be destructed properly. + */ + tsd_t *tsd = tsd_fetch_min(); check_entry_exit_locking(tsd_tsdn(tsd)); tcache_t *tcache; |