2010-01-28 05:10:55 +08:00
|
|
|
#define JEMALLOC_CTL_C_
|
2010-02-12 06:45:59 +08:00
|
|
|
#include "jemalloc/internal/jemalloc_internal.h"
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Data. */
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
/*
|
|
|
|
* ctl_mtx protects the following:
|
|
|
|
* - ctl_stats.*
|
|
|
|
* - opt_prof_active
|
|
|
|
*/
|
2010-01-28 05:10:55 +08:00
|
|
|
static malloc_mutex_t ctl_mtx;
|
|
|
|
static bool ctl_initialized;
|
|
|
|
static uint64_t ctl_epoch;
|
|
|
|
static ctl_stats_t ctl_stats;
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Helpers for named and indexed nodes. */
|
|
|
|
|
|
|
|
static inline const ctl_named_node_t *
|
|
|
|
ctl_named_node(const ctl_node_t *node)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ((node->named) ? (const ctl_named_node_t *)node : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const ctl_named_node_t *
|
|
|
|
ctl_named_children(const ctl_named_node_t *node, int index)
|
|
|
|
{
|
|
|
|
const ctl_named_node_t *children = ctl_named_node(node->children);
|
|
|
|
|
|
|
|
return (children ? &children[index] : NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const ctl_indexed_node_t *
|
|
|
|
ctl_indexed_node(const ctl_node_t *node)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ((node->named == false) ? (const ctl_indexed_node_t *)node :
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Function prototypes for non-inline static functions. */
|
|
|
|
|
|
|
|
#define CTL_PROTO(n) \
|
|
|
|
static int n##_ctl(const size_t *mib, size_t miblen, void *oldp, \
|
|
|
|
size_t *oldlenp, void *newp, size_t newlen);
|
|
|
|
|
|
|
|
#define INDEX_PROTO(n) \
|
2012-10-12 04:53:15 +08:00
|
|
|
static const ctl_named_node_t *n##_index(const size_t *mib, \
|
|
|
|
size_t miblen, size_t i);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
static bool ctl_arena_init(ctl_arena_stats_t *astats);
|
|
|
|
static void ctl_arena_clear(ctl_arena_stats_t *astats);
|
2010-03-14 12:32:56 +08:00
|
|
|
static void ctl_arena_stats_amerge(ctl_arena_stats_t *cstats,
|
|
|
|
arena_t *arena);
|
|
|
|
static void ctl_arena_stats_smerge(ctl_arena_stats_t *sstats,
|
|
|
|
ctl_arena_stats_t *astats);
|
2010-01-28 05:10:55 +08:00
|
|
|
static void ctl_arena_refresh(arena_t *arena, unsigned i);
|
2012-10-12 04:53:15 +08:00
|
|
|
static bool ctl_grow(void);
|
2010-01-28 05:10:55 +08:00
|
|
|
static void ctl_refresh(void);
|
|
|
|
static bool ctl_init(void);
|
|
|
|
static int ctl_lookup(const char *name, ctl_node_t const **nodesp,
|
|
|
|
size_t *mibp, size_t *depthp);
|
|
|
|
|
2010-03-03 05:01:16 +08:00
|
|
|
CTL_PROTO(version)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(epoch)
|
2012-03-27 09:54:44 +08:00
|
|
|
CTL_PROTO(thread_tcache_enabled)
|
2012-03-17 08:09:32 +08:00
|
|
|
CTL_PROTO(thread_tcache_flush)
|
2010-08-14 06:42:29 +08:00
|
|
|
CTL_PROTO(thread_arena)
|
2010-10-21 08:39:18 +08:00
|
|
|
CTL_PROTO(thread_allocated)
|
2010-12-04 07:55:47 +08:00
|
|
|
CTL_PROTO(thread_allocatedp)
|
2010-10-21 08:39:18 +08:00
|
|
|
CTL_PROTO(thread_deallocated)
|
2010-12-04 07:55:47 +08:00
|
|
|
CTL_PROTO(thread_deallocatedp)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(config_debug)
|
|
|
|
CTL_PROTO(config_fill)
|
|
|
|
CTL_PROTO(config_lazy_lock)
|
2012-05-10 07:12:00 +08:00
|
|
|
CTL_PROTO(config_mremap)
|
2012-04-17 08:52:27 +08:00
|
|
|
CTL_PROTO(config_munmap)
|
2010-02-12 05:19:21 +08:00
|
|
|
CTL_PROTO(config_prof)
|
|
|
|
CTL_PROTO(config_prof_libgcc)
|
|
|
|
CTL_PROTO(config_prof_libunwind)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(config_stats)
|
|
|
|
CTL_PROTO(config_tcache)
|
|
|
|
CTL_PROTO(config_tls)
|
2012-04-06 04:36:17 +08:00
|
|
|
CTL_PROTO(config_utrace)
|
2012-04-06 15:35:09 +08:00
|
|
|
CTL_PROTO(config_valgrind)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(config_xmalloc)
|
|
|
|
CTL_PROTO(opt_abort)
|
2012-10-12 04:53:15 +08:00
|
|
|
CTL_PROTO(opt_dss)
|
2010-10-24 09:37:06 +08:00
|
|
|
CTL_PROTO(opt_lg_chunk)
|
|
|
|
CTL_PROTO(opt_narenas)
|
|
|
|
CTL_PROTO(opt_lg_dirty_mult)
|
|
|
|
CTL_PROTO(opt_stats_print)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(opt_junk)
|
2010-10-24 09:37:06 +08:00
|
|
|
CTL_PROTO(opt_zero)
|
2012-04-06 15:35:09 +08:00
|
|
|
CTL_PROTO(opt_quarantine)
|
|
|
|
CTL_PROTO(opt_redzone)
|
2012-04-06 04:36:17 +08:00
|
|
|
CTL_PROTO(opt_utrace)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(opt_xmalloc)
|
2010-03-08 07:34:14 +08:00
|
|
|
CTL_PROTO(opt_tcache)
|
2012-04-05 07:16:09 +08:00
|
|
|
CTL_PROTO(opt_lg_tcache_max)
|
2010-02-12 05:19:21 +08:00
|
|
|
CTL_PROTO(opt_prof)
|
2010-10-24 09:37:06 +08:00
|
|
|
CTL_PROTO(opt_prof_prefix)
|
2010-04-01 09:43:24 +08:00
|
|
|
CTL_PROTO(opt_prof_active)
|
2010-03-02 12:15:26 +08:00
|
|
|
CTL_PROTO(opt_lg_prof_sample)
|
2010-02-12 05:19:21 +08:00
|
|
|
CTL_PROTO(opt_lg_prof_interval)
|
2010-10-24 09:37:06 +08:00
|
|
|
CTL_PROTO(opt_prof_gdump)
|
2012-04-18 07:39:33 +08:00
|
|
|
CTL_PROTO(opt_prof_final)
|
2010-02-12 05:19:21 +08:00
|
|
|
CTL_PROTO(opt_prof_leak)
|
2010-10-03 06:18:50 +08:00
|
|
|
CTL_PROTO(opt_prof_accum)
|
2012-10-12 04:53:15 +08:00
|
|
|
CTL_PROTO(arena_i_purge)
|
2012-11-04 12:18:28 +08:00
|
|
|
static void arena_purge(unsigned arena_ind);
|
2012-10-12 04:53:15 +08:00
|
|
|
CTL_PROTO(arena_i_dss)
|
|
|
|
INDEX_PROTO(arena_i)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(arenas_bin_i_size)
|
|
|
|
CTL_PROTO(arenas_bin_i_nregs)
|
|
|
|
CTL_PROTO(arenas_bin_i_run_size)
|
|
|
|
INDEX_PROTO(arenas_bin_i)
|
|
|
|
CTL_PROTO(arenas_lrun_i_size)
|
|
|
|
INDEX_PROTO(arenas_lrun_i)
|
|
|
|
CTL_PROTO(arenas_narenas)
|
|
|
|
CTL_PROTO(arenas_initialized)
|
|
|
|
CTL_PROTO(arenas_quantum)
|
2012-04-02 22:04:34 +08:00
|
|
|
CTL_PROTO(arenas_page)
|
2010-03-18 07:27:39 +08:00
|
|
|
CTL_PROTO(arenas_tcache_max)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(arenas_nbins)
|
2010-03-18 07:27:39 +08:00
|
|
|
CTL_PROTO(arenas_nhbins)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(arenas_nlruns)
|
2012-10-12 04:53:15 +08:00
|
|
|
CTL_PROTO(arenas_extend)
|
2010-04-01 09:43:24 +08:00
|
|
|
CTL_PROTO(prof_active)
|
2010-02-12 05:19:21 +08:00
|
|
|
CTL_PROTO(prof_dump)
|
|
|
|
CTL_PROTO(prof_interval)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(stats_chunks_current)
|
|
|
|
CTL_PROTO(stats_chunks_total)
|
|
|
|
CTL_PROTO(stats_chunks_high)
|
|
|
|
CTL_PROTO(stats_huge_allocated)
|
|
|
|
CTL_PROTO(stats_huge_nmalloc)
|
|
|
|
CTL_PROTO(stats_huge_ndalloc)
|
|
|
|
CTL_PROTO(stats_arenas_i_small_allocated)
|
|
|
|
CTL_PROTO(stats_arenas_i_small_nmalloc)
|
|
|
|
CTL_PROTO(stats_arenas_i_small_ndalloc)
|
2010-03-14 12:32:56 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_small_nrequests)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_large_allocated)
|
|
|
|
CTL_PROTO(stats_arenas_i_large_nmalloc)
|
|
|
|
CTL_PROTO(stats_arenas_i_large_ndalloc)
|
2010-03-18 07:27:39 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_large_nrequests)
|
2010-03-14 12:32:56 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_allocated)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_nmalloc)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_ndalloc)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_nrequests)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_nfills)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_nflushes)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_nruns)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_nreruns)
|
|
|
|
CTL_PROTO(stats_arenas_i_bins_j_curruns)
|
|
|
|
INDEX_PROTO(stats_arenas_i_bins_j)
|
2010-03-18 07:27:39 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_lruns_j_nmalloc)
|
|
|
|
CTL_PROTO(stats_arenas_i_lruns_j_ndalloc)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_lruns_j_nrequests)
|
|
|
|
CTL_PROTO(stats_arenas_i_lruns_j_curruns)
|
|
|
|
INDEX_PROTO(stats_arenas_i_lruns_j)
|
2011-03-19 04:41:33 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_nthreads)
|
2012-10-12 04:53:15 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_dss)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(stats_arenas_i_pactive)
|
|
|
|
CTL_PROTO(stats_arenas_i_pdirty)
|
|
|
|
CTL_PROTO(stats_arenas_i_mapped)
|
|
|
|
CTL_PROTO(stats_arenas_i_npurge)
|
|
|
|
CTL_PROTO(stats_arenas_i_nmadvise)
|
|
|
|
CTL_PROTO(stats_arenas_i_purged)
|
|
|
|
INDEX_PROTO(stats_arenas_i)
|
2011-03-19 08:56:14 +08:00
|
|
|
CTL_PROTO(stats_cactive)
|
2010-01-28 05:10:55 +08:00
|
|
|
CTL_PROTO(stats_allocated)
|
|
|
|
CTL_PROTO(stats_active)
|
|
|
|
CTL_PROTO(stats_mapped)
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* mallctl tree. */
|
|
|
|
|
|
|
|
/* Maximum tree depth. */
|
|
|
|
#define CTL_MAX_DEPTH 6
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
#define NAME(n) {true}, n
|
2012-04-24 10:31:45 +08:00
|
|
|
#define CHILD(t, c) \
|
|
|
|
sizeof(c##_node) / sizeof(ctl_##t##_node_t), \
|
|
|
|
(ctl_node_t *)c##_node, \
|
|
|
|
NULL
|
2012-04-20 14:38:42 +08:00
|
|
|
#define CTL(c) 0, NULL, c##_ctl
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only handles internal indexed nodes, since there are currently no external
|
|
|
|
* ones.
|
|
|
|
*/
|
2012-04-20 14:38:42 +08:00
|
|
|
#define INDEX(i) {false}, i##_index
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t tcache_node[] = {
|
2012-03-27 09:54:44 +08:00
|
|
|
{NAME("enabled"), CTL(thread_tcache_enabled)},
|
2012-03-17 08:09:32 +08:00
|
|
|
{NAME("flush"), CTL(thread_tcache_flush)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t thread_node[] = {
|
2012-02-11 12:22:09 +08:00
|
|
|
{NAME("arena"), CTL(thread_arena)},
|
2010-10-21 08:39:18 +08:00
|
|
|
{NAME("allocated"), CTL(thread_allocated)},
|
2010-12-04 07:55:47 +08:00
|
|
|
{NAME("allocatedp"), CTL(thread_allocatedp)},
|
|
|
|
{NAME("deallocated"), CTL(thread_deallocated)},
|
2012-03-17 08:09:32 +08:00
|
|
|
{NAME("deallocatedp"), CTL(thread_deallocatedp)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("tcache"), CHILD(named, tcache)}
|
2010-08-14 06:42:29 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t config_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("debug"), CTL(config_debug)},
|
|
|
|
{NAME("fill"), CTL(config_fill)},
|
|
|
|
{NAME("lazy_lock"), CTL(config_lazy_lock)},
|
2012-05-10 07:12:00 +08:00
|
|
|
{NAME("mremap"), CTL(config_mremap)},
|
2012-04-17 08:52:27 +08:00
|
|
|
{NAME("munmap"), CTL(config_munmap)},
|
2010-02-12 05:19:21 +08:00
|
|
|
{NAME("prof"), CTL(config_prof)},
|
|
|
|
{NAME("prof_libgcc"), CTL(config_prof_libgcc)},
|
|
|
|
{NAME("prof_libunwind"), CTL(config_prof_libunwind)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("stats"), CTL(config_stats)},
|
|
|
|
{NAME("tcache"), CTL(config_tcache)},
|
|
|
|
{NAME("tls"), CTL(config_tls)},
|
2012-04-06 04:36:17 +08:00
|
|
|
{NAME("utrace"), CTL(config_utrace)},
|
2012-04-06 15:35:09 +08:00
|
|
|
{NAME("valgrind"), CTL(config_valgrind)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("xmalloc"), CTL(config_xmalloc)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t opt_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("abort"), CTL(opt_abort)},
|
2012-10-12 04:53:15 +08:00
|
|
|
{NAME("dss"), CTL(opt_dss)},
|
2010-10-24 09:37:06 +08:00
|
|
|
{NAME("lg_chunk"), CTL(opt_lg_chunk)},
|
|
|
|
{NAME("narenas"), CTL(opt_narenas)},
|
|
|
|
{NAME("lg_dirty_mult"), CTL(opt_lg_dirty_mult)},
|
2012-02-11 12:22:09 +08:00
|
|
|
{NAME("stats_print"), CTL(opt_stats_print)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("junk"), CTL(opt_junk)},
|
2012-02-11 12:22:09 +08:00
|
|
|
{NAME("zero"), CTL(opt_zero)},
|
2012-04-06 15:35:09 +08:00
|
|
|
{NAME("quarantine"), CTL(opt_quarantine)},
|
|
|
|
{NAME("redzone"), CTL(opt_redzone)},
|
2012-04-06 04:36:17 +08:00
|
|
|
{NAME("utrace"), CTL(opt_utrace)},
|
2012-02-11 12:22:09 +08:00
|
|
|
{NAME("xmalloc"), CTL(opt_xmalloc)},
|
2010-03-08 07:34:14 +08:00
|
|
|
{NAME("tcache"), CTL(opt_tcache)},
|
2012-04-05 07:16:09 +08:00
|
|
|
{NAME("lg_tcache_max"), CTL(opt_lg_tcache_max)},
|
2010-02-12 05:19:21 +08:00
|
|
|
{NAME("prof"), CTL(opt_prof)},
|
2010-10-24 09:37:06 +08:00
|
|
|
{NAME("prof_prefix"), CTL(opt_prof_prefix)},
|
2010-04-01 09:43:24 +08:00
|
|
|
{NAME("prof_active"), CTL(opt_prof_active)},
|
2010-03-02 12:15:26 +08:00
|
|
|
{NAME("lg_prof_sample"), CTL(opt_lg_prof_sample)},
|
2010-02-12 05:19:21 +08:00
|
|
|
{NAME("lg_prof_interval"), CTL(opt_lg_prof_interval)},
|
2010-10-24 09:37:06 +08:00
|
|
|
{NAME("prof_gdump"), CTL(opt_prof_gdump)},
|
2012-04-18 07:39:33 +08:00
|
|
|
{NAME("prof_final"), CTL(opt_prof_final)},
|
2010-02-12 05:19:21 +08:00
|
|
|
{NAME("prof_leak"), CTL(opt_prof_leak)},
|
2012-02-14 10:04:26 +08:00
|
|
|
{NAME("prof_accum"), CTL(opt_prof_accum)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static const ctl_named_node_t arena_i_node[] = {
|
|
|
|
{NAME("purge"), CTL(arena_i_purge)},
|
|
|
|
{NAME("dss"), CTL(arena_i_dss)}
|
|
|
|
};
|
|
|
|
static const ctl_named_node_t super_arena_i_node[] = {
|
|
|
|
{NAME(""), CHILD(named, arena_i)}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ctl_indexed_node_t arena_node[] = {
|
|
|
|
{INDEX(arena_i)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t arenas_bin_i_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("size"), CTL(arenas_bin_i_size)},
|
|
|
|
{NAME("nregs"), CTL(arenas_bin_i_nregs)},
|
|
|
|
{NAME("run_size"), CTL(arenas_bin_i_run_size)}
|
|
|
|
};
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t super_arenas_bin_i_node[] = {
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME(""), CHILD(named, arenas_bin_i)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_indexed_node_t arenas_bin_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{INDEX(arenas_bin_i)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t arenas_lrun_i_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("size"), CTL(arenas_lrun_i_size)}
|
|
|
|
};
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t super_arenas_lrun_i_node[] = {
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME(""), CHILD(named, arenas_lrun_i)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_indexed_node_t arenas_lrun_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{INDEX(arenas_lrun_i)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t arenas_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("narenas"), CTL(arenas_narenas)},
|
|
|
|
{NAME("initialized"), CTL(arenas_initialized)},
|
|
|
|
{NAME("quantum"), CTL(arenas_quantum)},
|
2012-04-02 22:04:34 +08:00
|
|
|
{NAME("page"), CTL(arenas_page)},
|
2010-03-18 07:27:39 +08:00
|
|
|
{NAME("tcache_max"), CTL(arenas_tcache_max)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("nbins"), CTL(arenas_nbins)},
|
2010-03-18 07:27:39 +08:00
|
|
|
{NAME("nhbins"), CTL(arenas_nhbins)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("bin"), CHILD(indexed, arenas_bin)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("nlruns"), CTL(arenas_nlruns)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("lrun"), CHILD(indexed, arenas_lrun)},
|
2012-10-12 04:53:15 +08:00
|
|
|
{NAME("extend"), CTL(arenas_extend)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t prof_node[] = {
|
2010-04-01 09:43:24 +08:00
|
|
|
{NAME("active"), CTL(prof_active)},
|
2010-02-12 05:19:21 +08:00
|
|
|
{NAME("dump"), CTL(prof_dump)},
|
|
|
|
{NAME("interval"), CTL(prof_interval)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_chunks_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("current"), CTL(stats_chunks_current)},
|
|
|
|
{NAME("total"), CTL(stats_chunks_total)},
|
|
|
|
{NAME("high"), CTL(stats_chunks_high)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_huge_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("allocated"), CTL(stats_huge_allocated)},
|
|
|
|
{NAME("nmalloc"), CTL(stats_huge_nmalloc)},
|
|
|
|
{NAME("ndalloc"), CTL(stats_huge_ndalloc)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_arenas_i_small_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("allocated"), CTL(stats_arenas_i_small_allocated)},
|
|
|
|
{NAME("nmalloc"), CTL(stats_arenas_i_small_nmalloc)},
|
2010-03-14 12:32:56 +08:00
|
|
|
{NAME("ndalloc"), CTL(stats_arenas_i_small_ndalloc)},
|
|
|
|
{NAME("nrequests"), CTL(stats_arenas_i_small_nrequests)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_arenas_i_large_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("allocated"), CTL(stats_arenas_i_large_allocated)},
|
|
|
|
{NAME("nmalloc"), CTL(stats_arenas_i_large_nmalloc)},
|
2010-03-18 07:27:39 +08:00
|
|
|
{NAME("ndalloc"), CTL(stats_arenas_i_large_ndalloc)},
|
|
|
|
{NAME("nrequests"), CTL(stats_arenas_i_large_nrequests)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_arenas_i_bins_j_node[] = {
|
2010-03-14 12:32:56 +08:00
|
|
|
{NAME("allocated"), CTL(stats_arenas_i_bins_j_allocated)},
|
|
|
|
{NAME("nmalloc"), CTL(stats_arenas_i_bins_j_nmalloc)},
|
|
|
|
{NAME("ndalloc"), CTL(stats_arenas_i_bins_j_ndalloc)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("nrequests"), CTL(stats_arenas_i_bins_j_nrequests)},
|
|
|
|
{NAME("nfills"), CTL(stats_arenas_i_bins_j_nfills)},
|
|
|
|
{NAME("nflushes"), CTL(stats_arenas_i_bins_j_nflushes)},
|
|
|
|
{NAME("nruns"), CTL(stats_arenas_i_bins_j_nruns)},
|
|
|
|
{NAME("nreruns"), CTL(stats_arenas_i_bins_j_nreruns)},
|
|
|
|
{NAME("curruns"), CTL(stats_arenas_i_bins_j_curruns)}
|
|
|
|
};
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t super_stats_arenas_i_bins_j_node[] = {
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME(""), CHILD(named, stats_arenas_i_bins_j)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_indexed_node_t stats_arenas_i_bins_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{INDEX(stats_arenas_i_bins_j)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_arenas_i_lruns_j_node[] = {
|
2010-03-18 07:27:39 +08:00
|
|
|
{NAME("nmalloc"), CTL(stats_arenas_i_lruns_j_nmalloc)},
|
|
|
|
{NAME("ndalloc"), CTL(stats_arenas_i_lruns_j_ndalloc)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("nrequests"), CTL(stats_arenas_i_lruns_j_nrequests)},
|
|
|
|
{NAME("curruns"), CTL(stats_arenas_i_lruns_j_curruns)}
|
|
|
|
};
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t super_stats_arenas_i_lruns_j_node[] = {
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME(""), CHILD(named, stats_arenas_i_lruns_j)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_indexed_node_t stats_arenas_i_lruns_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{INDEX(stats_arenas_i_lruns_j)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_arenas_i_node[] = {
|
2011-03-19 04:41:33 +08:00
|
|
|
{NAME("nthreads"), CTL(stats_arenas_i_nthreads)},
|
2012-10-12 04:53:15 +08:00
|
|
|
{NAME("dss"), CTL(stats_arenas_i_dss)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("pactive"), CTL(stats_arenas_i_pactive)},
|
2012-02-11 12:22:09 +08:00
|
|
|
{NAME("pdirty"), CTL(stats_arenas_i_pdirty)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("mapped"), CTL(stats_arenas_i_mapped)},
|
|
|
|
{NAME("npurge"), CTL(stats_arenas_i_npurge)},
|
|
|
|
{NAME("nmadvise"), CTL(stats_arenas_i_nmadvise)},
|
|
|
|
{NAME("purged"), CTL(stats_arenas_i_purged)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("small"), CHILD(named, stats_arenas_i_small)},
|
|
|
|
{NAME("large"), CHILD(named, stats_arenas_i_large)},
|
2012-04-24 10:54:15 +08:00
|
|
|
{NAME("bins"), CHILD(indexed, stats_arenas_i_bins)},
|
|
|
|
{NAME("lruns"), CHILD(indexed, stats_arenas_i_lruns)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t super_stats_arenas_i_node[] = {
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME(""), CHILD(named, stats_arenas_i)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_indexed_node_t stats_arenas_node[] = {
|
2010-01-28 05:10:55 +08:00
|
|
|
{INDEX(stats_arenas_i)}
|
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t stats_node[] = {
|
2011-03-19 08:56:14 +08:00
|
|
|
{NAME("cactive"), CTL(stats_cactive)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("allocated"), CTL(stats_allocated)},
|
|
|
|
{NAME("active"), CTL(stats_active)},
|
|
|
|
{NAME("mapped"), CTL(stats_mapped)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("chunks"), CHILD(named, stats_chunks)},
|
|
|
|
{NAME("huge"), CHILD(named, stats_huge)},
|
|
|
|
{NAME("arenas"), CHILD(indexed, stats_arenas)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t root_node[] = {
|
2010-03-03 05:01:16 +08:00
|
|
|
{NAME("version"), CTL(version)},
|
2010-01-28 05:10:55 +08:00
|
|
|
{NAME("epoch"), CTL(epoch)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("thread"), CHILD(named, thread)},
|
|
|
|
{NAME("config"), CHILD(named, config)},
|
|
|
|
{NAME("opt"), CHILD(named, opt)},
|
2012-10-12 04:53:15 +08:00
|
|
|
{NAME("arena"), CHILD(indexed, arena)},
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME("arenas"), CHILD(named, arenas)},
|
|
|
|
{NAME("prof"), CHILD(named, prof)},
|
|
|
|
{NAME("stats"), CHILD(named, stats)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
2012-04-20 14:38:42 +08:00
|
|
|
static const ctl_named_node_t super_root_node[] = {
|
2012-04-24 10:31:45 +08:00
|
|
|
{NAME(""), CHILD(named, root)}
|
2010-01-28 05:10:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#undef NAME
|
|
|
|
#undef CHILD
|
|
|
|
#undef CTL
|
|
|
|
#undef INDEX
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ctl_arena_init(ctl_arena_stats_t *astats)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (astats->lstats == NULL) {
|
|
|
|
astats->lstats = (malloc_large_stats_t *)base_alloc(nlclasses *
|
|
|
|
sizeof(malloc_large_stats_t));
|
|
|
|
if (astats->lstats == NULL)
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ctl_arena_clear(ctl_arena_stats_t *astats)
|
|
|
|
{
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
astats->dss = dss_prec_names[dss_prec_limit];
|
2010-01-28 05:10:55 +08:00
|
|
|
astats->pactive = 0;
|
|
|
|
astats->pdirty = 0;
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
memset(&astats->astats, 0, sizeof(arena_stats_t));
|
|
|
|
astats->allocated_small = 0;
|
|
|
|
astats->nmalloc_small = 0;
|
|
|
|
astats->ndalloc_small = 0;
|
|
|
|
astats->nrequests_small = 0;
|
2012-02-29 08:50:47 +08:00
|
|
|
memset(astats->bstats, 0, NBINS * sizeof(malloc_bin_stats_t));
|
2012-02-11 12:22:09 +08:00
|
|
|
memset(astats->lstats, 0, nlclasses *
|
|
|
|
sizeof(malloc_large_stats_t));
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
2010-03-14 12:32:56 +08:00
|
|
|
static void
|
|
|
|
ctl_arena_stats_amerge(ctl_arena_stats_t *cstats, arena_t *arena)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
arena_stats_merge(arena, &cstats->dss, &cstats->pactive,
|
|
|
|
&cstats->pdirty, &cstats->astats, cstats->bstats, cstats->lstats);
|
2010-03-14 12:32:56 +08:00
|
|
|
|
2012-02-29 08:50:47 +08:00
|
|
|
for (i = 0; i < NBINS; i++) {
|
2010-03-14 12:32:56 +08:00
|
|
|
cstats->allocated_small += cstats->bstats[i].allocated;
|
|
|
|
cstats->nmalloc_small += cstats->bstats[i].nmalloc;
|
|
|
|
cstats->ndalloc_small += cstats->bstats[i].ndalloc;
|
|
|
|
cstats->nrequests_small += cstats->bstats[i].nrequests;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ctl_arena_stats_smerge(ctl_arena_stats_t *sstats, ctl_arena_stats_t *astats)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
sstats->pactive += astats->pactive;
|
|
|
|
sstats->pdirty += astats->pdirty;
|
|
|
|
|
|
|
|
sstats->astats.mapped += astats->astats.mapped;
|
|
|
|
sstats->astats.npurge += astats->astats.npurge;
|
|
|
|
sstats->astats.nmadvise += astats->astats.nmadvise;
|
|
|
|
sstats->astats.purged += astats->astats.purged;
|
|
|
|
|
|
|
|
sstats->allocated_small += astats->allocated_small;
|
|
|
|
sstats->nmalloc_small += astats->nmalloc_small;
|
|
|
|
sstats->ndalloc_small += astats->ndalloc_small;
|
|
|
|
sstats->nrequests_small += astats->nrequests_small;
|
|
|
|
|
|
|
|
sstats->astats.allocated_large += astats->astats.allocated_large;
|
|
|
|
sstats->astats.nmalloc_large += astats->astats.nmalloc_large;
|
|
|
|
sstats->astats.ndalloc_large += astats->astats.ndalloc_large;
|
2010-03-18 07:27:39 +08:00
|
|
|
sstats->astats.nrequests_large += astats->astats.nrequests_large;
|
2010-03-14 12:32:56 +08:00
|
|
|
|
|
|
|
for (i = 0; i < nlclasses; i++) {
|
2010-03-18 07:27:39 +08:00
|
|
|
sstats->lstats[i].nmalloc += astats->lstats[i].nmalloc;
|
|
|
|
sstats->lstats[i].ndalloc += astats->lstats[i].ndalloc;
|
2010-03-14 12:32:56 +08:00
|
|
|
sstats->lstats[i].nrequests += astats->lstats[i].nrequests;
|
|
|
|
sstats->lstats[i].curruns += astats->lstats[i].curruns;
|
|
|
|
}
|
|
|
|
|
2012-02-29 08:50:47 +08:00
|
|
|
for (i = 0; i < NBINS; i++) {
|
2010-03-14 12:32:56 +08:00
|
|
|
sstats->bstats[i].allocated += astats->bstats[i].allocated;
|
|
|
|
sstats->bstats[i].nmalloc += astats->bstats[i].nmalloc;
|
|
|
|
sstats->bstats[i].ndalloc += astats->bstats[i].ndalloc;
|
|
|
|
sstats->bstats[i].nrequests += astats->bstats[i].nrequests;
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_tcache) {
|
|
|
|
sstats->bstats[i].nfills += astats->bstats[i].nfills;
|
|
|
|
sstats->bstats[i].nflushes +=
|
|
|
|
astats->bstats[i].nflushes;
|
|
|
|
}
|
2010-03-14 12:32:56 +08:00
|
|
|
sstats->bstats[i].nruns += astats->bstats[i].nruns;
|
|
|
|
sstats->bstats[i].reruns += astats->bstats[i].reruns;
|
|
|
|
sstats->bstats[i].curruns += astats->bstats[i].curruns;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
static void
|
|
|
|
ctl_arena_refresh(arena_t *arena, unsigned i)
|
|
|
|
{
|
|
|
|
ctl_arena_stats_t *astats = &ctl_stats.arenas[i];
|
2012-10-12 04:53:15 +08:00
|
|
|
ctl_arena_stats_t *sstats = &ctl_stats.arenas[ctl_stats.narenas];
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
ctl_arena_clear(astats);
|
|
|
|
|
2011-03-19 04:41:33 +08:00
|
|
|
sstats->nthreads += astats->nthreads;
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
ctl_arena_stats_amerge(astats, arena);
|
|
|
|
/* Merge into sum stats as well. */
|
|
|
|
ctl_arena_stats_smerge(sstats, astats);
|
|
|
|
} else {
|
|
|
|
astats->pactive += arena->nactive;
|
|
|
|
astats->pdirty += arena->ndirty;
|
|
|
|
/* Merge into sum stats as well. */
|
|
|
|
sstats->pactive += arena->nactive;
|
|
|
|
sstats->pdirty += arena->ndirty;
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static bool
|
|
|
|
ctl_grow(void)
|
|
|
|
{
|
|
|
|
ctl_arena_stats_t *astats;
|
|
|
|
arena_t **tarenas;
|
|
|
|
|
2013-10-21 05:09:54 +08:00
|
|
|
/* Allocate extended arena stats and arenas arrays. */
|
|
|
|
astats = (ctl_arena_stats_t *)imalloc((ctl_stats.narenas + 2) *
|
|
|
|
sizeof(ctl_arena_stats_t));
|
|
|
|
if (astats == NULL)
|
|
|
|
return (true);
|
|
|
|
tarenas = (arena_t **)imalloc((ctl_stats.narenas + 1) *
|
|
|
|
sizeof(arena_t *));
|
|
|
|
if (tarenas == NULL) {
|
|
|
|
idalloc(astats);
|
|
|
|
return (true);
|
2012-10-12 04:53:15 +08:00
|
|
|
}
|
2013-10-21 05:09:54 +08:00
|
|
|
|
|
|
|
/* Initialize the new astats element. */
|
|
|
|
memcpy(astats, ctl_stats.arenas, (ctl_stats.narenas + 1) *
|
|
|
|
sizeof(ctl_arena_stats_t));
|
2012-10-12 04:53:15 +08:00
|
|
|
memset(&astats[ctl_stats.narenas + 1], 0, sizeof(ctl_arena_stats_t));
|
2013-10-21 05:09:54 +08:00
|
|
|
if (ctl_arena_init(&astats[ctl_stats.narenas + 1])) {
|
|
|
|
idalloc(tarenas);
|
|
|
|
idalloc(astats);
|
2012-10-12 04:53:15 +08:00
|
|
|
return (true);
|
2013-10-21 05:09:54 +08:00
|
|
|
}
|
2012-10-12 04:53:15 +08:00
|
|
|
/* Swap merged stats to their new location. */
|
|
|
|
{
|
|
|
|
ctl_arena_stats_t tstats;
|
|
|
|
memcpy(&tstats, &astats[ctl_stats.narenas],
|
|
|
|
sizeof(ctl_arena_stats_t));
|
|
|
|
memcpy(&astats[ctl_stats.narenas],
|
|
|
|
&astats[ctl_stats.narenas + 1], sizeof(ctl_arena_stats_t));
|
|
|
|
memcpy(&astats[ctl_stats.narenas + 1], &tstats,
|
|
|
|
sizeof(ctl_arena_stats_t));
|
|
|
|
}
|
2013-10-21 05:09:54 +08:00
|
|
|
/* Initialize the new arenas element. */
|
|
|
|
tarenas[ctl_stats.narenas] = NULL;
|
|
|
|
{
|
|
|
|
arena_t **arenas_old = arenas;
|
|
|
|
/*
|
|
|
|
* Swap extended arenas array into place. Although ctl_mtx
|
|
|
|
* protects this function from other threads extending the
|
|
|
|
* array, it does not protect from other threads mutating it
|
|
|
|
* (i.e. initializing arenas and setting array elements to
|
|
|
|
* point to them). Therefore, array copying must happen under
|
|
|
|
* the protection of arenas_lock.
|
|
|
|
*/
|
|
|
|
malloc_mutex_lock(&arenas_lock);
|
|
|
|
arenas = tarenas;
|
|
|
|
memcpy(arenas, arenas_old, ctl_stats.narenas *
|
|
|
|
sizeof(arena_t *));
|
|
|
|
narenas_total++;
|
|
|
|
arenas_extend(narenas_total - 1);
|
|
|
|
malloc_mutex_unlock(&arenas_lock);
|
|
|
|
/*
|
|
|
|
* Deallocate arenas_old only if it came from imalloc() (not
|
|
|
|
* base_alloc()).
|
|
|
|
*/
|
|
|
|
if (ctl_stats.narenas != narenas_auto)
|
|
|
|
idalloc(arenas_old);
|
|
|
|
}
|
2012-10-12 04:53:15 +08:00
|
|
|
ctl_stats.arenas = astats;
|
|
|
|
ctl_stats.narenas++;
|
|
|
|
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
static void
|
|
|
|
ctl_refresh(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
2012-10-12 04:53:15 +08:00
|
|
|
VARIABLE_ARRAY(arena_t *, tarenas, ctl_stats.narenas);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
malloc_mutex_lock(&chunks_mtx);
|
|
|
|
ctl_stats.chunks.current = stats_chunks.curchunks;
|
|
|
|
ctl_stats.chunks.total = stats_chunks.nchunks;
|
|
|
|
ctl_stats.chunks.high = stats_chunks.highchunks;
|
|
|
|
malloc_mutex_unlock(&chunks_mtx);
|
|
|
|
|
|
|
|
malloc_mutex_lock(&huge_mtx);
|
|
|
|
ctl_stats.huge.allocated = huge_allocated;
|
|
|
|
ctl_stats.huge.nmalloc = huge_nmalloc;
|
|
|
|
ctl_stats.huge.ndalloc = huge_ndalloc;
|
|
|
|
malloc_mutex_unlock(&huge_mtx);
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
/*
|
2010-01-31 19:57:29 +08:00
|
|
|
* Clear sum stats, since they will be merged into by
|
2010-01-28 05:10:55 +08:00
|
|
|
* ctl_arena_refresh().
|
|
|
|
*/
|
2012-10-12 04:53:15 +08:00
|
|
|
ctl_stats.arenas[ctl_stats.narenas].nthreads = 0;
|
|
|
|
ctl_arena_clear(&ctl_stats.arenas[ctl_stats.narenas]);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
malloc_mutex_lock(&arenas_lock);
|
2012-10-12 04:53:15 +08:00
|
|
|
memcpy(tarenas, arenas, sizeof(arena_t *) * ctl_stats.narenas);
|
|
|
|
for (i = 0; i < ctl_stats.narenas; i++) {
|
2011-03-19 04:41:33 +08:00
|
|
|
if (arenas[i] != NULL)
|
|
|
|
ctl_stats.arenas[i].nthreads = arenas[i]->nthreads;
|
|
|
|
else
|
|
|
|
ctl_stats.arenas[i].nthreads = 0;
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
malloc_mutex_unlock(&arenas_lock);
|
2012-10-12 04:53:15 +08:00
|
|
|
for (i = 0; i < ctl_stats.narenas; i++) {
|
2010-01-28 05:10:55 +08:00
|
|
|
bool initialized = (tarenas[i] != NULL);
|
|
|
|
|
|
|
|
ctl_stats.arenas[i].initialized = initialized;
|
|
|
|
if (initialized)
|
|
|
|
ctl_arena_refresh(tarenas[i], i);
|
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
2012-10-12 04:53:15 +08:00
|
|
|
ctl_stats.allocated =
|
|
|
|
ctl_stats.arenas[ctl_stats.narenas].allocated_small
|
|
|
|
+ ctl_stats.arenas[ctl_stats.narenas].astats.allocated_large
|
|
|
|
+ ctl_stats.huge.allocated;
|
|
|
|
ctl_stats.active =
|
|
|
|
(ctl_stats.arenas[ctl_stats.narenas].pactive << LG_PAGE)
|
2012-02-11 12:22:09 +08:00
|
|
|
+ ctl_stats.huge.allocated;
|
|
|
|
ctl_stats.mapped = (ctl_stats.chunks.current << opt_lg_chunk);
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
ctl_epoch++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ctl_init(void)
|
|
|
|
{
|
2010-11-25 07:44:21 +08:00
|
|
|
bool ret;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
2010-01-28 05:10:55 +08:00
|
|
|
if (ctl_initialized == false) {
|
|
|
|
/*
|
|
|
|
* Allocate space for one extra arena stats element, which
|
|
|
|
* contains summed stats across all arenas.
|
|
|
|
*/
|
2012-10-12 04:53:15 +08:00
|
|
|
assert(narenas_auto == narenas_total_get());
|
|
|
|
ctl_stats.narenas = narenas_auto;
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas = (ctl_arena_stats_t *)base_alloc(
|
2012-10-12 04:53:15 +08:00
|
|
|
(ctl_stats.narenas + 1) * sizeof(ctl_arena_stats_t));
|
2010-11-25 07:44:21 +08:00
|
|
|
if (ctl_stats.arenas == NULL) {
|
|
|
|
ret = true;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-11-25 07:44:21 +08:00
|
|
|
}
|
2012-10-12 04:53:15 +08:00
|
|
|
memset(ctl_stats.arenas, 0, (ctl_stats.narenas + 1) *
|
2010-01-28 05:10:55 +08:00
|
|
|
sizeof(ctl_arena_stats_t));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize all stats structures, regardless of whether they
|
|
|
|
* ever get used. Lazy initialization would allow errors to
|
|
|
|
* cause inconsistent state to be viewable by the application.
|
|
|
|
*/
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_stats) {
|
|
|
|
unsigned i;
|
2012-10-12 04:53:15 +08:00
|
|
|
for (i = 0; i <= ctl_stats.narenas; i++) {
|
2012-02-11 12:22:09 +08:00
|
|
|
if (ctl_arena_init(&ctl_stats.arenas[i])) {
|
|
|
|
ret = true;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2012-02-11 12:22:09 +08:00
|
|
|
}
|
2010-11-25 07:44:21 +08:00
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2012-10-12 04:53:15 +08:00
|
|
|
ctl_stats.arenas[ctl_stats.narenas].initialized = true;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
ctl_epoch = 0;
|
|
|
|
ctl_refresh();
|
|
|
|
ctl_initialized = true;
|
|
|
|
}
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
ret = false;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
|
|
|
return (ret);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ctl_lookup(const char *name, ctl_node_t const **nodesp, size_t *mibp,
|
|
|
|
size_t *depthp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
const char *elm, *tdot, *dot;
|
|
|
|
size_t elen, i, j;
|
2012-04-20 14:38:42 +08:00
|
|
|
const ctl_named_node_t *node;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
elm = name;
|
|
|
|
/* Equivalent to strchrnul(). */
|
|
|
|
dot = ((tdot = strchr(elm, '.')) != NULL) ? tdot : strchr(elm, '\0');
|
|
|
|
elen = (size_t)((uintptr_t)dot - (uintptr_t)elm);
|
|
|
|
if (elen == 0) {
|
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
node = super_root_node;
|
|
|
|
for (i = 0; i < *depthp; i++) {
|
2012-04-20 14:38:42 +08:00
|
|
|
assert(node);
|
|
|
|
assert(node->nchildren > 0);
|
|
|
|
if (ctl_named_node(node->children) != NULL) {
|
|
|
|
const ctl_named_node_t *pnode = node;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
/* Children are named. */
|
2012-04-20 14:38:42 +08:00
|
|
|
for (j = 0; j < node->nchildren; j++) {
|
|
|
|
const ctl_named_node_t *child =
|
|
|
|
ctl_named_children(node, j);
|
|
|
|
if (strlen(child->name) == elen &&
|
|
|
|
strncmp(elm, child->name, elen) == 0) {
|
2010-01-28 05:10:55 +08:00
|
|
|
node = child;
|
|
|
|
if (nodesp != NULL)
|
2012-04-20 14:38:42 +08:00
|
|
|
nodesp[i] =
|
|
|
|
(const ctl_node_t *)node;
|
2010-01-28 05:10:55 +08:00
|
|
|
mibp[i] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node == pnode) {
|
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
} else {
|
2012-02-03 14:04:57 +08:00
|
|
|
uintmax_t index;
|
2012-04-20 14:38:42 +08:00
|
|
|
const ctl_indexed_node_t *inode;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
/* Children are indexed. */
|
2012-02-03 14:04:57 +08:00
|
|
|
index = malloc_strtoumax(elm, NULL, 10);
|
|
|
|
if (index == UINTMAX_MAX || index > SIZE_T_MAX) {
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
inode = ctl_indexed_node(node->children);
|
|
|
|
node = inode->index(mibp, *depthp, (size_t)index);
|
2010-01-28 05:10:55 +08:00
|
|
|
if (node == NULL) {
|
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nodesp != NULL)
|
2012-04-20 14:38:42 +08:00
|
|
|
nodesp[i] = (const ctl_node_t *)node;
|
2010-01-28 05:10:55 +08:00
|
|
|
mibp[i] = (size_t)index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->ctl != NULL) {
|
|
|
|
/* Terminal node. */
|
|
|
|
if (*dot != '\0') {
|
|
|
|
/*
|
|
|
|
* The name contains more elements than are
|
|
|
|
* in this path through the tree.
|
|
|
|
*/
|
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
/* Complete lookup successful. */
|
|
|
|
*depthp = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update elm. */
|
|
|
|
if (*dot == '\0') {
|
|
|
|
/* No more elements. */
|
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
elm = &dot[1];
|
|
|
|
dot = ((tdot = strchr(elm, '.')) != NULL) ? tdot :
|
|
|
|
strchr(elm, '\0');
|
|
|
|
elen = (size_t)((uintptr_t)dot - (uintptr_t)elm);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-01-28 05:10:55 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ctl_byname(const char *name, void *oldp, size_t *oldlenp, void *newp,
|
|
|
|
size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
size_t depth;
|
|
|
|
ctl_node_t const *nodes[CTL_MAX_DEPTH];
|
|
|
|
size_t mib[CTL_MAX_DEPTH];
|
2012-04-20 14:38:42 +08:00
|
|
|
const ctl_named_node_t *node;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
if (ctl_initialized == false && ctl_init()) {
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = EAGAIN;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
depth = CTL_MAX_DEPTH;
|
|
|
|
ret = ctl_lookup(name, nodes, mib, &depth);
|
|
|
|
if (ret != 0)
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-04-20 14:38:42 +08:00
|
|
|
node = ctl_named_node(nodes[depth-1]);
|
|
|
|
if (node != NULL && node->ctl)
|
|
|
|
ret = node->ctl(mib, depth, oldp, oldlenp, newp, newlen);
|
|
|
|
else {
|
2010-01-28 05:10:55 +08:00
|
|
|
/* The name refers to a partial path through the ctl tree. */
|
|
|
|
ret = ENOENT;
|
|
|
|
}
|
|
|
|
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-01-28 05:10:55 +08:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ctl_nametomib(const char *name, size_t *mibp, size_t *miblenp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
if (ctl_initialized == false && ctl_init()) {
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = EAGAIN;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ctl_lookup(name, NULL, mibp, miblenp);
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-01-28 05:10:55 +08:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ctl_bymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
2012-04-20 14:38:42 +08:00
|
|
|
const ctl_named_node_t *node;
|
2010-01-28 05:10:55 +08:00
|
|
|
size_t i;
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
if (ctl_initialized == false && ctl_init()) {
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = EAGAIN;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Iterate down the tree. */
|
|
|
|
node = super_root_node;
|
|
|
|
for (i = 0; i < miblen; i++) {
|
2012-04-20 14:38:42 +08:00
|
|
|
assert(node);
|
|
|
|
assert(node->nchildren > 0);
|
|
|
|
if (ctl_named_node(node->children) != NULL) {
|
2010-01-28 05:10:55 +08:00
|
|
|
/* Children are named. */
|
2012-04-20 14:38:42 +08:00
|
|
|
if (node->nchildren <= mib[i]) {
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
2012-04-20 14:38:42 +08:00
|
|
|
node = ctl_named_children(node, mib[i]);
|
2010-01-28 05:10:55 +08:00
|
|
|
} else {
|
2012-04-20 14:38:42 +08:00
|
|
|
const ctl_indexed_node_t *inode;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
/* Indexed element. */
|
2012-04-20 14:38:42 +08:00
|
|
|
inode = ctl_indexed_node(node->children);
|
|
|
|
node = inode->index(mib, miblen, mib[i]);
|
2010-01-28 05:10:55 +08:00
|
|
|
if (node == NULL) {
|
|
|
|
ret = ENOENT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the ctl function. */
|
2012-04-20 14:38:42 +08:00
|
|
|
if (node && node->ctl)
|
|
|
|
ret = node->ctl(mib, miblen, oldp, oldlenp, newp, newlen);
|
|
|
|
else {
|
2010-01-28 05:10:55 +08:00
|
|
|
/* Partial MIB. */
|
|
|
|
ret = ENOENT;
|
|
|
|
}
|
|
|
|
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-01-28 05:10:55 +08:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ctl_boot(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (malloc_mutex_init(&ctl_mtx))
|
|
|
|
return (true);
|
|
|
|
|
|
|
|
ctl_initialized = false;
|
|
|
|
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
2012-10-10 05:46:22 +08:00
|
|
|
void
|
|
|
|
ctl_prefork(void)
|
|
|
|
{
|
|
|
|
|
2013-10-22 05:59:10 +08:00
|
|
|
malloc_mutex_prefork(&ctl_mtx);
|
2012-10-10 05:46:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ctl_postfork_parent(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
malloc_mutex_postfork_parent(&ctl_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ctl_postfork_child(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
malloc_mutex_postfork_child(&ctl_mtx);
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
/* *_ctl() functions. */
|
|
|
|
|
|
|
|
#define READONLY() do { \
|
|
|
|
if (newp != NULL || newlen != 0) { \
|
|
|
|
ret = EPERM; \
|
2012-04-26 04:12:46 +08:00
|
|
|
goto label_return; \
|
2010-01-28 05:10:55 +08:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2010-03-03 03:57:30 +08:00
|
|
|
#define WRITEONLY() do { \
|
2010-01-28 05:10:55 +08:00
|
|
|
if (oldp != NULL || oldlenp != NULL) { \
|
|
|
|
ret = EPERM; \
|
2012-04-26 04:12:46 +08:00
|
|
|
goto label_return; \
|
2010-01-28 05:10:55 +08:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define READ(v, t) do { \
|
|
|
|
if (oldp != NULL && oldlenp != NULL) { \
|
|
|
|
if (*oldlenp != sizeof(t)) { \
|
|
|
|
size_t copylen = (sizeof(t) <= *oldlenp) \
|
|
|
|
? sizeof(t) : *oldlenp; \
|
2012-11-30 14:13:04 +08:00
|
|
|
memcpy(oldp, (void *)&(v), copylen); \
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = EINVAL; \
|
2012-04-26 04:12:46 +08:00
|
|
|
goto label_return; \
|
2010-01-28 05:10:55 +08:00
|
|
|
} else \
|
2012-11-30 14:13:04 +08:00
|
|
|
*(t *)oldp = (v); \
|
2010-01-28 05:10:55 +08:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define WRITE(v, t) do { \
|
|
|
|
if (newp != NULL) { \
|
|
|
|
if (newlen != sizeof(t)) { \
|
|
|
|
ret = EINVAL; \
|
2012-04-26 04:12:46 +08:00
|
|
|
goto label_return; \
|
2010-01-28 05:10:55 +08:00
|
|
|
} \
|
2012-11-30 14:13:04 +08:00
|
|
|
(v) = *(t *)newp; \
|
2010-01-28 05:10:55 +08:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
/*
|
|
|
|
* There's a lot of code duplication in the following macros due to limitations
|
|
|
|
* in how nested cpp macros are expanded.
|
|
|
|
*/
|
|
|
|
#define CTL_RO_CLGEN(c, l, n, v, t) \
|
|
|
|
static int \
|
|
|
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
|
|
|
void *newp, size_t newlen) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
|
|
|
t oldval; \
|
|
|
|
\
|
|
|
|
if ((c) == false) \
|
|
|
|
return (ENOENT); \
|
|
|
|
if (l) \
|
|
|
|
malloc_mutex_lock(&ctl_mtx); \
|
|
|
|
READONLY(); \
|
2012-11-30 14:13:04 +08:00
|
|
|
oldval = (v); \
|
2012-02-11 12:22:09 +08:00
|
|
|
READ(oldval, t); \
|
|
|
|
\
|
|
|
|
ret = 0; \
|
2012-04-26 04:12:46 +08:00
|
|
|
label_return: \
|
2012-02-11 12:22:09 +08:00
|
|
|
if (l) \
|
|
|
|
malloc_mutex_unlock(&ctl_mtx); \
|
|
|
|
return (ret); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CTL_RO_CGEN(c, n, v, t) \
|
|
|
|
static int \
|
|
|
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
|
|
|
void *newp, size_t newlen) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
|
|
|
t oldval; \
|
|
|
|
\
|
|
|
|
if ((c) == false) \
|
|
|
|
return (ENOENT); \
|
|
|
|
malloc_mutex_lock(&ctl_mtx); \
|
|
|
|
READONLY(); \
|
2012-11-30 14:13:04 +08:00
|
|
|
oldval = (v); \
|
2012-02-11 12:22:09 +08:00
|
|
|
READ(oldval, t); \
|
|
|
|
\
|
|
|
|
ret = 0; \
|
2012-04-26 04:12:46 +08:00
|
|
|
label_return: \
|
2012-02-11 12:22:09 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx); \
|
|
|
|
return (ret); \
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
#define CTL_RO_GEN(n, v, t) \
|
|
|
|
static int \
|
2010-11-25 07:44:21 +08:00
|
|
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
|
|
|
void *newp, size_t newlen) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
|
|
|
t oldval; \
|
|
|
|
\
|
|
|
|
malloc_mutex_lock(&ctl_mtx); \
|
|
|
|
READONLY(); \
|
2012-11-30 14:13:04 +08:00
|
|
|
oldval = (v); \
|
2010-11-25 07:44:21 +08:00
|
|
|
READ(oldval, t); \
|
|
|
|
\
|
|
|
|
ret = 0; \
|
2012-04-26 04:12:46 +08:00
|
|
|
label_return: \
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx); \
|
|
|
|
return (ret); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ctl_mtx is not acquired, under the assumption that no pertinent data will
|
|
|
|
* mutate during the call.
|
|
|
|
*/
|
2012-02-11 12:22:09 +08:00
|
|
|
#define CTL_RO_NL_CGEN(c, n, v, t) \
|
2010-11-25 07:44:21 +08:00
|
|
|
static int \
|
2010-01-28 05:10:55 +08:00
|
|
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
|
|
|
void *newp, size_t newlen) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
|
|
|
t oldval; \
|
|
|
|
\
|
2012-02-11 12:22:09 +08:00
|
|
|
if ((c) == false) \
|
|
|
|
return (ENOENT); \
|
2010-01-28 05:10:55 +08:00
|
|
|
READONLY(); \
|
2012-11-30 14:13:04 +08:00
|
|
|
oldval = (v); \
|
2010-01-28 05:10:55 +08:00
|
|
|
READ(oldval, t); \
|
|
|
|
\
|
|
|
|
ret = 0; \
|
2012-04-26 04:12:46 +08:00
|
|
|
label_return: \
|
2010-01-28 05:10:55 +08:00
|
|
|
return (ret); \
|
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
#define CTL_RO_NL_GEN(n, v, t) \
|
2010-01-28 05:10:55 +08:00
|
|
|
static int \
|
|
|
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
|
|
|
void *newp, size_t newlen) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
2012-02-11 12:22:09 +08:00
|
|
|
t oldval; \
|
2010-01-28 05:10:55 +08:00
|
|
|
\
|
|
|
|
READONLY(); \
|
2012-11-30 14:13:04 +08:00
|
|
|
oldval = (v); \
|
2012-02-11 12:22:09 +08:00
|
|
|
READ(oldval, t); \
|
2010-01-28 05:10:55 +08:00
|
|
|
\
|
|
|
|
ret = 0; \
|
2012-04-26 04:12:46 +08:00
|
|
|
label_return: \
|
2010-01-28 05:10:55 +08:00
|
|
|
return (ret); \
|
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
#define CTL_RO_BOOL_CONFIG_GEN(n) \
|
2010-01-28 05:10:55 +08:00
|
|
|
static int \
|
|
|
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
|
|
|
void *newp, size_t newlen) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
|
|
|
bool oldval; \
|
|
|
|
\
|
|
|
|
READONLY(); \
|
2012-02-11 12:22:09 +08:00
|
|
|
oldval = n; \
|
2010-01-28 05:10:55 +08:00
|
|
|
READ(oldval, bool); \
|
|
|
|
\
|
|
|
|
ret = 0; \
|
2012-04-26 04:12:46 +08:00
|
|
|
label_return: \
|
2010-01-28 05:10:55 +08:00
|
|
|
return (ret); \
|
|
|
|
}
|
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
CTL_RO_NL_GEN(version, JEMALLOC_VERSION, const char *)
|
2010-03-03 05:01:16 +08:00
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
static int
|
|
|
|
epoch_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
2013-10-20 08:19:49 +08:00
|
|
|
UNUSED uint64_t newval;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
2010-01-28 05:10:55 +08:00
|
|
|
WRITE(newval, uint64_t);
|
2012-04-26 04:12:46 +08:00
|
|
|
if (newp != NULL)
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_refresh();
|
|
|
|
READ(ctl_epoch, uint64_t);
|
|
|
|
|
|
|
|
ret = 0;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2010-01-28 05:10:55 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
/******************************************************************************/
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_debug)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_fill)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_lazy_lock)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_mremap)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_munmap)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_prof)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_prof_libgcc)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_prof_libunwind)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_stats)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_tcache)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_tls)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_utrace)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_valgrind)
|
|
|
|
CTL_RO_BOOL_CONFIG_GEN(config_xmalloc)
|
2012-02-11 12:22:09 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
/******************************************************************************/
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
CTL_RO_NL_GEN(opt_abort, opt_abort, bool)
|
|
|
|
CTL_RO_NL_GEN(opt_dss, opt_dss, const char *)
|
|
|
|
CTL_RO_NL_GEN(opt_lg_chunk, opt_lg_chunk, size_t)
|
|
|
|
CTL_RO_NL_GEN(opt_narenas, opt_narenas, size_t)
|
|
|
|
CTL_RO_NL_GEN(opt_lg_dirty_mult, opt_lg_dirty_mult, ssize_t)
|
|
|
|
CTL_RO_NL_GEN(opt_stats_print, opt_stats_print, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_fill, opt_junk, opt_junk, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_fill, opt_quarantine, opt_quarantine, size_t)
|
|
|
|
CTL_RO_NL_CGEN(config_fill, opt_redzone, opt_redzone, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_fill, opt_zero, opt_zero, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_utrace, opt_utrace, opt_utrace, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_xmalloc, opt_xmalloc, opt_xmalloc, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_tcache, opt_tcache, opt_tcache, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_tcache, opt_lg_tcache_max, opt_lg_tcache_max, ssize_t)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_prof, opt_prof, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_prof_prefix, opt_prof_prefix, const char *)
|
|
|
|
CTL_RO_CGEN(config_prof, opt_prof_active, opt_prof_active, bool) /* Mutable. */
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_lg_prof_sample, opt_lg_prof_sample, size_t)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_prof_accum, opt_prof_accum, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_lg_prof_interval, opt_lg_prof_interval, ssize_t)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_prof_gdump, opt_prof_gdump, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_prof_final, opt_prof_final, bool)
|
|
|
|
CTL_RO_NL_CGEN(config_prof, opt_prof_leak, opt_prof_leak, bool)
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
/******************************************************************************/
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-08-14 06:42:29 +08:00
|
|
|
static int
|
|
|
|
thread_arena_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned newind, oldind;
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
2012-04-04 00:28:00 +08:00
|
|
|
newind = oldind = choose_arena(NULL)->ind;
|
2011-03-15 02:39:49 +08:00
|
|
|
WRITE(newind, unsigned);
|
|
|
|
READ(oldind, unsigned);
|
2010-08-14 06:42:29 +08:00
|
|
|
if (newind != oldind) {
|
|
|
|
arena_t *arena;
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
if (newind >= ctl_stats.narenas) {
|
2010-08-14 06:42:29 +08:00
|
|
|
/* New arena index is out of range. */
|
|
|
|
ret = EFAULT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-08-14 06:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize arena if necessary. */
|
|
|
|
malloc_mutex_lock(&arenas_lock);
|
2012-03-22 09:33:03 +08:00
|
|
|
if ((arena = arenas[newind]) == NULL && (arena =
|
|
|
|
arenas_extend(newind)) == NULL) {
|
|
|
|
malloc_mutex_unlock(&arenas_lock);
|
2010-08-14 06:42:29 +08:00
|
|
|
ret = EAGAIN;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-08-14 06:42:29 +08:00
|
|
|
}
|
2012-03-22 09:33:03 +08:00
|
|
|
assert(arena == arenas[newind]);
|
|
|
|
arenas[oldind]->nthreads--;
|
|
|
|
arenas[newind]->nthreads++;
|
|
|
|
malloc_mutex_unlock(&arenas_lock);
|
2010-08-14 06:42:29 +08:00
|
|
|
|
|
|
|
/* Set new arena association. */
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_tcache) {
|
2012-03-22 09:33:03 +08:00
|
|
|
tcache_t *tcache;
|
2012-04-06 15:35:09 +08:00
|
|
|
if ((uintptr_t)(tcache = *tcache_tsd_get()) >
|
|
|
|
(uintptr_t)TCACHE_STATE_MAX) {
|
2012-03-22 09:33:03 +08:00
|
|
|
tcache_arena_dissociate(tcache);
|
|
|
|
tcache_arena_associate(tcache, arena);
|
|
|
|
}
|
2010-12-30 04:21:05 +08:00
|
|
|
}
|
2012-03-22 09:33:03 +08:00
|
|
|
arenas_tsd_set(&arena);
|
2010-08-14 06:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2012-10-12 04:53:15 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2010-08-14 06:42:29 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2012-03-22 09:33:03 +08:00
|
|
|
CTL_RO_NL_CGEN(config_stats, thread_allocated,
|
|
|
|
thread_allocated_tsd_get()->allocated, uint64_t)
|
|
|
|
CTL_RO_NL_CGEN(config_stats, thread_allocatedp,
|
|
|
|
&thread_allocated_tsd_get()->allocated, uint64_t *)
|
|
|
|
CTL_RO_NL_CGEN(config_stats, thread_deallocated,
|
|
|
|
thread_allocated_tsd_get()->deallocated, uint64_t)
|
|
|
|
CTL_RO_NL_CGEN(config_stats, thread_deallocatedp,
|
|
|
|
&thread_allocated_tsd_get()->deallocated, uint64_t *)
|
2010-10-21 08:39:18 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
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;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
if (config_tcache == false)
|
|
|
|
return (ENOENT);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
oldval = tcache_enabled_get();
|
|
|
|
if (newp != NULL) {
|
|
|
|
if (newlen != sizeof(bool)) {
|
|
|
|
ret = EINVAL;
|
|
|
|
goto label_return;
|
|
|
|
}
|
|
|
|
tcache_enabled_set(*(bool *)newp);
|
|
|
|
}
|
|
|
|
READ(oldval, bool);
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
ret = 0;
|
|
|
|
label_return:
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (config_tcache == false)
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
READONLY();
|
|
|
|
WRITEONLY();
|
|
|
|
|
|
|
|
tcache_flush();
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
label_return:
|
|
|
|
return (ret);
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2012-11-04 12:18:28 +08:00
|
|
|
/* ctl_mutex must be held during execution of this function. */
|
|
|
|
static void
|
2012-10-12 04:53:15 +08:00
|
|
|
arena_purge(unsigned arena_ind)
|
|
|
|
{
|
2012-11-04 12:18:28 +08:00
|
|
|
VARIABLE_ARRAY(arena_t *, tarenas, ctl_stats.narenas);
|
2012-10-12 04:53:15 +08:00
|
|
|
|
2012-11-04 12:18:28 +08:00
|
|
|
malloc_mutex_lock(&arenas_lock);
|
|
|
|
memcpy(tarenas, arenas, sizeof(arena_t *) * ctl_stats.narenas);
|
|
|
|
malloc_mutex_unlock(&arenas_lock);
|
2012-10-12 04:53:15 +08:00
|
|
|
|
2012-11-04 12:18:28 +08:00
|
|
|
if (arena_ind == ctl_stats.narenas) {
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < ctl_stats.narenas; i++) {
|
|
|
|
if (tarenas[i] != NULL)
|
|
|
|
arena_purge_all(tarenas[i]);
|
2012-10-12 04:53:15 +08:00
|
|
|
}
|
2012-11-04 12:18:28 +08:00
|
|
|
} else {
|
|
|
|
assert(arena_ind < ctl_stats.narenas);
|
|
|
|
if (tarenas[arena_ind] != NULL)
|
|
|
|
arena_purge_all(tarenas[arena_ind]);
|
2012-10-12 04:53:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
arena_i_purge_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
READONLY();
|
|
|
|
WRITEONLY();
|
2012-11-04 12:18:28 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
|
|
|
arena_purge(mib[1]);
|
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2012-10-12 04:53:15 +08:00
|
|
|
|
2012-11-04 12:18:28 +08:00
|
|
|
ret = 0;
|
2012-10-12 04:53:15 +08:00
|
|
|
label_return:
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
arena_i_dss_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
bool match, err;
|
|
|
|
const char *dss;
|
|
|
|
unsigned arena_ind = mib[1];
|
|
|
|
dss_prec_t dss_prec_old = dss_prec_limit;
|
|
|
|
dss_prec_t dss_prec = dss_prec_limit;
|
|
|
|
|
2012-10-16 03:48:59 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
2012-10-12 04:53:15 +08:00
|
|
|
WRITE(dss, const char *);
|
|
|
|
match = false;
|
|
|
|
for (i = 0; i < dss_prec_limit; i++) {
|
|
|
|
if (strcmp(dss_prec_names[i], dss) == 0) {
|
|
|
|
dss_prec = i;
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (match == false) {
|
|
|
|
ret = EINVAL;
|
|
|
|
goto label_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arena_ind < ctl_stats.narenas) {
|
|
|
|
arena_t *arena = arenas[arena_ind];
|
|
|
|
if (arena != NULL) {
|
|
|
|
dss_prec_old = arena_dss_prec_get(arena);
|
2014-04-16 03:09:48 +08:00
|
|
|
err = arena_dss_prec_set(arena, dss_prec);
|
2012-10-12 04:53:15 +08:00
|
|
|
} else
|
|
|
|
err = true;
|
|
|
|
} else {
|
|
|
|
dss_prec_old = chunk_dss_prec_get();
|
|
|
|
err = chunk_dss_prec_set(dss_prec);
|
|
|
|
}
|
|
|
|
dss = dss_prec_names[dss_prec_old];
|
|
|
|
READ(dss, const char *);
|
|
|
|
if (err) {
|
|
|
|
ret = EFAULT;
|
|
|
|
goto label_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
label_return:
|
2012-10-16 03:48:59 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2012-10-12 04:53:15 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const ctl_named_node_t *
|
|
|
|
arena_i_index(const size_t *mib, size_t miblen, size_t i)
|
|
|
|
{
|
|
|
|
const ctl_named_node_t * ret;
|
|
|
|
|
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
|
|
|
if (i > ctl_stats.narenas) {
|
|
|
|
ret = NULL;
|
|
|
|
goto label_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = super_arena_i_node;
|
|
|
|
label_return:
|
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static int
|
|
|
|
arenas_narenas_ctl(const size_t *mib, size_t miblen, void *oldp,
|
|
|
|
size_t *oldlenp, void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned narenas;
|
|
|
|
|
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
|
|
|
READONLY();
|
|
|
|
if (*oldlenp != sizeof(unsigned)) {
|
|
|
|
ret = EINVAL;
|
|
|
|
goto label_return;
|
|
|
|
}
|
|
|
|
narenas = ctl_stats.narenas;
|
|
|
|
READ(narenas, unsigned);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
label_return:
|
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
|
|
|
return (ret);
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
arenas_initialized_ctl(const size_t *mib, size_t miblen, void *oldp,
|
|
|
|
size_t *oldlenp, void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned nread, i;
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
2010-01-28 05:10:55 +08:00
|
|
|
READONLY();
|
2012-10-12 04:53:15 +08:00
|
|
|
if (*oldlenp != ctl_stats.narenas * sizeof(bool)) {
|
2010-01-28 05:10:55 +08:00
|
|
|
ret = EINVAL;
|
2012-10-12 04:53:15 +08:00
|
|
|
nread = (*oldlenp < ctl_stats.narenas * sizeof(bool))
|
|
|
|
? (*oldlenp / sizeof(bool)) : ctl_stats.narenas;
|
2010-01-28 05:10:55 +08:00
|
|
|
} else {
|
|
|
|
ret = 0;
|
2012-10-12 04:53:15 +08:00
|
|
|
nread = ctl_stats.narenas;
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nread; i++)
|
|
|
|
((bool *)oldp)[i] = ctl_stats.arenas[i].initialized;
|
|
|
|
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2010-01-28 05:10:55 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
CTL_RO_NL_GEN(arenas_quantum, QUANTUM, size_t)
|
2012-04-02 22:04:34 +08:00
|
|
|
CTL_RO_NL_GEN(arenas_page, PAGE, size_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_NL_CGEN(config_tcache, arenas_tcache_max, tcache_maxclass, size_t)
|
2012-02-29 08:50:47 +08:00
|
|
|
CTL_RO_NL_GEN(arenas_nbins, NBINS, unsigned)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_NL_CGEN(config_tcache, arenas_nhbins, nhbins, unsigned)
|
2013-12-20 13:40:41 +08:00
|
|
|
CTL_RO_NL_GEN(arenas_bin_i_size, arena_bin_info[mib[2]].reg_size, size_t)
|
|
|
|
CTL_RO_NL_GEN(arenas_bin_i_nregs, arena_bin_info[mib[2]].nregs, uint32_t)
|
|
|
|
CTL_RO_NL_GEN(arenas_bin_i_run_size, arena_bin_info[mib[2]].run_size, size_t)
|
|
|
|
static const ctl_named_node_t *
|
|
|
|
arenas_bin_i_index(const size_t *mib, size_t miblen, size_t i)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (i > NBINS)
|
|
|
|
return (NULL);
|
|
|
|
return (super_arenas_bin_i_node);
|
|
|
|
}
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
CTL_RO_NL_GEN(arenas_nlruns, nlclasses, size_t)
|
2013-12-20 13:40:41 +08:00
|
|
|
CTL_RO_NL_GEN(arenas_lrun_i_size, ((mib[2]+1) << LG_PAGE), size_t)
|
|
|
|
static const ctl_named_node_t *
|
|
|
|
arenas_lrun_i_index(const size_t *mib, size_t miblen, size_t i)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (i > nlclasses)
|
|
|
|
return (NULL);
|
|
|
|
return (super_arenas_lrun_i_node);
|
|
|
|
}
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static int
|
|
|
|
arenas_extend_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
2012-11-30 14:13:04 +08:00
|
|
|
unsigned narenas;
|
2012-10-12 04:53:15 +08:00
|
|
|
|
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
|
|
|
READONLY();
|
|
|
|
if (ctl_grow()) {
|
|
|
|
ret = EAGAIN;
|
|
|
|
goto label_return;
|
2010-10-01 07:55:08 +08:00
|
|
|
}
|
2012-11-30 14:13:04 +08:00
|
|
|
narenas = ctl_stats.narenas - 1;
|
|
|
|
READ(narenas, unsigned);
|
2010-10-01 07:55:08 +08:00
|
|
|
|
|
|
|
ret = 0;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2012-10-12 04:53:15 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2010-10-01 07:55:08 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-01-28 05:10:55 +08:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2010-04-01 09:43:24 +08:00
|
|
|
static int
|
|
|
|
prof_active_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
bool oldval;
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_prof == false)
|
|
|
|
return (ENOENT);
|
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx); /* Protect opt_prof_active. */
|
2010-04-01 09:43:24 +08:00
|
|
|
oldval = opt_prof_active;
|
|
|
|
if (newp != NULL) {
|
|
|
|
/*
|
|
|
|
* The memory barriers will tend to make opt_prof_active
|
|
|
|
* propagate faster on systems with weak memory ordering.
|
|
|
|
*/
|
|
|
|
mb_write();
|
|
|
|
WRITE(opt_prof_active, bool);
|
|
|
|
mb_write();
|
|
|
|
}
|
|
|
|
READ(oldval, bool);
|
|
|
|
|
|
|
|
ret = 0;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
2010-04-01 09:43:24 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2010-02-12 05:19:21 +08:00
|
|
|
static int
|
|
|
|
prof_dump_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
|
|
|
|
void *newp, size_t newlen)
|
|
|
|
{
|
|
|
|
int ret;
|
2010-03-03 03:57:30 +08:00
|
|
|
const char *filename = NULL;
|
2010-02-12 05:19:21 +08:00
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
if (config_prof == false)
|
|
|
|
return (ENOENT);
|
|
|
|
|
2010-03-03 03:57:30 +08:00
|
|
|
WRITEONLY();
|
|
|
|
WRITE(filename, const char *);
|
2010-02-12 05:19:21 +08:00
|
|
|
|
2010-03-03 03:57:30 +08:00
|
|
|
if (prof_mdump(filename)) {
|
|
|
|
ret = EFAULT;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-03-03 03:57:30 +08:00
|
|
|
}
|
2010-02-12 05:19:21 +08:00
|
|
|
|
|
|
|
ret = 0;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-02-12 05:19:21 +08:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_NL_CGEN(config_prof, prof_interval, prof_interval, uint64_t)
|
2010-02-12 05:19:21 +08:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2013-12-20 13:40:41 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_cactive, &stats_cactive, size_t *)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_allocated, ctl_stats.allocated, size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_active, ctl_stats.active, size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_mapped, ctl_stats.mapped, size_t)
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_chunks_current, ctl_stats.chunks.current,
|
|
|
|
size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_chunks_total, ctl_stats.chunks.total, uint64_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_chunks_high, ctl_stats.chunks.high, size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_huge_allocated, huge_allocated, size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_huge_nmalloc, huge_nmalloc, uint64_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_huge_ndalloc, huge_ndalloc, uint64_t)
|
2013-12-20 13:40:41 +08:00
|
|
|
|
|
|
|
CTL_RO_GEN(stats_arenas_i_dss, ctl_stats.arenas[mib[2]].dss, const char *)
|
|
|
|
CTL_RO_GEN(stats_arenas_i_nthreads, ctl_stats.arenas[mib[2]].nthreads, unsigned)
|
|
|
|
CTL_RO_GEN(stats_arenas_i_pactive, ctl_stats.arenas[mib[2]].pactive, size_t)
|
|
|
|
CTL_RO_GEN(stats_arenas_i_pdirty, ctl_stats.arenas[mib[2]].pdirty, size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_mapped,
|
|
|
|
ctl_stats.arenas[mib[2]].astats.mapped, size_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_npurge,
|
|
|
|
ctl_stats.arenas[mib[2]].astats.npurge, uint64_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_nmadvise,
|
|
|
|
ctl_stats.arenas[mib[2]].astats.nmadvise, uint64_t)
|
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_purged,
|
|
|
|
ctl_stats.arenas[mib[2]].astats.purged, uint64_t)
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_small_allocated,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].allocated_small, size_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_small_nmalloc,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].nmalloc_small, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_small_ndalloc,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].ndalloc_small, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_small_nrequests,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].nrequests_small, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_large_allocated,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].astats.allocated_large, size_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_large_nmalloc,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].astats.nmalloc_large, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_large_ndalloc,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].astats.ndalloc_large, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_large_nrequests,
|
2010-03-18 07:27:39 +08:00
|
|
|
ctl_stats.arenas[mib[2]].astats.nrequests_large, uint64_t)
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_allocated,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].allocated, size_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nmalloc,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].nmalloc, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_ndalloc,
|
2010-03-14 12:32:56 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].ndalloc, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nrequests,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].nrequests, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_bins_j_nfills,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].nfills, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_bins_j_nflushes,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].nflushes, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nruns,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].nruns, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nreruns,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].reruns, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_curruns,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].bstats[mib[4]].curruns, size_t)
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static const ctl_named_node_t *
|
2010-01-28 05:10:55 +08:00
|
|
|
stats_arenas_i_bins_j_index(const size_t *mib, size_t miblen, size_t j)
|
|
|
|
{
|
|
|
|
|
2012-02-29 08:50:47 +08:00
|
|
|
if (j > NBINS)
|
2010-01-28 05:10:55 +08:00
|
|
|
return (NULL);
|
|
|
|
return (super_stats_arenas_i_bins_j_node);
|
|
|
|
}
|
|
|
|
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_nmalloc,
|
2010-03-18 07:27:39 +08:00
|
|
|
ctl_stats.arenas[mib[2]].lstats[mib[4]].nmalloc, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_ndalloc,
|
2010-03-18 07:27:39 +08:00
|
|
|
ctl_stats.arenas[mib[2]].lstats[mib[4]].ndalloc, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_nrequests,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].lstats[mib[4]].nrequests, uint64_t)
|
2012-02-11 12:22:09 +08:00
|
|
|
CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_curruns,
|
2010-01-28 05:10:55 +08:00
|
|
|
ctl_stats.arenas[mib[2]].lstats[mib[4]].curruns, size_t)
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static const ctl_named_node_t *
|
2010-01-28 05:10:55 +08:00
|
|
|
stats_arenas_i_lruns_j_index(const size_t *mib, size_t miblen, size_t j)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (j > nlclasses)
|
|
|
|
return (NULL);
|
|
|
|
return (super_stats_arenas_i_lruns_j_node);
|
|
|
|
}
|
|
|
|
|
2012-10-12 04:53:15 +08:00
|
|
|
static const ctl_named_node_t *
|
2010-01-28 05:10:55 +08:00
|
|
|
stats_arenas_i_index(const size_t *mib, size_t miblen, size_t i)
|
|
|
|
{
|
2012-04-20 14:38:42 +08:00
|
|
|
const ctl_named_node_t * ret;
|
2010-01-28 05:10:55 +08:00
|
|
|
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_lock(&ctl_mtx);
|
2012-10-12 04:53:15 +08:00
|
|
|
if (i > ctl_stats.narenas || ctl_stats.arenas[i].initialized == false) {
|
2010-11-25 07:44:21 +08:00
|
|
|
ret = NULL;
|
2012-04-11 06:07:44 +08:00
|
|
|
goto label_return;
|
2010-11-25 07:44:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = super_stats_arenas_i_node;
|
2012-04-11 06:07:44 +08:00
|
|
|
label_return:
|
2010-11-25 07:44:21 +08:00
|
|
|
malloc_mutex_unlock(&ctl_mtx);
|
|
|
|
return (ret);
|
2010-01-28 05:10:55 +08:00
|
|
|
}
|