How to add swap on Ubuntu
When it makes sense
1. Check current memory and swap
free -h
swapon --show2. Create a swap file
sudo fallocate -l 2G /swapfilesudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress3. Set secure permissions
4. Format the file as swap
5. Enable swap
6. Make it persistent after reboot
7. Optional: tune swappiness
Choosing a swap size
Best practices
How to remove swap
Conclusion
Last updated