summaryrefslogtreecommitdiff
path: root/usr/src/man/man2/meminfo.2
blob: 797b91a2ef3cdb38607fb098f2109a7c4ccae20b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
'\" te
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 2015, Joyent, Inc.
.\" 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.
.\" 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.
.\" 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]
.TH MEMINFO 2 "Mar 10, 2015"
.SH NAME
meminfo \- provide information about memory
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/mman.h>

\fBint\fR \fBmeminfo\fR(\fBconst uint64_t\fR \fIinaddr\fR[], \fBint\fR \fIaddr_count\fR,
     \fBconst uint_t\fR \fIinfo_req\fR[], \fBint\fR \fIinfo_count\fR, \fBuint64_t\fR \fIoutdata\fR[],
     \fBuint_t\fR \fIvalidity\fR[]);
.fi

.SH PARAMETERS
.ne 2
.na
\fB\fIinaddr\fR\fR
.ad
.RS 14n
array of input addresses; the maximum number of addresses that can be processed
for each call is \fBMAX_MEMINFO_CNT\fR
.RE

.sp
.ne 2
.na
\fB\fIaddr_count\fR\fR
.ad
.RS 14n
number of addresses
.RE

.sp
.ne 2
.na
\fB\fIinfo_req\fR\fR
.ad
.RS 14n
array of types of information requested
.RE

.sp
.ne 2
.na
\fB\fIinfo_count\fR\fR
.ad
.RS 14n
number of pieces of information requested for each address in \fIinaddr\fR
.RE

.sp
.ne 2
.na
\fB\fIoutdata\fR\fR
.ad
.RS 14n
array into which results are placed; array size must be the product of
\fIinfo_count\fR and \fIaddr_count\fR
.RE

.sp
.ne 2
.na
\fB\fIvalidity\fR\fR
.ad
.RS 14n
array of size \fIaddr_count\fR containing bitwise result codes; 0th bit
evaluates validity of corresponding input address, 1st bit validity of response
to first member of \fIinfo_req\fR, and so on
.RE

.SH DESCRIPTION
.LP
The \fBmeminfo()\fR function provides information about virtual and physical
memory particular to the calling process.  The user or developer of performance
utilities can use this information to analyze system memory allocations and
develop a better understanding of the factors affecting application
performance.
.sp
.LP
The caller of \fBmeminfo()\fR can obtain the following types of information
about both virtual and physical memory.
.sp
.ne 2
.na
\fB\fBMEMINFO_VPHYSICAL\fR\fR
.ad
.RS 26n
physical address corresponding to virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VLGRP\fR\fR
.ad
.RS 26n
locality group of physical page corresponding to virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VPAGESIZE\fR\fR
.ad
.RS 26n
size of physical page corresponding to virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VREPLCNT\fR\fR
.ad
.RS 26n
number of replicated physical pages corresponding to specified virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VREPL\fR | \fIn\fR\fR
.ad
.RS 26n
\fIn\fRth physical replica of specified virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_VREPL_LGRP\fR | \fIn\fR\fR
.ad
.RS 26n
lgrp of \fIn\fRth physical replica of specified virtual address
.RE

.sp
.ne 2
.na
\fB\fBMEMINFO_PLGRP\fR\fR
.ad
.RS 26n
locality group of specified physical address
.RE

.sp
.LP
All but \fBMEMINFO_VLGRP\fR and \fBMEMINFO_VPAGESIZE\fR require the
\fBPRIV_PROC_MEMINFO\fR privilege.

.SH RETURN VALUES
.LP
Upon successful completion \fBmeminfo()\fR returns 0. Otherwise \(mi1 is
returned and \fBerrno\fR is set to indicate the error.
.SH ERRORS
.LP
The \fBmeminfo()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEFAULT\fR\fR
.ad
.RS 10n
The area pointed to by \fIoutdata\fR or \fIvalidity\fR could not be written, or
the data pointed to by \fIinfo_req\fR or \fIinaddr\fR could not be read.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
The value of \fIinfo_count\fR is greater than 31 or less than 1, or the value
of \fIaddr_count\fR is less than 1.
.RE

.SH EXAMPLES
.LP
\fBExample 1 \fRPrint physical pages and page sizes corresponding to a set of
virtual addresses.
.sp
.LP
The following example prints the physical pages and page sizes corresponding to
a set of virtual addresses.

.sp
.in +2
.nf
void
print_info(void **addrvec, int how_many)
{
    static const uint_t info[] = {
        MEMINFO_VPHYSICAL,
        MEMINFO_VPAGESIZE
    };

    int info_num = sizeof (info) / sizeof (info[0]);
    int i;

    uint64_t *inaddr = alloca(sizeof (uint64_t) * how_many);
    uint64_t *outdata = alloca(sizeof (uint64_t) * how_many * info_num);
    uint_t *validity = alloca(sizeof (uint_t) * how_many);

    for (i = 0; i < how_many; i++)
        inaddr[i] = (uint64_t)addrvec[i];

    if (meminfo(inaddr, how_many, info, info_num, outdata,
                validity) < 0) {
        perror("meminfo");
        return;
    }

    for (i = 0; i < how_many; i++) {
        if ((validity[i] & 1) == 0)
            printf("address 0x%llx not part of address space\en",
                inaddr[i]);

        else if ((validity[i] & 2) == 0)
            printf("address 0x%llx has no physical page "
                "associated with it\en", inaddr[i]);

        else {
            char buff[80];
            if ((validity[i] & 4) == 0)
                strcpy(buff, "<Unknown>");
            else
                sprintf(buff, "%lld",
                    outdata[i * info_num + 1]);

            printf("address 0x%llx is backed by physical "
                "page 0x%llx of size %s\en",
                inaddr[i], outdata[i * info_num], buff);
        }
    }
}
.fi
.in -2

.SH ATTRIBUTES
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Stable
_
MT-Level	Async-Signal-Safe
.TE

.SH SEE ALSO
.LP
\fBmemcntl\fR(2), \fBmmap\fR(2), \fBgethomelgroup\fR(3C),
\fBgetpagesize\fR(3C), \fBmadvise\fR(3C), \fBsysconf\fR(3C),
\fBattributes\fR(5), \fBprivileges\fR(5)