Add the "thread.tcache.enabled" mallctl.

This commit is contained in:
Jason Evans
2012-03-26 18:54:44 -07:00
parent fd4fcefa00
commit d4be8b7b6e
7 changed files with 271 additions and 36 deletions

View File

@@ -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)}
};
@@ -966,25 +968,43 @@ RETURN:
return (ret);
}
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:

View File

@@ -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) {
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_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 == (void *)(uintptr_t)2) {
/*
* 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_tsd_set(&tcache);
} 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);
}