Amazon EC2 common problems – there’s no swap space

Ubuntu EC2 EBS images don’t come with swap space configured (for 11.04 at least). The “regular” instance-type images do have a swap partition, though only 896 MB.

amazonec2

If some process blows up and you don’t have enough memory or a swap space, your server could come to a crawling halt for a good while before the OOM (out of memory) killer kicks in, whereas with swap, it merely gets slow. For that reason, I always like to have swap space around, even with enough RAM.

The simplest solution here is to create a swap file ( this is my favorite choice), we can create one (size 1024) using this command :

sudo dd if=/dev/zero of=/var/swapfile bs=1M count=1024 &&
sudo chmod 600 /var/swapfile &&
sudo mkswap /var/swapfile &&
echo /var/swapfile none swap defaults 0 0 | sudo tee -a /etc/fstab &&
sudo swapon -a

Done. 🙂 I know a lot of people feel icky about using files instead of partitions, but it certainly works well enough as emergency swap space.

actually you can use a swap partition if you want to, but amazon EC2 “normal” instances don’t support it.

collected from http://serverfault.com/a/279632

2 Comments

    1. yes, thank you for reminding me, credit added. actually i read it and save it to my evernote – where i keep note for what i discovered or found, i picked some good notes from it but there is no reference URL.

Leave a Comment