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