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