Swap & Disk Usage

Swap

RAM is fast but finite. Swap is a reserved area of disk (a dedicated partition or even a regular file) that the kernel can use as overflow: when physical memory is under pressure, it moves rarely-used pages out to swap to free up RAM for what's actively needed. It's much slower than RAM, so heavy swapping is a performance red flag, but a modest amount of swap acts as a safety net that keeps a memory-hungry moment from crashing the whole system outright.

$ mkswap /dev/sdb2         # or a file: fallocate -l 2G /swapfile; mkswap /swapfile
$ swapon /dev/sdb2
$ swapon --show
$ free -h                  # see RAM + swap usage

Like any other storage, swap needs to be declared in /etc/fstab (swap swap defaults 0 0) to be activated automatically on every boot rather than needing a manual swapon each time.

Disk Usage

Two very different questions come up constantly when triaging "disk full" issues, and each has its own tool:

CommandPurpose
df -hFree space per filesystem
df -iInode usage
du -sh /var/*Size of directories
ncduInteractive usage browser

df answers "how much space is left on this filesystem as a whole?" - it's fast because it reads filesystem-level counters directly. du answers "how much space is this specific directory actually using?" - it's slower because it has to walk every file underneath and add up their sizes one by one. When a disk is full and you don't know why, the usual move is df -h to confirm which filesystem is full, then du -sh /some/dir/* narrowing down directory by directory until you find the culprit.

Warning: df -h can report plenty of free bytes while a filesystem is still completely unusable - because filesystems also have a finite number of inodes (the metadata records tracking each file's location, owner, and permissions), and once every inode is used, no new file can be created even with gigabytes of raw space free. This typically happens on systems creating huge numbers of tiny files (like millions of small cache or session files). Always check df -i alongside df -h when "no space left on device" doesn't match what the byte count shows.