Skip to content
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

Fix spurious major GC slices. #13086

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ _______________
- #13003: new, more consistent names for array-creation C functions
(Gabriel Scherer, review by Olivier Nicole)

- #13086: Avoid spurious major GC slices.
(Damien Doligez, report by Stephen Dolan, review by Gabriel Scherer
and Stephen Dolan)

### Code generation and optimizations:

- #13014: Enable compile-time option -function-sections on all previously
Expand Down
6 changes: 6 additions & 0 deletions runtime/caml/domain_state.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ DOMAIN_STATE(uintnat, sweeping_done)
/* Is sweeping done for the current major cycle. */

DOMAIN_STATE(uintnat, allocated_words)
/* Number of words promoted or allocated directly to the major heap since
latest slice. */

DOMAIN_STATE(uintnat, allocated_words_direct)
/* Number of words allocated directly to the major heap since the latest
slice. (subset of allocated_words) */

DOMAIN_STATE(uintnat, swept_words)

Expand Down
1 change: 1 addition & 0 deletions runtime/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ static void domain_create(uintnat initial_minor_heap_wsize,
domain_state->gc_regs = NULL;

domain_state->allocated_words = 0;
domain_state->allocated_words_direct = 0;
domain_state->swept_words = 0;

domain_state->local_roots = NULL;
Expand Down
3 changes: 2 additions & 1 deletion runtime/intern.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,12 @@ static value intern_alloc_obj(struct caml_intern_state* s, caml_domain_state* d,
} else {
p = caml_shared_try_alloc(d->shared_heap, wosize, tag,
0 /* no reserved bits */);
d->allocated_words += Whsize_wosize(wosize);
if (p == NULL) {
intern_cleanup (s);
caml_raise_out_of_memory();
}
d->allocated_words += Whsize_wosize(wosize);
d->allocated_words_direct += Whsize_wosize(wosize);
Hd_hp(p) = Make_header (wosize, tag, caml_global_heap_state.MARKED);
caml_memprof_sample_block(Val_hp(p), wosize,
Whsize_wosize(wosize),
Expand Down
8 changes: 7 additions & 1 deletion runtime/major_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,16 +627,18 @@ static void update_major_slice_work(intnat howmuch,
{
double heap_words;
intnat alloc_work, dependent_work, extra_work, new_work;
intnat my_alloc_count, my_dependent_count;
intnat my_alloc_count, my_alloc_direct_count, my_dependent_count;
double my_extra_count;
caml_domain_state *dom_st = Caml_state;
uintnat heap_size, heap_sweep_words, total_cycle_work;

my_alloc_count = dom_st->allocated_words;
my_alloc_direct_count = dom_st->allocated_words_direct;
my_dependent_count = dom_st->dependent_allocated;
my_extra_count = dom_st->extra_heap_resources;
dom_st->stat_major_words += dom_st->allocated_words;
dom_st->allocated_words = 0;
dom_st->allocated_words_direct = 0;
dom_st->dependent_allocated = 0;
dom_st->extra_heap_resources = 0.0;
/*
Expand Down Expand Up @@ -708,6 +710,9 @@ static void update_major_slice_work(intnat howmuch,
caml_gc_message (0x40, "allocated_words = %"
ARCH_INTNAT_PRINTF_FORMAT "u\n",
my_alloc_count);
caml_gc_message (0x40, "allocated_words_direct = %"
ARCH_INTNAT_PRINTF_FORMAT "u\n",
my_alloc_direct_count);
caml_gc_message (0x40, "alloc work-to-do = %"
ARCH_INTNAT_PRINTF_FORMAT "d\n",
alloc_work);
Expand Down Expand Up @@ -2015,6 +2020,7 @@ void caml_finish_marking (void)
caml_shrink_mark_stack();
Caml_state->stat_major_words += Caml_state->allocated_words;
Caml_state->allocated_words = 0;
Caml_state->allocated_words_direct = 0;
CAML_EV_END(EV_MAJOR_FINISH_MARKING);
}
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@ Caml_inline value alloc_shr(mlsize_t wosize, tag_t tag, reserved_t reserved,
}

dom_st->allocated_words += Whsize_wosize(wosize);
if (dom_st->allocated_words > dom_st->minor_heap_wsz / 5) {
dom_st->allocated_words_direct += Whsize_wosize(wosize);
if (dom_st->allocated_words_direct > dom_st->minor_heap_wsz / 5) {
CAML_EV_COUNTER (EV_C_REQUEST_MAJOR_ALLOC_SHR, 1);
caml_request_major_slice(1);
}
Expand Down