Increasing the Swap Space on Ubuntu [duplicate]

My Swap space is currently set to 2 GB. How do I increase it?

Also I'm running with an SSD and have 16GB of RAM. What is the Max Memory I can set the swap file to?


Solution 1:

OK - That was a lot less scary than I thought it was going to be. I increased the swap size to 8 GB with the following sequence (Based on the 3rd answer in the linked post - Note that I had to turn off swap first - If you look at your system monitor you will see Ubuntu emptying out your swap space as you run the first command):

sudo swapoff /swapfile
sudo fallocate -l 8G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Verify it:

 sudo swapon --show

Make it permanent:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Update

This worked great and my laptop stopped freezing due to memory hogging by Chrome. One of the comments asserted that 16GB is enough, and in general I agree, but this is what my situation looks like:

enter image description here