Promising More Than You Have
Linux, by default, allows processes to allocate more virtual memory than physical RAM plus swap combined. This is called memory overcommitment, and it's intentional.
The rationale: when a process calls malloc(1GB), it rarely uses all 1GB immediately — or ever. Programs routinely allocate large buffers speculatively. If the kernel required real physical RAM to back every allocation at the moment of malloc(), systems would run out of memory far sooner than necessary.
The kernel's overcommitment behavior is controlled by vm.overcommit_memory:
| Value | Behavior |
|---|---|
0 (default) |
Heuristic overcommit. The kernel uses an algorithm to allow most allocations but reject obviously impossible ones. |
1 |
Always overcommit. Every malloc() succeeds, no matter what. Maximizes allocation success but increases OOM risk. |
2 |
Never overcommit. Total committed memory cannot exceed swap + a configurable percentage of RAM. Safer but more restrictive. |
The current policy is readable from /proc/sys/vm/overcommit_memory, and /proc/meminfo exposes the accounting behind it. The CommitLimit line shows the maximum the system will commit (under mode 2). The Committed_AS line shows how much has actually been promised to processes.
Why this matters for containers: Kubernetes and container runtimes rely on overcommitment. When you set a container's memory request to 256MB but its limit to 512MB, the kernel has overcommitted. If many containers simultaneously hit their limits, the OOM killer activates. Understanding overcommitment explains why Kubernetes memory limits are enforced by cgroups (hard limits) rather than relying on the kernel's overcommit accounting alone.
A common interview question: "Why does free show very little free memory on a healthy Linux server, and should you be worried?" The answer: Linux aggressively uses free RAM as page cache (disk file cache). The available column in free -h (not free) is what matters — it shows memory that can be reclaimed for applications without going to swap. A server with 100MB free but 8GB available is healthy. A server with 100MB available is in trouble.