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