$_ CLI In Depth
Learning progress 0%
lesson performance tmux vim git

CPU & Memory Pressure: top, free & vmstat

6 min read Module 18: Performance, Debugging & Power Tools Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:23

Load is a queue, not a percentage

The load average is the number of processes that are running or waiting for a CPU, averaged over one, five, and fifteen minutes. The kernel also counts processes that are in uninterruptible sleep, usually waiting for the disk. The number is not a percentage. A load of 4 on a four-core machine means the queue is about as long as the number of cores, and a load of 8 means that half of the work is waiting.

The current load is in the file /proc/loadavg, and the uptime command prints the same three numbers with the time since boot. Compare the load with the core count, which you can read from the nproc command. A load that stays above the core count for minutes is a sign of CPU pressure.

BASH1 lines
cat /proc/loadavg; nproc

Memory: free and available

free reports the memory of the whole machine. The -m option prints megabytes, which is easier to read than kibibytes. The most important column is available, not free. Linux uses spare memory as a cache for files, so free memory is normally small on a healthy machine. Available memory is the estimate of how much a new program could get without swapping, and it is the number that tells you whether memory is short.

BASH1 lines
free -m

The row labelled Mem shows the physical memory, and the Swap row shows the swap space on disk. Any use of swap is a sign that the machine once ran short, and heavy swap use while the machine is busy is a sign of real memory pressure.

vmstat: a sample over time

vmstat prints a line of statistics for each interval, which makes it the best tool for seeing change. Give it an interval and a count. The first line is an average since boot, and the following lines cover the interval. The columns are grouped under headings. Under procs, r is the number of runnable processes and b is the number blocked on I/O. Under memory, swpd is swap in use. Under swap, si and so are the amounts swapped in and out per second. Under io, bi and bo are blocks read and written. Under cpu, us, sy, id, wa, and st are the shares of user, system, idle, I/O wait, and stolen time.

BASH1 lines
vmstat 1 2

Read the line for the interval, not the average. Persistent r values above the core count point at CPU pressure. A persistent wa value shows the CPU waiting for storage, and nonzero si and so values show memory pressure that forces swapping.

top: the process table

top shows the same resources and then ranks the processes that use them. Interactive top refreshes the screen, which is awkward in a file. The -b option selects batch mode, which writes plain text, and -n 1 asks for a single frame. Batch mode is the form you want in scripts and in reports.

BASH1 lines
top -b -n 1 | head -n 12

The header lines repeat the load, the task counts, the CPU shares, and the memory totals. The table below it has one row for each process, with the PID, the user, the CPU and memory percentages, and the command. Sort order matters. The interactive keys choose the sort column, and in batch mode the process list is in the default order, so read the %CPU and %MEM columns for the largest values.

Pressure stall information

Newer kernels expose pressure stall information in /proc/pressure. Each file reports the share of time that tasks waited because of a resource, as averages over ten, sixty, and three hundred seconds. A value near zero means no waiting, and a high value means that tasks were stalled. The lab kernel may or may not provide these files, so check that they exist before you rely on them.

Tip

Read the resources in a fixed order each time: load first, then memory, then swap, then I/O wait. A habit of the same order makes it easy to see which number changed.

Reading the three together

A machine with a high load, a small available value, and steady swap activity is short of memory, and the processes that use the most memory are the first suspects. A machine with a high load, plenty of available memory, and low I/O wait is short of CPU. A machine with high wait and a long b column is waiting on storage. The three numbers select the next tool to use, which is the purpose of this lesson.

The lab machine has no man pages. Use the --help option of each command to check the flags, and read the proc filesystem lesson in the Linux module for the files that these commands read.

Caches make free look full

Linux keeps recently used file data in memory, and it gives that memory back as soon as a program asks for it. As a result, a healthy machine often shows little free memory and a large buff/cache column. The used column in free excludes the cache, and the available column adds back the part of the cache that can be dropped at once. Reading the free column alone is the most common way to mistake a busy but healthy machine for one that is out of memory.

Swap is not always a symptom

Some swap use is normal on a machine that has been busy for a long time, because the kernel moves rarely used pages out of memory to make room for the cache. The question is whether swap activity is happening now. A nonzero swpd with zero si and so is old, and it is harmless. Nonzero si and so values during a slow task mean that the machine is swapping under load, which is the pressure that makes everything feel slow.

Reading the processes that use memory

When top shows a process with a large %MEM value, check whether the value grows over time or stays flat. A flat value is a large but stable program, and it may be fine. A value that rises between two samples is the one to investigate, because a leak or a runaway cache looks like that. Two batch frames a few seconds apart are enough to see the trend, and the same method works with ps sorted by memory.

Real, user and sys: where the time went

Visualizer

time reports three clocks. Reading them tells you whether a command was waiting, computing, or making system calls.

1 / 3
The three numbers `time` prints
ClockCountsFor sleep 1
realwall clock time, start to finishabout 1 s
userCPU time spent in the program’s own codeabout 0 s
sysCPU time spent in the kernel for its system callsabout 0 s

time prints three numbers once the command ends. real is the wall clock. user and sys add up the CPU time the process actually used.

time sleep 1
Terminal lab · 3 steps · real Linux in your browser

Sample memory and CPU pressure

Save snapshots from free, vmstat, and top, then read the columns that show memory and CPU pressure.

01
Save a memory summary
free reports total, used, and free memory. The -m option shows megabytes. Save the output: ``bash free -m > memory.txt `` Open memory.txt. The Mem: row shows the total and available memory. The available column is the one to watch.
Show hint for step 1
The row labelled Mem: is the physical memory. Its columns are total, used, free, shared, buff/cache, and available.
02
Take two vmstat samples
vmstat prints one line per interval. The first line is an average since boot, so a second line shows recent activity. Take two samples one second apart: ``bash vmstat 1 2 > vmstat.txt `` Open vmstat.txt. The column headers include r, b, swpd, and free, and the cpu columns us, sy, id, and wa.
Show hint for step 2
The first sample is an average since boot. The second line describes the last second, which is closer to what is happening now.
03
Take one top snapshot
top normally refreshes the screen, which is awkward in a file. The -b option makes it batch mode and -n 1 asks for one frame. Save the frame: ``bash top -b -n 1 > top.txt `` Open top.txt. The header lines show the load and the memory totals, followed by a table whose first column is PID.
Show hint for step 3
Batch mode writes plain text, so the frame can go to a file. The table header starts with PID.
Check yourself Question 1 of 4
Concept Check What available memory means recall

What does the available column in free -m estimate?

Recap & Key Takeaways

The load average counts runnable and waiting processes, so compare it with the number of cores from nproc.
free -m reports memory in megabytes, and the available column is the one that shows how much room a new program has.
vmstat with an interval shows what changes over time, with r and b for queues and si and so for swapping.
top -b -n 1 writes one frame of the process table to a file, which makes it usable in reports and scripts.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue