Wednesday, November 18, 2009

Linux Kernel Recompilation: Is it Worth the Pain?

linux kernel recompilation is not necessary
With Linux Kernel 2.6.32 around the corners I see some gurus suggesting users to recompile their own kernels for a dozen of reasons: performance, fast booting, support of some esoteric drivers, bla... bla... What's more, the way some persuade for kernel recompilation seems the job is as easy as any point-n-click installation.

Dear users, kernel recompilation is not easy like that. Plus, you won't get that perceivable performance boost. May be after hours of toil you can cut down 2 secs from your boot time and some unnoticeable system responsiveness.

Except for some really weird situations, modern Linux distributions don't really need kernel recompilation. Here are the reasons:

  • Rise of Hardware: Gone are those days of Mega Hertz processors. Now when Quad Core processors have reached the shelves you won't find much performance difference between one of your custom (recompiled) kernels and the one that came with your favorite distribution. Of course, you will still see some point differences in actual benchmarks, but that's minismal enough to be ignored. The point here is modern hardware is really fast. For more speed you can just make some manual changes in your runlevels, services and desktop environment settings.
  • Intelligent Kernel: A modern linux kernel though multiple times heavier than its predecessors is also far more intelligent than them. It loads just the required stuff and cuts the clutter from beginning. So, no need to be panic looking at those hundreds of modules.
  • Can you Bell the Cat well: Recompiling a kernel is not just a make menuconfig >> make >> make modules, and a couple of such commands away. Even if you do it, you as a normal user (sorry, if you are a geek) can't do the job that good compared to hundreds of developers rolling kernel for your favorite distribution.
  • Most often you don't need to: Do you know that the upcoming linux kernel 2.6.32 has support for USB 3.0 drives? Just imagine when the hardware is not yet shipped to the vendors the device drivers are ready in linux kernel. The same thing may not be true for all your ultramodern devices. But, it's matter of time. Just wait for some time and next kernel will most probably have it. Else browse through linux forums you will certainly get a fix or workaround.
  • Does it Pay: Though recompiling a kernel really helped couple of years back. Today it doesn't really help you that much. You might take all the pains to roll your own kernel. But at the end just get unnoticeable performance boost.

So, is kernel recompilation all that futile? No! The only benefit lies in enhancing your knowledge. If you are intelligent/keen enough to know the system internals kernel recompilation is a great session. Never mind, if you break you system you can pop up a distro cd and go for clean install, always.

27 comments:

Alle said...

I could not agree more! Also, it makes the server more difficult to maintain in respect to system updates.

Yossarian UK said...

I always compile my kernel.

The resulting vmlinuz is usually 1/3 less that the original distribution kernel

Once you have a customised kernel.config you can upgrade to the next version usually very quickly, yes it may be only a small improvement but if you are on your machine all day I belive you may as well..

As well as occasionally needing a later kernel to support hardware here are some reasons why I would compile a 2.6.32 kernel (when released) on your distro (not needed if you run Arch linux as that will get it ...)

- New Scheduler improvement - a long term regression (since 2.6.24) has been fixed - should result in speed ups.
- If you have have intel video and are having random crashes/issues with 2.6.31 these should be fixed
- If you run KVM you will get the latest version

manmath sahu said...

Hi Alle and Yossarian UK,
Thanks for dropping by. Actually the post is about Desktop. IMO home users should not take the pain of recompiling kernel on their systems as modern linux OS and hardware are both swift enough to do the daily chore. Recompiling doesn't really help them get that perceivable performance boost.

Of course, for servers the story is different.

Regards.
Manmath

Allen said...

I disagree. It goes a long way in taking an 'average user' and bumping up their skill levels. The more they learn, the more independent they become. Instead of waiting for someone else to do the work for them, they can do it themselves, right away. It goes a long way to learning how Linux ticks and may open the door for a future programmer/maintainer.

Anonymous said...

1. No Ham Radio.

2. Distributions do not ship with every driver module compiled. Just a "general" idea of what hardware you might have. If it doesn't ship the one you need you're S.O.L.

3. Do 'make xconfig' for the nice QT menus.

4. Use this script for Debian-based systems. http://www.paidpaste.com/paste-16014

5. 1352 distribution modules to 342 custom kermel modules.

