]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/posix_fadvise.2
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[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 "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 #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 \fBposix_fadvise\fP() to announce an intention to access
38 file data in a specific pattern in the future, thus allowing the kernel
39 to perform appropriate optimisations.
40
41 The \fIadvice\fP applies to a (not necessarily existent) region starting
42 at \fIoffset\fP and extending for \fIlen\fP bytes (or until the end of
43 the file if \fIlen\fP is 0) within the file referred to by \fIfd\fP.
44 The advice is not binding; it merely constitutes an expectation on behalf of
45 the application.
46
47 Permissible values for \fIadvice\fP include:
48 .TP
49 .B POSIX_FADV_NORMAL
50 Indicates that the application has no advice to give about its access
51 pattern for the specified data.
52 If no advice is given for an open file,
53 this is the default assumption.
54 .TP
55 .B POSIX_FADV_SEQUENTIAL
56 The application expects to access the specified data sequentially (with
57 lower offsets read before higher ones).
58 .TP
59 .B POSIX_FADV_RANDOM
60 The specified data will be accessed in random order.
61 .TP
62 .B POSIX_FADV_NOREUSE
63 The specified data will be accessed only once.
64 .TP
65 .B POSIX_FADV_WILLNEED
66 The specified data will be accessed in the near future.
67 .TP
68 .B POSIX_FADV_DONTNEED
69 The specified data will not be accessed in the near future.
70 .SH "RETURN VALUE"
71 On success, zero is returned.
72 On error, an error number is returned.
73 .SH ERRORS
74 .TP
75 .B EBADF
76 The \fIfd\fP argument was not a valid file descriptor.
77 .TP
78 .B EINVAL
79 An invalid value was specified for \fIadvice\fP.
80 .TP
81 .B ESPIPE
82 The specified file descriptor refers to a pipe or FIFO. (Linux actually
83 returns EINVAL in this case.)
84 .SH NOTES
85 .BR posix_fadvise ()
86 appeared in kernel 2.5.60.
87 .\" Actually as fadvise64() -- MTK
88
89 Under Linux, \fBPOSIX_FADV_NORMAL\fP sets the readahead window to the
90 default size for the backing device; \fBPOSIX_FADV_SEQUENTIAL\fP doubles
91 this size, and \fBPOSIX_FADV_RANDOM\fP disables file readahead entirely.
92 These changes affect the entire file, not just the specified region
93 (but other open file handles to the same file are unaffected).
94
95 \fBPOSIX_FADV_WILLNEED\fP initiates a
96 non-blocking read of the specified region into the page cache.
97 The amount of data read may be decreased by the kernel depending
98 on virtual memory load.
99 (A few megabytes will usually be fully satisfied,
100 and more is rarely useful.)
101
102 In kernels before 2.6.18, \fBPOSIX_FADV_NOREUSE\fP had the
103 same semantics as \fBPOSIX_FADV_WILLNEED\fP.
104 This was probably a bug; since kernel 2.6.18, this flag is a no-op.
105
106 \fBPOSIX_FADV_DONTNEED\fP attempts to free cached pages associated with
107 the specified region.
108 This is useful, for example, while streaming large
109 files.
110 A program may periodically request the kernel to free cached data
111 that has already been used, so that more useful cached pages are not
112 discarded instead.
113
114 Pages that have not yet been written out will be unaffected, so if the
115 application wishes to guarantee that pages will be released, it should
116 call \fBfsync\fP() or \fBfdatasync\fP() first.
117 .SH "CONFORMING TO"
118 POSIX.1-2001.
119 Note that the type of the
120 .I len
121 parameter was changed from
122 .I size_t
123 to
124 .I off_t
125 in POSIX.1-2003 TC1.
126 .SH BUGS
127 In kernels before 2.6.6, if
128 .I len
129 was specified as 0, then this was interpreted literally as "zero bytes",
130 rather than as meaning "all bytes through to the end of the file".
131 .SH "SEE ALSO"
132 .BR posix_madvise (2),
133 .BR readahead (2),
134 .BR posix_fallocate (3) ,
135 .BR feature_test_macros (7)