Swap Space Size Calculator for Linux RAM and Hibernation

Swap Space Size Calculator

Size Linux swap the right way. Enter your installed RAM, pick a distribution guideline such as RHEL or Ubuntu, and choose whether you need hibernation. The tool applies the RHEL tiered ratios and the Ubuntu square-root rule, adds RAM on top when hibernation is enabled, and reports recommended, minimum, and total virtual memory in gigabytes.

🐧Real Swap Sizing Presets

šŸ’¾System and Swap Inputs

Physical memory installed on the machine.

Unit for the RAM value above.

Sets the base rule used for the recommendation.

Hibernation writes RAM to swap, so swap must hold all of RAM.

Database hosts often prefer smaller swap to avoid latency.

Drives the suggested swappiness value, not the size.

Compressed in-memory swap can reduce on-disk swap need.

Snaps the recommended swap to a tidy partition size.

Recommended swap (no hibernate) 0 GB from the distro rule
Recommended swap (hibernate) 0 GB base plus full RAM
Minimum swap 0 GB safe floor to keep
Total virtual memory 0 GB RAM plus chosen swap

šŸ”¢RHEL Rule Snapshot

2xRAM ≤ 2 GB
1x2 to 8 GB
0.5x8 to 64 GB
+RAMIf hibernate

šŸ“ŠRHEL Tiered Swap Guideline

RAM RangeSwap (No Hibernation)Swap (With Hibernation)Notes
Less than 2 GB2 times RAM3 times RAMTiny systems need headroom
2 GB to 8 GBEqual to RAM2 times RAMBalanced default
8 GB to 64 GB0.5 times RAM1.5 times RAMMinimum 4 GB swap
More than 64 GBAt least 4 GBRAM plus 4 GBHibernation rarely used here

šŸ—„RAM to Swap Comparison Grid

Installed RAMRHEL RuleUbuntu RuleWith HibernationTotal VirtualNote
2 GB4 GB1 GB4 GB6 GB2x tier applies
4 GB4 GB2 GB8 GB12 GBEqual to RAM
8 GB8 GB3 GB16 GB24 GBBoundary case
16 GB8 GB4 GB24 GB40 GBHalf of RAM
32 GB16 GB6 GB48 GB80 GBHalf of RAM
64 GB32 GB8 GB96 GB160 GBHalf at top edge
128 GB4 GB11 GB132 GB260 GB4 GB floor only

šŸžUbuntu Square-Root Rule Examples

RAMsqrt(RAM) SwapRAM + sqrt(RAM) HibernateReads As
1 GB1 GB2 GBRound up small
2 GB1 GB3 GBsqrt 2 is 1.4
4 GB2 GB6 GBExact square
8 GB3 GB11 GBsqrt 8 is 2.8
16 GB4 GB20 GBExact square
32 GB6 GB38 GBsqrt 32 is 5.7
64 GB8 GB72 GBExact square
128 GB11 GB139 GBsqrt 128 is 11.3

šŸŽ›Swappiness by Storage and Role

ScenarioStorageSuggested swappinessWhy
DesktopSSD or NVMe10Keep apps in RAM, spare flash
DesktopSpinning HDD30Balance slow disk and RAM
General serverSSD or NVMe10Favor page cache
Database serverSSD or NVMe1Avoid swap latency spikes
Database serverSpinning HDD1Never swap hot pages
Low-RAM box with zramAny100Compressed swap is fast

āš™Formula Breakdown

RHEL, RAM ≤ 2 GBSwap equals two times RAM. A 2 GB box gets 4 GB of swap without hibernation.
RHEL, 2 to 8 GBSwap equals RAM. A 4 GB machine gets 4 GB of swap under the balanced default.
RHEL, 8 to 64 GBSwap equals half of RAM, with a 4 GB floor. A 16 GB host gets 8 GB of swap.
RHEL, over 64 GBSwap is a 4 GB minimum. A 128 GB server needs only 4 GB unless it hibernates.
Ubuntu ruleSwap equals round(sqrt(RAM)). For 16 GB that is sqrt(16) = 4 GB of swap.
Hibernation add-onAdd full RAM on top so the sleeping image fits. Swap becomes at least RAM in size.
Total virtual memoryTotal equals RAM plus the swap you choose. 16 GB RAM plus 8 GB swap is 24 GB.

šŸ’”Swap Tuning Tips

