CREATE
- Creating a Swap File
sudo dd if=/dev/zero of=/swapfile bs=1024 count=<1024*desired_swap-size_in_MB>
Keep block size bs=1024
- Set the file permissions to 600 to prevent regular users to write and read the file:
sudo chmod 600 /swapfile
- Create a Linux swap area on the file:
sudo mkswap /swapfile
ACTIVATE
- Activate swap file
sudo swapon /swapfile
- To Make the change permanent open the /etc/fstab file:
sudo nano /etc/fstab
- Paste following line
/swapfile swap swap defaults 0 0
SWAPPINESS
- Check swappiness value
cat /proc/sys/vm/swappiness
On Ubuntu, the default swappiness value is set to 60
- Modify swappiness
sudo sysctl vm.swappiness=10
While the swappiness value of 60 is OK for most Linux systems, for production servers, you may need to set a lower value.
- Make swappiness permanent
To make this parameter persistent across reboots, append the following line to the
/etc/sysctl.conf
file:
vm.swappiness=10
DEACTIVATE
- Deactivate swap file
sudo swapoff -v /swapfile
REMOVE
Remove the swap file entry
/swapfile swap swap defaults 0 0
from the/etc/fstab
file. From Step 5.Finally, remove the actual swapfile from your disk
sudo rm /swapfile
You can find your swapfile at root
directory
To check the status of swap use free -h
or swapon -s
Top comments (0)