Skip to content

Commit

Permalink
Hack to work around accounting problem: artificially catch-up work_co…
Browse files Browse the repository at this point in the history
…unter at the start of any slice when it falls very far behind alloc_counter.
  • Loading branch information
NickBarnes committed Dec 10, 2024
1 parent 6d6a3cc commit 6eb0f2d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,30 @@ update_major_slice_work(intnat howmuch,
extra_work);

new_work = max3 (alloc_work, dependent_work, extra_work);
atomic_fetch_add (&alloc_counter, new_work);

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
* (PR #13580). */
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(SLICESIZE,
"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 Expand Up @@ -1874,7 +1895,7 @@ static void major_collection_slice(intnat howmuch,
if (log_events) CAML_EV_END(EV_MAJOR_SWEEP);
}

if (domain_state->sweeping_done) {
if (domain_state->sweeping_done && !caml_marking_started()) {
/* We do not immediately trigger a minor GC, but instead wait for
* the next one to happen normally. This gives some chance that
* other domains will finish sweeping as well.
Expand Down

0 comments on commit 6eb0f2d

Please sign in to comment.