Conversation
|
I had a quick look, overall this looks good and makes sense to me. Not a formal review yet but let me know if you need one from me. I am also reassured that there is no overlap with the other PRs on systhreads. The issue was originally for 4.13, is the fix substantially different there? Do we know what introduced the issue? |
If you are available and interested to do a review, then yes a review would be welcome. (I think it could definitely help other people decide to approve the PR.) We haven't investigated the 4.13 systhreads codebase, so I don't know where leaks are there and how 4.14 fixed them. My guess is that the two implementations are very different, and the sources of leak are probably different as well. |
Co-authored-by: Enguerrand Decorne <decorne.en@gmail.com> Co-authored-by: Fabrice Buoro <fabrice@tarides.com>
Co-authored-by: Enguerrand Decorne <decorne.en@gmail.com> Co-authored-by: Fabrice Buoro <fabrice@tarides.com>
Co-authored-by: Enguerrand Decorne <decorne.en@gmail.com> Co-authored-by: Fabrice Buoro <fabrice@tarides.com>
(there are probably other resource leaks in domain_terminate, but those are reused from the work on thread cleanup.) Co-authored-by: Enguerrand Decorne <decorne.en@gmail.com> Co-authored-by: Fabrice Buoro <fabrice@tarides.com>
| caml_free_stack(domain_state->current_stack); | ||
| } | ||
| caml_free_backtrace_buffer(domain_state->backtrace_buffer); | ||
| caml_free_gc_regs_buckets(domain_state->gc_regs_buckets); |
There was a problem hiding this comment.
This part is cleaning up some resource on the main domain thread and is not strictly speaking part of the systhread leak, isn't it?
There was a problem hiding this comment.
Yes indeed. (This is a separated fourth commit.) We thought it made more sense to employ the new resource-cleanup in both places where they initialized, for threads and for domains. (Otherwise the code ends up in an arguably inconsistent state.)
There was a problem hiding this comment.
+1 for cleaning up memory at domain exit too, not just thread exit. The title of this PR and the Changes entry could reflect this fact.
| caml_stat_free(gc_regs_buckets); | ||
| gc_regs_buckets = next; | ||
| } | ||
| } |
There was a problem hiding this comment.
Note: @Octachron and myself discussed this offline and we decided that it would be nice to have a documentation comment that explains what gc_regs and gc_regs_buckets are. I may submit this as a separate (complementary) PR.
There was a problem hiding this comment.
Yes, some documentation about gc_regs_buckets would be great. I know what gc_regs does in OCaml 4, but I'm a bit lost as to the OCaml 5 implementation of gc_regs, what with the allocation via malloc and so on.
There was a problem hiding this comment.
For the record, I proposed some documentation of gc_regs and gc_regs_buckets in #11437.
xavierleroy
left a comment
There was a problem hiding this comment.
Looks good to me overall, but I don't claim I understand the gc_regs_bucket business. Let's wait for @Octachron's approval before merging.
| caml_free_stack(domain_state->current_stack); | ||
| } | ||
| caml_free_backtrace_buffer(domain_state->backtrace_buffer); | ||
| caml_free_gc_regs_buckets(domain_state->gc_regs_buckets); |
There was a problem hiding this comment.
+1 for cleaning up memory at domain exit too, not just thread exit. The title of this PR and the Changes entry could reflect this fact.
| caml_stat_free(gc_regs_buckets); | ||
| gc_regs_buckets = next; | ||
| } | ||
| } |
There was a problem hiding this comment.
Yes, some documentation about gc_regs_buckets would be great. I know what gc_regs does in OCaml 4, but I'm a bit lost as to the OCaml 5 implementation of gc_regs, what with the allocation via malloc and so on.
|
As far as I understand, |
My understanding is rather that only "pthread resources" (mutexes and what not) need to be reset after a fork, not memory which we assume was correctly duplicated. (A hint is that there is currently no code to cleanup the call stack in |
|
The |
|
Ah, right, the |
Suggested-by: Florian Angeletti <florian.angeletti@inria.fr>
|
@Octachron this should have been addressed in cacc1cd. Thanks! |
Octachron
left a comment
There was a problem hiding this comment.
I agree that this PR fixes a leak.
|
Sorry, I'm currently on leave (will be back on monday). |

This PR, joint work with @Engil and @fabbing, fixes some leaks in threads that we hope are the leak issues reported in #11289.
@toots, could you try on trunk (or 5.0) and tell us if you still observe leaks with this PR?
We wonder who would be interested in reviewing this. Maybe @gadmm, @xavierleroy or @sadiqj?