Skip to content

Instantly share code, notes, and snippets.

@lcampanis
Created June 10, 2017 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lcampanis/9c65dca997532ae8c7d549ee0159566c to your computer and use it in GitHub Desktop.
Save lcampanis/9c65dca997532ae8c7d549ee0159566c to your computer and use it in GitHub Desktop.
Add More SWAP Memory to avoid "Memory Allocation Error"
# Confirm you have no swap
sudo swapon -s
# Allocate 4GB (or more if you wish) in /swapfile
sudo fallocate -l 4G /swapfile
# Make it secure
sudo chmod 600 /swapfile
ls -lh /swapfile
# Activate it
sudo mkswap /swapfile
sudo swapon /swapfile
# Confirm again there's indeed more memory now
free -m
sudo swapon -s
# Configure fstab to use swap when instance restart
sudo nano /etc/fstab
# Add this line to /etc/fstab, save and exit
/swapfile none swap sw 0 0
# Change swappiness to 10, so that swap is used only when 10% RAM is unused
# The default is too high at 60
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment