Linuxカーネルビルドの並列数 Linux kernel build concurrency
LInuxカーネルビルドの並列数と所要時間の関係を調査しました.
This article reports the relationship between the kernel build time and the number of simultaneous jobs.
報告内容 Objectives
Linuxカーネルをビルドするときの並列ジョブ数と,所要時間の関係の調査結果を報告します.
This article reports the relationship between the kernel build time and the number of simultaneous jobs.
趣旨 Objectives
Linunx カーネルのビルドは,長い時間を要します.
make コマンドに -j オプションを付ければ,ビルドを並列に実行でき,時間短縮につながると期待されます.
しかし,過度に並列数を増やすとプロセススケジューリングなどの負荷が増えて,逆に時間が増えると予想されます.
どの程度が適切か調べます.
Linux kernel build takes a long time. You can reduce the time with simultaneous jobs by adding the -j option to the make command. However, the time may be increased if you create too many jobs.
This article presents the relationship for discussing the optimal number.
調査方法 Measuing method
並列数ごとの make 時間を調査しました.
make clean, make bzImage, make modules, make install, make modules_install の時間を個別の調査しました.
並列実行しているのは make bzImage と make modulesのみです.
並列数は1から15で,各並列数で3回計測しました.
The number of simultaneous jobs ranged from 1 to 15. The times to complete the make command were measured three times with every number of jobs.
The times of make clean, make bzImage, make modules, make install, make modules_install were measured. Only make bzImage and make modules were done with multiple jobs.
具体的には,以下のシェルスクリプトを実行して調査しました.
The measurement was done with the following shell script file.
resul=../result.txt
log=/tmp/a.log
dir=linux-5.15.25
jmax=15
repemax=3
cd ${dir}
for j in `seq 1 ${jmax}`
do
echo -j${j} | tee -a ${resul} >> ${log} 2>&1
for r in `seq 1 ${repemax}`
do
time0=`date +%s%N`
make clean >> ${log} 2>&1
time1=`date +%s%N`
make bzImage -j${j} >> ${log} 2>&1
time2=`date +%s%N`
make modules -j${j} >> ${log} 2>&1
time3=`date +%s%N`
make install >> ${log} 2>&1
time4=`date +%s%N`
make modules_install >> ${log} 2>&1
time5=`date +%s%N`
timea=$((time1-time0))
timeb=$((time2-time1))
timec=$((time3-time2))
timed=$((time4-time3))
timee=$((time5-time4))
#echo "-j $j , $time0 $time1 $time2 $time3 $time4" | tee -a ${resul}| tee -a ${log}
echo "-j $j , $timea $timeb $timec $timed $timee" | tee -a ${resul} >> tee -a ${log} 2>&1
done
done
echo fin >> ${log} 2>&1
上記シェルスクリプトの実行前に,以下を実行しました.
Before the above script execution, the following steps were done.
環境 Setup
CPU: Intel Core i7-3770 CPU @ 3.40GHz.4 cores,8 threads,ベース周波数 basic clock rate 3.40 GHz,ターボ・ブースト時の最大周波数 maximu clock rate with turbo boost 3.9 GHz
OS: Ubuntu 20.04.3 LTS, desktop, Linux 5.15.25
Memory: 16 GB
HDD: Hitachi Deskstar 7K1000.C
Filesystem: Ext4
結果 Results
CPUのスレッド数である8までは,並列数を増やすと時間が明確に減少しました.それ以上は増やしても性能はほとんど変わりませんでした.
The time effectively decreased as the number of jobs increased from 1 to 8, which is the number of threads. The time kept almost constant later.
↑ make bzImage (左Y軸) と make modules (右Y軸)のみ,かかった時間の逆数をグラフ化しました.時間の逆数は,速度に比例します.
Inverses of times to complete make bzImage and make modules. The inverse of time is proportional to the speed.
コア数である4までは,並列数を上げると速度がぼぼ正比例で増加しました.コア数の4からスレッド数の8の範囲も,増加量が減りましたが,速度は増加しました.
The speed increased proportionally from 1 to 4, which is the number of cores. It increased from 4 to 8, but the sizes of increases were smaller.
結論 Conclusion
この環境では,並列数は「スレッド数と同一」が好ましい様です.
他の環境にも当てはまるかは不明です.
The optimal number of jobs was the number of threads in this environment. The optimal number may depend on the environment.
おまけ Appendix
誤って以下の様に打つと(-jの後の数字をつけ忘れると),たぶんシステムがとります.makeが無制限に並列数を増やします.
If you forget to type a number to -j like this, your system may crash. The make command increases the number of threads unlimitedly.