I wrote a test program to help me understand the output field of different memory utilities such as free,ps,top,/proc/$pid/status,/proc/$pid/smaps,/proc/$pid/statm etc. One question finally rose up and I could not manage to understand:
Question: The vmRss field of /proc/$pid/status is not same with the one calculated out of /proc/$pid/smaps (by adding up all the Rss field).
The former value should be source of the RSS output of "ps" command while the latter one source of "pmap -x" command.
The test program I wrote is to create 20 threads with identical procedure in which each thread call malloc(4*1024) 256 times, resulting in a memory footprint of 1MB per thread, therefore 1MB/thread * 20 thread = 20MB totally.
Based on this program, the output of VmRSS from /proc/$pid/status is
VmRSS: 16468 kB
which align with the output of ps
8941 0.0 0.1 4102600 16468 pts/22 Sl+ 10:07 0:00 ./a.out
While the add-up of /proc/8941/smaps and output of pmap -x 8941 is:
$ cat /proc/8941/smaps | grep Rss | awk '{print $2}' | awk '{s+=$1} END {printf "%.0f\n", s}' /dev/stdin
22536
$ pmap -x 8941 | tail -n 1
total kB 4102604 22536 20992
The output of free command convinced me that my program do consume 20+MB memory, therefore the RSS value of "ps" and "/proc/$pid/status" does not make sense to me.
Can anybody explain what is happening? Thanks in advance.