GHC leaks LLVM's llc processes on a package with large number of modules on macOS
Summary
When compiling gl
package (https://hackage.haskell.org/package/gl) the compilation fails midway.
I believe the error happens, because the compilation hits per-user limit of number of processes allowed on macOS. It seems that GHC does not reap llc
processes while it is building this package, they accumulate and eventually the build fails when the process limit is reached. This package (gl
) has an unusually large number of modules.
If I compile gl
from source (rather than from Hackage), I can usually do it in two runs: one that fails, and second that picks off from where it failed.
The setup I have is GHC 8.10.7 from ghcup, on aarch64 macOS (Apple's MacBook Air), using LLVM backend.
Steps to reproduce
# Environment setup
$ uname -a
Darwin Mikkos-Air.attlocal.net 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101 arm64
$ opt --version
Homebrew LLVM version 12.0.1
Optimized build.
Default target: arm64-apple-darwin20.6.0
Host CPU: cyclone
$ ulimit -u # This prints the limit on number of processes allowed
2666
$ brew install llvm
$ ghcup install 8.10.7
$ ghcup set 8.10.7
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.7
$ cabal --version
cabal-install version 3.4.0.0
compiled using version 3.4.0.0 of the Cabal library
# The compilation part itself
$ cabal new-install gl --lib
# ... omitted most of output
[772 of 833] Compiling Graphics.GL.Ext.ARB.ShaderObjects ( generated-src/Graphics/GL/Ext/ARB/ShaderObjects.hs, dist/build/Graphics/GL/Ext/ARB/ShaderObjects.o, dist/build/Graphics/GL/Ext/ARB/ShaderObjects.dyn_o )
[773 of 833] Compiling Graphics.GL.Ext.ARB.SampleShading ( generated-src/Graphics/GL/Ext/ARB/SampleShading.hs, dist/build/Graphics/GL/Ext/ARB/SampleShading.o, dist/build/Graphics/GL/Ext/ARB/SampleShading.dyn_o )
[774 of 833] Compiling Graphics.GL.Ext.ARB.SampleLocations ( generated-src/Graphics/GL/Ext/ARB/SampleLocations.hs, dist/build/Graphics/GL/Ext/ARB/SampleLocations.o, dist/build/Graphics/GL/Ext/ARB/SampleLocations.dyn_o )
[775 of 833] Compiling Graphics.GL.Ext.ARB.Robustness ( generated-src/Graphics/GL/Ext/ARB/Robustness.hs, dist/build/Graphics/GL/Ext/ARB/Robustness.o, dist/build/Graphics/GL/Ext/ARB/Robustness.dyn_o )
[776 of 833] Compiling Graphics.GL.Ext.ARB.PointParameters ( generated-src/Graphics/GL/Ext/ARB/PointParameters.hs, dist/build/Graphics/GL/Ext/ARB/PointParameters.o, dist/build/Graphics/GL/Ext/ARB/PointParameters.dyn_o )
ghc: could not execute: opt
cabal: Failed to build gl-0.9. See the build log above for details.
While the building is ongoing, I can see from another terminal:
$ ps aux | grep llc
shannon 31999 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31942 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31885 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31828 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31771 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31714 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31657 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31600 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31543 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31486 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31429 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
shannon 31372 0.0 0.0 0 0 s003 Z+ 6:59PM 0:00.00 (llc)
<lots and lots of llcs omitted>
I can work around the bug by increasing the process limit to 4000 (it doesn't seem to go higher on my system).
$ sudo zsh
$ sysctl kern.maxprocperuid=4000 # Unsure if really needed
$ ulimit -u 4000
$ su shannon
$ cabal new-install gl --lib
Expected behavior
gl
package compiling successfully.
Environment
- GHC version used: 8.10.7 (from
ghcup
)
Optional:
- Operating System: macOS (MacBook Air, using Apple Silicon M1)
- System Architecture: aarch64