Opened 2 years ago

Last modified 7 months ago

#10445 new bug

Wrong stack space size when using -Ksize

Reported by: asr Owned by:
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.10.1
Keywords: Cc: simonmar
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D938, Phab:D961
Wiki Page:

Description (last modified by asr)

After compiling the first example in https://wiki.haskell.org/Performance/Accumulating_parameter:

$ cat Test.hs

len :: [a] -> Int
len []     = 0
len (x:xs) = len xs + 1

main :: IO ()
main = print $ len [1..1000000]
$ ghc Test.hs -rtsopts

and running

./Test +RTS -K10K

GHC 7.6.3 reports

Stack space overflow: current size 10240 bytes.

GHC 7.8.4 reports

Stack space overflow: current size 33632 bytes.

GHC 7.10.1 reports

Stack space overflow: current size 99136 bytes.

and GHC 7.10.2, 7.10.3. 8.0.1 and 8.0.2-rc1 report

Stack space overflow: current size 33624 bytes.

GHC >= 7.8.4 report an incorrect stack space size.

Change History (13)

comment:1 Changed 2 years ago by rwbarton

I have a vague recollection (from the time that the default stack size limit was effectively removed) that GHC 7.6.3 was lying and would display the stack size limit as the current stack size in that error message regardless of the actual current stack size.

I don't understand though why you are seeing a stack size that is so much larger than the limit though; and I also notice that even when increasing the stack size limit to much more than the reported stack size (like -K1M) the reported stack size does not change (and then the error message becomes rather confusing). So it does seem likely there is some sort of bug here.

comment:2 Changed 2 years ago by archblob

Cc: simonmar added

I think you are right about GHC 7.6.3 I can't see from the code how this worked then.

I have a patch that validates but I'm not sure if it's the best approach, here it goes: In https://github.com/ghc/ghc/blob/master/rts/Threads.c#L589, it seems that when we allocate a new chunk, the chunk_size is always RtsFlags.GcFlags.stkChunkSize at a minimum even though alone or together with the old stack size this will be above the limit set by -K. We fix this by only allocating enough to not go over the -K user set limit. Now what I don't know is if we should always allocate a minimum of stkChunkSize and why?

Last edited 2 years ago by archblob (previous) (diff)

comment:3 Changed 2 years ago by archblob

Differential Rev(s): Phab:D938

comment:4 Changed 2 years ago by archblob

Differential Rev(s): Phab:D938

comment:5 Changed 2 years ago by thoughtpolice

Differential Rev(s): Phab:D938
Status: newpatch

comment:6 Changed 2 years ago by archblob

Differential Rev(s): Phab:D938Phab:D938, Phab:D961
Owner: set to archblob

comment:7 Changed 2 years ago by thoughtpolice

In lieu of Phab:D961 getting flagged by Simon, I'm going to move this out of 7.10.2 - archblob, if you fix it up before the end of this week (when I'd like to do the RC), please just remilestone it.

comment:8 Changed 2 years ago by thoughtpolice

Milestone: 7.10.27.12.1

comment:9 Changed 2 years ago by Austin Seipp <austin@…>

In 892c3e98bcef50aa56ec818f4d001aee36e05bbc/ghc:

Do not copy stack after stack overflow, refix #8435

Summary:
This was reverted in d70b19bfb5ed79b22c2ac31e22f46782fc47a117
and is a part of the reason for #10445.

Test Plan: validate

Reviewers: ezyang, simonmar, austin

Reviewed By: simonmar, austin

Subscribers: bgamari, thomie

Differential Revision: https://phabricator.haskell.org/D938

GHC Trac Issues: #8435

comment:10 Changed 22 months ago by bgamari

Resolution: fixed
Status: patchclosed

This seems to have been merged.

comment:11 Changed 22 months ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:12 Changed 7 months ago by rwbarton

Owner: archblob deleted
Resolution: fixed
Status: closednew

As far as I can tell, this was never actually fixed. It is still broken in both 8.0.1 and in HEAD.

comment:13 Changed 7 months ago by asr

Description: modified (diff)
Note: See TracTickets for help on using tickets.