I am running Ubuntu 16.04.1 LTS, with a 4.4.0-36 kernel. I don't think that this matters a lot though, because I've seen terrible kernel behaviour across many distributions/kernel versions.Consider the following starting point:My system has let's say 4GB of memory and a swap partition of 4GB.I am running a desktop environment with GNOME, a Browser and an IDE currently open.I'm doing some programming, and in the course of that, I introduce a bug which causes my program to allocate an infinite amount of memory.So far so good, this is a situation that I should recover from, right? Here's what I want to happen:My operating system realizes that the program that I wrote is rogue and not behaving correctly.It kills my program, possibly with a helpful debug or log messageI am able to resume my activitiesBut this is not what happens with a more or less default install of Ubuntu. what happens is this:The buggy program is allowed to run indefinitelyEventually, when all the physical memory is exhausted, the system starts swapping. As the buggy program claims more and more memory, all the pages of my desktop programs are pushed out to the swap. My hard drive ist starting to make very very scary sounds My user-interface becomes completely unresponsive. Clicks are registered minutes after they happened, mouse movement is often ignored.Any access to the machine effectively grinds to a halt. This includes changing virtual terminals, logging in via virtual terminals and logging in via SSH.If I do manage to somehow kill the offending program, not everything is fine. Far from it.All of the user interface and system services are now swapped out, and start to get slowly swapped back in to the physical ram. My hard drive is still going crazy at this point.It takes about 0.5 - 1 hour for my system to calm down. Rebooting the machine without pushing the reset button also takes forever.Who would have thought that something simple as running out of memory causes such a cataclysmic event?I have several questions:Who thought that using swap on a desktop system would be a good idea and why??Should I simply disable swap? What are the reasons not to?Is there a better way than disabling swapping? For example, is there a way to limit the swapping to the rogue program and retain my system services and user interface in physical memory?
OOM situations handled horribly - better to disable swap?
ubuntu;memory;swap;out of memory