Exclusive Metin2 game shield on FreeBSD: Automatic siege mode, VIP list, and whitelist from your dashboard. See how it works
Create a server

Guide

How to Create Swap Space on a Linux VPS

Without swap, a memory spike can OOM-kill processes. A 1–2 GB swap file on a 1–2 GB RAM VPS is usually a sensible cushion.

Steps

  1. Check whether swap already exists:

    free -h
    swapon --show
  2. Create a 2G file, format and enable it:

    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    free -h
  3. Make it persistent in fstab:

    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    sudo swapon --show
  4. Optional: lower swappiness:

    echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf
    sudo sysctl -p /etc/sysctl.d/99-swappiness.conf

Tips

  • If fallocate fails on some filesystems, use sudo dd if=/dev/zero of=/swapfile bs=1M count=2048.
  • Swap is not a RAM upgrade: if the VPS is thrashing, resize the plan.

ext step

More real RAM when swap is not enough: Deploy your Cloud VPS.

Related guides