2014-04-24 12:07:47

by Michael Opdenacker

[permalink] [raw]
Subject: [PATCH 0/1] init/Kconfig: improve CC_OPTIMIZE_FOR_SIZE documentation

This patch proposes to warn users about the negative performance
impact of CC_OPTIMIZE_FOR_SIZE (compiling with -Os instead of -O2).
For the moment, we are just advising users not to select this option,
but extra details would be useful.

I made some experiments with this option. All of them yielded
degraded overall boot time. The kernel is smaller and hence is copied
and started earlier, but the benefits are quickly offset by the
slower kernel code. Even the total boot time is usually worse
than with a regular kernel.

Here are my latest results, on Atmel SAMA5D3 Xplained (ARM),
Linux 3.10, gzip compressed kernel:

Timestamp O2 Os Diff
Starting kernel 4.307 s 5.593 s -94 ms
Starting init 4.213 s 5.549 s -44 ms
Login prompt 21.085 s 22.900 s +1.815 s

Michael Opdenacker (1):
init/Kconfig: improve CC_OPTIMIZE_FOR_SIZE documentation

init/Kconfig | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

--
1.8.3.2


2014-04-24 12:08:26

by Michael Opdenacker

[permalink] [raw]
Subject: [PATCH 1/1] init/Kconfig: improve CC_OPTIMIZE_FOR_SIZE documentation

Signed-off-by: Michael Opdenacker <[email protected]>
---
init/Kconfig | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/init/Kconfig b/init/Kconfig
index 9d3585bb2a7a..b6394a9ddc38 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1251,7 +1251,19 @@ config CC_OPTIMIZE_FOR_SIZE
bool "Optimize for size"
help
Enabling this option will pass "-Os" instead of "-O2" to gcc
- resulting in a smaller kernel.
+ resulting in a smaller but slower kernel.
+
+ This option can be useful in very small systems where every
+ byte counts.
+
+ A smaller kernel will also be slightly faster to load and start.
+ However, experiments have shown that such early speedups are
+ quickly offset by the slower kernel speed. Unless you are running
+ a very simple user space, the total boot time should be degraded
+ by this option.
+
+ Anyway, kernel code will be slower to execute and overall system
+ performance will be degraded.

If unsure, say N.

--
1.8.3.2

2014-04-24 14:55:51

by Josh Triplett

[permalink] [raw]
Subject: Re: [PATCH 0/1] init/Kconfig: improve CC_OPTIMIZE_FOR_SIZE documentation

On Thu, Apr 24, 2014 at 02:07:33PM +0200, Michael Opdenacker wrote:
> This patch proposes to warn users about the negative performance
> impact of CC_OPTIMIZE_FOR_SIZE (compiling with -Os instead of -O2).
> For the moment, we are just advising users not to select this option,
> but extra details would be useful.
>
> I made some experiments with this option. All of them yielded
> degraded overall boot time. The kernel is smaller and hence is copied
> and started earlier, but the benefits are quickly offset by the
> slower kernel code. Even the total boot time is usually worse
> than with a regular kernel.
>
> Here are my latest results, on Atmel SAMA5D3 Xplained (ARM),
> Linux 3.10, gzip compressed kernel:
>
> Timestamp O2 Os Diff
> Starting kernel 4.307 s 5.593 s -94 ms
> Starting init 4.213 s 5.549 s -44 ms
> Login prompt 21.085 s 22.900 s +1.815 s

Did you get the times in the upper two rows transposed row/column? Based
on the diffs, I'd guess 4.213s goes in Os "Starting kernel", and 5.593s
goes in O2 "Starting init".

- Josh Triplett

2014-04-24 15:06:36

by Josh Triplett

[permalink] [raw]
Subject: Re: [PATCH 1/1] init/Kconfig: improve CC_OPTIMIZE_FOR_SIZE documentation

On Thu, Apr 24, 2014 at 02:07:34PM +0200, Michael Opdenacker wrote:
> Signed-off-by: Michael Opdenacker <[email protected]>

The benchmarks from your cover letter should appear here in the commit
message, along with corresponding information about kernel size.

> ---
> init/Kconfig | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/init/Kconfig b/init/Kconfig
> index 9d3585bb2a7a..b6394a9ddc38 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -1251,7 +1251,19 @@ config CC_OPTIMIZE_FOR_SIZE
> bool "Optimize for size"
> help
> Enabling this option will pass "-Os" instead of "-O2" to gcc
> - resulting in a smaller kernel.
> + resulting in a smaller but slower kernel.
> +
> + This option can be useful in very small systems where every
> + byte counts.
> +
> + A smaller kernel will also be slightly faster to load and start.
> + However, experiments have shown that such early speedups are
> + quickly offset by the slower kernel speed. Unless you are running
> + a very simple user space, the total boot time should be degraded
> + by this option.
> +
> + Anyway, kernel code will be slower to execute and overall system
> + performance will be degraded.

I'd suggest leaving out the middle paragraph ("A smaller kernel
will...") entirely; it seems already implied by "smaller but slower
kernel", and the last sentence of that paragraph seems quite speculative
given your benchmarks in the cover letter. That already should
counteract any mistaken impression people might have that -Os would
speed the kernel up. How about:

This option can be useful on very small systems where every
byte counts. However, the resulting kernel will be slower to
execute, and overall system performance will be degraded.

Also, when you collected your performance benchmarks, did you collect
any profiling information on what part of the kernel got slower?
Compiling a couple of kernel hotspots with -O2 (or -O3) might eliminate
the performance delta.

- Josh Triplett

2014-04-24 19:35:07

by Michael Opdenacker

[permalink] [raw]
Subject: Re: [PATCH 0/1] init/Kconfig: improve CC_OPTIMIZE_FOR_SIZE documentation

Hi Josh,

Thank you for your review!

On 04/24/2014 04:55 PM, Josh Triplett wrote:
> On Thu, Apr 24, 2014 at 02:07:33PM +0200, Michael Opdenacker wrote:
>> This patch proposes to warn users about the negative performance
>> impact of CC_OPTIMIZE_FOR_SIZE (compiling with -Os instead of -O2).
>> For the moment, we are just advising users not to select this option,
>> but extra details would be useful.
>>
>> I made some experiments with this option. All of them yielded
>> degraded overall boot time. The kernel is smaller and hence is copied
>> and started earlier, but the benefits are quickly offset by the
>> slower kernel code. Even the total boot time is usually worse
>> than with a regular kernel.
>>
>> Here are my latest results, on Atmel SAMA5D3 Xplained (ARM),
>> Linux 3.10, gzip compressed kernel:
>>
>> Timestamp O2 Os Diff
>> Starting kernel 4.307 s 5.593 s -94 ms
>> Starting init 4.213 s 5.549 s -44 ms
>> Login prompt 21.085 s 22.900 s +1.815 s
> Did you get the times in the upper two rows transposed row/column? Based
> on the diffs, I'd guess 4.213s goes in Os "Starting kernel", and 5.593s
> goes in O2 "Starting init".
Oops, yes I did. I shouldn't have tried to copy from a PDF file I
produced ;)

Thanks!

Michael.

--
Michael Opdenacker, CEO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com