Swap is disk space Linux can use as emergency memory. It is slower than RAM, but it can help prevent processes from being killed when memory usage briefly spikes.

Swap is not a replacement for enough RAM. If a game server constantly uses swap, reduce its settings or upgrade the VPS RAM.

  1. Connect to the VPS with SSH.
  2. Check existing swap:
    free -h
    swapon --show
  3. Create a 2 GB swap file:
    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile

    Linux VPS terminal showing a swap file being created and enabled

  4. Enable the swap file after reboot:
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  5. Check it is active:
    free -h
    swapon --show

 

How much swap should you add?

For most small VPS use cases, 1 GB to 4 GB of swap is enough. Do not create swap larger than the free disk space can comfortably support.

If the VPS is running a memory-heavy game server, swap may prevent a crash during a spike, but it will not fix performance problems caused by not having enough RAM.

Do not create a huge swap file on a small disk. Leave enough free disk space for logs, updates, and backups.

  • 0 brukere syntes dette svaret var til hjelp
Var dette svaret til hjelp?

Relaterte artikler

How to connect to a Linux VPS with SSH

SSH is the normal way to manage a Linux VPS. It gives you a terminal on the server so you can...

How to update packages on a Linux VPS

Keeping packages updated helps patch security issues and keeps server tools compatible. Run...

How to create a sudo user on a Linux VPS

A sudo user lets you manage a Linux VPS without logging in as root for every task. This is safer...

How to secure SSH on a Linux VPS

SSH is the main way to manage a Linux VPS, so it should be secured before the server is used for...

How to check disk usage on a Linux VPS

Disk usage issues can stop updates, backups, logs, databases, and game saves from writing...