4 ms·
I have 32GB Ram on Ubuntu 18.04. Can I just turn swap off? If I do, what's the worst that will happen?
by Waterluvian 7y ago
I have 32GB Ram on Ubuntu 18.04. Can I just turn swap off? If I do, what's the worst that will happen?
- devoply 7y agoOut of memory processes will be terminated automatically with only a message in the kernel log, i.e. dmesg.
- Beldin 7y agoWhat happens in case you have swap space and run out of memory?
- devoply 7y agosome stuff in your memory gets written to the swap page. https://en.wikipedia.org/wiki/Paging https://en.wikipedia.org/wiki/Paging
- pjc50 7y agoYour 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.
- Dylan16807 7y agoEven 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.
- serf 7y agoin 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.
- Waterluvian 7y agoFascinating. Maybe just as a part of the fingerprinting mechanism?
- paulcarroty 7y agoOf course, in any case if you have enough RAM for your tasks.
- mixmastamyk 7y agoI 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.
- stevekemp 7y ago"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..
- JustSomeNobody 7y agoDunno. Do you care about hibernating your system?
- jschwartzi 7y agoNot 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.
- JustSomeNobody 7y agoI 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.
- pfranz 7y agoRecent 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."
- blihp 7y agoYou 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.
- xorcist 7y agoOf 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.