Skip to content

Guard pages instead of Heap/Stack limit checks in Cmm

Recently I have debugged a small program and I saw that there are a lot of Heap/Stack limit checks on function entrances (https://ghc.haskell.org/trac/ghc/browser/ghc/rts/HeapStackCheck.cmm). This is not cheap and introduce more branch mispredictions and instructions. What you think if we use guard OS pages (that trigger exceptions when someone try to read/write on them) around Stack and Heap? Stack and Heap sizes should be aligned on page size (usually 4K) and with sizes that fits 4K pages. We could handle such exceptions so we could do GC if needed. This trick is usually found in some memory managers for finding out-of-bounds bugs.

Trac metadata
Trac field Value
Version 8.0.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information