Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1 | #define JEMALLOC_CTL_C_ |
Jason Evans | 376b152 | 2010-02-11 14:45:59 -0800 | [diff] [blame] | 2 | #include "jemalloc/internal/jemalloc_internal.h" |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 3 | |
| 4 | /******************************************************************************/ |
| 5 | /* Data. */ |
| 6 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 7 | /* |
| 8 | * ctl_mtx protects the following: |
| 9 | * - ctl_stats.* |
| 10 | * - opt_prof_active |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 11 | */ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 12 | static malloc_mutex_t ctl_mtx; |
| 13 | static bool ctl_initialized; |
| 14 | static uint64_t ctl_epoch; |
| 15 | static ctl_stats_t ctl_stats; |
| 16 | |
| 17 | /******************************************************************************/ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 18 | /* Helpers for named and indexed nodes. */ |
| 19 | |
| 20 | static inline const ctl_named_node_t * |
| 21 | ctl_named_node(const ctl_node_t *node) |
| 22 | { |
| 23 | |
| 24 | return ((node->named) ? (const ctl_named_node_t *)node : NULL); |
| 25 | } |
| 26 | |
| 27 | static inline const ctl_named_node_t * |
| 28 | ctl_named_children(const ctl_named_node_t *node, int index) |
| 29 | { |
| 30 | const ctl_named_node_t *children = ctl_named_node(node->children); |
| 31 | |
| 32 | return (children ? &children[index] : NULL); |
| 33 | } |
| 34 | |
| 35 | static inline const ctl_indexed_node_t * |
| 36 | ctl_indexed_node(const ctl_node_t *node) |
| 37 | { |
| 38 | |
| 39 | return ((node->named == false) ? (const ctl_indexed_node_t *)node : |
| 40 | NULL); |
| 41 | } |
| 42 | |
| 43 | /******************************************************************************/ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 44 | /* Function prototypes for non-inline static functions. */ |
| 45 | |
| 46 | #define CTL_PROTO(n) \ |
| 47 | static int n##_ctl(const size_t *mib, size_t miblen, void *oldp, \ |
| 48 | size_t *oldlenp, void *newp, size_t newlen); |
| 49 | |
| 50 | #define INDEX_PROTO(n) \ |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 51 | static const ctl_named_node_t *n##_index(const size_t *mib, \ |
| 52 | size_t miblen, size_t i); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 53 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 54 | static bool ctl_arena_init(ctl_arena_stats_t *astats); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 55 | static void ctl_arena_clear(ctl_arena_stats_t *astats); |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 56 | static void ctl_arena_stats_amerge(ctl_arena_stats_t *cstats, |
| 57 | arena_t *arena); |
| 58 | static void ctl_arena_stats_smerge(ctl_arena_stats_t *sstats, |
| 59 | ctl_arena_stats_t *astats); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 60 | static void ctl_arena_refresh(arena_t *arena, unsigned i); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 61 | static bool ctl_grow(void); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 62 | static void ctl_refresh(void); |
| 63 | static bool ctl_init(void); |
| 64 | static int ctl_lookup(const char *name, ctl_node_t const **nodesp, |
| 65 | size_t *mibp, size_t *depthp); |
| 66 | |
Jason Evans | a40bc7a | 2010-03-02 13:01:16 -0800 | [diff] [blame] | 67 | CTL_PROTO(version) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 68 | CTL_PROTO(epoch) |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 69 | CTL_PROTO(thread_tcache_enabled) |
Jason Evans | e7b8fa1 | 2012-03-16 17:09:32 -0700 | [diff] [blame] | 70 | CTL_PROTO(thread_tcache_flush) |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 71 | CTL_PROTO(thread_arena) |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 72 | CTL_PROTO(thread_allocated) |
Jason Evans | ecf229a | 2010-12-03 15:55:47 -0800 | [diff] [blame] | 73 | CTL_PROTO(thread_allocatedp) |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 74 | CTL_PROTO(thread_deallocated) |
Jason Evans | ecf229a | 2010-12-03 15:55:47 -0800 | [diff] [blame] | 75 | CTL_PROTO(thread_deallocatedp) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 76 | CTL_PROTO(config_debug) |
| 77 | CTL_PROTO(config_dss) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 78 | CTL_PROTO(config_fill) |
| 79 | CTL_PROTO(config_lazy_lock) |
Jason Evans | 2e671ff | 2012-05-09 16:12:00 -0700 | [diff] [blame] | 80 | CTL_PROTO(config_mremap) |
Jason Evans | 59ae276 | 2012-04-16 17:52:27 -0700 | [diff] [blame] | 81 | CTL_PROTO(config_munmap) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 82 | CTL_PROTO(config_prof) |
| 83 | CTL_PROTO(config_prof_libgcc) |
| 84 | CTL_PROTO(config_prof_libunwind) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 85 | CTL_PROTO(config_stats) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 86 | CTL_PROTO(config_tcache) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 87 | CTL_PROTO(config_tls) |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 88 | CTL_PROTO(config_utrace) |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 89 | CTL_PROTO(config_valgrind) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 90 | CTL_PROTO(config_xmalloc) |
| 91 | CTL_PROTO(opt_abort) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 92 | CTL_PROTO(opt_dss) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 93 | CTL_PROTO(opt_lg_chunk) |
| 94 | CTL_PROTO(opt_narenas) |
| 95 | CTL_PROTO(opt_lg_dirty_mult) |
| 96 | CTL_PROTO(opt_stats_print) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 97 | CTL_PROTO(opt_junk) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 98 | CTL_PROTO(opt_zero) |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 99 | CTL_PROTO(opt_quarantine) |
| 100 | CTL_PROTO(opt_redzone) |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 101 | CTL_PROTO(opt_utrace) |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 102 | CTL_PROTO(opt_valgrind) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 103 | CTL_PROTO(opt_xmalloc) |
Jason Evans | 3fa9a2f | 2010-03-07 15:34:14 -0800 | [diff] [blame] | 104 | CTL_PROTO(opt_tcache) |
Jason Evans | f3ca7c8 | 2012-04-04 16:16:09 -0700 | [diff] [blame] | 105 | CTL_PROTO(opt_lg_tcache_max) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 106 | CTL_PROTO(opt_prof) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 107 | CTL_PROTO(opt_prof_prefix) |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 108 | CTL_PROTO(opt_prof_active) |
Jason Evans | b9477e7 | 2010-03-01 20:15:26 -0800 | [diff] [blame] | 109 | CTL_PROTO(opt_lg_prof_sample) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 110 | CTL_PROTO(opt_lg_prof_interval) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 111 | CTL_PROTO(opt_prof_gdump) |
Jason Evans | 0b25fe7 | 2012-04-17 16:39:33 -0700 | [diff] [blame] | 112 | CTL_PROTO(opt_prof_final) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 113 | CTL_PROTO(opt_prof_leak) |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 114 | CTL_PROTO(opt_prof_accum) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 115 | CTL_PROTO(arena_i_purge) |
| 116 | static int arena_purge(unsigned arena_ind); |
| 117 | CTL_PROTO(arena_i_dss) |
| 118 | INDEX_PROTO(arena_i) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 119 | CTL_PROTO(arenas_bin_i_size) |
| 120 | CTL_PROTO(arenas_bin_i_nregs) |
| 121 | CTL_PROTO(arenas_bin_i_run_size) |
| 122 | INDEX_PROTO(arenas_bin_i) |
| 123 | CTL_PROTO(arenas_lrun_i_size) |
| 124 | INDEX_PROTO(arenas_lrun_i) |
| 125 | CTL_PROTO(arenas_narenas) |
| 126 | CTL_PROTO(arenas_initialized) |
| 127 | CTL_PROTO(arenas_quantum) |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame] | 128 | CTL_PROTO(arenas_page) |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 129 | CTL_PROTO(arenas_tcache_max) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 130 | CTL_PROTO(arenas_nbins) |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 131 | CTL_PROTO(arenas_nhbins) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 132 | CTL_PROTO(arenas_nlruns) |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 133 | CTL_PROTO(arenas_purge) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 134 | CTL_PROTO(arenas_extend) |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 135 | CTL_PROTO(prof_active) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 136 | CTL_PROTO(prof_dump) |
| 137 | CTL_PROTO(prof_interval) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 138 | CTL_PROTO(stats_chunks_current) |
| 139 | CTL_PROTO(stats_chunks_total) |
| 140 | CTL_PROTO(stats_chunks_high) |
| 141 | CTL_PROTO(stats_huge_allocated) |
| 142 | CTL_PROTO(stats_huge_nmalloc) |
| 143 | CTL_PROTO(stats_huge_ndalloc) |
| 144 | CTL_PROTO(stats_arenas_i_small_allocated) |
| 145 | CTL_PROTO(stats_arenas_i_small_nmalloc) |
| 146 | CTL_PROTO(stats_arenas_i_small_ndalloc) |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 147 | CTL_PROTO(stats_arenas_i_small_nrequests) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 148 | CTL_PROTO(stats_arenas_i_large_allocated) |
| 149 | CTL_PROTO(stats_arenas_i_large_nmalloc) |
| 150 | CTL_PROTO(stats_arenas_i_large_ndalloc) |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 151 | CTL_PROTO(stats_arenas_i_large_nrequests) |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 152 | CTL_PROTO(stats_arenas_i_bins_j_allocated) |
| 153 | CTL_PROTO(stats_arenas_i_bins_j_nmalloc) |
| 154 | CTL_PROTO(stats_arenas_i_bins_j_ndalloc) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 155 | CTL_PROTO(stats_arenas_i_bins_j_nrequests) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 156 | CTL_PROTO(stats_arenas_i_bins_j_nfills) |
| 157 | CTL_PROTO(stats_arenas_i_bins_j_nflushes) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 158 | CTL_PROTO(stats_arenas_i_bins_j_nruns) |
| 159 | CTL_PROTO(stats_arenas_i_bins_j_nreruns) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 160 | CTL_PROTO(stats_arenas_i_bins_j_curruns) |
| 161 | INDEX_PROTO(stats_arenas_i_bins_j) |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 162 | CTL_PROTO(stats_arenas_i_lruns_j_nmalloc) |
| 163 | CTL_PROTO(stats_arenas_i_lruns_j_ndalloc) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 164 | CTL_PROTO(stats_arenas_i_lruns_j_nrequests) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 165 | CTL_PROTO(stats_arenas_i_lruns_j_curruns) |
| 166 | INDEX_PROTO(stats_arenas_i_lruns_j) |
Jason Evans | 597632b | 2011-03-18 13:41:33 -0700 | [diff] [blame] | 167 | CTL_PROTO(stats_arenas_i_nthreads) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 168 | CTL_PROTO(stats_arenas_i_dss) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 169 | CTL_PROTO(stats_arenas_i_pactive) |
| 170 | CTL_PROTO(stats_arenas_i_pdirty) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 171 | CTL_PROTO(stats_arenas_i_mapped) |
| 172 | CTL_PROTO(stats_arenas_i_npurge) |
| 173 | CTL_PROTO(stats_arenas_i_nmadvise) |
| 174 | CTL_PROTO(stats_arenas_i_purged) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 175 | INDEX_PROTO(stats_arenas_i) |
Jason Evans | 0657f12 | 2011-03-18 17:56:14 -0700 | [diff] [blame] | 176 | CTL_PROTO(stats_cactive) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 177 | CTL_PROTO(stats_allocated) |
| 178 | CTL_PROTO(stats_active) |
| 179 | CTL_PROTO(stats_mapped) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 180 | |
| 181 | /******************************************************************************/ |
| 182 | /* mallctl tree. */ |
| 183 | |
| 184 | /* Maximum tree depth. */ |
| 185 | #define CTL_MAX_DEPTH 6 |
| 186 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 187 | #define NAME(n) {true}, n |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 188 | #define CHILD(t, c) \ |
| 189 | sizeof(c##_node) / sizeof(ctl_##t##_node_t), \ |
| 190 | (ctl_node_t *)c##_node, \ |
| 191 | NULL |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 192 | #define CTL(c) 0, NULL, c##_ctl |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 193 | |
| 194 | /* |
| 195 | * Only handles internal indexed nodes, since there are currently no external |
| 196 | * ones. |
| 197 | */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 198 | #define INDEX(i) {false}, i##_index |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 199 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 200 | static const ctl_named_node_t tcache_node[] = { |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 201 | {NAME("enabled"), CTL(thread_tcache_enabled)}, |
Jason Evans | e7b8fa1 | 2012-03-16 17:09:32 -0700 | [diff] [blame] | 202 | {NAME("flush"), CTL(thread_tcache_flush)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 203 | }; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 204 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 205 | static const ctl_named_node_t thread_node[] = { |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 206 | {NAME("arena"), CTL(thread_arena)}, |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 207 | {NAME("allocated"), CTL(thread_allocated)}, |
Jason Evans | ecf229a | 2010-12-03 15:55:47 -0800 | [diff] [blame] | 208 | {NAME("allocatedp"), CTL(thread_allocatedp)}, |
| 209 | {NAME("deallocated"), CTL(thread_deallocated)}, |
Jason Evans | e7b8fa1 | 2012-03-16 17:09:32 -0700 | [diff] [blame] | 210 | {NAME("deallocatedp"), CTL(thread_deallocatedp)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 211 | {NAME("tcache"), CHILD(named, tcache)} |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 212 | }; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 213 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 214 | static const ctl_named_node_t config_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 215 | {NAME("debug"), CTL(config_debug)}, |
| 216 | {NAME("dss"), CTL(config_dss)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 217 | {NAME("fill"), CTL(config_fill)}, |
| 218 | {NAME("lazy_lock"), CTL(config_lazy_lock)}, |
Jason Evans | 2e671ff | 2012-05-09 16:12:00 -0700 | [diff] [blame] | 219 | {NAME("mremap"), CTL(config_mremap)}, |
Jason Evans | 59ae276 | 2012-04-16 17:52:27 -0700 | [diff] [blame] | 220 | {NAME("munmap"), CTL(config_munmap)}, |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 221 | {NAME("prof"), CTL(config_prof)}, |
| 222 | {NAME("prof_libgcc"), CTL(config_prof_libgcc)}, |
| 223 | {NAME("prof_libunwind"), CTL(config_prof_libunwind)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 224 | {NAME("stats"), CTL(config_stats)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 225 | {NAME("tcache"), CTL(config_tcache)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 226 | {NAME("tls"), CTL(config_tls)}, |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 227 | {NAME("utrace"), CTL(config_utrace)}, |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 228 | {NAME("valgrind"), CTL(config_valgrind)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 229 | {NAME("xmalloc"), CTL(config_xmalloc)} |
| 230 | }; |
| 231 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 232 | static const ctl_named_node_t opt_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 233 | {NAME("abort"), CTL(opt_abort)}, |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 234 | {NAME("dss"), CTL(opt_dss)}, |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 235 | {NAME("lg_chunk"), CTL(opt_lg_chunk)}, |
| 236 | {NAME("narenas"), CTL(opt_narenas)}, |
| 237 | {NAME("lg_dirty_mult"), CTL(opt_lg_dirty_mult)}, |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 238 | {NAME("stats_print"), CTL(opt_stats_print)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 239 | {NAME("junk"), CTL(opt_junk)}, |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 240 | {NAME("zero"), CTL(opt_zero)}, |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 241 | {NAME("quarantine"), CTL(opt_quarantine)}, |
| 242 | {NAME("redzone"), CTL(opt_redzone)}, |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 243 | {NAME("utrace"), CTL(opt_utrace)}, |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 244 | {NAME("valgrind"), CTL(opt_valgrind)}, |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 245 | {NAME("xmalloc"), CTL(opt_xmalloc)}, |
Jason Evans | 3fa9a2f | 2010-03-07 15:34:14 -0800 | [diff] [blame] | 246 | {NAME("tcache"), CTL(opt_tcache)}, |
Jason Evans | f3ca7c8 | 2012-04-04 16:16:09 -0700 | [diff] [blame] | 247 | {NAME("lg_tcache_max"), CTL(opt_lg_tcache_max)}, |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 248 | {NAME("prof"), CTL(opt_prof)}, |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 249 | {NAME("prof_prefix"), CTL(opt_prof_prefix)}, |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 250 | {NAME("prof_active"), CTL(opt_prof_active)}, |
Jason Evans | b9477e7 | 2010-03-01 20:15:26 -0800 | [diff] [blame] | 251 | {NAME("lg_prof_sample"), CTL(opt_lg_prof_sample)}, |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 252 | {NAME("lg_prof_interval"), CTL(opt_lg_prof_interval)}, |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 253 | {NAME("prof_gdump"), CTL(opt_prof_gdump)}, |
Jason Evans | 0b25fe7 | 2012-04-17 16:39:33 -0700 | [diff] [blame] | 254 | {NAME("prof_final"), CTL(opt_prof_final)}, |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 255 | {NAME("prof_leak"), CTL(opt_prof_leak)}, |
Jason Evans | 0b526ff | 2012-02-13 18:04:26 -0800 | [diff] [blame] | 256 | {NAME("prof_accum"), CTL(opt_prof_accum)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 257 | }; |
| 258 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 259 | static const ctl_named_node_t arena_i_node[] = { |
| 260 | {NAME("purge"), CTL(arena_i_purge)}, |
| 261 | {NAME("dss"), CTL(arena_i_dss)} |
| 262 | }; |
| 263 | static const ctl_named_node_t super_arena_i_node[] = { |
| 264 | {NAME(""), CHILD(named, arena_i)} |
| 265 | }; |
| 266 | |
| 267 | static const ctl_indexed_node_t arena_node[] = { |
| 268 | {INDEX(arena_i)} |
| 269 | }; |
| 270 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 271 | static const ctl_named_node_t arenas_bin_i_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 272 | {NAME("size"), CTL(arenas_bin_i_size)}, |
| 273 | {NAME("nregs"), CTL(arenas_bin_i_nregs)}, |
| 274 | {NAME("run_size"), CTL(arenas_bin_i_run_size)} |
| 275 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 276 | static const ctl_named_node_t super_arenas_bin_i_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 277 | {NAME(""), CHILD(named, arenas_bin_i)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 278 | }; |
| 279 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 280 | static const ctl_indexed_node_t arenas_bin_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 281 | {INDEX(arenas_bin_i)} |
| 282 | }; |
| 283 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 284 | static const ctl_named_node_t arenas_lrun_i_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 285 | {NAME("size"), CTL(arenas_lrun_i_size)} |
| 286 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 287 | static const ctl_named_node_t super_arenas_lrun_i_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 288 | {NAME(""), CHILD(named, arenas_lrun_i)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 289 | }; |
| 290 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 291 | static const ctl_indexed_node_t arenas_lrun_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 292 | {INDEX(arenas_lrun_i)} |
| 293 | }; |
| 294 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 295 | static const ctl_named_node_t arenas_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 296 | {NAME("narenas"), CTL(arenas_narenas)}, |
| 297 | {NAME("initialized"), CTL(arenas_initialized)}, |
| 298 | {NAME("quantum"), CTL(arenas_quantum)}, |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame] | 299 | {NAME("page"), CTL(arenas_page)}, |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 300 | {NAME("tcache_max"), CTL(arenas_tcache_max)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 301 | {NAME("nbins"), CTL(arenas_nbins)}, |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 302 | {NAME("nhbins"), CTL(arenas_nhbins)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 303 | {NAME("bin"), CHILD(indexed, arenas_bin)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 304 | {NAME("nlruns"), CTL(arenas_nlruns)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 305 | {NAME("lrun"), CHILD(indexed, arenas_lrun)}, |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 306 | {NAME("purge"), CTL(arenas_purge)}, |
| 307 | {NAME("extend"), CTL(arenas_extend)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 308 | }; |
| 309 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 310 | static const ctl_named_node_t prof_node[] = { |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 311 | {NAME("active"), CTL(prof_active)}, |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 312 | {NAME("dump"), CTL(prof_dump)}, |
| 313 | {NAME("interval"), CTL(prof_interval)} |
| 314 | }; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 315 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 316 | static const ctl_named_node_t stats_chunks_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 317 | {NAME("current"), CTL(stats_chunks_current)}, |
| 318 | {NAME("total"), CTL(stats_chunks_total)}, |
| 319 | {NAME("high"), CTL(stats_chunks_high)} |
| 320 | }; |
| 321 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 322 | static const ctl_named_node_t stats_huge_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 323 | {NAME("allocated"), CTL(stats_huge_allocated)}, |
| 324 | {NAME("nmalloc"), CTL(stats_huge_nmalloc)}, |
| 325 | {NAME("ndalloc"), CTL(stats_huge_ndalloc)} |
| 326 | }; |
| 327 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 328 | static const ctl_named_node_t stats_arenas_i_small_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 329 | {NAME("allocated"), CTL(stats_arenas_i_small_allocated)}, |
| 330 | {NAME("nmalloc"), CTL(stats_arenas_i_small_nmalloc)}, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 331 | {NAME("ndalloc"), CTL(stats_arenas_i_small_ndalloc)}, |
| 332 | {NAME("nrequests"), CTL(stats_arenas_i_small_nrequests)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 333 | }; |
| 334 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 335 | static const ctl_named_node_t stats_arenas_i_large_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 336 | {NAME("allocated"), CTL(stats_arenas_i_large_allocated)}, |
| 337 | {NAME("nmalloc"), CTL(stats_arenas_i_large_nmalloc)}, |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 338 | {NAME("ndalloc"), CTL(stats_arenas_i_large_ndalloc)}, |
| 339 | {NAME("nrequests"), CTL(stats_arenas_i_large_nrequests)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 340 | }; |
| 341 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 342 | static const ctl_named_node_t stats_arenas_i_bins_j_node[] = { |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 343 | {NAME("allocated"), CTL(stats_arenas_i_bins_j_allocated)}, |
| 344 | {NAME("nmalloc"), CTL(stats_arenas_i_bins_j_nmalloc)}, |
| 345 | {NAME("ndalloc"), CTL(stats_arenas_i_bins_j_ndalloc)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 346 | {NAME("nrequests"), CTL(stats_arenas_i_bins_j_nrequests)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 347 | {NAME("nfills"), CTL(stats_arenas_i_bins_j_nfills)}, |
| 348 | {NAME("nflushes"), CTL(stats_arenas_i_bins_j_nflushes)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 349 | {NAME("nruns"), CTL(stats_arenas_i_bins_j_nruns)}, |
| 350 | {NAME("nreruns"), CTL(stats_arenas_i_bins_j_nreruns)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 351 | {NAME("curruns"), CTL(stats_arenas_i_bins_j_curruns)} |
| 352 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 353 | static const ctl_named_node_t super_stats_arenas_i_bins_j_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 354 | {NAME(""), CHILD(named, stats_arenas_i_bins_j)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 355 | }; |
| 356 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 357 | static const ctl_indexed_node_t stats_arenas_i_bins_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 358 | {INDEX(stats_arenas_i_bins_j)} |
| 359 | }; |
| 360 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 361 | static const ctl_named_node_t stats_arenas_i_lruns_j_node[] = { |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 362 | {NAME("nmalloc"), CTL(stats_arenas_i_lruns_j_nmalloc)}, |
| 363 | {NAME("ndalloc"), CTL(stats_arenas_i_lruns_j_ndalloc)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 364 | {NAME("nrequests"), CTL(stats_arenas_i_lruns_j_nrequests)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 365 | {NAME("curruns"), CTL(stats_arenas_i_lruns_j_curruns)} |
| 366 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 367 | static const ctl_named_node_t super_stats_arenas_i_lruns_j_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 368 | {NAME(""), CHILD(named, stats_arenas_i_lruns_j)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 369 | }; |
| 370 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 371 | static const ctl_indexed_node_t stats_arenas_i_lruns_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 372 | {INDEX(stats_arenas_i_lruns_j)} |
| 373 | }; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 374 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 375 | static const ctl_named_node_t stats_arenas_i_node[] = { |
Jason Evans | 597632b | 2011-03-18 13:41:33 -0700 | [diff] [blame] | 376 | {NAME("nthreads"), CTL(stats_arenas_i_nthreads)}, |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 377 | {NAME("dss"), CTL(stats_arenas_i_dss)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 378 | {NAME("pactive"), CTL(stats_arenas_i_pactive)}, |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 379 | {NAME("pdirty"), CTL(stats_arenas_i_pdirty)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 380 | {NAME("mapped"), CTL(stats_arenas_i_mapped)}, |
| 381 | {NAME("npurge"), CTL(stats_arenas_i_npurge)}, |
| 382 | {NAME("nmadvise"), CTL(stats_arenas_i_nmadvise)}, |
| 383 | {NAME("purged"), CTL(stats_arenas_i_purged)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 384 | {NAME("small"), CHILD(named, stats_arenas_i_small)}, |
| 385 | {NAME("large"), CHILD(named, stats_arenas_i_large)}, |
Jason Evans | 87667a8 | 2012-04-23 19:54:15 -0700 | [diff] [blame] | 386 | {NAME("bins"), CHILD(indexed, stats_arenas_i_bins)}, |
| 387 | {NAME("lruns"), CHILD(indexed, stats_arenas_i_lruns)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 388 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 389 | static const ctl_named_node_t super_stats_arenas_i_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 390 | {NAME(""), CHILD(named, stats_arenas_i)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 391 | }; |
| 392 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 393 | static const ctl_indexed_node_t stats_arenas_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 394 | {INDEX(stats_arenas_i)} |
| 395 | }; |
| 396 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 397 | static const ctl_named_node_t stats_node[] = { |
Jason Evans | 0657f12 | 2011-03-18 17:56:14 -0700 | [diff] [blame] | 398 | {NAME("cactive"), CTL(stats_cactive)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 399 | {NAME("allocated"), CTL(stats_allocated)}, |
| 400 | {NAME("active"), CTL(stats_active)}, |
| 401 | {NAME("mapped"), CTL(stats_mapped)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 402 | {NAME("chunks"), CHILD(named, stats_chunks)}, |
| 403 | {NAME("huge"), CHILD(named, stats_huge)}, |
| 404 | {NAME("arenas"), CHILD(indexed, stats_arenas)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 405 | }; |
| 406 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 407 | static const ctl_named_node_t root_node[] = { |
Jason Evans | a40bc7a | 2010-03-02 13:01:16 -0800 | [diff] [blame] | 408 | {NAME("version"), CTL(version)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 409 | {NAME("epoch"), CTL(epoch)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 410 | {NAME("thread"), CHILD(named, thread)}, |
| 411 | {NAME("config"), CHILD(named, config)}, |
| 412 | {NAME("opt"), CHILD(named, opt)}, |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 413 | {NAME("arena"), CHILD(indexed, arena)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 414 | {NAME("arenas"), CHILD(named, arenas)}, |
| 415 | {NAME("prof"), CHILD(named, prof)}, |
| 416 | {NAME("stats"), CHILD(named, stats)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 417 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 418 | static const ctl_named_node_t super_root_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 419 | {NAME(""), CHILD(named, root)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | #undef NAME |
| 423 | #undef CHILD |
| 424 | #undef CTL |
| 425 | #undef INDEX |
| 426 | |
| 427 | /******************************************************************************/ |
| 428 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 429 | static bool |
| 430 | ctl_arena_init(ctl_arena_stats_t *astats) |
| 431 | { |
| 432 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 433 | if (astats->lstats == NULL) { |
| 434 | astats->lstats = (malloc_large_stats_t *)base_alloc(nlclasses * |
| 435 | sizeof(malloc_large_stats_t)); |
| 436 | if (astats->lstats == NULL) |
| 437 | return (true); |
| 438 | } |
| 439 | |
| 440 | return (false); |
| 441 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 442 | |
| 443 | static void |
| 444 | ctl_arena_clear(ctl_arena_stats_t *astats) |
| 445 | { |
| 446 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 447 | astats->dss = dss_prec_names[dss_prec_limit]; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 448 | astats->pactive = 0; |
| 449 | astats->pdirty = 0; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 450 | if (config_stats) { |
| 451 | memset(&astats->astats, 0, sizeof(arena_stats_t)); |
| 452 | astats->allocated_small = 0; |
| 453 | astats->nmalloc_small = 0; |
| 454 | astats->ndalloc_small = 0; |
| 455 | astats->nrequests_small = 0; |
Jason Evans | b172610 | 2012-02-28 16:50:47 -0800 | [diff] [blame] | 456 | memset(astats->bstats, 0, NBINS * sizeof(malloc_bin_stats_t)); |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 457 | memset(astats->lstats, 0, nlclasses * |
| 458 | sizeof(malloc_large_stats_t)); |
| 459 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 462 | static void |
| 463 | ctl_arena_stats_amerge(ctl_arena_stats_t *cstats, arena_t *arena) |
| 464 | { |
| 465 | unsigned i; |
| 466 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 467 | arena_stats_merge(arena, &cstats->dss, &cstats->pactive, |
| 468 | &cstats->pdirty, &cstats->astats, cstats->bstats, cstats->lstats); |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 469 | |
Jason Evans | b172610 | 2012-02-28 16:50:47 -0800 | [diff] [blame] | 470 | for (i = 0; i < NBINS; i++) { |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 471 | cstats->allocated_small += cstats->bstats[i].allocated; |
| 472 | cstats->nmalloc_small += cstats->bstats[i].nmalloc; |
| 473 | cstats->ndalloc_small += cstats->bstats[i].ndalloc; |
| 474 | cstats->nrequests_small += cstats->bstats[i].nrequests; |
| 475 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | static void |
| 479 | ctl_arena_stats_smerge(ctl_arena_stats_t *sstats, ctl_arena_stats_t *astats) |
| 480 | { |
| 481 | unsigned i; |
| 482 | |
| 483 | sstats->pactive += astats->pactive; |
| 484 | sstats->pdirty += astats->pdirty; |
| 485 | |
| 486 | sstats->astats.mapped += astats->astats.mapped; |
| 487 | sstats->astats.npurge += astats->astats.npurge; |
| 488 | sstats->astats.nmadvise += astats->astats.nmadvise; |
| 489 | sstats->astats.purged += astats->astats.purged; |
| 490 | |
| 491 | sstats->allocated_small += astats->allocated_small; |
| 492 | sstats->nmalloc_small += astats->nmalloc_small; |
| 493 | sstats->ndalloc_small += astats->ndalloc_small; |
| 494 | sstats->nrequests_small += astats->nrequests_small; |
| 495 | |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 496 | sstats->astats.allocated_large += astats->astats.allocated_large; |
| 497 | sstats->astats.nmalloc_large += astats->astats.nmalloc_large; |
| 498 | sstats->astats.ndalloc_large += astats->astats.ndalloc_large; |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 499 | sstats->astats.nrequests_large += astats->astats.nrequests_large; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 500 | |
| 501 | for (i = 0; i < nlclasses; i++) { |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 502 | sstats->lstats[i].nmalloc += astats->lstats[i].nmalloc; |
| 503 | sstats->lstats[i].ndalloc += astats->lstats[i].ndalloc; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 504 | sstats->lstats[i].nrequests += astats->lstats[i].nrequests; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 505 | sstats->lstats[i].curruns += astats->lstats[i].curruns; |
| 506 | } |
| 507 | |
Jason Evans | b172610 | 2012-02-28 16:50:47 -0800 | [diff] [blame] | 508 | for (i = 0; i < NBINS; i++) { |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 509 | sstats->bstats[i].allocated += astats->bstats[i].allocated; |
| 510 | sstats->bstats[i].nmalloc += astats->bstats[i].nmalloc; |
| 511 | sstats->bstats[i].ndalloc += astats->bstats[i].ndalloc; |
| 512 | sstats->bstats[i].nrequests += astats->bstats[i].nrequests; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 513 | if (config_tcache) { |
| 514 | sstats->bstats[i].nfills += astats->bstats[i].nfills; |
| 515 | sstats->bstats[i].nflushes += |
| 516 | astats->bstats[i].nflushes; |
| 517 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 518 | sstats->bstats[i].nruns += astats->bstats[i].nruns; |
| 519 | sstats->bstats[i].reruns += astats->bstats[i].reruns; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 520 | sstats->bstats[i].curruns += astats->bstats[i].curruns; |
| 521 | } |
| 522 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 523 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 524 | static void |
| 525 | ctl_arena_refresh(arena_t *arena, unsigned i) |
| 526 | { |
| 527 | ctl_arena_stats_t *astats = &ctl_stats.arenas[i]; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 528 | ctl_arena_stats_t *sstats = &ctl_stats.arenas[ctl_stats.narenas]; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 529 | |
| 530 | ctl_arena_clear(astats); |
| 531 | |
Jason Evans | 597632b | 2011-03-18 13:41:33 -0700 | [diff] [blame] | 532 | sstats->nthreads += astats->nthreads; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 533 | if (config_stats) { |
| 534 | ctl_arena_stats_amerge(astats, arena); |
| 535 | /* Merge into sum stats as well. */ |
| 536 | ctl_arena_stats_smerge(sstats, astats); |
| 537 | } else { |
| 538 | astats->pactive += arena->nactive; |
| 539 | astats->pdirty += arena->ndirty; |
| 540 | /* Merge into sum stats as well. */ |
| 541 | sstats->pactive += arena->nactive; |
| 542 | sstats->pdirty += arena->ndirty; |
| 543 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 546 | static bool |
| 547 | ctl_grow(void) |
| 548 | { |
| 549 | size_t astats_size; |
| 550 | ctl_arena_stats_t *astats; |
| 551 | arena_t **tarenas; |
| 552 | |
| 553 | /* Extend arena stats and arenas arrays. */ |
| 554 | astats_size = (ctl_stats.narenas + 2) * sizeof(ctl_arena_stats_t); |
| 555 | if (ctl_stats.narenas == narenas_auto) { |
| 556 | /* ctl_stats.arenas and arenas came from base_alloc(). */ |
| 557 | astats = (ctl_arena_stats_t *)imalloc(astats_size); |
| 558 | if (astats == NULL) |
| 559 | return (true); |
| 560 | memcpy(astats, ctl_stats.arenas, (ctl_stats.narenas + 1) * |
| 561 | sizeof(ctl_arena_stats_t)); |
| 562 | |
| 563 | tarenas = (arena_t **)imalloc((ctl_stats.narenas + 1) * |
| 564 | sizeof(arena_t *)); |
| 565 | if (tarenas == NULL) { |
| 566 | idalloc(astats); |
| 567 | return (true); |
| 568 | } |
| 569 | memcpy(tarenas, arenas, ctl_stats.narenas * sizeof(arena_t *)); |
| 570 | } else { |
| 571 | astats = (ctl_arena_stats_t *)iralloc(ctl_stats.arenas, |
| 572 | astats_size, 0, 0, false, false); |
| 573 | if (astats == NULL) |
| 574 | return (true); |
| 575 | |
| 576 | tarenas = (arena_t **)iralloc(arenas, (ctl_stats.narenas + 1) * |
| 577 | sizeof(arena_t *), 0, 0, false, false); |
| 578 | if (tarenas == NULL) |
| 579 | return (true); |
| 580 | } |
| 581 | /* Initialize the new astats and arenas elements. */ |
| 582 | memset(&astats[ctl_stats.narenas + 1], 0, sizeof(ctl_arena_stats_t)); |
| 583 | if (ctl_arena_init(&astats[ctl_stats.narenas + 1])) |
| 584 | return (true); |
| 585 | tarenas[ctl_stats.narenas] = NULL; |
| 586 | /* Swap merged stats to their new location. */ |
| 587 | { |
| 588 | ctl_arena_stats_t tstats; |
| 589 | memcpy(&tstats, &astats[ctl_stats.narenas], |
| 590 | sizeof(ctl_arena_stats_t)); |
| 591 | memcpy(&astats[ctl_stats.narenas], |
| 592 | &astats[ctl_stats.narenas + 1], sizeof(ctl_arena_stats_t)); |
| 593 | memcpy(&astats[ctl_stats.narenas + 1], &tstats, |
| 594 | sizeof(ctl_arena_stats_t)); |
| 595 | } |
| 596 | ctl_stats.arenas = astats; |
| 597 | ctl_stats.narenas++; |
| 598 | malloc_mutex_lock(&arenas_lock); |
| 599 | arenas = tarenas; |
| 600 | narenas_total++; |
| 601 | arenas_extend(narenas_total - 1); |
| 602 | malloc_mutex_unlock(&arenas_lock); |
| 603 | |
| 604 | return (false); |
| 605 | } |
| 606 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 607 | static void |
| 608 | ctl_refresh(void) |
| 609 | { |
| 610 | unsigned i; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 611 | VARIABLE_ARRAY(arena_t *, tarenas, ctl_stats.narenas); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 612 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 613 | if (config_stats) { |
| 614 | malloc_mutex_lock(&chunks_mtx); |
| 615 | ctl_stats.chunks.current = stats_chunks.curchunks; |
| 616 | ctl_stats.chunks.total = stats_chunks.nchunks; |
| 617 | ctl_stats.chunks.high = stats_chunks.highchunks; |
| 618 | malloc_mutex_unlock(&chunks_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 619 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 620 | malloc_mutex_lock(&huge_mtx); |
| 621 | ctl_stats.huge.allocated = huge_allocated; |
| 622 | ctl_stats.huge.nmalloc = huge_nmalloc; |
| 623 | ctl_stats.huge.ndalloc = huge_ndalloc; |
| 624 | malloc_mutex_unlock(&huge_mtx); |
| 625 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 626 | |
| 627 | /* |
Jason Evans | 1366826 | 2010-01-31 03:57:29 -0800 | [diff] [blame] | 628 | * Clear sum stats, since they will be merged into by |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 629 | * ctl_arena_refresh(). |
| 630 | */ |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 631 | ctl_stats.arenas[ctl_stats.narenas].nthreads = 0; |
| 632 | ctl_arena_clear(&ctl_stats.arenas[ctl_stats.narenas]); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 633 | |
| 634 | malloc_mutex_lock(&arenas_lock); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 635 | memcpy(tarenas, arenas, sizeof(arena_t *) * ctl_stats.narenas); |
| 636 | for (i = 0; i < ctl_stats.narenas; i++) { |
Jason Evans | 597632b | 2011-03-18 13:41:33 -0700 | [diff] [blame] | 637 | if (arenas[i] != NULL) |
| 638 | ctl_stats.arenas[i].nthreads = arenas[i]->nthreads; |
| 639 | else |
| 640 | ctl_stats.arenas[i].nthreads = 0; |
| 641 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 642 | malloc_mutex_unlock(&arenas_lock); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 643 | for (i = 0; i < ctl_stats.narenas; i++) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 644 | bool initialized = (tarenas[i] != NULL); |
| 645 | |
| 646 | ctl_stats.arenas[i].initialized = initialized; |
| 647 | if (initialized) |
| 648 | ctl_arena_refresh(tarenas[i], i); |
| 649 | } |
| 650 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 651 | if (config_stats) { |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 652 | ctl_stats.allocated = |
| 653 | ctl_stats.arenas[ctl_stats.narenas].allocated_small |
| 654 | + ctl_stats.arenas[ctl_stats.narenas].astats.allocated_large |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 655 | + ctl_stats.huge.allocated; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 656 | ctl_stats.active = |
| 657 | (ctl_stats.arenas[ctl_stats.narenas].pactive << LG_PAGE) |
| 658 | + ctl_stats.huge.allocated; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 659 | ctl_stats.mapped = (ctl_stats.chunks.current << opt_lg_chunk); |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 660 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 661 | |
| 662 | ctl_epoch++; |
| 663 | } |
| 664 | |
| 665 | static bool |
| 666 | ctl_init(void) |
| 667 | { |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 668 | bool ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 669 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 670 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 671 | if (ctl_initialized == false) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 672 | /* |
| 673 | * Allocate space for one extra arena stats element, which |
| 674 | * contains summed stats across all arenas. |
| 675 | */ |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 676 | assert(narenas_auto == narenas_total_get()); |
| 677 | ctl_stats.narenas = narenas_auto; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 678 | ctl_stats.arenas = (ctl_arena_stats_t *)base_alloc( |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 679 | (ctl_stats.narenas + 1) * sizeof(ctl_arena_stats_t)); |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 680 | if (ctl_stats.arenas == NULL) { |
| 681 | ret = true; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 682 | goto label_return; |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 683 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 684 | memset(ctl_stats.arenas, 0, (ctl_stats.narenas + 1) * |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 685 | sizeof(ctl_arena_stats_t)); |
| 686 | |
| 687 | /* |
| 688 | * Initialize all stats structures, regardless of whether they |
| 689 | * ever get used. Lazy initialization would allow errors to |
| 690 | * cause inconsistent state to be viewable by the application. |
| 691 | */ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 692 | if (config_stats) { |
| 693 | unsigned i; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 694 | for (i = 0; i <= ctl_stats.narenas; i++) { |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 695 | if (ctl_arena_init(&ctl_stats.arenas[i])) { |
| 696 | ret = true; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 697 | goto label_return; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 698 | } |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 699 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 700 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 701 | ctl_stats.arenas[ctl_stats.narenas].initialized = true; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 702 | |
| 703 | ctl_epoch = 0; |
| 704 | ctl_refresh(); |
| 705 | ctl_initialized = true; |
| 706 | } |
| 707 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 708 | ret = false; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 709 | label_return: |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 710 | malloc_mutex_unlock(&ctl_mtx); |
| 711 | return (ret); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | static int |
| 715 | ctl_lookup(const char *name, ctl_node_t const **nodesp, size_t *mibp, |
| 716 | size_t *depthp) |
| 717 | { |
| 718 | int ret; |
| 719 | const char *elm, *tdot, *dot; |
| 720 | size_t elen, i, j; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 721 | const ctl_named_node_t *node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 722 | |
| 723 | elm = name; |
| 724 | /* Equivalent to strchrnul(). */ |
| 725 | dot = ((tdot = strchr(elm, '.')) != NULL) ? tdot : strchr(elm, '\0'); |
| 726 | elen = (size_t)((uintptr_t)dot - (uintptr_t)elm); |
| 727 | if (elen == 0) { |
| 728 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 729 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 730 | } |
| 731 | node = super_root_node; |
| 732 | for (i = 0; i < *depthp; i++) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 733 | assert(node); |
| 734 | assert(node->nchildren > 0); |
| 735 | if (ctl_named_node(node->children) != NULL) { |
| 736 | const ctl_named_node_t *pnode = node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 737 | |
| 738 | /* Children are named. */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 739 | for (j = 0; j < node->nchildren; j++) { |
| 740 | const ctl_named_node_t *child = |
| 741 | ctl_named_children(node, j); |
| 742 | if (strlen(child->name) == elen && |
| 743 | strncmp(elm, child->name, elen) == 0) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 744 | node = child; |
| 745 | if (nodesp != NULL) |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 746 | nodesp[i] = |
| 747 | (const ctl_node_t *)node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 748 | mibp[i] = j; |
| 749 | break; |
| 750 | } |
| 751 | } |
| 752 | if (node == pnode) { |
| 753 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 754 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 755 | } |
| 756 | } else { |
Jason Evans | 41b6afb | 2012-02-02 22:04:57 -0800 | [diff] [blame] | 757 | uintmax_t index; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 758 | const ctl_indexed_node_t *inode; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 759 | |
| 760 | /* Children are indexed. */ |
Jason Evans | 41b6afb | 2012-02-02 22:04:57 -0800 | [diff] [blame] | 761 | index = malloc_strtoumax(elm, NULL, 10); |
| 762 | if (index == UINTMAX_MAX || index > SIZE_T_MAX) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 763 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 764 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 765 | } |
| 766 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 767 | inode = ctl_indexed_node(node->children); |
| 768 | node = inode->index(mibp, *depthp, (size_t)index); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 769 | if (node == NULL) { |
| 770 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 771 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | if (nodesp != NULL) |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 775 | nodesp[i] = (const ctl_node_t *)node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 776 | mibp[i] = (size_t)index; |
| 777 | } |
| 778 | |
| 779 | if (node->ctl != NULL) { |
| 780 | /* Terminal node. */ |
| 781 | if (*dot != '\0') { |
| 782 | /* |
| 783 | * The name contains more elements than are |
| 784 | * in this path through the tree. |
| 785 | */ |
| 786 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 787 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 788 | } |
| 789 | /* Complete lookup successful. */ |
| 790 | *depthp = i + 1; |
| 791 | break; |
| 792 | } |
| 793 | |
| 794 | /* Update elm. */ |
| 795 | if (*dot == '\0') { |
| 796 | /* No more elements. */ |
| 797 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 798 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 799 | } |
| 800 | elm = &dot[1]; |
| 801 | dot = ((tdot = strchr(elm, '.')) != NULL) ? tdot : |
| 802 | strchr(elm, '\0'); |
| 803 | elen = (size_t)((uintptr_t)dot - (uintptr_t)elm); |
| 804 | } |
| 805 | |
| 806 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 807 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 808 | return (ret); |
| 809 | } |
| 810 | |
| 811 | int |
| 812 | ctl_byname(const char *name, void *oldp, size_t *oldlenp, void *newp, |
| 813 | size_t newlen) |
| 814 | { |
| 815 | int ret; |
| 816 | size_t depth; |
| 817 | ctl_node_t const *nodes[CTL_MAX_DEPTH]; |
| 818 | size_t mib[CTL_MAX_DEPTH]; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 819 | const ctl_named_node_t *node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 820 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 821 | if (ctl_initialized == false && ctl_init()) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 822 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 823 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | depth = CTL_MAX_DEPTH; |
| 827 | ret = ctl_lookup(name, nodes, mib, &depth); |
| 828 | if (ret != 0) |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 829 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 830 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 831 | node = ctl_named_node(nodes[depth-1]); |
| 832 | if (node != NULL && node->ctl) |
| 833 | ret = node->ctl(mib, depth, oldp, oldlenp, newp, newlen); |
| 834 | else { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 835 | /* The name refers to a partial path through the ctl tree. */ |
| 836 | ret = ENOENT; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 837 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 838 | |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 839 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 840 | return(ret); |
| 841 | } |
| 842 | |
| 843 | int |
| 844 | ctl_nametomib(const char *name, size_t *mibp, size_t *miblenp) |
| 845 | { |
| 846 | int ret; |
| 847 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 848 | if (ctl_initialized == false && ctl_init()) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 849 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 850 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | ret = ctl_lookup(name, NULL, mibp, miblenp); |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 854 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 855 | return(ret); |
| 856 | } |
| 857 | |
| 858 | int |
| 859 | ctl_bymib(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 860 | void *newp, size_t newlen) |
| 861 | { |
| 862 | int ret; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 863 | const ctl_named_node_t *node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 864 | size_t i; |
| 865 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 866 | if (ctl_initialized == false && ctl_init()) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 867 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 868 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* Iterate down the tree. */ |
| 872 | node = super_root_node; |
| 873 | for (i = 0; i < miblen; i++) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 874 | assert(node); |
| 875 | assert(node->nchildren > 0); |
| 876 | if (ctl_named_node(node->children) != NULL) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 877 | /* Children are named. */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 878 | if (node->nchildren <= mib[i]) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 879 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 880 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 881 | } |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 882 | node = ctl_named_children(node, mib[i]); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 883 | } else { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 884 | const ctl_indexed_node_t *inode; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 885 | |
| 886 | /* Indexed element. */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 887 | inode = ctl_indexed_node(node->children); |
| 888 | node = inode->index(mib, miblen, mib[i]); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 889 | if (node == NULL) { |
| 890 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 891 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | /* Call the ctl function. */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 897 | if (node && node->ctl) |
| 898 | ret = node->ctl(mib, miblen, oldp, oldlenp, newp, newlen); |
| 899 | else { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 900 | /* Partial MIB. */ |
| 901 | ret = ENOENT; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 902 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 903 | |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 904 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 905 | return(ret); |
| 906 | } |
| 907 | |
| 908 | bool |
| 909 | ctl_boot(void) |
| 910 | { |
| 911 | |
| 912 | if (malloc_mutex_init(&ctl_mtx)) |
| 913 | return (true); |
| 914 | |
| 915 | ctl_initialized = false; |
| 916 | |
| 917 | return (false); |
| 918 | } |
| 919 | |
Jason Evans | 20f1fc9 | 2012-10-09 14:46:22 -0700 | [diff] [blame] | 920 | void |
| 921 | ctl_prefork(void) |
| 922 | { |
| 923 | |
| 924 | malloc_mutex_lock(&ctl_mtx); |
| 925 | } |
| 926 | |
| 927 | void |
| 928 | ctl_postfork_parent(void) |
| 929 | { |
| 930 | |
| 931 | malloc_mutex_postfork_parent(&ctl_mtx); |
| 932 | } |
| 933 | |
| 934 | void |
| 935 | ctl_postfork_child(void) |
| 936 | { |
| 937 | |
| 938 | malloc_mutex_postfork_child(&ctl_mtx); |
| 939 | } |
| 940 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 941 | /******************************************************************************/ |
| 942 | /* *_ctl() functions. */ |
| 943 | |
| 944 | #define READONLY() do { \ |
| 945 | if (newp != NULL || newlen != 0) { \ |
| 946 | ret = EPERM; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 947 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 948 | } \ |
| 949 | } while (0) |
| 950 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 951 | #define WRITEONLY() do { \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 952 | if (oldp != NULL || oldlenp != NULL) { \ |
| 953 | ret = EPERM; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 954 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 955 | } \ |
| 956 | } while (0) |
| 957 | |
| 958 | #define READ(v, t) do { \ |
| 959 | if (oldp != NULL && oldlenp != NULL) { \ |
| 960 | if (*oldlenp != sizeof(t)) { \ |
| 961 | size_t copylen = (sizeof(t) <= *oldlenp) \ |
| 962 | ? sizeof(t) : *oldlenp; \ |
| 963 | memcpy(oldp, (void *)&v, copylen); \ |
| 964 | ret = EINVAL; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 965 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 966 | } else \ |
| 967 | *(t *)oldp = v; \ |
| 968 | } \ |
| 969 | } while (0) |
| 970 | |
| 971 | #define WRITE(v, t) do { \ |
| 972 | if (newp != NULL) { \ |
| 973 | if (newlen != sizeof(t)) { \ |
| 974 | ret = EINVAL; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 975 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 976 | } \ |
| 977 | v = *(t *)newp; \ |
| 978 | } \ |
| 979 | } while (0) |
| 980 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 981 | /* |
| 982 | * There's a lot of code duplication in the following macros due to limitations |
| 983 | * in how nested cpp macros are expanded. |
| 984 | */ |
| 985 | #define CTL_RO_CLGEN(c, l, n, v, t) \ |
| 986 | static int \ |
| 987 | n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \ |
| 988 | void *newp, size_t newlen) \ |
| 989 | { \ |
| 990 | int ret; \ |
| 991 | t oldval; \ |
| 992 | \ |
| 993 | if ((c) == false) \ |
| 994 | return (ENOENT); \ |
| 995 | if (l) \ |
| 996 | malloc_mutex_lock(&ctl_mtx); \ |
| 997 | READONLY(); \ |
| 998 | oldval = v; \ |
| 999 | READ(oldval, t); \ |
| 1000 | \ |
| 1001 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1002 | label_return: \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1003 | if (l) \ |
| 1004 | malloc_mutex_unlock(&ctl_mtx); \ |
| 1005 | return (ret); \ |
| 1006 | } |
| 1007 | |
| 1008 | #define CTL_RO_CGEN(c, n, v, t) \ |
| 1009 | static int \ |
| 1010 | n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \ |
| 1011 | void *newp, size_t newlen) \ |
| 1012 | { \ |
| 1013 | int ret; \ |
| 1014 | t oldval; \ |
| 1015 | \ |
| 1016 | if ((c) == false) \ |
| 1017 | return (ENOENT); \ |
| 1018 | malloc_mutex_lock(&ctl_mtx); \ |
| 1019 | READONLY(); \ |
| 1020 | oldval = v; \ |
| 1021 | READ(oldval, t); \ |
| 1022 | \ |
| 1023 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1024 | label_return: \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1025 | malloc_mutex_unlock(&ctl_mtx); \ |
| 1026 | return (ret); \ |
| 1027 | } |
| 1028 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1029 | #define CTL_RO_GEN(n, v, t) \ |
| 1030 | static int \ |
| 1031 | n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \ |
| 1032 | void *newp, size_t newlen) \ |
| 1033 | { \ |
| 1034 | int ret; \ |
| 1035 | t oldval; \ |
| 1036 | \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1037 | malloc_mutex_lock(&ctl_mtx); \ |
| 1038 | READONLY(); \ |
| 1039 | oldval = v; \ |
| 1040 | READ(oldval, t); \ |
| 1041 | \ |
| 1042 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1043 | label_return: \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1044 | malloc_mutex_unlock(&ctl_mtx); \ |
| 1045 | return (ret); \ |
| 1046 | } |
| 1047 | |
| 1048 | /* |
| 1049 | * ctl_mtx is not acquired, under the assumption that no pertinent data will |
| 1050 | * mutate during the call. |
| 1051 | */ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1052 | #define CTL_RO_NL_CGEN(c, n, v, t) \ |
| 1053 | static int \ |
| 1054 | n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \ |
| 1055 | void *newp, size_t newlen) \ |
| 1056 | { \ |
| 1057 | int ret; \ |
| 1058 | t oldval; \ |
| 1059 | \ |
| 1060 | if ((c) == false) \ |
| 1061 | return (ENOENT); \ |
| 1062 | READONLY(); \ |
| 1063 | oldval = v; \ |
| 1064 | READ(oldval, t); \ |
| 1065 | \ |
| 1066 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1067 | label_return: \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1068 | return (ret); \ |
| 1069 | } |
| 1070 | |
| 1071 | #define CTL_RO_NL_GEN(n, v, t) \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1072 | static int \ |
| 1073 | n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \ |
| 1074 | void *newp, size_t newlen) \ |
| 1075 | { \ |
| 1076 | int ret; \ |
| 1077 | t oldval; \ |
| 1078 | \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1079 | READONLY(); \ |
| 1080 | oldval = v; \ |
| 1081 | READ(oldval, t); \ |
| 1082 | \ |
| 1083 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1084 | label_return: \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1085 | return (ret); \ |
| 1086 | } |
| 1087 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1088 | #define CTL_RO_BOOL_CONFIG_GEN(n) \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1089 | static int \ |
| 1090 | n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \ |
| 1091 | void *newp, size_t newlen) \ |
| 1092 | { \ |
| 1093 | int ret; \ |
| 1094 | bool oldval; \ |
| 1095 | \ |
| 1096 | READONLY(); \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1097 | oldval = n; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1098 | READ(oldval, bool); \ |
| 1099 | \ |
| 1100 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1101 | label_return: \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1102 | return (ret); \ |
| 1103 | } |
| 1104 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1105 | CTL_RO_NL_GEN(version, JEMALLOC_VERSION, const char *) |
Jason Evans | a40bc7a | 2010-03-02 13:01:16 -0800 | [diff] [blame] | 1106 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1107 | static int |
| 1108 | epoch_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1109 | void *newp, size_t newlen) |
| 1110 | { |
| 1111 | int ret; |
| 1112 | uint64_t newval; |
| 1113 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1114 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1115 | WRITE(newval, uint64_t); |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1116 | if (newp != NULL) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1117 | ctl_refresh(); |
| 1118 | READ(ctl_epoch, uint64_t); |
| 1119 | |
| 1120 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1121 | label_return: |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1122 | malloc_mutex_unlock(&ctl_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1123 | return (ret); |
| 1124 | } |
| 1125 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1126 | static int |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1127 | thread_tcache_enabled_ctl(const size_t *mib, size_t miblen, void *oldp, |
| 1128 | size_t *oldlenp, void *newp, size_t newlen) |
| 1129 | { |
| 1130 | int ret; |
| 1131 | bool oldval; |
| 1132 | |
| 1133 | if (config_tcache == false) |
| 1134 | return (ENOENT); |
| 1135 | |
| 1136 | oldval = tcache_enabled_get(); |
| 1137 | if (newp != NULL) { |
| 1138 | if (newlen != sizeof(bool)) { |
| 1139 | ret = EINVAL; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1140 | goto label_return; |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1141 | } |
| 1142 | tcache_enabled_set(*(bool *)newp); |
| 1143 | } |
| 1144 | READ(oldval, bool); |
| 1145 | |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1146 | ret = 0; |
Jason Evans | f4c3f85 | 2012-10-08 15:48:04 -0700 | [diff] [blame] | 1147 | label_return: |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1148 | return (ret); |
| 1149 | } |
| 1150 | |
| 1151 | static int |
Jason Evans | e7b8fa1 | 2012-03-16 17:09:32 -0700 | [diff] [blame] | 1152 | thread_tcache_flush_ctl(const size_t *mib, size_t miblen, void *oldp, |
| 1153 | size_t *oldlenp, void *newp, size_t newlen) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1154 | { |
| 1155 | int ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1156 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1157 | if (config_tcache == false) |
| 1158 | return (ENOENT); |
| 1159 | |
Mike Hommey | af04b74 | 2012-04-30 12:38:25 +0200 | [diff] [blame] | 1160 | READONLY(); |
| 1161 | WRITEONLY(); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1162 | |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1163 | tcache_flush(); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1164 | |
| 1165 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1166 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1167 | return (ret); |
| 1168 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1169 | |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1170 | static int |
| 1171 | thread_arena_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1172 | void *newp, size_t newlen) |
| 1173 | { |
| 1174 | int ret; |
| 1175 | unsigned newind, oldind; |
| 1176 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1177 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 01b3fe5 | 2012-04-03 09:28:00 -0700 | [diff] [blame] | 1178 | newind = oldind = choose_arena(NULL)->ind; |
Jason Evans | a7153a0 | 2011-03-14 11:39:49 -0700 | [diff] [blame] | 1179 | WRITE(newind, unsigned); |
| 1180 | READ(oldind, unsigned); |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1181 | if (newind != oldind) { |
| 1182 | arena_t *arena; |
| 1183 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1184 | if (newind >= ctl_stats.narenas) { |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1185 | /* New arena index is out of range. */ |
| 1186 | ret = EFAULT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1187 | goto label_return; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | /* Initialize arena if necessary. */ |
| 1191 | malloc_mutex_lock(&arenas_lock); |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1192 | if ((arena = arenas[newind]) == NULL && (arena = |
| 1193 | arenas_extend(newind)) == NULL) { |
| 1194 | malloc_mutex_unlock(&arenas_lock); |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1195 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1196 | goto label_return; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1197 | } |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1198 | assert(arena == arenas[newind]); |
| 1199 | arenas[oldind]->nthreads--; |
| 1200 | arenas[newind]->nthreads++; |
| 1201 | malloc_mutex_unlock(&arenas_lock); |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1202 | |
| 1203 | /* Set new arena association. */ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1204 | if (config_tcache) { |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1205 | tcache_t *tcache; |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 1206 | if ((uintptr_t)(tcache = *tcache_tsd_get()) > |
| 1207 | (uintptr_t)TCACHE_STATE_MAX) { |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1208 | tcache_arena_dissociate(tcache); |
| 1209 | tcache_arena_associate(tcache, arena); |
| 1210 | } |
Jason Evans | 624f2f3 | 2010-12-29 12:21:05 -0800 | [diff] [blame] | 1211 | } |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1212 | arenas_tsd_set(&arena); |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1216 | label_return: |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1217 | malloc_mutex_unlock(&ctl_mtx); |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1218 | return (ret); |
| 1219 | } |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1220 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1221 | CTL_RO_NL_CGEN(config_stats, thread_allocated, |
| 1222 | thread_allocated_tsd_get()->allocated, uint64_t) |
| 1223 | CTL_RO_NL_CGEN(config_stats, thread_allocatedp, |
| 1224 | &thread_allocated_tsd_get()->allocated, uint64_t *) |
| 1225 | CTL_RO_NL_CGEN(config_stats, thread_deallocated, |
| 1226 | thread_allocated_tsd_get()->deallocated, uint64_t) |
| 1227 | CTL_RO_NL_CGEN(config_stats, thread_deallocatedp, |
| 1228 | &thread_allocated_tsd_get()->deallocated, uint64_t *) |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 1229 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1230 | /******************************************************************************/ |
| 1231 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1232 | CTL_RO_BOOL_CONFIG_GEN(config_debug) |
| 1233 | CTL_RO_BOOL_CONFIG_GEN(config_dss) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1234 | CTL_RO_BOOL_CONFIG_GEN(config_fill) |
| 1235 | CTL_RO_BOOL_CONFIG_GEN(config_lazy_lock) |
Jason Evans | 2e671ff | 2012-05-09 16:12:00 -0700 | [diff] [blame] | 1236 | CTL_RO_BOOL_CONFIG_GEN(config_mremap) |
Jason Evans | 59ae276 | 2012-04-16 17:52:27 -0700 | [diff] [blame] | 1237 | CTL_RO_BOOL_CONFIG_GEN(config_munmap) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1238 | CTL_RO_BOOL_CONFIG_GEN(config_prof) |
| 1239 | CTL_RO_BOOL_CONFIG_GEN(config_prof_libgcc) |
| 1240 | CTL_RO_BOOL_CONFIG_GEN(config_prof_libunwind) |
| 1241 | CTL_RO_BOOL_CONFIG_GEN(config_stats) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1242 | CTL_RO_BOOL_CONFIG_GEN(config_tcache) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1243 | CTL_RO_BOOL_CONFIG_GEN(config_tls) |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 1244 | CTL_RO_BOOL_CONFIG_GEN(config_utrace) |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 1245 | CTL_RO_BOOL_CONFIG_GEN(config_valgrind) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1246 | CTL_RO_BOOL_CONFIG_GEN(config_xmalloc) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1247 | |
| 1248 | /******************************************************************************/ |
| 1249 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1250 | CTL_RO_NL_GEN(opt_abort, opt_abort, bool) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1251 | CTL_RO_NL_GEN(opt_dss, opt_dss, const char *) |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1252 | CTL_RO_NL_GEN(opt_lg_chunk, opt_lg_chunk, size_t) |
| 1253 | CTL_RO_NL_GEN(opt_narenas, opt_narenas, size_t) |
| 1254 | CTL_RO_NL_GEN(opt_lg_dirty_mult, opt_lg_dirty_mult, ssize_t) |
| 1255 | CTL_RO_NL_GEN(opt_stats_print, opt_stats_print, bool) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1256 | CTL_RO_NL_CGEN(config_fill, opt_junk, opt_junk, bool) |
| 1257 | CTL_RO_NL_CGEN(config_fill, opt_zero, opt_zero, bool) |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 1258 | CTL_RO_NL_CGEN(config_fill, opt_quarantine, opt_quarantine, size_t) |
| 1259 | CTL_RO_NL_CGEN(config_fill, opt_redzone, opt_redzone, bool) |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 1260 | CTL_RO_NL_CGEN(config_utrace, opt_utrace, opt_utrace, bool) |
Jason Evans | 122449b | 2012-04-06 00:35:09 -0700 | [diff] [blame] | 1261 | CTL_RO_NL_CGEN(config_valgrind, opt_valgrind, opt_valgrind, bool) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1262 | CTL_RO_NL_CGEN(config_xmalloc, opt_xmalloc, opt_xmalloc, bool) |
| 1263 | CTL_RO_NL_CGEN(config_tcache, opt_tcache, opt_tcache, bool) |
Jason Evans | f3ca7c8 | 2012-04-04 16:16:09 -0700 | [diff] [blame] | 1264 | CTL_RO_NL_CGEN(config_tcache, opt_lg_tcache_max, opt_lg_tcache_max, ssize_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1265 | CTL_RO_NL_CGEN(config_prof, opt_prof, opt_prof, bool) |
| 1266 | CTL_RO_NL_CGEN(config_prof, opt_prof_prefix, opt_prof_prefix, const char *) |
| 1267 | CTL_RO_CGEN(config_prof, opt_prof_active, opt_prof_active, bool) /* Mutable. */ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1268 | CTL_RO_NL_CGEN(config_prof, opt_lg_prof_sample, opt_lg_prof_sample, size_t) |
| 1269 | CTL_RO_NL_CGEN(config_prof, opt_lg_prof_interval, opt_lg_prof_interval, ssize_t) |
| 1270 | CTL_RO_NL_CGEN(config_prof, opt_prof_gdump, opt_prof_gdump, bool) |
Jason Evans | 0b25fe7 | 2012-04-17 16:39:33 -0700 | [diff] [blame] | 1271 | CTL_RO_NL_CGEN(config_prof, opt_prof_final, opt_prof_final, bool) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1272 | CTL_RO_NL_CGEN(config_prof, opt_prof_leak, opt_prof_leak, bool) |
| 1273 | CTL_RO_NL_CGEN(config_prof, opt_prof_accum, opt_prof_accum, bool) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1274 | |
| 1275 | /******************************************************************************/ |
| 1276 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1277 | static int |
| 1278 | arena_purge(unsigned arena_ind) |
| 1279 | { |
| 1280 | int ret; |
| 1281 | |
| 1282 | malloc_mutex_lock(&ctl_mtx); |
| 1283 | { |
| 1284 | VARIABLE_ARRAY(arena_t *, tarenas, ctl_stats.narenas); |
| 1285 | |
| 1286 | malloc_mutex_lock(&arenas_lock); |
| 1287 | memcpy(tarenas, arenas, sizeof(arena_t *) * ctl_stats.narenas); |
| 1288 | malloc_mutex_unlock(&arenas_lock); |
| 1289 | |
| 1290 | if (arena_ind == ctl_stats.narenas) { |
| 1291 | unsigned i; |
| 1292 | for (i = 0; i < ctl_stats.narenas; i++) { |
| 1293 | if (tarenas[i] != NULL) |
| 1294 | arena_purge_all(tarenas[i]); |
| 1295 | } |
| 1296 | } else { |
| 1297 | assert(arena_ind < ctl_stats.narenas); |
| 1298 | if (tarenas[arena_ind] != NULL) |
| 1299 | arena_purge_all(tarenas[arena_ind]); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | ret = 0; |
| 1304 | malloc_mutex_unlock(&ctl_mtx); |
| 1305 | return (ret); |
| 1306 | } |
| 1307 | |
| 1308 | static int |
| 1309 | arena_i_purge_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1310 | void *newp, size_t newlen) |
| 1311 | { |
| 1312 | int ret; |
| 1313 | |
| 1314 | READONLY(); |
| 1315 | WRITEONLY(); |
| 1316 | ret = arena_purge(mib[1]); |
| 1317 | |
| 1318 | label_return: |
| 1319 | return (ret); |
| 1320 | } |
| 1321 | |
| 1322 | static int |
| 1323 | arena_i_dss_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1324 | void *newp, size_t newlen) |
| 1325 | { |
| 1326 | int ret, i; |
| 1327 | bool match, err; |
| 1328 | const char *dss; |
| 1329 | unsigned arena_ind = mib[1]; |
| 1330 | dss_prec_t dss_prec_old = dss_prec_limit; |
| 1331 | dss_prec_t dss_prec = dss_prec_limit; |
| 1332 | |
Jason Evans | a5c80f8 | 2012-10-15 12:48:59 -0700 | [diff] [blame^] | 1333 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1334 | WRITE(dss, const char *); |
| 1335 | match = false; |
| 1336 | for (i = 0; i < dss_prec_limit; i++) { |
| 1337 | if (strcmp(dss_prec_names[i], dss) == 0) { |
| 1338 | dss_prec = i; |
| 1339 | match = true; |
| 1340 | break; |
| 1341 | } |
| 1342 | } |
| 1343 | if (match == false) { |
| 1344 | ret = EINVAL; |
| 1345 | goto label_return; |
| 1346 | } |
| 1347 | |
| 1348 | if (arena_ind < ctl_stats.narenas) { |
| 1349 | arena_t *arena = arenas[arena_ind]; |
| 1350 | if (arena != NULL) { |
| 1351 | dss_prec_old = arena_dss_prec_get(arena); |
| 1352 | arena_dss_prec_set(arena, dss_prec); |
| 1353 | err = false; |
| 1354 | } else |
| 1355 | err = true; |
| 1356 | } else { |
| 1357 | dss_prec_old = chunk_dss_prec_get(); |
| 1358 | err = chunk_dss_prec_set(dss_prec); |
| 1359 | } |
| 1360 | dss = dss_prec_names[dss_prec_old]; |
| 1361 | READ(dss, const char *); |
| 1362 | if (err) { |
| 1363 | ret = EFAULT; |
| 1364 | goto label_return; |
| 1365 | } |
| 1366 | |
| 1367 | ret = 0; |
| 1368 | label_return: |
Jason Evans | a5c80f8 | 2012-10-15 12:48:59 -0700 | [diff] [blame^] | 1369 | malloc_mutex_unlock(&ctl_mtx); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1370 | return (ret); |
| 1371 | } |
| 1372 | |
| 1373 | static const ctl_named_node_t * |
| 1374 | arena_i_index(const size_t *mib, size_t miblen, size_t i) |
| 1375 | { |
| 1376 | const ctl_named_node_t * ret; |
| 1377 | |
| 1378 | malloc_mutex_lock(&ctl_mtx); |
| 1379 | if (i > ctl_stats.narenas) { |
| 1380 | ret = NULL; |
| 1381 | goto label_return; |
| 1382 | } |
| 1383 | |
| 1384 | ret = super_arena_i_node; |
| 1385 | label_return: |
| 1386 | malloc_mutex_unlock(&ctl_mtx); |
| 1387 | return (ret); |
| 1388 | } |
| 1389 | |
| 1390 | |
| 1391 | /******************************************************************************/ |
| 1392 | |
Jason Evans | 49f7e8f | 2011-03-15 13:59:15 -0700 | [diff] [blame] | 1393 | CTL_RO_NL_GEN(arenas_bin_i_size, arena_bin_info[mib[2]].reg_size, size_t) |
| 1394 | CTL_RO_NL_GEN(arenas_bin_i_nregs, arena_bin_info[mib[2]].nregs, uint32_t) |
| 1395 | CTL_RO_NL_GEN(arenas_bin_i_run_size, arena_bin_info[mib[2]].run_size, size_t) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1396 | static const ctl_named_node_t * |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1397 | arenas_bin_i_index(const size_t *mib, size_t miblen, size_t i) |
| 1398 | { |
| 1399 | |
Jason Evans | b172610 | 2012-02-28 16:50:47 -0800 | [diff] [blame] | 1400 | if (i > NBINS) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1401 | return (NULL); |
| 1402 | return (super_arenas_bin_i_node); |
| 1403 | } |
| 1404 | |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame] | 1405 | CTL_RO_NL_GEN(arenas_lrun_i_size, ((mib[2]+1) << LG_PAGE), size_t) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1406 | static const ctl_named_node_t * |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1407 | arenas_lrun_i_index(const size_t *mib, size_t miblen, size_t i) |
| 1408 | { |
| 1409 | |
| 1410 | if (i > nlclasses) |
| 1411 | return (NULL); |
| 1412 | return (super_arenas_lrun_i_node); |
| 1413 | } |
| 1414 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1415 | static int |
| 1416 | arenas_narenas_ctl(const size_t *mib, size_t miblen, void *oldp, |
| 1417 | size_t *oldlenp, void *newp, size_t newlen) |
| 1418 | { |
| 1419 | int ret; |
| 1420 | unsigned narenas; |
| 1421 | |
| 1422 | malloc_mutex_lock(&ctl_mtx); |
| 1423 | READONLY(); |
| 1424 | if (*oldlenp != sizeof(unsigned)) { |
| 1425 | ret = EINVAL; |
| 1426 | goto label_return; |
| 1427 | } |
| 1428 | narenas = ctl_stats.narenas; |
| 1429 | READ(narenas, unsigned); |
| 1430 | |
| 1431 | ret = 0; |
| 1432 | label_return: |
| 1433 | malloc_mutex_unlock(&ctl_mtx); |
| 1434 | return (ret); |
| 1435 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1436 | |
| 1437 | static int |
| 1438 | arenas_initialized_ctl(const size_t *mib, size_t miblen, void *oldp, |
| 1439 | size_t *oldlenp, void *newp, size_t newlen) |
| 1440 | { |
| 1441 | int ret; |
| 1442 | unsigned nread, i; |
| 1443 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1444 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1445 | READONLY(); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1446 | if (*oldlenp != ctl_stats.narenas * sizeof(bool)) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1447 | ret = EINVAL; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1448 | nread = (*oldlenp < ctl_stats.narenas * sizeof(bool)) |
| 1449 | ? (*oldlenp / sizeof(bool)) : ctl_stats.narenas; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1450 | } else { |
| 1451 | ret = 0; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1452 | nread = ctl_stats.narenas; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | for (i = 0; i < nread; i++) |
| 1456 | ((bool *)oldp)[i] = ctl_stats.arenas[i].initialized; |
| 1457 | |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1458 | label_return: |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1459 | malloc_mutex_unlock(&ctl_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1460 | return (ret); |
| 1461 | } |
| 1462 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1463 | CTL_RO_NL_GEN(arenas_quantum, QUANTUM, size_t) |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame] | 1464 | CTL_RO_NL_GEN(arenas_page, PAGE, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1465 | CTL_RO_NL_CGEN(config_tcache, arenas_tcache_max, tcache_maxclass, size_t) |
Jason Evans | b172610 | 2012-02-28 16:50:47 -0800 | [diff] [blame] | 1466 | CTL_RO_NL_GEN(arenas_nbins, NBINS, unsigned) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1467 | CTL_RO_NL_CGEN(config_tcache, arenas_nhbins, nhbins, unsigned) |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1468 | CTL_RO_NL_GEN(arenas_nlruns, nlclasses, size_t) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1469 | |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1470 | static int |
| 1471 | arenas_purge_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1472 | void *newp, size_t newlen) |
| 1473 | { |
| 1474 | int ret; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1475 | unsigned arena_ind; |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1476 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1477 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1478 | WRITEONLY(); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1479 | arena_ind = UINT_MAX; |
| 1480 | WRITE(arena_ind, unsigned); |
| 1481 | if (newp != NULL && arena_ind >= ctl_stats.narenas) |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1482 | ret = EFAULT; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1483 | else { |
| 1484 | if (arena_ind == UINT_MAX) |
| 1485 | arena_ind = ctl_stats.narenas; |
| 1486 | ret = arena_purge(arena_ind); |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1489 | label_return: |
| 1490 | malloc_mutex_unlock(&ctl_mtx); |
| 1491 | return (ret); |
| 1492 | } |
| 1493 | |
| 1494 | static int |
| 1495 | arenas_extend_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1496 | void *newp, size_t newlen) |
| 1497 | { |
| 1498 | int ret; |
| 1499 | |
| 1500 | malloc_mutex_lock(&ctl_mtx); |
| 1501 | READONLY(); |
| 1502 | if (ctl_grow()) { |
| 1503 | ret = EAGAIN; |
| 1504 | goto label_return; |
| 1505 | } |
| 1506 | READ(ctl_stats.narenas - 1, unsigned); |
| 1507 | |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1508 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1509 | label_return: |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1510 | malloc_mutex_unlock(&ctl_mtx); |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1511 | return (ret); |
| 1512 | } |
| 1513 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1514 | /******************************************************************************/ |
| 1515 | |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1516 | static int |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 1517 | prof_active_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1518 | void *newp, size_t newlen) |
| 1519 | { |
| 1520 | int ret; |
| 1521 | bool oldval; |
| 1522 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1523 | if (config_prof == false) |
| 1524 | return (ENOENT); |
| 1525 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1526 | malloc_mutex_lock(&ctl_mtx); /* Protect opt_prof_active. */ |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 1527 | oldval = opt_prof_active; |
| 1528 | if (newp != NULL) { |
| 1529 | /* |
| 1530 | * The memory barriers will tend to make opt_prof_active |
| 1531 | * propagate faster on systems with weak memory ordering. |
| 1532 | */ |
| 1533 | mb_write(); |
| 1534 | WRITE(opt_prof_active, bool); |
| 1535 | mb_write(); |
| 1536 | } |
| 1537 | READ(oldval, bool); |
| 1538 | |
| 1539 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1540 | label_return: |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1541 | malloc_mutex_unlock(&ctl_mtx); |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 1542 | return (ret); |
| 1543 | } |
| 1544 | |
| 1545 | static int |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1546 | prof_dump_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, |
| 1547 | void *newp, size_t newlen) |
| 1548 | { |
| 1549 | int ret; |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 1550 | const char *filename = NULL; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1551 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1552 | if (config_prof == false) |
| 1553 | return (ENOENT); |
| 1554 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 1555 | WRITEONLY(); |
| 1556 | WRITE(filename, const char *); |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1557 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 1558 | if (prof_mdump(filename)) { |
| 1559 | ret = EFAULT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1560 | goto label_return; |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 1561 | } |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1562 | |
| 1563 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1564 | label_return: |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1565 | return (ret); |
| 1566 | } |
| 1567 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1568 | CTL_RO_NL_CGEN(config_prof, prof_interval, prof_interval, uint64_t) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1569 | |
| 1570 | /******************************************************************************/ |
| 1571 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1572 | CTL_RO_CGEN(config_stats, stats_chunks_current, ctl_stats.chunks.current, |
| 1573 | size_t) |
| 1574 | CTL_RO_CGEN(config_stats, stats_chunks_total, ctl_stats.chunks.total, uint64_t) |
| 1575 | CTL_RO_CGEN(config_stats, stats_chunks_high, ctl_stats.chunks.high, size_t) |
| 1576 | CTL_RO_CGEN(config_stats, stats_huge_allocated, huge_allocated, size_t) |
| 1577 | CTL_RO_CGEN(config_stats, stats_huge_nmalloc, huge_nmalloc, uint64_t) |
| 1578 | CTL_RO_CGEN(config_stats, stats_huge_ndalloc, huge_ndalloc, uint64_t) |
| 1579 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_allocated, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1580 | ctl_stats.arenas[mib[2]].allocated_small, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1581 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_nmalloc, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1582 | ctl_stats.arenas[mib[2]].nmalloc_small, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1583 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_ndalloc, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1584 | ctl_stats.arenas[mib[2]].ndalloc_small, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1585 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_nrequests, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1586 | ctl_stats.arenas[mib[2]].nrequests_small, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1587 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_allocated, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1588 | ctl_stats.arenas[mib[2]].astats.allocated_large, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1589 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_nmalloc, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1590 | ctl_stats.arenas[mib[2]].astats.nmalloc_large, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1591 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_ndalloc, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1592 | ctl_stats.arenas[mib[2]].astats.ndalloc_large, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1593 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_nrequests, |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 1594 | ctl_stats.arenas[mib[2]].astats.nrequests_large, uint64_t) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1595 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1596 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_allocated, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1597 | ctl_stats.arenas[mib[2]].bstats[mib[4]].allocated, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1598 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nmalloc, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1599 | ctl_stats.arenas[mib[2]].bstats[mib[4]].nmalloc, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1600 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_ndalloc, |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 1601 | ctl_stats.arenas[mib[2]].bstats[mib[4]].ndalloc, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1602 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nrequests, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1603 | ctl_stats.arenas[mib[2]].bstats[mib[4]].nrequests, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1604 | CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_bins_j_nfills, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1605 | ctl_stats.arenas[mib[2]].bstats[mib[4]].nfills, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1606 | CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_bins_j_nflushes, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1607 | ctl_stats.arenas[mib[2]].bstats[mib[4]].nflushes, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1608 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nruns, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1609 | ctl_stats.arenas[mib[2]].bstats[mib[4]].nruns, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1610 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nreruns, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1611 | ctl_stats.arenas[mib[2]].bstats[mib[4]].reruns, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1612 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_curruns, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1613 | ctl_stats.arenas[mib[2]].bstats[mib[4]].curruns, size_t) |
| 1614 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1615 | static const ctl_named_node_t * |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1616 | stats_arenas_i_bins_j_index(const size_t *mib, size_t miblen, size_t j) |
| 1617 | { |
| 1618 | |
Jason Evans | b172610 | 2012-02-28 16:50:47 -0800 | [diff] [blame] | 1619 | if (j > NBINS) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1620 | return (NULL); |
| 1621 | return (super_stats_arenas_i_bins_j_node); |
| 1622 | } |
| 1623 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1624 | CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_nmalloc, |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 1625 | ctl_stats.arenas[mib[2]].lstats[mib[4]].nmalloc, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1626 | CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_ndalloc, |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 1627 | ctl_stats.arenas[mib[2]].lstats[mib[4]].ndalloc, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1628 | CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_nrequests, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1629 | ctl_stats.arenas[mib[2]].lstats[mib[4]].nrequests, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1630 | CTL_RO_CGEN(config_stats, stats_arenas_i_lruns_j_curruns, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1631 | ctl_stats.arenas[mib[2]].lstats[mib[4]].curruns, size_t) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1632 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1633 | static const ctl_named_node_t * |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1634 | stats_arenas_i_lruns_j_index(const size_t *mib, size_t miblen, size_t j) |
| 1635 | { |
| 1636 | |
| 1637 | if (j > nlclasses) |
| 1638 | return (NULL); |
| 1639 | return (super_stats_arenas_i_lruns_j_node); |
| 1640 | } |
| 1641 | |
Jason Evans | 597632b | 2011-03-18 13:41:33 -0700 | [diff] [blame] | 1642 | CTL_RO_GEN(stats_arenas_i_nthreads, ctl_stats.arenas[mib[2]].nthreads, unsigned) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1643 | CTL_RO_GEN(stats_arenas_i_dss, ctl_stats.arenas[mib[2]].dss, const char *) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1644 | CTL_RO_GEN(stats_arenas_i_pactive, ctl_stats.arenas[mib[2]].pactive, size_t) |
| 1645 | CTL_RO_GEN(stats_arenas_i_pdirty, ctl_stats.arenas[mib[2]].pdirty, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1646 | CTL_RO_CGEN(config_stats, stats_arenas_i_mapped, |
| 1647 | ctl_stats.arenas[mib[2]].astats.mapped, size_t) |
| 1648 | CTL_RO_CGEN(config_stats, stats_arenas_i_npurge, |
| 1649 | ctl_stats.arenas[mib[2]].astats.npurge, uint64_t) |
| 1650 | CTL_RO_CGEN(config_stats, stats_arenas_i_nmadvise, |
| 1651 | ctl_stats.arenas[mib[2]].astats.nmadvise, uint64_t) |
| 1652 | CTL_RO_CGEN(config_stats, stats_arenas_i_purged, |
| 1653 | ctl_stats.arenas[mib[2]].astats.purged, uint64_t) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1654 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1655 | static const ctl_named_node_t * |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1656 | stats_arenas_i_index(const size_t *mib, size_t miblen, size_t i) |
| 1657 | { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 1658 | const ctl_named_node_t * ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1659 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1660 | malloc_mutex_lock(&ctl_mtx); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1661 | if (i > ctl_stats.narenas || ctl_stats.arenas[i].initialized == false) { |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1662 | ret = NULL; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1663 | goto label_return; |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | ret = super_stats_arenas_i_node; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1667 | label_return: |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1668 | malloc_mutex_unlock(&ctl_mtx); |
| 1669 | return (ret); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1670 | } |
| 1671 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1672 | CTL_RO_CGEN(config_stats, stats_cactive, &stats_cactive, size_t *) |
| 1673 | CTL_RO_CGEN(config_stats, stats_allocated, ctl_stats.allocated, size_t) |
| 1674 | CTL_RO_CGEN(config_stats, stats_active, ctl_stats.active, size_t) |
| 1675 | CTL_RO_CGEN(config_stats, stats_mapped, ctl_stats.mapped, size_t) |