Reference

Swap Space

Swap space is storage set aside as overflow for RAM: when physical memory fills up, the OS writes idle memory pages to a swap file or partition and reloads them on demand. It lets a system keep running under memory pressure at the cost of slower disk access.

APIs & internalsGeneral

Swap Space

Also known as: swap memory, swapfile, swap space

Swap space is storage set aside as overflow for RAM: when physical memory fills up, the OS writes idle memory pages to a swap file or partition and reloads them on demand. It lets a system keep running under memory pressure at the cost of slower disk access.

  • Swap holds idle RAM pages on disk, reloaded on demand via page faults.
  • Heavy swapping (thrashing) is slow because flash/SSD is far slower than RAM.
  • iOS uses app termination, while Android favors compressed zRAM over disk swap.

How swap works

When virtual memory demand exceeds physical RAM, the kernel selects rarely used (typically anonymous) pages and writes them to swap, freeing that RAM for active work. When a swapped-out page is touched again, a page fault pulls it back from disk. Because flash/SSD is far slower than RAM, heavy swapping ("thrashing") makes a device feel sluggish.

Swap can be a dedicated swap partition or a swap file on an existing file system. macOS uses dynamic swap files under /private/var/vm, and Linux/Android use swap partitions, swap files, or compressed swap. Clean, file-backed pages (such as program code) generally do not need swap because they can be reloaded from their original file.

Swap on phones vs desktops

Desktops and laptops use real swap freely. Mobile platforms are more conservative to protect flash endurance and battery. iOS does not provide conventional disk swap for third-party apps; instead it terminates background apps under pressure (and recent iPads expose a "swap" feature built on storage). Android typically uses zRAM, a compressed in-RAM swap device, rather than writing pages to the flash storage that holds your files.

Either way, swap is the OS borrowing storage as slow overflow RAM, not a way to add usable file space. Freeing photos or junk files reclaims storage capacity; it does not directly reduce memory pressure or swap usage, which is governed by how many apps are active.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.