ZetCode

Linux free, uptime, and vmstat Commands

last modified October 24, 2026

Three small commands give a quick picture of a system's health. free shows how memory is used, uptime shows how long the system has been running and how busy it is, and vmstat reports processes, memory, swapping, disk I/O, and CPU activity over time. All three read their data from the /proc file system and are part of the procps package.

The examples were run with procps-ng 4.0.2 on Debian 12, in a container on a machine with 8 CPUs and 16 GB of memory. Memory and load are properties of the kernel, so the container sees the values of the whole machine, including the work of other programs that were running on it.

Memory usage with free

Without options, free prints the amounts in kibibytes.

free

total is the installed memory minus what the kernel reserves for itself. used is the memory used by processes and the kernel. free is memory that is not used for anything. shared is mostly tmpfs and shared memory. buff/cache is memory used for the page cache (file contents) and kernel buffers. available estimates how much memory new programs can get without swapping; it includes free memory and the part of the cache that can be dropped. The Swap line shows the swap space.

$ free
               total        used        free      shared  buff/cache   available
Mem:        16165976     8545848     2182976      419488     6201588     7620128
Swap:        2097148        8192     2088956

Choosing the units

Several options change the units of the output.

free -h
free -m
free -h --si
free -wh
free -th

-h picks a readable unit for each value; Gi and Mi are powers of 1024. -m prints mebibytes, which suits scripts and comparisons. With --si, units are powers of 1000, so the 15 GiB of memory become 16 GB. -w (wide) splits buff/cache into its two parts, and -t adds a line with the totals of memory and swap.

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       8.1Gi       2.1Gi       409Mi       5.9Gi       7.3Gi
Swap:          2.0Gi       8.0Mi       2.0Gi
$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15787        8346        2131         409        6056        7440
Swap:           2047           8        2039
$ free -h --si
               total        used        free      shared  buff/cache   available
Mem:             16G        8.8G        2.2G        429M        6.4G        7.8G
Swap:           2.1G        8.4M        2.1G
$ free -wh
               total        used        free      shared     buffers       cache   available
Mem:            15Gi       8.2Gi       2.1Gi       409Mi       568Mi       5.4Gi       7.3Gi
Swap:          2.0Gi       8.0Mi       2.0Gi
$ free -th
               total        used        free      shared  buff/cache   available
Mem:            15Gi       8.2Gi       2.1Gi       409Mi       5.9Gi       7.3Gi
Swap:          2.0Gi       8.0Mi       2.0Gi
Total:          17Gi       8.2Gi       4.1Gi

Free is not the same as available

Linux uses memory that programs do not need to cache file contents. A small value in the free column is therefore normal, and the available column is the one to watch.

free -m
head -c 1G /dev/urandom > big.bin
free -m
rm big.bin
free -m

Writing a 1 GiB file filled the page cache: free dropped from 675 to 317 MiB, while available did not drop at all, because the cached data can be thrown away when programs need the memory. The kernel also evicted older cached data to make room, so buff/cache grew by less than 1 GiB. Deleting the file released its cached pages and free rose by about 1000 MiB.

$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15787        8347        2130         409        6056        7439
Swap:           2047           8        2039
$ head -c 1G /dev/urandom > big.bin
$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15787        8131        1315         428        7104        7655
Swap:           2047           8        2039
$ rm big.bin
$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15787        8112        2364         420        6067        7674
Swap:           2047           8        2039

Memory used by a program

Memory that a program allocates and uses cannot be reclaimed like the cache; it reduces the available memory.

free -m
python3 -c 'import time; b = bytearray(2 * 1024**3); time.sleep(5)' &
sleep 2; free -m
wait; free -m

The Python program creates a 2 GiB array filled with zeros and keeps it for five seconds. While it runs, used grows by about 2036 MiB and available drops by the same amount. To find room, the kernel shrank the cache. When the program exits, its memory is free again.

$ free -m
               total        used        free      shared  buff/cache   available