6. Palpabale system responsiveness and performance. I got numbers!

5. Painless.

Anonymous said...

This is the kind of thinking that lead to bloated inefficient software.
It is true that it is most likely in most cases only measurable with performance benchmarks....but it IS optimal (if you choose to compile it for your HW)
This is the thinking that gave us Vista/Win7 OS:es that you needed to buy new hardware to even begin using.
Just because the HW is there does not mean we should use up all the resources.

Anonymous said...

Compiling your own kernel requires GB of disk space, and takes hours.

In general simply using a distro kernel tuned to your circumstances, saves much work and Watts; and the result has been QA-ed.

The kernel is very clever at using alternative code, tuned to particular processors where there's a significant advantage. SMP Alternatives patch kernel to be Uni or Multi processor for example. The scaling work to larger number of processors mean there's fewer static tables wasting memory by over-sizing data structures to a high maximum number of processors.

Why can't a distro include the scheduler patch & intel video fix ups, as an update in there 2.6.31 kernel source? There's nothing to stop them, and significant fixes with low impact do get included by "stable" kernel teams.

The real reason to compile own kernel, is to track recent developments, and test vanilla kernel on your hardware for regressions.

Yossarian UK said...

Hi

I was referring to my desktops...

As I use it pretty much all day i think the effort of compiling is worth it.

I always for example set the kernel to 1000Hz (ubuntu 9.10 amd64 it is set to 100Hz for the desktop for some reason.)
If you read the ETQW readme it says to achieve the best performance you must compile a kernel with 1000Hz and full preemption - for the client and server.

I only ever compile a kenel on server if I need need hardware support - i.e if you run the ancient centos kernel and need a sata/network driver that isn't in the centos kernel.

Anyway

Cheers !

Anonymous said...

Sorry, don't agree...

I recompile mine to get a preemptible kernel, fit for my core2duo with a 300Hz context timer... Take out SELinux (apparmor fan) and, of course, kernel debugging (Keeping the stock kernel for debugging)...

Recompiling at the basics requires to go through one of these easy 20 minutes tutorials and then wait for the thing to be done...

The commands are in a script so that whenever I want to update I need approx 5 secondes of interraction.

In the end my system is much more responsice. In face, if I don't recompile, I cannot look at an HD movie without skipping frames while after a recompile, It works like a charm (yeah... boot is somewhat faster... not that I care that much)

Anonymous said...

Recompiling a kernel is not just a untar >> make config >> make dep >> make modules, and a couple of such commands away.

