Experimental -O3 Optimizing The Linux Kernel For Better Performance Brought Up Again

Written by Michael Larabel in Linux Kernel on 23 June 2022 at 06:18 AM EDT. 79 Comments
LINUX KERNEL
A set of patches have been posted for making the "-O3" compiler optimization level more easily accessible when building the Linux kernel but still it's not recommended and some kernel developers do not even want to see it as a Kconfig option.

Right now there exists the "CC_OPTIMIZE_FOR_PERFORMANCE_O3" Kconfig option to set the "-O3" optimization level when building the kernel for making use of that higher optimization level over the default -O2. The hope is that the GCC or Clang compiler will better optimize the kernel for better performance, but right now that option is only exposed for the ARC CPU architecture port.

While -O3 optimizing user-space application builds is commonly done for achieving better performance, with the complexity of the kernel and the very large code-base it's prone to possible errors or incorrect behavior with the low-level kernel code. Thus -O3'ing the kernel isn't widely carried out due to the possibility of likely subtle and possibly difficult to notice/detect problems.

But there is interest by enthusiasts in -O3 optimizing the kernel for greater performance and/or by developers in building with the higher optimization level to try to uncover bugs within the Linux kernel code and/or the compiler itself where optimizations go awry.


Miko Larsson sent out a set of patches this week that would allow CC_OPTIMIZE_FOR_PERFORMANCE_O3 to be flipped on for non-ARC architectures -- i.e. make it available for all Linux kernel builds. It also marks the option clearly as being an "EXPERIMENTAL" feature.

The patch series is out for review. It has been suggested though about possibly removing the option even though it's always been used on ARC. The suggestion is for those interested in "experimental features" could just build the kernel using make KCFLAGS=-O3 to achieve the same O3 optimized build. Generally the upstream Linux kernel developers are quite conservative in aggressive compiler features just intended for performance gains when it can mean subtle bugs / hard to detect issues. But we'll see if anything more comes from this most recent discussion over the -O3 compiler optimizations for Linux kernel builds.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week