Linux Performance Tuning: 7 Proven Fixes, 3 Mistakes

Most advice on Linux performance tuning is a list of commands to paste. I ran the common ones from this post's earlier version on a clean Debian 13.7 virtual machine (kernel 6.12, 4 vCPU, 2 GB RAM, no swap), and several of them either fail or quietly do nothing on a current system. Below is what really happens, in the order I would work on a slow server: measure first, profile second, change one setting last.

Linux performance tuning lab: sysctl --system output where /etc/sysctl.conf overrides the value from sysctl.d
Real lab output: the value from /etc/sysctl.d/90-tuning.conf lost to the old /etc/sysctl.conf.

Linux performance tuning starts with measuring

Linux performance tuning means you do not touch a sysctl before you know which resource is short. Four commands answer that in under a minute. vmstat 1 3 shows run queue, memory, swap, I/O and CPU split in one table. With stress-ng --cpu 2 running on the 4-core lab, the table changed exactly as expected:

# vmstat 1 3
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 0  0      0 1006920  26512 815696    0    0     0     0   82   42  0  0 100  0  0  0

# stress-ng --cpu 2 --timeout 8s >/dev/null 2>&1 & sleep 2; vmstat 1 3
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 2  0      0 978108  26512 832668    0    0     0     0  743   43 50  1 50  0  0  0

Two runnable processes (r = 2) and 50% user time on four cores means two cores are saturated and two are free. That reading tells you the workload is not parallel, which no Linux performance tuning of the kernel will fix.

Read iostat -x from the second report onward. The first report is the average since boot, which is why my first block showed 3.86% user time on an idle machine and the second block showed 0.00. For history you need the sysstat collector, and on Debian it is off by default:

# grep -v "^#" /etc/default/sysstat | grep -v "^$"
ENABLED="false"

# sar -u -f /var/log/sysstat/sa$(date +%d)
Cannot open /var/log/sysstat/sa10: No such file or directory

Set ENABLED="true" and restart the sysstat service now, because the data you need after an incident is the data from before it. If you prefer one interactive view, see the btop guide.

Profiling for Linux performance tuning with strace and perf

Once a process is the suspect, strace -c counts system calls. On ls -R /usr/share/doc it put 46% of the syscall time in getdents64 (842 calls), which is just directory reading, so nothing was wrong there. The more useful lesson came from dd with a tiny block size:

# strace -c dd if=/dev/zero of=/dev/null bs=512 count=200000 2>&1 | tail -1
100.00    0.900703           2    400122        14 total

# perf stat dd if=/dev/zero of=/dev/null bs=512 count=200000      (100 MB)
       0.057103220 seconds time elapsed
# perf stat dd if=/dev/zero of=/dev/null bs=1M count=2000         (2 GB)
       0.041572837 seconds time elapsed

Under strace the 512-byte run made 400,122 system calls and took 0.9 s; without it, 100 MB took 57 ms while 2 GB with a 1 MB block took 42 ms. The fix was a bigger block size, not a sysctl. Linux performance tuning often ends like this.

Two traps with perf on a virtual machine. First, hardware counters are not exposed, so cycles and instructions print <not supported>. Second, Debian ships kernel.perf_event_paranoid = 3, so a normal user gets "Access to performance monitoring and observability operations is limited". Lower it only on a machine you control and read the kernel perf security document first.

CPU and memory: Linux performance tuning settings that surprise you

Pinning and priorities, the basic CPU part of Linux performance tuning, work as documented, with two details. taskset -c 0 kept a stress process on CPU 0, but taskset -c 5 true on a 4-CPU machine fails with "Invalid argument". A normal user can raise the nice value of a process (0 to 5) but not lower it: renice -n -5 gave "Permission denied". Root can set -5 without complaint.

For memory, the swappiness line from the old post needs root, and a non-root shell gets "Permission denied" on both the redirect and sysctl -w. The default is 60 and this VM had no swap at all, so the value changes nothing until swap exists. Clearing the page cache is the habit I would drop completely:

# free -m | head -2   (after writing a 400 MB file)
Mem:            1973         316         572           0        1241        1657
# time cat /root/cache.bin > /dev/null
real	0m0.045s

