I'm wondering , what is the recommended thing to do for a swap partition on a server-like system with an M.2 PCI SSD?

I'm wondering if it's wise to put swap on that device, because it's so fast that swap thrashing (which shouldn't ever happen) might go un-noticed until a significant fraction of the drive's lifetime write cycles have been consumed.

Other options include

  1. No swap partition at all, but that will make RAM utilisation less efficient. Also diagnosis if no swapping kills the system.

  2. Add an old slow HD for swap, so its obvious if it's used more than rarely. But that will waste electricity, and it's one more thing that could break the system.

  3. Or...?

Is there some way to give a Linux swap partition an artificial degree of slowness or a data-rate limit? Or to easily monitor and detect that a system is swapping at a high rate, although nobody is complaining that performance sucks?

Centos / RHEL 7, should it make any difference.

closed as too broad by vonbrand, Jeff Schaller, Timothy Martin, Jesse_b, Archemar Apr 29 '18 at 8:03

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • "Easily" depends upon what other monitoring solution you have in place for this machine. If you have something already posting measurements, adding a swatch on vmstat swap-out, and setting an alert as appropriate would work. For example, I believe Telegraf can post swap out stats than can then be monitored. – KevinO Apr 26 '18 at 15:49
  • Fit a slow HD and then use hdparm -S 1 /dev/sdX so it doesn't waste electricity. – steve Apr 26 '18 at 16:28

Three options come to mind:

  1. Just use the SSD. Unless it's a really fast NVMe device, the system will still slow down if it's thrashing (the 500-600MB/s access speed on most SATA and SAS SSD's is still exponentially slower than the double-digit GB/s memory speeds on most modern servers). Even if you don't notice, most SSD's are very good about write endurance these days (Most are rated at hundreds of thousands of their size worth of writes), so it probably won't be much of an issue.
  2. Use the SSD, but also use zswap. Zswap provides an intermediary cache of compressed memory between main memory and swap which can significantly reduce writes to swap. I'm not sure if CentOS 7 supports this or not.
  3. Use a ZRAM compressed ramdisk for swap. In essence, instead of pushing memory out to disk under pressure, the system will compress the memory. This provides very good performance, and reasonable behavior for most workloads, and is what I use on pretty much all of my systems. If you take this approach, make sure you don't set the ZRAM device size too high, otherwise it will run out of space (and having a swap device return a write error is just as bad if not worse than running out of memory).

Not the answer you're looking for? Browse other questions tagged or ask your own question.