The Runtime Theory

Memory Pressure and the OOM Killer

Memory pressure and the OOM killer: watermarks, kswapd LRU reclaim, swap, badness scoring, and SIGKILL.

The Runtime Theory Team07 stages

trace / request.md

WATERMARKBREACHEDLRU SCANCLEAN PAGESRECLAIMEDSWAP AND SHRINKPRESSURE PERSISTSVICTIM SCOREDSIGKILL SENT

readyFree memory drops below the low watermark and kswapd — the kernel's background reclaimer — wakes up. Above the watermark, allocation never needs it.

Memory pressure is a ladder, and the OOM killer is the last rung. This diagram follows the kernel's escalation: free memory drops below a watermark, kswapd wakes and walks the LRU lists reclaiming cold pages, clean file pages drop immediately, dirty ones are written back first, anonymous pages swap out, and slab caches shrink. Only when reclaim fails to keep up does the kernel call the OOM killer, which scores every process by badness — memory footprint, runtime, privileges, oom_score_adj — and SIGKILLs the worst. The ordering matters because the kernel would always rather reclaim than kill. The done state: the victim's pages are freed, allocation succeeds again, and the rest of the system continues.