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.
Create a file of size
1GB.fallocateis the tool for that.$ sudo fallocate -l 1G /swapfileFill that file with
zeros.$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576Change the permissions so that only
rootcan change the file.$ sudo chmod 600 /swapfileMake this file a
swappartition.$ sudo mkswap /swapfileEnable this swap partition (start using it).
$ sudo swapon /swapfile
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 0Let’s see what this entry does.
/swapfileis the file that we will be using.swapis the device mount point.swapspecifies the file system type.defaultsthis is the filed for mount options.0specifies the option to be used by the dump program.0specifies the fsck command option.
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.