Hibernation needs swap at least RAM: Suspend-to-disk copies the entire contents of RAM into swap, so on a 16 GB laptop the swap area must be 16 GB or larger before hibernation will succeed. Follow the RHEL tier for daily paging, then bump swap up to full RAM if you plan to hibernate.
Lower swappiness on SSDs: The default vm.swappiness of 60 is aggressive for flash storage. Set it to 10 on SSD and NVMe desktops, or 1 on database servers, so the kernel keeps hot pages in RAM and only swaps under real pressure. This cuts write wear and avoids latency spikes while still using swap as a safety net.

In just a few seconds, it looks at your installed RAM, uses it as a guide, checks if you use hibernation, and suggests your total, minimum, and recommended virtual memory amounts. In so doing, it removes guesswork and uses real-world distribution guidelines from distributions like Debian, SUSE, Ubuntu, and Red Hat. And it accommodates that special case: hibernation, which messes up the whole calculation.

Twice your RAM was good advice for a machine shipping with 512 megabytes of RAM, not for a server with 128 gigabytes.

How to Set Up Swap Space

Swap: The kernel allocate some disk space to use as an overflow for physical memory. As your RAM becomes full, the kernel dumps those least recently used memory page into swap. This frees up physical memory for things you are actively working on. It also allow the kernel to store less frequently used pages in swap while giving more RAM to its file cache. Everything speeds up.

However, because disk is much slower than memory, swap isn’t a substitute for RAM. But having a modest swap area act like a safety valve that prevents out-of-memory killer from abruptly killing any process when memory runs out.

The official Red Hat Enterprise Linux guideline for swap space is published in levels where it adjusts the ratio downward with increasing RAM. If you have 2 gigabytes of RAM or less: 2x RAM is swap. Between 2 gigabytes and 8 gigabytes of RAM: RAM = swap. Between 8 gigabytes and 64 gigabytes of RAM: swap is set to half of your RAM with a 4 gigabyte floor. If you have more than 64 gigabytes of RAM, you are mostly paging out to disk anyway. Because of this, they recommend a 4 gigabyte floor.

In practice, these distros land pretty close to the same number. We used the same tiered calculation for Debian and SUSE in the swap calculator above.

Another lighter guideline from Ubuntu is the square root of your RAM. Swap should be approximately the square root of your RAM size, rounded up. For instance, a machine with 16 GB of RAM would use 4GB, and 64GB would use 8GB. On big machines, it generates lower levels of swap than the RHEL tiers do, which matches Ubuntu’s desktop-first assumption that it doesn’t need heavy paging if it has lots of RAM. The Ubuntu guideline sets the default formula to this kind of square-root approach, allowing you to see both philosophies side-by-side before committing to a set of partitions.

And then there’s hibernation. In hibernation, the whole contents of RAM are written out to the swap space (it’s called suspend-to-disk), and then the machine is powered down entirely. When you wake it up again, the kernel reads that image back into memory, restoring your session exactly. Your swap therefore has to be at least as big as your RAM, because the entire memory image must fit. So if you have a 16 gigabyte laptop, you need 16 gigabytes or more of swap. The RHEL paging level would just ask for 8 gigabytes of swap every day. How does it know? It takes the default recommendation and adds a complete copy of RAM on top of it when you turn on hibernation.

Swap profiles aren’t one size fits all. Database servers typically like a small amount of swap space with a low swappiness value. For the database role, the calculator reduces the base recommendation and says ā€œConsider setting vm.swappiness=1.ā€ This allows hot data pages to stay in RAM. It also avoids the latency spikes that swapping causes for query response times.

Storage type matters for tuning rather than sizing. Flash drives (NVMe and SSD) are recommended to have a swappiness of 10 to preserve their flash write endurance. Middle values strike a balance between memory pressure and slow seeks on spinning disks.

Nowadays, our moddern kernels also generate compressed swap which actualy resides within the physical RAM. Zswap acts as a compressed cache in front of your real swap device, while zram creates a block device backed by compressed memory. Both reduce the amount of writing to disk. If either is turned on the calculator notes it and increases the recommended swappiness towards 100. Writing to compressed RAM is cheap and fast.

For single-board computers such as a Raspberry Pi or small cloud instances, turning on zram is frequently more effective than creating a big swap file on disk.

The answer lies in three questions: how much RAM do you have? What is the distribution rule that best fits your system? Do you hibernate? Answer them and the sizes fit together.

Sizes vary based off how strict the distribution guidelines are: two times the RAM on small systems, or just a 4 gigabyte minimum on big servers. Add some more if you want to hibernate. Tune swappiness so it matches your workload and storage. Think about compressed swap on constrained systems. Use the presets as a starting point. Read the breakdown to see why.

In the end, you’ll wind up with a swap configuration that protects your system without wasting disk space.

Swap Space Size Calculator for Linux RAM and Hibernation