Linux – Running out of memory, fork can’t allocate memory

apache-http-serverlinuxmemoryPHP

We are getting out of memory frequently, as well fork cannot allocate memory. I did some investigation.

It seems that scripts are not case as I thought before this. I will share information which I get after analyzing.

I have isolated server, so other people cant reach to server. This will show "true" memory usage in this case.

  1. I have no mysqld and apache started [memory usage ~182mb].
  2. just started mysqld. no connections made to mysqld [mu ~340mb].
  3. httpd started [~360mb].
  4. first request to script. [~630mb]. But!! The most interesting part. Memory doesn't get deallocated. Everything looks OK. Script ended, page loaded successfuly. But it still around ~630mb.

Why one request eats 270MB? Why thats not deallocated after request?

Some stats:

  • Server RAM 512 MB guaranteed
  • 256 MB burstable
  • PHP memory limit: 256MB

httpd.conf

<IfModule prefork.c>
StartServers 1
MinSpareServers 1
MaxSpareServers 3
ServerLimit 50
MaxClients 50
MaxRequestsPerChild  50
</IfModule>

Best Answer

Why one request eats 270MB?

Likely because it accessed a lot of data or metadata in or about files on disk.

Why thats not deallocated after request?

Because the data might be used again soon. Deallocating it after the request makes the next request expensive. It makes more sense to defer the deallocation until the memory is actually needed for something else.

Related Question