4

I am trying to install LLVM on my CentOS machine. In the installation tutorial of LLVM, a flag -jn is specified along with make.

It says to perform make -jn and also says "Choose n such that make doesn’t run in to swap space issue."

What is the use of the -j flag and how can I choose the value of n?

terdon
  • 234,489
  • 66
  • 447
  • 667
Rakesh R Nair
  • 365
  • 5
  • 7
  • 14

4 Answers4

5

The -j make flag denotes how many threads you want to allot for compiling.

n is, in this case, a place-holder for the number of processes.

The classic rule of thumb is that it's safe to make n = the number of cores your CPU has. So if you are on a dual core machine, you might use -j2, while on an 8-core machine -j8

In practise, I have found that to be a good starting place, but you should probably feel free to experiment a bit and see what works best for you.

Klaatu von Schlacker
  • 3,028
  • 13
  • 15
2

Whether it's safe to use n = number of cores also depends on whether you have enough memory for all the parallel compile/link jobs. It could also cause issues for disk I/O. If this is a make job you only expect to need to run once it's probably better to choose a lower n and just let it take its time.

Bjorn Munch
  • 484
  • 3
  • 5
2

The -j flag tells make(1) how many processes to run in parallel. Best value depends on the tasks run, dependencies, ... a rule of thumb is the number of processors. If you give just -j (no n), make starts as many processes in parallel as possible.

vonbrand
  • 18,156
  • 2
  • 37
  • 59
1

Just as a concrete example of how the -j flag affects a build operation and a reason to be careful with it:

I forgot I had MAKEFLAGS=-j5 and tried to build LLVM; once it reached 97% percent it spawned 5 ld processes at the same time, each consuming 1.5GB+ RAM. The first one crashed within 20 minutes, and the rest kept consuming more and more memory until my computer was unusable and I finally decided to Ctrl+C it and try again with a smaller -j. With -j3 my computer is still struggling with three ld processes but at least I can still type this with only a few hiccups.

phicr
  • 111
  • 3