Changes

Jump to navigation Jump to search
1,616 bytes added ,  08:56, 19 May 2016
Created page with "Swap memory is a file-system based temporary storage for memory to allow a system to shuffle between different tasks that would otherwise consume all available physical memory..."
Swap memory is a file-system based temporary storage for memory to allow a system to shuffle between different tasks that would otherwise consume all available physical memory (RAM). Cloud providers like [[AWS]]<ref>https://serverfault.com/questions/218750/why-dont-ec2-ubuntu-images-have-swap</ref> and [[Digital Ocean]] do not setup swap on their default images. So, it's up to you to enable swap. https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

<source lang="bash">
# see if it's enabled?
swapon -s
# check how much RAM we have (also tells you swap is zero)
free -m
# how much disk do we have, and where?
df -h
# lets make a swap file that is 2x RAM
# dd if=/dev/zero of=/swapfile bs=1G count=2
# fallocate is faster than dd because it doesn't actually write 2GB of zeroes
fallocate -l 2G /swapfile
# set permissions so that nobody but root can read/write
chmod 600 /swapfile
# setup the swap area
mkswap /swapfile
# turn it on
swapon /swapfile
# show it for confirmation
swapon -s
# make it permanent in the file system
echo /swapfile none swap sw 0 0 | tee -a /etc/fstab
# there are some other problems with a default Droplet
# swappiness is too high, and cache pressure is too high

cat << HERE >> /etc/sysctl.conf
# swappiness for a VM should be closer to zero
# 60 might be good for a desktop
# 10 for a server
vm.swappiness=10
# you can check cache_pressure with
# cat /proc/sys/vm/vfs_cache_pressure
# Default is 100 at Digital Ocean which is bad
# set it lower
vm.vfs_cache_pressure=50
HERE
</source>

[[Category:System Administration]] [[Category:Cloud]]
4,558

edits

Navigation menu