Operating System - Tru64 Unix
1752577 Members
4452 Online
108788 Solutions
New Discussion юеВ

Re: Calculate amount of free memory (8k pages)

 
SOLVED
Go to solution
Srikanth Arunachalam
Trusted Contributor

Calculate amount of free memory (8k pages)

Hi,

I have the below function call for calculating amount of free memory in tru64. I need to migrate this script on hp-ux. I would like to know 2 things.
(1) Why they have multiplied MEM_FREE by 128 below
(2) Will the output of TOP alone be sufficient to determine the free memory in HP-UX
or
will the below script be more accurate. Please let know the equivalent on hp-ux. Your efforts will be greately appreciated.

#-----------------------------------------------------------------
# Calculate amount of free memory (8k pages)
#-----------------------------------------------------------------

function get_free_mem
{
if [ ! -f free_mem_$today.dat ]
then
echo "time free_mem" > free_mem_$today.dat
fi
time=`date +'%H:%M:%S'`
cli_proc=`ps -ef | grep "oracle"$ORACLE_SID" " | grep -v grep | wc -l`

MEM_ITEMS=$(ps -e -o rssize)
RSSTOT=0
MEM_FILE=/var/adm/messages
if [ -r $MEM_FILE ]
then
TOT_MEM=$(grep 'physical memory' $MEM_FILE |tail -1|awk '{print $9}')
AVL_MEM=$(grep 'available memory' $MEM_FILE |tail -1|awk '{print $9}')
BUF_MEM=$(grep 'buffers containing' $MEM_FILE | grep -v ADVFS |tail -1|awk '{print $10}')
AVF_MEM=$(grep 'buffers containing' $MEM_FILE | grep ADVFS |tail -1|awk '{print $11}')
else
# bit of a bummer
exit 3
fi
TOT_MEM=${TOT_MEM%.*}
AVL_MEM=${AVL_MEM%.*}
BUF_MEM=${BUF_MEM%.*}
AVF_MEM=${AVF_MEM%.*}

for I in $MEM_ITEMS
do
if [[ $I != "RSS" ]]
then
T=${I%M|K}
D=${T#*.}
N=${T%.*}
if [[ ${#T} -eq ${#N} ]]
then
M=$( echo $I | sed -e's/M/ \* 1024 \* 1024/' -e's/K/ \* 1024/')
else
B=$( echo $I | sed -e's/[0-9]*\.[0-9]*//')
M=$( echo "$N$D$B * 100 / 1000" | sed -e's/M/ \* 1024 \* 1024/' -e's/K/ \* 1024/')
fi
eval "(( S = $M ))"
(( RSSTOT = RSSTOT + S ))
fi
done

((RSSTOT = RSSTOT/1024/1024))
(( KERNEL_MEM = TOT_MEM - AVL_MEM ))
(( MEM_USED = KERNEL_MEM + BUF_MEM + AVF_MEM + RSSTOT ))
(( MEM_FREE = TOT_MEM - MEM_USED ))
(( PAGES_FREE = MEM_FREE * 128 ))
echo "$time $PAGES_FREE" >> free_mem_$today.dat

Thanks,
Srikanth A
01473 348880
4 REPLIES 4
Steven Schweda
Honored Contributor

Re: Calculate amount of free memory (8k pages)

> (1) Why they have multiplied MEM_FREE by 128 below

Perhaps because MEM_FREE is in megabytes,
and, as the comment says, the script is
reporting the result in "8k pages". (Hint:
What's 8KB * 128?)

If you want to know about how to find free
memory on an HP-UX system, you might simply
ask that question on the HP-UX forum. Asking
anyone how to migrate a script like this is
probably not the best way to get that datum.
Hein van den Heuvel
Honored Contributor
Solution

Re: Calculate amount of free memory (8k pages)

Also, fwiw, that is a horrible script to begin with.
Wrong language for the job, Wrong data, excessive resource usage.

What is it with these unix shell script writers that they fail to see beyond simplistic features of tools.

>> TOT_MEM=$(grep 'physical memory' $MEM_FILE |tail -1|awk '{print $9}')

Three program activations where not will do.
Why not let awk do the grepping and tailing?

awk '/physical memory/{phy=$9} END {print phy}' $MEM_FILE

And to make it worse, they re-read the same file over and over instead of grabbing all they need in one pass.

And they co-erce the shell to do math which awk (or perl) would so gracefully do.

And in the end none of those symbols are needed as just 1 line with 1 value is added to a file.

Just throw that script away!

A simple vmstat >> some-file is more useful.

Spend two minutes to properly learn what free memory means in hpux, where hpux maintains that, and how to report it.
Before asking PLEASE google for existing material on the matter. It's out there.

Cheers,
Hein.
Srikanth Arunachalam
Trusted Contributor

Re: Calculate amount of free memory (8k pages)

Hi Hien,

You deserve more than 10 points, I could not give anything more than this. Absolutely fine with the output of vmstat, but want to make sure if there are any limitations in vmstat output please.

Thanks,
Srikanth A
Hein van den Heuvel
Honored Contributor

Re: Calculate amount of free memory (8k pages)


There was a recent topic in the HPUX forum on this subject:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1087669

"top/vmstat/swapinfo Outputs And Memory"

It points to an interesting document:

ftp://eh:spear9@hprc.external.hp.com/memory.htm

That in turn points to menay other sources of knowledge. However deep you want to dive (or not).

Cheers,
Hein.