OSDN Git Service

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