A Linux server has 64 GB of RAM. Its monitoring dashboard shows plenty of memory available. Yet an application suddenly disappears, and the logs suggest that Linux killed it for running out of memory.
How can both things be true?
Because Linux does not always decide whether an application has enough memory by looking at the entire server. A process may be running inside a smaller, enforced memory boundary. Once that boundary is exhausted, the kernel can kill a process even while the machine has gigabytes of RAM available for other workloads.
This is especially relevant to Docker containers, Kubernetes workloads and systemd services. But there is an important complication: not every abrupt termination blamed on the Linux out-of-memory killer actually comes from the same mechanism.
The number on the dashboard describes the wrong boundary
Start with the familiar Linux command free -h.
It reports memory statistics for the operating system, including a value called available. The underlying kernel statistic, MemAvailable, estimates how much memory could be used to start applications without swapping. It considers free pages alongside some memory the kernel expects to reclaim.
That is generally more useful than looking only at completely unused RAM. Linux deliberately uses otherwise idle memory for caching files and other data.
But MemAvailable answers a system-wide question. It does not tell you how much additional memory a particular application is permitted to consume.
Linux control groups, usually called cgroups, provide the missing boundary. A cgroup collects processes into a resource-managed group. The kernel can enforce memory restrictions on that group independently of the machine’s total capacity.
For example, Docker documents a hard container memory limit, while Kubernetes explains how container memory limits are enforced through the Linux kernel.
The result is a server that has available RAM but a workload that has reached the maximum amount it is allowed to use.
Host reports 18 GiB MemAvailable.
A new memory charge approaches the hard limit. If the kernel cannot reclaim enough memory within the group’s constraints, it can invoke the OOM killer inside this cgroup.
The kernel tries to recover memory first
Reaching a limit does not mean Linux immediately kills an application.
On systems using cgroup v2, the important hard-limit setting is memory.max. The Linux kernel’s cgroup v2 documentation explains that when a group reaches this limit, the kernel attempts to reduce its memory usage. If the required memory cannot be reclaimed, the group’s out-of-memory mechanism is invoked.
Reclaim can involve discarding file-cache pages that are safe to reload later. Depending on configuration and available swap, other memory may be moved out of RAM. The kernel also needs to respect memory protections and other allocation constraints.
The critical question is whether the group can make enough space for the allocation that triggered the pressure.
Some workloads have little memory that can be reclaimed cheaply. A database might have a large active working set. A Python worker might retain growing data structures. A CPU-based AI inference service might keep model data and working buffers resident while additional requests increase memory demand.
For local AI specifically, this connects to a different issue explored in why a local LLM becomes slow when memory and execution resources are constrained. Long before a process is killed, reclaim and swapping may already be affecting its performance.
There is also a distinction between two cgroup settings that sound similar:
memory.high is a throttling boundary. Exceeding it causes additional reclaim pressure and can slow the workload, but crossing that boundary does not itself invoke the OOM killer. memory.max is the hard ceiling that can lead to a cgroup OOM kill when reclaim is insufficient.
One setting makes a workload struggle to progress. The other can end its execution.
Why did Linux choose that process?
When the kernel needs to kill something to recover memory, it does not simply select the process with the highest number in a system monitor.
Linux uses an OOM scoring mechanism that considers memory use relative to the resources available in the relevant OOM context. Administrators and service managers can influence selection through oom_score_adj.
The permitted adjustment ranges from -1000 to +1000. Higher adjustments make a process more attractive to the OOM killer; a value of -1000 protects it from OOM victim selection. These semantics are documented in the kernel’s /proc interface reference.
For a memory-cgroup OOM event, victim selection is confined to that cgroup. A process outside the exhausted group is not selected merely because it consumes more memory on the same host.
There is another possibility: a cgroup can be configured with memory.oom.group so that the kernel treats its processes as one workload during an OOM event. In that case, the group can be terminated together, subject to OOM-protected tasks.
This explains why an application with several workers may lose more than the individual process that triggered the allocation failure.
The evidence is usually still there
The most useful investigation begins with the boundary that contained the terminated application, rather than another snapshot of total server RAM.
On a cgroup v2 system, the relevant cgroup directory exposes several memory accounting files. When the process is running in a cgroup namespace whose mounted root represents the workload, these commands provide a useful starting point:
cat /sys/fs/cgroup/memory.max
cat /sys/fs/cgroup/memory.current
cat /sys/fs/cgroup/memory.events
On a host, locate the affected service’s actual cgroup directory instead. These paths are not universal for cgroup v1 or differently mounted hierarchies.
The first file reports the configured hard memory limit in bytes, or max if no hard limit is set at that level. The second reports current memory usage accounted to the group and its descendants.
Importantly, memory.current is not just the application’s heap size. The cgroup memory controller also accounts for categories such as file cache and certain kernel memory allocations.
The third file is particularly interesting because it contains event counters. Under cgroup v2:
highcounts events associated with crossing the high memory boundary.maxcounts occasions when memory usage was about to cross the hard limit.oomrecords qualifying out-of-memory conditions.oom_killcounts processes in the group killed by an OOM killer.
These counters do not all mean the same thing. A max event alone does not prove that Linux killed a process. The kernel may have successfully reclaimed memory and allowed the workload to continue.
In the default cgroup v2 reporting model, memory.events includes events from descendants. memory.events.local shows local events. Understanding that distinction matters when several services share a parent group.
For a convincing diagnosis, compare event counters over time, examine the affected cgroup and its ancestors, and correlate the results with kernel logs and the application’s termination time.
There is a timing trap here, too. A server showing available RAM five minutes after an application crashed does not establish its memory condition at the instant of failure. Once a process is terminated, the memory it held can be released, making the machine look healthy again.
An exit code of 137 does not settle the case
A terminated container often leaves behind exit code 137. In the common convention where a shell reports signal termination as 128 plus the signal number, this corresponds to SIGKILL, signal 9.
The Linux OOM killer sends SIGKILL to terminate victims. But it is not the only component capable of sending that signal.
An administrator, container runtime, service manager or orchestration system may also force a process to stop. Therefore, exit code 137 on its own is not proof that memory exhaustion caused the termination.
In Kubernetes, a container status reporting OOMKilled is much stronger evidence of a memory-related termination than the numeric exit code alone.
On systems that use systemd, another mechanism deserves attention: systemd-oomd.
This userspace service can monitor memory pressure using Linux pressure stall information, or PSI, as well as swap-related conditions. When configured thresholds are exceeded, it can select a cgroup and terminate its processes before the kernel reaches its own OOM decision.
The systemd-oomd documentation describes this behavior and the associated management controls. The oomctl utility can show monitored cgroups and pressure information when the service is available.
So a process can disappear because of a hard cgroup limit, system-wide memory exhaustion, or a userspace policy responding to sustained pressure. Linux can also face allocation constraints involving restricted NUMA nodes or memory policies, even when other physical memory exists.
The operating-system logs and the relevant resource configuration determine which explanation fits the incident.
Buying more RAM might change nothing
Suppose the server has 64 GiB of physical memory and a container is limited to 4 GiB.
Installing another 64 GiB in the machine does not automatically increase that container’s limit. If the application repeatedly exceeds its 4 GiB boundary and memory reclaim cannot resolve the pressure, the same failure can occur on a server with 128 GiB.
A legitimate workload that consistently requires more memory may need a higher limit, provided the host has sufficient capacity. But increasing limits without understanding actual consumption can merely move the pressure elsewhere. An application leak, uncontrolled concurrency or unnecessary caching still needs attention.
For an AI worker, avoiding a crash also has an application-level consequence. Memory held only by a terminated process is lost. A workflow must rely on persistent checkpoints or saved state if it needs to resume unfinished work. That problem is explored in what happens when an AI agent crashes halfway through a task.
When the cause is an enforced workload limit, the useful capacity is the memory available inside that limit, after accounting for the workload’s actual requirements and reclaim behavior. When the cause is global memory pressure or a systemd-oomd decision, the relevant evidence and remedy are different.
The server’s RAM total is only one part of the answer. To understand why Linux killed an application, you first have to establish which memory boundary was being enforced at the moment the process died.
Sources
- Linux Kernel Documentation — Control Group v2. Memory accounting, memory.max, memory.high, memory.events and group OOM behavior.
- Linux Kernel Documentation — The /proc Filesystem. MemAvailable and OOM victim-scoring interfaces.
- Docker Documentation — Resource Constraints. Container memory limits, swap and OOM behavior.
- Kubernetes Documentation — Resource Management for Pods and Containers. Enforcement of container memory limits.
- systemd Documentation — systemd-oomd. Userspace memory-pressure monitoring and process termination.







