Running tmp and swap from your fast SSD in AWS

Ensure your SSDs are mounted on /mnt

# mount -l

Add a 8GB swapfile to /mnt

# cd /mnt
# /bin/dd if=/dev/zero of=swapfile bs=1M count=8192
# chown root:root swapfile
# chmod 0600 swapfile

Activate your new swapfile

$ mkswap /mnt/swapfile
$ swapon /mnt/swapfile

I symlink tmp to the mnt directory as well…

# mkdir /mnt/tmp
# chown -R root:root /mnt/tmp
# chmod 1777 /mnt/tmp
# ln -s /mnt/tmp /tmp

Ensure both these are happy at reboot by adding/modifying these lines in /etc/fstab

/dev/xvd[X] /mnt ext3 defaults,usrquota 0 0
/mnt/swapfile swap swap defaults 0 0

PS: If you haven’t got any ephemeral storage attached to your EC2 instance, you’ll need to create an AMI from that instance, modify the attached volumes and create a new box attaching the EBS drives to it. A little bit of downtime, but hopefully worth it for the snappy swap space.

Ref:
http://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-swap-creating-file.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html#Using_AddingDefaultLocalInstanceStorageToAMI