# Memory usage



## urosgruber (Sep 19, 2011)

Hi,

while building our second server I noticed some differences of memory usage or let say RSS output from ps command.

Both servers are 8.2 amd64 and on both we installed the same jail. Output of syslogd and login process are roughly the same. The main difference is with php running in php-fpm sapi.

We build php from ports with the same params, so build should be more or less the same, right. But checking memory usage one one server php-fpm process uses 7200 RSS memory and on the other server it uses just 544 RSS memory. But funny thing is that not always  Sometimes RSS show 4376

Anyone know what could be the cause for such difference?

Results from

[CMD=""]procstat -v PID[/CMD]

1. 544 RSS


```
PID              START                END PRT  RES PRES REF SHD FL TP PATH
38829           0x400000           0x6b7000 r-x   10    0  20  10 CN vn /usr/local/sbin/php-fpm
38829           0x7b7000           0x7e4000 rw-    1    0   1   0 C- vn /usr/local/sbin/php-fpm
38829           0x7e4000           0x800000 rw-    3    0   1   0 C- sw 
38829        0x8007b7000        0x8007e7000 r-x    4    0 128  54 CN vn /usr/jails/basejail/libexec/ld-elf.so.1
38829        0x8008e6000        0x8008ee000 rw-    0    0   1   0 CN vn /usr/jails/basejail/libexec/ld-elf.so.1
38829        0x8008fd000        0x800904000 r-x    1    0  62  23 CN vn /usr/jails/basejail/lib/libcrypt.so.5
38829        0x800a03000        0x800a05000 rw-    0    0   1   0 CN vn /usr/jails/basejail/lib/libcrypt.so.5
38829        0x800a16000        0x800a52000 r-x    0    0  27  11 CN vn /usr/local/lib/libpcre.so.0
38829        0x800b52000        0x800b53000 rw-    0    0   1   0 CN vn /usr/local/lib/libpcre.so.0
38829        0x800b53000        0x800b71000 r-x    1    0  66  25 CN vn /usr/jails/basejail/lib/libm.so.5
38829        0x800c71000        0x800c73000 rw-    0    0   1   0 CN vn /usr/jails/basejail/lib/libm.so.5
38829        0x800c73000        0x800da4000 r-x    0    0  20  10 CN vn /usr/local/lib/libxml2.so.5
38829        0x800ea3000        0x800ec2000 rw-    0    0   1   0 CN vn /usr/local/lib/libxml2.so.5
38829        0x800ec3000        0x800ed7000 r-x    0    0  66  25 CN vn /usr/jails/basejail/lib/libz.so.5
38829        0x800fd6000        0x800fd8000 rw-    0    0   1   0 CN vn /usr/jails/basejail/lib/libz.so.5
38829        0x800fd8000        0x8010cf000 r-x    0    0  29  12 CN vn /usr/local/lib/libiconv.so.3
38829        0x8011cf000        0x8011d3000 rw-    0    0   1   0 CN vn /usr/local/lib/libiconv.so.3
38829        0x8011d3000        0x8012db000 r-x   91    0 128  54 CN vn /usr/jails/basejail/lib/libc.so.7
38829        0x8013db000        0x8013fa000 rw-    1    0   1   0 C- vn /usr/jails/basejail/lib/libc.so.7
38829        0x801415000        0x80143d000 r-x    0    0  18   9 CN vn /usr/local/lib/php/20090626/apc.so
38829        0x80153c000        0x801542000 rw-    0    0   1   0 CN vn /usr/local/lib/php/20090626/apc.so
38829        0x801800000        0x801805000 r-x    0    0  40  20 CN vn /usr/jails/basejail/usr/lib/librt.so.1
38829        0x801904000        0x801905000 rw-    0    0   1   0 CN vn /usr/jails/basejail/usr/lib/librt.so.1
38829     0x7ffffffe0000     0x800000000000 rwx    1    0   1   0 C- sw
```

2.  4376 RSS


