1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//! Per-branch atomic counter instrumentation for `thread_free`.
//!
//! This opt-in probe surfaces which `thread_free` commit arm serves a
//! deallocation workload. It only compiles when the `dealloc-probe`
//! Cargo feature is enabled, so default builds do not include the
//! module or call sites.
//!
//! # Surface
//!
//! [`DeallocPath`] enumerates the five commit points in
//! `thread_free_classified`:
//!
//! 1. [`DeallocPath::HugeClassifier`] — `page.block_size == 0` branch
//! reached (rare on the `large_8192` row).
//! 2. [`DeallocPath::InPlaceSmall`] — same-owner active-page free
//! that stays in the active list (page_alloc_count>1 or current
//! segment).
//! 3. [`DeallocPath::ActiveFreeLastBlock`] — same-owner active-page
//! free of the *last* live block (page_alloc_count==1 or non-current
//! segment); the page may or may not actually transition to
//! `empty_pages` because the `is_only_active` short-circuit leaves
//! a sole active page in place. Counter records the arm the dealloc
//! reached, not the page-list mutation (the mutation is a refcount
//! detail tracked separately).
//! 4. [`DeallocPath::FullToActive`] — full page transitions back to
//! the active list on first free.
//! 5. [`DeallocPath::ColdOrRecursing`] — `thread_free_cold` fallback
//! for genuinely cross-thread frees, owner-mismatch frees, AND
//! re-entrant frees where `is_allocating == true` made the inner
//! arm fall through without recording a hot-path label. This is
//! a coarse bucket by design (splitting recursing out is a Phase
//! 5 candidate) but it is the *single* bucket every fall-through
//! path lands on, so the partition is sound.
//!
//! # Caveat for `--enforce-thresholds` runs
//!
//! Any `benchmark_summary --enforce-thresholds` invocation that gates
//! an allocator change must run on the default-feature build, not on
//! `--features dealloc-probe`. The probe intentionally adds one
//! Relaxed atomic increment per deallocation commit, so use it only
//! when the goal is to read the branch-mix snapshot.
//!
//! # Layout
//!
//! Five `AtomicU64` counters live in a single `[AtomicU64; 5]` static.
//! [`record`] does a Relaxed `fetch_add(1)`, so the bench hot-path
//! pays one Relaxed atomic increment per dealloc. The probe is only
//! wired at *commit* points (just
//! before a `return` or fall-through), so the recorded count reflects
//! the branch the dealloc actually took, not the path the dealloc
//! entered but later bounced out of via a corruption guard.
//!
//! [`reset`] is **not** synchronized against concurrent `record()`
//! calls (uses `Ordering::Relaxed` per counter). Callers that need a
//! scoped measurement window MUST ensure all prior deallocations have
//! retired before calling `reset()` — in the single-threaded bench
//! A/B scenario this is satisfied implicitly.
//!
//! # Read
//!
//! [`snapshot`] returns a fixed-size `[(DeallocPath, &'static str, u64); 5]`
//! suitable for `println!` or log capture. [`reset`] zeroes the
//! counters so a fresh measurement window can start; pair with a
//! test or post-bench hook to surface the data without committing to
//! a particular harness plumbing in the hot path.
use ;
static COUNTS: = ;
/// Records that `path` was committed by the calling deallocation.
///
/// Always-on when the `dealloc-probe` feature is enabled. The atomic
/// increment uses Relaxed ordering — the dealloc fast-path pays a
/// single uncontended atomic increment. Gate the call site with
/// `#[cfg(feature = "dealloc-probe")]` so production builds
/// eliminate both the call and the load/store entirely.
/// Returns `(path, name, count)` rows in the order
/// [`DeallocPath::ALL`] walks. Useful for snapshotting before/after
/// a benchmark run without committing to a particular output
/// harness.
/// Zeroes every counter. Pair with [`snapshot`] to scope a
/// measurement window — call before the bench pass, call after.
/// Sum across all five counters. Useful for asserting in tests
/// that `total == bundle_call_count`.