Kiet Nguyen logo
NotesNotesResumeResume
© 2026 Kiet Nguyen
← All categories

11

Resources: Disk, Memory, CPU

  • Disk full triage
  • free: available vs free vs buff/cache
  • Load average vs nproc (cores)
dfdulsblkfindmntfreeswaponuptimenproclscpuvmstatiostatmpstatpidstatlsoffuser

Must-know cold

  • df -h · df -i · lsblk -f · du -xh --max-depth=1 /var | sort -rh
  • free -h → watch available, not only free · swapon --show
  • uptime / load · nproc · lscpu · vmstat -y 1 5
  • Full disk breaks “unrelated” services (logs, temp, deploys)

Toolchain map

Definition: Resource RCA is six jobs. df is mounted capacity; lsblk is block devices; du is a tree. Do not treat them as one command.

JobTools
1 Space & mountsdf, du, lsblk, findmnt
2 Memory & swapfree, swapon --show
3 CPU inventorylscpu, nproc, uptime
4 Live samplestop / htop, vmstat, mpstat, iostat
5 Per-processps, pidstat, pmap
6 Holders / pressurelsof, fuser, /proc/pressure/*

Quick interpret

Definition: How to read full disk, inode exhaustion, memory pressure, and high load.

SignalMeaning
df Use% → 100%Unprivileged writes fail (ext reserved blocks can bite before 100%; root may still write)
df -i 100%No inodes (many tiny files) even if space remains
free low availableMemory pressure risk (new work may swap/fail)
Load ≫ nprocOversubscribed (runnable or uninterruptible I/O) — not “CPU %”
High wa in top/vmstatI/O wait

Commands

df

Definition: Report free disk space and capacity per mounted filesystem.

OptionArgumentMeaningExample
(none)—Disk space per filesystemdf
-h—Human sizes (G/M)df -h
-T—Print filesystem typedf -hT
-i—Inode usage instead of block spacedf -i
-hPATHFS containing PATHdf -h /var
--outputFIELDSCustom columns (GNU)df -h --output=source,size,used,avail,pcent,target
-l—Local only (skip NFS)df -hl
-tTYPEOnly typedf -t ext4
-xTYPEExclude typedf -x tmpfs

Flag combos

ComboMeaningExample
df -hFirst look at block spaceAlways
df -iInode table (run separately; -i replaces size columns)Full mystery
df -h /var/lib/jenkinsFilesystem that contains that pathAgents

du

Definition: Estimate disk space used by files and directories.

OptionArgumentMeaningExample
(none)PATHDisk usage of treedu dir
-hPATHHuman sizesdu -h dir
-sPATHSummary total onlydu -sh dir
-aPATHAll files not just dirsdu -ah dir
-xPATHOne filesystem only (no other mounts)du -xh /
-d / --max-depthN PATHLimit depthdu -h --max-depth=1 /var
-cPATHGrand totaldu -ch *
--inodesPATHCount inodes (GNU)du --inodes -s *

Flag combos

ComboMeaningExample
du -xh --max-depth=1 /var | sort -rhBiggest dirs on same FSDisk full
du -sh * | sort -rhHere, largest first
du -sh /var/lib/dockerKnown fat pathAgents

lsblk

Definition: List block devices from sysfs/udev (lsblk(8)). Tree of disks → partitions → LVM/mapper. Default columns change; scripts should pass -o. RAM disks omitted unless -a.

OptionMeaningExample
(none)Tree of block deviceslsblk
-fFS columns (FSTYPE, LABEL, UUID, FSUSE%, MOUNTPOINTS)lsblk -f
-pFull /dev pathslsblk -p
-lList (no tree); each device once (util-linux ≥ 2.34)lsblk -l
-o LISTColumns (NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS)lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
-dDevice only, no holders/slaveslsblk -d /dev/sda
-tTopology (rotational, scheduler, sector size)lsblk -t

Authoritative FS probe is blkid. MOUNTPOINT is one path; MOUNTPOINTS lists all (bind mounts).

findmnt

Definition: Find a filesystem / list mounts (findmnt(8)). Default source is kernel /proc/self/mountinfo. --target PATH walks up to the mount of that path (like df PATH).

OptionMeaningExample
(none)All mounts, treefindmnt
-T / --targetFS containing PATHfindmnt -T /var/lib/jenkins
-t TYPEFilter typefindmnt -t ext4,xfs
-Ddf-like columns (excludes pseudo FS)findmnt -D
-s / --fstabSearch /etc/fstabfindmnt --fstab -t nfs
-n -o TARGET,SOURCEStable columns for scripts

Default output is not stable — use -o. Exit 1 if nothing matches.

free

Definition: Display RAM and swap usage (watch available, not only free).

OptionArgumentMeaningExample
(none)—Memory + swapfree
-h—Humanfree -h
-m—Mebibytesfree -m
-g—Gibibytesfree -g
-sNRefresh every N secondsfree -h -s 2
-cNWith -s: N times then exitfree -h -s 1 -c 5
-w—Wide (buffers/cache separate)free -wh
-t—Total linefree -ht

Columns: total · used · free · shared · buff/cache · available (what matters for new work)

Flag combos

ComboMeaningExample
free -hDefault interview command
free -h -s 2Watch pressure live

swapon

Definition: Show or enable swap (swapon(8)). --show is the table; -s / cat /proc/swaps is deprecated in favour of --show. swapoff can fail with OOM (exit 2 since util-linux 2.36).

OptionMeaningExample
--showSwap areas (size, used, prio)swapon --show
-aEnable all fstab swap (skip noauto)Boot scripts
-sOld summary ≡ /proc/swapsPrefer --show

Priority (pri=) 0–32767, higher first. Swap files with holes / CoW (plain Btrfs) are rejected; Btrfs needs nocow (kernel ≥ 5.0).

uptime

Definition: Show how long the system has been up and load averages.

OptionArgumentMeaningExample
(none)—Up time, users, load average 1/5/15 minuptime

Load ≈ tasks runnable (R) + uninterruptible (D), 1/5/15 min averages. Compare to nproc (available units, often SMT threads). Load 8 on 8 units ≈ busy; load 8 on 2 units ≈ overloaded. High load with low %us is often I/O (wa / D), not CPU.

Flag combos

ComboMeaningExample
watch -n 1 uptimeLive loadWhile stressing

nproc

Definition: Print processing units available to this process (affinity / cgroup / OMP_*), not “physical cores.” Counts SMT threads as units.

OptionArgumentMeaningExample
(none)—Units this process may usenproc
--all—Installed processors (ignores cgroup quota / OpenMP)nproc --all

Flag combos

ComboMeaningExample
echo "load $(uptime); cores $(nproc)"Context for loadSpoken RCA

lscpu

Definition: CPU architecture from sysfs + /proc/cpuinfo (lscpu(1)). Reports guest topology in a VM (often not the host). Cache sizes are a summary across CPUs (not per-core since util-linux 2.34). Default output changes — do not parse it.

OptionMeaningExample
(none)Human summary (sockets, cores, threads, NUMA, model)lscpu
-ePer-CPU tablelscpu -e
-pParseableScripts
-CCache detailslscpu -C
-yPhysical IDs from the kernel

Compare CPU(s) here with nproc (available to this process) and load from uptime.

vmstat

Definition: Report virtual memory, processes, and CPU/I/O samples over time. From procps; install if missing.

OptionArgumentMeaningExample
(none)—Since-boot averages for I/O/CPU (procs/memory are current)Ignore as “now”
(none)NThen a sample every N secondsvmstat 1
(none)N CEvery N sec, C reports (first is still since-boot)vmstat 1 5
-y—Omit the since-boot first line (procps)vmstat -y 1 5
-s—Event counters summaryvmstat -s
-d—Disk statsvmstat -d
-w—Wide columnsvmstat -w 1

CPU columns: us user · sy system · id idle · wa I/O wait · st steal (VM)

Flag combos

ComboMeaningExample
vmstat -y 1 1010 live samples (skip since-boot line)High load RCA

iostat

Definition: Show CPU and per-device disk I/O statistics. Optional: sysstat package.

OptionArgumentMeaningExample
(none)—CPU + device I/O (since boot if no interval/-y)iostat
-x—Extended device stats (await, %util, …)iostat -x
-y—Omit the since-boot first reportiostat -yxz 1 5
-h / -m—Human / MiB units (version-dependent)iostat -xm 1
(none)N CInterval + count (first report is since-boot unless -y)iostat -x 1 5
-pDEVDevice and its partitionsiostat -xp sda 1

Flag combos

ComboMeaningExample
iostat -yxz 1 5Extended, skip idle devices, skip since-bootDisk latency (%util≈100% saturates serial disks; not SSDs)

mpstat

Definition: Per-processor utilisation (mpstat(1), sysstat). No interval → since boot. Default report is CPU (-u). %iowait = idle with outstanding disk I/O; %idle = idle without. %sys does not include IRQ/softirq (%irq / %soft).

OptionMeaningExample
interval [count]Sample (first line is still since-boot unless you ignore it)mpstat 1 5
-P ALLEvery CPU + all averagempstat -P ALL 1 5
-uUtilisation (%usr %nice %sys %iowait %irq %soft %steal %idle)Default
-I SUMInterrupts/s per CPU
-A-n -u -I ALL (implies -P ALL -N ALL unless set)

Offline CPUs are omitted. Needs /proc.

pidstat

Definition: Per-task stats (pidstat(1), sysstat). No -p → active tasks only (non-zero stats), not every PID. No interval → since boot. Default metric is CPU (-u). Units labelled kB are KiB.

OptionMeaningExample
1 5Five CPU reports, 1 s apart, active taskspidstat 1 5
-p PID|ALLOne PID, or every task (including idle)pidstat -p 1643 1 5
-u%usr %system %guest %wait %CPUDefault
-rminflt/majflt, VSZ, RSS, %MEMpidstat -r 1 5
-dI/O kB_rd/s kB_wr/s (kernel ≥ 2.6.20)Disk hogs
-tThreads (TGID/TID)
-lCommand and args
-IDivide %CPU by CPU count (SMP)

pidstat is live rates over the interval — closer to top than ps %cpu.

lsof

Definition: List open files/sockets by process; find deleted-but-open space hogs.

OptionArgumentMeaningExample
(none)—List open files (huge)Avoid bare
-pPIDFiles for PIDlsof -p 1234
+L1—Open files with link count 0 (deleted but open)sudo lsof +L1
-i—Network filesSee networking sheet
-n—No DNS resolvelsof -n
-uUSERBy userlsof -u jenkins

Flag combos

ComboMeaningExample
sudo lsof +L1 | headSpace held after deletedf full, du small
sudo lsof /var | headWho uses /var

fuser

Definition: fuser names processes using a file or mount. Linux PSI (/proc/pressure/{cpu,memory,io}) is stall time, not utilisation.

CommandMeaningExample
sudo fuser -vm /varPIDs on that mount (-v verbose, -m name is a mount)Unmount busy
cat /proc/pressure/memorysome/full avg10= avg60= avg300=Memory stall
cat /proc/pressure/ioI/O stallHigh wa correlation
cat /proc/pressure/cpuRunnable but no CPULoad vs nproc

avg10 is a 10 s average of the fraction of time some (or all) tasks were stalled. Missing files → kernel built without PSI.

Common recipes

GoalCommand
Space overviewdf -h
Inodesdf -i
Largest under /varsudo du -xh --max-depth=1 /var | sort -rh | head
Memoryfree -h
Load vs coresuptime; nproc
CPU/I/O samplesvmstat -y 1 5
Deleted-open spacesudo lsof +L1
Block deviceslsblk -f
Mount of a pathfindmnt -T /var/lib/jenkins
Swapswapon --show
CPU topologylscpu
Per-CPU livempstat -P ALL 1 5
One PID I/Opidstat -d -p PID 1 5
PSIcat /proc/pressure/memory
OOM evidencejournalctl -k --since "today" | grep -iE 'oom|killed process'

Pitfalls

  • available is the estimate for new work (includes reclaimable cache, excludes some unevictable). Low free alone ≠ crisis. Modern used ≈ total − available.
  • df -i replaces the space columns; it is not “space plus inodes.” Run df -h and df -i.
  • ext-style reserved blocks (often ~5% for root) make unprivileged writes fail before Use% looks “full.”
  • du does not see space held by deleted-but-open files — use lsof +L1 and restart/truncate the holder.
  • du without -x walks other mounts (NFS, extra disks). Same-device bind mounts can still double-count even with -x.
  • du -sh * skips hidden (.*) names.
  • First line of vmstat / iostat is since boot unless you pass -y. Do not RCA from that line.
  • ps %CPU is lifetime CPU/elapsed, not the live burn top shows.
  • nproc is units this process may use (cgroup/affinity/OpenMP), not socket×core. --all ignores quota.
  • rm -rf large trees under load can make I/O worse — prefer targeted cleanup.
  • Load high + low CPU user% → check wa, NFS, D state, mpstat %iowait, /proc/pressure/io.
  • lsblk default columns change; so does lscpu / findmnt. Pin -o / do not parse the pretty summary.
  • mpstat / pidstat with no interval are since boot, same class of trap as vmstat / iostat.
  • pidstat without -p hides idle tasks. pidstat -p ALL is everyone.
  • nproc ≠ lscpu “CPU(s)” in a cgroup. lscpu in a VM is the guest.
  • swapon -s is deprecated; swapon --show. swapoff can OOM (exit 2).

For more details, try man <command> in your terminal.

Previous10 Cron & TimersNext12 Networking Basics