Commit 67b6697
Fix concurrent SIGSEGV in DLRM forward() and feature extractors (#739)
Summary:
Pull Request resolved: #739
Two thread-safety bugs were causing leaf SIGSEGVs whenever requested QPS exceeded server saturation. The "collapse to 0.5 QPS" observed at over-saturation in t27/t28 was actually the leaf crashing, then the next driver phase achieving only the trickle of completions that landed before the crash.
t27 forensic analysis (2026-05-28) found crashes at BGM/Grace q=100+/inst (100% of iters), CPL q=50+/inst (17-45% of iters depending on QPS). Two distinct crash sites observed:
(A) `torch::jit::InterpreterStateImpl::runTemplate` -> `dlrmInferenceServerSide`. The existing per-clone LIFO checkout (`get_avail_thread_id` / `put_avail_thread_id`) was supposed to prevent concurrent `forward()` calls on the same Module clone (added in D105659812 / t16). It's likely that `torch::jit::Module::clone()` does not fully isolate JIT interpreter state — under high concurrency the leaf still crashed despite the LIFO. Added a per-`ThreadState` `std::mutex forward_mutex` as a safety net. Uncontended when the LIFO is working; serializes calls per clone if it's not, preventing the segfault.
(B) `dcperf::feature_extractors::generated::vc_NNNN_NNNN` -> `std::vector<IdScorePair>::_M_realloc_insert` -> `je_large_dalloc`. The generated extractor code calls `c->example->idScoreLists[i].emplace_back(...)` and `c->structData[i] += ...`. `c->example` pointed at a single shared `flat_example_` member of `FeatureExtractorSuite`, and `c->structData` pointed at a single shared `flat_struct_data_` heap buffer. `LeafNodeRank::DLRMRequestHandler` dispatches `runFeatureExtraction(*this_thread_ptr, ...)` onto the multi-threaded folly GlobalCPUThread singleton, so multiple in-flight requests sharing the same `ThreadData` can hit `runFlatExtractors` concurrently on different worker threads, racing on those shared mutable members. Fixed by making both per-call (`thread_local MockFeatureExample local_example` + `thread_local std::vector<float> local_struct`), with `local_struct` snapshotted from the read-only `flat_struct_data_` template each call.
Also converted `flat_pos_` from `size_t` to `std::atomic<size_t>` and reserve `count` slots in a single `fetch_add` so concurrent calls don't race the cursor.
Read-only state (`flat_tables_`, `flat_hash_tables_`, `flat_features_`, `flat_copies_`) stays shared — extractor code only does `.find()` on tables and never mutates the others.
Reviewed By: YifanYuan3
Differential Revision: D1067318151 parent d1c6354 commit 67b6697
3 files changed
Lines changed: 86 additions & 23 deletions
File tree
- packages/feedsim/third_party/src/workloads/ranking
- dwarfs
- feature_extractors
Lines changed: 22 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
| 56 | + | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
| |||
248 | 259 | | |
249 | 260 | | |
250 | 261 | | |
251 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
252 | 265 | | |
253 | 266 | | |
254 | 267 | | |
255 | 268 | | |
256 | 269 | | |
257 | | - | |
258 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
259 | 273 | | |
260 | 274 | | |
261 | 275 | | |
| |||
299 | 313 | | |
300 | 314 | | |
301 | 315 | | |
302 | | - | |
| 316 | + | |
| 317 | + | |
303 | 318 | | |
304 | 319 | | |
305 | 320 | | |
306 | 321 | | |
307 | 322 | | |
308 | | - | |
309 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
310 | 326 | | |
311 | 327 | | |
312 | 328 | | |
| |||
Lines changed: 46 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
| 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 | + | |
139 | 171 | | |
140 | 172 | | |
141 | | - | |
142 | | - | |
143 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
144 | 176 | | |
145 | 177 | | |
146 | 178 | | |
| |||
150 | 182 | | |
151 | 183 | | |
152 | 184 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
161 | 194 | | |
162 | | - | |
163 | | - | |
| 195 | + | |
164 | 196 | | |
165 | 197 | | |
Lines changed: 18 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
70 | 86 | | |
71 | | - | |
| 87 | + | |
72 | 88 | | |
73 | 89 | | |
74 | 90 | | |
75 | 91 | | |
76 | | - | |
77 | 92 | | |
78 | 93 | | |
0 commit comments