Microsoft Certified Systems Administrator (MCSA)

Microsoft Certified Technology Specialist (Windows 7 Deployment)

CompTIA Security+ Certified IT Professional

Certified Internet Web Associate v5

Network+ Certified IT Professional

CIW Certified JavaScript Developer

Microsoft Certified Professional

Cheating Death: Overcoming the Lack of Swap in Amazon EC2. PDF Print E-mail
Written by Sam Caldwell   
Monday, 22 October 2012 07:05



Most virtualized environments correctly eliminate swap in their guest environments, but this leads to crashes in Amazon EC2 or Digital Ocean "cloud" hosting where the hosting provider places hard limits on memory.  Such crashes often are intended to force the customer to upgrade to larger (and more expensive) servers or to otherwise implement high availability for web applications.


(1) Connect to the virtual guest using SSH and obtain root access (e.g. sudo su -).

(2) Create a loopback device (a file that we will mount as a disk to create our own local "swap" space).

(3) Format the loop file using mkswap.

(4) Mount the loop file to the file system as (/mnt/swap)

(5) Turn on swap (swapon /mnt/swap).

(6) Edit /etc/fstab to remount this swap file at boot up.


(1) Where possible (e.g. Amazon EC2) use a separate EBS volume for swap to avoid slowing down the system.  This will also allow scalability.

(2) Remember the rule: allocate 1.5 to 2 times the amount of RAM for your swap space.



Need help implementing this strategy, email the author at This e-mail address is being protected from spambots. You need JavaScript enabled to view it .

Last Updated on Monday, 22 October 2012 07:13