Create Swap Partition on VPS Instances

If you are using a small VPS instance. Like an instance with half a Gig or one Gig of the RAM. You probably need to configure the swapfile on that instance in order to increase the performance.

So let’s see how to configure the swapfile on those instances.

Let’s say you have 512MB of RAM available and you want to make 1GB of swap.

The process goes like this.

Now you can check in htop if you have a swap partition and and if you are making use of it.

Remember these changes you have just made to the system are temporary. So after restart you won’t see the swap space of 1Gb.

In order to make it persitiant. You need to edit the file /etc/fstab. Add following entry to /etc/fstab.

/swapfile    swap    swap    defaults 0 0

Let’s see what this entry does.

Once you have this entry for swapfile in /etc/fstab you can reboot the system and check if the swap space is being used or not.