How To View & Disable Swap Memory in CentOS
Swap is an exchange space that can be represented by a file or a partition, thus swap uses hard disk space instead of using RAM space and in that space it hosts temporary files allowing memory RAM is used at its maximum potential.
With the boom of solid state hard drives, we can have much greater access to the system and we have RAM memory greater than 8 GB. It is possible to disable the partitioned swap of the distro, in this case CentOS , and thus optimize better system resources.
See Amount of Swap Memory in CentOS
First of all we must verify what amount of swap memory is defined for the equipment, this is possible to verify using the following command:
In this example we can see that although we have 1.8 GB available for swap memory, the use is in 0 bytes, so there is an indication that physical memory is more than enough for the tasks carried out in CentOS.
Now, to identify the path where swap is located, we must execute the blkid command :
We can observe the line TYPE = “swap” to define and identify the swap partition. Now, we will run the lsblk command and we will see the following:
There we can determine that the swap partition is hosted on sda2. Once we identify the partition where swap is, we proceed to execute the following command to disable swap in CentOS 7:
We run the free -h command again to verify that swap has been disabled correctly:
Permanently Disable Swap Memory in CentOS 7
If the objective is to permanently disable the swap partition in the system, we must access the file / etc / fstab using the desired editor:
Once there, we should comment on the swap line by prefixing the # sign like this:
We save the changes using the following key combination Ctrl + O and exit the editor using Ctrl + X.
Then we can restart the operating system, or use the mount -a command to apply the changes.
After this we can execute the following commands to verify that swap has been permanently disabled:
free -h blkid lsblk
This way we have disabled swap in CentOS.