Hi guys,
I’m looking to create a swap partition on my server. I want it to be at least 3 GB big so that I can actually have more RAM there and server my websites faster or is it not how that works?
Additionally, if possible I would like to have priority of partition and if I see that it works good, I’ll add more.
Can you please let me know how to approach this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
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
If faillocate is not installed, you’ll need to do
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
Set up a Linux swap area.
Enable the swap
To make the change permanent open the /etc/fstab file and append the following line:
Verify the swap status.
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
That’s it, you now have everything configured as you wished
Kind regards, Kalin D.
Hello all,
Apart from from CentOS, you can create SWAP on any distribution you want. Here is a link to a tutorial on how to add SWAP on an Ubuntu droplet:
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04