Using meminfo
()
The meminfo
()
function gives the calling process information
about the virtual memory and physical memory that the system has allocated to that
process.
#include <sys/types.h> #include <sys/mman.h> int meminfo(const uint64_t inaddr[], int addr_count, const uint_t info_req[], int info_count, uint64_t outdata[], uint_t validity[]);
The meminfo
()
function can return the following types of
information:
-
MEMINFO_VPHYSICAL
-
The physical memory address corresponding to the given virtual address
-
MEMINFO_VLGRP
-
The lgroup to which the physical page corresponding to the given virtual address belongs
-
MEMINFO_VPAGESIZE
-
The size of the physical page corresponding to the given virtual address
-
MEMINFO_VREPLCNT
-
The number of replicated physical pages that correspond to the given virtual address
-
MEMINFO_VREPL|n
-
The nth physical replica of the given virtual address
-
MEMINFO_VREPL_LGRP|n
-
The lgroup to which the nth physical replica of the given virtual address belongs
-
MEMINFO_PLGRP
-
The lgroup to which the given physical address belongs
-
MEMINFO_VADI
-
Application Data Integrity (ADI) status for the specified virtual address. If the status is
0
, ADI is disabled. If the status is1
, ADI is enabled.
The meminfo
()
function takes the following parameters:
-
inaddr
-
An array of input addresses.
-
addr_count
-
The number of addresses that are passed to
meminfo
() function. -
info_req
-
An array that lists the types of information that are being requested.
-
info_count
-
The number of pieces of information that are requested for each address in the
inaddr
array. -
outdata
-
An array where the
meminfo
() function places the results. The array's size is equal to the product of the values of theinfo_req
andaddr_count
parameters. -
validity
-
An array of size equal to the value of the
addr_count
parameter. Thevalidity
array contains bitwise result codes. The 0th bit of the result code evaluates the validity of the corresponding input address. Each successive bit in the result code evaluates the validity of the response to the members of theinfo_req
array in turn.
For all types of information except MEMINFO_VADI
, any addresses
in the inaddr
array that have never been referenced will not
have any information about them returned by the meminfo
()
function. This can also occur if an address has not been referenced recently and the
physical page that had been backing that address has been paged out. Information for
MEMINFO_VADI
is always returned.
The meminfo
()
function returns EFAULT
when the area of memory to which the outdata
or
validity
arrays point cannot be written to. The
meminfo
()
function returns EFAULT
when
the area of memory to which the info_req
or
inaddr
arrays point cannot be read from. The
meminfo
()
function returns EINVAL
when
the value of info_count
exceeds 31 or is less than 1. The
meminfo
()
function returns EINVAL
when
the value of addr_count
is less than zero.
Example 4-6 Using meminfo
()
to Print Physical Pages and Page Sizes of a Set of Virtual Addresses
void print_info(void **addrvec, int how_many) { static const int info[] = { MEMINFO_VPHYSICAL, MEMINFO_VPAGESIZE}; uint64_t * inaddr = alloca(sizeof(uint64_t) * how_many); uint64_t * outdata = alloca(sizeof(uint64_t) * how_many * 2; uint_t * validity = alloca(sizeof(uint_t) * how_many); int i; for (i = 0; i < how_many; i++) inaddr[i] = (uint64_t *)addrvec[i]; if (meminfo(inaddr, how_many, info, sizeof (info)/ sizeof(info[0]), outdata, validity) < 0) for (i = 0; i < how_many; i++) { if ((validity[i] & 1) == 0) printf("address 0x%llx not part of address space\n", inaddr[i]); if ((validity[i] & 2) == 0) printf("address 0x%llx has no physical page associated with it\n", inaddr[i]); else { char buff[80]; if (validity[i] & 4 == 0) strlcpy(buff, "<Unknown>", sizeof(buff)); else snprintf(buff, sizeof(buff), "%lld", outdata[i * 2 + 1]); printf("address 0x%llx is backed by physical page 0x%llx of size %s\n", inaddr[i], outdata[i * 2], buff); } } }