tikv_jemalloc_ctl/stats.rs
1//! Global allocator statistics.
2//!
3//! `jemalloc` tracks a wide variety of statistics. Many of them are cached, and
4//! only refreshed when the `jemalloc` "epoch" is advanced. See the [`crate::epoch`] type
5//! for more information.
6
7option! {
8 allocated[ str: b"stats.allocated\0", non_str: 2 ] => libc::size_t |
9 ops: r |
10 docs:
11 /// Total number of bytes allocated by the application.
12 ///
13 /// This statistic is cached, and is only refreshed when the epoch is
14 /// advanced. See the [`crate::epoch`] type for more information.
15 ///
16 /// This corresponds to `stats.allocated` in jemalloc's API.
17 ///
18 /// # Examples
19 ///
20 /// ```rust
21 /// # #[global_allocator]
22 /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
23 /// #
24 /// # fn main() {
25 /// use tikv_jemalloc_ctl::{epoch, stats};
26 /// let e = epoch::mib().unwrap();
27 /// let allocated = stats::allocated::mib().unwrap();
28 ///
29 /// let a = allocated.read().unwrap();
30 /// let _buf = vec![0; 1024 * 1024];
31 /// e.advance().unwrap();
32 /// let b = allocated.read().unwrap();
33 /// assert!(a < b);
34 /// # }
35 /// ```
36 mib_docs: /// See [`allocated`].
37}
38
39option! {
40 active[ str: b"stats.active\0", non_str: 2 ] => libc::size_t |
41 ops: r |
42 docs:
43 /// Total number of bytes in active pages allocated by the application.
44 ///
45 /// This is a multiple of the page size, and greater than or equal to the
46 /// value returned by [`allocated`].
47 ///
48 /// This statistic is cached, and is only refreshed when the epoch is
49 /// advanced. See the [`crate::epoch`] type for more information.
50 ///
51 /// This corresponds to `stats.active` in jemalloc's API.
52 ///
53 /// # Examples
54 ///
55 /// ```rust
56 /// # #[global_allocator]
57 /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
58 /// #
59 /// # fn main() {
60 /// use tikv_jemalloc_ctl::{epoch, stats};
61 /// let e = epoch::mib().unwrap();
62 /// let active = stats::active::mib().unwrap();
63 ///
64 /// let a = active.read().unwrap();
65 /// let _buf = vec![0; 1024 * 1024];
66 /// e.advance().unwrap();
67 /// let b = active.read().unwrap();
68 /// assert!(a < b);
69 /// # }
70 /// ```
71 mib_docs: /// See [`active`].
72}
73
74option! {
75 metadata[ str: b"stats.metadata\0", non_str: 2 ] => libc::size_t |
76 ops: r |
77 docs:
78 /// Total number of bytes dedicated to `jemalloc` metadata.
79 ///
80 /// This statistic is cached, and is only refreshed when the epoch is
81 /// advanced. See the [`crate::epoch`] type for more information.
82 ///
83 /// This corresponds to `stats.metadata` in jemalloc's API.
84 ///
85 /// # Examples
86 ///
87 /// ```rust
88 /// # #[global_allocator]
89 /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
90 /// #
91 /// # fn main() {
92 /// use tikv_jemalloc_ctl::{epoch, stats};
93 /// let e = epoch::mib().unwrap();
94 /// let metadata = stats::metadata::mib().unwrap();
95 ///
96 /// e.advance().unwrap();
97 /// let size = metadata.read().unwrap();
98 /// println!("{} bytes of jemalloc metadata", size);
99 /// # }
100 /// ```
101 mib_docs: /// See [`metadata`].
102}
103
104option! {
105 resident[ str: b"stats.resident\0", non_str: 2 ] => libc::size_t |
106 ops: r |
107 docs:
108 /// Total number of bytes in physically resident data pages mapped by the
109 /// allocator.
110 ///
111 /// This consists of all pages dedicated to allocator metadata, pages
112 /// backing active allocations, and unused dirty pages. It may overestimate
113 /// the true value because pages may not actually be physically resident if
114 /// they correspond to demand-zeroed virtual memory that has not yet been
115 /// touched. This is a multiple of the page size, and is larger than the
116 /// value returned by [`active`].
117 ///
118 /// This statistic is cached, and is only refreshed when the epoch is
119 /// advanced. See the [`crate::epoch`] type for more information.
120 ///
121 /// This corresponds to `stats.resident` in jemalloc's API.
122 ///
123 /// # Examples
124 ///
125 /// ```rust
126 /// # #[global_allocator]
127 /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
128 /// #
129 /// # fn main() {
130 /// use tikv_jemalloc_ctl::{epoch, stats};
131 /// let e = epoch::mib().unwrap();
132 /// let resident = stats::resident::mib().unwrap();
133 ///
134 /// e.advance().unwrap();
135 /// let size = resident.read().unwrap();
136 /// println!("{} bytes of total resident data", size);
137 /// # }
138 /// ```
139 mib_docs: /// See [`resident`].
140}
141
142option! {
143 mapped[ str: b"stats.mapped\0", non_str: 2 ] => libc::size_t |
144 ops: r |
145 docs:
146 /// Total number of bytes in active extents mapped by the allocator.
147 ///
148 /// This does not include inactive extents, even those that contain unused
149 /// dirty pages, so there is no strict ordering between this and the value
150 /// returned by [`resident`]. This is a multiple of the page size, and is
151 /// larger than the value returned by [`active`].
152 ///
153 /// This statistic is cached, and is only refreshed when the epoch is
154 /// advanced. See the [`crate::epoch`] type for more information.
155 ///
156 /// This corresponds to `stats.mapped` in jemalloc's API.
157 ///
158 /// # Examples
159 ///
160 /// ```rust
161 /// # #[global_allocator]
162 /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
163 /// #
164 /// # fn main() {
165 /// use tikv_jemalloc_ctl::{epoch, stats};
166 /// let e = epoch::mib().unwrap();
167 /// let mapped = stats::mapped::mib().unwrap();
168 ///
169 /// e.advance().unwrap();
170 /// let size = mapped.read().unwrap();
171 /// println!("{} bytes of total mapped data", size);
172 /// # }
173 /// ```
174 mib_docs: /// See [`mapped`].
175}
176
177option! {
178 retained[ str: b"stats.retained\0", non_str: 2 ] => libc::size_t |
179 ops: r |
180 docs:
181 /// Total number of bytes in virtual memory mappings that were retained
182 /// rather than being returned to the operating system via e.g. `munmap(2)`.
183 ///
184 /// Retained virtual memory is typically untouched, decommitted, or purged,
185 /// so it has no strongly associated physical memory. Retained memory is
186 /// excluded from mapped memory statistics, e.g. [`mapped`].
187 ///
188 /// This statistic is cached, and is only refreshed when the epoch is
189 /// advanced. See the [`crate::epoch`] type for more information.
190 ///
191 /// This corresponds to `stats.retained` in jemalloc's API.
192 ///
193 /// # Examples
194 ///
195 /// ```rust
196 /// # #[global_allocator]
197 /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
198 /// #
199 /// # fn main() {
200 /// use tikv_jemalloc_ctl::{epoch, stats};
201 /// let e = epoch::mib().unwrap();
202 /// let retained = stats::retained::mib().unwrap();
203 ///
204 /// e.advance().unwrap();
205 /// let size = retained.read().unwrap();
206 /// println!("{} bytes of total retained data", size);
207 /// # }
208 /// ```
209 mib_docs: /// See [`retained`].
210}