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