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