1#ifndef JEMALLOC_INTERNAL_CTL_H
2#define JEMALLOC_INTERNAL_CTL_H
3
4#include "jemalloc/internal/jemalloc_internal_types.h"
5#include "jemalloc/internal/malloc_io.h"
6#include "jemalloc/internal/mutex_prof.h"
7#include "jemalloc/internal/ql.h"
8#include "jemalloc/internal/sc.h"
9#include "jemalloc/internal/stats.h"
10
11/* Maximum ctl tree depth. */
12#define CTL_MAX_DEPTH 7
13
14typedef struct ctl_node_s {
15 bool named;
16} ctl_node_t;
17
18typedef struct ctl_named_node_s {
19 ctl_node_t node;
20 const char *name;
21 /* If (nchildren == 0), this is a terminal node. */
22 size_t nchildren;
23 const ctl_node_t *children;
24 int (*ctl)(tsd_t *, const size_t *, size_t, void *, size_t *, void *,
25 size_t);
26} ctl_named_node_t;
27
28typedef struct ctl_indexed_node_s {
29 struct ctl_node_s node;
30 const ctl_named_node_t *(*index)(tsdn_t *, const size_t *, size_t,
31 size_t);
32} ctl_indexed_node_t;
33
34typedef struct ctl_arena_stats_s {
35 arena_stats_t astats;
36
37 /* Aggregate stats for small size classes, based on bin stats. */
38 size_t allocated_small;
39 uint64_t nmalloc_small;
40 uint64_t ndalloc_small;
41 uint64_t nrequests_small;
42 uint64_t nfills_small;
43 uint64_t nflushes_small;
44
45 bin_stats_data_t bstats[SC_NBINS];
46 arena_stats_large_t lstats[SC_NSIZES - SC_NBINS];
47 pac_estats_t estats[SC_NPSIZES];
48 hpa_shard_stats_t hpastats;
49 sec_stats_t secstats;
50} ctl_arena_stats_t;
51
52typedef struct ctl_stats_s {
53 size_t allocated;
54 size_t active;
55 size_t metadata;
56 size_t metadata_thp;
57 size_t resident;
58 size_t mapped;
59 size_t retained;
60
61 background_thread_stats_t background_thread;
62 mutex_prof_data_t mutex_prof_data[mutex_prof_num_global_mutexes];
63} ctl_stats_t;
64
65typedef struct ctl_arena_s ctl_arena_t;
66struct ctl_arena_s {
67 unsigned arena_ind;
68 bool initialized;
69 ql_elm(ctl_arena_t) destroyed_link;
70
71 /* Basic stats, supported even if !config_stats. */
72 unsigned nthreads;
73 const char *dss;
74 ssize_t dirty_decay_ms;
75 ssize_t muzzy_decay_ms;
76 size_t pactive;
77 size_t pdirty;
78 size_t pmuzzy;
79
80 /* NULL if !config_stats. */
81 ctl_arena_stats_t *astats;
82};
83
84typedef struct ctl_arenas_s {
85 uint64_t epoch;
86 unsigned narenas;
87 ql_head(ctl_arena_t) destroyed;
88
89 /*
90 * Element 0 corresponds to merged stats for extant arenas (accessed via
91 * MALLCTL_ARENAS_ALL), element 1 corresponds to merged stats for
92 * destroyed arenas (accessed via MALLCTL_ARENAS_DESTROYED), and the
93 * remaining MALLOCX_ARENA_LIMIT elements correspond to arenas.
94 */
95 ctl_arena_t *arenas[2 + MALLOCX_ARENA_LIMIT];
96} ctl_arenas_t;
97
98int ctl_byname(tsd_t *tsd, const char *name, void *oldp, size_t *oldlenp,
99 void *newp, size_t newlen);
100int ctl_nametomib(tsd_t *tsd, const char *name, size_t *mibp, size_t *miblenp);
101int ctl_bymib(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp,
102 size_t *oldlenp, void *newp, size_t newlen);
103int ctl_mibnametomib(tsd_t *tsd, size_t *mib, size_t miblen, const char *name,
104 size_t *miblenp);
105int ctl_bymibname(tsd_t *tsd, size_t *mib, size_t miblen, const char *name,
106 size_t *miblenp, void *oldp, size_t *oldlenp, void *newp, size_t newlen);
107bool ctl_boot(void);
108void ctl_prefork(tsdn_t *tsdn);
109void ctl_postfork_parent(tsdn_t *tsdn);
110void ctl_postfork_child(tsdn_t *tsdn);
111void ctl_mtx_assert_held(tsdn_t *tsdn);
112
113#define xmallctl(name, oldp, oldlenp, newp, newlen) do { \
114 if (je_mallctl(name, oldp, oldlenp, newp, newlen) \
115 != 0) { \
116 malloc_printf( \
117 "<jemalloc>: Failure in xmallctl(\"%s\", ...)\n", \
118 name); \
119 abort(); \
120 } \
121} while (0)
122
123#define xmallctlnametomib(name, mibp, miblenp) do { \
124 if (je_mallctlnametomib(name, mibp, miblenp) != 0) { \
125 malloc_printf("<jemalloc>: Failure in " \
126 "xmallctlnametomib(\"%s\", ...)\n", name); \
127 abort(); \
128 } \
129} while (0)
130
131#define xmallctlbymib(mib, miblen, oldp, oldlenp, newp, newlen) do { \
132 if (je_mallctlbymib(mib, miblen, oldp, oldlenp, newp, \
133 newlen) != 0) { \
134 malloc_write( \
135 "<jemalloc>: Failure in xmallctlbymib()\n"); \
136 abort(); \
137 } \
138} while (0)
139
140#define xmallctlmibnametomib(mib, miblen, name, miblenp) do { \
141 if (ctl_mibnametomib(tsd_fetch(), mib, miblen, name, miblenp) \
142 != 0) { \
143 malloc_write( \
144 "<jemalloc>: Failure in ctl_mibnametomib()\n"); \
145 abort(); \
146 } \
147} while (0)
148
149#define xmallctlbymibname(mib, miblen, name, miblenp, oldp, oldlenp, \
150 newp, newlen) do { \
151 if (ctl_bymibname(tsd_fetch(), mib, miblen, name, miblenp, \
152 oldp, oldlenp, newp, newlen) != 0) { \
153 malloc_write( \
154 "<jemalloc>: Failure in ctl_bymibname()\n"); \
155 abort(); \
156 } \
157} while (0)
158
159#endif /* JEMALLOC_INTERNAL_CTL_H */
160