]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/posix_fadvise.2
Removed version number from .TH line
[thirdparty/man-pages.git] / man2 / posix_fadvise.2
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 .\"
24 .\" 2005-04-08 mtk, noted kernel version and added BUGS
25 .\"
26 .TH POSIX_FADVISE 2 2003-02-14 "Linux" "Linux Programmer's Manual"
27 .SH NAME
28 posix_fadvise \- predeclare an access pattern for file data
29 .SH SYNOPSIS
30 .nf
31 .B #define _XOPEN_SOURCE 600
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
37 Programs can use
38 .BR posix_fadvise ()
39 to announce an intention to access
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
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
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
53 pattern for the specified data.
54 If no advice is given for an open file,
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"
73 On success, zero is returned.
74 On error, an error number is returned.
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.)
86 .SH VERSIONS
87 .BR posix_fadvise ()
88 appeared in kernel 2.5.60.
89 .\" Actually as fadvise64() -- MTK
90 .SH "CONFORMING TO"
91 POSIX.1-2001.
92 Note that the type of the
93 .I len
94 parameter was changed from
95 .I size_t
96 to
97 .I off_t
98 in POSIX.1-2003 TC1.
99 .SH NOTES
100 VERSIONS
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.
104 These changes affect the entire file, not just the specified region
105 (but other open file handles to the same file are unaffected).
106
107 \fBPOSIX_FADV_WILLNEED\fP initiates a
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,
112 and more is rarely useful.)
113
114 In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
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.
117
118 \fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
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
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
128 call
129 .BR fsync (2)
130 or
131 .BR fdatasync (2)
132 first.
133 .SH BUGS
134 In kernels before 2.6.6, if
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".
138 .SH "SEE ALSO"
139 .BR posix_madvise (2),
140 .BR readahead (2),
141 .BR posix_fallocate (3) ,
142 .BR feature_test_macros (7)