Live data from Hacker News

Linux Performance: Why You Should Almost Always Add Swap Space

haydenjames.io

51–60 of 120 posts

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#51
post #38
post #15

I wondered this for a while, unfortunately a major question I have remains unanswered in the text: What about SSDs and SSD-only systems? (Like... any average laptop.) Should I be worried that putting a swap on an SSD will cause it to wear out fast due to many write cycles?

I've swapped hundreds of terabytes to consumer SSDs. Haven't noticed any problems yet (visibly).

By the time you start to see r/w issues on anything that resembles a modern SSD, you're probably wanting to replace the overall device anyway

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#52

Cargo cult system administration. No, you should not 'almost always add swap space'. What you should do instead is tune your system for its intended use. If you need swap as an 'early warning system' that you're about to run out of memory you're already doing it wrong and the OOM killer is a piece of code that has default settings that can be tuned, ditto for the virtual memory manager in the kernel. http://www.oracl…

You should just about always add at least some swap.

Anyone who thinks otherwise hasn't read much or seen very many systems.

start here:

- https://www.kernel.org/doc/gorman/html/understand/understand...

- https://www.kernel.org/doc/gorman/html/understand/understand...

- https://www.linuxquestions.org/questions/linux-kernel-70/why...

- https://kerneltalks.com/disk-management/swap-addition-in-lin...

- https://linuxaria.com/howto/linux-memory-management

- https://kernelnewbies.org/Linux_4.8#head-a0b674ff33af7e3e7b8...

- https://kernelnewbies.org/Linux_4.11#head-680ed3eee137456d6a...

- https://kernelnewbies.org/Linux_4.14#head-5327850512ba28763d...

- https://help.ubuntu.com/community/SwapFaq#How_much_swap_do_I...

- https://access.redhat.com/solutions/15244

- https://serverfault.com/a/684800/2321

- https://serverfault.com/q/329928/2321

- https://serverfault.com/q/25653/2321

- https://serverfault.com/a/825915/2321

- https://askubuntu.com/q/184217/3544

- https://antipaucity.com/2011/08/08/why-technical-intricacies...

I've been in environments ranging from a few dozen individual servers to 100s of 1000s. In companies ranging from mom-and-pop shops to international investment banks. Every last one is configured with swap. Because unless you have done all the profiling to truly know you don't need it, you should be running it.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#53
post #50

Earlier quoted context omitted.

I used to work in flash manufacturing. We would joke, "I hope nobody ever uses this for swap!" The numbers I saw for endurance (basically write-erase cycles before failure) were not encouraging at all. As far as I can tell the only reason MLC flash works at all is that the controller does some magic to present a whole bunch of pretty flaky cells as a single reliable unit.

>I used to work in flash manufacturing How long ago? r/w cycles haven't really been an issue on SSDs in a long time

2010. I've been following the industry since I left, and I promise you neither the physics of FN flash nor the manufacturing process has fundamentally changed since then. Nor have the true endurance numbers substantially improved. If anything the situation is worse now with smaller device dimensions. The only thing standing between your collection of cat gifs and oblivion is the flash controller making intelligent guesses about what it just read.

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#54

So, wouldn't the best answer clearly be to buy even more RAM, and use a RAMdisk for swap?

That would be the ideal response, but unfortunately there are cases when it's not possible.

1. System is already maxed-out at its board limit

2. Specific RAM simply isn't available any more from preferred vendors

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#55
post #33

> As a last resort, the Kernel will deploy OOM killer to nuke high-memory process(es) Yes! That is exactly what I want to happen! When the system runs out of RAM, things will generally stop functioning, swap enabled or not. The only question is how you want it to stop functioning when that happens. In almost every situation, I'll easily take the kernel killing whatever single process it thinks is most appropriate to…

You really need to learn more about swap. Start here: https://news.ycombinator.com/item?id=15952447

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#56
post #39

Nowadays linux has this thing called zram disk. It compresses data in memory on the fly. I think general swapping advice would serve most people better if they always add swap on zram first, before swap on ssd or hdd. The difference is that getting data in and out of zram is so fast that you can actually use it as a tier of a slower ram, transparently compressed.

Not exactly helpful.

Swap is vital in modern systems: https://news.ycombinator.com/item?id=15952447

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#57

I'm not going to disagree with the article, because I haven't done any testing myself that would suggest that the point made are wrong. I do however find it amusing to login to a system with 32 or 64GB of memory with a 2GB swap. It seems humorous that those 2GB should somehow do anything if you already used 64GB of RAM.

I can save you a bunch of testing time. Just enable swap (I typically peak at 34GB, but follow the `RAM + 2GB` rule-of-thumb before that

Here's a bunch of data that helps understand why swap is important: https://news.ycombinator.com/item?id=15952447

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#58

If you must use swap (you probably don't need to), then at least set zswap.enabled=1 in the kernel boot options, typically in grub. This will enable lzo compression of swap in memory so there is less writing to disk. Some newer kernels use lz4. Either way, what most folks are actually missing is the correct kernel settings for the amount of memory they have. Sadly, the kernel does not dynamically adjust these based o…

You probably do need swap.

Start here to know why: https://news.ycombinator.com/item?id=15952447

Re: Linux Performance: Why You Should Almost Always Add Swap Space

#60
post #47

System tuning is largely dependent on workload and use case. You can't just give a generic advice like this.

>System tuning is largely dependent on workload and use case

Yes, you can - and should - give general advice like this

Heres a whole host of reasons why you almost surely need/want swap: https://news.ycombinator.com/item?id=15952447

Post reply on HN