What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Add swap as a safety buffer for short memory spikes, not as a substitute for RAM. On an Ubuntu or Debian WordPress VPS, the reliable process is to check existing swap, create a hole-free file, restrict it to mode 600, format and enable it, add an exact /etc/fstab entry, and verify it after activation and reboot.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
Swap is disk-backed virtual memory, so it is dramatically slower than physical memory. If the server remains under pressure, investigate PHP-FPM, the database, plugins and workload—or add RAM—instead of continually enlarging swap.
As an Amazon Associate I earn from qualifying purchases.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →What swap does for a WordPress VPS
Swap is disk storage reserved for pages that Linux cannot keep in RAM. DigitalOcean describes it as storage set aside so the operating system can temporarily hold data that no longer fits in memory. That reserve can keep a small VPS alive during a brief traffic burst, backup, image-processing job or database spike.
The trade-off is latency. RAM access is measured in nanoseconds; a swap-in requires storage I/O and can be thousands of times slower. When active WordPress workers are repeatedly moved between RAM and swap, the site may become sluggish even though the kernel has not killed a process. Treat swap as an emergency cushion that buys time to diagnose the cause, not as extra usable memory for normal operation.
#1 Best Overall
Swap is not a WordPress requirement. Current WordPress guidance recommends PHP 8.3 or newer, MariaDB 10.11 or newer or MySQL 8.0 or newer, HTTPS, and a web server such as Apache or Nginx. None of those requirements is satisfied by adding swap, and swap cannot compensate for an undersized VPS running too many services.
Check whether swap already exists
Do not create a second swap area until you know what is active. Log in with an account that can use sudo and run:
sudo swapon --show
free -h
df -h /
Interpret the output
sudo swapon --showlists active swap devices and files. If it prints only column headings—or no rows—there is no active swap area.- In
free -h, theSwaprow shows total, used and free swap. A total of0Bconfirms that none is active. df -h /shows free space on the filesystem where/swapfilewill be created. Leave room for WordPress core, uploads, logs, the database and backups; filling the root filesystem can break the site.
A swap entry can exist in /etc/fstab without currently being active after a failed boot or manual change. The commands above show the running state; later, test the persistent configuration with swapon -a.
Choose a sensible size
There is no WordPress-mandated swap size. The right amount depends on installed RAM, peak workload, disk capacity and whether the server is expected to survive a transient spike or sustained memory pressure.
| Starting approach | When it fits | Qualification |
|---|---|---|
| Swap approximately equal to RAM | A general starting point for a small VPS that needs a safety margin. | DigitalOcean presents RAM-sized swap as a heuristic, not a WordPress rule. |
| Swap up to roughly twice RAM | A low-memory server with occasional bursts and enough free disk. | Also described by DigitalOcean as a starting heuristic; it does not make sustained overcommit safe. |
| More than 4 GiB | Only when measurements and workload justify it. | DigitalOcean notes that more than 4 GiB is often unnecessary when swap is only a fallback for RAM. |
| 1 GiB example | A practical example for a very small VPS with adequate free space. | The command below creates 1 GiB; it is an example, not a universal recommendation. |
Use the smallest size that gives the operating system breathing room while preserving disk space for the application. A server that continuously consumes swap is still short of RAM or misconfigured. Increasing the file again can postpone an out-of-memory kill while making response times worse.
Swap file or swap partition?
A swap file is usually the least disruptive option on an existing VPS: it can be created without repartitioning or reinstalling the operating system, and its size can be changed later. A dedicated swap partition is a separate block device and can be appropriate when the provider supplies one or when filesystem support for files is problematic, but changing partitions generally requires more planning and may be impossible on a running virtual machine.
Rank #2
Regardless of the form, compare these factors before choosing:
- Filesystem support: regular files must not contain holes; Btrfs has additional restrictions.
- Disk headroom: the reserved space must remain available alongside site data and backups.
- Performance: neither form turns storage into RAM; fast local storage reduces, but does not remove, swap latency.
- Operations: a file is easy to remove or resize, while a partition may be harder to alter after deployment.
Create a swap file on Ubuntu or Debian
The following sequence is suitable for a typical Ubuntu or Debian VPS. Replace the size or path only after checking the filesystem and free space. Keep the commands in order.
1. Create a hole-free file
On filesystems where it produces a valid swap file, fallocate is concise:
sudo fallocate -l 1G /swapfile
Some filesystems or kernels reject files containing holes. When compatibility is uncertain—or when swapon later reports holes—use dd, which writes every block:
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 status=progress
Here, 1,024 blocks of 1 MiB create approximately 1 GiB. The command can take time on slower storage; wait for it to finish and check that it reports the expected number of bytes.
2. Restrict access to the file
sudo chmod 600 /swapfile
Swap may contain fragments of passwords, cookies, database records or other process data. Mode 600 allows root to read and write the file while preventing ordinary users from reading it. Verify the permission if you are troubleshooting:
ls -lh /swapfile
The permission string should show read/write access for the owner only (for example, -rw-------).
3. Format it as swap
sudo mkswap /swapfile
mkswap writes the swap signature and reports the usable size. If it warns about an unsuitable file, stop and resolve the filesystem or file-creation issue instead of forcing activation.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →4. Activate it immediately
sudo swapon /swapfile
Activation changes the running kernel state but is not yet persistent across reboot. Check both views:
sudo swapon --show
free -h
You should see /swapfile in the first command and a non-zero total in the Swap row of the second.
Make the configuration survive a reboot
Add one line to /etc/fstab:
/swapfile none swap sw 0 0
Use an absolute path for a regular-file source. Edit the file with your preferred editor, save it, and then test every swap entry without rebooting:
sudo swapon -a
sudo swapon --show
swapon --all reads swap entries from /etc/fstab. If the test prints an error, fix the line before restarting. A typo, a missing file, an incorrect filesystem type or an extra character can leave the VPS without swap after the next boot.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteRank #4
After a maintenance window, reboot if you need to validate the complete boot path. Once the server returns, run:
sudo swapon --show
free -h
Do not consider the setup complete until the file is active after reboot. If it disappeared, inspect the exact /etc/fstab line and run sudo swapon -a manually to capture the error.
Understand and tune swappiness
The kernel’s swappiness value, from 0 to 100, influences how readily it reclaims anonymous memory to swap rather than keeping it in RAM. Debian documentation notes that many distributions default to 60. The value is a policy preference, not a promise that the kernel will wait until RAM reaches a particular percentage.
Free tools Windows power users keep installed
One-click scans. No signup required.
Read the current value:
cat /proc/sys/vm/swappiness
Change it temporarily for observation:
sudo sysctl vm.swappiness=10
A lower value can keep application pages in RAM longer, which may help latency on a busy WordPress stack, but it can also increase reclaim pressure and trigger an out-of-memory event sooner during a spike. Do not copy a “magic” value from an unrelated server. Observe page-in activity, request latency, available RAM and swap usage under your real workload. Only after testing should you persist a chosen value in /etc/sysctl.conf, for example:
vm.swappiness=10
Apply a persistent change with sudo sysctl -p and confirm the resulting value. If performance worsens, remove or revise the line and reload the configuration.
Why swap does not fix WordPress memory limits
There are several independent memory ceilings on a WordPress VPS:
Best Value
- Physical RAM: the capacity shared by the kernel, web server, PHP-FPM, database, caching services and monitoring tools.
- PHP limits: WordPress documentation states that the default requested PHP memory is 40 MB for a single site and 64 MB for multisite. The effective limit can also be constrained by the PHP configuration and hosting setup.
- Worker and process counts: each PHP-FPM worker consumes memory. Too many concurrent workers can exhaust RAM even when each request is individually modest.
- Database workload: large buffers, complex queries, imports and concurrent connections compete with PHP for the same memory.
- Plugin and theme behavior: a memory leak or an operation that loads a large catalog, image set or export can overwhelm an otherwise adequate server.
Raising a PHP memory limit may allow one request to allocate more, but WordPress documentation warns that increasing the limit can hide the underlying cause. Swap can keep the kernel from immediately killing a process, yet it cannot make an oversized request efficient. Resolve persistent failures by profiling the request, reviewing recent plugins and themes, adjusting PHP-FPM workers, tuning the database and adding RAM when demand is genuinely sustained.
Diagnose an out-of-memory event after adding swap
If the site still returns 502/503 errors, hangs or loses services, determine whether the kernel or an application component failed.
Check kernel evidence
dmesg | grep -i -E 'out of memory|oom|killed process'
Look for the process the kernel killed and the memory conditions at that moment. On systems where kernel messages are restricted, use the system journal or your distribution’s log viewer with equivalent OOM filtering.
Check service logs and concurrency
- Review PHP-FPM logs for worker exhaustion, child crashes and slow requests.
- Check the web server error log for upstream timeouts and refused connections.
- Inspect database logs for connection limits, failed queries and restarts.
- Compare PHP-FPM worker counts with the memory footprint of one worker; reducing concurrency can be safer than allowing every request to run at once.
- Identify scheduled jobs, backups, image conversions and imports that coincide with the failures.
Check swap activity, not just capacity
A non-zero swap total does not prove that the server is healthy. Watch whether swap used grows continuously and whether swap-in activity coincides with latency. If the system spends most of its time moving pages between disk and RAM, adding more swap only creates a larger slow queue. Move to a larger VPS or redesign the workload when pressure is persistent.
Common activation failures and their fixes
swapon: /swapfile has holes
The file was created with holes that the kernel will not accept as swap. Remove the file, recreate it with the dd command shown above, run chmod 600, then repeat mkswap and swapon. Ubuntu’s swapon manual specifically warns about hole-containing files.
Recommended Free Tools
Invalid argument or a Btrfs error
Verify the filesystem:
findmnt -no FSTYPE /
Btrfs imposes additional swap-file restrictions. Follow the distribution’s documented Btrfs method, or use a supported swap partition or block device supplied by the VPS provider. Do not assume that a command that works on ext4 is valid on Btrfs.
Swap vanishes after reboot
Confirm that /swapfile still exists, inspect the exact /etc/fstab entry, and run sudo swapon -a. The command’s error output usually identifies a path, syntax or filesystem problem. Once corrected, verify with swapon --show after reboot.
The VPS continues to be killed by OOM
Swap is not a cure for sustained overcommit. Use kernel and service logs to identify the largest consumer, reduce memory-heavy plugins or jobs, right-size PHP-FPM and database settings, or provision more RAM. If you cannot safely administer these settings, a managed WordPress or managed Linux service can provide that operational layer, but it does not change the underlying resource requirement.
Quick Recap
Operational checklist
- Record the current output of
sudo swapon --show,free -handdf -h /. - Choose a size based on RAM, observed peaks and remaining disk space; use the RAM-sized or double-RAM heuristics only as starting points.
- Confirm filesystem support, especially on Btrfs.
- Create a hole-free file, using
ddwhenfallocateis not known to be safe. - Set mode 600 before writing any swap signature.
- Run
mkswap, activate withswapon, and verify bothswapon --showandfree -h. - Add
/swapfile none swap sw 0 0to/etc/fstaband test withsudo swapon -a. - Reboot during a planned window and verify that swap returns automatically.
- Monitor latency, RAM, swap used and OOM logs; tune swappiness only after observing the workload.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




