News for hackers. Stuff that matters.
Re:Almost Always Add Swap Space by Waterluvian on Friday July 19, 2019 @11:44AM (#20479562)
I have 32GB Ram on Ubuntu 18.04. Can I just turn swap off? If I do, what's the worst that will happen?
Re:Almost Always Add Swap Space by blihp on Friday July 19, 2019 @01:01PM (#20480423)
You can absolutely turn it off. I've been running with swap turned off on all of my desktop systems (Linux, Unix and Windows), and some servers, for over 20 years.

The theoretical worst case scenario is that the system hits an OOM situation and you end up with data/filesystem corruption... I have not had this occur due to swap being turned off this century.[1] The typical worst case scenario is that either due to a runaway process or accidentally overloading the system for a indefinite period of time, the system goes completely unresponsive so you have to perform a hard reboot. This happens to me 1-2 times a year but I have yet to loose any data (and if it ever does, that's one of the many reasons to have backups) The more common scenario is that a runaway process will OOM briefly, when it can't allocate the memory it needs crash, and everything is back to normal within a couple of seconds.[2]

FWIW, mobile (Android and iOS) devices typically run without swap just fine. IMO, this 'always enable swap' is bad advice and dates from a time when very bad things could and did happen if you OOM'd a system. The marginal performance improvement from freeing up on the order of megabytes (or even tens of megabytes) of RAM on a system with double digit GB's of RAM makes absolutely no sense to me. It makes even less sense on SSD systems where you would be unlikely to notice a chronic swapping situation until you had severely shortened the life of your SSD.

[1] This would be a good reason to not turn off swap on a production database server where it is more likely to be an issue, for example.

[2] One of the dubious advantages to 'modern' programs not handling errors like OOM is that, since they don't check for it, they can't handle when it happens and just crash. This was actually more of a problem in the 90's and earlier when it was more common for applications to handle OOM situations which could actually make the problem worse since they would often hang around waiting for any memory to be freed and use it which resulted in a persistent OOM situation.

Re:Almost Always Add Swap Space by mixmastamyk on Friday July 19, 2019 @12:27PM (#20480013)
I haven't used swap for decades now. Does it make sense for you? Depends on whether you exceed the physical amount of RAM in your machines often. Personally only when a bug occurs, and I’d rather the process was killed.
Re:Almost Always Add Swap Space by stevekemp on Friday July 19, 2019 @12:28PM (#20480034)
"It depends".

I'd suggest trying it and seeing what happens, if you wish to learn rather than listen to people who aren't using your host - and don't know what you run..

Re:Almost Always Add Swap Space by serf on Friday July 19, 2019 @11:49AM (#20479608)
in a sane OS? Nothing until you run out of ram.

In a Microsoft OS? Depends on the app -- some are dependent (many games) on having swap available (and may err silently or under false pretenses without one).

I've found that a lot of MMO style games include cheat detection systems (see : rootkit) that rely on swap, and fail without it. As to why they do that, i'm unsure.

Re:Almost Always Add Swap Space by Waterluvian on Friday July 19, 2019 @11:53AM (#20479635)
Fascinating. Maybe just as a part of the fingerprinting mechanism?
Re:Almost Always Add Swap Space by devoply on Friday July 19, 2019 @11:45AM (#20479575)
Out of memory processes will be terminated automatically with only a message in the kernel log, i.e. dmesg.
Re:Almost Always Add Swap Space by Beldin on Friday July 19, 2019 @11:58AM (#20479697)
What happens in case you have swap space and run out of memory?
Re:Almost Always Add Swap Space by pjc50 on Friday July 19, 2019 @03:23PM (#20481682)
Your system thrashes to a halt, until eventually you run out of swap as well and the OOM killer is activated anyway. It just takes longer and is preceded by a period of dismal performance.
Re:Almost Always Add Swap Space by Dylan16807 on Saturday July 20, 2019 @01:08AM (#20484290)
Even without swap, you get a period of thrashing and dismal performance as your disk cache is squeezed to nothing.

If you have swap, this happens later and more gradually, and lasts longer before the OOM killer kicks in.

Re:Almost Always Add Swap Space by devoply on Friday July 19, 2019 @12:03PM (#20479745)
some stuff in your memory gets written to the swap page.

https://en.wikipedia.org/wiki/Paging

Re:Almost Always Add Swap Space by xorcist on Friday July 19, 2019 @06:46PM (#20483071)
Of course you can, but performance can be a bit lower since less memory will be available for file system buffers. Most mainstream applications isn't very careful with their memory usage. It will depend on your use case.
Re:Almost Always Add Swap Space by paulcarroty on Friday July 19, 2019 @12:10PM (#20479823)
Of course, in any case if you have enough RAM for your tasks.
Re:Almost Always Add Swap Space by JustSomeNobody on Friday July 19, 2019 @12:29PM (#20480052)
Dunno. Do you care about hibernating your system?
Re:Almost Always Add Swap Space by jschwartzi on Friday July 19, 2019 @01:36PM (#20480757)
Not OP, but I don't. Hibernating and Sleeping my systems always causes massive problems for me, and I'd rather just shut down and start up really fast.

For example on my current laptop if I hibernate or sleep the system the USB fails to initialize in Windows until I power-cycle. I think this is mainly due to me having about 10 or 15 USB devices plugged in via hubs and USB ports. But that's not the norm.

I've also got 64 GB of ram and a pretty decent pair of NVMe SSDs so read speed isn't really a limiting factor for startup time.

Re:Almost Always Add Swap Space by JustSomeNobody on Friday July 19, 2019 @02:14PM (#20481108)
I agree, hibernate isn't the most stable thing in world. My work machine is a Windows laptop with a regular ssd so I usually hibernate it and about 1 in 20 times it forgets either BT, network card or wifi. I have a NUC8 running ubuntu for one of my personal machines and have a NVMe and I shut that down because, as you mentioned, the speed is there.
Re:Almost Always Add Swap Space by pfranz on Friday July 19, 2019 @04:33PM (#20482212)
Recent Windows seems especially horrible about this. Personally, my workstation seems to forget which output to send video to and fails to properly wake up my USB wifi adapter. A tech I recently spoke to said, "Windows 10? Yeah, it seems to have way more problems. I just suggest disabling sleep."