Skip to content

Tips for optimizing the system

To find out which process is slowing down your system startup the most, run the systemd-analyze blame command

Let me guess, NetworkManager-wait-online has turned out to be a traitor and is taking ~4 seconds off your system startup? No problem. You can just disable it)

Terminal window
sudo systemctl mask NetworkManager-wait-online.service

This is the initial boot environment that completes the Linux kernel image. To save space, it is presented as a self-extracting archive. In Arch Linux, the mkinitcpio utility creates initramfs and by default uses the zstd compression algorithm. To speed up loading, it is better to use the lz4 algorithm.

  1. Change compression algorithm

    Edit the /etc/mkinitcpio.conf file, adding the following lines:

    COMPRESSION="lz4"
    COMPRESSION_OPTIONS=(-9)
  2. Replace hooks with systemd (optional)

    For additional acceleration, replace base and udev hooks with systemd:

    HOOKS=(systemd autodetect microcode modconf kms keyboard sd-vconsole block filesystems fsck)
  3. Update initramfs images

    After making changes, run the command:

    Terminal window
    sudo mkinitcpio -P

Compilation flags are pointers for the compiler on what instructions and optimizations to use when building programs.

To optimize the build process, we can change them by creating a custom ~/.makepkg.conf config in the home directory to override system settings:

CFLAGS="-march=native -mtune=native -O2 -pipe -fno-plt -fexceptions \
-Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security \
-fstack-clash-protection -fcf-protection"
CXXFLAGS="$CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"
RUSTFLAGS="-C opt-level=3 -C target-cpu=native -C link-arg=-z -C link-arg=pack-relative-relocs"
MAKEFLAGS="-j$(nproc) -l$(nproc)"

Linux has programs that can take more than two hours to build, and ccache can be used to speed up the recompilation of applications such as Wine or Proton-GE.

Ccache is a cache for C/C++ compilers, compatible with GCC and Clang, that speeds up recompilation of the same code. If identical blocks of source code are found when building a new version of a program, ccache uses already compiled code from the cache, which greatly speeds up the compilation process.

To install it, run the following commands:

sudo pacman -S ccache

After installation, it still needs to be activated in your makepkg settings. To do this, edit the ~/.makepkg.conf configuration file by adding the following configurations:

BUILDENV=(!distcc color ccache check !sign)

This is a command used in solid state drives (SSDs) that allows the operating system to tell the drive which data blocks are no longer needed and can be cleared. This helps maintain SSD performance by preventing the SSD from slowing down when writing data.

To enable it, run the following commands:

sudo systemctl enable fstrim.timer
sudo fstrim -v /

Out-Of-Memory Killer (OOM) is a Linux process that terminates an application to save the kernel from crashing. It sacrifices the application to keep the OS running.

To enable it, run the command:

Terminal window
sudo systemctl enable --now systemd-oomd

Ananicy is a task prioritization daemon that greatly improves system responsiveness. We will install Ananicy CPP, rewritten in C++ for increased performance.

  1. Install Ananicy CPP

    Clone and build the package from AUR:

    Terminal window
    git clone https://aur.archlinux.org/ananicy-cpp.git
    cd ananicy-cpp
    makepkg -sric
  2. Enable the service

    Enable and start the service:

    Terminal window
    sudo systemctl enable --now ananicy-cpp
  3. Install additional rules (recommended)

    Install extended rules for better optimization:

    Terminal window
    git clone https://aur.archlinux.org/cachyos-ananicy-rules-git.git
    cd cachyos-ananicy-rules-git
    makepkg -sric
  4. Restart the service

    Restart the service to apply new rules:

    Terminal window
    sudo systemctl restart ananicy-cpp

I can also recommend the package Haveged. This is a daemon that monitors the entropy of the system. It is needed to speed up system startup at high systemd-analyze blame (More than 1 second).

To install it, run the following commands:

Terminal window
sudo pacman -S haveged
sudo systemctl enable haveged

Rng-tools - a daemon that also monitors system entropy, but, unlike haveged, via a hardware timer. It is needed to speed up system startup at high systemd-analyze blame (More than 1 second).

To install it, run the following commands:

Terminal window
sudo pacman -S rng-tools
sudo systemctl enable --now rngd

By default, the processor dynamically changes its frequency, which provides a balance between power saving and performance. However, for maximum performance, you can lock the maximum frequency mode.

  1. Install CPUPower utility

    Terminal window
    sudo pacman -S cpupower
  2. Set performance mode

    Terminal window
    sudo cpupower frequency-set -g performance
  3. Configure settings

    Open the configuration file:

    Terminal window
    sudo nano /etc/default/cpupower

    Find and edit the line:

    governor='performance'
  4. Enable the service

    Terminal window
    sudo systemctl enable cpupower

This is a utility for automatically optimizing CPU speed and power consumption. It monitors battery status, CPU utilization, temperature and system load, dynamically switching between power saving and high performance modes.

  1. Install from AUR

    Terminal window
    yay -S auto-cpufreq
  2. Enable the service

    Terminal window
    sudo systemctl enable --now auto-cpufreq

You can change the kernel boot parameters in GRUB a bit, change the following line in /etc/default/grub adding the following parameters to your own:

GRUB_CMDLINE_LINUX_DEFAULT="... loglevel=2 nowatchdog split_lock_detect=off processor.ignore_ppc=1 migrations=off msr.allow_writes=on pcie_aspm=force module.sig_unenforce cryptomgr.notests initcall_debug no_timer_check noreplace-smp page_alloc.shuffle=1 rcupdate.rcu_expedited=1 tsc=reliable ..."

And finally update grub

Terminal window
sudo grub-mkconfig -o /boot/grub/grub.cfg

I suggest you visit this repo. It contains all the ways to optimize Arch linux.