Date:
Category:
DevOps Strategy
What Is Swap Memory? How Linux Swap Space Works

Written by
Dino Starcic
·
CEO

Swap memory is a reserved area on disk that Linux uses as overflow when physical RAM runs short. The kernel moves memory pages that nothing is using right now out to swap, which frees RAM for work that needs it. It keeps a busy server from crashing, but it is far slower than RAM, so what matters is how fast a server swaps, not how full its swap is. For a team running production on AWS, that distinction decides whether a memory alert is noise or an outage in progress. Cloudwise engineers handle this kind of memory and capacity work through a shared backlog, so your team does not have to tune it between feature releases.
CloudwiseKeep AWS Memory Issues in CheckCloudwise engineers handle cloud operations, including infrastructure management and cost optimization, through a shared backlog.Visit
TL;DR
Swap is disk-backed space that acts as an extension of RAM. Linux moves inactive memory pages there when RAM is under pressure.
Some swap in use is normal. Constant swapping in and out (thrashing) is the real warning sign, and the only cure is more RAM or less memory in use.
Red Hat suggests at least 4 GB of swap for a system with 8 GB of RAM, and more if the machine must hibernate. Workload matters more than any formula.
Swap on a cloud instance is a safety margin, not extra capacity. Watch swap rates, not the fill percentage.
Compressed options such as zram and zswap trade a little CPU for less disk I/O on small instances.
Table of Contents
What swap memory is
How Linux decides what to swap
Swap vs. virtual memory vs. RAM
When swap helps and when it hurts
How to tell healthy swap from a problem
How much swap should you have?
Disk swap, zram and zswap
Swap on AWS: what to know
A short checklist for your servers
Getting this off your team’s plate
FAQ
Sources
What swap memory is
Every running program needs memory. RAM is fast but limited and expensive. Disk is slow but cheap and large. Swap is the bridge between them: a partition or a file on storage that the operating system treats as an overflow area for RAM.
Red Hat’s documentation describes swap space as temporary storage for inactive processes and data that prevents out-of-memory errors when physical memory is full. When the system needs more memory than RAM can give, inactive pages are moved to swap, so swap behaves as an extension of physical memory. It can be a dedicated partition, a swap file, or both, and it sits on storage with slower access than RAM.
A “page” is simply a small fixed-size block of memory, usually 4 KB. The kernel does not swap whole programs in most cases. It moves individual pages that have not been touched recently.
The terms you will see around the keyword:
Swap space and swap memory mean the same thing: the disk area used for overflow.
Linux swap is the Linux implementation, which can be a partition or a file. GNOME’s system monitor help describes it as the on-disk part of the virtual memory system, usually set up as a partition or file at install time.
Virtual memory is the broader technique. It gives each program its own address space and maps those addresses to RAM or disk. Swap is one part of it.
How Linux decides what to swap
The kernel’s own memory management guide gives two reasons swap is useful. First, it expands the memory a process may use, through demand paging. Second, it lets the kernel push out pages that were only needed during start-up, so the freed memory can become disk cache that speeds up file access.
This surprises many engineers: Linux does not wait for RAM to hit zero. Oracle’s Linux swapping FAQ explains that the kernel reclaims memory from both file pages and anonymous pages. It prefers to drop clean cache first but does not wait until the cache is gone. So seeing a few hundred megabytes in swap on a server with plenty of free RAM is usually harmless. Pages that were swapped out long ago simply stay there until the owning process exits or modifies them, which is why swap usage can look high with no current pressure.

