1readahead(2)                  System Calls Manual                 readahead(2)
2
3
4

NAME

6       readahead - initiate file readahead into page cache
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #define _GNU_SOURCE             /* See feature_test_macros(7) */
13       #include <fcntl.h>
14
15       ssize_t readahead(int fd, off64_t offset, size_t count);
16

DESCRIPTION

18       readahead() initiates readahead on a file so that subsequent reads from
19       that file will be satisfied from the cache, and not block on  disk  I/O
20       (assuming  the  readahead was initiated early enough and that other ac‐
21       tivity on the system did not in  the  meantime  flush  pages  from  the
22       cache).
23
24       The  fd  argument is a file descriptor identifying the file which is to
25       be read.  The offset argument specifies the starting point  from  which
26       data  is to be read and count specifies the number of bytes to be read.
27       I/O is performed in whole pages, so that offset is effectively  rounded
28       down to a page boundary and bytes are read up to the next page boundary
29       greater than or equal to (offset+count).  readahead() does not read be‐
30       yond the end of the file.  The file offset of the open file description
31       referred to by the file descriptor fd is left unchanged.
32

RETURN VALUE

34       On success, readahead() returns 0; on failure, -1 is returned, with er‐
35       rno set to indicate the error.
36

ERRORS

38       EBADF  fd is not a valid file descriptor or is not open for reading.
39
40       EINVAL fd does not refer to a file type to which readahead() can be ap‐
41              plied.
42

VERSIONS

44       On some 32-bit architectures, the calling  signature  for  this  system
45       call differs, for the reasons described in syscall(2).
46

STANDARDS

48       Linux.
49

HISTORY

51       Linux 2.4.13, glibc 2.3.
52

BUGS

54       readahead() attempts to schedule the reads in the background and return
55       immediately.  However, it may block while it reads the filesystem meta‐
56       data  needed  to  locate  the requested blocks.  This occurs frequently
57       with ext[234] on large files using indirect blocks instead of  extents,
58       giving the appearance that the call blocks until the requested data has
59       been read.
60

SEE ALSO

62       lseek(2), madvise(2), mmap(2), posix_fadvise(2), read(2)
63
64
65
66Linux man-pages 6.04              2023-03-30                      readahead(2)
Impressum