OFFER Limited time only: -10% site-wide with code WELCOME10

Configuring swap on a Linux VPS for a game server

Updated on September 18, 2026 5 min read 8 sections

On a Linux VPS, swap can act as a safety net when RAM reaches saturation. It does not replace RAM and it does not turn an undersized server into a high-performance machine. For a game server, the goal is mainly to avoid a sudden stop during a spike and to keep a clear diagnosis method.

Preparing VPS server access

This guide concerns a Linux virtual server administered over SSH, with an account that has sudo or root access. The commands suit a standard Ubuntu or Debian installation, but the exact behavior may depend on the distribution and the virtualization used by the host.

Before changing the disk, keep your IP address and SSH access available, check that the SSD disk or the VPS storage has free space, then schedule the operation outside a period of heavy activity. A control panel or a firewall does not replace these system checks. For the first settings of a dedicated server, also read our guide to securing a dedicated server.

What swap is for on a Linux VPS

Swap is a storage space that Linux can use when certain memory pages cannot stay in RAM. Depending on the provider, it may be presented as a partition or as a file. A swap file is convenient on an already-installed VPS, because it avoids repartitioning the disk.

Since storage is much slower than RAM, a machine that constantly exchanges data with swap can become very slow. Before adding it, check the available memory and the real consumption of your game server. Swap is a fallback mechanism on a virtual server, not a performance promise or an increase in physical memory.

A VPS is a virtual machine isolated on a physical server. This architecture provides flexibility to adjust a VPS plan, but it does not change the limits of the allocated memory. A cloud hosting or an infrastructure made of several virtual servers may offer other resizing mechanisms: always check what is actually included in your contract before enabling a Linux setting.

The operating system, the number of processor cores, the memory and the storage form a whole. Adding swap fixes neither a saturated processor nor a badly configured game script. If a migration to another VPS is considered, first measure the real consumption so you can choose a suitable virtual machine rather than move the problem.

Checking the current state before any change

Start by observing the existing RAM and swap. These commands do not change the machine:

free -h
swapon --show
findmnt -no FSTYPE,OPTIONS /

If swapon --show already shows a line, a swap space is active. Do not automatically create a second file without understanding the existing configuration. Also note the available space before reserving a new file:

df -h /
cat /etc/os-release

The last command confirms the distribution in use. This check is particularly important on a VPS that already hosts several services, an administration panel or backups. Our guide to backing up a dedicated server reminds why disk space must stay monitored separately from memory.

Creating a swap file with simple checks

The method below creates a 2 GiB file at the root of the system. Adapt the size to the available memory, the free space and the documentation of your distribution. Run each step with an account allowed to use sudo:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
swapon --show
free -h

chmod 600 limits access to the file. mkswap prepares the file for swap, then swapon enables it for the current session. If a command returns an error, stop and read it before continuing. Do not delete an old active swap to work around a message you did not understand.

Making swap available after a reboot

Manual activation is not enough after a reboot. Add an entry to /etc/fstab only after checking the path and the output of swapon --show:

sudo cp /etc/fstab /etc/fstab.bak
printf '/swapfile none swap sw 0 0\n' | sudo tee -a /etc/fstab
sudo swapon -a
swapon --show

The backup copy lets you return to the previous state if the entry is incorrect. Also check that an identical line does not already exist in /etc/fstab, so you do not register the same file twice. Keep a backup SSH access or the console offered by your host before restarting a virtual server.

Monitoring usage without confusing swap and performance

After enabling it, regularly check free -h and the overall load. Occasional use of swap is not, by itself, proof of a failure. However, persistent swap activity with nearly full memory indicates that you should reduce the server's consumption or increase its resources.

On a game server, start by identifying the process that consumes the memory, the loaded extensions and the scheduled tasks. For a broader diagnosis, our article on the overload of a Linux game server offers a distinct approach for the CPU. Monitoring the disk space also remains necessary: a full disk can cause symptoms that resemble a memory problem.

Monitoring must look at least at the memory, the swap, the disk and the availability of the game process. Supervision scripts can alert on saturation, but an alert does not replace the analysis of the cause. If the server regularly reaches its limits, a private server with more resources or a better-sized plan will be more coherent than a swap that is constantly solicited.

Do not change a firewall, DNS or control-panel setting just because swap is used. These components address other problems. First measure the memory, the storage and the processes, then document each change made with your root or sudo access.

Disabling or deleting the file cleanly

Never delete a swap file that is still active. To disable it temporarily, use:

sudo swapoff /swapfile

Then remove its entry from /etc/fstab, and delete the file only if you are certain you no longer need it:

sudo rm /swapfile

After any change, run swapon --show and free -h again. If your priority is first to reduce the pressure on memory, also see our guide to optimizing the performance of a FiveM server, separating the game settings from the system settings.

Need a VPS suited to your game server?

Swap is a safety net, not a substitute for a coherent configuration. Compare the resources, the storage and the Linux environment before choosing a virtual server suited to your load on our Linux VPS page.

Discover Linux VPS