执行 make -jn 时, n> m ,其中 m 是物理上可用的CPU数量,这些 n - m 作业会发生什么?只有 m 作业被分派执行到操作系统,剩下的 n - m 被 make 排队,或者全部是 n 分派的作业和操作系统之间的上下文切换?
答案 0 :(得分:2)
The latter: all the n jobs dispatched and the OS is context-switching between them.
Linux normally tries to juggle processes in a fair fashion, so that if you compile a large project with make -j
(without the process count limit) that is likely to swamp your machine with processes and bring it to halt (due to swapping because all processes do not fit into RAM).
Solaris 10 did not suffer from that.
When compiling on Linux with build systems that scale linearly with the number of jobs (e.g. non-recursive make) a rule of thumb is to not use more jobs than logical CPUs (i.e. a hyper-threaded core is a logical CPU). A bit of empirical data.