How to Increasing Memory (RAM) on DigitalOcean Droplets for "Free"

Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated



This post explains how to setup swap area on Debian machines which do not already have it.

*= It denotes that, you actually do not increase the RAM size but by adding a SWAP area you are able to give more working memory to your machine. OS can then offload inactive/less active memory pages to SWAP file on your disk, so that it can manage tasks requiring memory beyond the limited memory on $5 droplet. And, Swap is not RAM.

I like the tiny $5 droplets from DigitalOcean a lot. But the trouble I used to face was frequently running out of memory while compiling or installing dependencies or projects which simple MEAN setups for development/testing. In most cases, without digging things out from logs you won't even know why is your build/install failing. By the way, I use Gitlab CI to automate build pipelines and deployments.

Mostly, I faced memory issues while things are getting installed using apt (Debian Package Manager) or when Angular CLI is compiling the app bundle. I use Debian distros on my droplets. When I faced memory related issues first, I wondered if the droplet had swap file set up?

I quickly checked this by

$ free -m

And the output suggested that there is no swap file provisioned. This is how the output looked -

     total   used   free   shared   buff/cache   available
Mem:  492     109    280      4         102         366
Swap:  0       0      0

Well, so we know the solution for this one, yes, we need to setup a swapfile. The no-frills procedure I followed to setup a swap file of 2 gigs is as below -

  1. Allocate 2 Gb to swap file

    $ sudo fallocate -l 2G /swapfile
    
  2. Set appropriate permissions for the swap area file

    $ sudo chmod 600 /swapfile
    
  3. Setup the swap area using the space allocated above

    $ sudo mkswap /swapfile
    
  4. Enable the swap area

    $ sudo swapon /swapfile
    
  5. Veify that swap area has been enabled

    $ sudo swapon -s
    

    Output:

    Filename    Type     Size       Used     Priority
    /swapfile   file     2097148    44088    -1
    
  6. To make the swap file permanent, we need to add it to /etc/fstab file. Add the following line to the /etc/fstab file

    /swapfile   none    swap    sw    0   0
    

Well, that’s it.

So, before you think about upgrading to 1 GB ($10) or 2 GB ($20) droplet for the trivial things which $5 can achieve very well, check if you have a swap file set up and give it a try before going ahead with the upgrade.

About the Author

Ordinary People

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.