转帖:Linux Kernel: Speed Up Compilation

来源:互联网 发布:国际纵队知乎 编辑:程序博客网 时间:2024/05/02 07:05

Linux Kernel: Speed Up Compilation

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 patheticallythe moment when you become the sitting duck. :). So here are some ofthe things I came across to speed up the compilation.

  1. Make sure you have ccache installed and configured. As the name suggests, ccachedramatically speeds up subsequent compilations by caching the objectfiles. In most new Fedora distros, its enabled by default. You cancheck 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. Ifyou have dual core or quad core processor and a lot of RAM, you'llnotice that while compiling, only a fraction of your processor and RAMgets used. This is because there is only one compile process running ata 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 ofyour multi-core CPU and RAM. Some argue on setting higher value, but Ido not recommend it, as it likely to have negative effect because ofthe large amount of context switched in the CPU. People say that thisapproach leads to race conditions but I haven't bumped into any of thatyet.
  4. For Linux Kernel compilation, make sure you have CONFIG_DEBUG_KERNEL unset in .configfile. If set, this builds your kernel with debugging symbol making yourkernel a lot bigger and significantly longer to build. It will makekernel debugging impossible though, but when you are in a hurry, thisreally makes more sense. Also strip the .config file fromany unnecessary drivers/modules you don't require, but this willrequire you to have a thorough knowledge about both your PC and runningkernel.
  5. For those with high speed network (ethernet or more), give a try to distcc,that distributes the compilation among multiple machine. Theconfiguration is quite straight forward. Check the references sectionfor details. 
  6. Try tmpfs. It enables you to mountany folder in your file system in RAM, so theoretically speeding up thecompilation. Try mounting your build folder with tmpfs like this $sudo mount -t tmpfs -o size=500M,mode=0777 tmpfs /usr/src/linux-build.

Usingthe above mentioned method, you can get a clean build of 2.6.29 kernelin less than 15 minutes. Let me know if you have any problems or comeup 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

原创粉丝点击