perfstat_memory_total Interface
The perfstat_memory_total interface returns a perfstat_memory_total_t structure, which is defined in the libperfstat.h file.
Selected fields from the perfstat_memory_total_t structure include:
Item | Descriptor |
---|---|
bytes_coalesced | Number of bytes of the calling partition’s logical real memory coalesced |
bytes_coalesced_mempool | Number of bytes of logical real memory coalesced in the calling partition’s memory pool if the calling partition is authorized to see pool wide statistics else, set to zero. |
virt_total | Amount of virtual memory (in units of 4 KB pages) |
real_total | Amount of real memory (in units of 4 KB pages) |
real_free | Amount of free real memory (in units of 4 KB pages) |
real_pinned | Amount of pinned memory (in units of 4 KB pages) |
pgins | Number of pages paged in |
pgouts | Number of pages paged out |
pgsp_total | Total amount of paging space (in units of 4 KB pages) |
pgsp_free | Amount of free paging space (in units of 4 KB pages) |
pgsp_rsvd | Amount of reserved paging space (in units of 4 KB pages) |
Note: Page coalescing is a transparent operation wherein the hypervisor detects duplicate
pages, directs all user reads to a single copy, and can reclaim other duplicate physical memory
pages.
Several other memory-related metrics (such as amount of paging space paged in and out,
and amount of system memory) are also returned. For a complete list, see the
perfstat_memory_total_t section of the libperfstat.h header file in Files Reference.The preceding program emulates vmstat's behavior
and also shows an example of how the perfstat_memory_total interface
is used:
#include <stdio.h>
#include <libperfstat.h>
int main(int argc, char* argv[]) {
perfstat_memory_total_t minfo;
int rc;
rc = perfstat_memory_total(NULL, &minfo, sizeof(perfstat_memory_total_t), 1);
if (rc != 1) {
perror("perfstat_memory_total");
exit(-1);
}
printf("Memory statistics\n");
printf("-----------------\n");
printf("real memory size : %llu MB\n",
minfo.real_total*4096/1024/1024);
printf("reserved paging space : %llu MB\n",minfo.pgsp_rsvd);
printf("virtual memory size : %llu MB\n",
minfo.virt_total*4096/1024/1024);
printf("number of free pages : %llu\n",minfo.real_free);
printf("number of pinned pages : %llu\n",minfo.real_pinned);
printf("number of pages in file cache : %llu\n",minfo.numperm);
printf("total paging space pages : %llu\n",minfo.pgsp_total);
printf("free paging space pages : %llu\n", minfo.pgsp_free);
printf("used paging space : %3.2f%%\n",
(float)(minfo.pgsp_total-minfo.pgsp_free)*100.0/
(float)minfo.pgsp_total);
perfstat_memory_total(NULL, &minfo, sizeof(perfstat_memory_total_t), 1);
printf("Memory statistics\n");
printf("-----------------\n");
printf("real memory size : %llu MB\n",
minfo.real_total*4096/1024/1024);
printf("reserved paging space : %llu MB\n",minfo.pgsp_rsvd);
printf("virtual memory size : %llu MB\n",
minfo.virt_total*4096/1024/1024);
printf("number of free pages : %llu\n",minfo.real_free);
printf("number of pinned pages : %llu\n",minfo.real_pinned);
printf("number of pages in file cache : %llu\n",minfo.numperm);
printf("total paging space pages : %llu\n",minfo.pgsp_total);
printf("free paging space pages : %llu\n", minfo.pgsp_free);
printf("used paging space : %3.2f%%\n",
(float)(minfo.pgsp_total-minfo.pgsp_free)*100.0/
(float)minfo.pgsp_total);
printf("number of paging space page ins : %llu\n",minfo.pgspins);
printf("number of paging space page outs : %llu\n",minfo.pgspouts);
printf("number of page ins : %llu\n",minfo.pgins);
printf("number of page outs : %llu\n",minfo.pgouts);
}
The preceding program produces output such as the following:
Memory statistics
-----------------
real memory size : 256 MB
reserved paging space : 512 MB
virtual memory size : 768 MB
number of free pages : 32304
number of pinned pages : 6546
number of pages in file cache : 12881
total paging space pages : 131072
free paging space pages : 129932
used paging space : 0.87%
number of paging space page ins : 0
number of paging space page outs : 0
number of page ins : 20574
number of page outs : 92508
The preceding
program emulates vmstat's behavior and also shows how perfstat_memory_total is
used.