Operating System - HP-UX
1844185 Members
2485 Online
110229 Solutions
New Discussion

Re: Calculating Real Memory Usage

 
Wolfgang Richter
New Member

Calculating Real Memory Usage

I am trying to calculate physical memory usage within HP-UX using the pstat interface.

I would like my numbers to match up with Glance's output under the RSS column.

I am having a lot of trouble making this happen, so far my calculation is:

procMem = (((double) (pst.pst_dsize + pst.pst_ssize + pst.pst_tsize)) * getpagesize()) / (1024 * 1024)

In my mind, this calculation gets all the real space used by the process and converts the returned page numbers into megabytes.

However, this calculation returns sizes much larger than the RSS column in Glance for the exact same PID's.

Please advise on how Glance is calculating RSS.
6 REPLIES 6
Wolfgang Richter
New Member

Re: Calculating Real Memory Usage

Quick update, it appears that my logic gives me numbers slightly below for some processes, much larger for others. I think this is because I do not account for shared memory yet.

Can anyone advise me on some C logic to correctly calculate shared memory usage to not overstate things?
Geoff Wild
Honored Contributor

Re: Calculating Real Memory Usage

I've done this with ps:

# cat /usr/local/bin/processmem
#!/bin/sh
# processmem - display memory claimed by a process
# gwild 03192004
#
if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "processmem \"process\""
echo "Example:"
echo "processmem rpc"
exit 1
fi
echo " "

PROCESS=$1

mps=0
for sz in `UNIX95= ps -e -o vsz=Kbytes -o ruser -o pid,args=Command-Line | sort -rnk1 | grep -v Kbytes | grep $PROCESS | awk '{print $1}'`
do
mps=`expr $mps + $sz`
done
#echo `expr $mps \* 4096`
echo "\nMemory claimed by $PROCESS: $mps Kbytes.\n"


Does that not give you the same?

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Wolfgang Richter
New Member

Re: Calculating Real Memory Usage

Thanks for the response, I am going to run that script you sent.

I was using ps before, however I don't think the values were matching (perfectly).
Wolfgang Richter
New Member

Re: Calculating Real Memory Usage

I don't believe that script is entirely accurate. It is getting vsz from ps which is virtual assigned memory, I think you should be using sz. Also it doesn't actually report solely on one process - it groups processes that have the same name (desirable in some cases).

For example, I ran your script with the process name of an Oracle database. The script claims that all of these processes put together claim over 9 Gigabytes of memory. I'm pretty sure Glance isn't reporting the same number for RSS.

When using sz it provides a more reasonable number of 2 Gigabytes which is more in tune with Glance.
Adam Scheblein
Advisor

Re: Calculating Real Memory Usage

You have to be careful when using the RSS from glance, while mostly accurate, the glance plus performance metrics guide: http://ovweb.external.hp.com/ovnsmdps/pdf/glanceplus450_hpux_dict_os_perf_metrics.txt
says this about RSS:

RSS = sum of private region pages +
(sum of shared region pages /
number of references)

The number of references is a count of the number of attachments to the memory region. Attachments, for shared regions, may come from several processes sharing the same memory, a single process with multiple attachments, or combinations of these.

This value is only updated when a process uses CPU. Thus, under memory pressure, this value may be higher than the actual amount of resident memory for processes which are idle because their memory pages may no longer be resident or the reference count for shared segments may have changed.

On HP-UX, this metric is specific to a process. If this metric is reported for a kernel thread, the value for its associated process is given.

A value of â naâ is displayed when this information is unobtainable. This information may not be obtainable for some system (kernel) processes. It may also not be available for processes.
Wolfgang Richter
New Member

Re: Calculating Real Memory Usage

Any idea how those values are gotten in the RSS calculation?