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).

  • Have you checked if your system can have more ram. Ram for older systems would be quite cheap. Just need to match new ram with what you have now.
    – crip659
    Nov 20, 2020 at 19:36

1 Answer 1


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.

  • 1
    It works in 20.04. I had Firefox opened. Then I created a large (12000x12000) random matrix in GNU Octave, and Octave was killed within 5 seconds. But it did not kill Firefox. Nov 20, 2020 at 19:09
  • 1
    This may be helpful: journalctl -a | grep -i "killed process" That will tell you what was killed and a bit more info.
    – KGIII
    Nov 20, 2020 at 20:17
  • "Yes Ubuntu 20.04 does." Does what? I know you go on to explain, but it's a pet peeve -- yes/no answers to questions that did not clearly establish a polarity of yes/no. It's quite common for questions to be stated in opposing alternatives, as here: "Will the machine freeze? Will Ubuntu (or the Linux kernel) intelligently close the programs consuming too much memory?" If you say "yes", please make it clear immediately what you're saying "yes" to.
    – nanoman
    Nov 21, 2020 at 6:58
  • It depends if the running out of memory is due to allocating actual memory to furfil an existing commitment, or to commit a new allocation. In the case of the second linux will fail to allocate memory and the process has to handle it. In the first case (which only happens if overcommit is enabled kernel.org/doc/Documentation/vm/overcommit-accounting, then it will kill something) Nov 21, 2020 at 14:35
  • I would guess the difference between 18.04 and 20.04 is the default settings for overcommit, but they can be changed by the user. Nov 21, 2020 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .