Operating System - HP-UX
1834490 Members
3198 Online
110067 Solutions
New Discussion

PSTAT Getting Swap Information

 
SOLVED
Go to solution
Philip A. Reyniers
Occasional Advisor

PSTAT Getting Swap Information

I yeild to the experts, the following code demonstrates how to obtain all swap information from a given HPUX 11.x PA-Risc server. It leverages the pstat routines to accomplish the task. However, I have on REALLY NAGGING question that I hope someone can answer. How do I obtain the lvol name for device swap. For Instance, my output is as follows:

Total number of swap devices: 2
-------------------------------------------------------
swap_device_flags=3
swap_device_flags=SW_ENABLED|SW_BLOCK
swap_device_priority=1
swap_device_major=64
swap_device_minor=0x000002
swap_device_blocks_enabled=786432
swap_device_blocks_available=786432
swap_device_fs_mount=
swap_device_swap_chunk_size=2048
-------------------------------------------------------
swap_device_flags=5
swap_device_flags=SW_ENABLED|SW_FS
swap_device_priority=2
swap_device_major=0
swap_device_minor=0x000000
swap_device_blocks_enabled=0
swap_device_blocks_available=795108720
swap_device_fs_mount=/depot/paging
swap_device_swap_chunk_size=2048

You will notice that if the swap is File System Swap the mount point (swap_device_fs_mount) is listed but if the swap is device swap it is not. How do I get this information for device swap?

You will notice that swapinfo is able to get this information in the following output:

server_name# swapinfo -tam
Mb Mb Mb PCT START/ Mb
TYPE AVAIL USED FREE USED LIMIT RESERVE PRI NAME
dev 768 0 768 0% 0 - 1 /dev/vg00/lvol2
localfs 10 0 10 0% 10 0 2 /depot/paging
... REST OF OUTPUT REMOVED

**********************START SOURCE CODE**********************
#include
#include
#include
#include

#define SW_ENABLED_SW_BLOCK 0x03
#define SW_ENABLED_SW_FS 0x05

int main ( void ) {
struct pst_swapinfo *swapInfo;
struct pst_static *pstStatic;
unsigned long swapCount;

pstStatic = new pst_static;
memset( pstStatic, 0, sizeof( pst_static ) );
if( pstat_getstatic( pstStatic, sizeof( pst_static ), (size_t)1, 0 ) == -1 ) {
cerr << "Failed to get static information: " << strerror( errno ) << endl;
delete [] pstStatic;
return 4;
}

swapCount = 0;
swapInfo = new pst_swapinfo[ pstStatic->pst_swapinfo_size ];
memset( swapInfo, 0, sizeof( pst_swapinfo ) );

swapCount = pstat_getswap( swapInfo, sizeof( pst_swapinfo ), pstStatic->pst_swapinfo_size, 0 );
if( swapCount == -1 ) {
cerr << "Failed to get swap information: " << strerror( errno ) << endl;
delete [] pstStatic;
delete [] swapInfo;
return 4;
}

cout << "Total number of swap devices: " << swapCount << endl;
for( unsigned long i = 0; i < swapCount; i++ ) {
printf( "-------------------------------------------------------\n" );
printf( "swap_device_flags=%x\n", swapInfo[i].pss_flags );
switch( swapInfo[i].pss_flags ){
case SW_ENABLED: // 0x01
printf( "swap_device_flags=SW_ENABLED\n" );
break;
case SW_BLOCK: // 0x02
printf( "swap_device_flags=SW_BLOCK\n" );
break;
case SW_ENABLED_SW_BLOCK: // 0x03
printf( "swap_device_flags=SW_ENABLED|SW_BLOCK\n" );
break;
case SW_FS: // 0x04
printf( "swap_device_flags=SW_FS\n" );
break;
case SW_ENABLED_SW_FS: // 0x05
printf( "swap_device_flags=SW_ENABLED|SW_FS\n" );
break;
default:
printf( "swap_device_flags=DISABLED\n" );
break;
}
printf( "swap_device_priority=%ld\n", swapInfo[i].pss_priority );
printf( "swap_device_major=%ld\n", swapInfo[i].pss_un.Pss_blk.Pss_dev.psd_major );
printf( "swap_device_minor=0x%06x\n", swapInfo[i].pss_un.Pss_blk.Pss_dev.psd_minor );
printf( "swap_device_blocks_enabled=%ld\n", swapInfo[i].pss_un.Pss_blk.Pss_nblks );
printf( "swap_device_blocks_available=%ld\n", swapInfo[i].pss_un.Pss_blk.Pss_nblksavail );
/////////////////////////////////////////////////////////////////////////////////////////
// Pss_mntpt is used only for file system swap mounts. SW_FS flag is true. //
/////////////////////////////////////////////////////////////////////////////////////////
printf( "swap_device_fs_mount=%s\n", swapInfo[i].pss_un.Pss_fs.Pss_mntpt );
printf( "swap_device_swap_chunk_size=%ld\n", swapInfo[i].pss_swapchunk );
}

delete [] pstStatic;
delete [] swapInfo;
return 0;
}
**********************STOP SOURCE CODE**********************

To all, I have looked at the pstat include files and their supporting includes and unless I have missed something, I just do not see the move.

Thanks in advance to all that reply.

Sincerely,

Phil
If it is not broken leave it alone, if you have time try to improve it, and if you do not care then get another job.
3 REPLIES 3
Mark Grant
Honored Contributor
Solution

Re: PSTAT Getting Swap Information

Interesting question!

This could do with a bit more thought but one thing that comes to mind is the major and minor device numbers. The major number will always be 64 if it's logical volume swap. However, the minor number will be your clue. In your example, the minor number is 0x00002. This means that it is in the volume group whose "group" file is 0x000000 (probably vg00) and it is the second logical volume.

There might be a tidy way to do this but if you can look at all the group files (ls -l /dev/vg*/group) you will be able to determine which volume group the swap is in by reference to the first part of the minor device number, and which logical volume it is by the last part.
Never preceed any demonstration with anything more predictive than "watch this"
Philip A. Reyniers
Occasional Advisor

Re: PSTAT Getting Swap Information

Mark, in theory, that applies because remember that first a volume group can have any name assisgned to it. Second, a logical volume can have a user defined name assigned to it. Third, all of the special files can have thier minor number set to a user defined value, with in reason, as long as they are not duplicated.

However, I did a little more research and wished I had read the manpage for swapinfo a little closer. You are correct in saying that the major and minor numbers are the key to solving the problem. Here is a snip from the swapinfo man page:
*******************MAN SWAPINFO SNIP*******************
NAME
For device paging areas, the block special file name whose major and minor numbers match the device's ID. The swapinfo command searches the /dev tree to find device names. If no matching block special file is found, swapinfo prints the device ID (major and minor values), for example, 28,0x15000.

For file system swap areas, NAME is the name of a directory on the file system in which the paging files are stored.
*******************MAN SWAPINFO SNIP*******************

It appears that the HP delelopers like stating an entire directory and evaluating every file in that directory. If one performs a tusc/truss of the swapinfo command it proves it. They actually stat all the device files in /dev. One would think that what I am asking would be built into a simple function to get the device name from something like a major, minor number combination or even the hardware path( see the pstat diskinfo structure ). It appears just plain silly that HP has not exposed any API's or functions to simplify development efforts.

Thanks for your response, I am giving you 10 Pts because you were the only one to reply.

If there are others out there that have a better idea or have seen a different approach to converting major minor combination or hardware path into device file name please chime in to the matter.

Phil
If it is not broken leave it alone, if you have time try to improve it, and if you do not care then get another job.
Mark Grant
Honored Contributor

Re: PSTAT Getting Swap Information

THanks for the additional information Phil, this was an enjoyable problem :)
Never preceed any demonstration with anything more predictive than "watch this"