Back
VPS

Add a swap file

Add a swap file to your Victus VPS to survive memory spikes and avoid the OOM killer when RAM is tight.

swapswapfilememoryoomout of memoryperformance

Swap is disk space the kernel uses as overflow when RAM fills up. On a smaller VPS plan a swap file is a cheap safety valve: it keeps the out-of-memory (OOM) killer from abruptly terminating your app during a brief memory spike. This is a file-based swap, so no repartitioning is required.

Swap is a cushion, not a substitute for RAM

Disk is far slower than RAM, so a machine that swaps heavily and constantly will feel sluggish. Use swap to absorb spikes; if you swap all the time, upgrade the plan for more RAM.

Create a swap file

bash
# Create a 2G swap file (adjust size as needed)
fallocate -l 2G /swapfile
# If fallocate is unavailable:
# dd if=/dev/zero of=/swapfile bs=1M count=2048

# Lock down permissions (required)
chmod 600 /swapfile

# Format and enable it
mkswap /swapfile
swapon /swapfile

# Confirm it is active
swapon --show
free -h

Make it survive reboots

bash
# Add to fstab so it re-enables on boot
echo '/swapfile none swap sw 0 0' >> /etc/fstab

Do not add a duplicate fstab line

Only append the swap line once. If you run the setup twice, check /etc/fstab and remove any duplicate /swapfile entry, or boot will error.

Tune how eagerly it swaps

bash
# Lower swappiness = prefer RAM, only swap when really needed (good for servers)
sysctl vm.swappiness=10

# Persist it
echo 'vm.swappiness=10' >> /etc/sysctl.d/99-swappiness.conf

Sizing rule of thumb

For servers, 1x to 2x your RAM is a reasonable swap size (e.g. 2-4G on a 2G VPS). Make sure you have the free disk space first with df -h — and remember swap consumes disk that counts toward your plan.

Related in VPS

First login over SSH (find your IP + root password)Locate your Victus VPS IP address and root password in the control panel, then connect over SSH from Windows, macOS or Linux for the first time.Reset the root passwordChange your Victus VPS root password from inside the machine, or reset it from the panel or rescue mode if you are locked out.Reinstall / rebuild the OSWipe your Victus VPS and reinstall a fresh Ubuntu template from the control panel, including how to back up first and what survives.Open firewall ports (ufw)Use ufw on your Victus Ubuntu VPS to open the ports your apps need — web, game and custom services — without locking yourself out of SSH.Cannot connect / SSH connection refusedDiagnose and fix the common reasons an SSH connection to your Victus VPS is refused, times out, or rejects your password/key.Resize the disk after an upgradeAfter upgrading your Victus VPS plan the virtual disk grows, but Linux needs the partition and filesystem expanded to actually use the new space.Create and restore snapshotsTake point-in-time snapshots of your Victus VPS before risky changes and roll back to them from the panel if something breaks.Boot into rescue modeBoot your Victus VPS into a rescue environment to repair a broken boot, fix fstab, reset the root password, or recover files when the OS will not start.Mount a custom ISOAttach and boot your Victus VPS from a custom ISO to install an operating system that is not offered as a stock template.IPv6 networking basicsUnderstand and configure the IPv6 address on your Victus VPS — find your address, test connectivity, and bind services to IPv6.Install a one-click appDeploy common software on your Victus VPS in minutes using the one-click app installer in the control panel.Check CPU/RAM/disk usageMonitor CPU, memory and disk usage on your Victus VPS from the panel graphs and with standard Linux commands to spot bottlenecks.