Can check if you're using swap with sudo swapon --show
and free -h
.
Useful for t2.micro and other instances with no access to instance store. Use this if you prefer not to mess with the root volume.
- Create the EBS volume e.g., 1 GB. Be sure to avoid the Previous Generation EBS Magnetic volume as it charges for I/O.
- Run
lsblk
before on the instance. - Attach the volume to an instance.
Attaching to
/dev/sdf
will appear as/dev/xvdf
on the instance. - Run
lsblk
again on the instance to verify it's attached. - Set up the swap area:
sudo mkswap /dev/xvdf
- Turn on the swap:
sudo swapon /dev/xvdf
To make this persist across reboots:
- Backup the fstab file:
sudo cp -iv /etc/fstab{,-$(date '+%y%m%d%H%M%S').bak}
- Add:
/dev/xvdf none swap sw 0 0
Sources:
- http://www.bogotobogo.com/DevOps/AWS/aws_adding_swap_space_to_attached_volume_via_mkswap_and_swapon.php
- http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-store-swap-volumes.html
- http://tecadmin.net/add-swap-partition-on-ec2-linux-instance/#
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
View current values:
cat /proc/sys/vm/swappiness
cat /proc/sys/vm/vfs_cache_pressure
Temporarily change the values:
sudo sysctl vm.swappiness=10
sudo sysctl vm.vfs_cache_pressure=50
Persist the values across reboots by appending to
/etc/sysctl.conf
:
vm.swappiness=10
vm.vfs_cache_pressure=50
Good stuff! This helped me out for an AWS install. Thanks.