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