Cannot allocate memory Linux Origin: Platform & cloud OSI layer 7 · Application Last updated 12 Oct 2026

fork: Cannot allocate memory / ENOMEM

The kernel refused a memory allocation — RAM and swap are exhausted, or overcommit/cgroup limits block it.

Exact message you may see Cannot allocate memoryfork: Cannot allocate memoryOSError: [Errno 12] Cannot allocate memory
Seen on: Linux

Meaning

Unlike the OOM killer (which kills a process), this fails the allocation: new processes can’t fork, commands fail. Small VPSs without swap, memory leaks, or a container memory limit cause it.

Common causes

  • RAM full and no swap
  • Memory leak in a long-running process
  • vm.overcommit_memory=2 strict accounting
  • Container/cgroup memory limit

⚡ Quick fix

  1. Find the biggest processes: ps aux --sort=-%mem | head
  2. Add swap on small servers
  3. Fix the leak or raise the limit

Detailed fix by platform

Linux

  1. bash
    free -h
    ps aux --sort=-%mem | head
    sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile

How to diagnose

  1. Memory — free -h
  2. Top users — ps sorted by memory
  3. Limits — cgroup/container limits, sysctl vm.overcommit_memory

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):

0xC0000005 — The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation (Windows)0xC0000005701 — SQL Server Msg 701: There is insufficient system memory in resource pool to run this query (SQL)701AddressSanitizer: heap-buffer-overflow — C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N (C/C++)AddressSanitizer: hea…AddressSanitizer: heap-use-after-free — C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free (C/C++)AddressSanitizer: hea…Bus error — C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file (C/C++)Bus errorCan't save in background: fork: Cannot allocate memory — Redis: # Can't save in background: fork: Cannot allocate memory / WARNING overcommit_memory is set to 0! (Redis)Can't save in backgro…Client output buffer limit reached (scheduled to be closed) — Redis: Client id=12 addr=10.0.0.5:51234 scheduled to be closed ASAP for overcoming of output buffer limits (Redis)Client output buffer …Composer: Allowed memory size exhausted — Composer: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/bin/composer (Laravel)Composer: Allowed mem…Cannot al…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.