-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 memory corruption caused by GC-invisible coroutine stacks #4206
Conversation
Crucially this introduces BoehmGCStackAllocator, but it also adds a bunch of wiring to avoid making libutil depend on bdw-gc. Part of the solutions for NixOS#4178, NixOS#4200
The default stack size was not based on the normal stack size and was too small.
Yes, it's okay to make libutil depend on bdw-gc. The only downside is that it makes the footprint of nix-daemon a bit bigger, if we ever want to have a separate daemon executable (NixOS/rfcs#68). Another solution would be to not have GC roots on coroutine stacks. Where are we doing that? 8 MiB sounds like quite a lot for coroutines. So long as we're not evaluating in coroutines (which we shouldn't, since the stack overflow detection probably doesn't work there), then a much smaller stack should be sufficient. How much does Boost allocate by default? |
We've started evaluating in coroutines with #4030. It's not so obvious because of the indirections, but the source filter in eg
I think I agree, but for evaluation it seems like a safe number. It's only virtual memory, so a bigger value shouldn't hurt.
This works. Boost provides
Does that mean you want to remove the |
Figured I'd drop by to report that this fixed the |
@edolstra Not sure if you saw my response. I think I've addressed your concerns. |
@roberth Thanks! |
I suspect that this PR has resulted in Could you take a look at the stack trace in NixOS/hydra#816 (comment) and see whether it's related? |
Do you think the following patch would fix the 100% CPU usage / infinite stack overflow correctly? I don't understand the code (way too many C++isms for me) so I'm not sure if it's correct... diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc
index 28f6968d0..038ede049 100644
--- a/src/libutil/serialise.cc
+++ b/src/libutil/serialise.cc
@@ -195,7 +195,7 @@ class DefaultStackAllocator : public StackAllocator {
}
void deallocate(boost::context::stack_context sctx) {
- deallocate(sctx);
+ stack.deallocate(sctx);
}
}; |
I've submitted the above patch as PR #4242. |
Fix stack overflow introduced in #4206
Crucially this introduces BoehmGCStackAllocator, but it also
adds a bunch of wiring to avoid making libutil depend on bdw-gc.
The extra wiring, more than half of the PR, can be removed if it's ok to depend on bdw-gc.
Part of the solutions for #4178, #4200
Ping @edolstra