]>
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. | |
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 | .\" | |
f21a10c8 MK |
24 | .\" 2005-04-08 mtk, noted kernel version and added BUGS |
25 | .\" | |
fea681da MK |
26 | .TH POSIX_FADVISE 2 "14 Feb 2003" "Linux 2.5.60" "Linux Programmer's Manual" |
27 | .SH NAME | |
28 | posix_fadvise \- predeclare an access pattern for file data | |
29 | .SH SYNOPSIS | |
30 | .nf | |
31 | .B #include <fcntl.h> | |
32 | .sp | |
33 | .BI "int posix_fadvise(int " fd ", off_t " offset ", off_t " len ", int " advice ");" | |
34 | .fi | |
35 | .SH DESCRIPTION | |
36 | Programs can use \fBposix_fadvise\fP to announce an intention to access | |
37 | file data in a specific pattern in the future, thus allowing the kernel | |
38 | to perform appropriate optimisations. | |
39 | ||
40 | The \fIadvice\fP applies to a (not necessarily existent) region starting | |
41 | at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of | |
42 | the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP. The | |
43 | advice is not binding; it merely constitutes an expectation on behalf of | |
44 | the application. | |
45 | ||
46 | Permissible values for \fIadvice\fP include: | |
47 | .TP | |
48 | .B POSIX_FADV_NORMAL | |
49 | Indicates that the application has no advice to give about its access | |
50 | pattern for the specified data. If no advice is given for an open file, | |
51 | this is the default assumption. | |
52 | .TP | |
53 | .B POSIX_FADV_SEQUENTIAL | |
54 | The application expects to access the specified data sequentially (with | |
55 | lower offsets read before higher ones). | |
56 | .TP | |
57 | .B POSIX_FADV_RANDOM | |
58 | The specified data will be accessed in random order. | |
59 | .TP | |
60 | .B POSIX_FADV_NOREUSE | |
61 | The specified data will be accessed only once. | |
62 | .TP | |
63 | .B POSIX_FADV_WILLNEED | |
64 | The specified data will be accessed in the near future. | |
65 | .TP | |
66 | .B POSIX_FADV_DONTNEED | |
67 | The specified data will not be accessed in the near future. | |
68 | .SH "RETURN VALUE" | |
69 | On success, zero is returned. On error, \-1 is returned, and \fIerrno\fP | |
70 | is set appropriately. | |
71 | .SH ERRORS | |
72 | .TP | |
73 | .B EBADF | |
74 | The \fIfd\fP argument was not a valid file descriptor. | |
75 | .TP | |
76 | .B EINVAL | |
77 | An invalid value was specified for \fIadvice\fP. | |
78 | .TP | |
79 | .B ESPIPE | |
80 | The specified file descriptor refers to a pipe or FIFO. (Linux actually | |
81 | returns EINVAL in this case.) | |
82 | .SH NOTES | |
f21a10c8 MK |
83 | .BR posix_fadvise |
84 | appeared in kernel 2.5.60. | |
85 | .\" Actually as fadvise64() -- MTK | |
86 | ||
fea681da MK |
87 | Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the |
88 | default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles | |
89 | this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely. | |
90 | These changes affect the the entire file, not just the specified region | |
91 | (but other open file handles to the same file are unaffected). | |
92 | ||
93 | \fBPOSIX_FADV_WILLNEED\fP and \fBPOSIX_FADV_NOREUSE\fP both initiate a | |
94 | non-blocking read of the specified region into the page cache. The amount | |
95 | of data read may be decreased by the kernel depending on VM load. (A few | |
96 | megabytes will usually be fully satisfied, and more is rarely useful.) | |
97 | ||
98 | \fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with | |
99 | the specified region. This is useful, for example, while streaming large | |
100 | files. A program may periodically request the kernel to free cached data | |
101 | that has already been used, so that more useful cached pages are not | |
102 | discarded instead. | |
103 | ||
104 | Pages that have not yet been written out will be unaffected, so if the | |
105 | application wishes to guarantee that pages will be released, it should | |
106 | call \fBfsync\fP or \fBfdatasync\fP first. | |
107 | .SH "CONFORMING TO" | |
108 | SUSv3 (Advanced Realtime Option), POSIX 1003.1-2003. | |
109 | Note that the type of the | |
110 | .I len | |
111 | parameter was changed from size_t to off_t in POSIX 1003.1-2003 TC5. | |
f21a10c8 MK |
112 | .SH BUGS |
113 | In kernels before 2.6.6, if | |
114 | .I len | |
115 | was specified as 0, then this was interpreted literally as "zero bytes", | |
116 | rather than as meaning "all bytes through to the end of the file". | |
fea681da MK |
117 | .SH "SEE ALSO" |
118 | .BR posix_fallocate "(2), " posix_madvise "(2)." |