244 Chapter 13
Figure 13-1: Summary of I/O buffering13.5 Advising the Kernel About I/O Patterns........................................................................
The posix_fadvise() system call allows a process to inform the kernel about its likely
pattern for accessing file data.The kernel may (but is not obliged to) use the information provided by
posix_fadvise() to optimize its use of the buffer cache, thereby improving I/O per-
formance for the process and for the system as a whole. Calling posix_fadvise() has
no effect on the semantics of a program.
The fd argument is a file descriptor identifying the file about whose access pat-
terns we wish to inform the kernel. The offset and len arguments identify the region
of the file about which advice is being given: offset specifies the starting offset of the
region, and len specifies the size of the region in bytes. A len value of 0 means allKernel memoryUser MemoryMake flushing automatic
on each I/O callKernel buffer cacheprintf(),stdio bufferDiskfsync()
fdatasync()
sync()fflush() setbuf(stream, NULL)open(path, flags |
O_SYNC, mode)User dataI/O system calls
write(), etc.Kernel-initiated writeTo force
buffer flushstdio library calls
fputc(), etc.#define _XOPEN_SOURCE 600
#include <fcntl.h>int posix_fadvise(int fd, off_t offset, off_t len, int advice);
Returns 0 on success, or a positive error number on error