1

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.

1 Answer 1

1

Please refer Linux man-pages project at https://www.kernel.org/doc/man-pages/. They can explain what you are seeing.

As of this writing (release 5.13), proc(5) says VmRSS in /proc/[pid]/status is inaccurate.

VmRSS Resident set size. Note that the value here is the sum of RssAnon, RssFile, and RssShmem. This value is inaccurate; see /proc/[pid]/statm above.

proc(5) says RssAnon and RssFile are inaccurate, so VmRSS must be inaccurate.

For accurate values you should refer /proc/[pid]/smaps (man page says so under /proc/[pid]/statm).

And, ps(1) says

The SIZE and RSS fields don't count some parts of a process including the page tables, kernel stack, struct thread_info, and struct task_struct. This is usually at least 20 KiB of memory that is always resident. SIZE is the virtual size of the process (code+data+stack).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.