Mem:           15787        8106        2370         420        6067        7680
Swap:           2047           8        2039
$ python3 -c 'import time; b = bytearray(2 * 1024**3); time.sleep(5)' &
$ sleep 2; free -m
               total        used        free      shared  buff/cache   available
Mem:           15787       10220         257         444        6090        5566
Swap:           2047           8        2039
$ wait; free -m
               total        used        free      shared  buff/cache   available
Mem:           15787        8173        2398         460        6017        7614
Swap:           2047           8        2039

The /proc/meminfo file

free takes its values from /proc/meminfo, which has many more fields.

grep -E '^(MemTotal|MemFree|MemAvailable|Buffers|Cached|Shmem|SwapTotal|SwapFree):' /proc/meminfo

MemAvailable is the kernel's own estimate behind the available column. Scripts can read this file directly; it is cheaper than running free and the format is stable.

$ grep -E '^(MemTotal|MemFree|MemAvailable|Buffers|Cached|Shmem|SwapTotal|SwapFree):' /proc/meminfo
MemTotal:       16165976 kB
MemFree:         2455916 kB
MemAvailable:    7796744 kB
Buffers:          582264 kB
Cached:          4375604 kB
SwapTotal:       2097148 kB
SwapFree:        2088956 kB
Shmem:            471712 kB

Repeating the output

The -s option repeats the output at an interval in seconds, and -c limits the number of repetitions.

free -m -s 2 -c 3

Without -c, free -s runs until it is stopped with Ctrl+C. vmstat, described below, is better suited to watching changes over time.

$ free -m -s 2 -c 3
               total        used        free      shared  buff/cache   available
Mem:           15787        8173        2398         460        6017        7614
Swap:           2047           8        2039

               total        used        free      shared  buff/cache   available
Mem:           15787        8169        2402         454        6010        7617
Swap:           2047           8        2039

               total        used        free      shared  buff/cache   available
Mem:           15787        8125        2446         438        5995        7661
Swap:           2047           8        2039

free inside a container

A container with a memory limit still sees the memory of the whole machine. The following commands were typed in a container started with docker run -m 512m --memory-swap 512m.

free -h
cat /sys/fs/cgroup/memory.max
python3 -c 'b = bytearray(1024**3); print("allocated")'; echo $?

free reports 15 GiB, but the cgroup limit in memory.max is 536870912 bytes, 512 MiB. A program that tries to use 1 GiB is killed by the kernel's out-of-memory killer, and the shell reports the exit status 137, which is 128 plus 9 (SIGKILL). Inside containers, check the cgroup files rather than free.

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       8.0Gi       2.3Gi       375Mi       5.8Gi       7.4Gi
Swap:          2.0Gi       8.0Mi       2.0Gi
$ cat /sys/fs/cgroup/memory.max
536870912
$ python3 -c 'b = bytearray(1024**3); print("allocated")'; echo $?
Killed
137

System uptime

The uptime command prints the current time, how long the system has been running, the number of logged-in users, and the load averages.

uptime
uptime -p
uptime -s
cat /proc/loadavg
nproc

-p prints the uptime in a readable form and -s the time the system was booted. No users are logged in to the container. The three load averages cover the last 1, 5, and 15 minutes. /proc/loadavg holds the same values, followed by the number of currently runnable and of all tasks, and the most recently assigned PID. nproc prints the number of CPUs, which is needed to interpret the load.

$ uptime
 21:19:45 up  1:29,  0 user,  load average: 3.25, 2.70, 1.74
$ uptime -p
up 1 hour, 29 minutes
$ uptime -s
2026-10-24 19:50:02
$ cat /proc/loadavg
3.25 2.70 1.74 2/1553 62
$ nproc
8

Understanding the load average

The load is the number of processes that are running or waiting for a CPU, averaged over time. On Linux, it also counts processes waiting for disk I/O in the uninterruptible state D. We start eight CPU-bound processes, one per CPU, and check the load after a minute.

uptime
for i in $(seq 8); do timeout 90 awk 'BEGIN { while (1) {} }' & done
sleep 60; uptime

