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 Cores | 1 to 8 vCPU (Dedicated resources) | 4 to 12 vCPU (High Core Count) |
| RAM Memory | 4 GB to 32 GB | 6 GB to 64 GB (Gigantic RAM) |
| Storage Technology | 50 GB – 400 GB NVMe SSD | 50 GB NVMe or 300 GB SSD |
| Traffic / Bandwidth | 4 TB to 32 TB | 32 TB Outgoing + Unlimited In |
| Control Panel & UI | hPanel (Ultra Modern & Easy) | cPanel, Plesk, Webmin, or CLI |
| Customer Support | 24/7 Live Chat & AI Support (Multi-lingual) | Email Ticket Support (German Business Hours) |
| Best For | Bloggers, WordPress Sites & Devs wanting easy UI | Heavy Database, Docker, Game Servers & SysAdmins |
| Money-Back Guarantee | 30-Day Money-Back Guarantee | 14-Day EU Statutory Cancellation |
| Official Links | Visit Hostinger | Visit 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
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
Hostinger vs Contabo VPS (2026): Real Benchmark Test & In-Depth Comparison
A comprehensive, benchmark-driven comparison between Hostinger and Contabo VPS. We tested Geekbench CPU scores, NVMe I/O, network latency, and hPanel vs CLI.
Hostinger Review (2026): Is It Truly the Best Web Hosting for the Price?
We stress-tested Hostinger's Premium and Cloud Startup plans across 180 days. Read our honest review covering uptime, LiteSpeed speed tests, and renewal fees.