linux process memory usage

Programming, for all ages and all languages.
Post Reply
Ozguxxx

linux process memory usage

Post by Ozguxxx »

Hi every1, I have a quick question do you have any thoughts on how to get a reasonable value for memory usage of a process in linux? I am currently using ps however it is reporting 3 namely rss ,vsz and size and I dont know how to use these. I have read some articles on internet and all of them are rather discouraging i.e. they all tell that it is really hard to determine a reasonable value for size of memory a process is using, some state that rss+vsz might be a good measure, but I might have misunderstood.. im open to even the quickest ideas, thanx in adv.
Oz.
chasetec

Re:linux process memory usage

Post by chasetec »

Short(not perfectly correct) answer is:

rss = how much memory is currently being used
vsz = how much memory the program thinks it's taking up
size = vsz + memory the program is using for files

The difference between rss and vsz is because the OS pages out chunks of applications that haven't been used in a while(usually to swap). As long as you system isn't short on memory already rss should give you a close enough estimate on memory average memory usage for a program.

None of this takes in to account shared memory where two or more programs can overlap each other. ps isn't smart enough to notice the overlap, sometime you can add up all the memory used that ps shows and it'll be more memory then you have.

In truth the amount of memory a new run of a process takes up varies based on what other process you have running on your system. The only real way to determine memory usage is with pmap but that is not easy to use. Several people have written scripts that parse pmap to give more accurate numbers. Several programs use more shared memory than others, like databases.
Ozguxxx

Re:linux process memory usage

Post by Ozguxxx »

thanks for reply and explanation chase,
it seems to me (based on pure observation) that size should be a reasonable estimate of used memory because it is nearly the same when I observe it on different machines, vsz and rss usually are differing by significant amount (most probably based on current state of os, i guess) let me check pmap otw i think ill go with size.. thanx again.
Oz.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:linux process memory usage

Post by Solar »

"man ps" (on Solaris 8) gives me::

rss - The resident set size of the process, in kilobytes. The rss value reported by ps is an estimate provided by proc(4) that may underestimate the actual resident set size. Users who wish to get more accurate usage information for capacity planning should use pmap(1) -x instead.

vsz - The total size of the process in virtual memory, in kilobytes.

SZ - The total size of the process in virtual memory, including all mapped files and devices, in pages. See pagesize(1).
Every good solution is obvious once you've found it.
Ozguxxx

Re:linux process memory usage

Post by Ozguxxx »

great, then ill absolutely go with size, pmap seems rather complicated anyway.. thanks..
Post Reply