Each awk runs an empty endless loop, and timeout stops it after 90 seconds. The 1-minute average rose from 3.25 to 6.44, not to 8 plus the background load: the averages are exponentially damped, so after one minute the 1-minute value has covered about 63% of the change, and the 5- and 15-minute values react more slowly. A load equal to the number of CPUs means the CPUs are fully used; a higher load means that processes wait. A load of 6 is a lot for a machine with 2 CPUs, but leaves room on this one.

$ uptime
 21:19:45 up  1:29,  0 user,  load average: 3.25, 2.70, 1.74
$ for i in $(seq 8); do timeout 90 awk 'BEGIN { while (1) {} }' & done
$ sleep 60; uptime
 21:20:45 up  1:30,  0 user,  load average: 6.44, 3.73, 2.16

System activity with vmstat

Without arguments, vmstat prints one line of averages since boot.

vmstat

The columns are grouped. procs: r runnable processes (running or waiting for a CPU), b processes in uninterruptible sleep, usually waiting for I/O. memory in KiB: swpd used swap, free, buff, and cache. swap: si and so, memory swapped in from and out to disk per second. io: bi and bo, blocks read from and written to block devices per second (in KiB). system: in interrupts and cs context switches per second. cpu: percentages of CPU time in user code (us), the kernel (sy), idle (id), waiting for I/O (wa), and stolen by the hypervisor (st).

$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0   8192 2574700 582512 5496420    0    0   153   197  578 1054 10  2 87  0  0

Sampling at an interval

With a delay and a count, vmstat prints a new line at each interval.

vmstat 2 4

The first line still shows averages since boot; ignore it. The following lines describe each 2-second interval. The machine is mostly idle, with 6–8% user time from other programs. r is a snapshot taken at the moment of the sample, so it fluctuates: a value of 9 with 92% idle CPUs is a short burst of activity, not a problem. Without a count, vmstat 2 runs until stopped.

$ vmstat 2 4
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0   8192 2574700 582512 5496420    0    0   153   197  578 1054 10  2 87  0  0
 9  0   8192 2574700 582512 5496420    0    0     0     2 4603 10108  6  2 92  0  0
 2  0   8192 2574700 582512 5496420    0    0     0    22 4849 8996  8  2 90  0  0
 1  0   8192 2574700 582512 5496420    0    0     0     0 4108 9284  6  2 92  0  0

A CPU-bound workload

We start twelve busy processes on the eight CPUs and watch them with vmstat.

for i in $(seq 12); do timeout 8 awk 'BEGIN { while (1) {} }' & done
vmstat 2 3

us is at 99% and id at 0: the CPUs are saturated with user code. r is higher than the number of CPUs, so processes wait for their turn. When sy is high instead of us, the time goes to system calls; a program like yes > /dev/null, which calls write continuously, shows mostly system time.

$ for i in $(seq 12); do timeout 8 awk 'BEGIN { while (1) {} }' & done
$ vmstat 2 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
14  0   8192 2551604 582520 5507720    0    0   153   196  578 1054 10  2 87  0  0
17  0   8192 2551604 582520 5507720    0    0    58    80 10380 9959 99  1  0  0  0
21  0   8192 2551604 582520 5507720    0    0     0     0 9985 9854 99  1  0  0  0

An I/O-bound workload

Next, we write 3000 MiB to a file with dd, bypassing the page cache with oflag=direct.

dd if=/dev/zero of=io.bin bs=1M count=3000 oflag=direct status=none &
vmstat 1 4
wait; rm io.bin

The bo column shows about 2.3 million KiB written per second to the NVMe disk, and wa rises to 7%, the share of time the CPUs were idle while a process waited for I/O. b was 1 in the first sample: dd was blocked on the disk. High wa and b values point to a disk bottleneck. On a server that swaps heavily, non-zero si and so values would appear as well, which is a sign of too little memory.

