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: |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 9 | * - ctl_stats->* |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 10 | */ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 11 | static malloc_mutex_t ctl_mtx; |
| 12 | static bool ctl_initialized; |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 13 | static ctl_stats_t *ctl_stats; |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 14 | static ctl_arenas_t *ctl_arenas; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 15 | |
| 16 | /******************************************************************************/ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 17 | /* Helpers for named and indexed nodes. */ |
| 18 | |
Jason Evans | af1f592 | 2014-10-30 16:38:08 -0700 | [diff] [blame] | 19 | JEMALLOC_INLINE_C const ctl_named_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 20 | ctl_named_node(const ctl_node_t *node) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 21 | return ((node->named) ? (const ctl_named_node_t *)node : NULL); |
| 22 | } |
| 23 | |
Jason Evans | af1f592 | 2014-10-30 16:38:08 -0700 | [diff] [blame] | 24 | JEMALLOC_INLINE_C const ctl_named_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 25 | ctl_named_children(const ctl_named_node_t *node, size_t index) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 26 | const ctl_named_node_t *children = ctl_named_node(node->children); |
| 27 | |
| 28 | return (children ? &children[index] : NULL); |
| 29 | } |
| 30 | |
Jason Evans | af1f592 | 2014-10-30 16:38:08 -0700 | [diff] [blame] | 31 | JEMALLOC_INLINE_C const ctl_indexed_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 32 | ctl_indexed_node(const ctl_node_t *node) { |
Jason Evans | 551ebc4 | 2014-10-03 10:16:09 -0700 | [diff] [blame] | 33 | return (!node->named ? (const ctl_indexed_node_t *)node : NULL); |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /******************************************************************************/ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 37 | /* Function prototypes for non-inline static functions. */ |
| 38 | |
| 39 | #define CTL_PROTO(n) \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 40 | static int n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, \ |
| 41 | void *oldp, size_t *oldlenp, void *newp, size_t newlen); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 42 | |
| 43 | #define INDEX_PROTO(n) \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 44 | static const ctl_named_node_t *n##_index(tsdn_t *tsdn, \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 45 | const size_t *mib, size_t miblen, size_t i); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 46 | |
Jason Evans | a40bc7a | 2010-03-02 13:01:16 -0800 | [diff] [blame] | 47 | CTL_PROTO(version) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 48 | CTL_PROTO(epoch) |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 49 | CTL_PROTO(thread_tcache_enabled) |
Jason Evans | e7b8fa1 | 2012-03-16 17:09:32 -0700 | [diff] [blame] | 50 | CTL_PROTO(thread_tcache_flush) |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 51 | CTL_PROTO(thread_prof_name) |
| 52 | CTL_PROTO(thread_prof_active) |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 53 | CTL_PROTO(thread_arena) |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 54 | CTL_PROTO(thread_allocated) |
Jason Evans | ecf229a | 2010-12-03 15:55:47 -0800 | [diff] [blame] | 55 | CTL_PROTO(thread_allocatedp) |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 56 | CTL_PROTO(thread_deallocated) |
Jason Evans | ecf229a | 2010-12-03 15:55:47 -0800 | [diff] [blame] | 57 | CTL_PROTO(thread_deallocatedp) |
Jason Evans | f2bc852 | 2015-07-17 16:38:25 -0700 | [diff] [blame] | 58 | CTL_PROTO(config_cache_oblivious) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 59 | CTL_PROTO(config_debug) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 60 | CTL_PROTO(config_fill) |
| 61 | CTL_PROTO(config_lazy_lock) |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 62 | CTL_PROTO(config_malloc_conf) |
Jason Evans | 59ae276 | 2012-04-16 17:52:27 -0700 | [diff] [blame] | 63 | CTL_PROTO(config_munmap) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 64 | CTL_PROTO(config_prof) |
| 65 | CTL_PROTO(config_prof_libgcc) |
| 66 | CTL_PROTO(config_prof_libunwind) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 67 | CTL_PROTO(config_stats) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 68 | CTL_PROTO(config_tcache) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 69 | CTL_PROTO(config_tls) |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 70 | CTL_PROTO(config_utrace) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 71 | CTL_PROTO(config_xmalloc) |
| 72 | CTL_PROTO(opt_abort) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 73 | CTL_PROTO(opt_dss) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 74 | CTL_PROTO(opt_narenas) |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 75 | CTL_PROTO(opt_decay_time) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 76 | CTL_PROTO(opt_stats_print) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 77 | CTL_PROTO(opt_junk) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 78 | CTL_PROTO(opt_zero) |
Jason Evans | b147611 | 2012-04-05 13:36:17 -0700 | [diff] [blame] | 79 | CTL_PROTO(opt_utrace) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 80 | CTL_PROTO(opt_xmalloc) |
Jason Evans | 3fa9a2f | 2010-03-07 15:34:14 -0800 | [diff] [blame] | 81 | CTL_PROTO(opt_tcache) |
Jason Evans | f3ca7c8 | 2012-04-04 16:16:09 -0700 | [diff] [blame] | 82 | CTL_PROTO(opt_lg_tcache_max) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 83 | CTL_PROTO(opt_prof) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 84 | CTL_PROTO(opt_prof_prefix) |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 85 | CTL_PROTO(opt_prof_active) |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 86 | CTL_PROTO(opt_prof_thread_active_init) |
Jason Evans | b9477e7 | 2010-03-01 20:15:26 -0800 | [diff] [blame] | 87 | CTL_PROTO(opt_lg_prof_sample) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 88 | CTL_PROTO(opt_lg_prof_interval) |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 89 | CTL_PROTO(opt_prof_gdump) |
Jason Evans | 0b25fe7 | 2012-04-17 16:39:33 -0700 | [diff] [blame] | 90 | CTL_PROTO(opt_prof_final) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 91 | CTL_PROTO(opt_prof_leak) |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 92 | CTL_PROTO(opt_prof_accum) |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 93 | CTL_PROTO(tcache_create) |
| 94 | CTL_PROTO(tcache_flush) |
| 95 | CTL_PROTO(tcache_destroy) |
Jason Evans | dc2125c | 2017-01-04 10:21:53 -0800 | [diff] [blame] | 96 | CTL_PROTO(arena_i_initialized) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 97 | CTL_PROTO(arena_i_purge) |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 98 | CTL_PROTO(arena_i_decay) |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 99 | CTL_PROTO(arena_i_reset) |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 100 | CTL_PROTO(arena_i_destroy) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 101 | CTL_PROTO(arena_i_dss) |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 102 | CTL_PROTO(arena_i_decay_time) |
Jason Evans | 9c305c9 | 2016-05-31 15:03:51 -0700 | [diff] [blame] | 103 | CTL_PROTO(arena_i_extent_hooks) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 104 | INDEX_PROTO(arena_i) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 105 | CTL_PROTO(arenas_bin_i_size) |
| 106 | CTL_PROTO(arenas_bin_i_nregs) |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 107 | CTL_PROTO(arenas_bin_i_slab_size) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 108 | INDEX_PROTO(arenas_bin_i) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 109 | CTL_PROTO(arenas_lextent_i_size) |
| 110 | INDEX_PROTO(arenas_lextent_i) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 111 | CTL_PROTO(arenas_narenas) |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 112 | CTL_PROTO(arenas_decay_time) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 113 | CTL_PROTO(arenas_quantum) |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame] | 114 | CTL_PROTO(arenas_page) |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 115 | CTL_PROTO(arenas_tcache_max) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 116 | CTL_PROTO(arenas_nbins) |
Jason Evans | dafde14 | 2010-03-17 16:27:39 -0700 | [diff] [blame] | 117 | CTL_PROTO(arenas_nhbins) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 118 | CTL_PROTO(arenas_nlextents) |
Jason Evans | 0f04bb1 | 2017-01-03 08:21:29 -0800 | [diff] [blame] | 119 | CTL_PROTO(arenas_create) |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 120 | CTL_PROTO(prof_thread_active_init) |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 121 | CTL_PROTO(prof_active) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 122 | CTL_PROTO(prof_dump) |
Jason Evans | 5b8ed5b | 2015-01-25 21:16:57 -0800 | [diff] [blame] | 123 | CTL_PROTO(prof_gdump) |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 124 | CTL_PROTO(prof_reset) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 125 | CTL_PROTO(prof_interval) |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 126 | CTL_PROTO(lg_prof_sample) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 127 | CTL_PROTO(stats_arenas_i_small_allocated) |
| 128 | CTL_PROTO(stats_arenas_i_small_nmalloc) |
| 129 | CTL_PROTO(stats_arenas_i_small_ndalloc) |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 130 | CTL_PROTO(stats_arenas_i_small_nrequests) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 131 | CTL_PROTO(stats_arenas_i_large_allocated) |
| 132 | CTL_PROTO(stats_arenas_i_large_nmalloc) |
| 133 | CTL_PROTO(stats_arenas_i_large_ndalloc) |
| 134 | CTL_PROTO(stats_arenas_i_large_nrequests) |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 135 | CTL_PROTO(stats_arenas_i_bins_j_nmalloc) |
| 136 | CTL_PROTO(stats_arenas_i_bins_j_ndalloc) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 137 | CTL_PROTO(stats_arenas_i_bins_j_nrequests) |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 138 | CTL_PROTO(stats_arenas_i_bins_j_curregs) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 139 | CTL_PROTO(stats_arenas_i_bins_j_nfills) |
| 140 | CTL_PROTO(stats_arenas_i_bins_j_nflushes) |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 141 | CTL_PROTO(stats_arenas_i_bins_j_nslabs) |
| 142 | CTL_PROTO(stats_arenas_i_bins_j_nreslabs) |
| 143 | CTL_PROTO(stats_arenas_i_bins_j_curslabs) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 144 | INDEX_PROTO(stats_arenas_i_bins_j) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 145 | CTL_PROTO(stats_arenas_i_lextents_j_nmalloc) |
| 146 | CTL_PROTO(stats_arenas_i_lextents_j_ndalloc) |
| 147 | CTL_PROTO(stats_arenas_i_lextents_j_nrequests) |
| 148 | CTL_PROTO(stats_arenas_i_lextents_j_curlextents) |
| 149 | INDEX_PROTO(stats_arenas_i_lextents_j) |
Jason Evans | 597632b | 2011-03-18 13:41:33 -0700 | [diff] [blame] | 150 | CTL_PROTO(stats_arenas_i_nthreads) |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 151 | CTL_PROTO(stats_arenas_i_dss) |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 152 | CTL_PROTO(stats_arenas_i_decay_time) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 153 | CTL_PROTO(stats_arenas_i_pactive) |
| 154 | CTL_PROTO(stats_arenas_i_pdirty) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 155 | CTL_PROTO(stats_arenas_i_mapped) |
Jason Evans | 04c3c0f | 2016-05-03 22:11:35 -0700 | [diff] [blame] | 156 | CTL_PROTO(stats_arenas_i_retained) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 157 | CTL_PROTO(stats_arenas_i_npurge) |
| 158 | CTL_PROTO(stats_arenas_i_nmadvise) |
| 159 | CTL_PROTO(stats_arenas_i_purged) |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 160 | CTL_PROTO(stats_arenas_i_base) |
| 161 | CTL_PROTO(stats_arenas_i_internal) |
Qi Wang | 58424e6 | 2016-04-22 18:37:44 -0700 | [diff] [blame] | 162 | CTL_PROTO(stats_arenas_i_tcache_bytes) |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 163 | CTL_PROTO(stats_arenas_i_resident) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 164 | INDEX_PROTO(stats_arenas_i) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 165 | CTL_PROTO(stats_allocated) |
| 166 | CTL_PROTO(stats_active) |
Jason Evans | 4581b97 | 2014-11-27 17:22:36 -0200 | [diff] [blame] | 167 | CTL_PROTO(stats_metadata) |
Jason Evans | 4acd75a | 2015-03-23 17:25:57 -0700 | [diff] [blame] | 168 | CTL_PROTO(stats_resident) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 169 | CTL_PROTO(stats_mapped) |
Jason Evans | 04c3c0f | 2016-05-03 22:11:35 -0700 | [diff] [blame] | 170 | CTL_PROTO(stats_retained) |
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 | |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 191 | static const ctl_named_node_t thread_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 | |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 196 | static const ctl_named_node_t thread_prof_node[] = { |
| 197 | {NAME("name"), CTL(thread_prof_name)}, |
| 198 | {NAME("active"), CTL(thread_prof_active)} |
| 199 | }; |
| 200 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 201 | static const ctl_named_node_t thread_node[] = { |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 202 | {NAME("arena"), CTL(thread_arena)}, |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 203 | {NAME("allocated"), CTL(thread_allocated)}, |
Jason Evans | ecf229a | 2010-12-03 15:55:47 -0800 | [diff] [blame] | 204 | {NAME("allocatedp"), CTL(thread_allocatedp)}, |
| 205 | {NAME("deallocated"), CTL(thread_deallocated)}, |
Jason Evans | e7b8fa1 | 2012-03-16 17:09:32 -0700 | [diff] [blame] | 206 | {NAME("deallocatedp"), CTL(thread_deallocatedp)}, |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 207 | {NAME("tcache"), CHILD(named, thread_tcache)}, |
| 208 | {NAME("prof"), CHILD(named, thread_prof)} |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 209 | }; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 210 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 211 | static const ctl_named_node_t config_node[] = { |
Jason Evans | f2bc852 | 2015-07-17 16:38:25 -0700 | [diff] [blame] | 212 | {NAME("cache_oblivious"), CTL(config_cache_oblivious)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 213 | {NAME("debug"), CTL(config_debug)}, |
| 214 | {NAME("fill"), CTL(config_fill)}, |
| 215 | {NAME("lazy_lock"), CTL(config_lazy_lock)}, |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 216 | {NAME("malloc_conf"), CTL(config_malloc_conf)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 217 | {NAME("munmap"), CTL(config_munmap)}, |
| 218 | {NAME("prof"), CTL(config_prof)}, |
| 219 | {NAME("prof_libgcc"), CTL(config_prof_libgcc)}, |
| 220 | {NAME("prof_libunwind"), CTL(config_prof_libunwind)}, |
| 221 | {NAME("stats"), CTL(config_stats)}, |
| 222 | {NAME("tcache"), CTL(config_tcache)}, |
| 223 | {NAME("tls"), CTL(config_tls)}, |
| 224 | {NAME("utrace"), CTL(config_utrace)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 225 | {NAME("xmalloc"), CTL(config_xmalloc)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 226 | }; |
| 227 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 228 | static const ctl_named_node_t opt_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 229 | {NAME("abort"), CTL(opt_abort)}, |
| 230 | {NAME("dss"), CTL(opt_dss)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 231 | {NAME("narenas"), CTL(opt_narenas)}, |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 232 | {NAME("decay_time"), CTL(opt_decay_time)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 233 | {NAME("stats_print"), CTL(opt_stats_print)}, |
| 234 | {NAME("junk"), CTL(opt_junk)}, |
| 235 | {NAME("zero"), CTL(opt_zero)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 236 | {NAME("utrace"), CTL(opt_utrace)}, |
| 237 | {NAME("xmalloc"), CTL(opt_xmalloc)}, |
| 238 | {NAME("tcache"), CTL(opt_tcache)}, |
| 239 | {NAME("lg_tcache_max"), CTL(opt_lg_tcache_max)}, |
| 240 | {NAME("prof"), CTL(opt_prof)}, |
| 241 | {NAME("prof_prefix"), CTL(opt_prof_prefix)}, |
| 242 | {NAME("prof_active"), CTL(opt_prof_active)}, |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 243 | {NAME("prof_thread_active_init"), CTL(opt_prof_thread_active_init)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 244 | {NAME("lg_prof_sample"), CTL(opt_lg_prof_sample)}, |
| 245 | {NAME("lg_prof_interval"), CTL(opt_lg_prof_interval)}, |
| 246 | {NAME("prof_gdump"), CTL(opt_prof_gdump)}, |
| 247 | {NAME("prof_final"), CTL(opt_prof_final)}, |
| 248 | {NAME("prof_leak"), CTL(opt_prof_leak)}, |
| 249 | {NAME("prof_accum"), CTL(opt_prof_accum)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 250 | }; |
| 251 | |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 252 | static const ctl_named_node_t tcache_node[] = { |
| 253 | {NAME("create"), CTL(tcache_create)}, |
| 254 | {NAME("flush"), CTL(tcache_flush)}, |
| 255 | {NAME("destroy"), CTL(tcache_destroy)} |
| 256 | }; |
| 257 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 258 | static const ctl_named_node_t arena_i_node[] = { |
Jason Evans | dc2125c | 2017-01-04 10:21:53 -0800 | [diff] [blame] | 259 | {NAME("initialized"), CTL(arena_i_initialized)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 260 | {NAME("purge"), CTL(arena_i_purge)}, |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 261 | {NAME("decay"), CTL(arena_i_decay)}, |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 262 | {NAME("reset"), CTL(arena_i_reset)}, |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 263 | {NAME("destroy"), CTL(arena_i_destroy)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 264 | {NAME("dss"), CTL(arena_i_dss)}, |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 265 | {NAME("decay_time"), CTL(arena_i_decay_time)}, |
Jason Evans | 9c305c9 | 2016-05-31 15:03:51 -0700 | [diff] [blame] | 266 | {NAME("extent_hooks"), CTL(arena_i_extent_hooks)} |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 267 | }; |
| 268 | static const ctl_named_node_t super_arena_i_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 269 | {NAME(""), CHILD(named, arena_i)} |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | static const ctl_indexed_node_t arena_node[] = { |
| 273 | {INDEX(arena_i)} |
| 274 | }; |
| 275 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 276 | static const ctl_named_node_t arenas_bin_i_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 277 | {NAME("size"), CTL(arenas_bin_i_size)}, |
| 278 | {NAME("nregs"), CTL(arenas_bin_i_nregs)}, |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 279 | {NAME("slab_size"), CTL(arenas_bin_i_slab_size)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 280 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 281 | static const ctl_named_node_t super_arenas_bin_i_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 282 | {NAME(""), CHILD(named, arenas_bin_i)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 283 | }; |
| 284 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 285 | static const ctl_indexed_node_t arenas_bin_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 286 | {INDEX(arenas_bin_i)} |
| 287 | }; |
| 288 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 289 | static const ctl_named_node_t arenas_lextent_i_node[] = { |
| 290 | {NAME("size"), CTL(arenas_lextent_i_size)} |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 291 | }; |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 292 | static const ctl_named_node_t super_arenas_lextent_i_node[] = { |
| 293 | {NAME(""), CHILD(named, arenas_lextent_i)} |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 296 | static const ctl_indexed_node_t arenas_lextent_node[] = { |
| 297 | {INDEX(arenas_lextent_i)} |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 298 | }; |
| 299 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 300 | static const ctl_named_node_t arenas_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 301 | {NAME("narenas"), CTL(arenas_narenas)}, |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 302 | {NAME("decay_time"), CTL(arenas_decay_time)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 303 | {NAME("quantum"), CTL(arenas_quantum)}, |
| 304 | {NAME("page"), CTL(arenas_page)}, |
| 305 | {NAME("tcache_max"), CTL(arenas_tcache_max)}, |
| 306 | {NAME("nbins"), CTL(arenas_nbins)}, |
| 307 | {NAME("nhbins"), CTL(arenas_nhbins)}, |
| 308 | {NAME("bin"), CHILD(indexed, arenas_bin)}, |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 309 | {NAME("nlextents"), CTL(arenas_nlextents)}, |
| 310 | {NAME("lextent"), CHILD(indexed, arenas_lextent)}, |
Jason Evans | 0f04bb1 | 2017-01-03 08:21:29 -0800 | [diff] [blame] | 311 | {NAME("create"), CTL(arenas_create)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 312 | }; |
| 313 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 314 | static const ctl_named_node_t prof_node[] = { |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 315 | {NAME("thread_active_init"), CTL(prof_thread_active_init)}, |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 316 | {NAME("active"), CTL(prof_active)}, |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 317 | {NAME("dump"), CTL(prof_dump)}, |
Jason Evans | 5b8ed5b | 2015-01-25 21:16:57 -0800 | [diff] [blame] | 318 | {NAME("gdump"), CTL(prof_gdump)}, |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 319 | {NAME("reset"), CTL(prof_reset)}, |
| 320 | {NAME("interval"), CTL(prof_interval)}, |
| 321 | {NAME("lg_sample"), CTL(lg_prof_sample)} |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 322 | }; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 323 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 324 | static const ctl_named_node_t stats_arenas_i_small_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 325 | {NAME("allocated"), CTL(stats_arenas_i_small_allocated)}, |
| 326 | {NAME("nmalloc"), CTL(stats_arenas_i_small_nmalloc)}, |
| 327 | {NAME("ndalloc"), CTL(stats_arenas_i_small_ndalloc)}, |
| 328 | {NAME("nrequests"), CTL(stats_arenas_i_small_nrequests)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 329 | }; |
| 330 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 331 | static const ctl_named_node_t stats_arenas_i_large_node[] = { |
| 332 | {NAME("allocated"), CTL(stats_arenas_i_large_allocated)}, |
| 333 | {NAME("nmalloc"), CTL(stats_arenas_i_large_nmalloc)}, |
| 334 | {NAME("ndalloc"), CTL(stats_arenas_i_large_ndalloc)}, |
| 335 | {NAME("nrequests"), CTL(stats_arenas_i_large_nrequests)} |
Jason Evans | e2deab7 | 2014-05-15 22:22:27 -0700 | [diff] [blame] | 336 | }; |
| 337 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 338 | static const ctl_named_node_t stats_arenas_i_bins_j_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 339 | {NAME("nmalloc"), CTL(stats_arenas_i_bins_j_nmalloc)}, |
| 340 | {NAME("ndalloc"), CTL(stats_arenas_i_bins_j_ndalloc)}, |
| 341 | {NAME("nrequests"), CTL(stats_arenas_i_bins_j_nrequests)}, |
| 342 | {NAME("curregs"), CTL(stats_arenas_i_bins_j_curregs)}, |
| 343 | {NAME("nfills"), CTL(stats_arenas_i_bins_j_nfills)}, |
| 344 | {NAME("nflushes"), CTL(stats_arenas_i_bins_j_nflushes)}, |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 345 | {NAME("nslabs"), CTL(stats_arenas_i_bins_j_nslabs)}, |
| 346 | {NAME("nreslabs"), CTL(stats_arenas_i_bins_j_nreslabs)}, |
| 347 | {NAME("curslabs"), CTL(stats_arenas_i_bins_j_curslabs)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 348 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 349 | static const ctl_named_node_t super_stats_arenas_i_bins_j_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 350 | {NAME(""), CHILD(named, stats_arenas_i_bins_j)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 351 | }; |
| 352 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 353 | static const ctl_indexed_node_t stats_arenas_i_bins_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 354 | {INDEX(stats_arenas_i_bins_j)} |
| 355 | }; |
| 356 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 357 | static const ctl_named_node_t stats_arenas_i_lextents_j_node[] = { |
| 358 | {NAME("nmalloc"), CTL(stats_arenas_i_lextents_j_nmalloc)}, |
| 359 | {NAME("ndalloc"), CTL(stats_arenas_i_lextents_j_ndalloc)}, |
| 360 | {NAME("nrequests"), CTL(stats_arenas_i_lextents_j_nrequests)}, |
| 361 | {NAME("curlextents"), CTL(stats_arenas_i_lextents_j_curlextents)} |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 362 | }; |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 363 | static const ctl_named_node_t super_stats_arenas_i_lextents_j_node[] = { |
| 364 | {NAME(""), CHILD(named, stats_arenas_i_lextents_j)} |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 365 | }; |
| 366 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 367 | static const ctl_indexed_node_t stats_arenas_i_lextents_node[] = { |
| 368 | {INDEX(stats_arenas_i_lextents_j)} |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 369 | }; |
| 370 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 371 | static const ctl_named_node_t stats_arenas_i_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 372 | {NAME("nthreads"), CTL(stats_arenas_i_nthreads)}, |
| 373 | {NAME("dss"), CTL(stats_arenas_i_dss)}, |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 374 | {NAME("decay_time"), CTL(stats_arenas_i_decay_time)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 375 | {NAME("pactive"), CTL(stats_arenas_i_pactive)}, |
| 376 | {NAME("pdirty"), CTL(stats_arenas_i_pdirty)}, |
| 377 | {NAME("mapped"), CTL(stats_arenas_i_mapped)}, |
Jason Evans | 04c3c0f | 2016-05-03 22:11:35 -0700 | [diff] [blame] | 378 | {NAME("retained"), CTL(stats_arenas_i_retained)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 379 | {NAME("npurge"), CTL(stats_arenas_i_npurge)}, |
| 380 | {NAME("nmadvise"), CTL(stats_arenas_i_nmadvise)}, |
| 381 | {NAME("purged"), CTL(stats_arenas_i_purged)}, |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 382 | {NAME("base"), CTL(stats_arenas_i_base)}, |
| 383 | {NAME("internal"), CTL(stats_arenas_i_internal)}, |
Qi Wang | 58424e6 | 2016-04-22 18:37:44 -0700 | [diff] [blame] | 384 | {NAME("tcache_bytes"), CTL(stats_arenas_i_tcache_bytes)}, |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 385 | {NAME("resident"), CTL(stats_arenas_i_resident)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 386 | {NAME("small"), CHILD(named, stats_arenas_i_small)}, |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 387 | {NAME("large"), CHILD(named, stats_arenas_i_large)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 388 | {NAME("bins"), CHILD(indexed, stats_arenas_i_bins)}, |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 389 | {NAME("lextents"), CHILD(indexed, stats_arenas_i_lextents)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 390 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 391 | static const ctl_named_node_t super_stats_arenas_i_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 392 | {NAME(""), CHILD(named, stats_arenas_i)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 393 | }; |
| 394 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 395 | static const ctl_indexed_node_t stats_arenas_node[] = { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 396 | {INDEX(stats_arenas_i)} |
| 397 | }; |
| 398 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 399 | static const ctl_named_node_t stats_node[] = { |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 400 | {NAME("allocated"), CTL(stats_allocated)}, |
| 401 | {NAME("active"), CTL(stats_active)}, |
Jason Evans | 4581b97 | 2014-11-27 17:22:36 -0200 | [diff] [blame] | 402 | {NAME("metadata"), CTL(stats_metadata)}, |
Jason Evans | 4acd75a | 2015-03-23 17:25:57 -0700 | [diff] [blame] | 403 | {NAME("resident"), CTL(stats_resident)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 404 | {NAME("mapped"), CTL(stats_mapped)}, |
Jason Evans | 04c3c0f | 2016-05-03 22:11:35 -0700 | [diff] [blame] | 405 | {NAME("retained"), CTL(stats_retained)}, |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 406 | {NAME("arenas"), CHILD(indexed, stats_arenas)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 407 | }; |
| 408 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 409 | static const ctl_named_node_t root_node[] = { |
Jason Evans | a40bc7a | 2010-03-02 13:01:16 -0800 | [diff] [blame] | 410 | {NAME("version"), CTL(version)}, |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 411 | {NAME("epoch"), CTL(epoch)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 412 | {NAME("thread"), CHILD(named, thread)}, |
| 413 | {NAME("config"), CHILD(named, config)}, |
| 414 | {NAME("opt"), CHILD(named, opt)}, |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 415 | {NAME("tcache"), CHILD(named, tcache)}, |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 416 | {NAME("arena"), CHILD(indexed, arena)}, |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 417 | {NAME("arenas"), CHILD(named, arenas)}, |
| 418 | {NAME("prof"), CHILD(named, prof)}, |
| 419 | {NAME("stats"), CHILD(named, stats)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 420 | }; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 421 | static const ctl_named_node_t super_root_node[] = { |
Jason Evans | 65f343a | 2012-04-23 19:31:45 -0700 | [diff] [blame] | 422 | {NAME(""), CHILD(named, root)} |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | #undef NAME |
| 426 | #undef CHILD |
| 427 | #undef CTL |
| 428 | #undef INDEX |
| 429 | |
| 430 | /******************************************************************************/ |
| 431 | |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 432 | static unsigned |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 433 | arenas_i2a_impl(size_t i, bool compat, bool validate) { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 434 | unsigned a; |
| 435 | |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 436 | switch (i) { |
| 437 | case MALLCTL_ARENAS_ALL: |
| 438 | a = 0; |
| 439 | break; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 440 | case MALLCTL_ARENAS_DESTROYED: |
| 441 | a = 1; |
| 442 | break; |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 443 | default: |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 444 | if (compat && i == ctl_arenas->narenas) { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 445 | /* |
| 446 | * Provide deprecated backward compatibility for |
| 447 | * accessing the merged stats at index narenas rather |
| 448 | * than via MALLCTL_ARENAS_ALL. This is scheduled for |
| 449 | * removal in 6.0.0. |
| 450 | */ |
| 451 | a = 0; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 452 | } else if (validate && i >= ctl_arenas->narenas) { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 453 | a = UINT_MAX; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 454 | } else { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 455 | /* |
| 456 | * This function should never be called for an index |
| 457 | * more than one past the range of indices that have |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 458 | * initialized ctl data. |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 459 | */ |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 460 | assert(i < ctl_arenas->narenas || (!validate && i == |
| 461 | ctl_arenas->narenas)); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 462 | a = (unsigned)i + 2; |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 463 | } |
| 464 | break; |
| 465 | } |
| 466 | |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 467 | return a; |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 470 | static unsigned |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 471 | arenas_i2a(size_t i) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 472 | return arenas_i2a_impl(i, true, false); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 475 | static ctl_arena_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 476 | arenas_i_impl(tsdn_t *tsdn, size_t i, bool compat, bool init) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 477 | ctl_arena_t *ret; |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 478 | |
| 479 | assert(!compat || !init); |
| 480 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 481 | ret = ctl_arenas->arenas[arenas_i2a_impl(i, compat, false)]; |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 482 | if (init && ret == NULL) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 483 | if (config_stats) { |
| 484 | struct container_s { |
| 485 | ctl_arena_t ctl_arena; |
| 486 | ctl_arena_stats_t astats; |
| 487 | }; |
| 488 | struct container_s *cont = |
| 489 | (struct container_s *)base_alloc(tsdn, b0get(), |
| 490 | sizeof(struct container_s), QUANTUM); |
| 491 | if (cont == NULL) { |
| 492 | return NULL; |
| 493 | } |
| 494 | ret = &cont->ctl_arena; |
| 495 | ret->astats = &cont->astats; |
| 496 | } else { |
| 497 | ret = (ctl_arena_t *)base_alloc(tsdn, b0get(), |
| 498 | sizeof(ctl_arena_t), QUANTUM); |
| 499 | if (ret == NULL) { |
| 500 | return NULL; |
| 501 | } |
| 502 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 503 | ret->arena_ind = (unsigned)i; |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 504 | ctl_arenas->arenas[arenas_i2a_impl(i, compat, false)] = ret; |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 505 | } |
| 506 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 507 | assert(ret == NULL || arenas_i2a(ret->arena_ind) == arenas_i2a(i)); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 508 | return ret; |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 511 | static ctl_arena_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 512 | arenas_i(size_t i) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 513 | ctl_arena_t *ret = arenas_i_impl(TSDN_NULL, i, true, false); |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 514 | assert(ret != NULL); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 515 | return ret; |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 518 | static void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 519 | ctl_arena_clear(ctl_arena_t *ctl_arena) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 520 | ctl_arena->nthreads = 0; |
| 521 | ctl_arena->dss = dss_prec_names[dss_prec_limit]; |
| 522 | ctl_arena->decay_time = -1; |
| 523 | ctl_arena->pactive = 0; |
| 524 | ctl_arena->pdirty = 0; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 525 | if (config_stats) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 526 | memset(&ctl_arena->astats->astats, 0, sizeof(arena_stats_t)); |
| 527 | ctl_arena->astats->allocated_small = 0; |
| 528 | ctl_arena->astats->nmalloc_small = 0; |
| 529 | ctl_arena->astats->ndalloc_small = 0; |
| 530 | ctl_arena->astats->nrequests_small = 0; |
| 531 | memset(ctl_arena->astats->bstats, 0, NBINS * |
| 532 | sizeof(malloc_bin_stats_t)); |
| 533 | memset(ctl_arena->astats->lstats, 0, (NSIZES - NBINS) * |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 534 | sizeof(malloc_large_stats_t)); |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 535 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 538 | static void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 539 | ctl_arena_stats_amerge(tsdn_t *tsdn, ctl_arena_t *ctl_arena, arena_t *arena) { |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 540 | unsigned i; |
| 541 | |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 542 | if (config_stats) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 543 | arena_stats_merge(tsdn, arena, &ctl_arena->nthreads, |
| 544 | &ctl_arena->dss, &ctl_arena->decay_time, |
| 545 | &ctl_arena->pactive, &ctl_arena->pdirty, |
| 546 | &ctl_arena->astats->astats, ctl_arena->astats->bstats, |
| 547 | ctl_arena->astats->lstats); |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 548 | |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 549 | for (i = 0; i < NBINS; i++) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 550 | ctl_arena->astats->allocated_small += |
| 551 | ctl_arena->astats->bstats[i].curregs * |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 552 | index2size(i); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 553 | ctl_arena->astats->nmalloc_small += |
| 554 | ctl_arena->astats->bstats[i].nmalloc; |
| 555 | ctl_arena->astats->ndalloc_small += |
| 556 | ctl_arena->astats->bstats[i].ndalloc; |
| 557 | ctl_arena->astats->nrequests_small += |
| 558 | ctl_arena->astats->bstats[i].nrequests; |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 559 | } |
| 560 | } else { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 561 | arena_basic_stats_merge(tsdn, arena, &ctl_arena->nthreads, |
| 562 | &ctl_arena->dss, &ctl_arena->decay_time, |
| 563 | &ctl_arena->pactive, &ctl_arena->pdirty); |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 564 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 568 | ctl_arena_stats_sdmerge(ctl_arena_t *ctl_sdarena, ctl_arena_t *ctl_arena, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 569 | bool destroyed) { |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 570 | unsigned i; |
| 571 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 572 | if (!destroyed) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 573 | ctl_sdarena->nthreads += ctl_arena->nthreads; |
| 574 | ctl_sdarena->pactive += ctl_arena->pactive; |
| 575 | ctl_sdarena->pdirty += ctl_arena->pdirty; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 576 | } else { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 577 | assert(ctl_arena->nthreads == 0); |
| 578 | assert(ctl_arena->pactive == 0); |
| 579 | assert(ctl_arena->pdirty == 0); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 580 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 581 | |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 582 | if (config_stats) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 583 | ctl_arena_stats_t *sdstats = ctl_sdarena->astats; |
| 584 | ctl_arena_stats_t *astats = ctl_arena->astats; |
| 585 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 586 | if (!destroyed) { |
| 587 | sdstats->astats.mapped += astats->astats.mapped; |
| 588 | sdstats->astats.retained += astats->astats.retained; |
| 589 | } |
| 590 | sdstats->astats.npurge += astats->astats.npurge; |
| 591 | sdstats->astats.nmadvise += astats->astats.nmadvise; |
| 592 | sdstats->astats.purged += astats->astats.purged; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 593 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 594 | if (!destroyed) { |
| 595 | sdstats->astats.base += astats->astats.base; |
| 596 | sdstats->astats.internal += astats->astats.internal; |
| 597 | sdstats->astats.resident += astats->astats.resident; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 598 | } else { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 599 | assert(astats->astats.internal == 0); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 600 | } |
Jason Evans | 4581b97 | 2014-11-27 17:22:36 -0200 | [diff] [blame] | 601 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 602 | if (!destroyed) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 603 | sdstats->allocated_small += astats->allocated_small; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 604 | } else { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 605 | assert(astats->allocated_small == 0); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 606 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 607 | sdstats->nmalloc_small += astats->nmalloc_small; |
| 608 | sdstats->ndalloc_small += astats->ndalloc_small; |
| 609 | sdstats->nrequests_small += astats->nrequests_small; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 610 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 611 | if (!destroyed) { |
| 612 | sdstats->astats.allocated_large += |
| 613 | astats->astats.allocated_large; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 614 | } else { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 615 | assert(astats->astats.allocated_large == 0); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 616 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 617 | sdstats->astats.nmalloc_large += astats->astats.nmalloc_large; |
| 618 | sdstats->astats.ndalloc_large += astats->astats.ndalloc_large; |
| 619 | sdstats->astats.nrequests_large += |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 620 | astats->astats.nrequests_large; |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 621 | |
Qi Wang | 58424e6 | 2016-04-22 18:37:44 -0700 | [diff] [blame] | 622 | if (config_tcache) { |
| 623 | sdstats->astats.tcache_bytes += |
| 624 | astats->astats.tcache_bytes; |
| 625 | } |
| 626 | |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 627 | for (i = 0; i < NBINS; i++) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 628 | sdstats->bstats[i].nmalloc += astats->bstats[i].nmalloc; |
| 629 | sdstats->bstats[i].ndalloc += astats->bstats[i].ndalloc; |
| 630 | sdstats->bstats[i].nrequests += |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 631 | astats->bstats[i].nrequests; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 632 | if (!destroyed) { |
| 633 | sdstats->bstats[i].curregs += |
| 634 | astats->bstats[i].curregs; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 635 | } else { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 636 | assert(astats->bstats[i].curregs == 0); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 637 | } |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 638 | if (config_tcache) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 639 | sdstats->bstats[i].nfills += |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 640 | astats->bstats[i].nfills; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 641 | sdstats->bstats[i].nflushes += |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 642 | astats->bstats[i].nflushes; |
| 643 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 644 | sdstats->bstats[i].nslabs += astats->bstats[i].nslabs; |
| 645 | sdstats->bstats[i].reslabs += astats->bstats[i].reslabs; |
| 646 | if (!destroyed) { |
| 647 | sdstats->bstats[i].curslabs += |
| 648 | astats->bstats[i].curslabs; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 649 | } else { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 650 | assert(astats->bstats[i].curslabs == 0); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 651 | } |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 652 | } |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 653 | |
Jason Evans | ed2c242 | 2016-05-28 00:17:28 -0700 | [diff] [blame] | 654 | for (i = 0; i < NSIZES - NBINS; i++) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 655 | sdstats->lstats[i].nmalloc += astats->lstats[i].nmalloc; |
| 656 | sdstats->lstats[i].ndalloc += astats->lstats[i].ndalloc; |
| 657 | sdstats->lstats[i].nrequests += |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 658 | astats->lstats[i].nrequests; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 659 | if (!destroyed) { |
| 660 | sdstats->lstats[i].curlextents += |
| 661 | astats->lstats[i].curlextents; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 662 | } else { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 663 | assert(astats->lstats[i].curlextents == 0); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 664 | } |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 665 | } |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 666 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 667 | } |
Jason Evans | 86815df | 2010-03-13 20:32:56 -0800 | [diff] [blame] | 668 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 669 | static void |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 670 | ctl_arena_refresh(tsdn_t *tsdn, arena_t *arena, ctl_arena_t *ctl_sdarena, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 671 | unsigned i, bool destroyed) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 672 | ctl_arena_t *ctl_arena = arenas_i(i); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 673 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 674 | ctl_arena_clear(ctl_arena); |
| 675 | ctl_arena_stats_amerge(tsdn, ctl_arena, arena); |
Jason Evans | 3c07f80 | 2016-02-27 20:40:13 -0800 | [diff] [blame] | 676 | /* Merge into sum stats as well. */ |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 677 | ctl_arena_stats_sdmerge(ctl_sdarena, ctl_arena, destroyed); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 678 | } |
| 679 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 680 | static unsigned |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 681 | ctl_arena_init(tsdn_t *tsdn, extent_hooks_t *extent_hooks) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 682 | unsigned arena_ind; |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 683 | ctl_arena_t *ctl_arena; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 684 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 685 | if ((ctl_arena = ql_last(&ctl_arenas->destroyed, destroyed_link)) != |
| 686 | NULL) { |
| 687 | ql_remove(&ctl_arenas->destroyed, ctl_arena, destroyed_link); |
| 688 | arena_ind = ctl_arena->arena_ind; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 689 | } else { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 690 | arena_ind = ctl_arenas->narenas; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 691 | } |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 692 | |
| 693 | /* Trigger stats allocation. */ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 694 | if (arenas_i_impl(tsdn, arena_ind, false, true) == NULL) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 695 | return UINT_MAX; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 696 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 697 | |
Jason Evans | 8bb3198 | 2014-10-07 23:14:57 -0700 | [diff] [blame] | 698 | /* Initialize new arena. */ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 699 | if (arena_init(tsdn, arena_ind, extent_hooks) == NULL) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 700 | return UINT_MAX; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 701 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 702 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 703 | if (arena_ind == ctl_arenas->narenas) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 704 | ctl_arenas->narenas++; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 705 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 706 | |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 707 | return arena_ind; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 710 | static void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 711 | ctl_refresh(tsdn_t *tsdn) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 712 | unsigned i; |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 713 | ctl_arena_t *ctl_sarena = arenas_i(MALLCTL_ARENAS_ALL); |
| 714 | VARIABLE_ARRAY(arena_t *, tarenas, ctl_arenas->narenas); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 715 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 716 | /* |
Jason Evans | 1366826 | 2010-01-31 03:57:29 -0800 | [diff] [blame] | 717 | * Clear sum stats, since they will be merged into by |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 718 | * ctl_arena_refresh(). |
| 719 | */ |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 720 | ctl_arena_clear(ctl_sarena); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 721 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 722 | for (i = 0; i < ctl_arenas->narenas; i++) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 723 | tarenas[i] = arena_get(tsdn, i, false); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 724 | } |
Jason Evans | 8bb3198 | 2014-10-07 23:14:57 -0700 | [diff] [blame] | 725 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 726 | for (i = 0; i < ctl_arenas->narenas; i++) { |
| 727 | ctl_arena_t *ctl_arena = arenas_i(i); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 728 | bool initialized = (tarenas[i] != NULL); |
| 729 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 730 | ctl_arena->initialized = initialized; |
| 731 | if (initialized) { |
| 732 | ctl_arena_refresh(tsdn, tarenas[i], ctl_sarena, i, |
| 733 | false); |
| 734 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 735 | } |
| 736 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 737 | if (config_stats) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 738 | ctl_stats->allocated = ctl_sarena->astats->allocated_small + |
| 739 | ctl_sarena->astats->astats.allocated_large; |
| 740 | ctl_stats->active = (ctl_sarena->pactive << LG_PAGE); |
| 741 | ctl_stats->metadata = ctl_sarena->astats->astats.base + |
| 742 | ctl_sarena->astats->astats.internal; |
| 743 | ctl_stats->resident = ctl_sarena->astats->astats.resident; |
| 744 | ctl_stats->mapped = ctl_sarena->astats->astats.mapped; |
| 745 | ctl_stats->retained = ctl_sarena->astats->astats.retained; |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 746 | } |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 747 | ctl_arenas->epoch++; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | static bool |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 751 | ctl_init(tsdn_t *tsdn) { |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 752 | bool ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 753 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 754 | malloc_mutex_lock(tsdn, &ctl_mtx); |
Jason Evans | 551ebc4 | 2014-10-03 10:16:09 -0700 | [diff] [blame] | 755 | if (!ctl_initialized) { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 756 | ctl_arena_t *ctl_sarena, *ctl_darena; |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 757 | unsigned i; |
| 758 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 759 | /* |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 760 | * Allocate demand-zeroed space for pointers to the full |
| 761 | * range of supported arena indices. |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 762 | */ |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 763 | if (ctl_arenas == NULL) { |
| 764 | ctl_arenas = (ctl_arenas_t *)base_alloc(tsdn, |
| 765 | b0get(), sizeof(ctl_arenas_t), QUANTUM); |
| 766 | if (ctl_arenas == NULL) { |
| 767 | ret = true; |
| 768 | goto label_return; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | if (config_stats && ctl_stats == NULL) { |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 773 | ctl_stats = (ctl_stats_t *)base_alloc(tsdn, b0get(), |
| 774 | sizeof(ctl_stats_t), QUANTUM); |
| 775 | if (ctl_stats == NULL) { |
| 776 | ret = true; |
| 777 | goto label_return; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /* |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 782 | * Allocate space for the current full range of arenas |
| 783 | * here rather than doing it lazily elsewhere, in order |
| 784 | * to limit when OOM-caused errors can occur. |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 785 | */ |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 786 | if ((ctl_sarena = arenas_i_impl(tsdn, MALLCTL_ARENAS_ALL, false, |
| 787 | true)) == NULL) { |
| 788 | ret = true; |
| 789 | goto label_return; |
| 790 | } |
| 791 | ctl_sarena->initialized = true; |
| 792 | |
| 793 | if ((ctl_darena = arenas_i_impl(tsdn, MALLCTL_ARENAS_DESTROYED, |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 794 | false, true)) == NULL) { |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 795 | ret = true; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 796 | goto label_return; |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 797 | } |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 798 | ctl_arena_clear(ctl_darena); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 799 | /* |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 800 | * Don't toggle ctl_darena to initialized until an arena is |
| 801 | * actually destroyed, so that arena.<i>.initialized can be used |
| 802 | * to query whether the stats are relevant. |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 803 | */ |
| 804 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 805 | ctl_arenas->narenas = narenas_total_get(); |
| 806 | for (i = 0; i < ctl_arenas->narenas; i++) { |
| 807 | if (arenas_i_impl(tsdn, i, false, true) == NULL) { |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 808 | ret = true; |
| 809 | goto label_return; |
| 810 | } |
| 811 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 812 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 813 | ql_new(&ctl_arenas->destroyed); |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 814 | ctl_refresh(tsdn); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 815 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 816 | ctl_initialized = true; |
| 817 | } |
| 818 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 819 | ret = false; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 820 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 821 | malloc_mutex_unlock(tsdn, &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 822 | return ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | static int |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 826 | ctl_lookup(tsdn_t *tsdn, const char *name, ctl_node_t const **nodesp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 827 | size_t *mibp, size_t *depthp) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 828 | int ret; |
| 829 | const char *elm, *tdot, *dot; |
| 830 | size_t elen, i, j; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 831 | const ctl_named_node_t *node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 832 | |
| 833 | elm = name; |
| 834 | /* Equivalent to strchrnul(). */ |
| 835 | dot = ((tdot = strchr(elm, '.')) != NULL) ? tdot : strchr(elm, '\0'); |
| 836 | elen = (size_t)((uintptr_t)dot - (uintptr_t)elm); |
| 837 | if (elen == 0) { |
| 838 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 839 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 840 | } |
| 841 | node = super_root_node; |
| 842 | for (i = 0; i < *depthp; i++) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 843 | assert(node); |
| 844 | assert(node->nchildren > 0); |
| 845 | if (ctl_named_node(node->children) != NULL) { |
| 846 | const ctl_named_node_t *pnode = node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 847 | |
| 848 | /* Children are named. */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 849 | for (j = 0; j < node->nchildren; j++) { |
| 850 | const ctl_named_node_t *child = |
| 851 | ctl_named_children(node, j); |
| 852 | if (strlen(child->name) == elen && |
| 853 | strncmp(elm, child->name, elen) == 0) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 854 | node = child; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 855 | if (nodesp != NULL) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 856 | nodesp[i] = |
| 857 | (const ctl_node_t *)node; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 858 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 859 | mibp[i] = j; |
| 860 | break; |
| 861 | } |
| 862 | } |
| 863 | if (node == pnode) { |
| 864 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 865 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 866 | } |
| 867 | } else { |
Jason Evans | 41b6afb | 2012-02-02 22:04:57 -0800 | [diff] [blame] | 868 | uintmax_t index; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 869 | const ctl_indexed_node_t *inode; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 870 | |
| 871 | /* Children are indexed. */ |
Jason Evans | 41b6afb | 2012-02-02 22:04:57 -0800 | [diff] [blame] | 872 | index = malloc_strtoumax(elm, NULL, 10); |
| 873 | if (index == UINTMAX_MAX || index > SIZE_T_MAX) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 874 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 875 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 876 | } |
| 877 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 878 | inode = ctl_indexed_node(node->children); |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 879 | node = inode->index(tsdn, mibp, *depthp, (size_t)index); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 880 | if (node == NULL) { |
| 881 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 882 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 885 | if (nodesp != NULL) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 886 | nodesp[i] = (const ctl_node_t *)node; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 887 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 888 | mibp[i] = (size_t)index; |
| 889 | } |
| 890 | |
| 891 | if (node->ctl != NULL) { |
| 892 | /* Terminal node. */ |
| 893 | if (*dot != '\0') { |
| 894 | /* |
| 895 | * The name contains more elements than are |
| 896 | * in this path through the tree. |
| 897 | */ |
| 898 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 899 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 900 | } |
| 901 | /* Complete lookup successful. */ |
| 902 | *depthp = i + 1; |
| 903 | break; |
| 904 | } |
| 905 | |
| 906 | /* Update elm. */ |
| 907 | if (*dot == '\0') { |
| 908 | /* No more elements. */ |
| 909 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 910 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 911 | } |
| 912 | elm = &dot[1]; |
| 913 | dot = ((tdot = strchr(elm, '.')) != NULL) ? tdot : |
| 914 | strchr(elm, '\0'); |
| 915 | elen = (size_t)((uintptr_t)dot - (uintptr_t)elm); |
| 916 | } |
| 917 | |
| 918 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 919 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 920 | return ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 924 | ctl_byname(tsd_t *tsd, const char *name, void *oldp, size_t *oldlenp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 925 | void *newp, size_t newlen) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 926 | int ret; |
| 927 | size_t depth; |
| 928 | ctl_node_t const *nodes[CTL_MAX_DEPTH]; |
| 929 | size_t mib[CTL_MAX_DEPTH]; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 930 | const ctl_named_node_t *node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 931 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 932 | if (!ctl_initialized && ctl_init(tsd_tsdn(tsd))) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 933 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 934 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | depth = CTL_MAX_DEPTH; |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 938 | ret = ctl_lookup(tsd_tsdn(tsd), name, nodes, mib, &depth); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 939 | if (ret != 0) { |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 940 | goto label_return; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 941 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 942 | |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 943 | node = ctl_named_node(nodes[depth-1]); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 944 | if (node != NULL && node->ctl) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 945 | ret = node->ctl(tsd, mib, depth, oldp, oldlenp, newp, newlen); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 946 | } |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 947 | else { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 948 | /* The name refers to a partial path through the ctl tree. */ |
| 949 | ret = ENOENT; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 950 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 951 | |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 952 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 953 | return(ret); |
| 954 | } |
| 955 | |
| 956 | int |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 957 | ctl_nametomib(tsdn_t *tsdn, const char *name, size_t *mibp, size_t *miblenp) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 958 | int ret; |
| 959 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 960 | if (!ctl_initialized && ctl_init(tsdn)) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 961 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 962 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 965 | ret = ctl_lookup(tsdn, name, NULL, mibp, miblenp); |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 966 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 967 | return(ret); |
| 968 | } |
| 969 | |
| 970 | int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 971 | ctl_bymib(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 972 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 973 | int ret; |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 974 | const ctl_named_node_t *node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 975 | size_t i; |
| 976 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 977 | if (!ctl_initialized && ctl_init(tsd_tsdn(tsd))) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 978 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 979 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | /* Iterate down the tree. */ |
| 983 | node = super_root_node; |
| 984 | for (i = 0; i < miblen; i++) { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 985 | assert(node); |
| 986 | assert(node->nchildren > 0); |
| 987 | if (ctl_named_node(node->children) != NULL) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 988 | /* Children are named. */ |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 989 | if (node->nchildren <= mib[i]) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 990 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 991 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 992 | } |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 993 | node = ctl_named_children(node, mib[i]); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 994 | } else { |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 995 | const ctl_indexed_node_t *inode; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 996 | |
| 997 | /* Indexed element. */ |
Mike Hommey | 461ad5c | 2012-04-20 08:38:42 +0200 | [diff] [blame] | 998 | inode = ctl_indexed_node(node->children); |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 999 | node = inode->index(tsd_tsdn(tsd), mib, miblen, mib[i]); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1000 | if (node == NULL) { |
| 1001 | ret = ENOENT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1002 | goto label_return; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | /* Call the ctl function. */ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1008 | if (node && node->ctl) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1009 | ret = node->ctl(tsd, mib, miblen, oldp, oldlenp, newp, newlen); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1010 | } else { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1011 | /* Partial MIB. */ |
| 1012 | ret = ENOENT; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1013 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1014 | |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1015 | label_return: |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1016 | return(ret); |
| 1017 | } |
| 1018 | |
| 1019 | bool |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1020 | ctl_boot(void) { |
| 1021 | if (malloc_mutex_init(&ctl_mtx, "ctl", WITNESS_RANK_CTL)) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1022 | return true; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1023 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1024 | |
| 1025 | ctl_initialized = false; |
| 1026 | |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1027 | return false; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
Jason Evans | 20f1fc9 | 2012-10-09 14:46:22 -0700 | [diff] [blame] | 1030 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1031 | ctl_prefork(tsdn_t *tsdn) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1032 | malloc_mutex_prefork(tsdn, &ctl_mtx); |
Jason Evans | 20f1fc9 | 2012-10-09 14:46:22 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1036 | ctl_postfork_parent(tsdn_t *tsdn) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1037 | malloc_mutex_postfork_parent(tsdn, &ctl_mtx); |
Jason Evans | 20f1fc9 | 2012-10-09 14:46:22 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1041 | ctl_postfork_child(tsdn_t *tsdn) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1042 | malloc_mutex_postfork_child(tsdn, &ctl_mtx); |
Jason Evans | 20f1fc9 | 2012-10-09 14:46:22 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1045 | /******************************************************************************/ |
| 1046 | /* *_ctl() functions. */ |
| 1047 | |
| 1048 | #define READONLY() do { \ |
| 1049 | if (newp != NULL || newlen != 0) { \ |
| 1050 | ret = EPERM; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1051 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1052 | } \ |
| 1053 | } while (0) |
| 1054 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 1055 | #define WRITEONLY() do { \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1056 | if (oldp != NULL || oldlenp != NULL) { \ |
| 1057 | ret = EPERM; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1058 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1059 | } \ |
| 1060 | } while (0) |
| 1061 | |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 1062 | #define READ_XOR_WRITE() do { \ |
| 1063 | if ((oldp != NULL && oldlenp != NULL) && (newp != NULL || \ |
| 1064 | newlen != 0)) { \ |
| 1065 | ret = EPERM; \ |
| 1066 | goto label_return; \ |
| 1067 | } \ |
| 1068 | } while (0) |
| 1069 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1070 | #define READ(v, t) do { \ |
| 1071 | if (oldp != NULL && oldlenp != NULL) { \ |
| 1072 | if (*oldlenp != sizeof(t)) { \ |
| 1073 | size_t copylen = (sizeof(t) <= *oldlenp) \ |
| 1074 | ? sizeof(t) : *oldlenp; \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1075 | memcpy(oldp, (void *)&(v), copylen); \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1076 | ret = EINVAL; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1077 | goto label_return; \ |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1078 | } \ |
| 1079 | *(t *)oldp = (v); \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1080 | } \ |
| 1081 | } while (0) |
| 1082 | |
| 1083 | #define WRITE(v, t) do { \ |
| 1084 | if (newp != NULL) { \ |
| 1085 | if (newlen != sizeof(t)) { \ |
| 1086 | ret = EINVAL; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1087 | goto label_return; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1088 | } \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1089 | (v) = *(t *)newp; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1090 | } \ |
| 1091 | } while (0) |
| 1092 | |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1093 | #define MIB_UNSIGNED(v, i) do { \ |
| 1094 | if (mib[i] > UINT_MAX) { \ |
| 1095 | ret = EFAULT; \ |
| 1096 | goto label_return; \ |
| 1097 | } \ |
| 1098 | v = (unsigned)mib[i]; \ |
| 1099 | } while (0) |
| 1100 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1101 | /* |
| 1102 | * There's a lot of code duplication in the following macros due to limitations |
| 1103 | * in how nested cpp macros are expanded. |
| 1104 | */ |
| 1105 | #define CTL_RO_CLGEN(c, l, n, v, t) \ |
| 1106 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1107 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1108 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1109 | int ret; \ |
| 1110 | t oldval; \ |
| 1111 | \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1112 | if (!(c)) { \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1113 | return ENOENT; \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1114 | } \ |
| 1115 | if (l) { \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1116 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1117 | } \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1118 | READONLY(); \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1119 | oldval = (v); \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1120 | READ(oldval, t); \ |
| 1121 | \ |
| 1122 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1123 | label_return: \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1124 | if (l) { \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1125 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1126 | } \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1127 | return ret; \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | #define CTL_RO_CGEN(c, n, v, t) \ |
| 1131 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1132 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1133 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1134 | int ret; \ |
| 1135 | t oldval; \ |
| 1136 | \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1137 | if (!(c)) { \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1138 | return ENOENT; \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1139 | } \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1140 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1141 | READONLY(); \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1142 | oldval = (v); \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1143 | READ(oldval, t); \ |
| 1144 | \ |
| 1145 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1146 | label_return: \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1147 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1148 | return ret; \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1149 | } |
| 1150 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1151 | #define CTL_RO_GEN(n, v, t) \ |
| 1152 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1153 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1154 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1155 | int ret; \ |
| 1156 | t oldval; \ |
| 1157 | \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1158 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1159 | READONLY(); \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1160 | oldval = (v); \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1161 | READ(oldval, t); \ |
| 1162 | \ |
| 1163 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1164 | label_return: \ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1165 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1166 | return ret; \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /* |
| 1170 | * ctl_mtx is not acquired, under the assumption that no pertinent data will |
| 1171 | * mutate during the call. |
| 1172 | */ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1173 | #define CTL_RO_NL_CGEN(c, n, v, t) \ |
| 1174 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1175 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1176 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1177 | int ret; \ |
| 1178 | t oldval; \ |
| 1179 | \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1180 | if (!(c)) { \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1181 | return ENOENT; \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1182 | } \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1183 | READONLY(); \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1184 | oldval = (v); \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1185 | READ(oldval, t); \ |
| 1186 | \ |
| 1187 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1188 | label_return: \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1189 | return ret; \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | #define CTL_RO_NL_GEN(n, v, t) \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1193 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1194 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1195 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1196 | int ret; \ |
| 1197 | t oldval; \ |
| 1198 | \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1199 | READONLY(); \ |
Jason Evans | 6eb84fb | 2012-11-29 22:13:04 -0800 | [diff] [blame] | 1200 | oldval = (v); \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1201 | READ(oldval, t); \ |
| 1202 | \ |
| 1203 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1204 | label_return: \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1205 | return ret; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1208 | #define CTL_TSD_RO_NL_CGEN(c, n, m, t) \ |
| 1209 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1210 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1211 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1212 | int ret; \ |
| 1213 | t oldval; \ |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1214 | \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1215 | if (!(c)) { \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1216 | return ENOENT; \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1217 | } \ |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1218 | READONLY(); \ |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1219 | oldval = (m(tsd)); \ |
| 1220 | READ(oldval, t); \ |
| 1221 | \ |
| 1222 | ret = 0; \ |
| 1223 | label_return: \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1224 | return ret; \ |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 1227 | #define CTL_RO_CONFIG_GEN(n, t) \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1228 | static int \ |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1229 | n##_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, \ |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1230 | size_t *oldlenp, void *newp, size_t newlen) { \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1231 | int ret; \ |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 1232 | t oldval; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1233 | \ |
| 1234 | READONLY(); \ |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1235 | oldval = n; \ |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 1236 | READ(oldval, t); \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1237 | \ |
| 1238 | ret = 0; \ |
Jason Evans | 6b9ed67 | 2012-04-25 13:12:46 -0700 | [diff] [blame] | 1239 | label_return: \ |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1240 | return ret; \ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1243 | /******************************************************************************/ |
| 1244 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1245 | CTL_RO_NL_GEN(version, JEMALLOC_VERSION, const char *) |
Jason Evans | a40bc7a | 2010-03-02 13:01:16 -0800 | [diff] [blame] | 1246 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1247 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1248 | epoch_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1249 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1250 | int ret; |
Jason Evans | 3ab682d | 2013-10-19 17:19:49 -0700 | [diff] [blame] | 1251 | UNUSED uint64_t newval; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1252 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1253 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1254 | WRITE(newval, uint64_t); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1255 | if (newp != NULL) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1256 | ctl_refresh(tsd_tsdn(tsd)); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1257 | } |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1258 | READ(ctl_arenas->epoch, uint64_t); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1259 | |
| 1260 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1261 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1262 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1263 | return ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1266 | /******************************************************************************/ |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1267 | |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 1268 | CTL_RO_CONFIG_GEN(config_cache_oblivious, bool) |
| 1269 | CTL_RO_CONFIG_GEN(config_debug, bool) |
| 1270 | CTL_RO_CONFIG_GEN(config_fill, bool) |
| 1271 | CTL_RO_CONFIG_GEN(config_lazy_lock, bool) |
| 1272 | CTL_RO_CONFIG_GEN(config_malloc_conf, const char *) |
| 1273 | CTL_RO_CONFIG_GEN(config_munmap, bool) |
| 1274 | CTL_RO_CONFIG_GEN(config_prof, bool) |
| 1275 | CTL_RO_CONFIG_GEN(config_prof_libgcc, bool) |
| 1276 | CTL_RO_CONFIG_GEN(config_prof_libunwind, bool) |
| 1277 | CTL_RO_CONFIG_GEN(config_stats, bool) |
| 1278 | CTL_RO_CONFIG_GEN(config_tcache, bool) |
| 1279 | CTL_RO_CONFIG_GEN(config_tls, bool) |
| 1280 | CTL_RO_CONFIG_GEN(config_utrace, bool) |
Jason Evans | f829009 | 2016-02-07 14:23:22 -0800 | [diff] [blame] | 1281 | CTL_RO_CONFIG_GEN(config_xmalloc, bool) |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1282 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1283 | /******************************************************************************/ |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1284 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1285 | CTL_RO_NL_GEN(opt_abort, opt_abort, bool) |
| 1286 | CTL_RO_NL_GEN(opt_dss, opt_dss, const char *) |
Jason Evans | 8f683b9 | 2016-02-24 11:03:40 -0800 | [diff] [blame] | 1287 | CTL_RO_NL_GEN(opt_narenas, opt_narenas, unsigned) |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1288 | CTL_RO_NL_GEN(opt_decay_time, opt_decay_time, ssize_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1289 | CTL_RO_NL_GEN(opt_stats_print, opt_stats_print, bool) |
Guilherme Goncalves | 2c5cb61 | 2014-12-08 19:12:41 -0200 | [diff] [blame] | 1290 | CTL_RO_NL_CGEN(config_fill, opt_junk, opt_junk, const char *) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1291 | CTL_RO_NL_CGEN(config_fill, opt_zero, opt_zero, bool) |
| 1292 | CTL_RO_NL_CGEN(config_utrace, opt_utrace, opt_utrace, bool) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1293 | CTL_RO_NL_CGEN(config_xmalloc, opt_xmalloc, opt_xmalloc, bool) |
| 1294 | CTL_RO_NL_CGEN(config_tcache, opt_tcache, opt_tcache, bool) |
| 1295 | CTL_RO_NL_CGEN(config_tcache, opt_lg_tcache_max, opt_lg_tcache_max, ssize_t) |
| 1296 | CTL_RO_NL_CGEN(config_prof, opt_prof, opt_prof, bool) |
| 1297 | CTL_RO_NL_CGEN(config_prof, opt_prof_prefix, opt_prof_prefix, const char *) |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 1298 | CTL_RO_NL_CGEN(config_prof, opt_prof_active, opt_prof_active, bool) |
| 1299 | CTL_RO_NL_CGEN(config_prof, opt_prof_thread_active_init, |
| 1300 | opt_prof_thread_active_init, bool) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1301 | CTL_RO_NL_CGEN(config_prof, opt_lg_prof_sample, opt_lg_prof_sample, size_t) |
| 1302 | CTL_RO_NL_CGEN(config_prof, opt_prof_accum, opt_prof_accum, bool) |
| 1303 | CTL_RO_NL_CGEN(config_prof, opt_lg_prof_interval, opt_lg_prof_interval, ssize_t) |
| 1304 | CTL_RO_NL_CGEN(config_prof, opt_prof_gdump, opt_prof_gdump, bool) |
| 1305 | CTL_RO_NL_CGEN(config_prof, opt_prof_final, opt_prof_final, bool) |
| 1306 | CTL_RO_NL_CGEN(config_prof, opt_prof_leak, opt_prof_leak, bool) |
Jason Evans | d4be8b7 | 2012-03-26 18:54:44 -0700 | [diff] [blame] | 1307 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1308 | /******************************************************************************/ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1309 | |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1310 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1311 | thread_arena_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1312 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1313 | int ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1314 | arena_t *oldarena; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1315 | unsigned newind, oldind; |
| 1316 | |
Jason Evans | 90827a3 | 2016-05-03 15:00:42 -0700 | [diff] [blame] | 1317 | oldarena = arena_choose(tsd, NULL); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1318 | if (oldarena == NULL) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1319 | return EAGAIN; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1320 | } |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1321 | |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 1322 | newind = oldind = arena_ind_get(oldarena); |
Jason Evans | a7153a0 | 2011-03-14 11:39:49 -0700 | [diff] [blame] | 1323 | WRITE(newind, unsigned); |
| 1324 | READ(oldind, unsigned); |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1325 | if (newind != oldind) { |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1326 | arena_t *newarena; |
| 1327 | |
Jason Evans | b6c0867 | 2016-10-03 10:37:12 -0700 | [diff] [blame] | 1328 | if (newind >= narenas_total_get()) { |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1329 | /* New arena index is out of range. */ |
| 1330 | ret = EFAULT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1331 | goto label_return; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /* Initialize arena if necessary. */ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1335 | newarena = arena_get(tsd_tsdn(tsd), newind, true); |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1336 | if (newarena == NULL) { |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1337 | ret = EAGAIN; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1338 | goto label_return; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1339 | } |
Jason Evans | 8bb3198 | 2014-10-07 23:14:57 -0700 | [diff] [blame] | 1340 | /* Set new arena/tcache associations. */ |
| 1341 | arena_migrate(tsd, oldind, newind); |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1342 | if (config_tcache) { |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1343 | tcache_t *tcache = tsd_tcache_get(tsd); |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1344 | if (tcache != NULL) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1345 | tcache_arena_reassociate(tsd_tsdn(tsd), tcache, |
| 1346 | oldarena, newarena); |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1347 | } |
Jason Evans | 624f2f3 | 2010-12-29 12:21:05 -0800 | [diff] [blame] | 1348 | } |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1352 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1353 | return ret; |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1354 | } |
Jason Evans | b267d0f | 2010-08-13 15:42:29 -0700 | [diff] [blame] | 1355 | |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1356 | CTL_TSD_RO_NL_CGEN(config_stats, thread_allocated, tsd_thread_allocated_get, |
| 1357 | uint64_t) |
| 1358 | CTL_TSD_RO_NL_CGEN(config_stats, thread_allocatedp, tsd_thread_allocatedp_get, |
| 1359 | uint64_t *) |
| 1360 | CTL_TSD_RO_NL_CGEN(config_stats, thread_deallocated, tsd_thread_deallocated_get, |
| 1361 | uint64_t) |
| 1362 | CTL_TSD_RO_NL_CGEN(config_stats, thread_deallocatedp, |
| 1363 | tsd_thread_deallocatedp_get, uint64_t *) |
Jason Evans | 9344368 | 2010-10-20 17:39:18 -0700 | [diff] [blame] | 1364 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1365 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1366 | thread_tcache_enabled_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1367 | void *oldp, size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1368 | int ret; |
| 1369 | bool oldval; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1370 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1371 | if (!config_tcache) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1372 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1373 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1374 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1375 | oldval = tcache_enabled_get(); |
| 1376 | if (newp != NULL) { |
| 1377 | if (newlen != sizeof(bool)) { |
| 1378 | ret = EINVAL; |
| 1379 | goto label_return; |
| 1380 | } |
| 1381 | tcache_enabled_set(*(bool *)newp); |
| 1382 | } |
| 1383 | READ(oldval, bool); |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1384 | |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1385 | ret = 0; |
| 1386 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1387 | return ret; |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1391 | thread_tcache_flush_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1392 | void *oldp, size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1393 | int ret; |
| 1394 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1395 | if (!config_tcache) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1396 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1397 | } |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1398 | |
| 1399 | READONLY(); |
| 1400 | WRITEONLY(); |
| 1401 | |
| 1402 | tcache_flush(); |
| 1403 | |
| 1404 | ret = 0; |
| 1405 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1406 | return ret; |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1407 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1408 | |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1409 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1410 | thread_prof_name_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1411 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1412 | int ret; |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1413 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1414 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1415 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1416 | } |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1417 | |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 1418 | READ_XOR_WRITE(); |
| 1419 | |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1420 | if (newp != NULL) { |
| 1421 | if (newlen != sizeof(const char *)) { |
| 1422 | ret = EINVAL; |
| 1423 | goto label_return; |
| 1424 | } |
Jason Evans | 5460aa6 | 2014-09-22 21:09:23 -0700 | [diff] [blame] | 1425 | |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 1426 | if ((ret = prof_thread_name_set(tsd, *(const char **)newp)) != |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1427 | 0) { |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1428 | goto label_return; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1429 | } |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 1430 | } else { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1431 | const char *oldname = prof_thread_name_get(tsd); |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 1432 | READ(oldname, const char *); |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1433 | } |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1434 | |
| 1435 | ret = 0; |
| 1436 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1437 | return ret; |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1441 | thread_prof_active_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1442 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1443 | int ret; |
| 1444 | bool oldval; |
| 1445 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1446 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1447 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1448 | } |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1449 | |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1450 | oldval = prof_thread_active_get(tsd); |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1451 | if (newp != NULL) { |
| 1452 | if (newlen != sizeof(bool)) { |
| 1453 | ret = EINVAL; |
| 1454 | goto label_return; |
| 1455 | } |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1456 | if (prof_thread_active_set(tsd, *(bool *)newp)) { |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1457 | ret = EAGAIN; |
| 1458 | goto label_return; |
| 1459 | } |
| 1460 | } |
| 1461 | READ(oldval, bool); |
| 1462 | |
| 1463 | ret = 0; |
| 1464 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1465 | return ret; |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1468 | /******************************************************************************/ |
| 1469 | |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1470 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1471 | tcache_create_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1472 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1473 | int ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1474 | unsigned tcache_ind; |
| 1475 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1476 | if (!config_tcache) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1477 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1478 | } |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1479 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1480 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1481 | READONLY(); |
Jason Evans | b54d160 | 2016-10-20 23:59:12 -0700 | [diff] [blame] | 1482 | if (tcaches_create(tsd, &tcache_ind)) { |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1483 | ret = EFAULT; |
| 1484 | goto label_return; |
| 1485 | } |
| 1486 | READ(tcache_ind, unsigned); |
| 1487 | |
| 1488 | ret = 0; |
| 1489 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1490 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1491 | return ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1495 | tcache_flush_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1496 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1497 | int ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1498 | unsigned tcache_ind; |
| 1499 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1500 | if (!config_tcache) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1501 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1502 | } |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1503 | |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1504 | WRITEONLY(); |
| 1505 | tcache_ind = UINT_MAX; |
| 1506 | WRITE(tcache_ind, unsigned); |
| 1507 | if (tcache_ind == UINT_MAX) { |
| 1508 | ret = EFAULT; |
| 1509 | goto label_return; |
| 1510 | } |
| 1511 | tcaches_flush(tsd, tcache_ind); |
| 1512 | |
| 1513 | ret = 0; |
| 1514 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1515 | return ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1519 | tcache_destroy_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1520 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1521 | int ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1522 | unsigned tcache_ind; |
| 1523 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1524 | if (!config_tcache) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1525 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1526 | } |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1527 | |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1528 | WRITEONLY(); |
| 1529 | tcache_ind = UINT_MAX; |
| 1530 | WRITE(tcache_ind, unsigned); |
| 1531 | if (tcache_ind == UINT_MAX) { |
| 1532 | ret = EFAULT; |
| 1533 | goto label_return; |
| 1534 | } |
| 1535 | tcaches_destroy(tsd, tcache_ind); |
| 1536 | |
| 1537 | ret = 0; |
| 1538 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1539 | return ret; |
Jason Evans | 1cb181e | 2015-01-29 15:30:47 -0800 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /******************************************************************************/ |
| 1543 | |
Jason Evans | dc2125c | 2017-01-04 10:21:53 -0800 | [diff] [blame] | 1544 | static int |
| 1545 | arena_i_initialized_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1546 | void *oldp, size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | dc2125c | 2017-01-04 10:21:53 -0800 | [diff] [blame] | 1547 | int ret; |
| 1548 | tsdn_t *tsdn = tsd_tsdn(tsd); |
| 1549 | unsigned arena_ind; |
| 1550 | bool initialized; |
| 1551 | |
| 1552 | READONLY(); |
| 1553 | MIB_UNSIGNED(arena_ind, 1); |
| 1554 | |
| 1555 | malloc_mutex_lock(tsdn, &ctl_mtx); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1556 | initialized = arenas_i(arena_ind)->initialized; |
Jason Evans | dc2125c | 2017-01-04 10:21:53 -0800 | [diff] [blame] | 1557 | malloc_mutex_unlock(tsdn, &ctl_mtx); |
| 1558 | |
| 1559 | READ(initialized, bool); |
| 1560 | |
| 1561 | ret = 0; |
| 1562 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1563 | return ret; |
Jason Evans | dc2125c | 2017-01-04 10:21:53 -0800 | [diff] [blame] | 1564 | } |
| 1565 | |
Jason Evans | 34457f5 | 2012-11-03 21:18:28 -0700 | [diff] [blame] | 1566 | static void |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1567 | arena_i_purge(tsdn_t *tsdn, unsigned arena_ind, bool all) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1568 | malloc_mutex_lock(tsdn, &ctl_mtx); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1569 | { |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1570 | unsigned narenas = ctl_arenas->narenas; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1571 | |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 1572 | /* |
| 1573 | * Access via index narenas is deprecated, and scheduled for |
| 1574 | * removal in 6.0.0. |
| 1575 | */ |
| 1576 | if (arena_ind == MALLCTL_ARENAS_ALL || arena_ind == narenas) { |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1577 | unsigned i; |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1578 | VARIABLE_ARRAY(arena_t *, tarenas, narenas); |
| 1579 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1580 | for (i = 0; i < narenas; i++) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1581 | tarenas[i] = arena_get(tsdn, i, false); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1582 | } |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1583 | |
| 1584 | /* |
| 1585 | * No further need to hold ctl_mtx, since narenas and |
| 1586 | * tarenas contain everything needed below. |
| 1587 | */ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1588 | malloc_mutex_unlock(tsdn, &ctl_mtx); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1589 | |
| 1590 | for (i = 0; i < narenas; i++) { |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1591 | if (tarenas[i] != NULL) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1592 | arena_purge(tsdn, tarenas[i], all); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1593 | } |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1594 | } |
| 1595 | } else { |
| 1596 | arena_t *tarena; |
| 1597 | |
| 1598 | assert(arena_ind < narenas); |
| 1599 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1600 | tarena = arena_get(tsdn, arena_ind, false); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1601 | |
| 1602 | /* No further need to hold ctl_mtx. */ |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1603 | malloc_mutex_unlock(tsdn, &ctl_mtx); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1604 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1605 | if (tarena != NULL) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1606 | arena_purge(tsdn, tarena, all); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1607 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1608 | } |
| 1609 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1613 | arena_i_purge_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1614 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1615 | int ret; |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1616 | unsigned arena_ind; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1617 | |
| 1618 | READONLY(); |
| 1619 | WRITEONLY(); |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1620 | MIB_UNSIGNED(arena_ind, 1); |
| 1621 | arena_i_purge(tsd_tsdn(tsd), arena_ind, true); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1622 | |
| 1623 | ret = 0; |
| 1624 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1625 | return ret; |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1629 | arena_i_decay_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1630 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1631 | int ret; |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1632 | unsigned arena_ind; |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1633 | |
| 1634 | READONLY(); |
| 1635 | WRITEONLY(); |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1636 | MIB_UNSIGNED(arena_ind, 1); |
| 1637 | arena_i_purge(tsd_tsdn(tsd), arena_ind, false); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1638 | |
Jason Evans | 34457f5 | 2012-11-03 21:18:28 -0700 | [diff] [blame] | 1639 | ret = 0; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1640 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1641 | return ret; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | static int |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1645 | arena_i_reset_destroy_helper(tsd_t *tsd, const size_t *mib, size_t miblen, |
| 1646 | void *oldp, size_t *oldlenp, void *newp, size_t newlen, unsigned *arena_ind, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1647 | arena_t **arena) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1648 | int ret; |
| 1649 | |
| 1650 | READONLY(); |
| 1651 | WRITEONLY(); |
| 1652 | MIB_UNSIGNED(*arena_ind, 1); |
| 1653 | |
| 1654 | if (*arena_ind < narenas_auto) { |
| 1655 | ret = EFAULT; |
| 1656 | goto label_return; |
| 1657 | } |
| 1658 | |
| 1659 | *arena = arena_get(tsd_tsdn(tsd), *arena_ind, false); |
| 1660 | if (*arena == NULL) { |
| 1661 | ret = EFAULT; |
| 1662 | goto label_return; |
| 1663 | } |
| 1664 | |
| 1665 | ret = 0; |
| 1666 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1667 | return ret; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | static int |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1671 | arena_i_reset_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1672 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1673 | int ret; |
| 1674 | unsigned arena_ind; |
| 1675 | arena_t *arena; |
| 1676 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1677 | ret = arena_i_reset_destroy_helper(tsd, mib, miblen, oldp, oldlenp, |
| 1678 | newp, newlen, &arena_ind, &arena); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1679 | if (ret != 0) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1680 | return ret; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1681 | } |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1682 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1683 | arena_reset(tsd, arena); |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1684 | |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1685 | return ret; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | static int |
| 1689 | arena_i_destroy_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1690 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1691 | int ret; |
| 1692 | unsigned arena_ind; |
| 1693 | arena_t *arena; |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1694 | ctl_arena_t *ctl_darena, *ctl_arena; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1695 | |
| 1696 | ret = arena_i_reset_destroy_helper(tsd, mib, miblen, oldp, oldlenp, |
| 1697 | newp, newlen, &arena_ind, &arena); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1698 | if (ret != 0) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1699 | goto label_return; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1700 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1701 | |
| 1702 | if (arena_nthreads_get(arena, false) != 0 || arena_nthreads_get(arena, |
| 1703 | true) != 0) { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 1704 | ret = EFAULT; |
| 1705 | goto label_return; |
| 1706 | } |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1707 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1708 | /* Merge stats after resetting and purging arena. */ |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1709 | arena_reset(tsd, arena); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1710 | arena_purge(tsd_tsdn(tsd), arena, true); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1711 | ctl_darena = arenas_i(MALLCTL_ARENAS_DESTROYED); |
| 1712 | ctl_darena->initialized = true; |
| 1713 | ctl_arena_refresh(tsd_tsdn(tsd), arena, ctl_darena, arena_ind, true); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1714 | /* Destroy arena. */ |
| 1715 | arena_destroy(tsd, arena); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1716 | ctl_arena = arenas_i(arena_ind); |
| 1717 | ctl_arena->initialized = false; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1718 | /* Record arena index for later recycling via arenas.create. */ |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1719 | ql_elm_new(ctl_arena, destroyed_link); |
| 1720 | ql_tail_insert(&ctl_arenas->destroyed, ctl_arena, destroyed_link); |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1721 | |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1722 | assert(ret == 0); |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1723 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1724 | return ret; |
Jason Evans | 19ff2ce | 2016-04-22 14:37:17 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1728 | arena_i_dss_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1729 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1730 | int ret; |
| 1731 | const char *dss = NULL; |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1732 | unsigned arena_ind; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1733 | dss_prec_t dss_prec_old = dss_prec_limit; |
| 1734 | dss_prec_t dss_prec = dss_prec_limit; |
| 1735 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1736 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1737 | WRITE(dss, const char *); |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1738 | MIB_UNSIGNED(arena_ind, 1); |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1739 | if (dss != NULL) { |
| 1740 | int i; |
| 1741 | bool match = false; |
| 1742 | |
| 1743 | for (i = 0; i < dss_prec_limit; i++) { |
| 1744 | if (strcmp(dss_prec_names[i], dss) == 0) { |
| 1745 | dss_prec = i; |
| 1746 | match = true; |
| 1747 | break; |
| 1748 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1749 | } |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1750 | |
Jason Evans | 551ebc4 | 2014-10-03 10:16:09 -0700 | [diff] [blame] | 1751 | if (!match) { |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1752 | ret = EINVAL; |
| 1753 | goto label_return; |
| 1754 | } |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 1757 | /* |
| 1758 | * Access via index narenas is deprecated, and scheduled for removal in |
| 1759 | * 6.0.0. |
| 1760 | */ |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 1761 | if (arena_ind == MALLCTL_ARENAS_ALL || arena_ind == |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1762 | ctl_arenas->narenas) { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 1763 | if (dss_prec != dss_prec_limit && |
| 1764 | extent_dss_prec_set(dss_prec)) { |
| 1765 | ret = EFAULT; |
| 1766 | goto label_return; |
| 1767 | } |
| 1768 | dss_prec_old = extent_dss_prec_get(); |
| 1769 | } else { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1770 | arena_t *arena = arena_get(tsd_tsdn(tsd), arena_ind, false); |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1771 | if (arena == NULL || (dss_prec != dss_prec_limit && |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1772 | arena_dss_prec_set(tsd_tsdn(tsd), arena, dss_prec))) { |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1773 | ret = EFAULT; |
| 1774 | goto label_return; |
| 1775 | } |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1776 | dss_prec_old = arena_dss_prec_get(tsd_tsdn(tsd), arena); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1777 | } |
Jason Evans | 586c8ed | 2014-08-15 12:20:20 -0700 | [diff] [blame] | 1778 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1779 | dss = dss_prec_names[dss_prec_old]; |
| 1780 | READ(dss, const char *); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1781 | |
| 1782 | ret = 0; |
| 1783 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1784 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1785 | return ret; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 1788 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1789 | arena_i_decay_time_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1790 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1791 | int ret; |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1792 | unsigned arena_ind; |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1793 | arena_t *arena; |
| 1794 | |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1795 | MIB_UNSIGNED(arena_ind, 1); |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1796 | arena = arena_get(tsd_tsdn(tsd), arena_ind, false); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1797 | if (arena == NULL) { |
| 1798 | ret = EFAULT; |
| 1799 | goto label_return; |
| 1800 | } |
| 1801 | |
| 1802 | if (oldp != NULL && oldlenp != NULL) { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1803 | size_t oldval = arena_decay_time_get(tsd_tsdn(tsd), arena); |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1804 | READ(oldval, ssize_t); |
| 1805 | } |
| 1806 | if (newp != NULL) { |
| 1807 | if (newlen != sizeof(ssize_t)) { |
| 1808 | ret = EINVAL; |
| 1809 | goto label_return; |
| 1810 | } |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1811 | if (arena_decay_time_set(tsd_tsdn(tsd), arena, |
| 1812 | *(ssize_t *)newp)) { |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1813 | ret = EFAULT; |
| 1814 | goto label_return; |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | ret = 0; |
| 1819 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1820 | return ret; |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | static int |
Jason Evans | 9c305c9 | 2016-05-31 15:03:51 -0700 | [diff] [blame] | 1824 | arena_i_extent_hooks_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1825 | void *oldp, size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1826 | int ret; |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1827 | unsigned arena_ind; |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1828 | arena_t *arena; |
| 1829 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1830 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | 6edbedd | 2017-01-04 07:51:49 -0800 | [diff] [blame] | 1831 | MIB_UNSIGNED(arena_ind, 1); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1832 | if (arena_ind < narenas_total_get() && (arena = |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1833 | arena_get(tsd_tsdn(tsd), arena_ind, false)) != NULL) { |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1834 | if (newp != NULL) { |
Jason Evans | f02fec8 | 2016-06-03 19:39:14 -0700 | [diff] [blame] | 1835 | extent_hooks_t *old_extent_hooks; |
| 1836 | extent_hooks_t *new_extent_hooks |
| 1837 | JEMALLOC_CC_SILENCE_INIT(NULL); |
Jason Evans | f8f0542 | 2016-06-03 12:05:53 -0700 | [diff] [blame] | 1838 | WRITE(new_extent_hooks, extent_hooks_t *); |
| 1839 | old_extent_hooks = extent_hooks_set(arena, |
| 1840 | new_extent_hooks); |
| 1841 | READ(old_extent_hooks, extent_hooks_t *); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1842 | } else { |
Jason Evans | f8f0542 | 2016-06-03 12:05:53 -0700 | [diff] [blame] | 1843 | extent_hooks_t *old_extent_hooks = |
| 1844 | extent_hooks_get(arena); |
| 1845 | READ(old_extent_hooks, extent_hooks_t *); |
Jason Evans | b49a334 | 2015-07-28 11:28:19 -0400 | [diff] [blame] | 1846 | } |
| 1847 | } else { |
| 1848 | ret = EFAULT; |
| 1849 | goto label_return; |
| 1850 | } |
| 1851 | ret = 0; |
| 1852 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1853 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1854 | return ret; |
aravind | fb7fe50 | 2014-05-05 15:16:56 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1857 | static const ctl_named_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1858 | arena_i_index(tsdn_t *tsdn, const size_t *mib, size_t miblen, size_t i) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1859 | const ctl_named_node_t *ret; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1860 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1861 | malloc_mutex_lock(tsdn, &ctl_mtx); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1862 | switch (i) { |
| 1863 | case MALLCTL_ARENAS_ALL: |
| 1864 | case MALLCTL_ARENAS_DESTROYED: |
| 1865 | break; |
| 1866 | default: |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1867 | if (i > ctl_arenas->narenas) { |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1868 | ret = NULL; |
| 1869 | goto label_return; |
| 1870 | } |
| 1871 | break; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | ret = super_arena_i_node; |
| 1875 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1876 | malloc_mutex_unlock(tsdn, &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1877 | return ret; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1878 | } |
| 1879 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1880 | /******************************************************************************/ |
| 1881 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1882 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1883 | arenas_narenas_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1884 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1885 | int ret; |
| 1886 | unsigned narenas; |
| 1887 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1888 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1889 | READONLY(); |
| 1890 | if (*oldlenp != sizeof(unsigned)) { |
| 1891 | ret = EINVAL; |
| 1892 | goto label_return; |
| 1893 | } |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 1894 | narenas = ctl_arenas->narenas; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1895 | READ(narenas, unsigned); |
| 1896 | |
| 1897 | ret = 0; |
| 1898 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1899 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1900 | return ret; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1901 | } |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1902 | |
| 1903 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1904 | arenas_decay_time_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1905 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1906 | int ret; |
| 1907 | |
| 1908 | if (oldp != NULL && oldlenp != NULL) { |
| 1909 | size_t oldval = arena_decay_time_default_get(); |
| 1910 | READ(oldval, ssize_t); |
| 1911 | } |
| 1912 | if (newp != NULL) { |
| 1913 | if (newlen != sizeof(ssize_t)) { |
| 1914 | ret = EINVAL; |
| 1915 | goto label_return; |
| 1916 | } |
| 1917 | if (arena_decay_time_default_set(*(ssize_t *)newp)) { |
| 1918 | ret = EFAULT; |
| 1919 | goto label_return; |
| 1920 | } |
| 1921 | } |
| 1922 | |
| 1923 | ret = 0; |
| 1924 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1925 | return ret; |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 1926 | } |
| 1927 | |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 1928 | CTL_RO_NL_GEN(arenas_quantum, QUANTUM, size_t) |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame] | 1929 | CTL_RO_NL_GEN(arenas_page, PAGE, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1930 | 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] | 1931 | CTL_RO_NL_GEN(arenas_nbins, NBINS, unsigned) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1932 | CTL_RO_NL_CGEN(config_tcache, arenas_nhbins, nhbins, unsigned) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1933 | CTL_RO_NL_GEN(arenas_bin_i_size, arena_bin_info[mib[2]].reg_size, size_t) |
| 1934 | CTL_RO_NL_GEN(arenas_bin_i_nregs, arena_bin_info[mib[2]].nregs, uint32_t) |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 1935 | CTL_RO_NL_GEN(arenas_bin_i_slab_size, arena_bin_info[mib[2]].slab_size, size_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1936 | static const ctl_named_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1937 | arenas_bin_i_index(tsdn_t *tsdn, const size_t *mib, size_t miblen, size_t i) { |
| 1938 | if (i > NBINS) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1939 | return NULL; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1940 | } |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1941 | return super_arenas_bin_i_node; |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 1944 | CTL_RO_NL_GEN(arenas_nlextents, NSIZES - NBINS, unsigned) |
| 1945 | CTL_RO_NL_GEN(arenas_lextent_i_size, index2size(NBINS+(szind_t)mib[2]), size_t) |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 1946 | static const ctl_named_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1947 | arenas_lextent_i_index(tsdn_t *tsdn, const size_t *mib, size_t miblen, |
| 1948 | size_t i) { |
| 1949 | if (i > NSIZES - NBINS) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1950 | return NULL; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1951 | } |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1952 | return super_arenas_lextent_i_node; |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1955 | static int |
Jason Evans | 0f04bb1 | 2017-01-03 08:21:29 -0800 | [diff] [blame] | 1956 | arenas_create_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1957 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1958 | int ret; |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 1959 | extent_hooks_t *extent_hooks; |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1960 | unsigned arena_ind; |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1961 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1962 | malloc_mutex_lock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 1963 | |
| 1964 | extent_hooks = (extent_hooks_t *)&extent_hooks_default; |
| 1965 | WRITE(extent_hooks, extent_hooks_t *); |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1966 | if ((arena_ind = ctl_arena_init(tsd_tsdn(tsd), extent_hooks)) == |
| 1967 | UINT_MAX) { |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1968 | ret = EAGAIN; |
| 1969 | goto label_return; |
| 1970 | } |
Jason Evans | edf1baf | 2017-01-03 17:21:59 -0800 | [diff] [blame] | 1971 | READ(arena_ind, unsigned); |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 1972 | |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1973 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 1974 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1975 | malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1976 | return ret; |
Jason Evans | 6005f07 | 2010-09-30 16:55:08 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 1979 | /******************************************************************************/ |
| 1980 | |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1981 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1982 | prof_thread_active_init_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1983 | void *oldp, size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1984 | int ret; |
| 1985 | bool oldval; |
| 1986 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1987 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 1988 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1989 | } |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 1990 | |
| 1991 | if (newp != NULL) { |
| 1992 | if (newlen != sizeof(bool)) { |
| 1993 | ret = EINVAL; |
| 1994 | goto label_return; |
| 1995 | } |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1996 | oldval = prof_thread_active_init_set(tsd_tsdn(tsd), |
| 1997 | *(bool *)newp); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 1998 | } else { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 1999 | oldval = prof_thread_active_init_get(tsd_tsdn(tsd)); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2000 | } |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 2001 | READ(oldval, bool); |
| 2002 | |
| 2003 | ret = 0; |
| 2004 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2005 | return ret; |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | static int |
| 2009 | prof_active_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2010 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 2011 | int ret; |
| 2012 | bool oldval; |
| 2013 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2014 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2015 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2016 | } |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 2017 | |
| 2018 | if (newp != NULL) { |
| 2019 | if (newlen != sizeof(bool)) { |
| 2020 | ret = EINVAL; |
| 2021 | goto label_return; |
| 2022 | } |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2023 | oldval = prof_active_set(tsd_tsdn(tsd), *(bool *)newp); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2024 | } else { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2025 | oldval = prof_active_get(tsd_tsdn(tsd)); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2026 | } |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 2027 | READ(oldval, bool); |
| 2028 | |
| 2029 | ret = 0; |
| 2030 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2031 | return ret; |
Jason Evans | fc12c0b | 2014-10-03 23:25:30 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 2035 | prof_dump_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2036 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 2037 | int ret; |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 2038 | const char *filename = NULL; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 2039 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2040 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2041 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2042 | } |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2043 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 2044 | WRITEONLY(); |
| 2045 | WRITE(filename, const char *); |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 2046 | |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 2047 | if (prof_mdump(tsd, filename)) { |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 2048 | ret = EFAULT; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 2049 | goto label_return; |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 2050 | } |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 2051 | |
| 2052 | ret = 0; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 2053 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2054 | return ret; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2057 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 2058 | prof_gdump_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2059 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 5b8ed5b | 2015-01-25 21:16:57 -0800 | [diff] [blame] | 2060 | int ret; |
| 2061 | bool oldval; |
| 2062 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2063 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2064 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2065 | } |
Jason Evans | 5b8ed5b | 2015-01-25 21:16:57 -0800 | [diff] [blame] | 2066 | |
| 2067 | if (newp != NULL) { |
| 2068 | if (newlen != sizeof(bool)) { |
| 2069 | ret = EINVAL; |
| 2070 | goto label_return; |
| 2071 | } |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2072 | oldval = prof_gdump_set(tsd_tsdn(tsd), *(bool *)newp); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2073 | } else { |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2074 | oldval = prof_gdump_get(tsd_tsdn(tsd)); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2075 | } |
Jason Evans | 5b8ed5b | 2015-01-25 21:16:57 -0800 | [diff] [blame] | 2076 | READ(oldval, bool); |
| 2077 | |
| 2078 | ret = 0; |
| 2079 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2080 | return ret; |
Jason Evans | 5b8ed5b | 2015-01-25 21:16:57 -0800 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | static int |
Jason Evans | b2c0d63 | 2016-04-13 23:36:15 -0700 | [diff] [blame] | 2084 | prof_reset_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2085 | size_t *oldlenp, void *newp, size_t newlen) { |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2086 | int ret; |
| 2087 | size_t lg_sample = lg_prof_sample; |
| 2088 | |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2089 | if (!config_prof) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2090 | return ENOENT; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2091 | } |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2092 | |
| 2093 | WRITEONLY(); |
| 2094 | WRITE(lg_sample, size_t); |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2095 | if (lg_sample >= (sizeof(uint64_t) << 3)) { |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2096 | lg_sample = (sizeof(uint64_t) << 3) - 1; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2097 | } |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2098 | |
Jason Evans | b54d160 | 2016-10-20 23:59:12 -0700 | [diff] [blame] | 2099 | prof_reset(tsd, lg_sample); |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2100 | |
| 2101 | ret = 0; |
| 2102 | label_return: |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2103 | return ret; |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2106 | CTL_RO_NL_CGEN(config_prof, prof_interval, prof_interval, uint64_t) |
Jason Evans | 602c8e0 | 2014-08-18 16:22:13 -0700 | [diff] [blame] | 2107 | CTL_RO_NL_CGEN(config_prof, lg_prof_sample, lg_prof_sample, size_t) |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 2108 | |
| 2109 | /******************************************************************************/ |
| 2110 | |
Jason Evans | d778dd2 | 2017-01-03 12:40:54 -0800 | [diff] [blame] | 2111 | CTL_RO_CGEN(config_stats, stats_allocated, ctl_stats->allocated, size_t) |
| 2112 | CTL_RO_CGEN(config_stats, stats_active, ctl_stats->active, size_t) |
| 2113 | CTL_RO_CGEN(config_stats, stats_metadata, ctl_stats->metadata, size_t) |
| 2114 | CTL_RO_CGEN(config_stats, stats_resident, ctl_stats->resident, size_t) |
| 2115 | CTL_RO_CGEN(config_stats, stats_mapped, ctl_stats->mapped, size_t) |
| 2116 | CTL_RO_CGEN(config_stats, stats_retained, ctl_stats->retained, size_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 2117 | |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2118 | CTL_RO_GEN(stats_arenas_i_dss, arenas_i(mib[2])->dss, const char *) |
| 2119 | CTL_RO_GEN(stats_arenas_i_decay_time, arenas_i(mib[2])->decay_time, |
Jason Evans | 243f7a0 | 2016-02-19 20:09:31 -0800 | [diff] [blame] | 2120 | ssize_t) |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2121 | CTL_RO_GEN(stats_arenas_i_nthreads, arenas_i(mib[2])->nthreads, unsigned) |
| 2122 | CTL_RO_GEN(stats_arenas_i_pactive, arenas_i(mib[2])->pactive, size_t) |
| 2123 | CTL_RO_GEN(stats_arenas_i_pdirty, arenas_i(mib[2])->pdirty, size_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 2124 | CTL_RO_CGEN(config_stats, stats_arenas_i_mapped, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2125 | arenas_i(mib[2])->astats->astats.mapped, size_t) |
Jason Evans | 04c3c0f | 2016-05-03 22:11:35 -0700 | [diff] [blame] | 2126 | CTL_RO_CGEN(config_stats, stats_arenas_i_retained, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2127 | arenas_i(mib[2])->astats->astats.retained, size_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 2128 | CTL_RO_CGEN(config_stats, stats_arenas_i_npurge, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2129 | arenas_i(mib[2])->astats->astats.npurge, uint64_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 2130 | CTL_RO_CGEN(config_stats, stats_arenas_i_nmadvise, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2131 | arenas_i(mib[2])->astats->astats.nmadvise, uint64_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 2132 | CTL_RO_CGEN(config_stats, stats_arenas_i_purged, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2133 | arenas_i(mib[2])->astats->astats.purged, uint64_t) |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 2134 | CTL_RO_CGEN(config_stats, stats_arenas_i_base, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2135 | arenas_i(mib[2])->astats->astats.base, size_t) |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 2136 | CTL_RO_CGEN(config_stats, stats_arenas_i_internal, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2137 | arenas_i(mib[2])->astats->astats.internal, size_t) |
Qi Wang | 58424e6 | 2016-04-22 18:37:44 -0700 | [diff] [blame] | 2138 | CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_tcache_bytes, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2139 | arenas_i(mib[2])->astats->astats.tcache_bytes, size_t) |
Jason Evans | a0dd3a4 | 2016-12-22 16:39:10 -0600 | [diff] [blame] | 2140 | CTL_RO_CGEN(config_stats, stats_arenas_i_resident, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2141 | arenas_i(mib[2])->astats->astats.resident, size_t) |
Jason Evans | d8a3900 | 2013-12-19 21:40:41 -0800 | [diff] [blame] | 2142 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2143 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_allocated, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2144 | arenas_i(mib[2])->astats->allocated_small, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2145 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_nmalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2146 | arenas_i(mib[2])->astats->nmalloc_small, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2147 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_ndalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2148 | arenas_i(mib[2])->astats->ndalloc_small, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2149 | CTL_RO_CGEN(config_stats, stats_arenas_i_small_nrequests, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2150 | arenas_i(mib[2])->astats->nrequests_small, uint64_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2151 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_allocated, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2152 | arenas_i(mib[2])->astats->astats.allocated_large, size_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2153 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_nmalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2154 | arenas_i(mib[2])->astats->astats.nmalloc_large, uint64_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2155 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_ndalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2156 | arenas_i(mib[2])->astats->astats.ndalloc_large, uint64_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2157 | CTL_RO_CGEN(config_stats, stats_arenas_i_large_nrequests, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2158 | arenas_i(mib[2])->astats->astats.nmalloc_large, uint64_t) /* Intentional. */ |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 2159 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2160 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nmalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2161 | arenas_i(mib[2])->astats->bstats[mib[4]].nmalloc, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2162 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_ndalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2163 | arenas_i(mib[2])->astats->bstats[mib[4]].ndalloc, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2164 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nrequests, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2165 | arenas_i(mib[2])->astats->bstats[mib[4]].nrequests, uint64_t) |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 2166 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_curregs, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2167 | arenas_i(mib[2])->astats->bstats[mib[4]].curregs, size_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2168 | CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_bins_j_nfills, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2169 | arenas_i(mib[2])->astats->bstats[mib[4]].nfills, uint64_t) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 2170 | CTL_RO_CGEN(config_stats && config_tcache, stats_arenas_i_bins_j_nflushes, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2171 | arenas_i(mib[2])->astats->bstats[mib[4]].nflushes, uint64_t) |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 2172 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nslabs, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2173 | arenas_i(mib[2])->astats->bstats[mib[4]].nslabs, uint64_t) |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 2174 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_nreslabs, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2175 | arenas_i(mib[2])->astats->bstats[mib[4]].reslabs, uint64_t) |
Jason Evans | 498856f | 2016-05-29 18:34:50 -0700 | [diff] [blame] | 2176 | CTL_RO_CGEN(config_stats, stats_arenas_i_bins_j_curslabs, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2177 | arenas_i(mib[2])->astats->bstats[mib[4]].curslabs, size_t) |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 2178 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 2179 | static const ctl_named_node_t * |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2180 | stats_arenas_i_bins_j_index(tsdn_t *tsdn, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2181 | size_t j) { |
| 2182 | if (j > NBINS) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2183 | return NULL; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2184 | } |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2185 | return super_stats_arenas_i_bins_j_node; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 2186 | } |
| 2187 | |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2188 | CTL_RO_CGEN(config_stats, stats_arenas_i_lextents_j_nmalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2189 | arenas_i(mib[2])->astats->lstats[mib[4]].nmalloc, uint64_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2190 | CTL_RO_CGEN(config_stats, stats_arenas_i_lextents_j_ndalloc, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2191 | arenas_i(mib[2])->astats->lstats[mib[4]].ndalloc, uint64_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2192 | CTL_RO_CGEN(config_stats, stats_arenas_i_lextents_j_nrequests, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2193 | arenas_i(mib[2])->astats->lstats[mib[4]].nrequests, uint64_t) |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2194 | CTL_RO_CGEN(config_stats, stats_arenas_i_lextents_j_curlextents, |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2195 | arenas_i(mib[2])->astats->lstats[mib[4]].curlextents, size_t) |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 2196 | |
| 2197 | static const ctl_named_node_t * |
Jason Evans | 7d63fed | 2016-05-31 14:50:21 -0700 | [diff] [blame] | 2198 | stats_arenas_i_lextents_j_index(tsdn_t *tsdn, const size_t *mib, size_t miblen, |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2199 | size_t j) { |
| 2200 | if (j > NSIZES - NBINS) { |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2201 | return NULL; |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2202 | } |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2203 | return super_stats_arenas_i_lextents_j_node; |
Jason Evans | 3c4d92e | 2014-10-12 22:53:59 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Jason Evans | 609ae59 | 2012-10-11 13:53:15 -0700 | [diff] [blame] | 2206 | static const ctl_named_node_t * |
Jason Evans | c4c2592 | 2017-01-15 16:56:30 -0800 | [diff] [blame] | 2207 | stats_arenas_i_index(tsdn_t *tsdn, const size_t *mib, size_t miblen, size_t i) { |
Jason Evans | 3dc4e83 | 2017-01-03 07:27:42 -0800 | [diff] [blame] | 2208 | const ctl_named_node_t *ret; |
| 2209 | size_t a; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 2210 | |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2211 | malloc_mutex_lock(tsdn, &ctl_mtx); |
Jason Evans | 9eb1b1c | 2017-01-18 23:03:37 -0800 | [diff] [blame] | 2212 | a = arenas_i2a_impl(i, true, true); |
| 2213 | if (a == UINT_MAX || !ctl_arenas->arenas[a]->initialized) { |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 2214 | ret = NULL; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 2215 | goto label_return; |
Jason Evans | fc4dcfa | 2010-11-24 15:44:21 -0800 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | ret = super_stats_arenas_i_node; |
Jason Evans | a1ee783 | 2012-04-10 15:07:44 -0700 | [diff] [blame] | 2219 | label_return: |
Jason Evans | c1e00ef | 2016-05-10 22:21:10 -0700 | [diff] [blame] | 2220 | malloc_mutex_unlock(tsdn, &ctl_mtx); |
Jason Evans | f408643 | 2017-01-19 18:15:45 -0800 | [diff] [blame^] | 2221 | return ret; |
Jason Evans | 3c23435 | 2010-01-27 13:10:55 -0800 | [diff] [blame] | 2222 | } |