1POSIX_FADVISE(2) Linux Programmer's Manual POSIX_FADVISE(2)
2
3
4
6 posix_fadvise - predeclare an access pattern for file data
7
9 #include <fcntl.h>
10
11 int posix_fadvise(int fd, off_t offset, off_t len, int advice);
12
13 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15 posix_fadvise():
16 _POSIX_C_SOURCE >= 200112L
17
19 Programs can use posix_fadvise() to announce an intention to access
20 file data in a specific pattern in the future, thus allowing the kernel
21 to perform appropriate optimizations.
22
23 The advice applies to a (not necessarily existent) region starting at
24 offset and extending for len bytes (or until the end of the file if len
25 is 0) within the file referred to by fd. The advice is not binding; it
26 merely constitutes an expectation on behalf of the application.
27
28 Permissible values for advice include:
29
30 POSIX_FADV_NORMAL
31 Indicates that the application has no advice to give about its
32 access pattern for the specified data. If no advice is given
33 for an open file, this is the default assumption.
34
35 POSIX_FADV_SEQUENTIAL
36 The application expects to access the specified data sequen‐
37 tially (with lower offsets read before higher ones).
38
39 POSIX_FADV_RANDOM
40 The specified data will be accessed in random order.
41
42 POSIX_FADV_NOREUSE
43 The specified data will be accessed only once.
44
45 In kernels before 2.6.18, POSIX_FADV_NOREUSE had the same seman‐
46 tics as POSIX_FADV_WILLNEED. This was probably a bug; since
47 kernel 2.6.18, this flag is a no-op.
48
49 POSIX_FADV_WILLNEED
50 The specified data will be accessed in the near future.
51
52 POSIX_FADV_WILLNEED initiates a nonblocking read of the speci‐
53 fied region into the page cache. The amount of data read may be
54 decreased by the kernel depending on virtual memory load. (A
55 few megabytes will usually be fully satisfied, and more is
56 rarely useful.)
57
58 POSIX_FADV_DONTNEED
59 The specified data will not be accessed in the near future.
60
61 POSIX_FADV_DONTNEED attempts to free cached pages associated
62 with the specified region. This is useful, for example, while
63 streaming large files. A program may periodically request the
64 kernel to free cached data that has already been used, so that
65 more useful cached pages are not discarded instead.
66
67 Requests to discard partial pages are ignored. It is preferable
68 to preserve needed data than discard unneeded data. If the ap‐
69 plication requires that data be considered for discarding, then
70 offset and len must be page-aligned.
71
72 The implementation may attempt to write back dirty pages in the
73 specified region, but this is not guaranteed. Any unwritten
74 dirty pages will not be freed. If the application wishes to