Create
You can use free -h to check the current swap usage
Create a new swap file (set the size as needed)
bash
sudo fallocate -l 1G /swapfileSet file permissions to root only (optional)
bash
sudo chmod 600 /swapfileFormat the file as swap space
bash
sudo mkswap /swapfileEnable swap
bash
sudo swapon /swapfileEnable automatic mounting
Open the etc/fstab file and add at the end:
bash
/swapfile none swap sw 0 0Modify
Change swap activation threshold
Open etc/sysctl.conf and modify the value after vm.swappiness=80 .If it does not exist, add a new line.
Change swap size
- Use
swapoff -ato turn off swap - Delete the previously created
swapfile - Repeat the creation steps