1 '\" te
   2 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
   3 .\" Copyright 2015, Joyent, Inc.
   4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   7 .TH MEMINFO 2 "Mar 10, 2015"
   8 .SH NAME
   9 meminfo \- provide information about memory
  10 .SH SYNOPSIS
  11 .LP
  12 .nf
  13 #include <sys/types.h>
  14 #include <sys/mman.h>
  15 
  16 \fBint\fR \fBmeminfo\fR(\fBconst uint64_t\fR \fIinaddr\fR[], \fBint\fR \fIaddr_count\fR,
  17      \fBconst uint_t\fR \fIinfo_req\fR[], \fBint\fR \fIinfo_count\fR, \fBuint64_t\fR \fIoutdata\fR[],
  18      \fBuint_t\fR \fIvalidity\fR[]);
  19 .fi
  20 
  21 .SH PARAMETERS
  22 .ne 2
  23 .na
  24 \fB\fIinaddr\fR\fR
  25 .ad
  26 .RS 14n
  27 array of input addresses; the maximum number of addresses that can be processed
  28 for each call is \fBMAX_MEMINFO_CNT\fR
  29 .RE
  30 
  31 .sp
  32 .ne 2
  33 .na
  34 \fB\fIaddr_count\fR\fR
  35 .ad
  36 .RS 14n
  37 number of addresses
  38 .RE
  39 
  40 .sp
  41 .ne 2
  42 .na
  43 \fB\fIinfo_req\fR\fR
  44 .ad
  45 .RS 14n
  46 array of types of information requested
  47 .RE
  48 
  49 .sp
  50 .ne 2
  51 .na
  52 \fB\fIinfo_count\fR\fR
  53 .ad
  54 .RS 14n
  55 number of pieces of information requested for each address in \fIinaddr\fR
  56 .RE
  57 
  58 .sp
  59 .ne 2
  60 .na
  61 \fB\fIoutdata\fR\fR
  62 .ad
  63 .RS 14n
  64 array into which results are placed; array size must be the product of
  65 \fIinfo_count\fR and \fIaddr_count\fR
  66 .RE
  67 
  68 .sp
  69 .ne 2
  70 .na
  71 \fB\fIvalidity\fR\fR
  72 .ad
  73 .RS 14n
  74 array of size \fIaddr_count\fR containing bitwise result codes; 0th bit
  75 evaluates validity of corresponding input address, 1st bit validity of response
  76 to first member of \fIinfo_req\fR, and so on
  77 .RE
  78 
  79 .SH DESCRIPTION
  80 .LP
  81 The \fBmeminfo()\fR function provides information about virtual and physical
  82 memory particular to the calling process.  The user or developer of performance
  83 utilities can use this information to analyze system memory allocations and
  84 develop a better understanding of the factors affecting application
  85 performance.
  86 .sp
  87 .LP
  88 The caller of \fBmeminfo()\fR can obtain the following types of information
  89 about both virtual and physical memory.
  90 .sp
  91 .ne 2
  92 .na
  93 \fB\fBMEMINFO_VPHYSICAL\fR\fR
  94 .ad
  95 .RS 26n
  96 physical address corresponding to virtual address
  97 .RE
  98 
  99 .sp
 100 .ne 2
 101 .na
 102 \fB\fBMEMINFO_VLGRP\fR\fR
 103 .ad
 104 .RS 26n
 105 locality group of physical page corresponding to virtual address
 106 .RE
 107 
 108 .sp
 109 .ne 2
 110 .na
 111 \fB\fBMEMINFO_VPAGESIZE\fR\fR
 112 .ad
 113 .RS 26n
 114 size of physical page corresponding to virtual address
 115 .RE
 116 
 117 .sp
 118 .ne 2
 119 .na
 120 \fB\fBMEMINFO_VREPLCNT\fR\fR
 121 .ad
 122 .RS 26n
 123 number of replicated physical pages corresponding to specified virtual address
 124 .RE
 125 
 126 .sp
 127 .ne 2
 128 .na
 129 \fB\fBMEMINFO_VREPL\fR | \fIn\fR\fR
 130 .ad
 131 .RS 26n
 132 \fIn\fRth physical replica of specified virtual address
 133 .RE
 134 
 135 .sp
 136 .ne 2
 137 .na
 138 \fB\fBMEMINFO_VREPL_LGRP\fR | \fIn\fR\fR
 139 .ad
 140 .RS 26n
 141 lgrp of \fIn\fRth physical replica of specified virtual address
 142 .RE
 143 
 144 .sp
 145 .ne 2
 146 .na
 147 \fB\fBMEMINFO_PLGRP\fR\fR
 148 .ad
 149 .RS 26n
 150 locality group of specified physical address
 151 .RE
 152 
 153 .sp
 154 .LP
 155 All but \fBMEMINFO_VLGRP\fR and \fBMEMINFO_VPAGESIZE\fR require the
 156 \fBPRIV_PROC_MEMINFO\fR privilege.
 157 
 158 .SH RETURN VALUES
 159 .LP
 160 Upon successful completion \fBmeminfo()\fR returns 0. Otherwise \(mi1 is
 161 returned and \fBerrno\fR is set to indicate the error.
 162 .SH ERRORS
 163 .LP
 164 The \fBmeminfo()\fR function will fail if:
 165 .sp
 166 .ne 2
 167 .na
 168 \fB\fBEFAULT\fR\fR
 169 .ad
 170 .RS 10n
 171 The area pointed to by \fIoutdata\fR or \fIvalidity\fR could not be written, or
 172 the data pointed to by \fIinfo_req\fR or \fIinaddr\fR could not be read.
 173 .RE
 174 
 175 .sp
 176 .ne 2
 177 .na
 178 \fB\fBEINVAL\fR\fR
 179 .ad
 180 .RS 10n
 181 The value of \fIinfo_count\fR is greater than 31 or less than 1, or the value
 182 of \fIaddr_count\fR is less than 1.
 183 .RE
 184 
 185 .SH EXAMPLES
 186 .LP
 187 \fBExample 1 \fRPrint physical pages and page sizes corresponding to a set of
 188 virtual addresses.
 189 .sp
 190 .LP
 191 The following example prints the physical pages and page sizes corresponding to
 192 a set of virtual addresses.
 193 
 194 .sp
 195 .in +2
 196 .nf
 197 void
 198 print_info(void **addrvec, int how_many)
 199 {
 200     static const uint_t info[] = {
 201         MEMINFO_VPHYSICAL,
 202         MEMINFO_VPAGESIZE
 203     };
 204 
 205     int info_num = sizeof (info) / sizeof (info[0]);
 206     int i;
 207 
 208     uint64_t *inaddr = alloca(sizeof (uint64_t) * how_many);
 209     uint64_t *outdata = alloca(sizeof (uint64_t) * how_many * info_num);
 210     uint_t *validity = alloca(sizeof (uint_t) * how_many);
 211 
 212     for (i = 0; i < how_many; i++)
 213         inaddr[i] = (uint64_t)addrvec[i];
 214 
 215     if (meminfo(inaddr, how_many, info, info_num, outdata,
 216                 validity) < 0) {
 217         perror("meminfo");
 218         return;
 219     }
 220 
 221     for (i = 0; i < how_many; i++) {
 222         if ((validity[i] & 1) == 0)
 223             printf("address 0x%llx not part of address space\en",
 224                 inaddr[i]);
 225 
 226         else if ((validity[i] & 2) == 0)
 227             printf("address 0x%llx has no physical page "
 228                 "associated with it\en", inaddr[i]);
 229 
 230         else {
 231             char buff[80];
 232             if ((validity[i] & 4) == 0)
 233                 strcpy(buff, "<Unknown>");
 234             else
 235                 sprintf(buff, "%lld",
 236                     outdata[i * info_num + 1]);
 237 
 238             printf("address 0x%llx is backed by physical "
 239                 "page 0x%llx of size %s\en",
 240                 inaddr[i], outdata[i * info_num], buff);
 241         }
 242     }
 243 }
 244 .fi
 245 .in -2
 246 
 247 .SH ATTRIBUTES
 248 .LP
 249 See \fBattributes\fR(5) for descriptions of the following attributes:
 250 .sp
 251 
 252 .sp
 253 .TS
 254 box;
 255 c | c
 256 l | l .
 257 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 258 _
 259 Interface Stability     Stable
 260 _
 261 MT-Level        Async-Signal-Safe
 262 .TE
 263 
 264 .SH SEE ALSO
 265 .LP
 266 \fBmemcntl\fR(2), \fBmmap\fR(2), \fBgethomelgroup\fR(3C),
 267 \fBgetpagesize\fR(3C), \fBmadvise\fR(3C), \fBsysconf\fR(3C),
 268 \fBattributes\fR(5), \fBprivileges\fR(5)