4 ms·
If you don’t hibernate or other reasons to use swap, what does adding half a gig of swap do that adding that as extra ram doesn’t? Or more practically, if I’m
by dkersten 7y ago
If you don’t hibernate or other reasons to use swap, what does adding half a gig of swap do that adding that as extra ram doesn’t?
Or more practically, if I’m doing stuff with 8gigs and then I upgrade to 16gigs of ram, then why would I need to keep my 512mb of swap? Surely the extra 8gigs comfortably covers that extra room? Am I missing something?
- masklinn 7y ago> If you don’t hibernate or other reasons to use swap, what does adding half a gig of swap do that adding that as extra ram doesn’t? Linux (and generally most popular OS) really don't like having no swap whatsoever (https://lkml.org/lkml/2019/8/4/15 https://lkml.org/lkml/2019/8/4/15). Plus if you're running out of RAM (regardless of how much you have, sure put more in if you have it) the system starts visibly degrading but remains recoverable when it starts swapping. If it can't swap, it pretty much just dies.
- dkersten 7y ago> If it can't swap, it pretty much just dies. The point with my example was that if 512 MB of swap would save you, then why wouldn't 8 GB of extra RAM save you? Yes, if you run out of RAM, you're in trouble, but if you run out of RAM+swap you're in trouble too, so what's the point in adding a small 256 or 512 MB swap? Ok, so the point is that its visibly bad with swap before it actually dies, giving you time to recover. How about setting up some kind of alert when you're in your last half a gig or gig of RAM then? It seems like this would give a much better recovery experience. If its a server, you need an alert anyway since you're not going to notice the bad performance until its too late, most likely (you're not watching it 24/7 I assume). Of course, from the article: > I stand by my original position: have some swap. Not a lot. Just a little. Linux boxes just plain act weirdly without it. That's fair enough, if the reason is to stop linux from acting weirdly, then fine.
- masklinn 7y ago> The point with my example was that if 512 MB of swap would save you, then why wouldn't 8 GB of extra RAM save you? Having 8 GB more RAM might avoid the issue, but it won't visibly degrade the system so you will not see that you're in trouble. And again if you can have both, have both. > Yes, if you run out of RAM, you're in trouble, but if you run out of RAM+swap you're in trouble too, so what's the point in adding a small 256 or 512 MB swap? Because if you run out of RAM and have no swap, the system dies. If you run out of RAM and have swap, it starts swapping, which is noticeable. > How about setting up some kind of alert when you're in your last half a gig or gig of RAM then? It seems like this would give a much better recovery experience. If its a server, you need an alert anyway since you're not going to notice the bad performance until its too late, most likely (you're not watching it 24/7 I assume). If it's a server you need to do that anyway because the swapping will probably not be noticeable.
- isostatic 7y ago> Because if you run out of RAM and have no swap, the system dies. If you run out of RAM and have swap, it starts swapping, which is noticeable. Only if you're using the system, or are reacting to monitoring (if you can monitor it and the thing you're monitoring fails) fast enough I'd rather have a dead system than one that's not working But in any case shouldn't OOM killer come to the rescue?
- dkersten 7y ago> But in any case shouldn't OOM killer come to the rescue? Indeed. Its similar to the argument that segfaults are good due to fail fast. Wouldn't it be better to fail fast due to OOM than to hobble along? If you're actively using the system, ok, you might get a chance to save your work or whatever first, but, in my personal anecdotal experience, that process is pretty much dead anyway and I have to kill it. Yes, my system doesn't get taken down, but if OOM takes the system down, why isn't the kernel killing the process that's eating all the memory? It sounds to me that swap is just masking the problem.
- masklinn 7y ago> I'd rather have a dead system than one that's not working A swapping system is degraded, not "not working". > But in any case shouldn't OOM killer come to the rescue? The OOM killer will heuristically kill random crap. It could be the process with an unbounded memory growth, or it could be your text editor.
- alexanderchr 7y agoI think the point is that you want to know when you are approaching the limit so that you can start shutting down things instead of having your system crash on you.
- dkersten 7y agoHave an alert trigger when your RAM gets low? On desktop systems, I've literally never had any problems where I wasn't already aware that my RAM was low (and therefore made sure I saved my work etc) and on servers, I'm not watching them 24/7, so need alerting anyway. A tiny amount of swap only buys you a tiny amount of time.