Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot allocate memory: fork: Unable to fork new process?

We have our hosting in aws. Recently after moving our blog from wordpress to aws, we are experiencing noticeable delay in server response time. Mainly while accessing the blog. Below are the logs from the error_log file,

[Wed Feb 25 06:10:10 2015] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 25 06:12:22 2015] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 25 06:12:36 2015] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 25 06:12:50 2015] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 25 06:13:35 2015] [error] (12)Cannot allocate memory: fork: Unable to fork new process
[error] (12)Cannot allocate memory: fork: Unable to fork new process
[Wed Feb 25 06:27:14 2015] [error] (12)Cannot allocate memory: fork: Unable to fork new process

We increased the memory size from 256 to 512 mb in php.ini file. But, still the issue exist.

We also changed the KeepAlive as On. Still it doesn't resolve. Any suggestions / solutions would be of great help.

like image 279
Muruga Avatar asked Feb 25 '15 09:02

Muruga


People also ask

What can cause fork () to fail?

But off the top of my head - if you are sure that there is no way that your machine is running out of memory when running the script - the only major factor I can think of that could cause fork () to fail would be if the number of PIDs and/or threads that are running exceed the maximums set in the kernel.

Why does Unix fork take up 100MB of memory?

When unix fork ()s a process, the OS doesn’t yet know how much of that process’s memory allocation is going to be shared, and how much will remain local. So, it has to reserve enough for the entire space (i.e. 100MB per process, in the case of our apaches).

Why can’t I see the output of the fork error?

Some terminals limit the amount of output that is cached for scroll-back-often around 1000 lines or so. If the output from the script exceeds that limit, the lines of output regarding the fork error might be unavailable to you.

How much free virtual memory does it take to fork a process?

If you want to fork () a 100MB process, there must be 100MB of free virtual memory left on the system. So it’s now easy to see why our httpd’s were failing to fork: 100MB * 400 process = 40GB – once you’ve added in the 10GB of oracle SGA, 5GB of java heap, and sundry other processes, that’s everything all gone.


1 Answers

I've face that problem either while hosting a java app with jenkins, mysql & tomcat on ubuntu on an vm of AWS.

First steps I used to solve the problem with restarting a vm.

AWS doesn't give swap memory on a harddrive by default, so you'd better to make it with your hands. How to do this you can find here. Need to mention: the solution with swap zone (have no idea why) haven't work for me, I had to create a swap file.

Good luck to you!

like image 183
barbariania Avatar answered Sep 28 '22 18:09

barbariania