Tips for speeding up your Linux system
Hard Disk Requests Scheduler
Many of XanMod's benefits depend on the I/O scheduler. Historically, Linux has supported many I/O schedulers, but these days, the choice comes down to Multiqueue Deadline (mq-deadline
), Kyber, and BFQ. Check their availability with this command:
$ cat /sys/block/sda/queue/scheduler
Multiqueue Deadline is an adaptation of the original Deadline scheduler, which was created to guarantee a start service time for a request. Our tests showed that mq-deadline
is a good all-rounder with no drawbacks, yet with few advantages as well.
Kyber is a more recent scheduler tuned for fast multi-queue devices, such as modern NVMe drives. It has two queues: one synchronous and another for asynchronous requests.
BFQ is often advertised as the best scheduler of all. In fact, it provides the best interactivity for systems with relatively slow drives, including the low-end SSDs. If you wish to eliminate the slow I/O bottleneck and make disk read/writes appear to be faster, BFQ is second to none. Switch to the desired scheduler in the runtime using the following template:
$ sudo echo scheduler_name > /sys/block/sda/queue/scheduler
In the case of BFQ, it also makes sense to add the scsi_mod.use_blk_mq=1
boot option in the GRUB configuration (Figure 2).
![](/var/linux_magazin/storage/images/issues/2020/238/performance-tweaks/figure-2/772177-1-eng-US/Figure-2_large.png)
Changing the scheduler affects the Linux system when it is under heavy workload. For instance, try to encode or archive something big (or otherwise load the CPU), and then try to copy some data on a flash thumb drive. Such an exercise will show how the system handles the huge flow of I/O requests, which could help you decide with the right scheduler.
Make the Processes Run Nicer
Modern Linux systems include several services that start during boot time. Some of these services may be unused and therefore disabled with no harm. The first step is to look at which services are consuming the boot time:
$ systemd-analyze blame
This command prints the list of auto-started services in the descending order based on how much time they took to start. If you don't know what a service is used for, don't disable it. However, if you are not managing a mail server, then it is safe to turn off Postfix. Also, consider if CUPS (for printing) and database services like PostgreSQL or MariaDB are there for any use. Disabling a service is as simple as:
$ sudo systemctl disable service_name
Use stop
instead of disable
to stop a service immediately. For the rest, re-sort and optimize the running processes using Ananicy. Ananicy [1], a third-party tool, consists of a shell script and a systemd daemon to control priorities of running processes and applications. This is solely a desktop-oriented tweak intended to solve such issues as, "Why does my game lag during kernel compilation?" Ananicy ships with a community-maintained list of rules, which are very sane for the most part. After installing the tool (follow the README.md
guide), enable and start Ananicy as follows:
$ sudo systemctl enable ananicy && sudo systemctl start ananicy
The effect of tools such as Ananicy will be different across the endless variety of configurations, but it is always noticeable. Ananicy is perfect for laptops – it makes batteries last longer and fans behave more quietly.
Apply Filesystem Tweaks
In the past, it was common to hear the advice of using the noatime
mounting option for partitions listed in /etc/fstab
. This option is counterproductive in modern Linux systems that already use the less risky and performance-friendly relatime
option by default.
For everyday scenarios with most major Linux systems, the most balanced and fastest filesystem is usually ext4, which is already tuned for the best performance in most mainstream distros. However, long-running Linux systems suffer from disk fragmentation, which leads to slowdowns. Fragmentation in Linux isn't a nightmare that it used to be in the Windows world in late 90s, but it is still a problem if your Linux machine runs intensive disk reads and writes for a long time. The solution is defragmenting. There is the universal script by Con Kolivas, defrag
[2], that rewrites files in order of largest to smallest and works for any filesystem. But, for the extX filesystem family, a better solution is shipped within the E2fsprogs package. Start by examining the current state of fragmentation for a test /dev/sda3
partition:
$ sudo e4defrag -c /dev/sda3
Look at the 'Fragmentation score' and see if it is not too high (e.g., below 30). Even if the partition is healthy, the above command will list the files that have been fragmented and may suffer from longer access times. It is easy to defragment them with this command:
$ sudo e4defrag /dev/sda3
The e4defrag
command also accepts directories, so that you don't have to process the whole partition if you only work with a given directory. More than that, defragmenting adjusts free extents to the size of the files that you store. So, if you run the e2freefrag
tool afterwards, you'll see the table of extents of different sizes, adapted to the kind of information that already exists on the disk (Figure 3):
$ sudo e2freefrag /dev/sda3
![](/var/linux_magazin/storage/images/issues/2020/238/performance-tweaks/figure-3/772180-1-eng-US/Figure-3_large.png)
In addition to traditional defragmentation, you can also improve ext4 filesystem performance by reallocating frequently used files using e4rat. This tool reduces disk access time utilizing the EXT4_IOC_MOVE_EXT
ioctl
feature of ext4 and doing so-called online defragmentation. Modern e4rat code [3] takes few minutes to build from source (see the project page for guidance). Normally, e4rat requires three phases: first for learning (collecting files), second for reallocating what has been collected, and third for preloading reallocated data to page cache (Figure 4). To get started with e4rat, enter:
$ sudo systemctl stop auditd // (auditd conflicts with E4rat) $ sudo e4rat-collect // (start opening apps you want to optimize, hit Ctrl+C when done) $ sudo e4rat-realloc e4rat-collect.log
![](/var/linux_magazin/storage/images/issues/2020/238/performance-tweaks/figure-4/772183-1-eng-US/Figure-4_large.png)
This technique effectively makes every cold start of an optimized app feel like it is hot, which is a great aid for slow or low-end Linux systems.
« Previous 1 2 3 Next »
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.