Skip to content

Fix GC pacing problem exacerbated by mark-delay #3331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,27 @@ static void update_major_slice_work(intnat howmuch,
atomic_fetch_add (&work_counter, dom_st->major_work_done_between_slices);
dom_st->major_work_done_between_slices = 0;
atomic_fetch_add (&alloc_counter, new_work);

/* If the work_counter is falling far behind the alloc_counter,
* artificially catch up some of the difference. This is a band-aid
* for general GC pacing problems revealed by the mark-delay changes
* (see comments on ocaml/ocaml PR #13580): when we rework the
* pacing this should go away. */
int64_t pending = diffmod(atomic_load(&alloc_counter),
atomic_load(&work_counter));
if (pending > (int64_t)total_cycle_work * 2) {
intnat catchup = pending - total_cycle_work;
caml_gc_message(0x40,
"work counter %"ARCH_INTNAT_PRINTF_FORMAT"u falling behind "
"alloc counter %"ARCH_INTNAT_PRINTF_FORMAT"u by more than "
"twice a total cycle's work %"ARCH_INTNAT_PRINTF_FORMAT"d; "
"catching up by %"ARCH_INTNAT_PRINTF_FORMAT "d\n",
atomic_load(&work_counter),
atomic_load(&alloc_counter),
total_cycle_work, catchup);
atomic_fetch_add (&work_counter, catchup);
}

if (howmuch == AUTO_TRIGGERED_MAJOR_SLICE ||
howmuch == GC_CALCULATE_MAJOR_SLICE) {
dom_st->slice_target = atomic_load (&alloc_counter);
Expand Down
Loading