Skip to content
Linux system performance · Chapter 4 of 21 Day 2: The 60-second check

Day 2: The 60-second check

Goal: assess an unknown Linux server with ten commands in a fixed order, interpret every important column and find a built-in bottleneck · Duration: about 2.5 hours · Prerequisite: Days 0 and 1

Where we start

perf1 is reachable, /daten is mounted and empty, and no load from Day 1 is running any more.

# on perf1
ls /daten

Expected:

lost+found
# on perf1
pgrep -c stress-ng

-c counts the matches instead of listing them.

Expected:

0
# on perf1
cat /proc/pressure/cpu

Expected:

some avg10=0.00 avg60=0.02 avg300=0.34 total=339773693
full avg10=0.00 avg60=0.00 avg300=0.00 total=0

avg10=0.00 in both lines – nothing has waited for the CPU in the last ten seconds. The values over 60 and 300 seconds may still show remnants of earlier load.

If stress-ng is still running, end it with pkill stress-ng.

Introduction

You get a call: a server is slow, you do not know it, and someone is waiting on the phone. What do you do in the first minute?

The answer of this day: always the same thing. Ten commands, in a fixed order, each takes a few seconds. Together they roughly cover all resources – CPU, memory, disk, network – and for each one utilization, saturation and, where possible, errors. After a minute you do not know everything, but you know where to keep looking. And you have not missed anything just because it did not match your first suspicion.

This order is not an invention of this course. It goes back to a checklist published by Brendan Gregg and the performance team at Netflix and has been a classic ever since. Today you first get to know it on a healthy system – so that you know what “normal” looks like – then under load, and finally you use it to find a fault you do not know.

Today you learn:

  • the ten commands of the 60-second check and what each of them checks,
  • to read uptime, dmesg, vmstat, mpstat, pidstat, iostat, free, sar and top – column by column, as far as it matters for the overview,
  • why on multi-core systems you have to look per CPU,
  • what the state D of a process means and what %iowait really measures,
  • to follow a bottleneck from the symptom to the service causing it.

Background

The picture for today: the initial examination in the emergency room

A patient is brought in, nobody knows them. The emergency room does not work by gut feeling but by a fixed scheme that gives an overview in a minute:

  1. Temperature and general condition – is it getting better or worse? (uptime)
  2. A look at the file – was there an accident just now? (dmesg)
  3. The vital signs at a glance – pulse, blood pressure, breathing (vmstat)
  4. Organ by organ – listen to heart, lungs, abdomen separately (mpstat per CPU, iostat per disk, sar -n per network card)
  5. Who has complaints? – which process (pidstat)
  6. Finally the overall impression (top)

Whoever only looks at the overall impression first misses the broken leg – just like top, which mainly shows CPU.

The terms

Term Meaning In the picture
60-second check ten commands in a fixed order scheme of the initial examination
interval, count vmstat 1 5: every second, five times how often the pulse is measured
first output line average since system start values from last year – not from today
state D waits uninterruptibly, usually for the disk patient under anesthesia: reacts to nothing
%iowait idle CPU time while someone waits for I/O doctor waiting for the X-ray result

Remember: First the scheme, then the guess. The sum hides the single organ – which is why you look per CPU, per process, per disk.

The ten commands

No. Command What it shows USE
1 uptime load average – is the load rising or falling? saturation (rough)
2 dmesg -T \| tail latest kernel messages: OOM killer, disk errors, dropped packets errors
3 vmstat 1 run queue, blocked processes, memory, swap, I/O, CPU breakdown everything, roughly
4 mpstat -P ALL 1 CPU breakdown per CPU utilization, imbalance
5 pidstat 1 CPU per process, current instead of since start who?
6 iostat -sxz 1 throughput, waiting time, queue and utilization per disk utilization, saturation
7 free -m main memory and page cache utilization
8 sar -n DEV 1 throughput per network card utilization
9 sar -n TCP,ETCP 1 TCP connections, retransmits, resets errors
10 top overview as a check –

The order has a reason: the first two commands cost a second and can already name the problem (“Out of memory: Killed process …”). vmstat then gives an overall view, the next commands break it down by CPU, process, disk, memory and network. top comes last, not first – because whoever starts with top usually gets stuck there, and top mainly shows CPU.

Commands 3 to 9 take an interval as an argument (here 1 second) and keep running until you stop them with Ctrl+C. In the course you usually pass a count (vmstat 1 5) so that they stop by themselves. Almost all of them show averages since system start as their first output – you skip those when reading.

