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