1

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?

1

3 Answers 3

3

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).

6
  • we are running a couchbase server which gets OOM if it doesn't have at least a bit of swap to play with. It doesn't really respect the memory quota that's being assigned to it + it's a bit impractical to use another instance type as the moment.
    – dimisjim
    Jul 10, 2020 at 6:09
  • 1
    Swap has its uses. I have a t3a.nano (512MB RAM) running Nginx, PHP, MySQL, and a few utilities for five low volume production website - only gets a hit every ten seconds or so. It all generally fits in RAM, but I've added 512MB swap as occasionally there's a demand for memory. Sure it might be a bit slow with virtual memory on EBS occasionally, but it's better than running out of memory :)
    – Tim
    Jul 10, 2020 at 9:24
  • @DimitrisMoraitidis are you aware that there are Memory optimised instances that give you more memory for the same price as the general purpose T3/M5 instances? Updated the answer with a link. That may help.
    – MLu
    Jul 10, 2020 at 10:08
  • 1
    @MLu Yes I am aware of that. I am aware of alternatives. My question was not this. It is why it used to have swap before, but now it doesn't, given the kernel specs I provided.
    – dimisjim
    Jul 10, 2020 at 10:12
  • @DimitrisMoraitidis Swap configuration is a feature of the AMI, nothing to do with the kernel. Do you know what AMI ID did you use before and now? The version has probably changed.
    – MLu
    Jul 10, 2020 at 10:41
2

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.

1
  • no, I am using the same instance type as before
    – dimisjim
    Jul 10, 2020 at 6:04
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .