# [solved] Kernel optimize for size?

## MrBlond83

Okay, I have a simple question, one which I could seem to find an answer for in the forums:

Is "optimize for size" flag recommended when compiling a kernel? I have had it on for the past 5 or 6 kernels I compiled, but now I wonder if it's actually better to turn it off. My /boot partition is 100mb, so I don't really have any size problems, but I was wondering, if the kernel is loaded into memory, isn't it better to have it small than to O2 it?

I'm not sure which would yield better performance, O2 or Os.Last edited by MrBlond83 on Sat Dec 02, 2006 2:19 pm; edited 1 time in total

----------

## DocReedSolomon

are you actually talking about that flag in make.conf (CFLAGS)? its not used anyway for kernel compile   :Razz: 

or are you talking about

```

# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set

# CONFIG_EMBEDDED is not set

```

in the kernel .config itself  :Shocked: 

----------

## bLUEbYTE84

 *MrBlond83 wrote:*   

> Okay, I have a simple question, one which I could seem to find an answer for in the forums:
> 
> Is "optimize for size" flag recommended when compiling a kernel? I have had it on for the past 5 or 6 kernels I compiled, but now I wonder if it's actually better to turn it off. My /boot partition is 100mb, so I don't really have any size problems, but I was wondering, if the kernel is loaded into memory, isn't it better to have it small than to O2 it?
> 
> 

 

I used to choose that setting (optimize for size) in config but for some time I don't enable it; I recommed you, and everyone except with non-standard systems(embedded system with various constraints etc) to avoid it.

And also, although I never experienced or heard about, is the possibilty to produce broken executables, may be caused by the specific optimizations for code size introduced with Os.

 *Quote:*   

> 
> 
> I'm not sure which would yield better performance, O2 or Os.
> 
> 

 

In my benchmarks in amd64 with a 256K cache sempron64 CPU, O2 compiled kernel always outperforms the Os compiled. Test it for yourself. One would think that O2 would be slower on a such low-cache system, but the benchmarks doesn't say so. For me, O2 kernel was always a few percents faster on this system.  I think the speed difference(being faster) of O2 would be even more with standard range CPUs with more cache.

The bzImage size difference seems to be around 200-300 kb for me.

----------

## MrBlond83

Thanks for your reply.

I was not talking about the CFLAGS in make.conf, but about CONFIG_CC_OPTIMIZE_FOR_SIZE.

I will try to compile my next kernel with O2 and see how it goes.

----------

