Skip to content

Commit a771f2b

Browse files
Arjan van de VenLinus Torvalds
authored andcommitted
[PATCH] Add a section about inlining to Documentation/CodingStyle
Adds a bit of text to Documentation/Codingstyle to state that inlining everything "just because" is a bad idea Signed-off-by: Arjan van de Ven <arjan@infradead.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent e0804b1 commit a771f2b

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

‎Documentation/CodingStyle‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Remember: if another thread can find your data structure, and you don't
344344
have a reference count on it, you almost certainly have a bug.
345345

346346

347-
Chapter 11: Macros, Enums, Inline functions and RTL
347+
Chapter 11: Macros, Enums and RTL
348348

349349
Names of macros defining constants and labels in enums are capitalized.
350350

@@ -429,7 +429,35 @@ from void pointer to any other pointer type is guaranteed by the C programming
429429
language.
430430

431431

432-
Chapter 14: References
432+
Chapter 14: The inline disease
433+
434+
There appears to be a common misperception that gcc has a magic "make me
435+
faster" speedup option called "inline". While the use of inlines can be
436+
appropriate (for example as a means of replacing macros, see Chapter 11), it
437+
very often is not. Abundant use of the inline keyword leads to a much bigger
438+
kernel, which in turn slows the system as a whole down, due to a bigger
439+
icache footprint for the CPU and simply because there is less memory
440+
available for the pagecache. Just think about it; a pagecache miss causes a
441+
disk seek, which easily takes 5 miliseconds. There are a LOT of cpu cycles
442+
that can go into these 5 miliseconds.
443+
444+
A reasonable rule of thumb is to not put inline at functions that have more
445+
than 3 lines of code in them. An exception to this rule are the cases where
446+
a parameter is known to be a compiletime constant, and as a result of this
447+
constantness you *know* the compiler will be able to optimize most of your
448+
function away at compile time. For a good example of this later case, see
449+
the kmalloc() inline function.
450+
451+
Often people argue that adding inline to functions that are static and used
452+
only once is always a win since there is no space tradeoff. While this is
453+
technically correct, gcc is capable of inlining these automatically without
454+
help, and the maintenance issue of removing the inline when a second user
455+
appears outweighs the potential value of the hint that tells gcc to do
456+
something it would have done anyway.
457+
458+
459+
460+
Chapter 15: References
433461

434462
The C Programming Language, Second Edition
435463
by Brian W. Kernighan and Dennis M. Ritchie.
@@ -453,4 +481,4 @@ Kernel CodingStyle, by greg@kroah.com at OLS 2002:
453481
http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
454482

455483
--
456-
Last updated on 16 February 2004 by a community effort on LKML.
484+
Last updated on 30 December 2005 by a community effort on LKML.

0 commit comments

Comments
 (0)