title: What is the best way to prevent out of memory (OOM) freezes on Linux?
body: <p>Is there a way to make the OOM killer work and prevent Linux from freezing? I've been running Java and C# applications, where any memory allocated is usually used, and (if I'm understanding them right) overcommits are causing the machine to freeze. Right now, as a temporary solution, I added,</p>
  
  <pre><code>vm.overcommit_memory = 2
  vm.overcommit_ratio = 10
  </code></pre>
  
  <p>to /etc/sysctl.conf.</p>
  
  <p>Kudos to anyone who can explain why the existing OOM killer can't function correctly in a guaranteed manner,  killing processes whenever the kernel runs out of "real" memory.</p>
  
  <p><strong>EDIT</strong> -- many responses are along the lines of Michael's "if you are experiencing OOM killer related problems, then you probably need to fix whatever is causing you to run out of memory". I don't think this is the correct solution. There will always be apps with bugs, and I'd like to adjust the kernel so my entire system doesn't freeze. Given my current technical understandings, this doesn't seem like it should be impossible.</p>