Skip to main content

Swap Space

In Turkish
Swap Alanı
Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/swap-space

In short

Swap space is an area on disk that the operating system uses as overflow for RAM, moving rarely used memory pages there when physical memory runs low.

What is swap space?

Swap space is a dedicated partition or file on a disk that extends the memory an operating system can use. When RAM fills up, the kernel picks memory pages that haven't been used recently, writes them to swap, and frees that RAM for active work. If a program later touches a page that was swapped out, the kernel reads it back from disk before the program can continue.

On Linux, swap can be a partition or a regular file, and a setting called swappiness controls how eagerly the kernel swaps compared with dropping cached file data. Windows uses a page file named pagefile.sys, and macOS combines swap files with memory compression. Only memory that exists nowhere else, such as a program's heap and stack, needs swap; pages holding program code can simply be discarded and reread from the original file. Some systems also compress pages in RAM before resorting to disk, which is faster than swapping.

Swap is like renting a storage unit when your closet overflows: moving rarely used boxes there frees space at home, but fetching something takes a trip. If you keep shuttling the same boxes back and forth, you spend all day driving. In computing this is called thrashing, and it makes a system crawl because even a fast SSD is many times slower than RAM.

Swap space is often confused with virtual memory, but it is only one part of it; a system still uses virtual memory with swap turned off. Swap is not a substitute for enough RAM, and it doesn't fix a memory leak, it only delays the crash. Without swap, a Linux system that runs out of memory calls the out-of-memory (OOM) killer to terminate a process, and with swap it slows down first, which is why many servers and container hosts run with little or no swap to keep performance predictable.

Key takeaways

  • Swap space is disk storage used as overflow when RAM is full.
  • The kernel moves rarely used pages to swap and reads them back on demand.
  • Heavy swapping, called thrashing, makes a system extremely slow.
  • Swap is one part of virtual memory, not the same thing.
  • Windows calls its swap area the page file.

Example

Checking and adding swap on Linuxbash
# Show RAM and swap usage
free -h

# List active swap areas
swapon --show

# Create and enable a 2 GB swap file
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# How eagerly the kernel swaps (0-200, default 60)
cat /proc/sys/vm/swappiness

Readers ask

How much swap space do I need?

There is no single rule. Desktops and laptops often use a few gigabytes, or at least as much as RAM if you want hibernation, while many servers use a small amount or none so that memory problems show up quickly instead of causing slowdowns.

Is swap bad for SSDs?

Occasional swapping is fine for modern SSDs, which are built to handle many writes. Constant heavy swapping is a problem mainly because it slows the system down, and it signals that the machine needs more RAM.

What is thrashing?

Thrashing is when the system spends most of its time moving pages between RAM and swap instead of doing useful work. It happens when the active programs need much more memory than the machine has.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings