-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix GC alarm regression #13318
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
Fix GC alarm regression #13318
Conversation
|
|
|
Instead of playing with |
|
Nice, I just applied the suggestion. I chose |
|
@Octachron This is going to be a candidate for backporting |
|
Yes, I agree. |
That would be a decent solution, but making the |
|
@lthls This was my initial idea, but using |
I don't follow. With the new code,
We could have this property by implementing let rec call_alarm arec =
if Atomic.get arec.active then begin
let finally () = finalise call_alarm { arec with f = arec.f } in
Fun.protect ~finally arec.f
end |
|
It is not clear from the discussion that there is anything left to fix. Is there something left to change? |
|
I don't like the use of |
|
I understand the meaning of ref in forcing values to have an identity, but I don't typically relate this to being able to reason about the lifetime. It took me thinking about the compilation to understand why this would prevent making them static, and I am not sure I see how this is a consequence of preventing sharing. In both cases one reasons on consequences of implementation details rather than more conceptual program explanations, so both are equivalent to me in this regards. I'll defer to @lthls for what is the best solution. |
|
I'm a bit worried about the test. How long does it take to run ? If it is more than one second I think it should be changed to something less expensive (like a sequence of |
|
Good question, it takes 400ms to run here, which is also how long using |
The arec variable was referenced in the closure for at_exit, which prevented the value from being finalised. Added a regression test.
|
In case of failure of the test, the change I just pushed reduces the duration from 39s to 4s. |
Performance optimisations affect any program behaviour that depends on the GC, and this is one of them. We do not provide any guarantee about the time at which a value will be collected (some values will still be alive when the program ends), so whether a GC alarm will trigger in a given program can depend on GC parameters, compiler optimisations, and more. The |
|
As an aside,
Is there no effort at all in ensuring safety for space for flambda? |
I'm not sure what you mean by "no effort". OCaml's compilation scheme for closures ensures that the SSC property from the paper holds for all variables that are not statically allocated. Or formulated differently, the SSC property always holds in OCaml, but whether a variable is local or global depends on context and optimisations. |
|
Thanks @lthls, this is the clarification I was hoping for |
|
Thinking a bit more, I think that the SSC property might not hold with recursive definitions: let f x y =
let rec a () = x and b () = y in
ignore (b ());
aI think that on the above example, both |
Fix GC alarm regression (cherry picked from commit 9ca0ce5)
|
Cherry-picked to 5.2 as 13ee4da . |
The PR #12558 introduced the following regression: GC alarms did not run any more. (Reported at https://discuss.ocaml.org/t/changes-in-handling-of-gc-parameters-and-alarms-in-5-2-0/14986/2)
The arec variable was referenced in the closure for
at_exit, which prevented the value from being finalised.I wondered why it was not caught, and in fact the testsuite had no test for alarms. So naturally I add a regression test, based on the provided reproducer.