Cannot allocate memory Linux Origin: Platform & cloud 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)0xC0000005AddressSanitizer: 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 errordouble free or corruption — C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped) (C/C++)double free or corrup…EADDRINUSE — Error: listen EADDRINUSE: address already in use :::3000 (Node.js)EADDRINUSEEPIPE — Error: write EPIPE (Node.js)EPIPEerror while loading shared libraries — error while loading shared libraries: libX.so.N: cannot open shared object file: No such file or directory (Linux)error while loading s…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.