Click to See Complete Forum and Search --> : Memory usage per process


jdvilla
01-24-2007, 12:11 PM
I've looked around for a bit and I still don't get it.

How can I find out how much memory a specific process is using.

I usually run pmap -d PID and look at the writeable/private at the top and go forward believing that I've found the true amount being used...

or I'll use ps -lyu <user> and use that. But both are different.

Which is more reliable?

bwkaz
01-24-2007, 08:18 PM
Depends on what you're looking for. ;)

If you want to find out how much physical RAM a process is using, the pmap approach is probably the most reliable. However, it may be possible that a private mapping isn't actually backed by physical RAM, I'm not sure. If you want to find out how many page table entries it's using, I'm not sure you can get that from anywhere. If you want to find out how much swap space it's using, I'd bet that's available somewhere, but I don't know where.

But anyway, the ps command shows both RSS and SZ; which are you using? RSS is the "resident set size"; I'm not entirely sure what this is, but I think it's supposed to be the amount of (not-swapped-out!) physical memory being used. SZ is, according to ps's manpage, the "approximate amount of swap space that would be required if the process were to dirty all writable pages and then be swapped out". This doesn't really correspond to much in the real world, other than perhaps the number of writable pages being used, but the manpage says it's "very approximate" anyway. I'd stay away from that number, I think.

Maybe it'd be better for me to ask this question: What are you going to do with this information (that is, the amount of "memory" being used by each process) if you can find it? :)

voidinit
01-25-2007, 12:29 AM
/proc/$(pidof process)/{stat,status,statm} (under kernel 2.6.x at least) gives quite a few numbers on memory usage. Not quite sure what they all mean, and they might be subject to change for different kernel versions, but if you can get some documentation on what all the fields are, it could possibly be what you are looking for.