]>
Commit | Line | Data |
---|---|---|
fea681da MK |
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. | |
c13182ef | 12 | .\" |
fea681da MK |
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. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
23 | .\" | |
f21a10c8 MK |
24 | .\" 2005-04-08 mtk, noted kernel version and added BUGS |
25 | .\" | |
d9343c5c | 26 | .TH POSIX_FADVISE 2 2003-02-14 "Linux" "Linux Programmer's Manual" |
fea681da MK |
27 | .SH NAME |
28 | posix_fadvise \- predeclare an access pattern for file data | |
29 | .SH SYNOPSIS | |
30 | .nf | |
f5441d2a | 31 | .B #define _XOPEN_SOURCE 600 |
fea681da MK |
32 | .B #include <fcntl.h> |
33 | .sp | |
34 | .BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len ", int " advice ");" | |
35 | .fi | |
36 | .SH DESCRIPTION | |
60a90ecd MK |
37 | Programs can use |
38 | .BR posix_fadvise () | |
39 | to announce an intention to access | |
fea681da MK |
40 | file data in a specific pattern in the future, thus allowing the kernel |
41 | to perform appropriate optimisations. | |
42 | ||
43 | The \fIadvice\fP applies to a (not necessarily existent) region starting | |
44 | at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of | |
c13182ef MK |
45 | the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP. |
46 | The advice is not binding; it merely constitutes an expectation on behalf of | |
fea681da MK |
47 | the application. |
48 | ||
49 | Permissible values for \fIadvice\fP include: | |
50 | .TP | |
51 | .B POSIX_FADV_NORMAL | |
52 | Indicates that the application has no advice to give about its access | |
c13182ef MK |
53 | pattern for the specified data. |
54 | If no advice is given for an open file, | |
fea681da MK |
55 | this is the default assumption. |
56 | .TP | |
57 | .B POSIX_FADV_SEQUENTIAL | |
58 | The application expects to access the specified data sequentially (with | |
59 | lower offsets read before higher ones). | |
60 | .TP | |
61 | .B POSIX_FADV_RANDOM | |
62 | The specified data will be accessed in random order. | |
63 | .TP | |
64 | .B POSIX_FADV_NOREUSE | |
65 | The specified data will be accessed only once. | |
66 | .TP | |
67 | .B POSIX_FADV_WILLNEED | |
68 | The specified data will be accessed in the near future. | |
69 | .TP | |
70 | .B POSIX_FADV_DONTNEED | |
71 | The specified data will not be accessed in the near future. | |
72 | .SH "RETURN VALUE" | |
c13182ef | 73 | On success, zero is returned. |
b857d3da | 74 | On error, an error number is returned. |
fea681da MK |
75 | .SH ERRORS |
76 | .TP | |
77 | .B EBADF | |
78 | The \fIfd\fP argument was not a valid file descriptor. | |
79 | .TP | |
80 | .B EINVAL | |
81 | An invalid value was specified for \fIadvice\fP. | |
82 | .TP | |
83 | .B ESPIPE | |
84 | The specified file descriptor refers to a pipe or FIFO. (Linux actually | |
85 | returns EINVAL in this case.) | |
a1d5f77c | 86 | .SH VERSIONS |
e511ffb6 | 87 | .BR posix_fadvise () |
f21a10c8 | 88 | appeared in kernel 2.5.60. |
ed0e2b2f | 89 | Glibc support has been provided since version 2.2. |
f21a10c8 | 90 | .\" Actually as fadvise64() -- MTK |
a1d5f77c MK |
91 | .SH "CONFORMING TO" |
92 | POSIX.1-2001. | |
93 | Note that the type of the | |
94 | .I len | |
95 | parameter was changed from | |
96 | .I size_t | |
97 | to | |
98 | .I off_t | |
99 | in POSIX.1-2003 TC1. | |
100 | .SH NOTES | |
fea681da MK |
101 | Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the |
102 | default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles | |
103 | this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely. | |
8c450534 | 104 | These changes affect the entire file, not just the specified region |
fea681da MK |
105 | (but other open file handles to the same file are unaffected). |
106 | ||
5e6055f4 | 107 | \fBPOSIX_FADV_WILLNEED\fP initiates a |
c13182ef MK |
108 | non-blocking read of the specified region into the page cache. |
109 | The amount of data read may be decreased by the kernel depending | |
110 | on virtual memory load. | |
111 | (A few megabytes will usually be fully satisfied, | |
5e6055f4 MK |
112 | and more is rarely useful.) |
113 | ||
c13182ef | 114 | In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the |
5e6055f4 MK |
115 | same semantics as \fBPOSIX_FADV_WILLNEED\fP. |
116 | This was probably a bug; since kernel 2.6.18, this flag is a no-op. | |
fea681da MK |
117 | |
118 | \fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with | |
c13182ef MK |
119 | the specified region. |
120 | This is useful, for example, while streaming large | |
121 | files. | |
122 | A program may periodically request the kernel to free cached data | |
fea681da MK |
123 | that has already been used, so that more useful cached pages are not |
124 | discarded instead. | |
125 | ||
126 | Pages that have not yet been written out will be unaffected, so if the | |
127 | application wishes to guarantee that pages will be released, it should | |
60a90ecd MK |
128 | call |
129 | .BR fsync (2) | |
130 | or | |
131 | .BR fdatasync (2) | |
132 | first. | |
f21a10c8 | 133 | .SH BUGS |
c13182ef | 134 | In kernels before 2.6.6, if |
f21a10c8 MK |
135 | .I len |
136 | was specified as 0, then this was interpreted literally as "zero bytes", | |
137 | rather than as meaning "all bytes through to the end of the file". | |
fea681da | 138 | .SH "SEE ALSO" |
1f0ea6d8 | 139 | .BR posix_madvise (2), |
ef276d2f | 140 | .BR readahead (2), |
0a90178c MK |
141 | .BR posix_fallocate (3) , |
142 | .BR feature_test_macros (7) |