Memory overcommit is the practice of granting processes or virtual machines more memory than the physical RAM of the host can back at the same moment, on the assumption that much of the allocated memory will never be touched. Among server resources, it is one of the most consequential and least understood settings, because it decides whether a large allocation fails early with a clean error or succeeds and later triggers the out-of-memory killer.
Overcommit appears at two levels on servers: inside the Linux kernel, which hands out virtual address space lazily, and inside hypervisors, which assign guests more total memory than the host owns. Both rely on the same statistical bet, and both fail in the same way when that bet is lost.
How memory overcommit works in the kernel
The kernel can overcommit because allocation and use are separate events. When a program calls malloc or mmap, it receives virtual address space, not physical pages. Physical frames are assigned only on first write through demand paging, so a process that reserves 8 GB but writes to 500 MB consumes roughly 500 MB of RAM.
Two common patterns make this bet attractive. Copy-on-write after fork lets a parent and child share pages until one modifies them, so a 20 GB process that forks to run a short command would otherwise need another 20 GB of commitment. Sparse allocations, such as large hash tables, thread stacks and memory-mapped files, also reserve far more than they touch.
The kernel tracks the total promised memory as Committed_AS in /proc/meminfo, and compares it with CommitLimit, which equals swap plus a configurable share of RAM. Whether that limit is enforced depends on the overcommit mode.
Linux overcommit modes and tuning parameters
Linux exposes overcommit behavior through the vm.overcommit_memory sysctl, which selects one of three policies. The following table summarizes each mode and its practical consequence.
| Mode | Policy | Allocation behavior | Typical use |
|---|---|---|---|
| 0 (heuristic) | Default estimate | Refuses only obviously excessive requests | General-purpose servers |
| 1 (always) | No checks | Every allocation succeeds | Scientific computing, some Redis setups |
| 2 (strict) | Enforced CommitLimit | Fails once Committed_AS reaches the limit | Databases, safety-critical hosts |
In strict mode, the limit is computed from swap plus `vm.overcommit_ratio` percent of RAM (default 50) or from the absolute vm.overcommit_kbytes. Setting the ratio too low wastes memory, because applications see allocation failures while RAM remains idle; setting it too high recreates the risk that strict mode is meant to remove.
| Setting or field | Location | What it controls |
|---|---|---|
| vm.overcommit_ratio | sysctl | Share of RAM counted toward CommitLimit |
| vm.overcommit_kbytes | sysctl | Absolute alternative to the ratio |
| Committed_AS | /proc/meminfo | Total memory currently promised |
| CommitLimit | /proc/meminfo | Ceiling enforced in strict mode |
| oom_score_adj | /proc/PID | Bias for OOM killer victim selection |
Hypervisor memory overcommit
In virtualization, memory overcommit means the sum of guest memory exceeds host RAM. A host with 256 GB might run guests configured for 384 GB, an overcommit ratio of 1.5:1. This works only when guests rarely use their full allocation simultaneously.
Hypervisors reclaim memory through several techniques, ordered roughly from cheapest to most damaging. The table compares them.
| Technique | Mechanism | Performance cost |
|---|---|---|
| Page sharing | Merges identical pages, such as KSM on KVM | Low, but adds CPU scanning |
| Ballooning | A guest driver inflates to return pages | Moderate, guest may start swapping |
| Memory compression | Compresses cold pages in RAM | Moderate CPU overhead |
| Host swapping | Writes guest pages to disk | Severe, latency rises sharply |
Page sharing has also raised side-channel concerns, which is why many platforms now limit it across tenants. Once a host reaches swapping, every guest suffers, which turns overcommit into a classic noisy neighbor problem.
How overcommit relates to swap and memory usage
Overcommit is not the same as swap, although the two interact. Swap provides backing storage for pages that do not fit in RAM, while overcommit decides how much memory may be promised in the first place. More swap raises CommitLimit in strict mode and gives the kernel room to absorb a burst before the OOM killer acts.
Overcommit also distorts ordinary memory usage metrics. Virtual size (VSZ) can be many times larger than resident set size (RSS), so dashboards that sum virtual memory overstate demand, while dashboards that watch only free RAM miss how close the host is to its commitment ceiling. Monitoring Committed_AS against CommitLimit and resident memory together gives an accurate picture.
Choosing an overcommit policy
The right policy depends on whether an unpredictable process kill or an early allocation failure is the worse outcome. The decision table below maps common workloads to a recommended setting.
| Workload | Recommended setting | Reason |
|---|---|---|
| Relational database | Mode 2 with sized swap | Clean errors protect data integrity |
| Redis with background saves | Mode 1 | Fork for snapshots must not fail |
| Container host | Mode 0 plus cgroup limits | Per-container limits contain damage |
| VM host, mixed tenants | Ratio near 1.2:1 | Leaves headroom for bursts |
| VDI or test labs | Ratio up to 2:1 | Idle desktops share pages well |
Whatever the mode, capacity planning should be based on measured peak resident memory, not on allocations. Teams should also set oom_score_adj so that the OOM killer sacrifices disposable workers before the database or the SSH daemon.
Risks and common mistakes
The central risk is that overcommit moves failure from allocation time to use time. A program that checks every malloc return value can still be killed later, without warning, when it writes to memory the kernel cannot supply.
- Assuming that free RAM means safety, while Committed_AS already exceeds physical memory.
- Enabling strict mode with no swap and a ratio of 50, which causes failures at half of RAM.
- Running hypervisor hosts at high ratios without balloon drivers in the guests.
- Ignoring that the Java heap or a database buffer pool is touched fully at startup, which defeats the overcommit bet.
- Treating OOM kills as random crashes instead of reading the kernel log for OOM reports.
The short version
Memory overcommit works like an airline selling more tickets than there are seats. The airline knows some passengers will not show up, so it sells extra seats and usually everyone fits.
A server does the same with memory. Programs ask for more memory than they really use, so the system promises more than it has. Most of the time this saves money and works well. On the rare day when every program actually wants its share, someone gets bumped, and on a server that means a program is stopped abruptly to free memory.
Where it makes a difference
A hosting team runs a PostgreSQL server with 64 GB of RAM and the default heuristic mode. During a nightly batch job, several reporting queries allocate large work areas at once, Committed_AS climbs to 90 GB, and resident memory reaches the physical limit. The OOM killer selects the largest process, which is the database itself, and every connected application loses its session.
After the incident, the team switches to strict overcommit (mode 2), adds 16 GB of swap and sets the ratio to 85, which gives a CommitLimit of about 70 GB. They also lower the per-query memory setting. The next time the batch job overreaches, one query receives an out-of-memory error and is retried, while the database stays online for everyone else.