You're absolutely right. That particular instruction path has been obsolete since well before the kernel hit version 2.0. If that's the extent of your kernel compiling knowledge, I'm having a hard time taking the rest of yoru blog post seriously. Come back and take a position after you've learned how to use make menuconfig (which you used as a screenshot for Ghu's sake!), make oldconfig, etc.

Anonymous said...

Atom processors and other green pcs, anyone ?

Anonymous said...

No one in his right mind will support your system when you are using you own custom kernel. This is fine for us ├╝bernerds, but no way this is what you want if you don't have the time / energy / knowledge to debug your own system in case of again some vague problem.

Anonymous said...

I'd agree for the bog standard user.

A compile *is* simple (I'd say it's very simple from 2.6.18 onwards), but not always 100% "good".

On mine, I did it because I required some additional hardware drivers in a later kernel version and my distro was several versions behind at the time.
After compiling, I did get a faster boot, and what *seemed* better responsiveness.
After testing, some performance had actually decreased and I think one or two things were a little buggy / quirky.

The fact of the matter is, the default kernel is build to be GENERIC, and try to work as best as it can.
The distro's kernel (in most distros) have custom alterations which can be reflected in the REST of the packages for that distro.
So some binaries will gain in performance - but others will have a performance hit.

Most regressions and patches should be incorperated into the distro's kernel revisions, so a user compiling from source is ill advised.

The only reason, is a LARGE performance boost (greater than say 20%), a hardware issue (bug, or missing hardware support) required functionality (ie, requires 2.6.32 API functions not present in 2.6.24) or stability/security improvement (again, should be back-ported).

All other reasons (less modules / disk space) is pretty silly for *NORMAL USERS*.
16 Meg instead of 24? When's the last time you remember searching through all your files needing to delete some to free up 10M? For me it was about 10 years ago.
Modules are usually only loaded on request unless compiled into the kernel (which then seem to go doo-laly which I discovered on my own compilation tomfoolary).
Trying to get a "normal user" to learn kernel stuff? When you don't know about "man" pages, and won't normally touch the command line - let alone not know of the "ps" command - what does this actually teach them? .. Nothing. It's a menu approach which they step through and can just get it working - with possible issues.
Any "possible programmer" will discover it by themselves when looking into kernel modules and tweaking various settings.
I think a lot more can be gained by editing grub.conf and other config files rather than rebuilding the kernel itself.. Again, that is unless of the exceptions I've listed above.

Anonymous said...

I recompile the kernel because we can and its fun even though sometime it is long and unproductive.

Moreover, I get to see all the new options available compare with old kernel.

Anonymous said...

Windows users don't need to compile their own kernel, everyone uses the same cookie-cutter kernel and it works just fine. Really it does, and I'm glad for linux desktop users that things are just as fine now we are moving to this strategy too.

IME distro built kernels are perfectly adequate for desktop users, apart from a very small subset of users that have a set of use-cases that the distribution kernels don't meet. So unless you fit in to that category, there is no advantage to recompiling a kernel for your machine.

manmath sahu said...

That's what I said. 99% of Home desktop users need not recompile their kernels. One may only attempt recompiling for certain hardware/driver support and that's very rare these days.

AN Athar said...

hey,

I don’t usually post on blogs but had to on yours. I don’t have time to read all the articles right now, I found your site while I was looking for something else on google.com but I have bookmarked the homepage and will return soon to read more.

I myself m a IT Infrastructure consultant with specialization in VoIP and Secured IT Networks. Do visit my website www.itzeen.com

Thanks.
Abeer

website traffic said...

Ya but doesn't happen regulary....we have lots of benefits using linux ,but i have never seen such thing in my life.

Chris said...

The stock-standard kernel is bloated with many things the 'normal' user will never need. Why activate SELinux on a desktop? Do we need IPv6 in every instance? Linux is put forth as working on computers with low resources; it makes sense to disable such features when using old hardware (like PowerPC Macs).

Furthermore, why are kernels supplied with desktop distros configured to be optimized as servers? Re-compile them as desktops by changing a few parameters and gain desktop responsiveness.

These reasons are the nutshell view of why I choose to recompile on my low-resource hardware.

Chris Reich; Rochester, New York
twittername: chrisreich

manmath sahu said...

Chris,
Thanks for dropping by. But I would appreciate very much if you share your kernel tweaks for desktop. That means "please let's know what are the kernel parameter you change while recompiling a desktop kernel."

creativesumant said...

“Kernel compilation is a tough nut to crack” - Most frequently this would be followed by a sigh if the recompiled kernel is not booting up. Though the nut has the look of a tough one to crack, kernel recompilation is still an inescapable affair that every Linux system administrator runs into, sooner or later. I too had to. With this article, I intend to walk you through the phases of compiling a kernel. I am sure it will inspire confidence in you so that compiling a kernel is no longer a “mission impossible”.



Recently I just came across a good article on "Linux"
Here is its link.

Anonymous said...

Thanks for sharing this link, but unfortunately it seems to be down... Does anybody have a mirror or another source? Please answer to my post if you do!

I would appreciate if a staff member here at pclinuxos2007.blogspot.com could post it.

Thanks,
Charlie

Anonymous said...

Thank you, that was extremely valuable and interesting...I will be back again to read more on this topic.

Anonymous said...

Thanks for sharing this link, but unfortunately it seems to be down... Does anybody have a mirror or another source? Please reply to my post if you do!

I would appreciate if a staff member here at pclinuxos2007.blogspot.com could post it.

Thanks,
Harry

Anonymous said...

Cool web site, I hadn't come across pclinuxos2007.blogspot.com earlier in my searches!
Keep up the fantastic work!

Anonymous said...

Hey,

I have a inquiry for the webmaster/admin here at pclinuxos2007.blogspot.com.

Can I use part of the information from this blog post above if I give a backlink back to this site?

Thanks,
Jack

manmath sahu said...

A big Yes. If you place a backlink to this blog you can use the contents.

Share your thoughts