GHC 8.10.7 mmap Issue
Migrating a Reflex FRP + Reflex Platform + Rhyolite + Obelisk project to use GHC 8.10.7 instead of GHC 8.6.5, we have unfortunately run into Linux kernel bugs. In general, these bugs can be avoided by using GHC 9.4 or later, but this is unfortunately not an option in our case. At this time, we have no choice but to use systems running old kernels that do not have the bugs.
With this issue, we get errors like the following:
ghc: mmap 4096 bytes at (nil): Cannot allocate memory
ghc: Try specifying an address with +RTS -xm<addr> -RTS
Errors occur at different points of compilation with each attempt, so it is not deterministic. I think it is related to GHC issue #19421. There is an Arch Linux forum discussion that links to a few patches (first, second) fixing bugs in the maple tree implementation that is now used to track virtual memory areas (instead of red-black trees). For those interested, there are a few articles on the subject:
Those patches have been applied, and I have the issue while running
kernel version 6.3.10, so I suspect that there are more bugs that have
not yet been resolved. maple_tree.c
currently weighs in at 7,252 lines of C, so
it is not surprising that there are bugs.
I have not seen this issue when using GHC 8.6.5 with any kernel
version. When using GHC 8.10.7, I have only seen the issue with large
projects. I do not know if the likelihood of hitting the issue is
related to the project size or if it is a matter of feature usage,
however. The discussion linked above reports that the issue does not
occur with GHC 9.4 or later (due to refactoring in adjuster allocation,
m32
, and the linker), but I have not tested this
myself.
The Reflex ecosystem (currently?) uses GHCJS, and GHC 8.10.7 is the latest version that is supported. Switching to GHC 9.4 or later is (unfortunately) not an option. I am currently using a NixOS VM running an old kernel, and it works without issue.
$ uname -a
Linux ghc810 5.15.110 #1-NixOS SMP Sun Apr 30 23:23:24 UTC 2023 x86_64 GNU/Linux
Update: There is a discussion on Discourse.