From 49b6cde17800b5bbc4a0a37e935dc609131d59ac Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Wed, 14 Aug 2024 17:48:10 +0100 Subject: [PATCH 1/2] Fixes to domain.c bad merges (cherry picked from commit ace16c42727eb21450dac9fb830571b707aa31e4) --- ocaml/runtime/domain.c | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/ocaml/runtime/domain.c b/ocaml/runtime/domain.c index 4c666a86b03..5510ae4ddde 100644 --- a/ocaml/runtime/domain.c +++ b/ocaml/runtime/domain.c @@ -625,6 +625,10 @@ static void domain_create(uintnat initial_minor_heap_wsize, caml_state = domain_state; domain_state->young_limit = 0; + + domain_state->id = d->id; + domain_state->unique_id = s->unique_id; + /* Synchronized with [caml_interrupt_all_signal_safe], so that the initializing write of young_limit happens before any interrupt. */ @@ -639,26 +643,6 @@ static void domain_create(uintnat initial_minor_heap_wsize, goto init_memprof_failure; } - /* Set domain_self if we have successfully allocated the - * caml_domain_state. Otherwise domain_self will be NULL and it's up - * to the caller to deal with that. */ - - domain_self = d; - caml_state = domain_state; - - domain_state->young_limit = 0; - - domain_state->id = d->id; - domain_state->unique_id = s->unique_id; - - /* Tell memprof system about the new domain before either (a) new - * domain can allocate anything or (b) parent domain can go away. */ - CAMLassert(domain_state->memprof == NULL); - caml_memprof_new_domain(parent, domain_state); - if (!domain_state->memprof) { - goto init_memprof_failure; - } - CAMLassert(!s->interrupt_pending); domain_state->extra_heap_resources = 0.0; @@ -770,6 +754,7 @@ static void domain_create(uintnat initial_minor_heap_wsize, domain_state->trap_barrier_block = -1; #endif + caml_reset_young_limit(domain_state); add_next_to_stw_domains(); goto domain_init_complete; @@ -1687,6 +1672,8 @@ void caml_reset_young_limit(caml_domain_state * dom_st) (uintnat)dom_st->memprof_young_trigger); CAMLassert ((uintnat)dom_st->young_ptr >= (uintnat)dom_st->young_trigger); + /* An interrupt might have been queued in the meanwhile; this + achieves the proper synchronisation. */ atomic_exchange(&dom_st->young_limit, (uintnat)trigger); /* For non-delayable asynchronous actions, we immediately interrupt @@ -1797,11 +1784,6 @@ void caml_poll_gc_work(void) } caml_reset_young_limit(d); - - if (atomic_load_acquire(&d->requested_external_interrupt)) { - /* This function might allocate (e.g. upon a systhreads yield). */ - caml_domain_external_interrupt_hook(); - } } void caml_handle_gc_interrupt(void) From 1eeb7517274f1d9d7ac2ae4ba568bd558ee66bde Mon Sep 17 00:00:00 2001 From: Mark Shinwell Date: Mon, 19 Aug 2024 15:39:07 +0100 Subject: [PATCH 2/2] Remove caml_reset_young_limit line --- ocaml/runtime/domain.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ocaml/runtime/domain.c b/ocaml/runtime/domain.c index 5510ae4ddde..175c8c53894 100644 --- a/ocaml/runtime/domain.c +++ b/ocaml/runtime/domain.c @@ -754,7 +754,6 @@ static void domain_create(uintnat initial_minor_heap_wsize, domain_state->trap_barrier_block = -1; #endif - caml_reset_young_limit(domain_state); add_next_to_stw_domains(); goto domain_init_complete;