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