close_range.2: Glibc added a wrapper recently
[man-pages.git] / man2 / mincore.2
blob38ee7d6fabaf5817c2f07a297c4919793aac1247
1 .\" Copyright (C) 2001 Bert Hubert <ahu@ds9a.nl>
2 .\" and Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Created Sun Jun 3 17:23:32 2001 by bert hubert <ahu@ds9a.nl>
27 .\" Slightly adapted, following comments by Hugh Dickins, aeb, 2001-06-04.
28 .\" Modified, 20 May 2003, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Modified, 30 Apr 2004, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\" 2005-04-05 mtk, Fixed error descriptions
31 .\"     after message from <gordon.jin@intel.com>
32 .\" 2007-01-08 mtk, rewrote various parts
33 .\"
34 .TH MINCORE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
35 .SH NAME
36 mincore \- determine whether pages are resident in memory
37 .SH SYNOPSIS
38 .nf
39 .B #include <sys/mman.h>
40 .PP
41 .BI "int mincore(void *" addr ", size_t " length ", unsigned char *" vec );
42 .fi
43 .PP
44 .RS -4
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .RE
48 .PP
49 .BR mincore ():
50 .nf
51     Since glibc 2.19:
52         _DEFAULT_SOURCE
53     Glibc 2.19 and earlier:
54         _BSD_SOURCE || _SVID_SOURCE
55 .fi
56 .SH DESCRIPTION
57 .BR mincore ()
58 returns a vector that indicates whether pages
59 of the calling process's virtual memory are resident in core (RAM),
60 and so will not cause a disk access (page fault) if referenced.
61 The kernel returns residency information about the pages
62 starting at the address
63 .IR addr ,
64 and continuing for
65 .I length
66 bytes.
67 .PP
68 The
69 .I addr
70 argument must be a multiple of the system page size.
71 The
72 .I length
73 argument need not be a multiple of the page size,
74 but since residency information is returned for whole pages,
75 .I length
76 is effectively rounded up to the next multiple of the page size.
77 One may obtain the page size
78 .RB ( PAGE_SIZE )
79 using
80 .IR sysconf(_SC_PAGESIZE) .
81 .PP
82 The
83 .I vec
84 argument must point to an array containing at least
85 .I "(length+PAGE_SIZE\-1) / PAGE_SIZE"
86 bytes.
87 On return,
88 the least significant bit of each byte will be set if
89 the corresponding page is currently resident in memory,
90 and be clear otherwise.
91 (The settings of the other bits in each byte are undefined;
92 these bits are reserved for possible later use.)
93 Of course the information returned in
94 .I vec
95 is only a snapshot: pages that are not
96 locked in memory can come and go at any moment, and the contents of
97 .I vec
98 may already be stale by the time this call returns.
99 .SH RETURN VALUE
100 On success,
101 .BR mincore ()
102 returns zero.
103 On error, \-1 is returned, and
104 .I errno
105 is set to indicate the error.
106 .SH ERRORS
107 .B EAGAIN
108 kernel is temporarily out of resources.
110 .B EFAULT
111 .I vec
112 points to an invalid address.
114 .B EINVAL
115 .I addr
116 is not a multiple of the page size.
118 .B ENOMEM
119 .I length
120 is greater than
121 .RI ( TASK_SIZE " \- " addr ).
122 (This could occur if a negative value is specified for
123 .IR length ,
124 since that value will be interpreted as a large
125 unsigned integer.)
126 In Linux 2.6.11 and earlier, the error
127 .B EINVAL
128 was returned for this condition.
130 .B ENOMEM
131 .I addr
133 .I addr
135 .I length
136 contained unmapped memory.
137 .SH VERSIONS
138 Available since Linux 2.3.99pre1 and glibc 2.2.
139 .SH CONFORMING TO
140 .BR mincore ()
141 is not specified in POSIX.1,
142 and it is not available on all UNIX implementations.
143 .\" It is on at least NetBSD, FreeBSD, OpenBSD, Solaris 8,
144 .\" AIX 5.1, SunOS 4.1
145 .\" .SH HISTORY
146 .\" The
147 .\" .BR mincore ()
148 .\" function first appeared in 4.4BSD.
149 .SH BUGS
150 Before kernel 2.6.21,
151 .BR mincore ()
152 did not return correct information for
153 .B MAP_PRIVATE
154 mappings, or for nonlinear mappings (established using
155 .BR remap_file_pages (2)).
156 .\" Linux (up to now, 2.6.5),
157 .\" .B mincore
158 .\" does not return correct information for MAP_PRIVATE mappings:
159 .\" for a MAP_PRIVATE file mapping,
160 .\" .B mincore
161 .\" returns the residency of the file pages, rather than any
162 .\" modified process-private pages that have been copied on write;
163 .\" for a MAP_PRIVATE mapping of
164 .\" .IR /dev/zero ,
165 .\" .B mincore
166 .\" always reports pages as nonresident;
167 .\" and for a MAP_PRIVATE, MAP_ANONYMOUS mapping,
168 .\" .B mincore
169 .\" always fails with the error
170 .\" .BR ENOMEM .
171 .SH SEE ALSO
172 .BR fincore (1),
173 .BR madvise (2),
174 .BR mlock (2),
175 .BR mmap (2),
176 .BR posix_fadvise (2),
177 .BR posix_madvise (3)