Where the commands come from

uptime, vmstat, free and top belong to the procps package and are present on every Linux. mpstat, pidstat, iostat and sar come from sysstat (Day 0). dmesg is in util-linux. All of them read their numbers from /proc and /sys – Day 3 explains exactly where from.

The D state and %iowait

You need two terms for the first time today.

Process states. Every process is in a state. The most important: R (running, runs or wants to run), S (sleeping, waits for an event and can be interrupted while doing so, for example waiting for a network reply or a key press) and D (uninterruptible sleep, waits and cannot be interrupted while doing so). In D a process almost always waits for the disk or for a lock in the kernel. During that time it does not even react to kill -9. Linux counts processes in D towards the load average – that is why the load can be high on a server with an idle CPU.

%iowait is a share of CPU time, but not a sign that the CPU is working. It is the time in which a CPU had nothing to do while at least one process was waiting for I/O. So the CPU was actually free. A high value says: “processes are waiting for disks here” – but a low value does not say the opposite, because as soon as the CPU has something else to do, the waiting disappears from this column. %iowait is good as a hint, not as a metric. For disk saturation, iostat and PSI are more reliable.

Drill 1: The check on a healthy system

Where you are: on perf1. Nothing is running except the operating system.

What you have afterwards: all ten commands run once and, for each, the picture of a healthy system in mind.

Go through the commands one after the other. Read the explanation for each one before you start the next.

Step 1 – uptime.

# on perf1
uptime

Expected:

 12:21:07 up 2 days,  2:55,  1 user,  load average: 0.03, 0.45, 0.40

Time of day, running time since start, logged-in users, load average over 1, 5 and 15 minutes. The numbers are the average number of processes that are running, want to run or are waiting in D. On four CPUs 0.03 is idle. That the 5-minute value is higher than the 1-minute value means: a few minutes ago there was more going on (for you: Day 1), now it is calming down.

Step 2 – dmesg.

# on perf1
sudo dmesg -T | tail -5

dmesg prints the kernel’s buffer with its messages. -T writes readable times instead of seconds since start. sudo is needed because Ubuntu does not allow normal users to read this buffer. tail -5 shows the last five messages.

Expected (your lines are different):

[Mon Nov 30 11:43:12 2026] sd 0:0:0:1: [sdb] Mode Sense: 63 00 10 08
[Mon Nov 30 11:43:12 2026] sd 0:0:0:1: [sdb] Write cache: enabled, read cache: enabled, supports DPO and FUA
[Mon Nov 30 11:43:12 2026] sd 0:0:0:1: Attached scsi generic sg2 type 0
[Mon Nov 30 11:43:12 2026] sd 0:0:0:1: [sdb] Attached SCSI disk
[Mon Nov 30 11:49:37 2026] EXT4-fs (sdb): mounted filesystem 789cfd03-3269-45a4-b985-0ad37922baee r/w with ordered data mode. Quota mode: none.

The latest events are attaching the extra disk and mounting it on Day 0 – nothing unusual. What you look for here: lines with Out of memory, I/O error, blocked for more than 120 seconds, nf_conntrack: table full or soft lockup. Each of them would already be half the diagnosis.

Step 3 – vmstat.

# on perf1
vmstat 1 3

Expected:

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 0  0      0 4887172 119380 6968836    0    0    31   123 1862    4  4  1 93  0  1  0
 0  0      0 4890636 119380 6968836    0    0     0     0  207   82  0  0 100  0  0  0
 0  0      0 4893988 119380 6968836    0    0     0     0  166   64  0  0 100  0  0  0

You skip the first line (since start). The columns from left to right:

  • r – threads that are running or waiting for a CPU. Permanently greater than the number of CPUs: CPU saturation.
  • b – processes that are blocked, almost always in state D. Permanently greater than 0: something is waiting for I/O.
  • swpd, free, buff, cache – memory in KiB: swapped out, completely free, for file system management, for the page cache. Day 6 explains the difference.
  • si, so – per second fetched in from swap (swap in) and written out (swap out). Any value above 0 means: memory is not enough.
  • bi, bo – blocks per second read from disks (blocks in) and written (blocks out), in KiB.
  • in, cs – interrupts and context switches per second.
  • us, sy, id, wa, st, gu – breakdown of CPU time in percent: program code (user), kernel (system), idle, idle with I/O waiting (wait, the %iowait from above), given to the hypervisor (steal) and for its own guests (guest, only if the VM itself runs VMs).

