What does Ubuntu do when all RAM gets used up and there's no swap?

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":

journalctl -a | grep -i "killed process"

dmesg and syslog will also show notifications from oom-kill

kernel: [{timestamp}] Out of memory: Killed process {id} ({name}) {process information} oom_score_adj:{number}

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:

Whenever your server/process is out of memory, Linux has two ways to handle that, the first one is an OS(Linux) crash and your whole system is down, and the second one is to kill the process (application) making the system run out of memory. The best bet for the second option is to kill the process and save the OS from crashing. In short, the Out-Of-Memory Killer is the process which is responsible for terminating the application to save the kernel from crashing, as it only kills the application and saves the entire OS from crashing. Let’s first discuss how OOM and works and how to control that, and later we will discuss how OOM Killer decides which application to kill.

Personal comment: "as it only kills the application" is probably wrong. I noticed it killed a process and not restart the mysql service.