-
Notifications
You must be signed in to change notification settings - Fork 0
/
fadvise64.html
336 lines (249 loc) · 10.1 KB
/
fadvise64.html
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:26:56 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>POSIX_FADVISE</title>
</head>
<body>
<h1 align="center">POSIX_FADVISE</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#BUGS">BUGS</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">posix_fadvise -
predeclare an access pattern for file data</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<fcntl.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>int
posix_fadvise(int</b> <i>fd</i><b>, off_t</b>
<i>offset</i><b>, off_t</b> <i>len</i><b>, int</b>
<i>advice</i><b>);</b></p>
<p style="margin-left:5%; margin-top: 1em">Feature Test
Macro Requirements for glibc (see
<b>feature_test_macros</b>(7)):</p>
<p style="margin-left:11%; margin-top: 1em"><b>posix_fadvise</b>():</p>
<p style="margin-left:17%;">_POSIX_C_SOURCE >= 200112L</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Programs can
use <b>posix_fadvise</b>() to announce an intention to
access file data in a specific pattern in the future, thus
allowing the kernel to perform appropriate
optimizations.</p>
<p style="margin-left:11%; margin-top: 1em">The
<i>advice</i> applies to a (not necessarily existent) region
starting at <i>offset</i> and extending for <i>len</i> bytes
(or until the end of the file if <i>len</i> is 0) within the
file referred to by <i>fd</i>. The <i>advice</i> is not
binding; it merely constitutes an expectation on behalf of
the application.</p>
<p style="margin-left:11%; margin-top: 1em">Permissible
values for <i>advice</i> include: <b><br>
POSIX_FADV_NORMAL</b></p>
<p style="margin-left:22%;">Indicates that the application
has no advice to give about its access pattern for the
specified data. If no advice is given for an open file, this
is the default assumption.</p>
<p style="margin-left:11%;"><b>POSIX_FADV_SEQUENTIAL</b></p>
<p style="margin-left:22%;">The application expects to
access the specified data sequentially (with lower offsets
read before higher ones).</p>
<p style="margin-left:11%;"><b>POSIX_FADV_RANDOM</b></p>
<p style="margin-left:22%;">The specified data will be
accessed in random order.</p>
<p style="margin-left:11%;"><b>POSIX_FADV_NOREUSE</b></p>
<p style="margin-left:22%;">The specified data will be
accessed only once.</p>
<p style="margin-left:22%; margin-top: 1em">In kernels
before 2.6.18, <b>POSIX_FADV_NOREUSE</b> had the same
semantics as <b>POSIX_FADV_WILLNEED</b>. This was probably a
bug; since kernel 2.6.18, this flag is a no-op.</p>
<p style="margin-left:11%;"><b>POSIX_FADV_WILLNEED</b></p>
<p style="margin-left:22%;">The specified data will be
accessed in the near future.</p>
<p style="margin-left:22%; margin-top: 1em"><b>POSIX_FADV_WILLNEED</b>
initiates a nonblocking read of the specified region into
the page cache. The amount of data read may be decreased by
the kernel depending on virtual memory load. (A few
megabytes will usually be fully satisfied, and more is
rarely useful.)</p>
<p style="margin-left:11%;"><b>POSIX_FADV_DONTNEED</b></p>
<p style="margin-left:22%;">The specified data will not be
accessed in the near future.</p>
<p style="margin-left:22%; margin-top: 1em"><b>POSIX_FADV_DONTNEED</b>
attempts to free cached pages associated with the specified
region. This is useful, for example, while streaming large
files. A program may periodically request the kernel to free
cached data that has already been used, so that more useful
cached pages are not discarded instead.</p>
<p style="margin-left:22%; margin-top: 1em">Requests to
discard partial pages are ignored. It is preferable to
preserve needed data than discard unneeded data. If the
application requires that data be considered for discarding,
then <i>offset</i> and <i>len</i> must be page-aligned.</p>
<p style="margin-left:22%; margin-top: 1em">The
implementation <i>may</i> attempt to write back dirty pages
in the specified region, but this is not guaranteed. Any
unwritten dirty pages will not be freed. If the application
wishes to ensure that dirty pages will be released, it
should call <b>fsync</b>(2) or <b>fdatasync</b>(2)
first.</p>
<h2>RETURN VALUE
<a name="RETURN VALUE"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">On success,
zero is returned. On error, an error number is returned.</p>
<h2>ERRORS
<a name="ERRORS"></a>
</h2>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p style="margin-top: 1em"><b>EBADF</b></p></td>
<td width="2%"></td>
<td width="78%">
<p style="margin-top: 1em">The <i>fd</i> argument was not a
valid file descriptor.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>EINVAL</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>An invalid value was specified for <i>advice</i>.</p></td></tr>
<tr valign="top" align="left">
<td width="11%"></td>
<td width="9%">
<p><b>ESPIPE</b></p></td>
<td width="2%"></td>
<td width="78%">
<p>The specified file descriptor refers to a pipe or FIFO.
(<b>ESPIPE</b> is the error specified by POSIX, but before
kernel version 2.6.16, Linux returned <b>EINVAL</b> in this
case.)</p> </td></tr>
</table>
<h2>VERSIONS
<a name="VERSIONS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Kernel support
first appeared in Linux 2.5.60; the underlying system call
is called <b>fadvise64</b>(). Library support has been
provided since glibc version 2.2, via the wrapper function
<b>posix_fadvise</b>().</p>
<p style="margin-left:11%; margin-top: 1em">Since Linux
3.18, support for the underlying system call is optional,
depending on the setting of the
<b>CONFIG_ADVISE_SYSCALLS</b> configuration option.</p>
<h2>CONFORMING TO
<a name="CONFORMING TO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">POSIX.1-2001,
POSIX.1-2008. Note that the type of the <i>len</i> argument
was changed from <i>size_t</i> to <i>off_t</i> in
POSIX.1-2003 TC1.</p>
<h2>NOTES
<a name="NOTES"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">Under Linux,
<b>POSIX_FADV_NORMAL</b> sets the readahead window to the
default size for the backing device;
<b>POSIX_FADV_SEQUENTIAL</b> doubles this size, and
<b>POSIX_FADV_RANDOM</b> disables file readahead entirely.
These changes affect the entire file, not just the specified
region (but other open file handles to the same file are
unaffected).</p>
<p style="margin-left:11%; margin-top: 1em">The contents of
the kernel buffer cache can be cleared via the
<i>/proc/sys/vm/drop_caches</i> interface described in
<b>proc</b>(5).</p>
<p style="margin-left:11%; margin-top: 1em">One can obtain
a snapshot of which pages of a file are resident in the
buffer cache by opening a file, mapping it with
<b>mmap</b>(2), and then applying <b>mincore</b>(2) to the
mapping.</p>
<p style="margin-left:11%; margin-top: 1em"><b>C
library/kernel differences</b> <br>
The name of the wrapper function in the C library is
<b>posix_fadvise</b>(). The underlying system call is called
<b>fadvise64</b>() (or, on some architectures,
<b>fadvise64_64</b>()); the difference between the two is
that the former system call assumes that the type of the
<i>len</i> argument is <i>size_t</i>, while the latter
expects <i>loff_t</i> there.</p>
<p style="margin-left:11%; margin-top: 1em"><b>Architecture-specific
variants</b> <br>
Some architectures require 64-bit arguments to be aligned in
a suitable pair of registers (see <b>syscall</b>(2) for
further detail). On such architectures, the call signature
of <b>posix_fadvise</b>() shown in the SYNOPSIS would force
a register to be wasted as padding between the <i>fd</i> and
<i>offset</i> arguments. Therefore, these architectures
define a version of the system call that orders the
arguments suitably, but is otherwise exactly the same as
<b>posix_fadvise</b>().</p>
<p style="margin-left:11%; margin-top: 1em">For example,
since Linux 2.6.14, ARM has the following system call:</p>
<p style="margin-left:17%; margin-top: 1em"><b>long
arm_fadvise64_64(int</b> <i>fd</i><b>, int</b>
<i>advice</i><b>, <br>
loff_t</b> <i>offset</i><b>, loff_t</b>
<i>len</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em">These
architecture-specific details are generally hidden from
applications by the glibc <b>posix_fadvise</b>() wrapper
function, which invokes the appropriate
architecture-specific system call.</p>
<h2>BUGS
<a name="BUGS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">In kernels
before 2.6.6, if <i>len</i> was specified as 0, then this
was interpreted literally as "zero bytes", rather
than as meaning "all bytes through to the end of the
file".</p>
<h2>SEE ALSO
<a name="SEE ALSO"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>fincore</b>(1),
<b>mincore</b>(2), <b>readahead</b>(2),
<b>sync_file_range</b>(2), <b>posix_fallocate</b>(3),
<b>posix_madvise</b>(3)</p>
<h2>COLOPHON
<a name="COLOPHON"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">This page is
part of release 5.02 of the Linux <i>man-pages</i> project.
A description of the project, information about reporting
bugs, and the latest version of this page, can be found at
https://www.kernel.org/doc/man-pages/.</p>
<hr>
</body>
</html>