Healthy here means: r and b at 0, no swap, id at 100.

Step 4 – mpstat.

# on perf1
mpstat -P ALL 1 1

mpstat shows the same CPU breakdown as vmstat, but per CPU. -P ALL selects all CPUs and in addition the sum all. 1 1 means: an interval of one second, one output.

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:21:09     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
12:21:10     all    0.00    0.00    0.00    0.00    0.00    0.00    0.50    0.00    0.00   99.50
12:21:10       0    0.00    0.00    0.00    0.00    0.00    0.00    0.99    0.00    0.00   99.01
12:21:10       1    0.00    0.00    0.00    0.00    0.00    0.00    0.99    0.00    0.00   99.01
12:21:10       2    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
12:21:10       3    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    0.00    0.00    0.00    0.00    0.00    0.00    0.50    0.00    0.00   99.50
...

The header line names kernel, host name, date, architecture and number of CPUs – all sysstat tools start like this. New compared to vmstat are %nice (programs with lowered priority), %irq and %soft (time for hardware interrupts and for their deferred follow-up work, the softirqs – important for the network) and %gnice. With mpstat without a count there is no Average block; with a count their average follows after the measurements. Healthy: all CPUs almost equal and almost completely free.

Step 5 – pidstat.

# on perf1
pidstat 1 1

pidstat shows CPU usage per process in the chosen interval – so unlike ps (Day 1) the current consumption. Without further options only processes that used any CPU at all in the interval appear.

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:21:10      UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
12:21:11     1000    172617    0.96    0.96    0.00    0.00    1.92     2  pidstat

Average:      UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
Average:     1000    172617    0.96    0.96    0.00    0.00    1.92     -  pidstat

The only process computing is pidstat itself. The columns: user ID, process ID, shares in program code and in the kernel, %wait (time in which the process wanted to run but had to wait for a CPU – saturation per process), sum %CPU and the CPU it last ran on. Caution: %CPU refers to one CPU. A process with four fully working threads shows 400.

Step 6 – iostat.

# on perf1
iostat -sxz 1 2

iostat shows statistics per disk.

  • -x (extended) provides the extended columns: waiting time, queue, utilization.
  • -s (short) combines reading and writing so that the lines fit into a normal terminal. Without -s there is one column each for read, write, discard and flush – over 200 characters wide.
  • -z leaves out disks that did nothing in the interval.
  • 1 2 means: two outputs one second apart. The first again shows the average since start.

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.96    0.00    1.48    0.05    1.17   93.35

Device             tps      kB/s    rqm/s   await  areq-sz  aqu-sz  %util
loop0             0.00      0.00     0.00    0.18     1.27    0.00   0.00
sda               1.79    537.15     0.93    1.71   300.06    0.00   0.09
sdb               7.69    162.93     1.00    0.61    21.18    0.00   0.07
sr0               0.00      0.00     0.00    1.72     4.07    0.00   0.00


avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.25    0.00    0.00    0.00    0.00   99.75

Device             tps      kB/s    rqm/s   await  areq-sz  aqu-sz  %util

The second output – the current one – is empty: no disk did anything in this second, so -z hides all of them. That is the healthy picture. You can learn the columns from the first output:

  • tps – requests per second (transfers per second), that is, IOPS.
  • kB/s – throughput.
  • rqm/s – requests per second that the kernel merged with neighboring ones.
  • await – average time of a request in milliseconds, including the time in the queue. That is the latency a program feels.
  • areq-sz – average size of a request in KiB.
  • aqu-sz – average length of the queue: how many requests were in flight at the same time. That is the saturation.
  • %util – share of time in which at least one request was in flight. That is the utilization – with a trap that Day 9 explains: modern disks handle many requests in parallel, 100 % does not mean “full” there.

loop0 is a loop device that mounts snap packages, sr0 the virtual CD drive. You can ignore both.

Step 7 – free.

# on perf1
free -m

-m prints all values in MiB.

Expected:

               total        used        free      shared  buff/cache   available
Mem:           11961         577        4785           2        6922       11383
Swap:              0           0           0

The most important column is available: this much memory programs could get without anything having to be swapped out. It is much larger than free because the kernel can release the page cache (buff/cache) at any time. A server with little free and a lot of available is healthy – it uses spare memory sensibly as cache. Day 6 goes into detail.

