Swap is a space on the disk that would be used when the psychical amount of memory is full. Let’s see, how to create swap file centos and you can also use free -m command to check swap size in Linux.
How To Create Swap file On Linux:
This is slower than physical ram because it’s created from the disk. The size of the swap must be almost double or equal to the physical ram. You can either create a swap partition or swap file in Linux.
There’re two ways to create a file.
- Use fallocate command
- Use DD command
fallocate -l 1G /swfile
dd if=/dev/zero of=/swfile bs=1024 count=10048576
count = size of a file
Now change the permission the only root should be accessible the file.
chmod 600 /swfile
Run the below command to create a swap.
Make an entry in /etc/fstab and save the file.
/swfile swap swap defaults 0 0
Now run mount -a to check whether the entry is correct or not.
you can check swap partition size using the below commands and also use cat /proc/swaps
Now you have to change the value of vm.swapiness in /etc/sysctl.conf. sysctl vm.swappiness=30
echo ‘vm.swappiness=30’ >> /etc/sysctl.conf
The default value is 30 or 60 and you can put these vm.swapiness =20 line in sysctl.conf file and run sysctl -p
Check Out: How To Delete Backup AMI EC2 On Amazon Cloud
The values are between 0 to 100 and if you set is 0 means swap file will only be used when the system has fully utilized the psychical memory.
You’re done Linux swap file size command to check centos linux create framework 4.7