Skip to content

Lesson 7 of 9 · 23m

Kernel Tuning: sysctls That Matter and Ones That Do Not

How to tune networking, memory, and file-handle parameters deliberately — with rollback notes and evidence.

Every organization eventually inherits a sysctl.conf written by a ghost. It contains cargo-cult TCP tuning copied from a 2011 blog post, swappiness set to zero because someone read that swap is bad, and half a dozen values nobody can explain. Kernel tuning is powerful precisely because it is global. Treat it like database schema changes: small, reviewed, measured, and reversible.

Put tuning in files, not folklore

Use version-controlled drop-ins:

# /etc/sysctl.d/60-service.conf
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 4096
fs.file-max = 2097152
vm.max_map_count = 262144

Apply and verify:

sudo sysctl --system
sysctl net.core.somaxconn

If a value does not survive reboot or is overridden later by another file, you did not tune the system — you tuned one afternoon.

Networking: tune backlogs before algorithms

The most common useful network tuning is boring capacity plumbing:

  • net.core.somaxconn and net.ipv4.tcp_max_syn_backlog: completed and pending connection queues.
  • net.core.netdev_max_backlog and net.ipv4.tcp_congestion_control: ingress packet backlog and congestion algorithm such as cubic or bbr.

Congestion-control arguments are overrated unless you understand the path. BBR can help on lossy wide-area paths, but it is not a substitute for fixing retransmits, bufferbloat, or an undersized backlog. Measure handshake latency and accepted connections before and after.

Memory: avoid magical swappiness thinking

vm.swappiness influences the balance between reclaiming anonymous memory and dropping page cache. Lower values prefer dropping cache; higher values more readily swap cold anonymous pages. It is a bias knob, not an on/off switch.

sysctl vm.swappiness
cat /proc/pressure/memory

Changing swappiness without watching PSI is superstition. For latency-sensitive services, start with moderate values and test under realistic memory pressure. For hosts with no swap, swappiness is largely irrelevant; the kernel cannot swap what has nowhere to go.

File descriptors and process limits are performance features

A service that runs out of file descriptors does not degrade gracefully — it falls over. Systemd units often override shell limits, so check the actual process:

cat /proc/2417/limits | grep -i files
systemctl show myservice -p LimitNOFILE

Raise LimitNOFILE in the unit file when needed, then reload and restart deliberately. Do not set huge global values to compensate for a leaky service; descriptor growth should have an owner and a reason.

Field notes

  • Every sysctl change needs a reason, a measurement plan, and a rollback path. Kernel defaults are often better than internet folklore.
  • Beware settings copied from bare-metal databases onto containers or cloud VMs; topology and device behavior changed underneath.
  • Some sysctls are per-namespace in containers. Changing the host may not change the container's network stack the way you expect.
  • Keep tuning drops small and named by purpose. One giant 99-mystery.conf becomes untouchable within a year.

Was this lesson helpful?

Sign in to rate