$ dd if=/dev/zero of=io.bin bs=1M count=3000 oflag=direct status=none &
$ 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
 2  1   8192 2562556 582644 5492352    0    0   153   196  578 1054 10  2 87  0  0
 1  1   8192 2562556 582644 5492352    0    0     0 1460332 16761 13029  4  4 80 12  0
 4  0   8192 2562556 582644 5492352    0    0     4 1611776 17933 13080  4  5 88  3  0
 1  0   8192 2562556 582644 5492352    0    0     0     0 6872 11892 15  3 82  0  0
$ wait; rm io.bin

Wide output and units

Large memory values break the column alignment. The -w option widens the columns, and -S M switches to mebibytes.

vmstat -w -S M 1 2
vmstat -a -S M

The wide format of procps 4 also adds the gu column, time spent running virtual machine guests. With -a, vmstat shows active and inactive memory instead of buffers and cache; inactive memory has not been used recently and is reclaimed first.

$ vmstat -w -S M 1 2
--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            8         2306          569         5374    0    0   153   267  579 1055  10   2  87   0   0   0
   1    0            8         2306          569         5374    0    0     0   852 4708 9849   6   2  92   0   0   0
$ vmstat -a -S M
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 3  0      8   2304   4983   6460    0    0   153   267  579 1055 10  2 87  0  0

Summary statistics

The -s option prints a table of counters, and -D a summary of disk activity.

vmstat -s -S M | head -n 10
vmstat -D

The memory part of vmstat -s repeats what free shows (the line labelled swap cache is the page cache). The full output continues with CPU tick counters, page and swap counters, interrupts, context switches, and the boot time. The disk counters include loop devices; per-device values are printed by vmstat -d.

$ vmstat -s -S M | head -n 10
        15787 M total memory
         8263 M used memory
         6460 M active memory
         4983 M inactive memory
         2306 M free memory
          569 M buffer memory
         5374 M swap cache
         2047 M total swap
            8 M used swap
         2039 M free swap
$ vmstat -D
           29 disks
            2 partitions
       603333 total reads
       192804 merged reads
     13191900 read sectors
        93244 milli reading
       184787 writes
       307662 merged writes
     23074472 written sectors
       290521 milli writing
            0 inprogress IO
           58 milli spent IO
          399 milli weighted IO

A simple health check script

The following script reads /proc/meminfo and /proc/loadavg and prints warnings when memory is low or the load is too high.

health.sh
#!/bin/bash

# warns when available memory is low or the load exceeds the CPU count
min_avail_mb=${MIN_AVAIL_MB:-1024}

avail_kb=$(awk '/^MemAvailable:/ { print $2 }' /proc/meminfo)
avail_mb=$(( avail_kb / 1024 ))
read -r load1 load5 load15 rest < /proc/loadavg
cpus=$(nproc)

echo "available memory: $avail_mb MiB"
echo "load average:     $load1 $load5 $load15 ($cpus CPUs)"

if [ "$avail_mb" -lt "$min_avail_mb" ]; then
    echo "WARNING: less than $min_avail_mb MiB of memory available"
fi

# the load is a decimal number; compare with awk
if awk -v l="$load5" -v c="$cpus" 'BEGIN { exit !(l > c) }'; then
    echo "WARNING: 5-minute load is above the number of CPUs"
fi

The threshold for memory can be overridden with the MIN_AVAIL_MB variable; the second run uses an unrealistic value to trigger the warning. Bash arithmetic works only with integers, so the decimal load average is compared with awk, whose exit status drives the if.

$ bash health.sh
available memory: 7522 MiB
load average:     4.69 3.50 2.12 (8 CPUs)
$ MIN_AVAIL_MB=10000 bash health.sh
available memory: 7522 MiB
load average:     4.69 3.50 2.12 (8 CPUs)
WARNING: less than 10000 MiB of memory available

Best practices

Source

free(1), uptime(1), vmstat(8), proc(5)

In this article, we have looked at memory usage with free and learned why available memory matters more than free memory, read the uptime and load averages, and watched CPU and disk activity with vmstat. See also the ps, df, and du articles.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Linux tutorials.