```
PID              START                END PRT  RES PRES REF SHD FL TP PATH
87200           0x400000           0x6b7000 r-x  256    0  20  10 CN vn /usr/local/sbin/php-fpm
87200           0x7b7000           0x7e4000 rw-    5    0   1   0 C- vn /usr/local/sbin/php-fpm
87200           0x7e4000           0x800000 rw-   11    0   1   0 C- df 
87200        0x8007b7000        0x8007e7000 r-x   31    0 116  51 CN vn /usr/jails/basejail/libexec/ld-elf.so.1
87200        0x8007e7000        0x8007f0000 rw-    9    0   1   0 C- df 
87200        0x8007f0000        0x8007f1000 r--    1    0   1   0 CN df 
87200        0x8007f1000        0x8007fa000 rw-    2    0   1   0 CN df 
87200        0x8007fa000        0x800800000 rw-    6    0   1   0 -- df 
87200        0x8008e6000        0x8008ee000 rw-    4    0   1   0 CN vn /usr/jails/basejail/libexec/ld-elf.so.1
87200        0x8008fd000        0x800904000 r-x    4    0  58  22 CN vn /usr/jails/basejail/lib/libcrypt.so.5
87200        0x800a03000        0x800a05000 rw-    2    0   1   0 CN vn /usr/jails/basejail/lib/libcrypt.so.5
87200        0x800a16000        0x800a52000 r-x   17    0  26  11 CN vn /usr/local/lib/libpcre.so.0
87200        0x800b52000        0x800b53000 rw-    1    0   1   0 CN vn /usr/local/lib/libpcre.so.0
87200        0x800b53000        0x800b71000 r-x   23    0  62  24 CN vn /usr/jails/basejail/lib/libm.so.5
87200        0x800c71000        0x800c73000 rw-    2    0   1   0 CN vn /usr/jails/basejail/lib/libm.so.5
87200        0x800c73000        0x800da4000 r-x   76    0  20  10 CN vn /usr/local/lib/libxml2.so.5
87200        0x800ea3000        0x800ec2000 rw-   13    0   1   0 CN vn /usr/local/lib/libxml2.so.5
87200        0x800ec3000        0x800ed7000 r-x   19    0  62  24 CN vn /usr/jails/basejail/lib/libz.so.5
87200        0x800fd6000        0x800fd8000 rw-    2    0   1   0 CN vn /usr/jails/basejail/lib/libz.so.5
87200        0x800fd8000        0x8010cf000 r-x    3    0  28  12 CN vn /usr/local/lib/libiconv.so.3
87200        0x8011cf000        0x8011d3000 rw-    3    0   1   0 CN vn /usr/local/lib/libiconv.so.3
87200        0x8011d3000        0x8012db000 r-x  155    0 116  51 CN vn /usr/jails/basejail/lib/libc.so.7
87200        0x8013db000        0x8013fa000 rw-   12    0   1   0 C- vn /usr/jails/basejail/lib/libc.so.7
87200        0x8013fa000        0x801415000 rw-   10    0   1   0 C- df 
87200        0x801415000        0x80143c000 r-x   25    0  20  10 CN vn /usr/local/lib/php/20090626/dom.so
87200        0x80153b000        0x801543000 rw-    6    0   1   0 CN vn /usr/local/lib/php/20090626/dom.so
87200        0x801543000        0x801544000 rw-    1    0   1   0 CN df 
87200        0x801600000        0x801800000 rw-  316    0   1   0 C- df 
87200        0x801800000        0x801816000 r-x   12    0  20  10 CN vn /usr/local/lib/php/20090626/pdo.so
87200        0x801816000        0x801915000 ---    0    0   1   0 CN df 
87200        0x801915000        0x801919000 rw-    4    0   1   0 CN vn /usr/local/lib/php/20090626/pdo.so
87200        0x801a00000        0x801c00000 rw-   23    0   1   0 C- df 
87200     0x7ffffffe0000     0x800000000000 rwx    9    0   1   0 C- df
```

3. 7200 RSS


