Problem scenario
You go to /var/log/ for the program or application that is not working properly. You look for the word "error." You see HeapDumpOnOutofMemoryError or "OnOutOfMemoryError=kill -9" messages.
Or you get this error on the terminal that says "Errno::ENOMEM: Cannot allocate memory." How might you troubleshoot out of memory errors on Linux?
Solution
Possible solution #1
Add more memory, but be aware that this costs money. For a physical server you may need to purchase RAM. Resize your VM if you are using a VM. For resizing GCP virtual machines, see this posting. For upgrading AWS instances (aka servers), see this posting.
Possible solution #2
Add more swap space (aka virtual memory). See this posting if you do not know how. This solution involves losing available hard drive space. This solution will not increase the performance as much as possible solution #1.
Possible solution #3
You can use the top
or free -mh
commands to monitor memory usage. You could reproduce the problem while monitoring either of the above commands. This can help prove that you need more memory for the operations. You can then make the case, confidently, to your systems administrator or boss that you need a server with greater memory.
Possible solution #4
Has code been modified recently? Maybe there is a memory leak. This problem could be caused by memory leaks in an application. You may need to ask the programmer if the code could have been written with a flaw or if a systems administrator patched an OS that is not compatible with the current application. Some environmental variables can introduce problems.