转帖:Linux Kernel: Speed Up Compilation

Linux Kernel: Speed Up Compilation

<script type="text/javascript"> digg_url="http://zaher14.blogspot.com/2009/04/linux-kernel-speed-up-compilation.html"; </script> <script src="http://proxy5.8505.info/browse.php?u=Oi8vZGlnZy5jb20vdG9vbHMvZGlnZ3RoaXMuanM%3D&b=5" type="text/javascript"></script>

I have been having a hard time for the last few days in doing my "Linux Kernel Assignment". No, programming is not the hardest part. Waiting for the kernel to compile is the main problem. Its pathetically the moment when you become the sitting duck. :). So here are some of the things I came across to speed up the compilation.

  1. Make sure you have ccache installed and configured. As the name suggests, ccache dramatically speeds up subsequent compilations by caching the object files. In most new Fedora distros, its enabled by default. You can check it by doing $which gcc . If it says something like /usr/lib/ccache/gcc , you are all set up. If not, try google, :)
    You can see see its status by issuing command $ccache -s . Its good to set the cache amount a bigger than default, so $ccache -M 2G will set the cache to 2GB which is enough for everyone.
  2. Use gcc option -pipe whenever possible. Self explanatory, it uses pipes instead of temporary files.
  3. If you have dual core or quad core processor and a lot of RAM, you'll notice that while compiling, only a fraction of your processor and RAM gets used. This is because there is only one compile process running at a time. You can specify multiple make jobs by passing parameter like this $make -j 2 . Here, make will run at most 2 jobs at a time, taking full advantage of your multi-core CPU and RAM. Some argue on setting higher value, but I do not recommend it, as it likely to have negative effect because of the large amount of context switched in the CPU. People say that this approach leads to race conditions but I haven't bumped into any of that yet.
  4. For Linux Kernel compilation, make sure you have CONFIG_DEBUG_KERNEL unset in .config file. If set, this builds your kernel with debugging symbol making your kernel a lot bigger and significantly longer to build. It will make kernel debugging impossible though, but when you are in a hurry, this really makes more sense. Also strip the .config file from any unnecessary drivers/modules you don't require, but this will require you to have a thorough knowledge about both your PC and running kernel.
  5. For those with high speed network (ethernet or more), give a try to distcc , that distributes the compilation among multiple machine. The configuration is quite straight forward. Check the references section for details. 
  6. Try tmpfs . It enables you to mount any folder in your file system in RAM, so theoretically speeding up the compilation. Try mounting your build folder with tmpfs like this $sudo mount -t tmpfs -o size=500M,mode=0777 tmpfs /usr/src/linux-build .

Using the above mentioned method, you can get a clean build of 2.6.29 kernel in less than 15 minutes. Let me know if you have any problems or come up with any better solutions. :)

References:

https://help.ubuntu.com/community/Kernel/Compile

http://www.linux.org/docs/ldp/howto/Modules/speedup.html

http://en.gentoo-wiki.com/wiki/Portage_TMPDIR_on_tmpfs

http://www.ibm.com/developerworks/linux/library/l-distcc.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值