OSDN Git Service

57cf21fc2c2bb99cbf39d9a5ab78923cdeaa6b24
[linuxjm/LDP_man-pages.git] / original / man2 / readahead.2
1 .\" This manpage is Copyright (C) 2004, Michael Kerrisk
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
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 .\" %%%LICENSE_END
24 .\"
25 .\" 2004-05-40 Created by Michael Kerrisk <mtk.manpages@gmail.com>
26 .\" 2004-10-05 aeb, minor correction
27 .\"
28 .TH READAHEAD 2 2014-03-15 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 readahead \- initiate file readahead into page cache
31 .SH SYNOPSIS
32 .nf
33 .BR "#define _GNU_SOURCE" "             /* See feature_test_macros(7) */"
34 .B #include <fcntl.h>
35 .sp
36 .BI "ssize_t readahead(int " fd ", off64_t " offset ", size_t " count );
37 .fi
38 .SH DESCRIPTION
39 .BR readahead ()
40 initiates readahead on a file so that subsequent reads from that file will
41 be satisfied from the cache, and not block on disk I/O
42 (assuming the readahead was initiated early enough and that other activity
43 on the system did not in the meantime flush pages from the cache).
44
45 The
46 .I fd
47 argument is a file descriptor identifying the file which is
48 to be read.
49 The
50 .I offset
51 argument specifies the starting point from which data is to be read
52 and
53 .I count
54 specifies the number of bytes to be read.
55 I/O is performed in whole pages, so that
56 .I offset
57 is effectively rounded down to a page boundary
58 and bytes are read up to the next page boundary greater than or
59 equal to
60 .IR "(offset+count)" .
61 .BR readahead ()
62 does not read beyond the end of the file.
63 The current file offset of the open file referred to by
64 .I fd
65 is left unchanged.
66 .SH RETURN VALUE
67 On success,
68 .BR readahead ()
69 returns 0; on failure, \-1 is returned, with
70 .I errno
71 set to indicate the cause of the error.
72 .SH ERRORS
73 .TP
74 .B EBADF
75 .I fd
76 is not a valid file descriptor or is not open for reading.
77 .TP
78 .B EINVAL
79 .I fd
80 does not refer to a file type to which
81 .BR readahead ()
82 can be applied.
83 .SH VERSIONS
84 The
85 .BR readahead ()
86 system call appeared in Linux 2.4.13;
87 glibc support has been provided since version 2.3.
88 .SH CONFORMING TO
89 The
90 .BR readahead ()
91 system call is Linux-specific, and its use should be avoided
92 in portable applications.
93 .SH NOTES
94 On some 32-bit architectures,
95 the calling signature for this system call differs,
96 for the reasons described in
97 .BR syscall (2).
98 .SH BUGS
99 .BR readahead ()
100 attempts to schedule the reads in the background and return immediately.
101 However, it may block while it reads the filesystem metadata needed
102 to locate the requested blocks.
103 This occurs frequently with ext[234] on large files
104 using indirect blocks instead of extents,
105 giving the appearance that the call blocks until the requested data has
106 been read.
107 .SH SEE ALSO
108 .BR lseek (2),
109 .BR madvise (2),
110 .BR mmap (2),
111 .BR posix_fadvise (2),
112 .BR read (2)
113 .SH COLOPHON
114 This page is part of release 3.67 of the Linux
115 .I man-pages
116 project.
117 A description of the project,
118 information about reporting bugs,
119 and the latest version of this page,
120 can be found at
121 \%http://www.kernel.org/doc/man\-pages/.