Skip to content

LLM Inference OOM and Crash-Loop Recovery

When a production inference service dies, the worst reflex is to tweak flags at random. This note splits the failure by the moment the process disappears: exits at startup, gets killed under load, KV cache exhaustion, and crash loops. Each branch starts with one command that confirms it, then gives the smallest fix. I have watched a vLLM worker die silently when VRAM filled up, and I once raised gpu-memory-utilization to 0.99 and got more restarts, not fewer. Get the branch right first, then the flags matter.

60 seconds: decide which moment the service dies at

Run these three in order; the output almost always maps to one branch.

# 1. Is the process alive, and who killed it? (systemd units and kernel logs live here)
dmesg -T | grep -i "killed process" | tail -5

# 2. Host memory pressure (host OOM lives here)
free -h && cat /sys/fs/cgroup/memory.max 2>/dev/null

# 3. VRAM and engine state (VRAM OOM and KV cache live here)
nvidia-smi --query-gpu=memory.used,memory.total --format=csv
curl -s http://localhost:8000/metrics | grep -E "gpu_cache_usage|num_requests_running"
  • A Killed process line in dmesg means host or cgroup OOM: branch 1 or 2.
  • Clean dmesg but pegged VRAM means VRAM OOM or KV cache: branch 3.
  • Process alive and logs show 507 or no available slot: also branch 3, at the request level this time.
  • systemctl status showing repeated start failures means a crash loop: branch 4.

The four branches as a tree (land on the moment first, then drill into the branch):

Service is down
|
+-- dies within seconds of start (Killed, no traceback)
|   +-- dmesg shows OOM .........-> host memory OOM -> check weight peak / cgroup cap
|   \-- dmesg clean, VRAM pegged --> VRAM OOM -> clear stale procs, cut max-model-len
|
+-- batch 500s under load, then dies (status=9)
|   +-- cgroup usage near memory.max -> cut max-num-seqs / raise cgroup cap
|   \-- flat water level, still killed -> memory leak -> pmap for an RSS breakdown
|
+-- process alive, requests intermittently 507 / no available slot
|   +-- gpu_cache_usage_perc >0.95 for a while -> cut max-model-len / raise utilization
|   \-- already at 0.95 yet restarts more -> too tight -> pull back to 0.85-0.90
|
\-- start -> healthy -> crash, on repeat (sawtooth curve)
    +-- mostly Killed -> back to branch 1/2, the loop is only the symptom
    \-- killed at a fixed 60-90s -> health check start-period too short -> raise to 1.5x load time

Branch 1: dies at startup (process vanishes within seconds)

Symptom: systemctl start vllm flips back to failed after a few seconds with Killed as the last log line and no Python traceback. No traceback means the OS did it, not your code.

journalctl -u vllm --since "10 min ago" | tail -50
dmesg -T | grep -iE "out of memory|killed process"
python3 -c "import psutil;print(psutil.virtual_memory())"

How to branch further:

  • Killed right after Loading model weights: the weights plus temporary copies exceed host memory. A 7B FP16 model settles around 14 to 15 GB resident, so plan 1.5x the weight size. Fix in order of cost: switch to an AWQ or GGUF quantized weight, add memory, or enable memory-mapped loading so the weights are not fully copied.
  • Killed after CUDA init: VRAM is gone. Check nvidia-smi for leftovers from a previous run, then fuser -v /dev/nvidia* to reclaim the device.
  • A ValueError: max_model_len exceeds capacity instead: this is not OOM at all. Rebalance --max-model-len against --gpu-memory-utilization and move to branch 3.

The trap I hit most often (a scenario built from a typical production case): the container memory.max was 8 GB while the host showed 60 GB free. Inside a container you read the cgroup limit, never free -h. Skipping that step misclassifies the branch every time, and I once burned thirty minutes tuning launch flags before noticing the container cap. That is exactly why the 60-second block above leads with the kill evidence and the cgroup reading: a new on-call engineer who runs those three lines picks the right branch in minutes instead of guessing down a flag table.

Branch 2: killed under load (batch 500s during a stress test)

Symptom: the service runs fine for minutes, then a load test floods it with 500s and systemctl status reports status=9/KILL.

