Resources: load average, free, vmstat, iostat
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- load average is the average number of running and waiting processes over the last 1, 5 and 15 minutes; compare it with the core count (
nproc). - In
free -hlook at the available column: even iffreeis small, Linux uses spare memory for cache. vmstat 1:r(CPU queue),si/so(swap) andwa(disk wait) reveal the bottleneck.iostat -xz 1:%utilandawaitshow disk load (packagesysstat).- The one-minute check:
uptime→free -h→vmstat 1 5→iostat -xz 1 3→df -h→top.
Four resources
Every performance problem runs into one of four resources. Each has its question:
| Resource | Question | Main tool |
|---|---|---|
| CPU | Is the processor at 100%, or is there a queue? | uptime, top, vmstat |
| Memory | Has RAM run out, is swap in use? | free, vmstat |
| Disk | Is the disk slow to respond? | iostat, vmstat wa |
| Network | Is bandwidth full, are there too many connections? | ss, ip -s link (unit 7) |
load average
ali@srv-web01:~$ uptime 11:24:05 up 2:29, 1 user, load average: 0.42, 0.35, 0.30 ali@srv-web01:~$ nproc 2
The three numbers are averages over the last 1, 5 and 15 minutes. Load is the number of processes running on the CPU and waiting for it (on Linux, processes waiting for disk in state D are included too).
Compare the number with the core count:
| Load on a 2-core server | Meaning |
|---|---|
| 0.4 | Relaxed, most of the CPU is idle |
| 2.0 | Fully loaded, no queue |
| 6.0 | 3 jobs per core — processes are waiting |
The direction of the three numbers also tells you something: 5.1, 2.0, 0.8 — load is rising now; 0.8, 2.0, 5.1 — it is falling, the problem has passed.
free: memory
ali@srv-web01:~$ free -h total used free shared buff/cache available Mem: 1.9Gi 842Mi 312Mi 12Mi 812Mi 956Mi Swap: 2.0Gi 0B 2.0Gi
The most common beginner mistake: free is 312 MB, "memory is running out!" In fact Linux uses spare RAM as disk cache (buff/cache) and gives it back immediately when a program needs it. The real indicator is the available column — 956 MB.
You should worry if:
availableis below 10% of total memory;Swap usedkeeps growing;- the log shows
Out of memory: Killed process— the kernel killed a process to free memory (the OOM killer):
ali@srv-web01:~$ sudo journalctl -k | grep -i "out of memory" Nov 28 03:12:40 srv-web01 kernel: Out of memory: Killed process 1340 (mysqld) total-vm:1789420kB, anon-rss:1203112kB
vmstat: everything on one line
ali@srv-web01:~$ vmstat 1 5 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 319812 61204 770388 0 0 12 40 210 380 3 1 96 0 0 0 0 0 0 319780 61204 770392 0 0 0 16 188 341 2 1 97 0 0 0 4 2 0 318944 61212 770410 0 0 9820 4210 902 1544 21 9 41 29 0 0 5 3 0 318120 61212 770455 0 0 11240 5016 988 1690 24 10 33 33 0 0 1 0 0 319410 61220 770460 0 0 40 52 230 402 4 1 95 0 0 0
1 — every second, 5 — five times. The first line is the average since boot, the rest are live.
| Column | Meaning | When it is bad |
|---|---|---|
r | Waiting in the CPU queue | Consistently above the core count |
b | Processes blocked waiting for disk | Consistently above 0 |
si, so | Reading from / writing to swap | Not 0 — RAM is short |
bi, bo | Blocks read from / written to disk | Depends on context |
us, sy | User and kernel CPU time | Together close to 90% |
wa | Waiting for disk | Above 20% — the disk is the bottleneck |
In this example, in seconds 3 and 4, wa is 29–33% and b is 2–3: something is writing heavily to disk (for example a backup). Next step — which disk?
iostat: disk
iostat is in the sysstat package (sudo apt install sysstat):
ali@srv-web01:~$ iostat -xz 1 2 | tail -n 4 Device r/s w/s rkB/s wkB/s r_await w_await aqu-sz %util sda 2.00 8.00 32.00 160.00 0.50 1.10 0.01 1.20 sdb 310.00 45.00 11240.00 1820.00 4.80 6.20 1.71 92.40 sdc 0.00 120.00 0.00 5016.00 0.00 2.30 0.28 18.00
| Column | Meaning |
|---|---|
r/s, w/s | Read/write operations per second (IOPS) |
rkB/s, wkB/s | Volume transferred per second |
r_await, w_await | Average wait per operation (ms) — a few ms is normal for SSD |
%util | How busy the disk is |
Conclusion: sdb (the site disk) is 92% busy, 11 MB/s are read from it — the site directory is being archived to /backup. The fix: move the backup to night hours and lower its priority with nice/ionice (ionice -c3 tar ...).
The one-minute check
When you log in to a server with a "it is slow" complaint, this sequence usually shows where the problem is within a minute:
| Step | Command | What you look at |
|---|---|---|
| 1 | uptime | Is load above the core count? Rising or falling? |
| 2 | free -h | Is available low? Is swap in use? |
| 3 | vmstat 1 5 | r, wa, si/so |
| 4 | iostat -xz 1 3 | Which disk has %util near 100%? |
| 5 | df -h | Is a disk full? (a full disk stops many services) |
| 6 | top (P, M) | Which process is the culprit? |
| 7 | journalctl -p err -S -1h | Errors in the last hour |
This does not show everything, but it narrows the search to one of the four resources.
History: sar
Once installed, sysstat collects statistics every 10 minutes. In the morning you can see what happened at 3 a.m.:
ali@srv-web01:~$ sar -u -s 02:50:00 -e 03:20:00 02:50:01 AM CPU %user %nice %system %iowait %steal %idle 03:00:01 AM all 61.20 0.00 8.41 22.13 0.00 8.26 03:10:01 AM all 58.77 0.00 7.90 25.02 0.00 8.31
sar -r gives memory history, sar -d disk, sar -n DEV network. For permanent monitoring (graphs, alerts), systems such as Zabbix or Prometheus + Grafana are used — we cover them in a separate course.
Look at the server's state with uptime, free -h and df -h in the Linux simulator.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1What does a load average of 8.0 mean on a 4-core server?
2Which column in free -h shows the memory that can really be used?
3If wa in vmstat is 35%, where is the bottleneck?
4What is happening if si and so in vmstat are consistently above 0?
5How do you look in the morning at CPU load that happened during the night?
Comments
Sign in to comment.