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
.fallocate
is the tool for that.$ sudo fallocate -l 1G /swapfile
Fill that file with
zeros
.$ sudo dd if=/dev/zero of=/swapfile bs=1024 count=1048576
Change the permissions so that only
root
can change the file.$ sudo chmod 600 /swapfile
Make this file a
swap
partition.$ sudo mkswap /swapfile
Enable 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 0
Let’s see what this entry does.
/swapfile
is the file that we will be using.swap
is the device mount point.swap
specifies the file system type.defaults
this is the filed for mount options.0
specifies the option to be used by the dump program.0
specifies 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.