Tips for optimizing the system
System boot
Section titled “System boot”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)
sudo systemctl mask NetworkManager-wait-online.service
Speeding up initramfs unpacking
Section titled “Speeding up initramfs unpacking”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.
-
Change compression algorithm
Edit the
/etc/mkinitcpio.conf
file, adding the following lines:COMPRESSION="lz4"COMPRESSION_OPTIONS=(-9) -
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) -
Update initramfs images
After making changes, run the command:
Terminal window sudo mkinitcpio -P
Compilation flags
Section titled “Compilation flags”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)"
Ccache
Section titled “Ccache”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.timersudo 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:
sudo systemctl enable --now systemd-oomd
Ananicy CPP
Section titled “Ananicy CPP”Ananicy is a task prioritization daemon that greatly improves system responsiveness. We will install Ananicy CPP, rewritten in C++ for increased performance.
-
Install Ananicy CPP
Clone and build the package from AUR:
Terminal window git clone https://aur.archlinux.org/ananicy-cpp.gitcd ananicy-cppmakepkg -sric -
Enable the service
Enable and start the service:
Terminal window sudo systemctl enable --now ananicy-cpp -
Install additional rules (recommended)
Install extended rules for better optimization:
Terminal window git clone https://aur.archlinux.org/cachyos-ananicy-rules-git.gitcd cachyos-ananicy-rules-gitmakepkg -sric -
Restart the service
Restart the service to apply new rules:
Terminal window sudo systemctl restart ananicy-cpp
Haveged
Section titled “Haveged”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:
sudo pacman -S havegedsudo systemctl enable haveged
Rng-tools
Section titled “Rng-tools”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:
sudo pacman -S rng-toolssudo systemctl enable --now rngd
Cpu Power
Section titled “Cpu Power”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.
-
Install CPUPower utility
Terminal window sudo pacman -S cpupower -
Set performance mode
Terminal window sudo cpupower frequency-set -g performance -
Configure settings
Open the configuration file:
Terminal window sudo nano /etc/default/cpupowerFind and edit the line:
governor='performance' -
Enable the service
Terminal window sudo systemctl enable cpupower
Auto CpuFreq
Section titled “Auto CpuFreq”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.
-
Install from AUR
Terminal window yay -S auto-cpufreq -
Enable the service
Terminal window sudo systemctl enable --now auto-cpufreq
Optimizing kernel loading
Section titled “Optimizing kernel loading”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
sudo grub-mkconfig -o /boot/grub/grub.cfg
You want more?
Section titled “You want more?”I suggest you visit this repo. It contains all the ways to optimize Arch linux.