Recommend swap partition or swap file size based on installed RAM and workload type.
Swap sizing guidance varies with installed RAM. Small-memory systems (≤2GB) benefit from swap double their RAM because the OS itself needs breathing room. Mid-size systems (2-8GB) do well with swap equal to RAM. Large-memory systems (>8GB) rarely need swap proportional to RAM, so the recommendation flattens to the larger of 4GB or the square root of RAM. If hibernation (suspend-to-disk) is required, swap must be at least RAM plus a safety margin (approximated here as RAM + √RAM) since the entire RAM image is written to swap on suspend.
Swap for RAM ≤ 2GB
swap = 2 × RAM
Swap for 2GB < RAM ≤ 8GB
swap = RAM
Swap for RAM > 8GB
swap = max(4, √RAM)
Hibernation-safe swap
swap = RAM + √RAM
Some swap is still useful even with abundant RAM — it lets the kernel move rarely-used pages out of RAM and provides a safety margin against out-of-memory situations, but it no longer needs to scale linearly with RAM.
Hibernation writes the entire contents of RAM to swap before powering off, so the swap space must be at least as large as RAM, with a small margin for kernel bookkeeping — approximated here as RAM plus its square root.
Modern SSDs tolerate swap well under normal desktop/server workloads; the practical concern is more about performance (swapping is much slower than RAM) than SSD wear for typical usage patterns.