xref: /freebsd/lib/libsys/posix_fadvise.2 (revision 1edb7116)
1.\" Copyright (c) 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd March 30, 2020
29.Dt POSIX_FADVISE 2
30.Os
31.Sh NAME
32.Nm posix_fadvise
33.Nd give advice about use of file data
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In fcntl.h
38.Ft int
39.Fn posix_fadvise "int fd" "off_t offset" "off_t len" "int advice"
40.Sh DESCRIPTION
41The
42.Fn posix_fadvise
43system call
44allows a process to describe to the system its data access behavior for an
45open file descriptor
46.Fa fd .
47The advice covers the data starting at offset
48.Fa offset
49and continuing for
50.Fa len
51bytes.
52If
53.Fa len
54is zero,
55all data from
56.Fa offset
57to the end of the file is covered.
58.Pp
59The behavior is specified by the
60.Fa advice
61parameter and may be one of:
62.Bl -tag -width POSIX_FADV_SEQUENTIAL
63.It Dv POSIX_FADV_NORMAL
64Tells the system to revert to the default data access behavior.
65.It Dv POSIX_FADV_RANDOM
66Is a hint that file data will be accessed randomly,
67and prefetching is likely not advantageous.
68.It Dv POSIX_FADV_SEQUENTIAL
69Tells the system that file data will be accessed sequentially.
70This currently does nothing as the default behavior uses heuristics to
71detect sequential behavior.
72.It Dv POSIX_FADV_WILLNEED
73Tells the system that the specified data will be accessed in the near future.
74The system may initiate an asynchronous read of the data if it is not already
75present in memory.
76.It Dv POSIX_FADV_DONTNEED
77Tells the system that the specified data will not be accessed in the near
78future.
79The system may decrease the in-memory priority of clean data within the
80specified range and future access to this data may require a read operation.
81.It Dv POSIX_FADV_NOREUSE
82Tells the system that the specified data will only be accessed once and
83then not reused.
84The system may decrease the in-memory priority of data once it has been
85read or written.
86Future access to this data may require a read operation.
87.El
88.Sh RETURN VALUES
89If successful,
90.Fn posix_fadvise
91returns zero.
92It returns an error on failure, without setting
93.Va errno .
94.Sh ERRORS
95Possible failure conditions:
96.Bl -tag -width Er
97.It Bq Er EBADF
98The
99.Fa fd
100argument is not a valid file descriptor.
101.It Bq Er EINVAL
102The
103.Fa advice
104argument is not valid.
105.It Bq Er EINVAL
106The
107.Fa offset
108or
109.Fa len
110arguments are negative,
111or
112.Fa offset
113+
114.Fa len
115is greater than the maximum file size.
116.It Bq Er ENODEV
117The
118.Fa fd
119argument does not refer to a regular file.
120.It Bq Er ESPIPE
121The
122.Fa fd
123argument is associated with a pipe or FIFO.
124.It Bq Er EIO
125An I/O error occurred while reading from or writing to a file system.
126.It Bq Er EINTEGRITY
127Corrupted data was detected while reading from the file system.
128.El
129.Sh SEE ALSO
130.Xr madvise 2
131.Sh STANDARDS
132The
133.Fn posix_fadvise
134interface conforms to
135.St -p1003.1-2001 .
136.Sh HISTORY
137The
138.Fn posix_fadvise
139system call first appeared in
140.Fx 9.1 .
141