On Mon, May 11, 2015 at 07:57:22PM +0200, Denys Vlasenko wrote:
> With both gcc 4.7.2 and 4.9.2, sometimes gcc mysteriously doesn't inline
> very small functions we expect to be inlined. In particular,
> with this config: http://busybox.net/~vda/kernel_config
> there are more than a thousand copies of tiny spinlock-related functions:
> 
> $ nm --size-sort vmlinux | grep -iF ' t ' | uniq -c | grep -v '^ *1 ' | sort 
> -rn | grep ' spin'
>     473 000000000000000b t spin_unlock_irqrestore
>     292 000000000000000b t spin_unlock
>     215 000000000000000b t spin_lock
>     134 000000000000000b t spin_unlock_irq
>     130 000000000000000b t spin_unlock_bh
>     120 000000000000000b t spin_lock_irq
>     106 000000000000000b t spin_lock_bh
> 
> Disassembly:
> 
> ffffffff81004720 <spin_lock>:
> ffffffff81004720:       55                      push   %rbp
> ffffffff81004721:       48 89 e5                mov    %rsp,%rbp
> ffffffff81004724:       e8 f8 4e e2 02          callq  <_raw_spin_lock>
> ffffffff81004729:       5d                      pop    %rbp
> ffffffff8100472a:       c3                      retq

Frame pointers make this even more awful, since without them this could
just become a single jmp.  (Assuming _raw_spin_lock shouldn't be
inlined too.)

> This patch fixes this via s/inline/__always_inline/ in spinlock.h.
> This decreases vmlinux by about 30k:
> 
>     text     data      bss       dec     hex filename
> 82375570 22255544 20627456 125258570 7774b4a vmlinux.before
> 82335059 22255416 20627456 125217931 776ac8b vmlinux

Nice improvement.  Given that this actually makes the kernel *smaller*,
presumably in addition to faster, this forced inlining seems completely
reasonable.

> Signed-off-by: Denys Vlasenko <dvlas...@redhat.com>
> Cc: Thomas Graf <tg...@suug.ch>
> Cc: David S. Miller <da...@davemloft.net>
> Cc: Bart Van Assche <bvanass...@acm.org>
> Cc: Peter Zijlstra <pet...@infradead.org>
> Cc: David Rientjes <rient...@google.com>
> Cc: David S. Miller <da...@davemloft.net>
> Cc: Andrew Morton <a...@linux-foundation.org>
> Cc: Linus Torvalds <torva...@linux-foundation.org>
> Cc: Oleg Nesterov <o...@redhat.com>
> Cc: Paul E. McKenney <paul...@linux.vnet.ibm.com>
> Cc: Ingo Molnar <mi...@kernel.org>
> Cc: Paul E. McKenney <paul...@linux.vnet.ibm.com>
> CC: linux-kernel@vger.kernel.org

Reviewed-by: Josh Triplett <j...@joshtriplett.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to