Skip to content

Linux performance optimizations

This is a collection of optimizations that I've gathered over time to make my Arch Linux systems boot faster and run smoother.

Testing

This has been tested on all of my systems, please have an arch install usb ready in case something goes wrong. My systems are:

NameCPURAMStorage
ThinkPad T14 Gen 2AMD Ryzen 7 PRO 5850U2x16GB DDR42TB WD Green SN350 NVMe
Main PCIntel Core i5-10400F2x16GB DDR41TB Lexar NM710 NVMe + 4TB HDD
ThinkPad T470sIntel Core i5-7300U24GB DDR41TB i-dont-remember NVMe

Setting up Booster initramfs

  1. Install booster
yay -S booster
  1. Edit the /etc/booster.yaml file so it applies ZSTD compression

Other options

You might want to enable module stripping if you're feeling adventurous. It will make the initramfs smaller, but it might break things.
To enable it add strip: true to the booster.yaml file.

yaml
compression: zstd
  1. Regenerate the initramfs
bash
sudo /usr/lib/booster/regenerate_images
  1. Adding a pacman hook to regenerate the initramfs on kernel updates. Run sudo nvim /etc/pacman.d/hooks/90-booster-rebuild.hook and add the following:
bash
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = linux-*
# Change to just `linux` if you only use the default kernel

[Action]
Description = Regenerating Booster initramfs...
When = PostTransaction
Exec = /usr/lib/booster/regenerate_images

Setting up EFIStub booting (removing the bootloader)

  1. Forward your current kernel parameters to a file readable by systemd-ukify
bash
cat /proc/cmdline | sudo tee /etc/kernel/cmdline
  1. Install systemd-ukify
bash
yay -S systemd-ukify
  1. Build the EFI stub image. I am using the linux-cachyos kernel, if you're using a different one, look for the appropriate files in /boot/
bash
sudo ukify build \
    --linux=/boot/vmlinuz-linux-cachyos \
    --initrd=/boot/amd-ucode.img \
    --initrd=/boot/booster-linux-cachyos.img \
    --cmdline="@/etc/kernel/cmdline" \
    --output=/boot/EFI/linux-cachyos/arch-linux-cachyos.efi
  1. Add a new boot entry to UEFI

IMPORTANT

Make sure to change /dev/nvme0n1 and -p 1 to the appropriate disk and partition where your EFI System Partition is located.
You can check this with lsblk, and looking for the partition with the /boot mountpoint. In my example, it's /dev/nvme0n1p1.

❯ lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
zram0       253:0    0    4G  0 disk [SWAP]
nvme0n1     259:0    0  1.8T  0 disk 
├─nvme0n1p1 259:1    0    1G  0 part /boot
└─nvme0n1p2 259:2    0  1.8T  0 part /
bash
sudo efibootmgr -c -d /dev/nvme0n1 -p 1 -L "ArchLinux" -l 'EFI/linux-cachyos/arch-linux-cachyos.efi'
  1. Add a pacman hook to rebuild the EFI stub image on kernel updates. Edit this to match your kernel and initramfs paths. Run sudo nvim /etc/pacman.d/hooks/95-ukify.hook and add the following, replacing the paths with the ones that match your system:
bash
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = linux-cachyos

[Action]
Description = Rebuilding the UKI...
When = PostTransaction
Exec = /usr/bin/systemd-ukify build --linux=/boot/vmlinuz-linux-cachyos --initrd=/boot/amd-ucode.img --initrd=/boot/booster-linux-cachyos.img --cmdline="@/etc/kernel/cmdline" --output=/boot/EFI/linux-cachyos/arch-linux-cachyos.efi
  1. Reboot, and remove your old bootloader from the system, it's no longer needed as the system will boot directly from the EFI stub.

Optimizing NetworkManager

This only applies if you are using NetworkManager, and cannot just replace it with systemd-networkd.

  1. Disable the wait-online service. This will make your system boot slightly faster, but it will not wait for the network to be fully up before finishing the boot process. This doesn't matter in 99.9% of cases.
bash
sudo systemctl disable NetworkManager-wait-online.service

Using ZRAM

ZRAM creates compressed blocks of RAM that can be used as swap. This is beneficial for all systems.

  1. Install zram-generator
bash
yay -S zram-generator
  1. Create a configuration file for zram-generator. Run sudo nvim /etc/systemd/zram-generator.conf and add the following:
ini
[zram0]
zram-size = min(ram / 2, 4096)
compression-algorithm = zstd
  1. Reload daemons and start the zram swap
bash
sudo systemctl daemon-reload
sudo systemctl enable systemd-zram-setup@zram0.service
sudo systemctl start systemd-zram-setup@zram0.service
  1. Verify that the zram swap is active
bash
sudo systemctl status systemd-zram-setup@zram0.service

Kernel parameters

How to edit

Edit the /etc/kernel/cmdline file to add or remove kernel parameters.

  1. Using the ADIOS elevator
elevator=adios
  1. Overall optimizations
rw zswap.enabled=0 loglevel=3 quiet