lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150412054747.GA9062@gmail.com>
Date:	Sun, 12 Apr 2015 07:47:47 +0200
From:	Ingo Molnar <mingo@...nel.org>
To:	Linus Torvalds <torvalds@...ux-foundation.org>
Cc:	Thomas Gleixner <tglx@...utronix.de>,
	Jakub Jelinek <jakub@...hat.com>,
	Denys Vlasenko <dvlasenk@...hat.com>,
	Borislav Petkov <bp@...en8.de>,
	Tim Chen <tim.c.chen@...ux.intel.com>,
	Andy Lutomirski <luto@...capital.net>,
	Jason Low <jason.low2@...com>, Brian Gerst <brgerst@...il.com>,
	Aswin Chandramouleeswaran <aswin@...com>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Davidlohr Bueso <dave@...olabs.net>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	"H. Peter Anvin" <hpa@...or.com>,
	LKML <linux-kernel@...r.kernel.org>,
	Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH] x86: Turn off GCC branch probability heuristics


* Linus Torvalds <torvalds@...ux-foundation.org> wrote:

> On Sat, Apr 11, 2015 at 11:57 AM, Thomas Gleixner <tglx@...utronix.de> wrote:
> >
> > I thinks its just the no-guess one:
> >
> >    text        data       dec  patch           reduction
> > 7563475     1781048  10302987
> > 7192973     1780024   9931461  no-guess            -4.8%
> > 7354819     1781048    958464  align-1             -2.7%
> > 7192973     1780024   9931461  no-guess + align-1  -4.8%
> 
> Yeah, a 5% code expansion is a big deal. Sadly, it looks like
> 'no-guess' also disables our explicit likely/unlikely handling.

So I spent some time trying to get as much code size reduction as 
possible via GCC optimization options, and the total savings possible 
are 10.1%:

     text           data     bss      dec    filename
 12566391        1617840 1089536 15273767    vmlinux.vanilla
 11416805        1617840 1089536 14124181    vmlinux.combo
 10532552        1596080 1089536 13218168    vmlinux.Os

(combo patch attached below.)

The -Os savings are 19% total - but as you mentioned before, it's 
sometimes achieved through unacceptable techniques.

Unfortunately I found no other GCC options to achieve what -Os does - 
the missing 9% can purely be achieved via -Os, with no cherry-picking 
possible.

The other, smaller savings are:

+        # Reduces vmlinux size by 0.25%:
+        KBUILD_CFLAGS += -fno-caller-saves
+
+        # Reduces vmlinux size by 1.10%:
+        KBUILD_CFLAGS += -fno-inline-small-functions
+
+        # Reduces vmlinux size by about 0.95%:
+        KBUILD_CFLAGS += -fno-tree-ch

(each of them has to be double checked to make sure it leads to 
nothing silly and unacceptable - I just blindly tried to find GCC 
options that impacted kernel code size.)

Thanks,

	Ingo


---
 arch/x86/Makefile | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 5ba2d9ce82dc..999e94685d12 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -77,10 +77,34 @@ else
         KBUILD_AFLAGS += -m64
         KBUILD_CFLAGS += -m64
 
+        # Pack jump targets tightly, don't align them to the default 16 bytes:
+        KBUILD_CFLAGS += -falign-jumps=1
+
+        # Pack functions tightly as well:
+        KBUILD_CFLAGS += -falign-functions=1
+
+        # Pack loops tightly as well:
+        KBUILD_CFLAGS += -falign-loops=1
+
         # Don't autogenerate traditional x87 instructions
         KBUILD_CFLAGS += $(call cc-option,-mno-80387)
         KBUILD_CFLAGS += $(call cc-option,-mno-fp-ret-in-387)
 
+        #
+        # Don't guess branch probabilities, follow the code and unlikely()/likely() hints,
+        # which reduces vmlinux size by about 5.4%:
+        #
+        KBUILD_CFLAGS += -fno-guess-branch-probability
+
+        # Reduces vmlinux size by 0.25%:
+        KBUILD_CFLAGS += -fno-caller-saves
+
+        # Reduces vmlinux size by 1.10%:
+        KBUILD_CFLAGS += -fno-inline-small-functions
+
+        # Reduces vmlinux size by about 0.95%:
+        KBUILD_CFLAGS += -fno-tree-ch
+
 	# Use -mpreferred-stack-boundary=3 if supported.
 	KBUILD_CFLAGS += $(call cc-option,-mpreferred-stack-boundary=3)
 


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