Live data from Hacker News

Linux Performance: Why You Should Almost Always Add Swap Space

haydenjames.io

101–110 of 120 posts

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

#101
post #49
post #25

Earlier quoted context omitted.

indeed on ubuntu 16.04 64bit, when my chrome has 20+ tabs, some new tab could trigger a memory thrashing, that uses up all the memory and eats up a few GB disk, cpu load jumps up to 10x, the computer basically becomes unusable. i would rather a OOM kill the chrome process in this case, it wastes less time on me, a re-open of chrome will keep all the histories anyways. also on embedded system where the RAM is fairly l…

>when my chrome has 20+ tabs That's not a swap problem, that's a Chrome problem.

It is a swap problem. Swap is supposed to make things work and not stop.

I suppose this is actually a problem of Linux optimistic malloc policy.

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

#102

Earlier quoted context omitted.

I don't want this to happen. On servers, in almost every situation, I'd rather have the server reboot than have some random process crash and leave the system in a potentially broken state. On desktops, in every situation, I'd rather have X, my window manager and an emergency terminal pinned to RAM so I can always decide what to kill for myself. ( https://github.com/stiletto/angrymlocker helps with setting this up.)

> I'd rather have the server reboot than have some random process crash and leave the system in a potentially broken state. Set the OOM killer to trigger a reboot? Crawling to a swapping halt is the worst of both worlds, it's like a full system crash but the server never comes back.

Set overcommit policy and malloc would just fail, which is handled in mysql and would abort the query instead of invoking oom killer.

And a crashing service should get restarted, involving journal file recovery which is consistent state.

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

#103
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 set vm.swappiness to 0 on my Fedora laptop. Meaning the kernel will only swap to save the system. I've been doing this for years and had no issues. Edit: Actually in recent kernels, which I am using, 0 means it's disabled. I was thinking of 1.

It does not help, just makes the problem appear later in a more dire way. Try overcommit settings instead.

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

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

Only slightly worse. Technically, kernel will sometimes swap out live executable code unless you set swappiness to 0. This makes performance completely unpredictable under load.

Kernel does not "expect" things, the defaults are just heuristics not failing to malloc past amount of ram you have. This causes all of the mentioned behaviour. Apps allocating too big RSS for instance, deferring GC and heap compaction too late causing kernel to unload executable code.

And once you really run out of RAM, even on fast SSD swap will kill any performance. Unless you're using only hugepages.

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

#105
post #74
post #64

Earlier quoted context omitted.

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.

Nope, I'm not off the mark. But nice try at deflecting your lack of understanding.

Please don't be uncivil on Hacker News, regardless of how much someone knows about swap.

https://news.ycombinator.com/newsguidelines.html

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

#106

Earlier quoted context omitted.

> I'd rather have the server reboot than have some random process crash and leave the system in a potentially broken state. Set the OOM killer to trigger a reboot? Crawling to a swapping halt is the worst of both worlds, it's like a full system crash but the server never comes back.

Set overcommit policy and malloc would just fail, which is handled in mysql and would abort the query instead of invoking oom killer. And a crashing service should get restarted, involving journal file recovery which is consistent state.

> Set overcommit policy and malloc would just fail, which is handled in mysql and would abort the query instead of invoking oom killer.

So many things depend on so many gigabytes of overcommit, that seems like a pretty bad way to go about it in the general case.

> And a crashing service should get restarted, involving journal file recovery which is consistent state.

I think you're agreeing with me with this sentence?

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

#107

I always see people caring way to much about the amount of swap space used and not enough about the swap activity going on. It isn't the amount of swap space that slows a system down but actual swapping in/out of memory pages. In vmstat you want to pay attention to the "si" and "so" columns and in your alerting/graphing you want to keep track of the values "pswpin" and "pswpout" in /proc/vmstat. If these are almost a…

I've been making the same point about pagefile size versus paging I/O for a couple of decades now, finally turning it into an FGA a decade ago. (-:

* http://jdebp.eu./FGA/dont-throw-those-paging-files-away.html

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

#108
post #95

Earlier quoted context omitted.

There have been many times, in 30 years, where I've been glad I've got swap enabled so I can recover a nearly-out-of-control production system in time, with the right procedures, instead of everything just being killed. Thats enough for me to turn it on. But, also, gigs of RAM is another must-do cargo-cult thing...

Did you do root cause analysis and did you make sure that same condition could never happen again or did you figure that since the swap file saved you that no further action was needed? The 'many times' has me worried.

Many times .. over 30 years. And yes, it was mostly due to bugs in the code, which I wouldn't have been able to assess if my machine had just OOM'ed everything. That's the point: swap gives you a little leeway for these analyses.

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

#109

Earlier quoted context omitted.

Thanks for the list of resources--I've been struggling to find good information about whether to use swap. A friendly suggestion: you obviously care a lot about this, and want to bring people around to your point of view. I think you'd be more effective at that, if you wrote this up as a blog post, or a github gist. Cite the relevant information from those links (or leave some of them as further reading). As it stand…

> with no idea what I'm getting out of it. Not a whole lot. I've looked at them and they are for the most part outdated, do not make the case for 'some swap' or are simply fluff to make the list look more impressive.

Half of them are older, half are new/current

In short, unless you really know you don't need it, you should be running it

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

#110

Earlier quoted context omitted.

what if if you increase your RAM after installing the system?

It's a circular argument that people get into because they have the incorrect kernel settings. Even if you have 4TB of ram, someone will say to add more memory on disk. It just means the system is not configured correctly. I have 30k servers and not a single one of them has swap.

>I have 30k servers and not a single one of them has swap.

Physical? VM? Cloud?

I've never seen an environment with more than a couple carefully-tuned machines that didn't run swap on every last one

Post reply on HN