summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Maurer <bmaurer@fb.com>2014-04-15 20:28:37 (GMT)
committerBen Maurer <bmaurer@fb.com>2014-04-16 20:36:56 (GMT)
commita7619b7fa56f98d1ca99a23b458696dd37c12b77 (patch)
treed428b52a46cf1aaf944f32d1fff9fa066811f025
parent9b0cbf0850b130a9b0a8c58bd10b2926b2083510 (diff)
downloadjemalloc-a7619b7fa56f98d1ca99a23b458696dd37c12b77.zip
jemalloc-a7619b7fa56f98d1ca99a23b458696dd37c12b77.tar.gz
jemalloc-a7619b7fa56f98d1ca99a23b458696dd37c12b77.tar.bz2
outline rare tcache_get codepaths
-rw-r--r--include/jemalloc/internal/private_symbols.txt1
-rw-r--r--include/jemalloc/internal/tcache.h35
-rw-r--r--src/tcache.c40
3 files changed, 43 insertions, 33 deletions
diff --git a/include/jemalloc/internal/private_symbols.txt b/include/jemalloc/internal/private_symbols.txt
index f52d49f..376f95d 100644
--- a/include/jemalloc/internal/private_symbols.txt
+++ b/include/jemalloc/internal/private_symbols.txt
@@ -384,6 +384,7 @@ tcache_event
tcache_event_hard
tcache_flush
tcache_get
+tcache_get_hard
tcache_initialized
tcache_maxclass
tcache_salloc
diff --git a/include/jemalloc/internal/tcache.h b/include/jemalloc/internal/tcache.h
index 5197413..96447f4 100644
--- a/include/jemalloc/internal/tcache.h
+++ b/include/jemalloc/internal/tcache.h
@@ -110,6 +110,7 @@ void tcache_bin_flush_large(tcache_bin_t *tbin, size_t binind, unsigned rem,
tcache_t *tcache);
void tcache_arena_associate(tcache_t *tcache, arena_t *arena);
void tcache_arena_dissociate(tcache_t *tcache);
+tcache_t *tcache_get_hard(tcache_t *tcache, bool create);
tcache_t *tcache_create(arena_t *arena);
void tcache_destroy(tcache_t *tcache);
void tcache_thread_cleanup(void *arg);
@@ -220,39 +221,7 @@ tcache_get(bool create)
if ((uintptr_t)tcache <= (uintptr_t)TCACHE_STATE_MAX) {
if (tcache == TCACHE_STATE_DISABLED)
return (NULL);
- if (tcache == NULL) {
- if (create == false) {
- /*
- * Creating a tcache here would cause
- * allocation as a side effect of free().
- * Ordinarily that would be okay since
- * tcache_create() failure is a soft failure
- * that doesn't propagate. However, if TLS
- * data are freed via free() as in glibc,
- * subtle corruption could result from setting
- * a TLS variable after its backing memory is
- * freed.
- */
- return (NULL);
- }
- if (tcache_enabled_get() == false) {
- tcache_enabled_set(false); /* Memoize. */
- return (NULL);
- }
- return (tcache_create(choose_arena(NULL)));
- }
- if (tcache == TCACHE_STATE_PURGATORY) {
- /*
- * Make a note that an allocator function was called
- * after tcache_thread_cleanup() was called.
- */
- tcache = TCACHE_STATE_REINCARNATED;
- tcache_tsd_set(&tcache);
- return (NULL);
- }
- if (tcache == TCACHE_STATE_REINCARNATED)
- return (NULL);
- not_reached();
+ tcache = tcache_get_hard(tcache, create);
}
return (tcache);
diff --git a/src/tcache.c b/src/tcache.c
index 6de9296..868f2d7 100644
--- a/src/tcache.c
+++ b/src/tcache.c
@@ -266,6 +266,46 @@ tcache_arena_dissociate(tcache_t *tcache)
}
tcache_t *
+tcache_get_hard(tcache_t *tcache, bool create)
+{
+
+ if (tcache == NULL) {
+ if (create == false) {
+ /*
+ * Creating a tcache here would cause
+ * allocation as a side effect of free().
+ * Ordinarily that would be okay since
+ * tcache_create() failure is a soft failure
+ * that doesn't propagate. However, if TLS
+ * data are freed via free() as in glibc,
+ * subtle corruption could result from setting
+ * a TLS variable after its backing memory is
+ * freed.
+ */
+ return (NULL);
+ }
+ if (tcache_enabled_get() == false) {
+ tcache_enabled_set(false); /* Memoize. */
+ return (NULL);
+ }
+ return (tcache_create(choose_arena(NULL)));
+ }
+ if (tcache == TCACHE_STATE_PURGATORY) {
+ /*
+ * Make a note that an allocator function was called
+ * after tcache_thread_cleanup() was called.
+ */
+ tcache = TCACHE_STATE_REINCARNATED;
+ tcache_tsd_set(&tcache);
+ return (NULL);
+ }
+ if (tcache == TCACHE_STATE_REINCARNATED)
+ return (NULL);
+ not_reached();
+ return (NULL);
+}
+
+tcache_t *
tcache_create(arena_t *arena)
{
tcache_t *tcache;