Press "Enter" to skip to content

Murmur: should we use swap space?

I recently read a Reddit post asking whether Intel Optane SSD can be used for swap space in Linux. I didn’t really care about the question itself or the answer to it. I was just waiting for my bus at a bus stop and browsing random posts online. However, upon reading the replies, I found I couldn’t agree with one of them.

The OP was planning to build a machine for a Minecraft server. He/she would get 32GB of RAM and was wondering if swap was needed and whether Intel Optane can be used as swap. I don’t know if 32GB of RAM is enough for a Minecraft server.

But one guy said 32GB 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 would run some scientific computing. That’s when I felt like I had to say something.

My opinion: for scientific computing, swap should not be used! A good scientific computer program should crash when OOM (out-of-memory) happens. So users know OOM occurred and realize they have to deal with the issue.

If swap is used, a scientific computer program hitting OOM may keep running without users’ notice. And the computing performance goes down due to the I/O with the swap. This is unacceptable because, for long-running scientific calculations, time is money. Especially when the program runs on cloud VMs or non-free cluster, every CPU hour credit is precious.

Also, that’s why a good scientific computer program should have a mechanism to handle checkpoints. So we can always restart the calculation from the point before the crash.

As to the general use case of swap, I can only say from my own experience and use case: swap is a good-to-have on a laptop. First of all, hibernation requires swap. Even though I rarely get my laptop into hibernation manually, I still want it to hibernate automatically when the battery is depleted.

Second, modern webpages and browsers consume a lot of memory. While a laptop may only have 8GB (or even 4GB) of RAM,  I don’t want my laptops to crash just because I open too many tabs in the browsers. Nowadays, laptops use NVMe SSD. This means the I/O speed is much much much higher than traditional SATA spinning hard drives and SSDs. And the I/O speed of swap is hence much higher than it was in the old days. My recently-purchased XPS 13 is the first laptop I have that uses NVMe SSD. And I immediately noticed the difference in swap performance when I opened too many tabs in my browser and hit OOM.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.