OSDN Git Service

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