Step 8 – sar -n DEV.

# on perf1
sar -n DEV 1 1

sar can not only show recorded data (Day 3) but also measure live. -n DEV selects the network statistics per device, 1 1 one interval, one output.

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:21:12        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
12:21:13           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:21:13         eth0     61.00     43.00      4.07      2.38      0.00      0.00      0.00      0.00
...

Per network card: packets received and sent per second (rxpck/s, txpck/s), the same in KiB (rxkB/s, txkB/s), compressed packets and multicast (rarely important) and %ifutil – the utilization relative to the speed of the card. lo is the loopback interface for connections within the machine. About 60 packets per second are your SSH session and the commands you are running right now.

Step 9 – sar -n TCP,ETCP.

# on perf1
sar -n TCP,ETCP 1 1

TCP provides counters for TCP connections, ETCP for TCP errors.

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:27:59     active/s passive/s    iseg/s    oseg/s
12:28:00         0.00      0.00      0.00      1.00

12:27:59     atmptf/s  estres/s retrans/s isegerr/s   orsts/s
12:28:00         0.00      0.00      0.00      0.00      0.00
  • active/s – connections per second that this machine opens (it is the client).
  • passive/s – connections per second that it accepts (it is the server).
  • iseg/s, oseg/s – TCP segments received and sent.
  • atmptf/s – failed connection attempts.
  • estres/s – connections that were aborted from the “established” state.
  • retrans/s – retransmitted segments: the most important error signal on the network.
  • isegerr/s – segments received with errors.
  • orsts/s – resets sent (segments with the RST flag) with which the machine refuses or aborts a connection.

Healthy: no retransmits, no resets, no errors.

From building this course: on the first run of this step, perf1 showed orsts/s = 39.6 while idle – forty refused connections per second on a server on which nothing is running. A capture with tcpdump showed the cause: another VM on the same network was trying non-stop to connect to port 6443 – a forgotten Kubernetes agent whose server was no longer running. This is exactly what the error line is for.

Step 10 – top.

# on perf1
top -b -n 1 | head -12

top normally runs interactively and refreshes every three seconds (quit with q). -b (batch) writes plain text instead, -n 1 exactly one output – so it can be shortened with head.

Expected:

top - 12:21:14 up 2 days,  2:55,  1 user,  load average: 0.03, 0.43, 0.40
Tasks: 130 total,   1 running, 129 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.5 us,  2.9 sy,  0.0 ni, 89.7 id,  5.9 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  11961.2 total,   4786.1 free,    577.5 used,   6922.4 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  11383.7 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 172624 ubuntu    20   0   12368   5536   3400 R   7.7   0.0   0:00.05 top
      1 root      20   0   22972  14424   9656 S   0.0   0.1   1:15.16 systemd
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.26 kthreadd

top combines much of what you have just seen: load average, number of processes by state, CPU breakdown, memory and a process list with state (S) and %CPU. One detail shows why top comes last: the CPU line reports 5.9 wa although nothing is waiting for the disk. With -n 1, top only has a very short measuring period (since it started itself), and the values in it fluctuate strongly. For measurements you use the sysstat tools with a fixed interval; top is the quick look as a check.

Remember: Memorize the picture of the healthy system: r small, b 0, %idle high, si/so 0, no retransmits. Only if you know the normal values do you see the deviation.

If it doesn’t work

  • dmesg: read kernel buffer failed: Operation not permitted: forgot sudo.
  • mpstat: command not found (or pidstat, iostat, sar): sysstat is missing – Day 0, Drill 3.
  • sar -n DEV shows times from this morning instead of now: you called sar without an interval; then it reads the day’s recording (Day 0, Drill 5) instead of measuring live. Call it with 1 1.

Save your progress? Sign up for free

Drill 2: A hot thread and network traffic

Where you are: in two terminals – one on perf1, one on last1.

What you have afterwards: seen why the view per CPU and per process is necessary, and how network load appears in sar and mpstat.

Step 1 – Create load. On perf1 you first start an iperf3 server in the background:

# on perf1
iperf3 -s -1 > /dev/null 2>&1 &
  • You know -s -1 from Day 0: server for exactly one measurement.
  • > /dev/null 2>&1 discards all output, & starts the command in the background so that you can keep typing in the same terminal.

Then a single computing worker, also in the background, for 60 seconds:

