]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/readahead.2
262404ad4b815df8410715c179abc7ad5650627f
[thirdparty/man-pages.git] / man2 / readahead.2
1 .\" This manpage is Copyright (C) 2004, Michael Kerrisk
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" 2004-05-40 Created by Michael Kerrisk <mtk.manpages@gmail.com>
6 .\" 2004-10-05 aeb, minor correction
7 .\"
8 .TH READAHEAD 2 2022-09-09 "Linux man-pages (unreleased)"
9 .SH NAME
10 readahead \- initiate file readahead into page cache
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ", " \-lc )
14 .SH SYNOPSIS
15 .nf
16 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
17 .B #include <fcntl.h>
18 .PP
19 .BI "ssize_t readahead(int " fd ", off64_t " offset ", size_t " count );
20 .fi
21 .SH DESCRIPTION
22 .BR readahead ()
23 initiates readahead on a file so that subsequent reads from that file will
24 be satisfied from the cache, and not block on disk I/O
25 (assuming the readahead was initiated early enough and that other activity
26 on the system did not in the meantime flush pages from the cache).
27 .PP
28 The
29 .I fd
30 argument is a file descriptor identifying the file which is
31 to be read.
32 The
33 .I offset
34 argument specifies the starting point from which data is to be read
35 and
36 .I count
37 specifies the number of bytes to be read.
38 I/O is performed in whole pages, so that
39 .I offset
40 is effectively rounded down to a page boundary
41 and bytes are read up to the next page boundary greater than or
42 equal to
43 .IR "(offset+count)" .
44 .BR readahead ()
45 does not read beyond the end of the file.
46 The file offset of the open file description referred to by the file descriptor
47 .I fd
48 is left unchanged.
49 .SH RETURN VALUE
50 On success,
51 .BR readahead ()
52 returns 0; on failure, \-1 is returned, with
53 .I errno
54 set to indicate the error.
55 .SH ERRORS
56 .TP
57 .B EBADF
58 .I fd
59 is not a valid file descriptor or is not open for reading.
60 .TP
61 .B EINVAL
62 .I fd
63 does not refer to a file type to which
64 .BR readahead ()
65 can be applied.
66 .SH VERSIONS
67 The
68 .BR readahead ()
69 system call appeared in Linux 2.4.13;
70 glibc support has been provided since version 2.3.
71 .SH STANDARDS
72 The
73 .BR readahead ()
74 system call is Linux-specific, and its use should be avoided
75 in portable applications.
76 .SH NOTES
77 On some 32-bit architectures,
78 the calling signature for this system call differs,
79 for the reasons described in
80 .BR syscall (2).
81 .SH BUGS
82 .BR readahead ()
83 attempts to schedule the reads in the background and return immediately.
84 However, it may block while it reads the filesystem metadata needed
85 to locate the requested blocks.
86 This occurs frequently with ext[234] on large files
87 using indirect blocks instead of extents,
88 giving the appearance that the call blocks until the requested data has
89 been read.
90 .SH SEE ALSO
91 .BR lseek (2),
92 .BR madvise (2),
93 .BR mmap (2),
94 .BR posix_fadvise (2),
95 .BR read (2)