Inferensys

Glossary

Out-of-Memory (OOM) Killer

The Out-of-Memory Killer is a Linux kernel process that selects and terminates applications to free memory when the system is critically low, preventing a complete system crash.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
SYSTEMS MEMORY MANAGEMENT

What is the Out-of-Memory (OOM) Killer?

A critical Linux kernel process that terminates applications to prevent total system failure during severe memory exhaustion.

The Out-of-Memory (OOM) Killer is a Linux kernel mechanism that automatically selects and terminates one or more processes when the system is critically low on available memory, aiming to free resources and keep the core operating system functional. It activates as a last resort when all other memory reclamation efforts, such as flushing disk caches and swapping, have failed to prevent an imminent kernel panic. The selection algorithm typically targets the process consuming the most memory with the lowest priority, calculated via an adjustable oom_score.

In GPU-accelerated machine learning environments, the OOM Killer is a critical failsafe that can terminate a model inference or training job if it exhausts both GPU and system memory, especially when using unified memory or memory oversubscription. Systems engineers mitigate its disruptive action by configuring memory cgroups to impose hard limits, adjusting process oom_score_adj values, and ensuring adequate swap space. Its intervention, while preserving system stability, causes immediate job failure, making proactive memory monitoring essential for production ML workloads.

LINUX KERNEL MECHANISM

Key Characteristics of the OOM Killer

The Out-of-Memory Killer is a last-resort process in the Linux kernel designed to prevent a complete system crash by terminating one or more processes when available memory is critically exhausted.

01

Triggering Condition

The OOM Killer activates when the system faces a critical memory shortage and cannot satisfy an allocation request, even after the kernel has exhausted all other memory management techniques. This includes:

  • Aggressive swapping to disk (if swap is enabled and not full).
  • Dropping clean page caches and reclaimable slab objects.
  • Compacting memory.

When these measures fail, the kernel invokes the OOM Killer to free memory by force, preventing a kernel panic.

02

Selection Algorithm (oom_score)

The kernel selects a victim process using a heuristic badness score (oom_score). This score, visible in /proc/[pid]/oom_score, is calculated based on multiple factors to identify the 'best' process to kill:

  • Memory Usage: The primary factor. Processes using more memory, especially resident set size (RSS), receive higher scores.
  • Process Lifetime: Long-running daemons and critical system processes are penalized with lower scores.
  • User Privileges: Root-owned processes typically have their score adjusted to be less likely targets.
  • CPU Time: Processes that have consumed significant CPU time may be penalized.
  • OOM Score Adjustment (oom_score_adj): A user-settable value from -1000 to +1000 that directly shifts the final score, allowing administrators to protect critical processes or mark others as preferred victims.
03

Impact on ML/GPU Workloads

In machine learning inference servers, the OOM Killer poses a significant risk, often terminating the very process managing the GPU. Key failure scenarios include:

  • Host Memory Exhaustion: A large language model inference engine, like vLLM or TensorRT-LLM, may allocate substantial host memory for request queues, tokenizers, and communication buffers. If this exhausts system RAM, the kernel may kill the inference server process.
  • Indirect GPU Memory Pressure: While the OOM Killer doesn't directly manage GPU memory, system memory is used for GPU driver control structures, pinned memory for DMA, and Unified Memory pages. Exhausting system memory can cripple GPU operations.
  • Cascading Failures: Killing a critical orchestration process (e.g., a Kubernetes pod manager) can lead to uncontrolled restarts and service disruption.
04

Configuration and Mitigation

System administrators and ML Ops engineers can configure the OOM Killer's behavior to protect critical services:

  • oom_score_adj: Set this to -1000 for essential processes (e.g., the inference server, monitoring agent) in a container's spec.containers[].resources.limits.oomScoreAdj or via echo -1000 > /proc/[pid]/oom_score_adj.
  • Memory Cgroups (Control Groups): The primary modern defense. By placing workloads in cgroups with strict memory limits (memory.limit_in_bytes), you ensure a single container's memory exhaustion triggers a cgroup-specific OOM kill, isolating the failure and protecting the host system.
  • Disabling the OOM Killer: Setting vm.overcommit_memory = 2 and providing ample swap can make the kernel refuse allocations rather than invoke the killer, but this often causes application-level failures instead.
  • Monitoring: Tools like dmesg and the system log (/var/log/syslog) capture OOM Killer events, showing the killed process's PID and its oom_score.
05

Relation to GPU Memory Management

The Linux host OOM Killer is distinct from, but interacts with, GPU-level memory management:

  • Separate Domains: The OOM Killer operates on system (host) RAM. GPU device memory (VRAM) is managed by the GPU driver and runtime (e.g., CUDA). A GPU-side out-of-memory error (cudaErrorMemoryAllocation) is a different event handled within the application.
  • Unified Memory Pressure: When using Unified Virtual Memory (UVM), pages can migrate between host and GPU memory. Severe host memory pressure can stall these migrations, indirectly affecting GPU performance and potentially leading to host OOM conditions.
  • Pinned Memory Overhead: Allocating large amounts of page-locked (pinned) host memory for fast GPU transfers reduces the pool of swappable memory for the OS, increasing the risk of triggering the OOM Killer for other processes.
