Swap and Memory-backed Storage
Quick answer
Swap provides backing for some memory pages when the kernel chooses to reclaim RAM. tmpfs stores files in virtual memory, and those pages may also use swap. Neither is equivalent to durable storage.
Prepare the practice environment
Run python3 lab-fixtures/storage/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Only disposable regular files may be written. Optional examples require an authorized snapshot VM. Never substitute actual devices or modify mounts, system configuration or active swap. Review the lab guide.
How it works
free reports memory and swap statistics; available estimates memory usable without swapping under current conditions, rather than simply unused RAM. swapon --show lists active swap areas. mkswap initializes a swap signature, while swapon activates it. Creating a signature does not activate swap. Swapfiles require filesystem-specific support and allocation constraints; a sparse file is not generally suitable. tmpfs consumes memory as data is written and loses contents when unmounted or rebooted. Avoid changing swap on a running host just to experiment.
A swap signature is an on-disk format, whereas the active swap list describes areas currently registered with the kernel. A prepared but inactive swap file therefore need not appear in that list. A tmpfs size limit is a ceiling, not a reservation of that amount of physical RAM. Check actual usage and available memory separately; the presence of swap does not prove memory pressure is resolved.
Try the examples
Only row labels are asserted because values are dynamic.
Expected stdout:
Mem:Swap:test ! -e ./fresh.swap && test ! -L ./fresh.swap || exit 1dd if=/dev/zero of=./fresh.swap bs=1M count=1 status=nonechmod 600 ./fresh.swapmkswap -U 12345678-1234-4234-8234-123456789abc ./fresh.swap > swap.logblkid -p -s TYPE -o value ./fresh.swapFresh regular file only; this writes 1 MiB and initializes metadata but never activates swap. UUID is a fictional fixed fixture identifier.
Expected stdout:
swapRead-only VM exercise. No rows can mean there is no active swap. Do not activate the sample.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not use tmpfs for the only copy of valuable data, assume all free RAM is available, or activate a sparse swap file.
Practice
Compare Mem and Swap in free -b. Create only the supplied fresh swap image, inspect TYPE with blkid and explain why it is not active. Discard the private directory after practice.
Related references
Study: swapon, free. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Swap and memory-backed storage — Knowledge Check
Apply storage concepts to synthetic fixtures and VM-only scenarios.
Which initializes swap metadata?
Does mkswap activate swap?
What happens to tmpfs after reboot?
What does free available estimate?