# on perf1
stress-ng --cpu 1 --timeout 60s > /dev/null 2>&1 &

On last1 you send data to perf1 for 30 seconds, limited to 2 Gbit/s:

# on last1
iperf3 -c perf1 -t 30 -b 2G > /dev/null

-b 2G limits the send rate (bitrate) to 2 Gbit/s so that the load is steady. Let the command run and switch to perf1 immediately.

Step 2 – Per CPU.

# on perf1
mpstat -P ALL 1 1 | head -9

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:23:10     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
12:23:11     all   22.47    0.00    5.62    0.00    0.00   10.11    1.57    0.00    0.00   60.22
12:23:11       0    0.00    0.00    0.00    0.00    0.00    0.97    1.94    0.00    0.00   97.09
12:23:11       1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
12:23:11       2    1.42    0.00   17.73    0.00    0.00   29.79    2.84    0.00    0.00   48.23
12:23:11       3   97.03    0.00    0.00    0.00    0.00    1.98    0.99    0.00    0.00    0.00

The sum line all says: 60 % free, everything relaxed. The individual lines say something else:

  • CPU 3 is 97 % busy with program code and has 0 % idle – that is the one computing worker. A program that has only one thread can never become faster than one CPU, no matter how many are free. In the sum over four CPUs it shrinks to 22 %.
  • CPU 2 works 30 % in %soft and 18 % in %sys – that is the network traffic. The kernel processes incoming packets in softirqs, usually on the CPU that receives the network card’s interrupt. If network traffic keeps rising, this one CPU becomes the bottleneck while the others are free. Day 12 shows how to spread the load.

Step 3 – Per process.

# on perf1
pidstat 1 1 | head -6

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:23:13      UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
12:23:14     1000    173043    0.96   17.31    0.00    0.00   18.27     2  iperf3
12:23:14     1000    173046   96.15    1.92    0.00    0.00   98.08     3  stress-ng-cpu
12:23:14     1000    173110    0.96    1.92    0.00    0.00    2.88     2  pidstat

Now you have the names for the CPUs: stress-ng-cpu on CPU 3 with almost 100 % in program code, iperf3 on CPU 2 with 17 % in the kernel – copying data from network buffers into its own memory is kernel work. The softirq time does not appear for any process, because it belongs to nobody: the kernel does it on behalf of the network card.

Step 4 – The network.

# on perf1
sar -n DEV 1 1 | head -5

head -5 shows only the first five lines – the measurement, without the average lines at the end.

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:23:11        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
12:23:12           lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
12:23:12         eth0   4891.00   2184.00 244411.13    140.77      0.00      0.00      0.00      0.00
# on perf1
sar -n TCP,ETCP 1 1 | head -7

Expected:

Linux 6.8.0-151-generic (perf1)     11/30/26    _x86_64_    (4 CPU)

12:23:12     active/s passive/s    iseg/s    oseg/s
12:23:13         0.00      0.00   4890.00   2077.00

12:23:12     atmptf/s  estres/s retrans/s isegerr/s   orsts/s
12:23:13         0.00      0.00      0.00      0.00      0.00

eth0 receives about 244,000 KiB/s – that is 2 Gbit/s, exactly the limit you set in iperf3. The packets are large: 244,411 KiB divided by 4,891 packets gives about 50 KiB per packet. That is more than the usual packet size of 1,500 bytes because the virtual network card merges several packets before the kernel sees them (receive offload). Almost only acknowledgments are sent (txkB/s = 141).

And %ifutil = 0.00 with 2 Gbit/s of traffic: that is not a measuring error but a limit of the tool. sar calculates utilization from the speed the network card reports – and virtual virtio network cards report none. On real hardware there would be a sensible value here. In VMs you have to compare the throughput with the expected bandwidth yourself.

Retransmits and resets are at 0: the network is busy but free of errors.

Remember: A single thread can never use more than one CPU, and network traffic often lands on a single CPU. Both disappear in the sum line all – look per CPU and per process.

If it doesn’t work

  • iperf3: error - unable to connect to server on last1: the server on perf1 is no longer running because -1 ended it after one measurement. Start it again.
  • No CPU with 0 % idle: stress-ng has already ended (60 seconds). Start Step 1 again.

Save your progress? Sign up for free

Diagnosis task

A colleague reports: “perf1 has been sluggish for a few minutes, every command takes ages. But the CPU is not full, top shows nothing special.” You do not know what they started.

