How Much Swap Space Does Linux Need?
“Should I allocate twice as much swap as RAM? What about half the amount? And if my computer already has 32GB or 64GB of memory, do I need swap at all?”
This is one of the oldest Linux installation questions, and the traditional advice has not aged particularly well.
For years, the common recommendation was to allocate swap space equal to twice your physical RAM. That rule made more sense when computers shipped with 512MB or 1GB of memory. Today, a desktop with 32GB of RAM is fairly ordinary, and a workstation with 128GB is no longer unusual.
Following the old rule on a 32GB machine would mean reserving 64GB of disk space for swap. Is that actually useful?
Usually, no. Modern Linux systems do not need a fixed swap-to-RAM ratio. The right amount depends on your workload, available memory, and whether you use hibernation.
Before choosing a size, it helps to understand what swap actually does and what it cannot do.
🧠 What Is Linux Swap Space? #
Applications use physical memory (RAM) while they run. The operating system allocates memory for application data, process state, libraries, file caches, and its own internal structures.
When memory demand increases, Linux has several ways to reclaim space. It can discard clean file-cache pages that can be read again later, write modified file-backed pages back to storage, and move eligible anonymous memory pages to swap.
Swap is a storage area used to hold memory pages that are not currently resident in physical RAM. It can be implemented as a dedicated disk partition, a swap file, or an appropriate logical volume.
The important point is that Linux does not necessarily wait until RAM is completely full before using swap. The kernel may move less-active pages out of RAM so that physical memory remains available for other work.
Swap therefore serves several purposes:
- It gives the kernel another place to keep inactive memory pages.
- It provides additional capacity during temporary memory pressure.
- It can reduce the likelihood of applications being terminated by out-of-memory handling.
- It provides storage for the memory image used by hibernation.
However, swap is not a replacement for RAM.
RAM, SSDs, and HDDs Have Very Different Latencies #
The main limitation of disk-backed swap is access speed.
RAM is designed for low-latency access. SSDs are much faster than mechanical hard drives, but even a fast NVMe SSD cannot match normal RAM access latency. HDDs are slower still, especially when workloads involve scattered reads and writes.
The exact difference depends on the hardware and access pattern, so there is no universal multiplier. The practical distinction is simple: accessing a page from RAM is much cheaper than repeatedly retrieving it from storage.
When a workload begins actively paging memory in and out, performance can collapse. The CPU spends time waiting for data instead of doing useful work. Applications become sluggish, desktop interactions stall, and disk activity may remain high.
This behavior is commonly called thrashing.
A large swap area can let a system accommodate more committed memory, but it cannot make that memory behave like physical RAM. If a workload continuously needs more memory than the machine can keep resident, adding still more swap is unlikely to solve the underlying performance problem.
🛠️ Why Does Linux Need Swap? #
There are several reasons to keep some swap available, even on a machine with plenty of RAM.
1. Handling temporary memory pressure #
Applications do not always use memory consistently. A browser may accumulate large amounts of data, an IDE may launch several language servers, or a developer may start multiple containers at once.
A system with 32GB of RAM might run comfortably most of the day and then experience a sudden memory spike during a build or virtual-machine startup.
Swap gives the kernel another place to move inactive pages while it deals with that pressure.
It is a safety margin, not a performance upgrade.
2. Supporting memory-intensive workloads #
Video editing, software compilation, large database workloads, scientific applications, virtual machines, and local AI inference can consume substantial memory.
If your workload occasionally exceeds available RAM, swap can help the system remain operational long enough to finish the job or recover from a temporary spike.
For workloads that consistently exceed physical memory, however, more RAM is usually the better investment.
3. Supporting hibernation #
Hibernation, also known as suspend-to-disk, saves the system’s memory image to persistent storage before powering off.
When the machine starts again, Linux restores that image and resumes the previous session.
This requires suitable disk-backed storage and a working resume configuration. A zram device alone cannot provide hibernation because its contents disappear when the machine loses power.
The required storage size depends on the memory image, kernel configuration, and distribution. Allocating swap space at least equal to physical RAM is a conservative starting point, but some distribution guidelines recommend considerably more.
Hibernation is not the same as ordinary suspend-to-RAM. Normal suspend keeps memory powered and does not require writing the entire memory image to swap.
4. Reducing the risk of out-of-memory termination #
When the system cannot reclaim enough memory to satisfy allocations, Linux may invoke its Out-Of-Memory (OOM) handling mechanisms and terminate processes.
Available swap can provide additional headroom, but it does not guarantee that an application will survive memory exhaustion. Cgroup limits, userspace memory-pressure services, kernel allocation behavior, and the amount of reclaimable memory all affect the outcome.
For a closer look at how Ubuntu handles memory pressure and process termination, see Ubuntu 26.10 OOM Changes: Protecting the Linux Desktop.
💾 Do You Need Swap If You Have 32GB or 64GB of RAM? #
Suppose your computer has 32GB of RAM and you rarely use more than half of it.
You might never see significant swap usage. Does that mean swap is unnecessary?
Not necessarily.
A modest amount of disk-backed swap can provide room for unexpected memory spikes and allow the kernel to move inactive pages out of physical memory. The storage cost is usually small compared with the capacity of a modern SSD.
For a typical desktop with 32GB of RAM and no hibernation requirement, starting with 4GB to 8GB of swap is reasonable. You do not need to reserve 64GB simply because you have 32GB of RAM.
A system with 64GB or 128GB of RAM may need even less swap relative to its memory capacity. The amount should follow the workload rather than a percentage formula.
There are exceptions. A workstation that regularly runs virtual machines, large builds, or memory-intensive databases may benefit from more swap capacity than a lightweight desktop.
The right question is not “How much RAM do I have?” but “How much memory can my workload need, and what should happen when that limit is reached?”
Can Linux Run Without Any Swap? #
Yes. Linux can run without disk-backed swap, and some systems are deliberately configured that way.
For example, a dedicated appliance with a tightly controlled workload and sufficient physical memory may not need conventional swap. Some systems instead use zram, which compresses memory pages in RAM and exposes the compressed device as a swap area.
However, running without any swap removes one of the kernel’s options for reclaiming memory. A workload that exceeds available RAM may encounter allocation failures or OOM termination sooner.
For general-purpose desktops and workstations, keeping at least a modest amount of swap is usually a sensible default.
📏 How Much Swap Space Should You Allocate? #
There is no universal sizing formula. Linux distributions publish their own guidelines, and those recommendations vary according to release, workload assumptions, and hibernation support.
The traditional “twice your RAM” rule is not a good default for modern systems with large amounts of memory.
Red Hat’s current RHEL 10 documentation explicitly treats swap sizing as a function of the system’s memory workload rather than RAM capacity alone. Its recommendations are useful as a reference, although they are not mandatory rules for every Linux distribution.
Red Hat Enterprise Linux 10 recommendations #
The following table summarizes Red Hat’s published guidance:
| Physical RAM | Swap without hibernation | Swap with hibernation |
|---|---|---|
| Less than 2 GiB | 2 × RAM | 3 × RAM |
| 2–8 GiB | Equal to RAM | 2 × RAM |
| 8–64 GiB | At least 4 GiB | 1.5 × RAM |
| More than 64 GiB | Workload-dependent, at least 4 GiB | Hibernation not recommended |
Source: Red Hat Enterprise Linux 10 — Recommended System Swap Space.
Notice how the recommendations change as RAM capacity increases. A machine with 32GB of RAM does not need 64GB of swap by default. Red Hat’s baseline for that memory range is at least 4 GiB when hibernation is not required.
The hibernation column is much larger because the system needs room to save its memory image. Red Hat also advises against hibernation on systems with more than 64 GiB of RAM because writing and restoring such a large image can take substantial time and requires additional storage.
These figures are distribution guidance, not a universal Linux standard.
Practical swap recommendations for desktop systems #
For a general-purpose desktop or development workstation, the following starting points are easier to apply:
| RAM | Practical starting swap size without hibernation |
|---|---|
| 4GB | 4GB |
| 8GB | 4GB–8GB |
| 16GB | 4GB–8GB |
| 32GB | 4GB–8GB |
| 64GB | 4GB–8GB |
| 128GB | 4GB or more, depending on workload |
These are starting points, not guaranteed capacity requirements. Systems running large virtual machines, memory-heavy databases, or unusually large compilation jobs may need more.
For a 32GB desktop, for example, I would start with 4GB or 8GB of disk-backed swap if hibernation is disabled. I would increase it only after observing real memory pressure or identifying a workload that needs additional committed memory.
If hibernation is required, do not use this table. Size persistent swap according to the distribution’s hibernation guidance and verify that the resume mechanism supports the chosen partition or file.
⚡ What About zram and zswap? #
Modern Linux systems have another option: compressed memory.
zram: Compressed swap inside RAM #
zram creates a compressed block device in memory. Linux can use that device as swap, storing compressed pages in RAM instead of writing them directly to an SSD or HDD.
For example, a machine with 8GB of RAM might configure a 4GB zram device. That does not reserve an additional 4GB of physical memory in the same way as a disk partition. Instead, zram allocates physical memory as compressed pages are stored, with the actual compression ratio depending on the data.
The trade-off is CPU work for compression and decompression. For systems with limited RAM, this can be attractive because it reduces the need to access slower storage.
A zram device can also be combined with conventional disk-backed swap, often by assigning zram a higher swap priority.
zswap: A compressed cache in front of swap #
zswap works differently. It is a compressed cache for pages being swapped out. Pages are compressed and kept in RAM when possible; if the cache fills or cannot retain a page, the page can be written to the configured backing swap device.
In other words:
- zram creates a compressed swap device in RAM.
- zswap compresses pages before they reach the backing swap device.
Neither mechanism makes disk-backed swap equivalent to physical RAM, and zram by itself cannot preserve a hibernation image across a complete power-off.
For more on the Linux memory-management mechanisms behind compressed memory, see Linux 7.3 Ships as Torvalds’ Claude Code Patch Hits Review.
🔍 How Do You Check Whether Linux Is Using Swap? #
Before changing your swap configuration, check what the system already has.
Run free -h to view memory and swap usage in a readable format.
Run swapon --show to list active swap devices and files, including their sizes and priorities.
You can also inspect /proc/swaps directly.
Do not assume that swap usage indicates a problem. Linux may move inactive pages to swap while keeping useful file data in RAM. A system can show some swap usage and still perform normally.
What matters is sustained memory pressure and whether applications are waiting on swap I/O.
For a more detailed view, tools such as vmstat can show memory activity. Pay attention to the si and so columns, which report swap-in and swap-out activity. Consistent nonzero activity under load is more concerning than a small amount of swap allocated but rarely accessed.
If the system repeatedly swaps pages in and out while applications are running, investigate memory usage before simply increasing the swap size.
🧩 Swap Partition or Swap File: Which Should You Choose? #
A dedicated swap partition used to be the standard approach during Linux installation. It still works, but it is no longer the only practical choice.
A swap file is often easier to manage because you can create, resize, enable, or remove it without repartitioning the disk. This is convenient when you are unsure how much swap a workload will eventually require.
A dedicated partition can be useful for particular storage layouts, hibernation configurations, and systems with established administration practices. Logical volumes are another option.
There are filesystem-specific restrictions, especially when creating swap files on filesystems such as Btrfs. Check the filesystem and distribution documentation before creating one. Hibernation also requires the boot and resume configuration to match the selected swap location.
For most desktop installations, there is no need to insist on a dedicated swap partition. Use the option your distribution supports and choose a size that matches your workload.
🖥️ So, How Much Swap Would I Use? #
The old rule of allocating twice as much swap as RAM is no longer a useful default for most modern computers.
For a machine with 32GB of RAM, I would begin with 4GB to 8GB of disk-backed swap if I did not need hibernation. For a 64GB or 128GB workstation, I would start with at least a modest amount and adjust it based on the applications and services running on the machine.
If I needed hibernation, I would size swap separately according to the distribution’s documented requirements rather than relying on the general-purpose recommendations.
The most useful approach is to monitor actual memory pressure, understand the behavior of your applications, and leave enough swap capacity for the workload you intend to run. Adding more swap can provide additional headroom, but persistent paging is usually a sign that the system needs more physical memory or a different workload configuration.
How much swap do you allocate on your Linux systems, and do you use disk-backed swap, zram, or both?