1POSIX_FADVISE(2)           Linux Programmer's Manual          POSIX_FADVISE(2)
2
3
4

NAME

6       posix_fadvise - predeclare an access pattern for file data
7

SYNOPSIS

9       #define _XOPEN_SOURCE 600
10       #include <fcntl.h>
11
12       int posix_fadvise(int fd, off_t offset, off_t len, int advice);
13

DESCRIPTION

15       Programs  can  use  posix_fadvise()  to announce an intention to access
16       file data in a specific pattern in the future, thus allowing the kernel
17       to perform appropriate optimizations.
18
19       The  advice  applies to a (not necessarily existent) region starting at
20       offset and extending for len bytes (or until the end of the file if len
21       is 0) within the file referred to by fd.  The advice is not binding; it
22       merely constitutes an expectation on behalf of the application.
23
24       Permissible values for advice include:
25
26       POSIX_FADV_NORMAL
27              Indicates that the application has no advice to give  about  its
28              access  pattern  for  the specified data.  If no advice is given
29              for an open file, this is the default assumption.
30
31       POSIX_FADV_SEQUENTIAL
32              The application expects to access  the  specified  data  sequen‐
33              tially (with lower offsets read before higher ones).
34
35       POSIX_FADV_RANDOM
36              The specified data will be accessed in random order.
37
38       POSIX_FADV_NOREUSE
39              The specified data will be accessed only once.
40
41       POSIX_FADV_WILLNEED
42              The specified data will be accessed in the near future.
43
44       POSIX_FADV_DONTNEED
45              The specified data will not be accessed in the near future.
46

RETURN VALUE

48       On success, zero is returned.  On error, an error number is returned.
49

ERRORS

51       EBADF  The fd argument was not a valid file descriptor.
52
53       EINVAL An invalid value was specified for advice.
54
55       ESPIPE The  specified file descriptor refers to a pipe or FIFO.  (Linux
56              actually returns EINVAL in this case.)
57

VERSIONS

59       posix_fadvise() appeared in kernel 2.5.60.  Glibc support has been pro‐
60       vided since version 2.2.
61

CONFORMING TO

63       POSIX.1-2001.   Note that the type of the len argument was changed from
64       size_t to off_t in POSIX.1-2003 TC1.
65

NOTES

67       Under Linux, POSIX_FADV_NORMAL sets the readahead window to the default
68       size  for  the backing device; POSIX_FADV_SEQUENTIAL doubles this size,
69       and POSIX_FADV_RANDOM disables file readahead entirely.  These  changes
70       affect  the  entire file, not just the specified region (but other open
71       file handles to the same file are unaffected).
72
73       POSIX_FADV_WILLNEED initiates a  non-blocking  read  of  the  specified
74       region  into  the page cache.  The amount of data read may be decreased
75       by the kernel depending on virtual memory load.  (A few megabytes  will
76       usually be fully satisfied, and more is rarely useful.)
77
78       In  kernels before 2.6.18, POSIX_FADV_NOREUSE had the same semantics as
79       POSIX_FADV_WILLNEED.  This was probably a  bug;  since  kernel  2.6.18,
80       this flag is a no-op.
81
82       POSIX_FADV_DONTNEED  attempts  to free cached pages associated with the
83       specified region.  This is useful, for example, while  streaming  large
84       files.   A  program  may periodically request the kernel to free cached
85       data that has already been used, so that more useful cached  pages  are
86       not discarded instead.
87
88       Pages  that have not yet been written out will be unaffected, so if the
89       application wishes to guarantee that pages will be released, it  should
90       call fsync(2) or fdatasync(2) first.
91

BUGS

93       In  kernels  before  2.6.6,  if  len  was specified as 0, then this was
94       interpreted literally as "zero bytes",  rather  than  as  meaning  "all
95       bytes through to the end of the file".
96

SEE ALSO

98       readahead(2),      posix_fallocate(3),      posix_madvise(3),      fea‐
99       ture_test_macros(7)
100

COLOPHON

102       This page is part of release 3.22 of the Linux  man-pages  project.   A
103       description  of  the project, and information about reporting bugs, can
104       be found at http://www.kernel.org/doc/man-pages/.
105
106
107
108Linux                             2003-02-14                  POSIX_FADVISE(2)
Impressum