Swap is not a substitute for RAM, but on a 1 GB or 2 GB budget VPS it occasionally prevents the outage that would otherwise end the month. The question worth answering precisely is when a swap file changes the outcome and when it just makes a slow machine slower. The answer depends on three numbers: how much memory the site actually needs at peak, how long it stays above the physical ceiling, and how many disk IOPS the plan will give you when the kernel starts paging.
What the OOM killer actually targets
When memory runs out, the kernel does not kill the biggest process. It scores every process by an oom_score derived from resident memory, adjusted by oom_score_adj, and kills the highest scorer. On a typical LEMP box that is usually MariaDB or a PHP-FPM worker — whichever is largest — not the innocuous script that allocated the last megabyte. MySQL dying takes the site down for far longer than the process that caused it.
Swap changes the scoring landscape. With swap present, the kernel can reclaim anonymous pages instead of invoking the killer at all. A 15-second spike that would have killed MariaDB becomes a 15-second period of slow responses, and the site stays up. That is the specific benefit: it converts a hard failure into a soft degradation.
When swap genuinely saves the site
Swap earns its place when three conditions hold: the excess demand is short, the working set compresses well, and the disk can absorb the extra I/O. A WordPress site whose PHP workers grow during a cron-heavy five-minute window, or a Node app with a garbage collection spike, fits the first two. Idle PHP-FPM pools and cold database pages in swap are cheap to page back in on a plan with 2,000+ IOPS.
Sizing: 1–2 GB of swap on a 1–2 GB machine, on the same NVMe volume, is a reasonable default. Set vm.swappiness=10 so the kernel prefers dropping cache over paging out live processes, and vm.vfs_cache_pressure=50 to keep inode and dentry caches around. On a 4 GB plan with a database, 2 GB of swap is insurance; 8 GB is a sign you should have bought more RAM.
When swap just delays the inevitable
If a process’s working set permanently exceeds RAM, swap becomes a treadmill. The kernel pages out hot data, immediately pages it back, and the disk spends its IOPS on transfers that do no useful work. Throughput can fall to a few requests per second while load average climbs into the double digits — a state sometimes called swap death, which looks like a hung server with 100% disk utilisation.
Watch vmstat 1 for sustained so (swap-out) values above 1,000 KB/s for more than a minute. Brief spikes during a deploy are fine; a flat line of swap-out while your site is serving traffic means the plan is too small. More swap will not fix it and will make the disk problem worse.
Measure before you tune
Three commands settle most of this in ten minutes. free -m shows what is resident versus cached. cat /proc/meminfo | grep -E 'Committed_AS|CommitLimit' shows whether you are overcommitted relative to your own limits. ps aux --sort=-rss | head -12 shows which processes hold the memory and therefore which ones the killer would pick.
Run them at the peak hour, not at 3 a.m. If peak resident usage sits at 60–75% of RAM, swap is a safety net and you are correctly sized. At 85–95% every day, you are one cron job away from an incident and should be looking at the next plan up, not at swap tuning.
Configure it correctly
Create a fixed-size swap file rather than a partition so you can resize it without a rebuild: fallocate -l 2G /swapfile, then chmod 600, mkswap, swapon, and add an fstab entry with sw as the options. Set the sysctls in /etc/sysctl.d/99-swap.conf and apply them. On containers and OpenVZ plans, this may be blocked at the host level — test with swapon --show after creation.
Add early warning too: a cron that alerts when SwapFree drops below 20% of total catches the trend days before an OOM. Alerting on the OOM event itself is too late; by definition the outage already happened.
When adding RAM beats any swap configuration
Add RAM when sustained memory pressure is daily rather than weekly, when swap-in/out is continuous during traffic, or when the application’s baseline alone exceeds 70% of the plan. On budget hosts the step from 2 GB to 4 GB usually costs $3–6 per month, which is less than the billable hour you would spend tuning and re-tuning a configuration that is fundamentally short on memory.
Swap is the right tool for the last 10% of headroom, not the first 50%. Keep it small, keep it monitored, and treat a persistent swap-out line as the signal to move up a tier. Affordable VPS Server shows the price step between memory tiers so you can compare that cost against the hours you would otherwise spend on tuning.
Used this way, a swap file is the cheapest uptime insurance on a budget box: zero monthly cost, one incident quietly avoided, and a metric that tells you when it is time to stop relying on it. When that metric arrives, compare the next memory tier at affordablevpsserver.com before you spend another evening on tuning.

