1 .\" Hey Emacs! This file is -*- nroff -*- source.
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" 2005-04-08 mtk, noted kernel version and added BUGS
26 .TH POSIX_FADVISE 2 2010-06-14 "Linux" "Linux Programmer's Manual"
28 posix_fadvise \- predeclare an access pattern for file data
33 .BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len \
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
45 _XOPEN_SOURCE\ >=\ 600 || _POSIX_C_SOURCE\ >=\ 200112L
51 to announce an intention to access
52 file data in a specific pattern in the future, thus allowing the kernel
53 to perform appropriate optimizations.
55 The \fIadvice\fP applies to a (not necessarily existent) region starting
56 at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of
57 the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP.
58 The advice is not binding; it merely constitutes an expectation on behalf of
61 Permissible values for \fIadvice\fP include:
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.
69 .B POSIX_FADV_SEQUENTIAL
70 The application expects to access the specified data sequentially (with
71 lower offsets read before higher ones).
74 The specified data will be accessed in random order.
77 The specified data will be accessed only once.
79 .B POSIX_FADV_WILLNEED
80 The specified data will be accessed in the near future.
82 .B POSIX_FADV_DONTNEED
83 The specified data will not be accessed in the near future.
85 On success, zero is returned.
86 On error, an error number is returned.
90 The \fIfd\fP argument was not a valid file descriptor.
93 An invalid value was specified for \fIadvice\fP.
96 The specified file descriptor refers to a pipe or FIFO.
103 appeared in kernel 2.5.60.
104 Glibc support has been provided since version 2.2.
105 .\" Actually as fadvise64() -- MTK
108 Note that the type of the
110 argument was changed from
116 Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the
117 default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles
118 this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely.
119 These changes affect the entire file, not just the specified region
120 (but other open file handles to the same file are unaffected).
122 \fBPOSIX_FADV_WILLNEED\fP initiates a
123 nonblocking read of the specified region into the page cache.
124 The amount of data read may be decreased by the kernel depending
125 on virtual memory load.
126 (A few megabytes will usually be fully satisfied,
127 and more is rarely useful.)
129 In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
130 same semantics as \fBPOSIX_FADV_WILLNEED\fP.
131 This was probably a bug; since kernel 2.6.18, this flag is a no-op.
133 \fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
134 the specified region.
135 This is useful, for example, while streaming large
137 A program may periodically request the kernel to free cached data
138 that has already been used, so that more useful cached pages are not
141 Pages that have not yet been written out will be unaffected, so if the
142 application wishes to guarantee that pages will be released, it should
149 In kernels before 2.6.6, if
151 was specified as 0, then this was interpreted literally as "zero bytes",
152 rather than as meaning "all bytes through to the end of the file".
155 .BR sync_file_range (2),
156 .BR posix_fallocate (3),
157 .BR posix_madvise (3),
158 .\" FIXME . Write a posix_fadvise(3) page.
159 .BR feature_test_macros (7)