Just built a new AMI recently, based on the latest 18.04. Did also an apt upgrade
when provisioning it, in order to have the latest packages as well.
Problem is that this new AMI has no swapfile in it, checked via swapon --show
. It uses 5.3.0-1030-aws kernel. Same image built 6 months ago with the same way (but no apt upgrade
done on top of it) which uses 4.15.0-1052-aws, does have a swapfile as expected.
The swapfile can be created at provisioning time too, but I am just curious on why this has changed since December.
What am I missing?
I don’t know why or if it changed but ... do you actually need a swapfile or swap partition?
The times when it was needed for performance reasons are long gone. You should select an instance type with enough memory for your workload and you won’t need a swap space.
Check out Memory optimised EC2 instances with a lot more memory per CPU than the general purpose T3/M5/etc instances. For the same price you can get a much more memory (and fewer CPUs but that's often not an issue).
Possibly you picked an instance type without a swap volume by default. Certain EC2 small memory instances launch with swap enabled on a tiny instance store swap volume.
Or, perhaps the swap space exists, but isn't being used due to some scripting or fstab change. Conform any swap devices found with
lsblk --fs
are in use.Swap space still has use cases. Linux memory management is more efficient with swap for everything but systems with an excessive amount of free memory. It allows pushing memory allocations beyond what is possible with just physical RAM. Better to dig into swap space, than annoy the OOM killer or panic the system.
Of course, this isn't a magical get more RAM button. Too much paging and the kernel has to wait for slow secondary storage, killing performance. Swap on SAN storage (EBS in EC2 speak) consumes network bandwidth unnecessarily; use instance store volumes on EC2. And DRAM is relatively inexpensive for how fast it is. Then there is operations annoyances for configuring swap space, like your current mystery. So many systems don't bother with swap space.
After all there is no difference between such kernel versions (of course) or base AMIs.
Most plausible scenario is that someone did this change manually, at some point.