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