This post is a sequel to my previous article, “Optimizing Debian 12 for Work.”
In that guide, we covered the “standard” Linux optimizations like Zram, Preload, and basic sysctl memory adjustments.
In this article, I want to push those limits further by implementing specific tweaks used by CachyOS.
I highly recommend checking out the distro documentation. Much like the Arch Wiki, it contains invaluable technical insights.
Let’s dive into the optimizations!
1. Advanced Udev Rules for Storage Performance
I’ve implemented three specific udev rules inspired by CachyOS. These rules focus on reducing latency and ensuring your drives (HDD, SSD, and NVMe) use the best possible I/O scheduler.
Create these files in /etc/udev/rules.d/:
69-hdparm.rules
This rule disables power management and auto-standby for all ATA/SATA HDDs. This prevents “spin-up” lag when accessing a drive after a period of inactivity.
In the 69-hdparm.rules, add:
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTRS{id/bus}=="ata", RUN+="/usr/bin/hdparm -B 254 -S 0 /dev/%k"
50-sata.rules
This disables power saving on SATA devices and sets the policy to max_performance.
In the 50-sata.rules, add:
ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}=="", ATTR{link_power_management_policy}="max_performance"
60-ioschedulers.rules
This ensures each storage type uses its most efficient I/O scheduler. We move away from the “one-size-fits-all” approach to a hardware-specific setup.
In the 60-ioschedulers.rules, add:
# HDD
ACTION=="add|change", KERNEL=="sd[a-z]*", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq"
# SSD
ACTION=="add|change", KERNEL=="sd[a-z]*|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"
# NVMe SSD
ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="none"
To apply these rules, run:
udevadm control --reload-rules && udevadm trigger
2. Sysctl Tweaks: The CachyOS Approach
This is a direct adaptation of the CachyOS sysctl configuration, fine-tuned for my work environment.
Create the file /etc/sysctl.d/99-sysctl.conf and paste the following:
# Memory Management
vm.swappiness = 100
vm.vfs_cache_pressure = 50
vm.dirty_background_bytes = 268435456
vm.dirty_bytes = 536870912
vm.dirty_writeback_centisecs = 1500
vm.page-cluster = 0
# Security and Performance
kernel.nmi_watchdog = 0
kernel.unprivileged_userns_clone = 1
kernel.printk = 3 3 3 3
kernel.kptr_restrict = 2
kernel.kexec_load_disabled = 1
# Network
net.core.netdev_max_backlog = 4096
net.ipv4.tcp_rmem=4096 87380 8388608
net.ipv4.tcp_wmem=4096 65536 8388608
# NFS
sunrpc.tcp_slot_table_entries=128
sunrpc.udp_slot_table_entries=128
fs.nfs.nlm_tcpport=0
fs.nfs.nlm_udpport=0
Key Highlights Explained:
- vm.swappiness = 100: This is controversial. Usually, guides suggest a low value (like 10).
However, CachyOS uses 100 to aggressively swap out inactive memory pages, keeping your RAM free for active, high-priority tasks.
This works best if you have a fast SSD or Zram enabled. - vm.vfs_cache_pressure = 50: Tells the kernel to keep filesystem metadata (like directory structures) in RAM longer, speeding up file navigation.
- vm.page-cluster = 0: Optimized for SSDs. It disables readahead for contiguous pages, which is unnecessary for low-latency flash storage.
- kernel.nmi_watchdog = 0: Disables the NMI monitor to slightly reduce CPU interrupts and power consumption.
- net.core.netdev_max_backlog = 4096: Increases the network packet queue, preventing packet loss during intense traffic.
Final Thoughts
Setting vm.swappiness to 100 is a bold move compared to the usual “set it to 10” advice.
I’ll be testing this setup for a few days to see how it handles my daily workflow (Virtual Machines, multiple browser tabs, and remote access).
See you then!