inaabi / Guides / linux performance tuning commands

linux performance tuning commands

Five reads for CPU, memory, disk, and network, plus the one-core loop and the localhost transfer used to load this test.

Tested on Ubuntu 22.04.5 LTS amd64 and Debian 12 amd64, 2026-12-04.

These five commands are the set to run before changing anything. Four of them only read. The fifth number on the CPU line comes from a one-core loop that was started for the test and then allowed to exit. The network number comes from a one-megabyte transfer to 127.0.0.1 that was also allowed to finish.

The Ubuntu 22.04.5 container script that printed the mpstat, free, and vmstat lines exited 0. CPU, memory, and the vmstat sample were taken in that container. The disk-sector delta, the loopback transfer, and ionice were taken on Debian 12. Both used kernel 6.8.12-43-pve. This is not a course and it does not set sysctls. The sysctl command page belongs to the wiki. High load average as a symptom belongs to the troubleshooting guides.

Read the CPU

nproc
mpstat -P ALL 1 1
ps -eo pid,user,%cpu,stat,etime,comm --sort=-%cpu | head

mpstat is in the sysstat package. The two numbers are the interval and the count, in seconds. %usr is application code, %sys is the kernel, %iowait is time the CPU was idle while a disk request was outstanding, %steal is time the hypervisor gave away, %idle is unused.

On the Ubuntu 22.04.5 container, nproc printed 48. One second of mpstat for every CPU together:

Average:     all   14.07    0.28    6.75   22.70    0.00    0.05    0.00    0.69    0.00   55.46

The column order is %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle. Idle was 55.46%. Iowait was 22.70%. Steal was 0.00%. The machine was not short of CPUs in that second.

A bash loop started under nice -n 19 for five seconds showed up in ps like this:

   1135 root     91.5 RN         00:02 bash

R means runnable. N means low priority. ps %CPU is CPU time divided by how long the process has been alive, so use it to pick a pid, then watch that pid for a second if you need the current rate. pidstat aimed at the timeout wrapper around that loop printed 0.00, because the wrapper was waiting and the child was the loop. Point the tool at the pid ps ranked first.

mpstat is documented in mpstat(1).

Read memory

free -h

On procps 3.3.17 in that Ubuntu container:

               total        used        free      shared  buff/cache   available
Mem:           125Gi       110Gi       6.7Gi       2.0Gi       8.7Gi        12Gi
Swap:             0B          0B          0B

available is the kernel's estimate of RAM it can give a new allocation. It comes from MemAvailable in /proc/meminfo. The free column is RAM with nothing stored in it. The container was limited to 768 MiB (memory.max was 805306368) and free still printed the host. Inside a container, also read /sys/fs/cgroup/memory.max.

Read disk wait

vmstat 1 3

Skip the first line. It is the average since boot. The next lines are one-second samples. wa is iowait percent. b is tasks stuck in uninterruptible sleep, which on a server is almost always disk.

 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
14 16      0 6890656      0 9096388    0    0  3720  7548 71705 139708 28  9 43 20  0
11 15      0 7115912      0 9097256    0    0  2756 25624 59373 146178 19  7 53 21  0

wa was 20 and then 21, with id at 43 and 53. That is the same wait the CPU sample reported as %iowait 22.70. The page for that case is high iowait. vmstat is documented in vmstat(1).

Read the network

On Debian 12, a process sent 1048576 bytes to 127.0.0.1. The server read 1048576 bytes. The loopback receive counter in /proc/net/dev rose by 1050568. The extra 2016 bytes are the headers on that transfer.

awk '$1 ~ /^lo:/ {print $2}' /proc/net/dev

Run it, do the transfer or the real traffic you care about, and run it again. Subtract. The first field after the interface name is received bytes. This test did not send anything off the machine.

Stop what the test started

The bash loop was under timeout 5 and exited. The localhost sockets closed when the send finished. ps was not left running a loop. No sysctl was written.

Questions

Do these commands replace a monitoring stack?

No. They are the one-minute check. A monitoring stack is a different guide.

Why was idle high while the host felt busy?

Because 22.70% of the second was iowait. The CPUs were waiting on disk. Follow high iowait.

Where is the sysctl list?

This page does not set sysctls. The command reference for sysctl is a wiki page.