Linux ENOMEM (errno 12) — Cannot Allocate Memory (Deep Dive)
Criticalerrno
Overview
Deep dive into Linux ENOMEM covering OOM killer behavior, overcommit settings, memory cgroups, swap exhaustion, and kernel memory allocation failures.
Key Details
- ENOMEM can come from user-space malloc failure or kernel-space allocation failure
- Linux overcommit memory by default (vm.overcommit_memory=0), so ENOMEM is rare until truly out
- When physical RAM + swap is exhausted, OOM killer selects a process to kill
- OOM killer logs in dmesg: 'Out of memory: Kill process [PID] (name) score [N]'
- Memory cgroups can impose per-container or per-service memory limits triggering ENOMEM earlier
Common Causes
- Physical RAM + swap completely exhausted (system-wide OOM)
- Memory cgroup limit reached (container/service-level OOM)
- Memory leak in application consuming ever-increasing memory
- Kernel memory (slab, page tables) exhausted despite user-space memory available
- vm.overcommit_memory=2 (no overcommit) and commit limit reached
Steps
- 1Check memory usage: free -h to see RAM and swap status
- 2Check OOM killer activity: dmesg | grep -i 'out of memory' or 'oom-killer'
- 3Find memory hogs: ps aux --sort=-%mem | head -20
- 4Add swap space temporarily: sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
- 5Check cgroup limits: cat /sys/fs/cgroup/memory/memory.limit_in_bytes (cgroup v1) or memory.max (v2)
Tags
linuxenomemerrno-12oom-killermemory
More in Errno
linux-errno-1-epermLinux errno 1 (EPERM) — Operation Not Permitted
Warninglinux-errno-2-enoentLinux errno 2 (ENOENT) — No Such File or Directory
Warninglinux-errno-5-eioLinux errno 5 (EIO) — Input/Output Error
Errorlinux-errno-11-eagainLinux errno 11 (EAGAIN) — Resource Temporarily Unavailable
Informationallinux-errno-12-enomemLinux errno 12 (ENOMEM) — Out of Memory
Criticallinux-errno-13-eaccesLinux errno 13 (EACCES) — Permission Denied
WarningFrequently Asked Questions
Linux overcommits memory. The OOM killer kills processes when memory is truly exhausted, rather than returning ENOMEM at allocation time.