Shark
Shark

Reputation: 21

Building LLVM eats up all the RAM

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.

Upvotes: 2

Views: 3217

Answers (2)

lonejack
lonejack

Reputation: 27

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?

Upvotes: 0

A. K.
A. K.

Reputation: 38262

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.

Upvotes: 2

Related Questions