Setup. Create the fault with this command. Try not to read it closely – it is explained in the solution:

# on perf1
sudo systemd-run --unit=nachtlauf fio --name=nachtlauf --directory=/daten --size=256M \
  --rw=randwrite --bs=4k --fsync=1 --numjobs=4 --runtime=300 --time_based

Expected:

Running as unit: nachtlauf.service; invocation ID: 60a5c221671d44dd964acd2c76436133

Wait 30 seconds.

Task (15 minutes): run the 60-second check in the order of this day. For each command, note what stands out. At the end you should be able to say: which resource, which process, which service – and how you fix the fault. The fault runs for five minutes; if you need longer, start it again after cleaning up (see solution).

Solution path

1. uptime – load average: 2.05, 0.84, 0.53: the load is clearly rising, to over 2 – although according to the colleague the CPU is “not full”. That fits processes in state D.

2. dmesg – no new messages since /daten was mounted. No hardware error, no OOM.

3. vmstat 1 4:

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 2  3      0 4638672 222888 7134220    0    0    31   126 1864    4  4  1 93  0  1  0
 3  0      0 4634136 224088 7138920    0    0     0 16080 10979 13210  1 15 36 37 12  0
 0  3      0 4626072 226024 7145164    0    0     0 21112 13410 17397  2 16 37 39  6  0
 0  3      0 4619520 227476 7150436    0    0     0 18840 12379 15610  1 17 37 39  6  0

Three leads: b = 3 (three processes blocked), bo ≈ 16,000–21,000 KiB/s (writing is going on, nothing is read) and wa ≈ 38 % with only 1–2 % us. The CPU waits for I/O a good third of the time. cs is also high with 13,000–17,000 context switches per second – processes keep giving up the CPU because they are waiting for something. The trail leads to the disk.

4. mpstat – all four CPUs evenly: about 35–44 % %iowait, 11–15 % %sys, hardly any %usr. No single hot thread; the waiting is spread out.

5. pidstat 1 1 (excerpt – the header line and the lines with jbd2 and fio):

23:01:24      UID       PID    %usr %system  %guest   %wait    %CPU   CPU  Command
23:01:25        0       529    0.00   14.71    0.00    0.00   14.71     2  jbd2/sdb-8
23:01:25        0     74052    0.00    0.98    0.00    0.00    0.98     3  fio
23:01:25        0     74055    1.96    9.80    0.00    1.96   11.76     3  fio
23:01:25        0     74056    0.98    9.80    0.00    0.98   10.78     3  fio
23:01:25        0     74057    1.96    8.82    0.00    1.96   10.78     0  fio
23:01:25        0     74058    1.96    9.80    0.00    0.98   11.76     3  fio

Four processes named fio with about 10 % CPU each, almost only in the kernel – none of them “full”, which is why nothing stood out in top (the fifth with 1 % is the parent process that started the four). In addition a kernel thread: jbd2/sdb-8 is the journal thread of the ext4 file system on sdb. It writes the journal whenever someone demands that data be stored permanently on the disk. That it needs 15 % CPU means: this happens very often.

6. iostat -sxz 1 2 (second output):

Device             tps      kB/s    rqm/s   await  areq-sz  aqu-sz  %util
sdb            2667.00  19124.00  2116.00    0.53     7.17    1.69  85.80

The extra disk receives 2,667 requests per second with only 7 KiB on average and is busy 86 % of the time. The single request is not slow at 0.53 ms – the problem is the sheer number of small writes. If you want to see the full columns, leave out -s; then f/s appears too, the number of flush requests per second:

Device w/s wkB/s w_await wareq-sz f/s f_await aqu-sz %util
sdb 2874.00 21848.00 0.51 7.60 720.00 0.37 1.74 85.50

(This output is shortened with awk to the write and flush columns.) 720 flushes per second: for each of them the disk has to confirm that everything written so far is stored permanently. That is the pattern of a program that calls fsync after every small write.

7. free – unremarkable, available unchanged and high. No memory problem.

8./9. sar -n – unremarkable. No network problem.

10. top – confirms the picture, with a new detail in the S column:

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
    529 root      20   0       0      0      0 D  16.7   0.0   0:29.50 jbd2/sd+
  72708 root      20   0       0      0      0 R   8.3   0.0   0:11.99 kworker+
  74052 root      20   0  302140  29808  24492 S   8.3   0.2   0:00.63 fio
  74055 root      20   0  236592   7004   1700 D   8.3   0.1   0:03.24 fio
  74057 root      20   0  236600   6972   1668 D   8.3   0.1   0:03.30 fio
  74058 root      20   0  236604   7004   1700 D   8.3   0.1   0:03.28 fio

