Commit aaaacf2
authored
Backport OCaml ocaml#13736 to 5.3.0-semgrep (#26)
## Summary
Backport [ocaml#13736](ocaml#13736) to `5.3.0-semgrep`.
Synchronous major collections advance the major GC work counter without corresponding allocation. After `Gc.major`, `Gc.full_major`, or `Gc.compact`, the work counter can therefore remain far ahead of the allocation counter, suppressing subsequent automatic major GC slices until allocation catches up. On a large heap this can cause rapid heap growth or OOM after an explicit collection.
The upstream fix resets the allocation and work counters to the same logical clock after synchronous major GC work. This is relevant to Semgrep because its memory-limit handler calls `Gc.compact` before reraising an OOM or memory-limit exception.
## Backport Notes
The three runtime changes apply to OCaml 5.3 without adaptation and match upstream ocaml#13736:
- Add `caml_reset_major_pacing`.
- Invoke it after explicit major collection work, including each `Gc.full_major` and `Gc.compact` cycle.
- Omit the conflicting upstream `Changes` entry, since this is a Semgrep-fork backport.
No compiler or Semgrep-specific code is changed.
## Validation
- Clean Flambda bootstrap of the exact branch:
`./configure --enable-flambda && make -j8`
- Confirmed the resulting compiler reports `flambda: true`.
- Compiled an identical post-compaction pacing workload with unpatched and patched 5.3 runtimes. The workload compacts a 320 MiB live heap, drops it, and then performs short-lived major allocations:
- Unpatched: reached the 768 MiB guard after 17,900 iterations; heap reached 801 MiB with only 2 automatic major cycles.
- Patched: completed 100,000 iterations; final heap returned to 0 MiB with 10,169 automatic major cycles.3 files changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
| |||
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
| 266 | + | |
265 | 267 | | |
266 | 268 | | |
267 | 269 | | |
| |||
297 | 299 | | |
298 | 300 | | |
299 | 301 | | |
| 302 | + | |
300 | 303 | | |
301 | 304 | | |
302 | 305 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
576 | 576 | | |
577 | 577 | | |
578 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
579 | 603 | | |
580 | 604 | | |
581 | 605 | | |
| |||
0 commit comments