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