The fio workers and the journal thread are in state D (the parent process is only waiting, S) – they are waiting for the disk. These are the processes that drive the load average.

From the resource to the service. Now you know: disk sdb, processes fio, very many small synchronous writes. The question from Day 1 remains: why is this running, who started it?

First the process ID of the oldest fio process – that is the one that started the four workers:

# on perf1
pgrep -o -x fio

Expected:

74052

Yours shows a different number. Put yours in below.

# on perf1
ps -o pid,cgroup:60,args -p 74052

Expected:

    PID CGROUP                                                       COMMAND
  74052 0::/system.slice/nachtlauf.service                           /usr/bin/fio --name=nachtlauf --directory=/daten --size=256M --rw=randwrite --bs=4k --fsync=1 --numjobs=4 --runtime=300 --time_based

The service is called nachtlauf.service (“night run”) and lives in system.slice – a system service. Now you can also read the command from the setup:

  • --rw=randwrite --bs=4k – random writes of 4 KiB each,
  • --fsync=1 – call fsync() after every single write, that is, demand that the data be on the disk permanently right away,
  • --numjobs=4 – four such processes at the same time,
  • --directory=/daten --size=256M – one file of 256 MiB each in /daten.

A program that writes like this is, for example, a badly configured database or an application that saves every log line individually. Day 8 looks at such patterns more closely.

PSI for I/O provides one more confirmation:

# on perf1
cat /proc/pressure/io

Expected:

some avg10=44.04 avg60=25.18 avg300=7.04 total=135654634
full avg10=40.28 avg60=23.24 avg300=6.51 total=112917522

In 44 % of the last 10 seconds at least one task was waiting for I/O, in 40 % even all runnable tasks at the same time (full). Unlike for the CPU, full has a meaning here: during these times the system did nothing useful because everything was waiting for the disk.

Fix and check. In real operations you would now clarify with the owner whether the service has to run like this. Here you stop it and clean up:

# on perf1
sudo systemctl stop nachtlauf

systemctl stop ends the service. fio is aborted, ends with an error code, and systemd remembers the service as failed.

# on perf1
sudo systemctl reset-failed nachtlauf

systemctl reset-failed forgets this state. Without this step the name stays taken, and another systemd-run --unit=nachtlauf fails.

# on perf1
sudo rm -f /daten/nachtlauf.*

rm -f /daten/nachtlauf.* deletes the four test files; * matches any extension.

And then the control measurement:

# on perf1
vmstat 1 3

Expected:

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 1  0      0 4457392 246144 7275744    0    0    31   129 1865    4  4  1 93  0  1  0
 0  0      0 4459556 246144 7275608    0    0     0     0  131   77  0  0 100  0  0  0
 0  0      0 4459752 246144 7275608    0    0     0     0  153   89  0  0 100  0  0  0

b = 0, bo = 0, wa = 0: the normal state is back. Only this measurement after the change proves that you found the cause.

Remember: High load with a free CPU means: processes in state D. The check leads you from the resource (disk) via the process (fio) to the service (nachtlauf.service) – and the measurement afterwards proves the cause.

If it doesn’t work

  • Failed to start transient service unit: Unit nachtlauf.service was already loaded or has a fragment file. when setting up again: the service is still known as failed. sudo systemctl reset-failed nachtlauf and try again.
  • iostat shows nothing for sdb: the fault is already over (five minutes). Set it up again.

Challenge

Extend your file ~/use-perf1.md from Day 1: for every cell of the USE table, enter which of the ten commands fills it, and which column. Which cells stay empty?

Solution path: CPU utilization: mpstat %idle per CPU; CPU saturation: vmstat r > number of CPUs, pidstat %wait. Memory utilization: free available; saturation: vmstat si/so. Disk utilization: iostat %util; saturation: aqu-sz, await. Network utilization: sar -n DEV rxkB/s/txkB/s against the bandwidth (in VMs without %ifutil); errors: sar -n ETCP retrans/s. Errors in general: dmesg. Empty remain memory errors, disk errors in production (except via dmesg), network card errors (packets dropped on the card: sar -n EDEV, Day 11) and all software resources such as locks. Day 3 fills some of them, Appendix A all of them.

