Cloud Platform – Add Swap File on CentOS 7


I will start with adding 4GB of swapfile

sudo fallocate -l 4G /

to check 4GB equivalent to KB I will use below site:

4GB = 4194304 KB (in binary)

So run below command now:

sudo dd if=/dev/zero of=/ bs=1024 count=4194304

wait for a while so that system creates a 4 GB file.

See correct permissions:

sudo chmod 600 /


sudo mkswap /
sudo swapon /

you will need to add the swap file permanently, otherwise when the system will reboot this will be removed.

sudo nano /etc/fstab

you might need to install nano utility to install nano:

sudo yum install nano

after the nano is installed now run the same command to edit fstab file:

sudo nano /etc/fstab

move the cursor to the end of the file and paste:

/ swap swap defaults 0 0

to check if your swap file is added:

sudo swapon --show

you will need to setup how frequently the swap file should be used, to do that you can use below commands:

sudo nano /etc/sysctl.conf

Add below lines:

vm.swappiness = 20
vm.vfs_cache_pressure = 50
Cloud Platform - Add Swap File on CentOS 7

In case you want to remove the swap file for some reason you can remove by using this command:

sudo swapoff -v /
sudo rm /

and at the end reboot the system:


you will see the system performance will boost.


Learn more about Cloud Platform follow below links:

Cloud Platform – How to Create Account on Oracle Cloud – Part 1

Cloud Platform – Launch VM Instance on Oracle Cloud – Part 2

Leave a Reply

Your email address will not be published. Required fields are marked *