Skip to content
  • Ben Gamari's avatar
    rts/posix: Reduce heap allocation amount on mmap failure · 4ad2a8f9
    Ben Gamari authored and Ben Gamari's avatar Ben Gamari committed
    Since the two-step allocator the RTS asks the kernel for a large upfront
    mmap'd region of memory (on the order of terabytes). While we have no
    expectation that this entire region will be backed by physical memory,
    this scheme nevertheless fails on some systems with resource limits.
    Here we use a back-off scheme to reduce our allocation request until we
    find a size agreeable to the kernel. Fixes #10877.
    
    This also fixes a latent bug wherein the heap reservation retry logic
    would fail to free the previously reserved address space, which would
    likely result in a heap allocation failure.
    
    Test Plan:
    set address space limit with `ulimit -v 67108864` and try running
    a compiled program
    
    Reviewers: simonmar, austin
    
    Reviewed By: simonmar
    
    Subscribers: thomie, RyanGlScott
    
    Differential Revision: https://phabricator.haskell.org/D1405
    
    GHC Trac Issues: #10877
    4ad2a8f9