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 .sp
 160 .LP
 161 All but \fBMEMINFO_VLGRP\fR and \fBMEMINFO_VPAGESIZE\fR require the
 162 \fBPRIV_PROC_MEMINFO\fR privilege.
 163 
 164 .SH RETURN VALUES
 165 .LP
 166 Upon successful completion \fBmeminfo()\fR returns 0. Otherwise \(mi1 is
 167 returned and \fBerrno\fR is set to indicate the error.
 168 .SH ERRORS
 169 .LP
 170 The \fBmeminfo()\fR function will fail if:
 171 .sp
 172 .ne 2
 173 .na
 174 \fB\fBEFAULT\fR\fR
 175 .ad
 176 .RS 10n
 177 The area pointed to by \fIoutdata\fR or \fIvalidity\fR could not be written, or
 178 the data pointed to by \fIinfo_req\fR or \fIinaddr\fR could not be read.
 179 .RE
 180 
 181 .sp
 182 .ne 2
 183 .na
 184 \fB\fBEINVAL\fR\fR
 185 .ad
 186 .RS 10n
 187 The value of \fIinfo_count\fR is greater than 31 or less than 1, or the value
 188 of \fIaddr_count\fR is less than 1.
 189 .RE
 190 
 191 .SH EXAMPLES
 192 .LP
 193 \fBExample 1 \fRPrint physical pages and page sizes corresponding to a set of
 194 virtual addresses.
 195 .sp
 196 .LP
 197 The following example prints the physical pages and page sizes corresponding to
 198 a set of virtual addresses.
 199 
 200 .sp
 201 .in +2
 202 .nf
 203 void
 204 print_info(void **addrvec, int how_many)
 205 {
 206     static const uint_t info[] = {
 207         MEMINFO_VPHYSICAL,
 208         MEMINFO_VPAGESIZE
 209     };
 210 
 211     int info_num = sizeof (info) / sizeof (info[0]);
 212     int i;
 213 
 214     uint64_t *inaddr = alloca(sizeof (uint64_t) * how_many);
 215     uint64_t *outdata = alloca(sizeof (uint64_t) * how_many * info_num);
 216     uint_t *validity = alloca(sizeof (uint_t) * how_many);
 217 
 218     for (i = 0; i < how_many; i++)
 219         inaddr[i] = (uint64_t)addrvec[i];
 220 
 221     if (meminfo(inaddr, how_many, info, info_num, outdata,
 222                 validity) < 0) {
 223         perror("meminfo");
 224         return;
 225     }
 226 
 227     for (i = 0; i < how_many; i++) {
 228         if ((validity[i] & 1) == 0)
 229             printf("address 0x%llx not part of address space\en",
 230                 inaddr[i]);
 231 
 232         else if ((validity[i] & 2) == 0)
 233             printf("address 0x%llx has no physical page "
 234                 "associated with it\en", inaddr[i]);
 235 
 236         else {
 237             char buff[80];
 238             if ((validity[i] & 4) == 0)
 239                 strcpy(buff, "<Unknown>");
 240             else
 241                 sprintf(buff, "%lld",
 242                     outdata[i * info_num + 1]);
 243 
 244             printf("address 0x%llx is backed by physical "
 245                 "page 0x%llx of size %s\en",
 246                 inaddr[i], outdata[i * info_num], buff);
 247         }
 248     }
 249 }
 250 .fi
 251 .in -2
 252 
 253 .SH ATTRIBUTES
 254 .LP
 255 See \fBattributes\fR(5) for descriptions of the following attributes:
 256 .sp
 257 
 258 .sp
 259 .TS
 260 box;
 261 c | c
 262 l | l .
 263 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 264 _
 265 Interface Stability     Stable
 266 _
 267 MT-Level        Async-Signal-Safe
 268 .TE
 269 
 270 .SH SEE ALSO
 271 .LP
 272 \fBmemcntl\fR(2), \fBmmap\fR(2), \fBgethomelgroup\fR(3C),
 273 \fBgetpagesize\fR(3C), \fBmadvise\fR(3C), \fBsysconf\fR(3C),
 274 \fBattributes\fR(5), \fBprivileges\fR(5)