Memory overcommit

Also known as: memory overcommitment · overcommit

On this page 8

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.

ModePolicyAllocation behaviorTypical use
0 (heuristic)Default estimateRefuses only obviously excessive requestsGeneral-purpose servers
1 (always)No checksEvery allocation succeedsScientific computing, some Redis setups
2 (strict)Enforced CommitLimitFails once Committed_AS reaches the limitDatabases, safety-critical hosts
Values of vm.overcommit_memory

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 fieldLocationWhat it controls
vm.overcommit_ratiosysctlShare of RAM counted toward CommitLimit
vm.overcommit_kbytessysctlAbsolute alternative to the ratio
Committed_AS/proc/meminfoTotal memory currently promised
CommitLimit/proc/meminfoCeiling enforced in strict mode
oom_score_adj/proc/PIDBias for OOM killer victim selection
Related kernel settings and indicators

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.

TechniqueMechanismPerformance cost
Page sharingMerges identical pages, such as KSM on KVMLow, but adds CPU scanning
BallooningA guest driver inflates to return pagesModerate, guest may start swapping
Memory compressionCompresses cold pages in RAMModerate CPU overhead
Host swappingWrites guest pages to diskSevere, latency rises sharply
Memory reclamation techniques under overcommit

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.

WorkloadRecommended settingReason
Relational databaseMode 2 with sized swapClean errors protect data integrity
Redis with background savesMode 1Fork for snapshots must not fail
Container hostMode 0 plus cgroup limitsPer-container limits contain damage
VM host, mixed tenantsRatio near 1.2:1Leaves headroom for bursts
VDI or test labsRatio up to 2:1Idle desktops share pages well
Overcommit decisions by workload

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.