The swappiness setting
The vm.swappiness kernel parameter tunes how eagerly Linux swaps. Red Hat’s documentation describes it as ranging from 0 to 100, where higher values swap more aggressively and lower values try to keep processes in RAM. Newer kernels extend the range: one 2026 guide notes the range reaches 200 on modern kernels, with a default of 60, and that a value of 0 minimizes swapping rather than disabling it. Treat these as starting points to validate against your own workload, not rules.
Swap vs. virtual memory vs. RAM
These three get mixed up constantly, and a short comparison clears it up.
RAM | Swap | Virtual memory | |
|---|---|---|---|
What it is | Physical memory chips | Reserved area on disk | Technique that maps program addresses to RAM or disk |
Speed | Fastest | Much slower | Depends on where the page lives |
Holds | Active data and code | Inactive pages moved out of RAM | Not storage itself: an addressing scheme |
Survives reboot | No | No (contents are discarded) | No |
The short version: virtual memory is the system, swap is one of the places it can keep data. Programs never run straight from swap. A page must be brought back into RAM before it can be used.
When swap helps and when it hurts
Swap earns its place in three situations:
Absorbing spikes. A deploy, a batch job or a traffic burst briefly asks for more memory than the instance has. Swap gives the kernel room to cope instead of killing a process.
Freeing RAM from cold pages. Memory that is allocated but rarely touched, such as initialization data, can sit on disk while RAM serves hot data and file cache.
Buying time. A slow degradation is easier to catch and fix than a sudden out-of-memory kill.
It hurts when the working set, the memory your workload actively touches, is larger than the machine. The kernel documentation is blunt that disk is very slow: no amount of swap or fast disks will make a process that constantly addresses large amounts of memory run well. Only more RAM will. GNOME’s help says the same of thrashing, where the system spends its time moving pages in and out and everything slows down, with extra RAM as the only real solution.
One 2026 operations guide puts the principle well: swap is headroom, not capacity. If the live working set is bigger than the instance, swap only changes how slowly you find out.
How to tell healthy swap from a problem
The fill level of swap tells you little. The rate of swapping tells you a lot.
Healthy: swap holds some data, but pages rarely move in or out. In
vmstat, thesi(swapped in) andso(swapped out) columns sit near zero with occasional bursts.Trouble:
sistays steadily above a few hundred KB/s, and/proc/pressure/memoryshows sustained “full” pressure, meaning all tasks are stalling together. That same guide notes the fix for thrashing is never more swap but less memory in use or more RAM.
The signals to pair with swap rates on any production host:
Memory pressure (PSI) over time, not a single snapshot.
Latency of the application itself, because thrashing shows up as slow responses before it shows up as errors.
Out-of-memory kills in the kernel log.
Disk I/O wait, which climbs when swap is on a slow volume.
This is the kind of monitoring work that gets neglected until it pages someone at 2 a.m. Cloudwise’s monitoring and observability service covers CloudWatch and Grafana, so memory pressure and swap rates can be turned into alerts that mean something.
How much swap should you have?
The old rule of “twice your RAM” no longer holds for most servers. Red Hat’s current sizing table for RHEL 8 is a sensible reference:
RAM | Recommended swap | With hibernation |
|---|---|---|
Under 2 GiB | 2Ă— RAM | 3Ă— RAM |
2 to 8 GB | Equal to RAM | 2Ă— RAM |
8 to 64 GB | At least 4 GB | 1.5Ă— RAM |
Over 64 GiB | At least 4 GiB, workload dependent | Hibernation not recommended |
So for the common question of how much swap for 8 GB of RAM, Red Hat’s table puts a system at the boundary of two bands: swap equal to RAM in the 2 to 8 GB band, or at least 4 GB in the 8 to 64 GB band, and 12 GB if it needs to hibernate. Servers in the cloud almost never hibernate, so the lower figures apply. Red Hat adds that the right size ultimately depends on the memory workload, not on RAM alone.
A practical way to settle it:
Measure peak memory use across a normal week and a release day.
If peaks stay well under RAM, a modest swap file (a few GB) is enough as a safety margin.
If peaks regularly touch RAM, the answer is a larger instance or a leaner workload, not a bigger swap.
Disk swap, zram and zswap
There are now three common ways to configure swap, and the right one depends on how much RAM you have.
Disk-backed swap is the classic approach: a partition or file on storage. On servers with adequate RAM, a modest swap file on fast storage absorbs spikes at a tolerable latency cost.
zram creates a compressed block device inside RAM. Swapped pages are compressed and kept in memory, so there is no disk I/O. One 2026 guide cites typical compression of 2:1 to 3:1 and presents zram as a good default for RAM-constrained hosts, such as small VMs with 4 to 8 GB. The device size is its uncompressed capacity, so a 4 GB zram device with 3:1 compression uses roughly 1.3 GB of real RAM when full.
zswap is a compressed cache that sits in front of a real swap device. The Linux kernel documentation describes it as a lightweight cache that trades CPU cycles for less swap I/O. When its pool fills, the coldest pages are evicted to the backing disk. Its listed benefits include easing swap impact on low-RAM systems, reducing I/O pressure for overcommitted virtual machine guests and extending the life of SSD swap devices.
A useful rule of thumb: if the instance has no disk swap, zram is the simpler choice. If it already has a swap file, zswap fits on top of it. Pick one compressed layer, not both. Whichever you choose, run a userspace out-of-memory handler such as systemd-oomd alongside compressed swap, since the kernel’s own OOM killer can act too late when memory is compressed.
Swap on AWS: what to know
Many Linux images on EC2 ship without a swap file, and that surprises teams moving from physical servers. Memory sizing on AWS is a purchasing decision: you pick an instance type with a fixed amount of RAM, and cost grows with every step up. That makes swap part of a wider cost and reliability question.
Where swap lives matters. AWS’s own guidance on creating a swap file on EC2 says it is a best practice to create swap only on ephemeral instance store volumes. Swap on a network-attached EBS volume adds latency and I/O charges to something that is already slow.
Containers change the picture. Kubernetes historically did not support swap on nodes, because it is hard to account for pod memory when swap is involved. The project’s design document for node swap support describes enabling it through kubelet settings, with a mode that limits how much swap workloads can use. If you run Kubernetes, swap is a node-level decision that interacts with pod memory limits and eviction behavior.
Right-sizing beats swapping. A node that swaps constantly is usually the wrong size or running a leaky workload. Moving up one instance size often costs less than the engineering hours spent chasing slowness.
These are exactly the trade-offs that sit between infrastructure, Kubernetes and cost. Cloudwise handles AWS infrastructure management for production workloads and cost optimization and FinOps, so instance sizing, memory settings and spend are looked at together rather than in separate tickets.
A short checklist for your servers
Check whether each Linux host has swap at all: run
swapon --showorfree -h.Record swap in use, but alert on swap in and out rates and memory pressure, not on fill percentage.
Pick a size from the table above, then adjust to your measured peaks.
Decide the type: disk swap on fast local storage for ordinary servers, zram or zswap for small instances.
Review swappiness against your workload and kernel version.
Add an alert for out-of-memory kills.
Revisit instance size whenever pressure stays elevated after a deploy.
None of this is hard, but it competes with everything else on a small team’s list. That is the usual reason it stays undone.
Getting this off your team’s plate
Memory tuning, monitoring and right-sizing are routine tasks for a senior AWS engineer, and they pile up when the team is shipping product. Cloudwise is a subscription service that gives you senior AWS and DevOps engineers for day-to-day cloud operations. You add tasks to a shared backlog, prioritize them, and get a typical 24 to 48 hour response time. There is no hourly billing and no long-term contract. The Simplest Subscription is $7,499 per month, and covers requests across infrastructure, monitoring, cost optimization, security and more.

A ticket such as “investigate swap growth on the API nodes and propose a sizing change” is the kind of task that fits the backlog. See the full list of Cloudwise services to find where your team’s recurring operations work belongs.
Sources
Understanding the Linux Virtual Memory Manager: Swap Management
AWS: Use a swap file as swap space in an Amazon EC2 instance
Recommended
Questions Answered
Frequently asked questions
Clear answers to common questions about our AWS & DevOps subscription and how it works.