Operating System - HP-UX
1863043 Members
1098 Online
110446 Solutions
New Discussion

Re: Yet another memory question.

 
Steve Huizenga
Frequent Advisor

Yet another memory question.

On my N4000 with 8gb of memory glance shows 430mb system memory, 820mb buffer cache, 5.15gb user memory and 1.6gb free for a total of 8gb.
When i run "ps -elf | awk '{ sum += $10*4096/1024/1024 } END { printf "%ld\n", sum }'" I get 2248 or 2.25gb used. What gives? I need an accurate portral of utilization by process.

Steve
9 REPLIES 9
Steve Huizenga
Frequent Advisor

Re: Yet another memory question.

Memory utiliztion that is.
A. Clay Stephenson
Acclaimed Contributor

Re: Yet another memory question.

I would tend to use Glance in command-line mode as it is much more reliable BUT if you want an approximnation of process memory usage then

#!/usr/bin/sh
MEM=$(UNIX95= ps -f -o vsz | awk 'BEGIN {
sum = 0
}
{
if (NR > 1) sum += ($1 + 0)
}
END {
printf("%d\n",sum)
}')
echo "MEM = ${MEM}"

NOTE the UNIX95= - that put ps in the XPG4 mode; vsz is the core image size in KB. One problem with your version is the header line of ps; you didn't skip past it.
That's what the (NR > 1) does.
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: Yet another memory question.

Portraying Unix memory usage isn't simple at all. The kernel has it's own portion of memory (which Glance can identify) along with shared system resources (buffer cache, shared libraries, memory mapped files, process shared memory, etc) and the same processes share the text portion of their code. The only true program areas are data and stack. Glance has a large set of rules to sort all this out.

For ps, the sz column contains text, data and stack but this isn't a complete picture. Glance gives you a better picture. You can get a simple view with ps which is good enough for a virtual memory machine. When RAM is short, the operating system will quietly return sone system memory such as the buffer cache and eventually start deactivating processes and paging to the swap area. The metric of interest is the page out rate (seen with vmstat or Glance).

Here's a quick way to sort all processes by the Kbytes of RAM they are using as reported by ps:

UNIX95= ps -e -o vsz,pid,args | sort -rn | more


Bill Hassell, sysadmin
Sridhar Bhaskarla
Honored Contributor

Re: Yet another memory question.

Hi Steve,

Another way of looking at the used memory is to do a vmstat 2 2 and note down the free pages.

Your used memory in bytes = Total Memory - (free pages * 4096).

This includes all usages.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Steve Huizenga
Frequent Advisor

Re: Yet another memory question.

UNIX95= ps -e -o vsz | grep -v VSZ | awk '{ sum += $1 } END { printf "%ld\n", sum }' returns 3011928 which is about 3GB. Glance says I'm using 5.1 GB. Where is the other 2.1GB?

Steve
Mladen Despic
Honored Contributor

Re: Yet another memory question.

Steve,

If you have Glance, try the adviser syntax posted at this link:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x61d4a848deccd61190050090279cd0f9,00.html

Mladen
Mladen Despic
Honored Contributor

Re: Yet another memory question.

Steve,

1) In your first post, you were adding up the values under SZ. In your second post, you were adding up the values under VSZ. If you are trying to account for physical memory used, then I think SZ is the relevant value.

2) However, the man pages for 'ps' describe 'sz' as follows:

"The size in physical pages of the core image of the process, including text, data, and stack space"

What is missing is "shared memory RSS". So, for example, if you have a process that locks 1Gb of shared memory, then at least 1Gb of physical memory will not be accounted for when you add all SZ values as in your original post.

There are other types of memory pages that are included in the total user memory, but are not accounted for by adding all SZ values. Some of this user memory, as reported under HP-UX 11.00 is interpreted as system memory under HP-UX 11.11. See this link for more details:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x3f2a31ec5e34d711abdc0090277a778c,00.html

3) In Glance, you can look at various memory regions for each process, and compare these values with the output from 'ps'. On my system, for example, I have a Sybase process that uses 7Gb of shared memory, but SZ is reported as only 17 Mb ! The Glance's RSS, on the other hand, does try to account for the shared memory segment, but this is also inaccurate - the link of my previous post will give you more details about this problem.

Mladen
MANOJ SRIVASTAVA
Honored Contributor

Re: Yet another memory question.

Steve you may like to look at the C script attached , which gives the following output :


Memory Stat total used avail %used
physical 32764.0 8058.4 24705.6 25%
active virtual 531.3 128.9 402.4 24%
active real 597.0 136.0 461.0 23%
memory swap 26522.5 3738.2 22784.3 14%
device swap 2378.0 2365.5 12.5 99%

Re: Yet another memory question.

MANOJ,

Does your c program require anything special to compile? Having trouble with it. Thanks.