← All lessons
System administration · Lesson 4 of 7

Memory, disks and load

When a server is slow, check three things: memory, disk space and how busy the processor is.

$ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.7Gi       2.1Gi       1.2Gi       120Mi       4.4Gi       5.3Gi
Swap:          2.0Gi          0B       2.0Gi

Linux uses spare memory to cache files, so "free" is often small and that's fine. The number to watch is available: how much programs could still get. Swap is disk space used as overflow memory; a little is normal, but heavy swapping makes everything crawl. When memory truly runs out, the kernel's OOM (out of memory) killer stops a process to save the system, and the journal says which.

uptime (and the top line of top) shows the load average: three numbers for the last 1, 5 and 15 minutes. Roughly, it's how many processes want the processor at once. Compare it with how many cores you have (nproc): a load of 4 on a 4-core machine is fully busy; on a 16-core one it's quiet.

$ uptime
 10:41:07 up 12 days,  3:02,  1 user,  load average: 0.52, 0.61, 0.58
$ nproc
4

For disks, df -h shows space and lsblk lists the disks and their partitions. A full disk is one of the most common reasons a server stops working: logs and databases can't write. du -sh /var/* | sort -h shows which folder is biggest; old logs and package caches (sudo apt clean) are the usual things to clear.

Disks can also run out of inodes, the slots that record each file, if there are millions of tiny files. df -i shows inode use; "No space left on device" with free space in df -h is the sign.

Practice

Show memory use in readable sizes.

More info

Quick reference

free -hMemory and swap; watch available.
uptime, nprocLoad average; number of cores.
df -h, df -iDisk space; inodes.
lsblkDisks and partitions.
du -sh /var/* | sort -hBiggest folders, last.
OOM killerStops a process when memory runs out.

The other Linux courses