]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/posix_fadvise.2
random.4: spfix
[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 24.\" 2005-04-08 mtk, noted kernel version and added BUGS
dc30fdc6 25.\" 2010-10-09, mtk, document arm_fadvise64_64()
f21a10c8 26.\"
e049eee8 27.TH POSIX_FADVISE 2 2010-10-09 "Linux" "Linux Programmer's Manual"
fea681da
MK
28.SH NAME
29posix_fadvise \- predeclare an access pattern for file data
30.SH SYNOPSIS
31.nf
32.B #include <fcntl.h>
33.sp
34e8ac03
MK
34.BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len \
35", int " advice ");"
fea681da 36.fi
9a30939e
MK
37.sp
38.ad l
39.in -4n
40Feature Test Macro Requirements for glibc (see
41.BR feature_test_macros (7)):
42.in
43.sp
44.BR posix_fadvise ():
45.RS 4
46_XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
47.RE
48.ad
fea681da 49.SH DESCRIPTION
60a90ecd
MK
50Programs can use
51.BR posix_fadvise ()
52to announce an intention to access
fea681da 53file data in a specific pattern in the future, thus allowing the kernel
d9bfdb9c 54to perform appropriate optimizations.
fea681da
MK
55
56The \fIadvice\fP applies to a (not necessarily existent) region starting
57at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of
c13182ef 58the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP.
b265f7bb
YK
59The \fIadvice\fP is not binding;
60it merely constitutes an expectation on behalf of
fea681da
MK
61the application.
62
63Permissible values for \fIadvice\fP include:
64.TP
65.B POSIX_FADV_NORMAL
66Indicates that the application has no advice to give about its access
c13182ef
MK
67pattern for the specified data.
68If no advice is given for an open file,
fea681da
MK
69this is the default assumption.
70.TP
71.B POSIX_FADV_SEQUENTIAL
72The application expects to access the specified data sequentially (with
73lower offsets read before higher ones).
74.TP
75.B POSIX_FADV_RANDOM
76The specified data will be accessed in random order.
77.TP
78.B POSIX_FADV_NOREUSE
79The specified data will be accessed only once.
80.TP
81.B POSIX_FADV_WILLNEED
82The specified data will be accessed in the near future.
83.TP
84.B POSIX_FADV_DONTNEED
85The specified data will not be accessed in the near future.
86.SH "RETURN VALUE"
c13182ef 87On success, zero is returned.
b857d3da 88On error, an error number is returned.
fea681da
MK
89.SH ERRORS
90.TP
91.B EBADF
92The \fIfd\fP argument was not a valid file descriptor.
93.TP
94.B EINVAL
95An invalid value was specified for \fIadvice\fP.
96.TP
97.B ESPIPE
682edefb
MK
98The specified file descriptor refers to a pipe or FIFO.
99(Linux actually
100returns
101.B EINVAL
102in this case.)
a1d5f77c 103.SH VERSIONS
e049eee8
MK
104Kernel support first appeared in Linux 2.5.60;
105the underlying system call is called
106.BR fadvise64 ().
107.\" of fadvise64_64()
108Library support has been provided since glibc version 2.2,
109via the wrapper function
110.BR posix_fadvise ().
a1d5f77c
MK
111.SH "CONFORMING TO"
112POSIX.1-2001.
113Note that the type of the
114.I len
c4bb193f 115argument was changed from
a1d5f77c
MK
116.I size_t
117to
118.I off_t
119in POSIX.1-2003 TC1.
120.SH NOTES
fea681da
MK
121Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the
122default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles
123this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely.
8c450534 124These changes affect the entire file, not just the specified region
fea681da
MK
125(but other open file handles to the same file are unaffected).
126
5e6055f4 127\fBPOSIX_FADV_WILLNEED\fP initiates a
ff40dbb3 128nonblocking read of the specified region into the page cache.
c13182ef
MK
129The amount of data read may be decreased by the kernel depending
130on virtual memory load.
131(A few megabytes will usually be fully satisfied,
5e6055f4
MK
132and more is rarely useful.)
133
c13182ef 134In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
5e6055f4
MK
135same semantics as \fBPOSIX_FADV_WILLNEED\fP.
136This was probably a bug; since kernel 2.6.18, this flag is a no-op.
fea681da
MK
137
138\fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
c13182ef
MK
139the specified region.
140This is useful, for example, while streaming large
141files.
142A program may periodically request the kernel to free cached data
fea681da
MK
143that has already been used, so that more useful cached pages are not
144discarded instead.
145
146Pages that have not yet been written out will be unaffected, so if the
147application wishes to guarantee that pages will be released, it should
60a90ecd
MK
148call
149.BR fsync (2)
150or
151.BR fdatasync (2)
152first.
dc30fdc6
MK
153.SS arm_fadvise()
154The ARM architecture
155needs 64-bit arguments to be aligned in a suitable pair of registers.
156On this architecture, the call signature of
157.BR posix_fadvise ()
158is flawed, since it forces a register to be wasted as padding between the
159.I fd
160and
161.I len
162arguments.
163Therefore, since Linux 2.6.14, ARM defines a different
164system call that orders the arguments suitably:
165.PP
166.in +4n
167.nf
168.BI "long arm_fadvise64_64(int " fd ", int " advice ,
503979fa 169.BI " loff_t " offset ", loff_t " len );
dc30fdc6
MK
170.fi
171.in
172.PP
173The behavior of this system call is otherwise exactly the same as
62fc472f 174.BR posix_fadvise ().
dc30fdc6
MK
175No library support is provided for this system call in glibc.
176.\" No ARM support in glibc.
f21a10c8 177.SH BUGS
c13182ef 178In kernels before 2.6.6, if
f21a10c8
MK
179.I len
180was specified as 0, then this was interpreted literally as "zero bytes",
181rather than as meaning "all bytes through to the end of the file".
fea681da 182.SH "SEE ALSO"
ef276d2f 183.BR readahead (2),