Special Offers: Up to 75% OFF on Hostinger & High-RAM Contabo Cloud VPS available this month.Compare Plans

How to Configure Swap Space on Linux VPS: Complete Performance & Swappiness Guide

Marcus Sterling
Marcus SterlingLinux Systems Engineer
October 19, 2026
•
14 min read
•
4.8 / 5.0
Transparency Notice: This article contains affiliate links to hosting providers like Hostinger and Contabo. If you purchase through our links, we may earn a commission at zero extra cost to you. We only recommend products we personally benchmark and test. Read full disclosure.
How to Configure Swap Space on Linux VPS: Complete Performance & Swappiness Guide

Hostinger vs. Contabo: Full Specifications Breakdown

Data verified from our lab benchmarks • Updated for 2026

Feature / Metric
HostingerEditor's Choice UI
ContaboMax RAM Value
Starting Price$2.99 / month (Web) | $4.99 / mo (VPS)$5.50 / month (Cloud VPS S)
vCPU Cores1 to 8 vCPU (Dedicated resources)4 to 12 vCPU (High Core Count)
RAM Memory4 GB to 32 GB6 GB to 64 GB (Gigantic RAM)
Storage Technology50 GB – 400 GB NVMe SSD50 GB NVMe or 300 GB SSD
Traffic / Bandwidth4 TB to 32 TB32 TB Outgoing + Unlimited In
Control Panel & UIhPanel (Ultra Modern & Easy)cPanel, Plesk, Webmin, or CLI
Customer Support24/7 Live Chat & AI Support (Multi-lingual)Email Ticket Support (German Business Hours)
Best ForBloggers, WordPress Sites & Devs wanting easy UIHeavy Database, Docker, Game Servers & SysAdmins
Money-Back Guarantee30-Day Money-Back Guarantee14-Day EU Statutory Cancellation
Official LinksVisit HostingerVisit Contabo

What is Swap Space and Why Does Every VPS Need It?

Swap space is a designated area on a storage drive (SSD or NVMe) that operating systems use as overflow memory when physical Random Access Memory (RAM) becomes saturated. When an application requests more memory than currently available, the Linux kernel identifies inactive memory pages and moves them to the swap space, preventing the notorious OOM (Out Of Memory) Killer from forcibly terminating mission-critical processes like MySQL, PostgreSQL, or PHP-FPM.

Checking Existing Swap Configuration

Before creating a new swap file, verify whether your provider already provisioned a swap partition:

sudo swapon --show
free -h

If the output for Swap reads 0B, your VPS has no active swap space.

Step 1: Allocating the Swap File

Use fallocate to instantly reserve disk space without filling it with zeroes. For servers with 4GB-8GB of physical RAM, a 4GB swap file is ideal:

# Allocate a 4 Gigabyte swap file
sudo fallocate -l 4G /swapfile

# If fallocate fails or is not supported by your filesystem, use dd:
# sudo dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress

Verify the file size on disk:

ls -lh /swapfile

Step 2: Securing Swap File Permissions

Only the superuser should have permission to read or write to swap. Failing to restrict permissions allows unauthorized users to read sensitive application memory (including plaintext passwords and private SSL keys):

sudo chmod 600 /swapfile
ls -l /swapfile
# Output should show: -rw------- 1 root root 4.0G

Step 3: Initializing and Activating Swap

Format the file as Linux swap space and turn it on:

# Format as swap
sudo mkswap /swapfile

# Activate swap space
sudo swapon /swapfile

# Confirm active swap
free -h

Step 4: Making Swap Permanent Across Reboots

By default, swap files disappear upon system reboot unless registered in /etc/fstab:

# Backup your fstab configuration first
sudo cp /etc/fstab /etc/fstab.bak

# Append swap entry
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Step 5: Tuning Kernel Swappiness & Cache Pressure

The Linux kernel uses the vm.swappiness parameter (value from 0 to 100) to decide how aggressively memory pages are swapped. A value of 60 is standard for desktops, but for production cloud servers, a lower value between 10 and 20 is recommended so the kernel prioritizes physical RAM.

Check current swappiness:

cat /proc/sys/vm/swappiness

Permanently set optimal production parameters in /etc/sysctl.conf:

sudo nano /etc/sysctl.conf

Add these lines at the bottom:

# Swap only when RAM is critically low
vm.swappiness = 10

# Maintain cached inode/dentry file system metadata
vm.vfs_cache_pressure = 50

Apply changes immediately without rebooting:

sudo sysctl -p

Step 6: Monitoring Swap Usage in Real Time

To inspect which specific Linux processes are occupying swap space, run this diagnostic command:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head -10

Frequently Asked Questions (FAQ)

Does swap wear out my NVMe SSD?

With vm.swappiness=10, the Linux kernel rarely touches swap during normal operations. It acts primarily as an emergency safety net, meaning SSD write cycles are negligible.

How large should my swap file be on a 16GB RAM VPS?

For systems with 16GB or more of physical RAM, a 4GB to 8GB swap file is plenty. Sizing swap beyond 8GB is counterproductive because heavy swapping slows system performance.

Editorial Verdict: Pros & Cons

What We Love (Pros)

  • Prevents catastrophic MySQL and Nginx crashes due to OOM killer
  • Frees up expensive physical RAM for active disk caching
  • Takes under 3 minutes to implement with zero downtime

Drawbacks (Cons)

  • Swap space on disk is significantly slower than physical DRAM
  • Excessive swappiness can cause disk I/O thrashing if misconfigured
#Linux Swap#Server Optimization#Ubuntu#RAM Management#VPS Performance
Marcus Sterling

Written by Marcus Sterling

Linux Systems Engineer

Alex and the ServerCraft engineering lab run routine benchmarks on over 25 web hosting providers, maintaining strict objectivity and reproducibility.

Recommended Next Reads