I recently read a Reddit post asking whether an Intel Optane SSD can be used for swap space in Linux. I didn’t really care about the question itself or the answer. I was just waiting for my bus at a bus stop and browsing random posts online.
However, when I read the replies, I found that I couldn’t agree with one of them. The OP was planning to build a machine for a Minecraft server. They would get 32 GB of RAM and were wondering whether swap was needed and whether Intel Optane could be used as swap. I don’t know if 32 GB of RAM is enough for a Minecraft server. But one guy said 32 GB of RAM was enough, so swap was not needed unless the OP planned to do scientific computing or video editing.
In other words, this guy thought swap might be necessary if the machine were going to run scientific computing workloads. That’s when I felt like I had to say something.
My opinion: for scientific computing, swap should not be used.
A good scientific computing program should crash when OOM (out-of-memory) happens. Then users know OOM occurred and realize they have to deal with the issue. If swap is used, a scientific computing program that hits OOM may keep running without the user’s notice. And the computing performance goes down because of the I/O to swap.
This is unacceptable because for long-running scientific calculations, time is money. Especially when the program runs on cloud VMs or a non-free cluster, every CPU-hour credit is precious. That is also why a good scientific computing program should have a checkpoint mechanism. Then we can always restart the calculation from the point before the crash.
As for the general use case of swap, I can only speak from my own experience: swap is good to have on a laptop.
First of all, hibernation requires swap. Even though I rarely put my laptop into hibernation manually, I still want it to hibernate automatically when the battery is depleted.
Second, modern web pages and browsers consume a lot of memory. While a laptop may only have 8 GB, or even 4 GB, of RAM, I don’t want my laptops to crash just because I open too many tabs in the browser.
Nowadays, laptops use NVMe SSDs. This means the I/O speed is much higher than it was with traditional SATA hard drives and older SSDs. And the I/O speed of swap is therefore much higher than it was in the old days. My recently purchased XPS 13 is the first laptop I have that uses an NVMe SSD. And I immediately noticed the difference in swap performance when I opened too many tabs in my browser and hit OOM.