Create Swap File on Linux Ubuntu
I am using version 16.04 LTS.
In this video I experiment with performance by creating a ram swap file.
Below are the commands I used
Check if I have an existing swap
~# sudo swapon -s
Double checked using free
~# free -m
List available disks to see which I want to use for the new swap
~# df -h
Chose my disk, then allocated 4gb to a new file called swapfile
~# sudo fallocate -l 4G /swapfile
Verified it now exists
~# ls -lh /swapfile
Adjusted permissions so only root can use it
~# sudo chmod 600 /swapfile
Verified changes again
~# ls -lh /swapfile
Convert it to a real swapfile
~# sudo mkswap /swapfile
Turn it on
~# sudo swapon /swapfile
Checked it's usage
~# sudo swapon -s
Checked it using free
~# free -m
Now make it permanent in case of os reboot
~# sudo nano /etc/fstab
Added line below to file
/swapfile none swap sw 0 0
Press Ctrl X, then Y , then enter, to exit nano and save it back to disk
After a while htop showed me the swap file was now being used. You can check again using
~# sudo swapon -s