3

In this tutorial Digital Ocean explain how to enable swap on Ubuntu 14.04. I arrived at this article after experiencing some issues with my server and this looked like it could help.

However, they preface the article with a warning that dissuades their own users, and anyone else running a server with SSDs NOT to enable swap and instead to upgrade their hardward.

I'm a little confused as to why they have the tutorial at all if it's genuinely a bad idea or if it's a sales ploy.

Can anyone with more knowledge help out?

Jack Roscoe
  • 133
  • 4
  • 2
    Something termed write amplification is probably the main reason it's discouraged. And also, there had been concern for several years even back in 2014 about wearing out the flash. That seems to be less of a problem now. – hookenz Mar 13 '17 at 18:54
  • 1
    Adding swap to a server to compensate for not enough RAM is a bad idea anyway. I do like to have a bit of swap on my system for emergencies, though. So if you enable swap and set the swappiness to 1 it shouldn't be a problem unless it is always used. – Christopher Perrin Mar 16 '17 at 15:27
  • It's a sales ploy. – womble Mar 17 '17 at 00:44

2 Answers2

7

Whether or not you provision swap has nothing to do with whether or not you're on flash storage or spinning disk storage.

Everyone agrees that things are sub-optimal if you're hitting swap more than once in a very long period. That said, there are benefits to enabling swap in that it can serve as a "safety valve" of sorts to prevent a complete server crash in the event of RAM contention.

Whether or not you should use swap is not something any of us can answer. You'll need to examine your requirements and your infrastructure to make this decision. If you are running a single server, and if experiencing downtime of this server would be problematic, then it's likely worth it to have a bit of swap space around. On the other hand, if you have a cluster of application servers behind a load balancer, and the loss of one of those servers won't adversely affect your application, then you may decide to not maintain swap space on those systems.

For systems that *do * have swap space, be sure to monitor it very closely. You want to know quickly if the server starts using swap.

EEAA
  • 108,414
  • 18
  • 172
  • 242
3

Although swap is generally recommended for systems utilizing traditional spinning hard drives, using swap with SSDs can cause issues with hardware degradation over time. Due to this consideration, we do not recommend enabling swap on DigitalOcean or any other provider that utilizes SSD storage. Doing so can impact the reliability of the underlying hardware for you and your neighbors.

Yes, that is true. Although I've read multiple articles suggesting that todays SSD drives practically don't degrade before they are replaced due to other factors. I have no sources on that and I am too lazy to look for them.

Daniel
  • 6,780
  • 5
  • 31
  • 60
  • 2
    Should clarify that simply having swap enabled isn't going to cause a notable increase in IO operations. It's *using* that swap that causes IO load, and if you're using swap all that often, you're doing something wrong. For these reasons and the others you brought up, I feel that their hardware degradation argument is not worth putting much weight on. – EEAA Mar 13 '17 at 18:37