edgar 的窝

Happy coding
[Z]VS Debugging : Just My Code
[Z]推荐的C++书籍以及阅读顺序

make -j(n)的用法

edgar posted @ 2008年4月11日 06:03 in 编程语言 with tags make "make -j" , 3290 阅读

Timing the Linux -j(cpu+1) Myth

Quite a few times I've been told to use the make -j(cpu+1) flag when building on Linux. Once I got my smp box up and running I ran a series of tests to see if this was correct. I guess the theory is you should make sure the processor has something to do by telling it to start one more job than the number of processors available.

The title should be a clue to the results of my tests. The short version is, it's wrong. The best flag is that which matches the number of processors (which means, don't even bother with the -j flag if you only have one).

I did do a uniprocessor test, but didn't bother to write down the times. Here are the results on a dual 1Gh p3 running 2.4.19 (and building it. The test was make -j(n) bzImage after untarring a fresh kernel source each time, doing make oldconfig, then the make bzImage). The config was of course identical in each case. Timings were done using Big Clock on a Sony Clie. These results are averaged over two runs (which were usually identical).

make -j1 dep=24sec bzImage=4min38sec
make -j2 dep=13sec bzImage=2min31sec
make -j3 dep=13sec bzImage=2min33sec
make -j4 dep=19sec bzImage=2min34sec

Technically the first entry is with no flag. I did also write down a time for a single 1Ghz Celeron without flags (but did not write down the j2 and j3 tests I remember running. Oh well).

celeron: dep=23sec bzImage=6min34sec

All these tests were run from the console without much else running. You'll probably note that it's not real important which of the -j flags is used on an smp system, but I think the accuracy is enough to say that matching the job number to the processor count is probably best.

 

http://www.timocharis.com/help/jn.html


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter