RTS documentation for -Z (stack squeezing) is wrong
+RTS --help
says this about -Z
ghc: -Z Don't squeeze out update frames on stack overflow
Looking at the code I think this is wrong: we actually squeeze on every context switch depending on a heuristic. In threadPaused.c:threadPaused
:
// Should we squeeze or not? Arbitrary heuristic: we squeeze if
// the number of words we have to shift down is less than the
// number of stack words we squeeze away by doing so.
// The threshold was bumped from 5 to 8 as a result of #2797
heuristic_says_squeeze = ((weight <= 8 && words_to_squeeze > 0)
|| weight < words_to_squeeze);
...
if (RtsFlags.GcFlags.squeezeUpdFrames == true &&
heuristic_says_squeeze) {
stackSqueeze(cap, tso, (StgPtr)frame);
tso->flags |= TSO_SQUEEZED;
// This flag tells threadStackOverflow() that the stack was
// squeezed, because it may not need to be expanded.
} else {
tso->flags &= ~TSO_SQUEEZED;
}
If I'm reading this right then we sometimes squeeze even when there isn't a stack overflow, so the RTS documentation should be updated.
(I also checked threadStackOverflow()
to see if we actually squeeze when there's stack overflow, but that function doesn't really do any squeezing. Not sure if we do squeezing on stack overflow and if we do, where)