dmesg -T | grep -i "killed process" | tail -3
curl -s http://localhost:8000/metrics | grep -E "num_requests_running|num_requests_waiting"
cat /sys/fs/cgroup/memory.current; cat /sys/fs/cgroup/memory.max

How to branch further:

  • cgroup usage near memory.max: per-batch concurrency blew the buffers. Cut --max-num-seqs (default 256, start at 64 for tests) or raise the cgroup cap.
  • Water level flat yet still killed: a slow leak. Watch how often the tokenizer endpoint is called, because spawning a fresh process per encode leaks steadily, and check RSS composition with pmap -x <pid> for allocator fragmentation.
  • Two replicas on one box: their combined working set exceeds host memory. Fix it with anti-affinity in the scheduler, not by squeezing flags. While you are in there, check whether the two replicas share one swap partition, because swapping under load looks like a slow service until it looks like a dead one.

The decisive detail: a live process answering 507 is admission control working; a dead process is OOM. Grep the log for Killed versus 507 before touching any flag.

Branch 3: 507 and KV cache full (alive, but requests fail)

Symptom: the health endpoint returns 200, while inference requests intermittently fail with 507 no available slot or KV cache is full.

curl -s http://localhost:8000/metrics | grep gpu_cache_usage_perc
curl -s http://localhost:8000/metrics | grep num_requests_waiting

How to branch further:

  • gpu_cache_usage_perc above 0.95 with waiting > 0: the cache is genuinely full. Pick the cheapest of: cut --max-model-len (long context is the expensive part), raise --gpu-memory-utilization starting at 0.85, or move to larger VRAM.
  • Occupancy moderate but waiting climbs: not capacity, a head-of-line problem. Long generations block short ones. Cap --max-num-seqs and set a request timeout instead of letting a 32k generation starve everything behind it.
  • Restarts increased after raising utilization to 0.95: too tight. KV cache is pre-allocated from leftover VRAM, and without slack for the CUDA context and short spikes, allocation fails and the engine restarts. Pull it back to 0.85 to 0.90 and tune from the curve. I have personally hit this counterintuitive trap (built from a typical production case): a higher number produced worse stability.

Branch 4: crash loop (start, healthy, crash, repeat)

Symptom: systemctl status shows endless restarts and the process curve in Grafana is a sawtooth.

systemctl show vllm -p NRestarts
journalctl -u vllm --since "30 min ago" | grep -cE "Killed|Traceback"
grep -E "start-period|healthcheck" /etc/systemd/system/vllm.service /etc/docker-compose.yml 2>/dev/null

How to branch further:

  • Mostly Killed: this is not a loop problem, branches 1 and 2 are still open and the loop is only the visible symptom. Fix the OOM and the loop stops by itself.
  • Mostly Traceback: application errors. Read the last traceback's module; common culprits are an unmounted weights path or a port already in use.
  • Always killed between 60 and 90 seconds: the health check start-period is shorter than model loading, so the orchestrator restarts a service that was simply not ready. Set start-period to 1.5x the measured cold start, typically 60 to 120 seconds for a 7B model. This single misconfiguration accounts for most crash loops I see.

Quick reference

Symptom Branch First command Smallest fix
Startup Killed in seconds Host OOM dmesg -T \| grep killed Quantize weights / more memory
500s under load, status=9 cgroup OOM cat memory.current Lower max-num-seqs
Health 200, requests 507 KV cache full grep gpu_cache_usage_perc Cut max-model-len
Higher utilization, more restarts No VRAM headroom nvidia-smi Pull back to 0.85-0.90
Restarts every 60-90s Impatient health check systemctl show -p NRestarts Widen start-period
Ollama drops after a few turns Model eviction ollama ps Cap context and residents

The question I ask before touching anything

Before I edit a single flag I ask: was the process killed by the OS, or did it exit on its own? One dmesg line answers it. Killed means memory and concurrency; an exit with a traceback means code and mounts. The paths never overlap, and guessing wrong turns every later tweak into superstition. Once it is back up I do not walk away either: wire RSS, gpu_cache_usage_perc, and the OOM kill counter into alerting — wire them into Prometheus so the next attempt to kill the service shows up on a chart before it shows up in the incident channel.

Originality note: All commands, the decision tree, and the case studies in this article were compiled by the author from production troubleshooting on vLLM and Ollama inference services. The case studies are built from typical production scenarios and contain no real company names, IP addresses, or timelines.