1 .\" Copyright 2003 Abhijit Menon-Sen <ams@wiw.org>
2 .\" %%%LICENSE_START(VERBATIM)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" 2005-04-08 mtk, noted kernel version and added BUGS
25 .\" 2010-10-09, mtk, document arm_fadvise64_64()
27 .TH POSIX_FADVISE 2 2010-10-09 "Linux" "Linux Programmer's Manual"
29 posix_fadvise \- predeclare an access pattern for file data
34 .BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len \
40 Feature Test Macro Requirements for glibc (see
41 .BR feature_test_macros (7)):
46 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
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.
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 \fIadvice\fP is not binding;
60 it merely constitutes an expectation on behalf of
63 Permissible values for \fIadvice\fP include:
66 Indicates that the application has no advice to give about its access
67 pattern for the specified data.
68 If no advice is given for an open file,
69 this is the default assumption.
71 .B POSIX_FADV_SEQUENTIAL
72 The application expects to access the specified data sequentially (with
73 lower offsets read before higher ones).
76 The specified data will be accessed in random order.
79 The specified data will be accessed only once.
81 .B POSIX_FADV_WILLNEED
82 The specified data will be accessed in the near future.
84 .B POSIX_FADV_DONTNEED
85 The specified data will not be accessed in the near future.
87 On success, zero is returned.
88 On error, an error number is returned.
92 The \fIfd\fP argument was not a valid file descriptor.
95 An invalid value was specified for \fIadvice\fP.
98 The specified file descriptor refers to a pipe or FIFO.
104 Kernel support first appeared in Linux 2.5.60;
105 the underlying system call is called
107 .\" of fadvise64_64()
108 Library support has been provided since glibc version 2.2,
109 via the wrapper function
110 .BR posix_fadvise ().
113 Note that the type of the
115 argument was changed from
121 Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the
122 default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles
123 this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely.
124 These changes affect the entire file, not just the specified region
125 (but other open file handles to the same file are unaffected).
127 \fBPOSIX_FADV_WILLNEED\fP initiates a
128 nonblocking read of the specified region into the page cache.
129 The amount of data read may be decreased by the kernel depending
130 on virtual memory load.
131 (A few megabytes will usually be fully satisfied,
132 and more is rarely useful.)
134 In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
135 same semantics as \fBPOSIX_FADV_WILLNEED\fP.
136 This was probably a bug; since kernel 2.6.18, this flag is a no-op.
138 \fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
139 the specified region.
140 This is useful, for example, while streaming large
142 A program may periodically request the kernel to free cached data
143 that has already been used, so that more useful cached pages are not
146 Pages that have not yet been written out will be unaffected, so if the
147 application wishes to guarantee that pages will be released, it should
155 needs 64-bit arguments to be aligned in a suitable pair of registers.
156 On this architecture, the call signature of
158 is flawed, since it forces a register to be wasted as padding between the
163 Therefore, since Linux 2.6.14, ARM defines a different
164 system call that orders the arguments suitably:
168 .BI "long arm_fadvise64_64(int " fd ", int " advice ,
169 .BI " loff_t " offset ", loff_t " len );
173 The behavior of this system call is otherwise exactly the same as
174 .BR posix_fadvise ().
175 No library support is provided for this system call in glibc.
176 .\" No ARM support in glibc.
178 In kernels before 2.6.6, if
180 was specified as 0, then this was interpreted literally as "zero bytes",
181 rather than as meaning "all bytes through to the end of the file".
184 .BR sync_file_range (2),
185 .BR posix_fallocate (3),
186 .BR posix_madvise (3)
187 .\" FIXME . Write a posix_fadvise(3) page.