Here's a legitimate use for swap space -- even in 2016.
There's a Java program that runs as a daemon. It requires a medium
amount of memory. For example, let's say the system has 8GB of RAM and
the daemon requires 6GB of it. That's fine. The base system and maybe
a small database will require some additional memory, so the total
memory usage is about 7GB or something like that. 1GB is left for I/O
cache.
Let's say the system runs smoothly now.
Problem is, you need to be able to cleanly shut down the system. Said
Java daemon is an unfriendly one: In order to *shut down*, it needs to
launch a new Java VM that tells the first VM, "please shut down", and
it *insists* on using the same memory configuration for this task.
This means it will try to allocate *another* 6GB of memory, even
though it never uses it. Just for shutting down.
Now, Linux does memory overcommit by default, which means that the
kernel will happily tell the application, "here's your memory, I
allocated it", even though it is not necessarily backed up by actual
memory pages. This means that we *should* be able to shut down our
daemon! It should work. But there are limits to memory overcommit:
When above a certain threshold of memory usage, Linux will refuse to
do more overcommit. In our scenario, we do have passed that threshold.
As a result, our shutdown process will get an out of memory error and
we can't shut down the daemon. Dang.
One way to solve this is to add the proper amount of swap space to the
system. This keeps us *below* the threshold and the shutdown process
can now run. We will never actually use the swap space, it just has to
be there.
This daemon exists in real life and so does its shutdown procedure.
It's a product sold by a big company.
Next on the TODO list: Which kernel parameters to tweak? How to
actually set that threshold? Maybe we can get away without swap.