How to increase Swap in Linux / CentOS / Redhat / Ubuntu
Hi here we will go to know about the swap file system, and how to increase?
First thing, what is swap?
Swap is one type of file system (id=82), which is used as the virtual ram for the system, it provide the extra memory resource to system when it required. In windows it’s called pagefile.sys, and this file system will be created manually or automatically during installation of operating system.
Once swap file system created, you may want to increase the swap space. For that you can follow this tutorial.
In two methods we can create the swap space.
- Using swap partition
- Using swap file
Here we use the first method.
Let check the available swap space.
I am going to increase the swap form 2GB to 3GB.by the following command also. As per this command total swap space is 2GB.
As in the above /dev/sda2 is the swap file system. In my machine I don’t have any space in my primary HDD, so I use another HDD for demonstration. But you can use the same HDD for new swap partition, if you have enough space.
Let’s see the HDD’s attached to this machine.
In the above I have one extra HDD with free space, with the help of the HDD I am going to create the new partition for swap size of 1 GB and assigning the id of 82. The size may be depending on your swap size requirement.
Let create the partition with id of 82 for swap.
Tell the changes to kernel.
Confirm the created partition.
Make the swap partition using following command.
Enable it using following command.
List the swap space available on the machine.
In the above you can find /dev/sdb1 has activated and serves the swap resource to the machine with /dev/sda2.
Use the following command to see the memory available on the machine. In the follow you will be able see the actual memory and virtual memory also.
As per the above total size of swap is 3GB, this is as per our requirement.
If would like to off the swap, you can use the following command.
List the swap space. Because we swap off the above one, you will be able to see he one swap partition which we created now.
In normal case, if you restart the server the swap will not get on automatically. So put it on /etc/fstab
Reboot the server.
If you want to make the priority of swap usage by system, use the following command. High priority will be use more by system. High=10 low= -10.
Verify the priority.