perfstat_memory_page Interface

The perfstat_memory_page interface returns a set of structures of type perfstat_memory_page_t, which is defined in the libperfstat.h file.

Selected fields from the perfstat_memory_page_t structure include:
Item Descriptor
psize Page size in bytes
real_total Amount of real memory (in units of psize)
real_freesize Amount of free real memory (in units of psize)
real_pinned Amount of pinned memory (in units of psize multiplied by 4)
Pgins Number of pages paged in
Pgouts Number of pages paged out
Several other disk-adapter related metrics (such as the number of blocks read from and written to the adapter) are also returned. For a complete list of other disk-adapter-related metrics, see the perfstat_memory_page_t section in the libperfstat.h header file.
The following program shows an example of how the perfstat_memory_page interface is used:
#include <stdio.h> 
#include <stdlib.h>
#include <libperfstat.h>

int main (){
	int total_psizes, avail_psizes;
	perfstat_memory_page_t *psize_mem_values;
	perfstat_psize_t pagesize;
	int i;
	/*get the total number of page sizez */

	total_psizes = perfstat_memory_page(NULL, NULL, sizeof(perfstat_memory_page_t), 0);

	/*check for any error*/
    if(total_psizes < 1)
    {
        perror("do_initialization:"
               " Unable to retrieve the number of available pagesizes.");
        exit(-1);
    }

	/* allocate sufficient memory to store the structures */
	psize_mem_values = (perfstat_memory_page_t *)malloc(sizeof(perfstat_memory_page_t) * total_psizes);

	/*check for bad malloc */
    if(psize_mem_values == NULL)
    {
        perror("do_initialization: Unable to allocate sufficient"
               " memory for psize_mem_values buffer.");
        exit(-1);
    }

	pagesize.psize = FIRST_PSIZE;
   avail_psizes = perfstat_memory_page(&pagesize, psize_mem_values, sizeof(perfstat_memory_page_t), 
		total_psizes);

  /*check the return value for any error */

    if(avail_psizes < 1)
    {
        perror("display_psize_memory_stats: Unable to retrieve memory "
               "statistics for the available page sizes.");
        exit(-1);
   }

   for(i=0;i<avail_psizes;i++){
        printf("Page size in bytes=%llu\n",psize_mem_values[i].psize);
        printf("Number of real memory frames of this page size=%lld\n",psize_mem_values[i].real_total);
        printf("Number of pages on free list=%lld\n",psize_mem_values[i].real_free);
        printf("Number of pages pinned=%lld\n",psize_mem_values[i].real_pinned);
        printf("Number of pages in use=%lld\n",psize_mem_values[i].real_inuse);
        printf("Number of page faults =%lld\n",psize_mem_values[i].pgexct);
        printf("Number of pages paged in=%lld\n",psize_mem_values[i].pgins);
        printf("Number of pages paged out=%lld\n",psize_mem_values[i].pgouts);
        printf("\n");
   } 
	return 0;
}
The program displays an output that is similar to the following example output:
Page size in bytes=4096
Number of real memory frames of this page size=572640
Number of pages on free list=364101
Number of pages pinned=171770
Number of pages in use=208539
Number of page faults =1901334
Number of pages paged in=40569
Number of pages paged out=10381

Page size in bytes=65536
Number of real memory frames of this page size=29746
Number of pages on free list=24741
Number of pages pinned=4333
Number of pages in use=5005
Number of page faults =28495
Number of pages paged in=0
Number of pages paged out=0