Live data from Hacker News

Linux Performance: Why You Should Almost Always Add Swap Space

haydenjames.io

61–70 of 120 posts

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

#61
post #2

I'm sorry, but not a single reason was presented in favour of swap when you're 100% confident that you will not max out your RAM. Swap = completely useless slowdown if you have total control over your system. Better use ulimit to prevent processes with e.g. memory leaks from causing havoc.

Want reasoning? Here's a whole huge list: https://news.ycombinator.com/item?id=15952447

When it is the case in the overwhelming majority of cases that you should use swap, you should just use it.

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

#62
post #6

Earlier quoted context omitted.

The most compelling reason to enable at least some swap space is that the Linux kernel's memory handling algorithms can't cope with there being no swap. If you have no swap, then you will encounter stalls and OOMs even if you don't actually run out of memory. Adding even a tiny amount of swap prevents this from happening.

This sounds as if it is a serious issue and should be fixed. Is there a bug report about it?

It's not a serious issue at all. It's intentional.

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

#63
post #5
post #2

I'm sorry, but not a single reason was presented in favour of swap when you're 100% confident that you will not max out your RAM. Swap = completely useless slowdown if you have total control over your system. Better use ulimit to prevent processes with e.g. memory leaks from causing havoc.

Can you ever be 100% confident?

You can 100% be confident (except in a few very unusual use cases) that swap is important, yes.

https://news.ycombinator.com/item?id=15952447

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

#64
post #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

That is not a very helpful comment.

Anyway, the quote from the article I was responding to above was talking about using swap to handle a situation where you have insufficient RAM, so you're off mark.

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

#65

Swap isn’t needed at all in this age. It’s just there for people who can’t afford more RAM and therefore have to resort to hacky solutions like this.

>Swap isn’t needed at all in this age. It’s just there for people who can’t afford more RAM and therefore have to resort to hacky solutions like this.

Do you have anything that back that up? Because here's a solid list of many reasons why you need/want swap. Note the several reference to kernel documentation: https://news.ycombinator.com/item?id=15952447

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

#66

Earlier quoted context omitted.

What an absurd statement. Do you use a laptop? I do and I'm using swap space right now. I would like to buy a laptop with 32 or 64 Gigs of RAM but I can't as most(all?) laptop makers don't ship with a memory controller that permits more than 16 Gigs of RAM. And I can afford to buy more RAM.

What is the rule for setting swap size, or can I use just swap file just like on win/mac? (I heard it will disable hibernation then)

The basic rule is `RAM + 2GB`

I usually peak at 34GB, unless I have reason (like needing/wanting to enable full hibernation) to use 66GB, 130GB, etc.

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

#67
post #23

This is dangerous advice. At least on Ubuntu 16.04 with stock kernel running due to memory pressure into swap kills the systems. Basically everything times out and you can only hard-reboot. Without swap you have an OOM at least something you can recover from. If you need swap just add a little like 1-4gb - because if you have spinning disks 64gb swap won't help you at all because every request to swap is magnitudes m…

Sorry, but this is just patently not true.

See this list of many reasons why you're incorrect - https://news.ycombinator.com/item?id=15952447

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

#68
post #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

I don't think 2.6 kernel reasons are relevant anymore, in fact they apply to ram compression techniques better, than to old raw swap on disk.

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

#69

Interesting; Jeff Atwood of Coding Horror/Stackoverflow/Discourse forces swap creation as part of the installation of Discourse as a Docker container. He prefers slow performance to OOM. https://meta.discourse.org/t/create-a-swapfile-for-your-linu...

Pretty much all smart sysadmins want swap.

The kernel expects it, and performance is almost always worse without it.

https://news.ycombinator.com/item?id=15952447

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

#70
post #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

The reason those articles are suggesting swap is due to the settings I linked above that most people are missing. The kernel is not evacuating cache early enough and it gets wedged. Kernel devs even argue among themselves about this. A properly engineered system would never need swap, that much is for certain.

And if you must use it, then at least know when you need to encrypt your swap. If you have customer data in memory that is encrypted at rest, then you must encrypt your swap.

Some people use crypttab for this, but I think that is a mistake. Rather, people should have a swap volume or partition that on each system boot, you use cryptsetup with a long randomly generated password and mkswap -f, then swapon each time.

Most companies have policies about encrypting customer data. If you have swap, it plays into that policy.

Post reply on HN