Cannot allocate memory 🐧 Linux

fork: Cannot allocate memory / ENOMEM

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

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:

🧠 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.