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 optimisations.
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 for
29              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

NOTES

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

CONFORMING TO

87       POSIX.1-2001.  Note that the type of the len parameter was changed from
88       size_t to off_t in POSIX.1-2003 TC1.
89

BUGS

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

SEE ALSO

96       posix_madvise(2),      readahead(2),      posix_fallocate(3),      fea‐
97       ture_test_macros(7)
98
99
100
101Linux 2.5.60                      14 Feb 2003                 POSIX_FADVISE(2)
Impressum