BrainDump
  Home arrow BrainDump arrow Page 4 - Advising the Linux Kernel on File I/O
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
BRAINDUMP

Advising the Linux Kernel on File I/O
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2008-12-24


    Table of Contents:
  • Advising the Linux Kernel on File I/O
  • Advice Is Cheap
  • Synchronized, Synchronous, and Asynchronous Operations
  • Asynchronous I/O

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Advising the Linux Kernel on File I/O - Asynchronous I/O
    ( Page 4 of 4 )

    Performing asynchronous I/O requires kernel support at the very lowest layers. POSIX 1003.1-2003 defines the aio interfaces, which Linux fortunately implements. The aio library provides a family of functions for submitting asynchronous I/O and receiving notification upon its completion:

      #include <aio.h>

      /* asynchronous I/O control block */
      struct aiocb {
              int aio_filedes;        /* file descriptor */
              int aio_lio_opcode;     /* operation to perform */
              int aio_reqprio;        /* request priority offset */
              volatile void *aio_buf; /* pointer to buffer */
              size_t aio_nbytes;      /* length of operation */
              struct sigevent aio_sigevent;                     /*
    signal number and value */

              /* internal, private members follow... */
      };

      int aio_read (struct aiocb *aiocbp);
      int aio_write (struct aiocb *aiocbp);
      int aio_error (const struct aiocb *aiocbp);
      int aio_return (struct aiocb *aiocbp);
      int aio_cancel (int fd, struct aiocb *aiocbp);
      int aio_fsync (int op, struct aiocb *aiocbp);
      int aio_suspend (const struct aiocb * const cblist[],
                      
    int n,
                       const struct timespec *timeout);

    Thread-based asynchronous I/O

    Linux only supports aio on files opened with the O_DIRECT flag. To perform asynchronous I/O on regular files opened without O_DIRECT, we have to look inward, toward a solution of our own. Without kernel support, we can only hope to approximate asynchronous I/O, giving results similar to the real thing.

    First, let’s look at why an application developer would want asynchronous I/O:

    1. To perform I/O without blocking
    2. To separate the acts of queuing I/O, submitting I/O to the kernel, and receiving notification of operation completion

    The first point is a matter of performance. If I/O operations never block, the overhead of I/O reaches zero, and a process need not be I/O-bound. The second point is a matter of procedure, simply a different method of handling I/O.

    The most common way to reach these goals is with threads (scheduling matters are discussed thoroughly in Chapters 5 and 6). This approach involves the following programming tasks:

    1. Create a pool of “worker threads” to handle all I/O.
    2. Implement a set of interfaces for placing I/O operations onto a work queue.
    3. Have each of these interfaces return an I/O descriptor uniquely identifying the associated I/O operation. In each worker thread, grab I/O requests from the head of the queue and submit them, waiting for their completion.
    4. Upon completion, place the results of the operation (return values, error codes, any read data) onto a results queue.
    5. Implement a set of interfaces for retrieving status information from the results queue, using the originally returned I/O descriptors to identify each operation.

    This provides similar behavior to POSIX’s aio interfaces, albeit with the greater overhead of thread management.

    Please check back next week for the continuation of this article.



     
     
    >>> More BrainDump Articles          >>> More By O'Reilly Media
     

       

    BRAINDUMP ARTICLES

    - Replacing Oracle with PostgreSQL
    - Demystifying SELinux on Kernel 2.6
    - Yahoo and Microsoft Create Ad Partnership
    - The Advantages of Obscure Open Source Browse...
    - Dell Announces CSI-style Digital Forensics S...
    - Milepost GCC Speeds Open-Source Development
    - Learn These 10 Programming Languages
    - Tomcat Capacity Planning
    - Internal and External Performance Tuning wit...
    - Tomcat Benchmark Procedure
    - Benchmarking Tomcat Performance
    - Tomcat Performance Tuning
    - Wubi: Windows-based Ubuntu Installer
    - Configuring and Optimizing Your I/O Scheduler
    - Linux I/O Schedulers





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek