Actual memory usage php-fpm?

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,457
I am somewhat confused about the amount of memory DirectAdmin report in GUI for php-fpm. This is on a server with 128 GB RAM:

Code:
[root@server ~]# free -g
              total        used        free      shared  buff/cache   available
Mem:            125          22           1          15         101          86
Swap:             0           0           0
[root@server ~]#
At the same time of generating the above output, DirectAdmin GUI report that php-fpm72 is using 76.48 GB - but if that was true, then it would not show 86 under "available" in above output! That is confusing.

I am using opcache, and I have set the following setting:

Code:
opcache.interned_strings_buffer	128
I think that does indeed affect how much memory each php-fpm instance is using. I wonder if that is not actual memory used, but reported as used by buffers?

Also I suspect that all the memory that php-fpm is using, might not be actuall memory used, I suspect that maybe some of it is added by opcache and only reserved and not necessarily used. Because the math above does not make sense. Maybe someone else has more information?
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,457
So I found some interesting related discussion here (without it being much helpful): https://serverfault.com/questions/969967/php-fpm-why-do-i-have-a-process-memory-usage-higher-than-memory-limit

But this article has some interesting thought about it: https://linuxaria.com/article/how-to-measure-memory-usage-in-linux

Some of these numbers can be a little misleading. For instance, if you have a website that use PHP, and in particular php-fpm, you could see something like: ...

Is it possible that all these processes use around 30 percent of the total memory of the system? Yes it is, because they use a lot of shared memory – and this is why you cannot simply add the %MEM number for all of the processes to see how much of the total memory they use.
Above outlined the interesting part in bold. Then I found this reply by @smtalk: https://forum.directadmin.com/showthread.php?t=57343&p=293111#post293111

This is the total of shared memory (https://en.wikipedia.org/wiki/Shared_memory), not the actual one. Similar processes share lots of their memory, so physical memory usage is usually lower than VMEM usage. It should be possible to count physical (actual) memory usage in recent OS, so, that'd be a feature request to DA. (cut)
But it is not useful that DirectAdmin GUI display VMEM usage for PHP-FPM, I think. Because why would that be of any much relevance? It is the actual physical memory usage of PHP-FPM that we need to consider? Let me know if I am wrong!

So I guess this is going to be a feature request: Please change DirectAdmin GUI to display the actual physical memory usage of PHP-FPM instead of the VMEM.

In the meantime, does anybody know how to display the actual physical memory usage of PHP-FPM? The following does not work because it only shows the VMEM:

Code:
ps -ylC php-fpm72 --sort:rss
(the column rss is a number in kilobytes of how much RAM the current process is using)
 
Last edited:

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,457
@bdacus01, Thank you very much! It seems to work correct and give the actual physical memory usage. I just needed to take the first (of many) php-fpm pid, and then it seems the first number in output give the total physical memory usage of all the php-fpm pids. Perfect!

Edit: Hmm. I am a little confused. I get different total depending on wich php-fpm pid I use, but it is not much difference, only very small differences. When I get time, I will need to read up on the man link you provided.
 
Last edited:

bdacus01

Verified User
Joined
Jul 22, 2017
Messages
550
Location
Murfreesboro
@bdacus01, Thank you very much! It seems to work correct and give the actual physical memory usage. I just needed to take the first (of many) php-fpm pid, and then it seems the first number in output give the total physical memory usage of all the php-fpm pids. Perfect!

Edit: Hmm. I am a little confused. I get different total depending on which php-fpm pid I use, but it is not much difference, only very small differences. When I get time, I will need to read up on the man link you provided.
I could be due to the volatility of the process and its current use. There is also Master Php fpm process' and the sites use pid. I depends on if you are using ondemand or a static type PM maybe.

I found this video helpful. https://serversforhackers.com/c/php-fpm-process-management


Ditto it was great to actually help you as you have helped us all so much.
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,457
@bdacus01, I did not see the need to dig further into this, as I am happy with the command in your reply above. The first column in output shows about the total actual physical memory usage of php-fpm. That is all I need. For example last time I cheched a server it said in DA GUI that php-fpm was using a total of 81,60 GB of memory, however whan checking with your command at the same time, php-fpm was only using 18.37 GB of memory.
 
Top