Sunday, February 2, 2014

UNIX I/O

RAW I/O is issued directly to the disk driver without going through the file system.  One drawback is the data cannot be managed by file system tools.  Double buffering is avoided.  Applications that maintain its own cache (e.g. database) uses this technique.

Direct I/O allows an application to use a file system but bypass the cache.  It is almost as direct as Raw I/O except the file system is still required to map the file offset to disk offset and I/O must be resized to match the physical on-disk layout.  Depending on file system, not only read and write buffering is disabled, pre-fetch may also be disabled too.  Direct I/O is often used by back up program that avoid polluting cache with data that only used once (not reused).

Non-blocking I/O is enabled by opening file using O_NONBLOCK or O_NDELAY flags.  System will returns EAGAIN error instead of blocking to tell the application to try again.

Memory mapped file is created using mmap() call.  The file is mapped to memory and access by offset instead of READ and WRITE system calls.  This can avoid double buffering.  Use of mmap() cannot solve performance problem due to I/O latency.  The saving is syscall overhead is insignificant comparing to long I/O time.

No comments: