2

Of course, the purpose for swap is if your RAM runs out. But with 256GB RAM, I doubt this will happen.

A greater concern is that the frequent writing of the swap partition could wear out the SSD. As we know, flash drives have a limited number of reads and writes. That's why I specifically bought a datacenter grade SSD for my server, because consumer SSD is a risky endeavor for a live web server.

I once killed a 400GB consumer micro SD because I attached a swap partition. I had partitioned the micro sd and used a software to put a swap partition on it through Android. I can't verify that was the cause, but it's the only time a micro SD died on me.

With 256GB of RAM in my server, are there any potential risks to NOT having a swap partition at all?

unix
  • 207
  • It's worth noting that some software can be prone to sudden dramatic changes in memory usage. In those cases large amounts of swap can cause unpredictable delays. From personal experience, Java apps on webservers can be prone to this. They allocate a lot of RAM that's not used for a long time, but then suddenly "garbage collection" wants to read every byte the app has. You can't assume low memory usage leads to zero swap. Disk cache and buffer can expand under high IO and push "unused" app data into swap. – Philip Couling Jan 23 '23 at 14:22
  • This is a topic where you can get a lot of conflicting advice. Last time I heard there was little / no difference between swap file performance and swap partition, meaning that you may be better using a swap file and tuning its size per your own experience. Tuning partition sizes is a little more tricky. – Philip Couling Jan 23 '23 at 14:23
  • Some once posted that system seemed to run better if it saw some swap. I would just add a 4GB swap partition and assume it is never used. My 4GB RAM system several years ago for desktop use never used the swap partition. Your RAM may still fill up as Linux caches apps in RAM and releases cached RAM when needed for working app. – oldfred Jan 23 '23 at 15:24

1 Answers1

2

Of course, the purpose for swap is if your RAM runs out.

Not quite, it’s to provide a backing store for memory which doesn’t correspond to something on disk. See this answer for details.

The key is

But with 256GB RAM, I doubt this will happen.

If you never get close to 256GiB of actual memory use, you don’t need swap.

If you do, the risk you run by not having any swap is that some of your programs will be killed because they run out of memory, even though a decent amount of your memory is occupied by data which isn’t actually used. All long-running systems have pages which are never used, and can be usefully pushed out to swap without affecting performance negatively or causing significant wear on the device (they’re written once per boot and that’s it).

Note that swap use is unlikely to affect a SSD much, especially not a datacenter-grade SSD. In a web server, you’ll get more wear (and that’s still small compare to what a SSD can handle) from your server’s logs than from swap use. MicroSD cards have much less write endurance than SSDs.

Stephen Kitt
  • 434,908
  • to explain why it's not going to add to wear: as long as there's no memory pressure (i.e. you're not close to the 256 GB), the swap space simply won't be used. Now, if you don't use it… one might argue you don't need it. I think I agree with this answer, but the question then really becomes how much you're actually losing by not having swap – in a 256 GB system serving websites, I bet it's not that much, relatively to the overall RAM size, and it's probably more crucial that you get good monitoring that alerts you when you start running out of RAM, whether you have some swap or not. – Marcus Müller Jan 23 '23 at 14:16