🇫🇷 New VPS location: Marseille, where Europe meets Africa and Asia. 50% off 2 months on any Linux VPS plan with BONJOUR50 Deploy in Marseille →

Solving OOM Errors: Essential Tips for Memory Management

Glowing brain icon on a microchip surrounded by circuitry, symbolizing artificial intelligence and technological advancement.

If you’ve ever encountered the frustrating “OOM Killed Your Process” error in your logs, you’re not alone. This error indicates that your application has been terminated due to insufficient memory, a common issue for many users. In this article, we’ll explore the causes of this error, provide practical solutions, and explain why in this precise case, OpenVZ users might benefit from switching to KVM VPS providers.

In short: an OOM (out-of-memory) error means the Linux kernel ran out of RAM and swap, so its OOM killer terminated a process to keep the system running. Confirm it in the kernel log, find which process grew, then fix the cause: a memory leak, too little RAM or swap, or a service with no memory limit.

đź’Ą Processes killed for lack of memory on an oversold VPS?
Move to KVM4: your own kernel and 4 GB of ECC RAM that no neighbour can borrow
âś“ 4 vCores  Â·  âś“ 4 GB ECC RAM  Â·  âś“ 40 GB NVMe  Â·  âś“ Unmetered 1 Gbps  Â·  âś“ Full root access  Â·  $40/mo

What is an OOM Killed Process Error?

Out-of-Memory (OOM) errors occur when a process tries to use more memory than is available on the system. The operating system responds by killing the process to prevent the entire system from crashing. This can happen for several reasons, including memory leaks, high memory usage, insufficient system memory, and multiple concurrent processes consuming excessive memory.

How Does the Linux OOM Killer Work

When the system’s memory is critically low, the OOM Killer is triggered to free up memory by terminating one or more processes. It selects the process to kill based on a set of criteria, including the amount of memory each process is using and its importance to the system. Processes with high memory consumption or those that are less critical are more likely to be terminated. This helps to ensure the stability of the system by preventing a complete crash due to memory exhaustion.

To confirm that the OOM killer stopped your process, search the kernel log. Each match names the killed process, its PID and how much memory it was using:

sudo dmesg -T | grep -i "killed process"
sudo journalctl -k | grep -i "out of memory"

Understanding the common reasons behind OOM (Out-Of-Memory) killed processes can help you effectively prevent and troubleshoot this issue.

Common Reasons Leading to Killed Processes

Understanding the common reasons behind Out-Of-Memory (OOM) killed processes can help you prevent and troubleshoot this issue effectively. Below are the key causes along with explanations and the Linux commands to diagnose them.

Memory Leak

A memory leak occurs when your application keeps consuming memory without releasing it, gradually increasing its memory footprint and eventually exhausting the available memory.

To troubleshoot a memory leak, we use Valgrind, a powerful tool for memory debugging, leak detection, and profiling. Valgrind runs your program in a virtual machine, monitoring memory usage to help identify and fix memory leaks.

First, you would need to install Valgrind:

sudo apt-get install valgrind   # For Debian-based systems
sudo yum install valgrind       # For Red Hat-based systems

Then, once installed you may run it for a given application to obtain detailed information about its RAM usage. 

valgrind --leak-check=yes ./your-application

This command runs your application under Valgrind, providing detailed reports on memory usage and any detected leaks.

High Memory Usage

Some applications are inherently designed to use large amounts of memory, which can exceed the system’s available memory, leading to OOM errors. 

To identify high memory usage, we use the top command, which sorts running processes by memory usage. This helps in pinpointing processes consuming large amounts of memory so you can optimize or limit their usage.

top -o %MEM

This command sorts processes by memory usage, allowing you to identify those consuming excessive memory.

Insufficient System Memory

If your system does not have enough physical memory to meet the demands of your application, it can result in OOM errors as the system struggles to allocate the required memory.

To check available system memory, we use the free command, which displays the amount of free and used memory in megabytes. This helps determine if your system has sufficient memory for your applications.

free -m

This command shows the amount of free and used memory, helping you decide whether to upgrade memory or optimize usage.

Too Many Concurrent Processes

Running multiple processes simultaneously can collectively consume excessive memory, pushing the system beyond its memory limits and triggering the OOM killer.

To manage concurrent processes, we use the ps command, which lists all running processes and sorts them by memory usage. This helps in identifying multiple processes consuming excessive memory collectively.

ps aux --sort=-%mem

