Hi Remdore,
I see what you are trying to do, however SWAP is not as good as actual RAM. You might ask why? Simply put, virtual memory is a combination of RAM and disk space that running processes can use. Swap space is the portion of virtual memory that is on the hard disk, used when RAM is full. However SWAP is actually HDD/SSD so it’s slower. If the applications on your droplet do actually need to use that much SWAP they’ll be considerable slower. Having said that it’s good to have SWAP enabled
How to add SWAP
First as you mentioned, we’ll add 3GB of SWAP
sudo fallocate -l 1G /swapfile
If faillocate is not installed, you’ll need to do
yum update
yum install faillocate
Now that you have the swapfile, you’ll need to set the right permissions. Please note only the root user should/will have access to the file
sudo chmod 600 /swapfile
Set up a Linux swap area.
sudo mkswap /swapfile
Enable the swap
sudo swapon /swapfile
To make the change permanent open the /etc/fstab file and append the following line:
/swapfile swap swap defaults 0 0
Verify the swap status.
sudo swapon --show
Now your server has SWAP.
As I saw, you want to have different priorities on different SWAP. The default SWAP priority is -1. If you have two swap partitions one with priority 10 and one with priority -1 the swap partion with priority 10 will be used first.
To change the priority of a swap partions, you can
swapon -p 10 /path/to/swap file/partion
That’s it, you now have everything configured as you wished
Kind regards,
Kalin D.