]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/posix_fadvise.2
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
MK
24.\" 2005-04-08 mtk, noted kernel version and added BUGS
25.\"
d9343c5c 26.TH POSIX_FADVISE 2 2003-02-14 "Linux" "Linux Programmer's Manual"
fea681da
MK
27.SH NAME
28posix_fadvise \- predeclare an access pattern for file data
29.SH SYNOPSIS
30.nf
f5441d2a 31.B #define _XOPEN_SOURCE 600
fea681da
MK
32.B #include <fcntl.h>
33.sp
34.BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len ", int " advice ");"
35.fi
36.SH DESCRIPTION
60a90ecd
MK
37Programs can use
38.BR posix_fadvise ()
39to announce an intention to access
fea681da 40file data in a specific pattern in the future, thus allowing the kernel
d9bfdb9c 41to perform appropriate optimizations.
fea681da
MK
42
43The \fIadvice\fP applies to a (not necessarily existent) region starting
44at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of
c13182ef
MK
45the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP.
46The advice is not binding; it merely constitutes an expectation on behalf of
fea681da
MK
47the application.
48
49Permissible values for \fIadvice\fP include:
50.TP
51.B POSIX_FADV_NORMAL
52Indicates that the application has no advice to give about its access
c13182ef
MK
53pattern for the specified data.
54If no advice is given for an open file,
fea681da
MK
55this is the default assumption.
56.TP
57.B POSIX_FADV_SEQUENTIAL
58The application expects to access the specified data sequentially (with
59lower offsets read before higher ones).
60.TP
61.B POSIX_FADV_RANDOM
62The specified data will be accessed in random order.
63.TP
64.B POSIX_FADV_NOREUSE
65The specified data will be accessed only once.
66.TP
67.B POSIX_FADV_WILLNEED
68The specified data will be accessed in the near future.
69.TP
70.B POSIX_FADV_DONTNEED
71The specified data will not be accessed in the near future.
72.SH "RETURN VALUE"
c13182ef 73On success, zero is returned.
b857d3da 74On error, an error number is returned.
fea681da
MK
75.SH ERRORS
76.TP
77.B EBADF
78The \fIfd\fP argument was not a valid file descriptor.
79.TP
80.B EINVAL
81An invalid value was specified for \fIadvice\fP.
82.TP
83.B ESPIPE
84The specified file descriptor refers to a pipe or FIFO. (Linux actually
85returns EINVAL in this case.)
a1d5f77c 86.SH VERSIONS
e511ffb6 87.BR posix_fadvise ()
f21a10c8 88appeared in kernel 2.5.60.
ed0e2b2f 89Glibc support has been provided since version 2.2.
f21a10c8 90.\" Actually as fadvise64() -- MTK
a1d5f77c
MK
91.SH "CONFORMING TO"
92POSIX.1-2001.
93Note that the type of the
94.I len
95parameter was changed from
96.I size_t
97to
98.I off_t
99in POSIX.1-2003 TC1.
100.SH NOTES
fea681da
MK
101Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the
102default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles
103this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely.
8c450534 104These changes affect the entire file, not just the specified region
fea681da
MK
105(but other open file handles to the same file are unaffected).
106
5e6055f4 107\fBPOSIX_FADV_WILLNEED\fP initiates a
c13182ef
MK
108non-blocking read of the specified region into the page cache.
109The amount of data read may be decreased by the kernel depending
110on virtual memory load.
111(A few megabytes will usually be fully satisfied,
5e6055f4
MK
112and more is rarely useful.)
113
c13182ef 114In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
5e6055f4
MK
115same semantics as \fBPOSIX_FADV_WILLNEED\fP.
116This was probably a bug; since kernel 2.6.18, this flag is a no-op.
fea681da
MK
117
118\fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
c13182ef
MK
119the specified region.
120This is useful, for example, while streaming large
121files.
122A program may periodically request the kernel to free cached data
fea681da
MK
123that has already been used, so that more useful cached pages are not
124discarded instead.
125
126Pages that have not yet been written out will be unaffected, so if the
127application wishes to guarantee that pages will be released, it should
60a90ecd
MK
128call
129.BR fsync (2)
130or
131.BR fdatasync (2)
132first.
f21a10c8 133.SH BUGS
c13182ef 134In kernels before 2.6.6, if
f21a10c8
MK
135.I len
136was specified as 0, then this was interpreted literally as "zero bytes",
137rather than as meaning "all bytes through to the end of the file".
fea681da 138.SH "SEE ALSO"
1f0ea6d8 139.BR posix_madvise (2),
ef276d2f 140.BR readahead (2),
0a90178c
MK
141.BR posix_fallocate (3) ,
142.BR feature_test_macros (7)