This command lists and sorts running processes by memory usage, aiding in process management and optimization to prevent OOM errors.

Solutions to OOM Errors

By identifying and addressing the previous common issues, you can enhance the stability and performance of your applications. However, here are ways to go even further. 

Increase System Memory

Probably the easiest solution of all: give the system more memory (on a VPS, upgrade to a plan with more RAM).

Alternatively you can use swap space to extend available memory temporarily using the disks. (recommended to have SSD VPS over HDD). 

To create a 4 GB Swap Space, here is how to proceed:

sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

These commands only last until the next reboot. To keep the swap file, add it to /etc/fstab:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Adjust System Parameters from Kernel

Adjusting system parameters can optimize memory management and protect critical processes from being killed by the OOM killer.

  1. Configure oom_score_adj: These settings adjust the priority of processes, helping to protect important processes from being terminated when memory is low.
  2. Adjust Overcommit Settings: Tuning the system’s overcommit memory settings helps manage how the system allocates memory, balancing between performance and stability.

Here is how to proceed: 

First, start by protecting critical process from being killed by the OOM Killer. You can get the <pid> from the ‘ps aux’ command. 

echo -1000 | sudo tee /proc/<pid>/oom_score_adj

For information (values from the Linux kernel documentation; the older oom_adj file, -17 to +15, is only kept for backward compatibility):

  • -1000: This value protects the process from being killed by the OOM killer. It effectively tells the OOM killer to ignore this process, so keep it for truly critical services.
  • 0: The default value, where the process has a normal chance of being killed based on its memory usage.
  • 1000: This value makes the process a prime candidate for being killed by the OOM killer.

Then, if you would rather see memory allocations fail cleanly than have processes killed, switch to strict overcommit (mode 2). The ratio is the share of physical RAM, on top of swap, that programs may commit, and it only applies in mode 2 (kernel overcommit documentation; the default ratio is 50). Mode 1, “always overcommit”, does the opposite and makes OOM kills more likely.

sudo sysctl -w vm.overcommit_memory=2
sudo sysctl -w vm.overcommit_ratio=80

Monitor and Manage Processes

Regularly monitoring and managing processes can help identify and address memory issues before they lead to OOM errors.

Use monitoring tools. top, htop, free and vmstat give real-time insight into memory usage, helping you track and manage resources effectively. A few useful commands:

top
htop
free -m
vmstat

Set resource limits. Cap a single process with ulimit, or a whole service with cgroups. On systemd servers, MemoryMax= in the service’s unit file (for example MemoryMax=1G) does this for you: when the service hits its cap, the OOM killer acts inside that service only instead of picking another process on the server (systemd documentation). For a shell session:

ulimit -v <max-virtual-memory>

Additional Challenges in Shared Kernel Environment

While the above solutions can help mitigate OOM errors, OpenVZ, Virtuozzo or even LXC VPS users may face additional challenges. 

These virtualization technologies use a shared kernel architecture, meaning that all VPS instances on a host node share the same kernel and, to some extent, the same memory. This can lead to unpredictable memory allocation and OOM errors caused by other users on the same node.

Overselling RAM is common with OpenVZ providers. It is not necessarily a bad practice when done carefully, but when a node is oversold too far, OOM errors become frequent.

In a nutshell, a KVM VPS avoids this problem:

  1. Dedicated Resources: KVM (Kernel-based Virtual Machine) provides dedicated resources, ensuring that your VPS has its own allocated memory and CPU.
  2. Isolated Environment: Each KVM VPS runs its own kernel, providing better isolation and stability.
  3. Customizable Kernel: You can modify and optimize the kernel to better suit your application’s needs.
  4. Enhanced Performance: KVM generally offers better performance due to the dedicated resources and reduced overhead.

Conclusion

OOM errors can be a significant hurdle, but with the right strategies, they can be managed effectively. For OpenVZ users, switching to a KVM VPS provider can provide greater stability and performance, reducing the likelihood of OOM errors caused by shared resources. 

By optimizing memory usage, monitoring processes, and adjusting system parameters, you can minimize the impact of OOM errors on your applications.

Naturally, there are as many situations as there are VPS configurations, and it is impossible to predict every scenario. However, this article provides a great starting point for troubleshooting your specific situation.

Last verified October 2026: oom_score_adj values and overcommit modes against the Linux kernel documentation, MemoryMax against the systemd documentation.

Facebook
Twitter
LinkedIn

Table of Contents

Get started today

With VPS.US VPS Hosting you get all the features, tools

Image