# sync; echo 3 > /proc/sys/vm/drop_caches; free -m | head -2
Mem:            1973         226        1797           0          46        1747
# time cat /root/cache.bin > /dev/null
real	0m0.143s

Dropping the cache freed 1.2 GB on paper and made the next read of the same file three times slower (45 ms to 143 ms), because it had to come from disk again. The kernel also logs every use (drop_caches: 3). In Linux performance tuning, free memory is not a goal; "available" is the number to watch.

The dirty-page settings are linked, which the old post did not mention. After sysctl -w vm.dirty_bytes=268435456, vm.dirty_ratio reads 0, and setting the ratio again resets the bytes value to 0. Pick one pair and stick to it. The defaults here were dirty_ratio = 20 and dirty_background_ratio = 10, so the old advice only re-applied what was already set. The kernel vm sysctl documentation explains each key.

Disk scheduler and network settings: three mistakes to avoid

Mistake one in disk tuning: echo deadline > /sys/block/sda/queue/scheduler. On a current multi-queue kernel the name is mq-deadline, and the old name fails with "write error: Invalid argument". My virtio disk used [none], and both mq-deadline and bfq could be selected at runtime. That change is lost at reboot, so persist it with a udev rule:

# cat /etc/udev/rules.d/60-ioscheduler.rules
ACTION=="add|change", KERNEL=="vd[a-z]", ATTR{queue/scheduler}="mq-deadline"
# udevadm control --reload; udevadm trigger --action=change --sysname-match=vda
none [mq-deadline] bfq

For the scheduler itself, the kernel documentation on switching schedulers is the reference. On NVMe and virtio disks none is usually right; test mq-deadline or bfq only when you can measure the difference.

Mistake two: persisting sysctl values in the wrong place. Debian 13 has no /etc/sysctl.conf at all, so the old echo ... >> /etc/sysctl.conf creates it, and sysctl -p without a file reads only that one. The files in /etc/sysctl.d/ are ignored by it. Worse, when I put 16 MB buffers in /etc/sysctl.d/90-tuning.conf and kept the old 12 MB lines in /etc/sysctl.conf, sysctl --system loaded the .conf file last and the 12 MB value won (see the screenshot at the top). For reliable Linux performance tuning keep one source of truth, preferably a file in sysctl.d, and check with sysctl net.core.rmem_max after every change. A typo is reported, not ignored: cannot stat /proc/sys/net/core/rmem_mx.

Mistake three: copying ethtool -K eth0 tso off gso off. The interface here was ens3, so the command failed with "No such device". On the real name, the virtio driver refused with "Could not change any device features" and exit code 1. Offload settings also differ by driver, so read ethtool -k first and change one feature at a time on a physical NIC.

A safe order for Linux performance tuning

  1. Enable sysstat collection so your Linux performance tuning has history to work from.
  2. Use vmstat and iostat -x (second report) to find the short resource.
  3. Profile the suspect process with strace -c or perf stat before changing the system.
  4. Change one runtime value with sysctl -w, measure again, and only then write it to /etc/sysctl.d/.
  5. Keep the old value in your notes so you can roll back.

Frequently asked questions

Is Linux performance tuning safe on production? Runtime changes are reversible and are lost at reboot, which makes them a good test. Persisting them is the step that needs a change window.

Does Linux performance tuning include running drop_caches regularly? No. In my test it made the same read three times slower and gave nothing back that the kernel would not reclaim on its own.

Why does sysctl -p ignore my Linux performance tuning file? Without an argument it reads only /etc/sysctl.conf. Use sysctl --system or name the file.

Conclusion

Good Linux performance tuning is mostly measurement and restraint: the biggest gain in this lab came from a block size, not a kernel parameter, and three of the old post's commands failed or were overridden on Debian 13. Measure, change one thing, verify, and then persist it. Linux performance tuning tested on: lab Debian 13.7, kernel 6.12, sysstat 12.7.5, strace 6.13, linux-perf 6.12.

Comments

Popular posts from this blog

Linux Desktop Frozen? 5 Proven Fixes Before a Hard Reboot

Minecraft Bedrock on Linux: 4 Proven Ways to Play in 2026

DXVK in Wine on Linux: 7 Easy Setup Steps, Tested