Suppose I turn off swap, and all RAM gets used up. What will happen?
Will the machine freeze? Will Ubuntu (or the Linux kernel) intelligently close the programs consuming too much memory?
Background: I have an old desktop with 3 GB RAM, which works smoothly with Xubuntu 20.04. When I open many tabs in Firefox and some large PDF files simultaneously, about 2.4-2.5 GB RAM is utilized, and about 700-800 MB of swap space is used. However the desktop interface becomes somewhat slow to respond, and sometimes becomes unresponsive while loading RAM -> swap.
It again becomes responsive when I close some of these softwares and run the command sudo swapoff -a && sudo swapon -a
, so that the content of swap is loaded back into RAM.
I found that the system does not become slow to respond when swap is turned off before opening such programs (I was careful so not to consume all the RAM).
I want to know whether there can be any severe issue if I turn off the swap permanently and all RAM is used up. Of course, I would try to ensure that it does not happen. However, I would prefer to use a faster system (while being careful not to open too many programs simultaneosly), rather than using a slower system with a larger effective memory (physical RAM + swap).
Ubuntu 20.04 kills a process.
I noticed it myself on a new GCE 20.04 server: I got a notification one of our instances was acting up and before I could log into it Ubuntu had already killed one of 9 MySQL processes. After some investigation it was the one consuming more than 70% of the memory of the server.
This will give you information about "killes processes":
dmesg
andsyslog
will also show notifications fromoom-kill
I did not see that happen in 18.04 or older versions. The server would just stay slow until I killed a process myself. This works on processes, not when you hibernate/suspend: that will require swap and if there is not hibernate/suspend won't work
Story on out of memory killer:
Personal comment: "as it only kills the application" is probably wrong. I noticed it killed a process and not restart the mysql service.