Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. File I/O Buffering > Advising the Kernel About I/O Patterns

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.

#include <fcntl.h>

int posix_fadvise(int fd, off_t offset, off_t len, int advice);

Note

Returns 0 on success, or a positive error number on error

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 performance 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 patterns 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 all bytes from offset through to the end of the file. (In kernels before 2.6.6, a len of 0 was interpreted literally as zero bytes.)


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint