HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- PSTAT Getting Swap Information
Operating System - HP-UX
1834490
Members
3198
Online
110067
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2004 12:24 PM
02-16-2004 12:24 PM
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
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.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2004 07:41 PM
02-16-2004 07:41 PM
Solution
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.
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2004 01:06 AM
02-17-2004 01:06 AM
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
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2004 04:55 AM
02-17-2004 04:55 AM
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"
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP