-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Memory cleanup at exit #12964
base: trunk
Are you sure you want to change the base?
Memory cleanup at exit #12964
Conversation
717cea3
to
3de8ff8
Compare
In order to make progress for what is probably most of the use cases of that feature, I've currently restricted the cleanup to single-domain operation. In this state, there are no segmentation faults or other misbehaviours upon exit, only memory leaks (i.e. it's as bad as before in the worst case.) |
Allow me summarize my understanding of this work (feel free to correct me):
This strikes me as a good first step to get an initial "memory cleanup at exit" mode working in OCaml 5. Footnotes
|
Your understanding is correct. |
Possibly I am misunderstanding something here. In the current runtime, when a domain terminates, its major heap (a.k.a. "shared heap") is "orphaned" by |
55887fb
to
189fdc0
Compare
(This PR is related to #13010 and I was not sure which one to comment in.) Here is the behavior I would expect for
In 4.x, the cleanup-at-exit mode would make I could see a use-case for another function that does a "soft shutdown" by raising the |
189fdc0
to
cf89472
Compare
This new version incorporates @NickBarnes's feedback, but should not be considered ready yet. There are still issues when using the debug runtime. On the other hand it will be easier to review as the cleanup code paths are more visible now. |
This is currently only done if only one domain is left running at shutdown time - correctly handling multiple domain needs more work.
cf89472
to
8fb3d30
Compare
This is a work-in-progress support of "memory cleanup at exit" code (
OCAMLRUNPARAM=c
), see issue #10865.This is implemented in two parts:
domain_terminate
does in the main thread upon exit.This appears to work when only one domain is used. However, when multiple domains are used, several tests show that threads are still running at the time
caml_shutdown
is running, which can cause, at best, some memory leaks (e.g. nocaml_free_signal_stack
invocation in the remaining threads), and at worse, segmentation fault due to races between threads.This needs that some form of rendezvous or thread suspension is needed at caml termination.
Comments about the current state of this work and future directions are welcome.