KatInterview

Diagnosing a Kernel OOM Kill in a Containerized JSON Service

System DesignModel answer
EasyModel answerSystem Designlinuxoom-killercgroups

Last updated

Walk through confirming a kernel OOM kill, cutting memory use of a cache-heavy service without adding RAM, and reading RSS versus VSZ during an investigation.

Service Killed by the Kernel

You are on call for a high-throughput service running in a Linux container. It parses large JSON request bodies and keeps a custom in-process cache to speed up lookups. An alert tells you the kernel's Out-Of-Memory (OOM) killer terminated the service.

What to cover

  1. Confirm and attribute. Which logs, files, and command-line tools would you use to verify that an OOM kill happened and to identify which process was chosen? How would you tell whether the container hit its own limit or the whole host ran out of memory?
  2. Mitigate without more RAM. Suppose the cache is the main memory consumer. What changes, at both the application level and the OS/cgroup level, would reduce the chance of another OOM without simply raising the container's memory limit?
  3. RSS vs VSZ. Explain the difference between Resident Set Size and Virtual Memory Size, and how each helps or misleads you when investigating the memory spike.

Constraints

  • Assume Prometheus, Datadog, and similar tools are unavailable. Start from host-level investigation.
  • Focus on Linux memory mechanics.
  • Consider both application configuration and OS-level limits such as cgroups and ulimit.

Structure your answer as a clear process, not a list of unrelated commands.

Hints

Hint 1

The kernel is the authority on why a process died. Look at its ring buffer and at the constraint field in the kill message, which tells you whether a cgroup limit or global memory exhaustion triggered it.

Hint 2

Containers have their own accounting. Exit code 137 and the cgroup's memory.events, memory.peak, and memory.stat files show past kills and what kind of memory (anonymous, file, kernel) was in use.

Hint 3

A cache bounded by entry count is not bounded in memory when values vary in size. Think about byte budgets, eviction, and how JSON parsing multiplies payload size in memory.

Hint 4

VSZ counts address space that is mapped but may never be touched. Only resident pages consume physical RAM and count toward the OOM score.