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