06

Best Practices for Inference Serving

To prevent the OOM Killer from disrupting production model serving:

  1. Set Explicit Limits: Always use memory cgroups (via Kubernetes resources.limits.memory or Docker -m) to enforce hard boundaries on container memory usage.
  2. Monitor Memory Trends: Use profiling tools to understand the resident set size (RSS) of your inference server, not just its GPU memory allocation.
  3. Size Host Memory Appropriately: Ensure the physical host has sufficient RAM for the OS, monitoring tools, and the inference engine's host-side overhead (often 20-30% beyond model weights).
  4. Tune Swappiness: Adjust vm.swappiness to a lower value (e.g., 10) to make the kernel prefer caching over swapping, but be aware this can make the OOM Killer activate sooner.
  5. Implement Graceful Degradation: Design your inference service to handle memory pressure signals (e.g., listening for SIGKILL or monitoring cgroup pressure) and shed load or queue requests before a forced termination occurs.
MECHANISM

How the OOM Killer Works: The Selection Algorithm

The Out-of-Memory Killer's core function is to select a victim process for termination. It does not act randomly but uses a deterministic scoring algorithm to minimize system disruption.

The kernel calculates an OOM score for each eligible process, stored in /proc/[pid]/oom_score. This score is derived from the process's oom_score_adj value (a user-configurable adjustment from -1000 to 1000) and an internal heuristic. The heuristic heavily weights the process's resident memory usage and CPU time, favoring long-running, memory-intensive processes. Child processes typically inherit and contribute to the parent's memory footprint in this calculation.

The process with the highest OOM score is selected for termination. The kernel sends it a SIGKILL signal, which the process cannot catch or ignore. After termination, all the process's memory is reclaimed by the kernel. The algorithm may run multiple times if the initial kill does not free sufficient memory. In containerized environments like Docker, the OOM Killer operates within the memory cgroup of the offending container, targeting processes inside it first.

REACTIVE VS. PREVENTATIVE

OOM Killer vs. Proactive Memory Management

A comparison of the reactive Linux kernel OOM Killer mechanism against proactive software techniques for managing GPU memory pressure in machine learning inference workloads.

Feature / MetricOOM Killer (Reactive)Proactive Memory Management (Preventative)Ideal Hybrid Approach

Core Mechanism

Terminates processes post-OOM

Pre-allocates pools, monitors usage, swaps/caches data

Combines monitoring with graceful degradation & fallback

Trigger Condition

System-wide memory exhaustion

Predefined high-watermark (e.g., >85% GPU memory used)

Configurable thresholds with multiple escalation levels

Impact on ML Inference

Process kill causes request failure, lost context, job restart

Controlled performance degradation (increased latency)

Minimal latency impact until severe pressure, then managed fallback

Determinism & Predictability

Non-deterministic; uses oom_score heuristics

Highly deterministic based on configurable policies

Policy-driven with predictable failure modes

Data Loss Risk

High (in-flight requests and model state lost)

Low (state preserved via caching/checkpointing)

Very Low (state checkpointed before pressure triggers)

Typical Latency Added

N/A (catastrophic failure)

5-15% (for swapping/cache management)

<5% (optimized pooling & prefetching)

Implementation Complexity

Kernel-default; no app code required

High (requires integration into app/model server)

Moderate-High (requires policy engine & integration)

Best For

General-purpose systems, last-ditch safety net

Mission-critical, high-availability ML inference services

Production ML serving where cost control & reliability are paramount

GPU MEMORY OPTIMIZATION

Frequently Asked Questions

The Out-of-Memory (OOM) Killer is a critical Linux kernel process that terminates applications to prevent system-wide crashes during severe memory exhaustion. These questions address its operation, impact on AI workloads, and mitigation strategies for production systems.

The Out-of-Memory (OOM) Killer is a process within the Linux kernel that automatically selects and terminates one or more running processes when the system is critically low on available memory, aiming to free resources and keep the kernel operational.

Its operation follows a deterministic algorithm:

  1. The kernel continuously monitors memory pressure. When available memory and swap space fall below a critical threshold, the OOM killer is invoked.
  2. It evaluates all running processes and assigns each an OOM score (oom_score visible in /proc/[pid]/). This score is calculated based on the process's memory consumption, runtime, process niceness (nice value), and whether it runs as a privileged user (root).
  3. The process with the highest OOM score is selected for termination. The kernel sends it a SIGKILL signal (signal 9), which immediately terminates the process without allowing it to clean up.
  4. The memory held by the terminated process is reclaimed by the kernel. If memory pressure remains critically high, the OOM killer repeats the process.

The primary goal is to prevent a complete system lockup or kernel panic by sacrificing specific processes to preserve overall system stability.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.