Direct I/O is an unbuffered form of I/O for accessing files. If the VX_DIRECT advisory is set, the user requests direct data transfer between the disk and the user-supplied buffer for reads and writes. This bypasses the kernel buffering of data, and reduces the CPU overhead that is associated with I/O by eliminating the data copy between the kernel buffer and the user's buffer. Direct I/O also avoids taking up space in the buffer cache that might be better used for something else, such as an application cache. The direct I/O feature can provide significant performance gains for some applications.
For an I/O operation to be performed as direct I/O, it must meet certain alignment criteria. The disk driver, the disk controller, and the system memory management hardware and software usually determine the alignment constraints. The file offset must be aligned on a sector boundary (DEV_BSIZE). All user buffers must be aligned on a long or sector boundary. If the file offset is not aligned to sector boundaries, VxFS performs a regular read or write instead of a direct read or write.
If a request fails to meet the alignment constraints for direct I/O, the request is performed as data synchronous I/O. If the file is accessed by using memory mapped I/O, any direct I/O accesses are done as data synchronous I/O.
Because direct I/O maintains the same data integrity as synchronous I/O, it can be used in many applications that currently use synchronous I/O. If a direct I/O request does not allocate storage or extend the file, the inode metadata is not immediately written.
The CPU cost of direct I/O is about the same as a raw disk transfer. For sequential I/O to very large files, using direct I/O with large transfer sizes can provide the same speed as buffered I/O with much less CPU overhead.
If the file is extended or storage is allocated, direct I/O must write the inode change before returning to the application. This write eliminates some of the performance advantages of direct I/O.
The direct I/O advisory is maintained on a per-file-descriptor basis.