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