]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/posix_fadvise.2
syscalls.2: Add sync_file_range2() to syscalls list
[thirdparty/man-pages.git] / man2 / posix_fadvise.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
4.\" Permission is granted to make and distribute verbatim copies of this
5.\" manual provided the copyright notice and this permission notice are
6.\" preserved on all copies.
7.\"
8.\" Permission is granted to copy and distribute modified versions of this
9.\" manual under the conditions for verbatim copying, provided that the
10.\" entire resulting derived work is distributed under the terms of a
11.\" permission notice identical to this one.
c13182ef 12.\"
fea681da
MK
13.\" Since the Linux kernel and libraries are constantly changing, this
14.\" manual page may be incorrect or out-of-date. The author(s) assume no
15.\" responsibility for errors or omissions, or for damages resulting from
16.\" the use of the information contained herein. The author(s) may not
17.\" have taken the same level of care in the production of this manual,
18.\" which is licensed free of charge, as they might when working
19.\" professionally.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
23.\"
f21a10c8
MK
24.\" 2005-04-08 mtk, noted kernel version and added BUGS
25.\"
50831f9b 26.TH POSIX_FADVISE 2 2010-09-20 "Linux" "Linux Programmer's Manual"
fea681da
MK
27.SH NAME
28posix_fadvise \- predeclare an access pattern for file data
29.SH SYNOPSIS
30.nf
31.B #include <fcntl.h>
32.sp
34e8ac03
MK
33.BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len \
34", int " advice ");"
fea681da 35.fi
9a30939e
MK
36.sp
37.ad l
38.in -4n
39Feature Test Macro Requirements for glibc (see
40.BR feature_test_macros (7)):
41.in
42.sp
43.BR posix_fadvise ():
44.RS 4
45_XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
46.RE
47.ad
fea681da 48.SH DESCRIPTION
60a90ecd
MK
49Programs can use
50.BR posix_fadvise ()
51to announce an intention to access
fea681da 52file data in a specific pattern in the future, thus allowing the kernel
d9bfdb9c 53to perform appropriate optimizations.
fea681da
MK
54
55The \fIadvice\fP applies to a (not necessarily existent) region starting
56at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of
c13182ef
MK
57the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP.
58The advice is not binding; it merely constitutes an expectation on behalf of
fea681da
MK
59the application.
60
61Permissible values for \fIadvice\fP include:
62.TP
63.B POSIX_FADV_NORMAL
64Indicates that the application has no advice to give about its access
c13182ef
MK
65pattern for the specified data.
66If no advice is given for an open file,
fea681da
MK
67this is the default assumption.
68.TP
69.B POSIX_FADV_SEQUENTIAL
70The application expects to access the specified data sequentially (with
71lower offsets read before higher ones).
72.TP
73.B POSIX_FADV_RANDOM
74The specified data will be accessed in random order.
75.TP
76.B POSIX_FADV_NOREUSE
77The specified data will be accessed only once.
78.TP
79.B POSIX_FADV_WILLNEED
80The specified data will be accessed in the near future.
81.TP
82.B POSIX_FADV_DONTNEED
83The specified data will not be accessed in the near future.
84.SH "RETURN VALUE"
c13182ef 85On success, zero is returned.
b857d3da 86On error, an error number is returned.
fea681da
MK
87.SH ERRORS
88.TP
89.B EBADF
90The \fIfd\fP argument was not a valid file descriptor.
91.TP
92.B EINVAL
93An invalid value was specified for \fIadvice\fP.
94.TP
95.B ESPIPE
682edefb
MK
96The specified file descriptor refers to a pipe or FIFO.
97(Linux actually
98returns
99.B EINVAL
100in this case.)
a1d5f77c 101.SH VERSIONS
e511ffb6 102.BR posix_fadvise ()
f21a10c8 103appeared in kernel 2.5.60.
ed0e2b2f 104Glibc support has been provided since version 2.2.
f21a10c8 105.\" Actually as fadvise64() -- MTK
a1d5f77c
MK
106.SH "CONFORMING TO"
107POSIX.1-2001.
108Note that the type of the
109.I len
c4bb193f 110argument was changed from
a1d5f77c
MK
111.I size_t
112to
113.I off_t
114in POSIX.1-2003 TC1.
115.SH NOTES
fea681da
MK
116Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the
117default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles
118this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely.
8c450534 119These changes affect the entire file, not just the specified region
fea681da
MK
120(but other open file handles to the same file are unaffected).
121
5e6055f4 122\fBPOSIX_FADV_WILLNEED\fP initiates a
ff40dbb3 123nonblocking read of the specified region into the page cache.
c13182ef
MK
124The amount of data read may be decreased by the kernel depending
125on virtual memory load.
126(A few megabytes will usually be fully satisfied,
5e6055f4
MK
127and more is rarely useful.)
128
c13182ef 129In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
5e6055f4
MK
130same semantics as \fBPOSIX_FADV_WILLNEED\fP.
131This was probably a bug; since kernel 2.6.18, this flag is a no-op.
fea681da
MK
132
133\fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
c13182ef
MK
134the specified region.
135This is useful, for example, while streaming large
136files.
137A program may periodically request the kernel to free cached data
fea681da
MK
138that has already been used, so that more useful cached pages are not
139discarded instead.
140
141Pages that have not yet been written out will be unaffected, so if the
142application wishes to guarantee that pages will be released, it should
60a90ecd
MK
143call
144.BR fsync (2)
145or
146.BR fdatasync (2)
147first.
f21a10c8 148.SH BUGS
c13182ef 149In kernels before 2.6.6, if
f21a10c8
MK
150.I len
151was specified as 0, then this was interpreted literally as "zero bytes",
152rather than as meaning "all bytes through to the end of the file".
fea681da 153.SH "SEE ALSO"
ef276d2f 154.BR readahead (2),