Save your progress? Sign up for free

Checkpoint

# on perf1
systemctl is-active nachtlauf

Expected: inactive – the service is gone.

# on perf1
ls /daten

Expected: only lost+found.

# on perf1
vmstat 1 2

Expected:

procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st gu
 2  0      0 10831348 168340 1037340   73   73  2238  4630  952    1  2  1 95  1  0  0
 0  0      0 10831348 168340 1037308    0    0     0   668  241  119  0  0 99  0  0  0

In the last line b = 0 (second column) and wa = 0 – nobody is waiting for the disk. The first line is, as always, the average since start.

Test yourself

  1. Why do uptime and dmesg come first and top last?
  2. mpstat shows 60 % idle in the all line. Can a CPU still be the bottleneck?
  3. The load average is 4, the CPUs are 90 % free. What do you suspect, and how do you check it?
  4. Why is %iowait not a reliable metric for the disk?
  5. sar -n DEV shows %ifutil 0.00 with 2 Gbit/s of traffic. An error?

Answers:

  1. They cost a second and often already name the problem (trend, OOM, disk errors); top mainly shows CPU and tempts you to get stuck there.
  2. Yes – a single thread on one CPU with 0 % idle, or the network card’s softirqs on one CPU. Only visible with mpstat -P ALL.
  3. Processes in state D waiting for the disk. Check with vmstat (b), iostat -x and cat /proc/pressure/io.
  4. It is idle CPU time while someone waits for I/O; as soon as the CPU has something else to do, the waiting disappears from the column.
  5. No: virtual network cards report no speed, so sar cannot calculate utilization. Compare the throughput with the bandwidth yourself.

Interview Note

“You log in to a slow server. What do you type first?” – Whoever says top here is not wrong, but gives away points. Better: name the order and justify it. uptime and dmesg first, because they cost a second and often already contain the answer; then vmstat for the overview, then broken down by CPU, process, disk, memory, network. If you add that high load on Linux can also come from processes in state D and that %iowait is idle CPU time, you show depth. A sentence about %ifutil in VMs or about %util on SSDs proves that you know the tools not only from guides.

Enterprise Note

Put the 60-second check into the on-call handbook – with the order and the columns that matter. That gives new colleagues something to hold on to at night and makes sure everyone goes into the meeting with the same data. Many teams also run the commands as a diagnosis script that writes its output to a file; that makes sense as long as everyone knows what is in it. And: the check only works if sysstat is installed and you have sudo for dmesg. Both belong in the standard image (Day 0).

Summary

  • The 60-second check in a fixed order: uptime, dmesg -T | tail, vmstat 1, mpstat -P ALL 1, pidstat 1, iostat -sxz 1, free -m, sar -n DEV 1, sar -n TCP,ETCP 1, top.
  • The first output of vmstat, iostat and co. shows averages since start – skip it.
  • Look per CPU and per process: a hot thread or a CPU full of softirqs disappear in the sum.
  • State D = uninterruptible waiting, usually for I/O; counts towards the load average. %iowait is idle time with I/O waiting, a hint, not a metric.
  • iostat: await = latency, aqu-sz = saturation, %util = utilization (with a trap); f/s shows flushes.
  • %ifutil stays 0 with virtual network cards because they report no speed.
  • Diagnosis today: many small writes with fsync after each one – recognized by b, wa, jbd2, f/s, state D and PSI io; traced back via the cgroup to the service.

Commands at a glance

Command What it does Parameters
uptime load average 1/5/15 min –
sudo dmesg -T \| tail -5 latest kernel messages -T readable time
vmstat 1 3 run queue, blocked, memory, swap, I/O, CPU interval, count
mpstat -P ALL 1 1 CPU breakdown per CPU -P ALL all CPUs
pidstat 1 1 CPU per process in the interval interval, count
iostat -sxz 1 2 statistics per disk -x extended, -s short, -z only active
free -m memory in MiB -m MiB
sar -n DEV 1 1 throughput per network card -n DEV devices
sar -n TCP,ETCP 1 1 TCP connections and errors TCP, ETCP
top -b -n 1 overview as text -b batch, -n count
iperf3 -c perf1 -t 30 -b 2G network load with a limited rate -b bitrate
cat /proc/pressure/io I/O saturation as PSI –
systemctl stop NAME / reset-failed NAME stop a service / forget the failed state service name

Contents

More