Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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!
I’m not too sure I understand the warning about having a swap file being “dangerous” for your hardware. If that is true, wouldn’t it be a problem if my application writes several MB of logs every day, enlarge it’s database by many MB every day… etc.
Is there is a difference between a swap file or other files that make them so dangerous?
Hi - thanks for a great article. I have configured swap on ubuntu 16.04 with an Nginx web server, Wordpress underneath, it has plenty of spare memory on a $20 server but it seems to be all eaten up with 1.2GB of buff/cache, and is entering swap even with swappiness set to 10. Of course I would prefer swap space is only used in an emergency. Any thoughts - is this Ubuntu or Nginx eating it up? Here is the extract from Top.
KiB Mem : 2048444 total, 100876 free, 719396 used, 1228172 buff/cache
KiB Swap: 2097148 total, 1655576 free, 441572 used. 1082492 avail Mem
… and from “free”
total used free shared buff/cache available
Mem: 2048444 713328 121088 58368 1214028 1087688
Swap: 2097148 441608 1655540
Thanks. Reply to your WARNING - generally, swap on SSD might be ‘evil’ but it’s necessary to run some apps or to be able to upgrade some apps on basic 512 MB RAM droplet (in my case, I’ve tried to upgrade MariaDB; without swap it just failed and I was unable to run it again ever, with swap it upgraded like charm and runs smoothly).
I’ll leave this here as it can help someone in the future: Heads up on “Make the Swap File Permanent” step.
I had to destoy one droplet because it was entering on “linux emergency mode” after finishing up this tutorial and I couldn’t find the reason. As I created a brand new droplet and finished this tutorial again, it was entering on emergency mode just like the last one.
After some minutes thinking what would be the problem, I realized that I got wrong the step
“You can add the swap file information to the end of your /etc/fstab file by typing:”
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
The command above should be inserted and commited on the bash line command, and I have inserted it as is on the last line of the file /etc/fstab.
A very simple mistake, but I’m a begginer here and I got used to sudo nano files and insert the codes by hand on the other 10 previous tutorials from DO that I’ve consumed.
I hope this save someone droplet one day…
On the permanent part; you could also add the swapon and sysctl commands to your .bashrc.
I think to say SSDs will degrade (fail) quicker was true with earlier SSDs. Newer ones don’t seem to have this issue, and by the time it eventually failed, the SSD would be outdated and need replacing anyhow.
This isn’t to say you should use swap on a regular basis to replace physical memory.
Using Ubuntu 16.04.1 x64 w/ 512MB RAM … without swap there was not enough Mem to run apt-get. Nice straight forward tutorial. Enjoyed learning about swappiness and cache pressure :)
Can you add all links for each version of Ubuntu for swap? https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04 https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04 https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
“We can verify that the swap is available by typing:” “sudo swapon --show”
When I do that to verify, it gives no output, and the output of free -h is still the same as before:
me@server:/var/www$ sudo fallocate -l 1G /swapfile
me@server:/var/www$ ls -lh /swapfile
-rw-r--r-- 1 root root 1.0G Dec 3 07:15 /swapfile
me@server:/var/www$ sudo chmod 600 /swapfile
me@server:/var/www$ ls -lh /swapfile
-rw------- 1 root root 1.0G Dec 3 07:15 /swapfile
me@server:/var/www$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=some uuid
me@server:/var/www$ sudo swapon --show
me@server:/var/www$ free -h
total used free shared buff/cache available
Mem: 488M 190M 175M 15M 122M 251M
Swap: 0B 0B 0B
This is on Ubuntu 16.04.