From: Linus Torvalds <torvalds@linux-foundation.org>
To: Adrian Bunk <bunk@kernel.org>
Cc: Sam Ravnborg <sam@ravnborg.org>,
linux arch <linux-arch@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
David Miller <davem@davemloft.net>
Subject: Re: [PATCH] prepare kconfig inline optimization for all architectures
Date: Sun, 27 Apr 2008 11:11:27 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.1.10.0804271053300.2896@woody.linux-foundation.org> (raw)
In-Reply-To: <20080427174714.GB2252@cs181133002.pp.htv.fi>
On Sun, 27 Apr 2008, Adrian Bunk wrote:
>
> What I want instead:
> - we continue to force the compiler to always inline with "inline"
> - we remove the inline's in .c files and make too big functions in
> headers out-of-line
Sure, I can agree with that as a mostly good goal, but you're still
ignoring the fact that nobody should really expect the compiler to always
do a good job at deciding high-level issues.
For example, what's wrong with having "inline" on functions in .c files if
the author thinks they are small enough? He's likely right. Considering
past behaviour, he's quite often more right than the compiler.
Just as an example of this: gcc will often inline even big functions, if
they are called from only one call-site. In fact, ask a compiler guy, and
he'll likely say that that is obviously a good thing.
But ask somebody who debugs the resulting oops reports, and he may well
disagree violently.
In other words, inlining is about much more than pure optimization.
Sometimes it's about forcing it (or not forcing it) for simple correctness
issues when the compiler doesn't understand that the code in question has
specific rules (for example, we sometimes want to *force* certain
functions to be in specific segments).
And sometimes it's about debugging. For the kernel, backtraces posted by
random users are one of the main debug facilities, and unlike many other
projects, it's not reasonable to ask people to recompile with "-O0 -g" to
get better backtraces. The bulk of all reports will come from people who
use precompiled images from a distribution.
And that means that inlining has a *huge* impact on debuggability.
I have vey often cursed gcc inlining some biggish function - who the f*ck
cares if a thousand-instruction function can shave a couple of
instructions of call overhead, when it then causes the call trace to be
really hard to read?
So quite frankly, my preferred optimization would be:
- Heavily discourage gcc from inlining functions that aren't marked
"inline". I suspect it hurts kernel debugging more than many other
projects (because other projects aren't as dependent on the traces)
- I do agree 100% with you that header file functions should be small
(unless they use __builtin_constant_p() or other tricks to guarantee a
much smaller static footprint than dynamic one)
- I also suspect we should have some way for developers to ask fo *hints*
from the compiler, ie instead of having gcc inline on its own by
default, have the people who care about it ask the compiler to warn
about cases where inlining would be a big win.
- Make "inline" mean "you may want to inline this", and "forced_inline"
mean "you *have* to inline this". Ie the "inline" is where the compiler
can make a subtle choice (and we need that, because sometimes
architecture or config options means that the programmer should not
make the choice statically!)
In short, in general I actually wish we'd inline much much less than we
do. And yes, part of that is that we have way too much code in our header
files.
Linus
next prev parent reply other threads:[~2008-04-27 18:12 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-27 10:51 Sam Ravnborg
2008-04-27 11:31 ` Adrian Bunk
2008-04-27 11:56 ` Sam Ravnborg
2008-04-27 12:36 ` Ingo Molnar
2008-04-27 12:49 ` Ingo Molnar
2008-04-27 17:06 ` Linus Torvalds
2008-04-27 17:22 ` Adrian Bunk
2008-04-27 17:32 ` Linus Torvalds
2008-04-27 17:47 ` Adrian Bunk
2008-04-27 18:00 ` Christoph Hellwig
2008-04-27 18:09 ` Sam Ravnborg
2008-04-27 18:14 ` Christoph Hellwig
2008-04-27 18:24 ` Linus Torvalds
2008-04-27 18:32 ` Christoph Hellwig
2008-04-27 19:36 ` Ingo Molnar
2008-04-27 19:49 ` Adrian Bunk
2008-04-27 23:26 ` Arjan van de Ven
2008-04-27 23:36 ` Linus Torvalds
2008-04-27 23:41 ` Ingo Molnar
2008-04-27 18:31 ` Sam Ravnborg
2008-04-27 18:36 ` Christoph Hellwig
2008-04-27 18:11 ` Linus Torvalds [this message]
2008-04-27 18:25 ` Christoph Hellwig
2008-04-27 18:30 ` Linus Torvalds
2008-04-27 18:41 ` Adrian Bunk
2008-04-27 18:57 ` Linus Torvalds
2008-04-27 20:51 ` Mike Galbraith
2008-04-27 17:57 ` Christoph Hellwig
2008-04-27 17:40 ` Matthew Wilcox
2008-04-27 17:59 ` Adrian Bunk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.1.10.0804271053300.2896@woody.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=bunk@kernel.org \
--cc=davem@davemloft.net \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=sam@ravnborg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®