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