Skip to content
In progress

Changes

Progress:

Summary

  1. runtime: free the minor heap when leaving STW participants (commit: 8f0d4f4) (details)
Commit 8f0d4f4b77215029fcc3f331cfc0cee3cdff051b by gabriel.scherer
runtime: free the minor heap when leaving STW participants

The reserved address space for the minor heap area is a global
resource shared by all domains; each domain owns a portion of it,
within which it commits a part for its minor heap. (Having contiguous
address space allows for an efficient Is_young check.). When we need
more reserved space because the user increased the minor heap size, we
use a STW section to change the reservation: each domain in the STW
section first decommits its minor heap, a single domain changes the
reserved area, and then each domain re-commits its minor heap.

If a domain does not participate to STW sections, the boundaries of
its minor heap will change without the domain decommitting the
previous minor heap first. If the same domain structure is used for a
newly spawned domain later on, it will start by decommitting its minor
heap following the new boundaries, which is incorrect as it never
committed this adress range in the first place.

(In practice calling `caml_mem_decommit` incorrectly in this way does
not appear to crash the program. I think this is because `decommit`
has a fairly liberal behavior, it will happily do nothing if the
memory range is not committed. The code remains logically wrong, and
could become a hard failure if other parts of the runtime change in
reasonable ways later on.)

The present commit ensures that we systematically decommit the minor
heap of each domain when it leaves the set of STW participants. This
way, only STW-active domains have their minor heap allocated, and
changing the minor heap address space within STW section works as
intended.

(I tried to remove the new call to `free_minor_heap` in
`domain_terminate`, and checked that the testsuite fails in debug mode
when the `allocate_minor_heap` call in `domain_create` later on
notices an already-committed minor heap.)

Reviewed-by: KC Sivaramakrishnan <kc@kcsrk.info>
(commit: 8f0d4f4)
The file was modifiedruntime/domain.c (diff)