Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

vmstat

Report virtual memory statistics.

Description

Reports information about processes, memory, paging, block I/O, traps, disks, and CPU activity. The first report gives averages since the last reboot. Subsequent reports cover the sampling interval.

Inputs

  • /proc/stat – CPU times (user, nice, system, idle, iowait, irq, softirq, steal, guest), context switches, boot time, process forks, procs running, procs blocked, and total interrupt count from the “intr” line
  • /proc/meminfo – memory statistics (MemTotal, MemFree, Buffers, Cached, SwapTotal, SwapFree, Active, Inactive, SReclaimable)
  • /proc/vmstat – virtual memory counters (pswpin, pswpout, pgpgin, pgpgout)
  • /proc/uptime – system uptime in seconds (for per-second rate calculations on the first report)
  • /proc/diskstats – per-disk I/O statistics (for -d and -D modes)
  • /proc/slabinfo – slab allocator information (for -m mode)

Note: the total interrupt count is read directly from the “intr” line in /proc/stat because the procfs crate does not expose this field.

Arguments

Positional

ArgumentDescription
delaySeconds between updates (enables repeating mode)
countNumber of updates to print (default: infinite when delay is set)

Mode selection

These flags are mutually exclusive. If none is specified, the default VM statistics mode is used.

FlagDescription
-f, --forksDisplay the total number of forks since boot and exit
-m, --slabsDisplay slabinfo
-s, --statsDisplay a table of event counters and memory statistics
-d, --diskDisplay per-disk I/O statistics
-D, --disk-sumDisplay summary of disk I/O statistics across all disks

Display options

FlagDescription
-a, --activeShow active/inactive memory columns instead of buff/cache
-n, --one-headerPrint the column header only once, not periodically
-S, --unit CHARDisplay unit: k (1000), K (1024, default), m (1000000), M (1048576)
-t, --timestampAppend a timestamp column to each output line
-w, --wideWide output mode (wider columns to avoid truncation)
-y, --no-firstOmit the first report (which shows averages since boot)

Behavior

Default VM mode

Produces a table with the following column groups:

procs -----------memory---------- ---swap-- -----io---- -system-- --------cpu--------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs  us  sy  id  wa  st  gu

Columns:

  • procs: r (runnable processes), b (blocked processes)
  • memory: swpd (used swap), free (free memory), buff (buffer memory), cache (cache memory). With -a, buff and cache are replaced by inact (inactive memory) and active (active memory).
  • swap: si (swap in from disk per second), so (swap out to disk per second)
  • io: bi (blocks received from block devices per second), bo (blocks sent to block devices per second)
  • system: in (interrupts per second), cs (context switches per second)
  • cpu: us (user), sy (system), id (idle), wa (iowait), st (steal), gu (guest) – all as percentages of total CPU time

The first report shows averages since boot, calculated using system uptime as the elapsed interval. Subsequent reports show deltas over the sampling interval. With -y, the first report is omitted.

Stats mode (-s)

Displays a vertical list of memory statistics (in the selected unit), followed by CPU tick counts, paging and swap counts, interrupt and context switch totals, boot time, and fork count.

Disk mode (-d)

Displays a per-disk table:

DISK   TOTAL MERGED  SECTORS    MS  TOTAL MERGED  SECTORS     MS CUR SEC
vda   310603  34230 25314959 94573 392788 161615 28903938 850299   0  50

The first four data columns are reads (total, merged, sectors, ms); the next four are writes; the final two are current in-flight I/O and seconds spent on I/O.

Disk summary mode (-D)

Displays aggregate totals across all disks: total disks, partitions, total reads/writes, merged reads/writes, read/written sectors, and milliseconds spent reading/writing.

Forks mode (-f)

Prints a single line with the total number of forks (from the “processes” field in /proc/stat) since boot:

     12345678 forks

Slabs mode (-m)

Displays the raw contents of /proc/slabinfo.

Exit codes

CodeMeaning
0Success
1Failure (cannot read proc files or invalid arguments)

Divergences from procps-ng

  • Column headers are UPPERCASE (R, B, SWPD, FREE, SI, IN, …) rather than lowercase, matching the convention used by lsblk, lscpu, and other modern util-linux tools.
  • The section-grouping header line above the column names (procs / memory / swap / io / system / cpu for the default layout, disk / reads / writes / IO for -d) is not emitted. Column widths are sized to fit each report’s data, which would visually misalign with a fixed-width label row.