Saturday, March 7, 2009

gcc -Os vs -O2: linux kernel

So, I've been reading up about the size optimization (CC_OPTIMIZE_FOR_SIZE) after finding that the Fedora distro config enabled this option by default.

According to the LKML, this option is deprecated as an option that will "optimize" the performance of your builds of the Linux kernel. Here's an interesting quote from David Lang:

I started useing Os several years ago, even when it was hidden in the embedded menu becouse in many cases the smaller binary ended up being faster.

in reality this was a flaw in gcc that on modern CPU's with the larger difference between CPU speed and memory speed it still preferred to unroll loops (eating more memory and blowing out the cpu cache) when it shouldn't have.

Possibly the only reason this option remains default on large or important distributions is because they simply forgot it. I mean, if there's no reason to keep this on unless you're stupid enough to build the kernel with a deprecated compiler.

I actually have my own statistics. I compressed the debian package rules for the pidgin package in debian sid on an old pentium 3 laptop which has 256kb of L2 cache. This directory is small but after repeated benches, the results are still as important as a long 2 hour benchmark:

real 0m2.470s
user 0m2.251s
sys 0m0.134s

real 0m2.522s
user 0m2.279s
sys 0m0.159s

Well, the results look small, but this time can add up after a while. The funny part is the actual image of the kernel is only 12% smaller - what a waste. Within the LKML, people actually suggest that this size option is used to reduce the livecd image - hahaha.

Though, it is possible that this option is on for another reason but I'm doubtful that this should stay on.


Hubert Samm said...

Hey, didn't know where to leave this, but in order for me to get your repository to work correctly, I had to insert a step in front of the apt-get for installing the keyring... I had to first do an apt-get update, then when that failed, I could run the apt-get for getting the keyring.