1838604 Members
4590 Online
110128 Solutions
New Discussion

swapinfo

 
Kit Chatsinchai
New Member

swapinfo

I need to find out how 'reserve' is computed.
tusc /usr/sbin/swapinfo -r shows that only
pstat_getvminfo and pstat_getswap. How is
'reserve'value computed from pst_vminfo and
pst_swapinfo structures?

I am support JVM on HPUX and need to print out
swapinfo when we are encountering 'out of memory' error; so, I can not use popen to capture /usr/sbin/swapinfo command, because there is not enough space to execute popen command.

Thanks,
Kit Chatsinchai
3 REPLIES 3
James Murtagh
Honored Contributor

Re: swapinfo

Hi Kit,

The basic formula to calculate the reserved field is quite simple, the implemtation in code not quite so however. I did start to write the C code but quickly realised I was basically writing swapinfo -r (as to be expected I suppose) which is not too clever. However, all the information you need can be found here:

http://www.docs.hp.com/hpux/onlinedocs/5965-4641/5965-4641.html

Look under the "Swap Space Management" section, specifically Figure 28. All the structures and definitions are defined in detail which you could use to code it.

In short the reserve field is calculated using the forumla:

reserve = swapspc_max - swapspc_cnt - (sum of used device + fs swap)

Now swapspc_max and swapspc_cnt are easily found from the pst_vminfo structure. The used device swap is harder to calculate but the information in Tables 26 & 27 can be used along with the theory described in the section.

Here is a unix cli example:

# swapinfo -tam|egrep "dev|reserve"
dev 156 45 111 29% 0 - 1 /dev/vg00/lvol2
reserve - 99 -99
# echo swapspc_max/D|adb -k /stand/vmunix /dev/kmem|tail -1
swapspc_max: 39936
# echo swapspc_cnt/D|adb -k /stand/vmunix /dev/kmem|tail -1
swapspc_cnt: 2118

swapspc_max = 39936 pages (4096 bytes) = 156 MB
swapspc_cnt = 2118 pages = 12MB
Used Device swap = 45 MB

reserve = 156 - 12 - 45 = 99MB

as shown above. Sorry I couldn't provide any code, good luck.

Regards,

James.
Bill Hassell
Honored Contributor

Re: swapinfo

"Out of memory" are almost always due to maxdsiz or asking for more memory (local or shared) than the excutable allows. You can verify this by simply adding a couple of Gbytes of filesystem swapspace temporarily. Let's start with maxdsiz: for 32 bit programs, it is the maximum amount of data space that can be requested from the system. The default value is far too small (64 megs), so change maxdsiz in the kernel to 900 megs, regen the kernel and reboot. Your programmers should be able to tell you how much RAM the program needs.

Standard 32bit programs can request up to 940 megs (assuming maxdsiz is 940 megs or larger). 64bit programs have no practical limit (hundreds of Gbytes) for local data. To go beyond 940 megs, you'll need to print the two white papers on memory and process management found in /usr/share/doc. Look specifically for EXEC_MAGIC, DEMAND_MAGIC, SHARE_MAGIC and SHMEM_MAGIC and comments about loader and chatr options.

Note that shared memory is quire different: 940 megs is the limit but this memory is mapped into a common memory addressing space and thus shared by many other uses including memory mapped files, shared libraries and shared memory segments. Fragmentation (for 32bit programs) is a big problem and commonly generates "out of memory" errors.

Note that programs which need large amounts of swap space will be VERY slow when they run.


Bill Hassell, sysadmin
Kit Chatsinchai
New Member

Re: swapinfo

James,
Thank you very much for your help. What I did not
mentioned was that this was related to a Java critical JAG defect that I am fixing.

Many thanks,
Kit Chatsinchai