summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2012-03-27 01:54:44 (GMT)
committerJason Evans <jasone@canonware.com>2012-03-27 02:02:49 (GMT)
commitd4be8b7b6ee2e21d079180455d4ccbf45cc1cee7 (patch)
treea03c952f7409b34fbe75249dccb211dec03bd036 /src
parentfd4fcefa004e04ea8672b11e280a6ced16c38dd2 (diff)
downloadjemalloc-d4be8b7b6ee2e21d079180455d4ccbf45cc1cee7.zip
jemalloc-d4be8b7b6ee2e21d079180455d4ccbf45cc1cee7.tar.gz
jemalloc-d4be8b7b6ee2e21d079180455d4ccbf45cc1cee7.tar.bz2
Add the "thread.tcache.enabled" mallctl.
Diffstat (limited to 'src')
-rw-r--r--src/ctl.c36
-rw-r--r--src/tcache.c27
2 files changed, 43 insertions, 20 deletions
diff --git a/src/ctl.c b/src/ctl.c
index 943c292..0801161 100644
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -39,6 +39,7 @@ static int ctl_lookup(const char *name, ctl_node_t const **nodesp,
CTL_PROTO(version)
CTL_PROTO(epoch)
+CTL_PROTO(thread_tcache_enabled)
CTL_PROTO(thread_tcache_flush)
CTL_PROTO(thread_arena)
CTL_PROTO(thread_allocated)
@@ -151,6 +152,7 @@ CTL_PROTO(stats_mapped)
#define INDEX(i) false, {.indexed = {i##_index}}, NULL
static const ctl_node_t tcache_node[] = {
+ {NAME("enabled"), CTL(thread_tcache_enabled)},
{NAME("flush"), CTL(thread_tcache_flush)}
};
@@ -967,24 +969,42 @@ RETURN:
}
static int
+thread_tcache_enabled_ctl(const size_t *mib, size_t miblen, void *oldp,
+ size_t *oldlenp, void *newp, size_t newlen)
+{
+ int ret;
+ bool oldval;
+
+ if (config_tcache == false)
+ return (ENOENT);
+
+ oldval = tcache_enabled_get();
+ if (newp != NULL) {
+ if (newlen != sizeof(bool)) {
+ ret = EINVAL;
+ goto RETURN;
+ }
+ tcache_enabled_set(*(bool *)newp);
+ }
+ READ(oldval, bool);
+
+RETURN:
+ ret = 0;
+ return (ret);
+}
+
+static int
thread_tcache_flush_ctl(const size_t *mib, size_t miblen, void *oldp,
size_t *oldlenp, void *newp, size_t newlen)
{
int ret;
- tcache_t *tcache;
if (config_tcache == false)
return (ENOENT);
VOID();
- if ((tcache = *tcache_tsd_get()) == NULL) {
- ret = 0;
- goto RETURN;
- }
- tcache_destroy(tcache);
- tcache = NULL;
- tcache_tsd_set(&tcache);
+ tcache_flush();
ret = 0;
RETURN:
diff --git a/src/tcache.c b/src/tcache.c
index 3442406..bc911a6 100644
--- a/src/tcache.c
+++ b/src/tcache.c
@@ -5,6 +5,7 @@
/* Data. */
malloc_tsd_data(, tcache, tcache_t *, NULL)
+malloc_tsd_data(, tcache_enabled, tcache_enabled_t, tcache_enabled_default)
bool opt_tcache = true;
ssize_t opt_lg_tcache_max = LG_TCACHE_MAXCLASS_DEFAULT;
@@ -328,25 +329,27 @@ tcache_thread_cleanup(void *arg)
{
tcache_t *tcache = *(tcache_t **)arg;
- if (tcache == (void *)(uintptr_t)1) {
- /*
- * The previous time this destructor was called, we set the key
- * to 1 so that other destructors wouldn't cause re-creation of
- * the tcache. This time, do nothing, so that the destructor
- * will not be called again.
- */
- } else if (tcache == (void *)(uintptr_t)2) {
+ if (tcache == TCACHE_STATE_DISABLED) {
+ /* Do nothing. */
+ } else if (tcache == TCACHE_STATE_REINCARNATED) {
/*
* Another destructor called an allocator function after this
* destructor was called. Reset tcache to 1 in order to
* receive another callback.
*/
- tcache = (tcache_t *)(uintptr_t)1;
+ tcache = TCACHE_STATE_PURGATORY;
tcache_tsd_set(&tcache);
+ } else if (tcache == TCACHE_STATE_PURGATORY) {
+ /*
+ * The previous time this destructor was called, we set the key
+ * to 1 so that other destructors wouldn't cause re-creation of
+ * the tcache. This time, do nothing, so that the destructor
+ * will not be called again.
+ */
} else if (tcache != NULL) {
- assert(tcache != (void *)(uintptr_t)1);
+ assert(tcache != TCACHE_STATE_PURGATORY);
tcache_destroy(tcache);
- tcache = (tcache_t *)(uintptr_t)1;
+ tcache = TCACHE_STATE_PURGATORY;
tcache_tsd_set(&tcache);
}
}
@@ -428,7 +431,7 @@ tcache_boot1(void)
{
if (opt_tcache) {
- if (tcache_tsd_boot())
+ if (tcache_tsd_boot() || tcache_enabled_tsd_boot())
return (true);
}