```
PID              START                END PRT  RES PRES REF SHD FL TP PATH
54205           0x400000           0x6b7000 r-x  695    0  87  39 CN vn /usr/local/sbin/php-fpm
54205           0x7b7000           0x7e4000 rw-   45    0   1   0 CN vn /usr/local/sbin/php-fpm
54205           0x7e4000           0x800000 rw-   11    0   1   0 C- df 
54205        0x8007b7000        0x8007e7000 r-x   48    0 432 199 CN vn /usr/jails/basejail/libexec/ld-elf.so.1
54205        0x8007e7000        0x8007f0000 rw-    9    0   1   0 C- df 
54205        0x8007f0000        0x8007f1000 r--    1    0   1   0 CN df 
54205        0x8007f1000        0x8007fa000 rw-    2    0   1   0 CN df 
54205        0x8007fa000        0x8007fd000 rw-    3    0   1   0 -- df 
54205        0x8008e6000        0x8008ee000 rw-    8    0   1   0 CN vn /usr/jails/basejail/libexec/ld-elf.so.1
54205        0x8008ee000        0x8008fd000 rw-    6    0   1   0 CN df 
54205        0x8008fd000        0x800904000 r-x    7    0 228  97 CN vn /usr/jails/basejail/lib/libcrypt.so.5
54205        0x800a03000        0x800a05000 rw-    2    0   1   0 CN vn /usr/jails/basejail/lib/libcrypt.so.5
54205        0x800a16000        0x800a52000 r-x   42    0  94  42 CN vn /usr/local/lib/libpcre.so.0
54205        0x800b52000        0x800b53000 rw-    1    0   1   0 CN vn /usr/local/lib/libpcre.so.0
54205        0x800b53000        0x800b71000 r-x   30    0 227  97 CN vn /usr/jails/basejail/lib/libm.so.5
54205        0x800c71000        0x800c73000 rw-    2    0   1   0 CN vn /usr/jails/basejail/lib/libm.so.5
54205        0x800c73000        0x800da4000 r-x   99    0  87  39 CN vn /usr/local/lib/libxml2.so.5
54205        0x800ea3000        0x800ec2000 rw-   31    0   1   0 CN vn /usr/local/lib/libxml2.so.5
54205        0x800ec2000        0x800ec3000 rw-    1    0   1   0 CN df 
54205        0x800ec3000        0x800ed7000 r-x   20    0 223 100 CN vn /usr/jails/basejail/lib/libz.so.5
54205        0x800fd6000        0x800fd8000 rw-    2    0   1   0 CN vn /usr/jails/basejail/lib/libz.so.5
54205        0x800fd8000        0x8010b7000 r-x   13    0 112  43 CN vn /usr/local/lib/libiconv.so.3
54205        0x8011b6000        0x8011ba000 rw-    4    0   1   0 CN vn /usr/local/lib/libiconv.so.3
54205        0x8011ba000        0x8012c2000 r-x  215    0 432 199 CN vn /usr/jails/basejail/lib/libc.so.7
54205        0x8013c2000        0x8013e1000 rw-   31    0   1   0 CN vn /usr/jails/basejail/lib/libc.so.7
54205        0x8013e1000        0x8013fc000 rw-   14    0   1   0 C- df 
54205        0x801400000        0x801600000 rw-  315    0   1   0 C- df 
54205        0x801600000        0x801616000 r-x   21    0  87  39 CN vn /usr/local/lib/php/20090626/pdo.so
54205        0x801715000        0x801719000 rw-    4    0   1   0 CN vn /usr/local/lib/php/20090626/pdo.so
54205        0x801719000        0x801740000 r-x   37    0  87  39 CN vn /usr/local/lib/php/20090626/dom.so
54205        0x80183f000        0x801847000 rw-    6    0   1   0 CN vn /usr/local/lib/php/20090626/dom.so
54205        0x801847000        0x801848000 rw-    1    0   1   0 CN df 
54205        0x801a00000        0x801c00000 rw-   36    0   1   0 C- df 
54205     0x7ffffffc0000     0x7ffffffe0000 rwx    2    0   1   0 CN df 
54205     0x7ffffffe0000     0x800000000000 rwx   13    0   1   0 C- df
```

I removed the lines with zero RES

regards

Uros


----------



## Savagedlight (Sep 23, 2011)

wouldn't the memory consumption vary depending on what the running PHP applications do/consume?


----------



## urosgruber (Sep 24, 2011)

It's true for worker process, but not for master. Master only waits for connection and then fork a worker to do all the work. So if on both servers everything is the same (except CPU and total available memory) numbers should be more or less the same.

regards


----------

