2 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH DIRECTIO 3C "Apr 9, 2003"
8 directio \- provide advice to file system
12 #include <sys/types.h>
13 #include <sys/fcntl.h>
15 \fBint\fR \fBdirectio\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIadvice\fR);
21 The \fBdirectio()\fR function provides advice to the system about the expected
22 behavior of the application when accessing the data in the file associated with
23 the open file descriptor \fIfildes\fR. The system uses this information to help
24 optimize accesses to the file's data. The \fBdirectio()\fR function has no
25 effect on the semantics of the other operations on the data, though it may
26 affect the performance of other operations.
29 The \fIadvice\fR argument is kept per file; the last caller of \fBdirectio()\fR
30 sets the \fIadvice\fR for all applications using the file associated with
34 Values for \fIadvice\fR are defined in \fB<sys/fcntl.h>\fR\&.
38 \fB\fBDIRECTIO_OFF\fR\fR
41 Applications get the default system behavior when accessing file data.
43 When an application reads data from a file, the data is first cached in system
44 memory and then copied into the application's buffer (see \fBread\fR(2)). If
45 the system detects that the application is reading sequentially from a file,
46 the system will asynchronously "read ahead" from the file into system memory so
47 the data is immediately available for the next \fBread\fR(2) operation.
49 When an application writes data into a file, the data is first cached in system
50 memory and is written to the device at a later time (see \fBwrite\fR(2)). When
51 possible, the system increases the performance of \fBwrite\fR(2) operations by
52 cacheing the data in memory pages. The data is copied into system memory and
53 the \fBwrite\fR(2) operation returns immediately to the application. The data
54 is later written asynchronously to the device. When possible, the cached data
55 is "clustered" into large chunks and written to the device in a single write
58 The system behavior for \fBDIRECTIO_OFF\fR can change without notice.
64 \fB\fBDIRECTIO_ON\fR\fR
67 The system behaves as though the application is not going to reuse the file
68 data in the near future. In other words, the file data is not cached in the
69 system's memory pages.
71 When possible, data is read or written directly between the application's
72 memory and the device when the data is accessed with \fBread\fR(2) and
73 \fBwrite\fR(2) operations. When such transfers are not possible, the system
74 switches back to the default behavior, but just for that operation. In general,
75 the transfer is possible when the application's buffer is aligned on a two-byte
76 (short) boundary, the offset into the file is on a device sector boundary, and
77 the size of the operation is a multiple of device sectors.
79 This advisory is ignored while the file associated with \fIfildes\fR is mapped
82 The system behavior for \fBDIRECTIO_ON\fR can change without notice.
88 Upon successful completion, \fBdirectio()\fR returns \fB0\fR. Otherwise, it
89 returns \fB\(mi1\fR and sets \fBerrno\fR to indicate the error.
93 The \fBdirectio()\fR function will fail if:
100 The \fIfildes\fR argument is not a valid open file descriptor.
109 The \fIfildes\fR argument is not associated with a file system that accepts
119 The value in \fIadvice\fR is invalid.
125 Small sequential I/O generally performs best with \fBDIRECTIO_OFF\fR.
128 Large sequential I/O generally performs best with \fBDIRECTIO_ON\fR, except
129 when a file is sparse or is being extended and is opened with \fBO_SYNC\fR or
130 \fBO_DSYNC\fR (see \fBopen\fR(2)).
133 The \fBdirectio()\fR function is supported for the NFS and UFS file system
134 types (see \fBfstyp\fR(1M)).
138 See \fBattributes\fR(5) for descriptions of the following attributes:
146 ATTRIBUTE TYPE ATTRIBUTE VALUE
154 \fBfstyp\fR(1M), \fBmmap\fR(2), \fBopen\fR(2), \fBread\fR(2), \fBwrite\fR(2),
155 \fBfcntl.h\fR(3HEAD), \fBattributes\fR(5)
159 Switching between \fBDIRECTIO_OFF\fR and \fBDIRECTIO_ON\fR can slow the
160 system because each switch to \fBDIRECTIO_ON\fR might entail flushing the
161 file's data from the system's memory.