Commit 4d183aa
feat: Add S4-FIFO algo (#335)
* feat: Add S4-FIFO algo
* fix(s4fifo): address review findings on child sizing, warmup and feature tracking
Five fixes from the review of the S4-FIFO PR:
- Size each sub-FIFO's hash table from its own byte size, capped by any
requested --hashpower, rather than inheriting the parent's. Previously a
single S4FIFO allocated three full-size tables; at a 1GiB cache size peak
RSS drops from 527MiB to 338MiB, matching S3FIFO's 340MiB, with an
identical miss ratio.
- Leave WARMUP on the first capacity eviction instead of when occupancy
reaches cache_size. Eviction runs before occupancy can exceed the limit,
so the old test needed the trace to fill the cache exactly and in practice
never fired: on cloudPhysicsIO the learned mode spent the whole trace in
warmup and never predicted a configuration.
- Only pre-scan the trace for its request count when an algorithm actually
reads it. Every cachesim and MRC run paid for a full extra pass, which on
a txt or zstd trace costs as much as the simulation (LRU on a 1M-request
csv: 0.48s -> 0.33s).
- Stop double-counting one-hit-wonders: S4FIFO_track_ghost_insert already
records them, so the extra call doubled one_hit_count whenever a ghost
FIFO was configured.
- Stamp clock reinsertions in the main FIFO with S4FIFO_track_main_insert.
A reinserted object takes a fresh tail position but kept a stale
insert_seq, skewing the main queue's hit-position histogram.
The eviction path itself is unchanged: the static heuristic still matches
S3-FIFO exactly, and the full test suite passes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(s4fifo): propagate n_total_req through cloning, and fix ghost-queue tracking
Second round of review fixes.
- Adding n_total_req grew common_cache_params_t from 24 to 32 bytes, but
clone_cache and create_cache_with_new_size still asserted the old size, so
any assertion-enabled build aborted in simulate_at_multi_sizes (testSimulator
exited 134 under -DCMAKE_BUILD_TYPE=Debug). That assert was a tripwire for
exactly the bug that had happened - both functions rebuild the struct field
by field and were silently dropping the new field - so copy n_total_req in
both, retain it on cache_t to copy it from, and make the tripwire a
_Static_assert. As a runtime assert it was compiled out of release builds and
so never fired in CI; now it breaks the build for everyone, which is the
point. Verified it still trips by adding a scratch field.
- MINISIM hardcoded n_total_req = 0 even though it had just counted the trace,
so the default fractional feature-collect-reqs fell back to a fixed 10000 and
MRC disagreed with cachesim. Pass sampled_cnt - not n_req_, since spatial
sampling drops requests before the cache sees them, so sampled_cnt is what
cache->n_req climbs to. On twitter_cluster52 at wss 0.055 the miss ratio goes
0.216370 -> 0.205729, and the curve now matches cachesim exactly (0.299438
and 0.185243 against 0.2994 and 0.1852).
- S4FIFO_track_ghost_insert returned early outside a collection window, so
objects inserted during warmup or between windows kept a zero insert_seq and
ghost_insert_seq froze. A later hit inside a window was then scored against a
stamp from a different sequence. Always stamp and advance, as the small and
main helpers do, and gate only the per-window one-hit counter. Costs ~1%
throughput (4.82 -> 4.78 MQPS) for the extra lookup.
- record_ghost_removal ran on every ghost hit, but with a positive
ghost-to-main-threshold the entry deliberately stays in the queue. The
tracker subtracts recorded removals as holes from later hit positions, so
this invented holes that were never there; record it only in the branch that
actually removes.
Release and Debug both build clean and pass all 10 tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 9fc2edd commit 4d183aa
24 files changed
Lines changed: 90567 additions & 20 deletions
File tree
- libCacheSim
- bin
- MRC
- cachesim
- traceUtils
- cache
- eviction/S4FIFO
- include/libCacheSim
- mrcProfiler
- scripts
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
192 | 193 | | |
193 | 194 | | |
194 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
195 | 201 | | |
196 | 202 | | |
197 | 203 | | |
| |||
202 | 208 | | |
203 | 209 | | |
204 | 210 | | |
| 211 | + | |
205 | 212 | | |
206 | 213 | | |
207 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
332 | 344 | | |
333 | 345 | | |
334 | 346 | | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
339 | 351 | | |
340 | 352 | | |
341 | 353 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
20 | 34 | | |
21 | 35 | | |
22 | 36 | | |
| |||
32 | 46 | | |
33 | 47 | | |
34 | 48 | | |
35 | | - | |
| 49 | + | |
| 50 | + | |
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| 56 | + | |
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
359 | 375 | | |
360 | 376 | | |
361 | 377 | | |
362 | 378 | | |
363 | 379 | | |
364 | | - | |
| 380 | + | |
| 381 | + | |
365 | 382 | | |
366 | 383 | | |
367 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
101 | 111 | | |
102 | 112 | | |
103 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
20 | 35 | | |
21 | 36 | | |
22 | 37 | | |
| |||
37 | 52 | | |
38 | 53 | | |
39 | 54 | | |
| 55 | + | |
40 | 56 | | |
41 | 57 | | |
42 | 58 | | |
| |||
95 | 111 | | |
96 | 112 | | |
97 | 113 | | |
| 114 | + | |
98 | 115 | | |
99 | | - | |
| 116 | + | |
100 | 117 | | |
101 | 118 | | |
102 | 119 | | |
| |||
121 | 138 | | |
122 | 139 | | |
123 | 140 | | |
| 141 | + | |
124 | 142 | | |
125 | | - | |
| 143 | + | |
126 | 144 | | |
127 | 145 | | |
128 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| |||
0 commit comments