Skip to content

Ports #1156 (Shrink the ref_table if it grows large) #2056

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 22, 2023
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
24 changes: 20 additions & 4 deletions ocaml/runtime/minor_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,20 @@ static void reset_table (struct generic_table *tbl)
tbl->base = tbl->ptr = tbl->threshold = tbl->limit = tbl->end = NULL;
}

static void clear_table (struct generic_table *tbl)
static void clear_table (struct generic_table *tbl,
asize_t element_size,
const char *name)
{
asize_t maxsz = Caml_state->minor_heap_wsz;
if (tbl->size <= maxsz) {
tbl->ptr = tbl->base;
tbl->limit = tbl->threshold;
} else {
caml_gc_message (0x08, "Shrinking %s to %ldk bytes\n",
name,
(long)((maxsz * element_size) / 1024));
alloc_generic_table(tbl, Caml_state->minor_heap_wsz, 256, element_size);
}
}

struct caml_minor_tables* caml_alloc_minor_tables(void)
Expand Down Expand Up @@ -448,9 +458,15 @@ void caml_empty_minor_heap_domain_clear(caml_domain_state* domain)

caml_final_empty_young(domain);

clear_table ((struct generic_table *)&minor_tables->major_ref);
clear_table ((struct generic_table *)&minor_tables->ephe_ref);
clear_table ((struct generic_table *)&minor_tables->custom);
clear_table ((struct generic_table *)&minor_tables->major_ref,
sizeof(value *),
"major_ref");
clear_table ((struct generic_table *)&minor_tables->ephe_ref,
sizeof(struct caml_ephe_ref_elt),
"ephe_ref");
clear_table ((struct generic_table *)&minor_tables->custom,
sizeof(struct caml_custom_elt),
"custom");

domain->extra_heap_resources_minor = 0.0;
}
Expand Down