improper calculation of maxStkSize
Summary
Calculation of getPhysicalMemorySize() appears to be incorrect.
We're running on an i3.4xlarge EC2 instance (https://aws.amazon.com/ec2/instance-types/i3/) and noticed stack overflows. This shouldn't happen, since stack should be bounded by 80% of physical memory, which in this case is 122G. However, when I attached a debugger (at ben's suggestion) to a compiled haskell test program and called getPhysicalMemorySize()
it returned a value corresponding to only about 3.5M.
(gdb) print (unsigned long) getPhysicalMemorySize() $3 = 3559424
The number corresponds to what you get if you print out the correct value as an unsigned, rather than as an unsigned long.
When I tested this on a different linux box, or my local machine (darwin), the value was calculated correctly, in that it printed correctly as an unsigned long, and further the value when printed as an unsigned long or just an unsigned differed, while on the EC2 machine the value was exactly the same.
But I confess that auditing the code, I can't tell where the problem is, since it seems like it tries to do everything in StgWord64, which should be fine, and I don't see why this is arch-dependent...
Steps to reproduce
Attached is a dumb program to reproduce the issue. If you run it then enter "6" it fails if the calculated stack limit is significantly lower than it should be (one can play around with arguments to trigger at higher limits).stack.hs
Environment
- GHC version used: 8.6.5
Optional:
- Operating System: nixos-17.09
- System Architecture: x86_64