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