]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/jemalloc/include/jemalloc/internal/ctl.h
Update jemalloc to version 5.1.0.
[FreeBSD/FreeBSD.git] / contrib / jemalloc / include / jemalloc / internal / ctl.h
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/size_classes.h"
9 #include "jemalloc/internal/stats.h"
10
11 /* Maximum ctl tree depth. */
12 #define CTL_MAX_DEPTH   7
13
14 typedef struct ctl_node_s {
15         bool named;
16 } ctl_node_t;
17
18 typedef 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
28 typedef 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
34 typedef 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
43         bin_stats_t bstats[NBINS];
44         arena_stats_large_t lstats[NSIZES - NBINS];
45 } ctl_arena_stats_t;
46
47 typedef struct ctl_stats_s {
48         size_t allocated;
49         size_t active;
50         size_t metadata;
51         size_t metadata_thp;
52         size_t resident;
53         size_t mapped;
54         size_t retained;
55
56         background_thread_stats_t background_thread;
57         mutex_prof_data_t mutex_prof_data[mutex_prof_num_global_mutexes];
58 } ctl_stats_t;
59
60 typedef struct ctl_arena_s ctl_arena_t;
61 struct ctl_arena_s {
62         unsigned arena_ind;
63         bool initialized;
64         ql_elm(ctl_arena_t) destroyed_link;
65
66         /* Basic stats, supported even if !config_stats. */
67         unsigned nthreads;
68         const char *dss;
69         ssize_t dirty_decay_ms;
70         ssize_t muzzy_decay_ms;
71         size_t pactive;
72         size_t pdirty;
73         size_t pmuzzy;
74
75         /* NULL if !config_stats. */
76         ctl_arena_stats_t *astats;
77 };
78
79 typedef struct ctl_arenas_s {
80         uint64_t epoch;
81         unsigned narenas;
82         ql_head(ctl_arena_t) destroyed;
83
84         /*
85          * Element 0 corresponds to merged stats for extant arenas (accessed via
86          * MALLCTL_ARENAS_ALL), element 1 corresponds to merged stats for
87          * destroyed arenas (accessed via MALLCTL_ARENAS_DESTROYED), and the
88          * remaining MALLOCX_ARENA_LIMIT elements correspond to arenas.
89          */
90         ctl_arena_t *arenas[2 + MALLOCX_ARENA_LIMIT];
91 } ctl_arenas_t;
92
93 int ctl_byname(tsd_t *tsd, const char *name, void *oldp, size_t *oldlenp,
94     void *newp, size_t newlen);
95 int ctl_nametomib(tsd_t *tsd, const char *name, size_t *mibp, size_t *miblenp);
96
97 int ctl_bymib(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp,
98     size_t *oldlenp, void *newp, size_t newlen);
99 bool ctl_boot(void);
100 void ctl_prefork(tsdn_t *tsdn);
101 void ctl_postfork_parent(tsdn_t *tsdn);
102 void ctl_postfork_child(tsdn_t *tsdn);
103
104 #define xmallctl(name, oldp, oldlenp, newp, newlen) do {                \
105         if (je_mallctl(name, oldp, oldlenp, newp, newlen)               \
106             != 0) {                                                     \
107                 malloc_printf(                                          \
108                     "<jemalloc>: Failure in xmallctl(\"%s\", ...)\n",   \
109                     name);                                              \
110                 abort();                                                \
111         }                                                               \
112 } while (0)
113
114 #define xmallctlnametomib(name, mibp, miblenp) do {                     \
115         if (je_mallctlnametomib(name, mibp, miblenp) != 0) {            \
116                 malloc_printf("<jemalloc>: Failure in "                 \
117                     "xmallctlnametomib(\"%s\", ...)\n", name);          \
118                 abort();                                                \
119         }                                                               \
120 } while (0)
121
122 #define xmallctlbymib(mib, miblen, oldp, oldlenp, newp, newlen) do {    \
123         if (je_mallctlbymib(mib, miblen, oldp, oldlenp, newp,           \
124             newlen) != 0) {                                             \
125                 malloc_write(                                           \
126                     "<jemalloc>: Failure in xmallctlbymib()\n");        \
127                 abort();                                                \
128         }                                                               \
129 } while (0)
130
131 #endif /* JEMALLOC_INTERNAL_CTL_H */