Skip to content

Commit 422174e

Browse files
authored
flambda-backend: Ports #1156 (Shrink the ref_table if it grows large) (#2056)
1 parent cda2a5e commit 422174e

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

runtime/minor_gc.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,20 @@ static void reset_table (struct generic_table *tbl)
8282
tbl->base = tbl->ptr = tbl->threshold = tbl->limit = tbl->end = NULL;
8383
}
8484

85-
static void clear_table (struct generic_table *tbl)
85+
static void clear_table (struct generic_table *tbl,
86+
asize_t element_size,
87+
const char *name)
8688
{
89+
asize_t maxsz = Caml_state->minor_heap_wsz;
90+
if (tbl->size <= maxsz) {
8791
tbl->ptr = tbl->base;
8892
tbl->limit = tbl->threshold;
93+
} else {
94+
caml_gc_message (0x08, "Shrinking %s to %ldk bytes\n",
95+
name,
96+
(long)((maxsz * element_size) / 1024));
97+
alloc_generic_table(tbl, Caml_state->minor_heap_wsz, 256, element_size);
98+
}
8999
}
90100

91101
struct caml_minor_tables* caml_alloc_minor_tables(void)
@@ -448,9 +458,15 @@ void caml_empty_minor_heap_domain_clear(caml_domain_state* domain)
448458

449459
caml_final_empty_young(domain);
450460

451-
clear_table ((struct generic_table *)&minor_tables->major_ref);
452-
clear_table ((struct generic_table *)&minor_tables->ephe_ref);
453-
clear_table ((struct generic_table *)&minor_tables->custom);
461+
clear_table ((struct generic_table *)&minor_tables->major_ref,
462+
sizeof(value *),
463+
"major_ref");
464+
clear_table ((struct generic_table *)&minor_tables->ephe_ref,
465+
sizeof(struct caml_ephe_ref_elt),
466+
"ephe_ref");
467+
clear_table ((struct generic_table *)&minor_tables->custom,
468+
sizeof(struct caml_custom_elt),
469+
"custom");
454470

455471
domain->extra_heap_resources_minor = 0.0;
456472
}

0 commit comments

Comments
 (0)