2

I have been trying to install LLVM on my system [i7 + 16GB RAM]. I have been following this tutorial : LLVM Install. But in building, it eats up all the RAM and the terminal closes automatically. Is there any way to solve this?

Thanks.

Shark
  • 21
  • 1
  • 1
    It's likely the linker using up all the RAM, you could try `sudo apt install lld` then on the cmake line add `-DLLVM_USE_LINKER=lld` to ask cmake to use it. – Nick Lewycky Apr 25 '22 at 00:13
  • Also, `ninja` by default will use all cores in parallel, you could set it as low as a build-in-serial with `ninja -j1` to reduce simultaneous memory usage, but your build will be much slower. The number after `-j` specifies how many processes to run in parallel. – Nick Lewycky Apr 25 '22 at 00:14
  • 4
    It's also possible to use all cores for most things and limit only linking. Try setting the cmake variable LLVM_PARALLEL_LINK_JOBS to 2 if you have 16GB, perhaps as high as 5 for 32GB. – arnt Apr 25 '22 at 08:15
  • 1
    What worked : restricting no. of parallel jobs to 1 worked. – Shark Apr 27 '22 at 17:09
  • More information about the points by Nick Lewycky and arnt are given here: https://llvm.org/docs/CMake.html – Hari Jun 08 '23 at 09:28

2 Answers2

2

The resources consumed during build can depend on various factors:

  • Number of build targets that you are building. In general you should be able to skip a bunch of build targets (compiler-rt, libcxx etc)
  • The type of binaries that will be generated. I mean, shared vs. static. Enabling shared libraries (BUILD_SHARED_LIBS:ON) will consume way less memory.
  • The type of optimization flag. Debug, Release, RelWithDebInfo will also have an effect. The Debug build will have larger binary size so it may consume more memory during the link step. But the build time will be faster as few optimizations are enabled. Release build may consume less RAM during the link step.
  • Number of threads -jN

TLDR for reducing RAM pressure:

  1. Enable shared libraries
  2. Use Release builds
  3. Keep number of parallel threads low (Instead of max jN try, -j(N-2)). Using -j1 may use less RAM but would take long time to build.
  4. Skip building as many libraries (e.g., LLVM_ENABLE_RUNTIMES) and targets (e.g., LLVM_TARGETS_TO_BUILD) as you can. This may not be trivial as it requires spending time with the CMakeCache.txt file.
  5. Build only what you want e.g., instead of invoking just ninja, invoke ninja clang, or ninja opt etc.
A. K.
  • 34,395
  • 15
  • 52
  • 89
0

I've spent half day on this item. I've a PC i7 with 24GB of RAM based un Ubuntu 22.04. I tried (many times) but was not possible to compile with gcc (and I don't why). The system monitor sometimes shown 20GB ram usage and wasn't possible to reach the end of the compilation. The build system (I choosen ninja) crashed many times.

At the end I installed clang. The ram usage never gone over 8GB. I report what I did (if can help anyone)

follow this link How to build clang with clang?

lonejack
  • 17
  • 1
  • 3