locking/spinlocks: Force inlining of spinlock ops
authorDenys Vlasenko <dvlasenk@redhat.com>
Mon, 13 Jul 2015 18:31:03 +0000 (20:31 +0200)
committerIngo Molnar <mingo@kernel.org>
Tue, 21 Jul 2015 08:14:07 +0000 (10:14 +0200)
commit3490565b633c705d2fb1f6ede51228952664663d
tree264e6e7228a755b9890efec4db19449f5718c29f
parent9dea5dc921b5f4045a18c63eb92e84dc274d17eb
locking/spinlocks: Force inlining of spinlock ops

With both gcc 4.7.2 and 4.9.2, sometimes GCC mysteriously
doesn't inline very small functions we expect to be inlined.
See:

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66122

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

This patch fixes this via s/inline/__always_inline/ in
spinlock.h. This decreases vmlinux by about 40k:

      text     data      bss       dec     hex filename
  82375570 22255544 20627456 125258570 7774b4a vmlinux.before
  82335059 22255416 20627456 125217931 776ac8b vmlinux

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Bart Van Assche <bvanassche@acm.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Rientjes <rientjes@google.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Graf <tgraf@suug.ch>
Link: http://lkml.kernel.org/r/1436812263-15243-1-git-send-email-dvlasenk@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
include/linux/spinlock.h