Optimizing the Linux Kernel
Speed Test
We explore some optimizations designed to deliver a smoother experience for desktop users.
The Linux kernel is the core part of all GNU/Linux operating systems. The kernel is designed to run on a large variety of hardware, from web servers to routers and embedded devices. The default versions of the Linux kernel that arrive with the mainstream Linux distros are optimized for some very basic use cases. For instance, Ubuntu comes in Server, Desktop, IoT, and Cloud editions – each with basic optimizations tailored for the usage scenario.
Most distros make some effort to customize the kernel for its intended purpose; however, no one but you knows exactly how you are using your own system. You can tweak the Linux kernel in hundreds of different ways to improve performance or reduce latency. I'll outline some of those techniques in this article. Of course, some of these tweaks might have already been enabled by your distro's vendor; others are more specific and are seldom used at all. The goal of this discussion is to take you down inside the kernel and to demonstrate various performance-related optimizations. Needless to say, tricks with the kernel have the potential to destabilize your system. These ideas are best explored with a test system – at least at first, until you are sure everything is working.
I'll discuss a range of Linux kernel optimizations with the goal of improving perceived desktop performance, including smoothness and snappiness. Such things may have little effect in synthetic tests (such as the ones often conducted by Phoronix), but they can have a strong effect on the user. I am aiming this discussion at desktop and laptop users, including the significant number of people who need to run Linux on low-performance and legacy hardware.
Tinkering with the Current Kernel
You don't need to recompile the kernel to improve kernel performance. The easiest way to tweak the Linux kernel is to use the optional boot parameters that run at the command line when the kernel boots up. You can make temporary changes in the GRUB 2 boot menu by editing the line that starts with linux
, or you can make persistent changes by changing the GRUB 2 configuration. The steps for changing the GRUB 2 configuration vary across different Linux distros. Sometimes you can use graphical GRUB 2 configuration tools (Figure 1), like the one shipped with YaST (SLE, openSUSE), or kcm-grub2
, which is designed for KDE Plasma, or the command-line grubby
utility. All of these tools change the contents of the grub.cfg
file and then update the GRUB 2 configuration:
$ sudo grub2-mkconfig -o /path/to/grub.cfg
The following sections describe a few of the most useful kernel parameters.
elevator=
The elevator
setting defines the Linux kernel behavior when distributing the I/O load on block devices (storage drives). This parameter defines the scheduler that will manage the I/O. Linux supports several different schedulers, which all have different strategies for balancing disk throughput and read/write latencies. Find out what schedulers are available and which one is currently used in your system with the following command:
$ cat /sys/block/sda/queue/scheduler
See the "Schedulers in Linux" box for more information on the available schedulers. The kyber
scheduler is reported to have the best performance with mechanical hard drives (elevator=kyber
), but if you are using a modern SSD or NVMe drive, it might be better use none
to reduce the CPU overhead (elevator=none
).
Schedulers in Linux
Modern hardware, with its enhanced support for multithreading and multiple CPUs, requires a new approach to scheduling. Linux is currently undergoing a transition to a new generation of multiqueuing schedulers. Consequently, some of the old schedulers that were popular in the past are gradually becoming deprecated. Ubuntu [1], for instance, has enabled multiqueue I/O scheduling by default in Ubuntu 19.10 onward and supports the following schedulers:
bfq
(Budget Fair Queueing) – optimized for interactive response, especially with slow I/O deviceskyber
– a simple algorithm supporting both synchronous and asynchronous requests; intended for "fast multiqueue devices"none
– does not reorder requests, thus consuming minimal overhead (multiqueue version of the oldnoop
scheduler)mq-deadline
– multiqueue version of the old deadline scheduler
Older schedulers, such as cfq
(Completely Fair Queueing), deadline, and noop
are deprecated in recent versions of Ubuntu and other distros; however, they are still used with older systems and in situations that do not require multiqueuing.
Staggered Spin-Up Elimination
Even if Linux is installed on a super-fast SSD, the boot process can get slow if any other rotational hard drive is attached to the computer. This issue is called staggered spin-up, which means that the OS probes ATA interfaces serially, one by one, to reduce the peak power consumption. Normally, desktop users do not benefit from this default configuration, and they often feel annoyed with the longer boot times. To see if your system is using staggered spin-up, enter:
# dmesg | grep SSS
If it is, eliminate the issue by passing the following boot parameter:
libahci.ignore_sss=1
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.