I'm trying to understand memory usage of some php processes. I've tried using both get_memory_usage()
and pmap
, but the results seem to be off by about one order of magnitude. I've tried with both memory_get_usage()
and memory_get_usage(true)
, as well as memory_get_peak_usage(true)
, but even with memory_get_peak_usage(true)
(the largest of all three varieties) there is still a huge with what is reported via pmap.
More specifically, calling memory_get_peak_usage(true)
every minute within my php script returns values ranging between 1.75MB and 3.5MB, whereas a typical result of pmap -d PID
gives something like:
...
b7839000 4 r---- 0000000000008000 0ca:00060 libcrypt-2.11.1.so
b783a000 4 rw--- 0000000000009000 0ca:00060 libcrypt-2.11.1.so
b783b000 156 rw--- 0000000000000000 000:00000 [ anon ]
b7864000 8 rw--- 0000000000000000 000:00000 [ anon ]
b7867000 12 r-x-- 0000000000000000 0ca:00060 libgpg-error.so.0.4.0
b786a000 4 r---- 0000000000002000 0ca:00060 libgpg-error.so.0.4.0
b786b000 4 rw--- 0000000000003000 0ca:00060 libgpg-error.so.0.4.0
b786c000 4 r---- 0000000000000000 000:00000 [ anon ]
b786d000 16 rw--- 0000000000000000 000:00000 [ anon ]
b7871000 108 r-x-- 0000000000000000 0ca:00060 ld-2.11.1.so
b788c000 4 r---- 000000000001a000 0ca:00060 ld-2.11.1.so
b788d000 4 rw--- 000000000001b000 0ca:00060 ld-2.11.1.so
bffc7000 136 rw--- 0000000000000000 000:00000 [ stack ]
f57fe000 4 r-x-- 0000000000000000 000:00000 [ anon ]
mapped: 32740K writeable/private: 13116K shared: 28K
If I understand correctly, the writeable/private figure is the most relevant figure because it is the memory used exclusively by the process. Nearly 13MB is a far cry from the amount reported by memory_get_peak_usage(true)
. Can someone please explain the discrepancy?