Friday, September 02, 2005

What exactly is "rss" from ps and prstat ?

What exactly is "rss" from ps and prstat ?

Got a quick query - what exactly is the "rss" or resident set size of a
process, as reported by "ps" ? My understanding from the man page is
that it is the size of the program actually in memory, as opposed to
it's size in virtual memory.

However, this doesn't seem to be the case. If I run a quick script to
add up the total amount of memory used by a 'httpd' process :

# ps -e -o comm,rss | grep httpd | awk '{sum+=$2} END {print sum}'
11354832

So it appears that httpd processes (Apache) are taking up 11354832
Kilobytes, or nearly 11 Gigabytes. This is also confirmed by the output
from prstat, which also shows 11G in the RSS field.

Which would be a nifty trick, given that the box only has 4Gb...

I assume I've totally misunderstood what RSS refers to; if anyone could
clarify this for me, it would be greatly appreciated!

Thanks,

> Which would be a nifty trick, given that the box only has 4Gb...

Thanks to shared libraries and fork()s without subsequent exec()s,
a significant part of the memory is shared.

A
Ah, that certainly explains it. Thanks.

Could someone explain what the best method is to obtain the figure I'm
after then? Ideally, I'd like to find out the total amount used by each
process, excluding shared pages, and then how much memory is shared
between them. These figures could then be added up to show the "real"
amount of memory used by the given set of processes.

pmap -x looks like it may hold the answer, but I'm still not entirely
clear what I need to look for. Looking at Rich Teer's "Solaris Systems
Programming", it appears that I'd want to add up the amount used by the
stack and heap of each process. Is this correct ?

T
> stack and heap of each process. Is this correct ?

I'm afraid that things are more difficult thanks to copy-on-write which
is in effect after fork(). That means that some of the pages of a stack
or heap can still be shared while other pages have already been copied.
And there are many other mappings that require swap space. Take
initialized and uninitialized variables for example or storage areas
that have been allocated through mmap(2) with MAP_ANON added to the flags.

Andreas.

0 Comments:

Post a Comment

<< Home