Direct I/O

Discussion in 'Filesystem' started by Jarret W. Buse, Jul 10, 2013.

  1. Jarret W. Buse

    Jarret W. Buse Active Member Staff Writer

    Messages:
    148
    Likes Received:
    183
    Trophy Points:
    43
    Direct I/O


    Data read from a storage unit will normally be read from the media, written to memory (the file buffer cache of the RAM) and accessed by the application requesting it.

    NOTE: Applications that perform its own data caching perform their own version of Direct I/O.

    Be aware that data being read from a storage unit will also be processed by the CPU. Another process called Direct Memory Access (DMA) does allow for data from the storage unit to bypass the CPU. With DMA, data does go directly from the storage unit to the RAM. Using DMA can reduce access time when reading files. Keep in mind that the Direct I/O will bypass the CPU anyway, but files without Direct I/O enabled will still go through the CPU. Direct I/O will reduce CPU usage giving a performance boost so the CPU is available for other processes.

    Data read from the hard disk is held in the buffer, or cache. When multiple files are being requested, the files compete for the cache space. If one file requires more cache, other files must be cleared to open up cache space. Direct I/O bypasses the cache so the “battle” for cache space is reduced.

    Once data has been read from the disk and moved to the file buffer in RAM, it must then be moved to the application buffer. From a programming aspect, memory is set aside for use by the application. Usually this is done by creating arrays or some type of data object then placing the file information into it. Once the data is ready in the array or object, it is considered in the application buffer.

    Once the application is done with the data and the user saves the file (or the application does itself), the data is sent directly back to the storage unit. Again, the data bypasses the buffers.

    Let’s look at this process:

    1. Application X requests a file from the hard disk
    2. The OS sends the request to the hard disk controller
    3. The controller retrieves the required file
    4. The file is sent to the CPU (unless DMA is enabled)TThe file is sent to the file buffer
    5. The file is sent to the application buffer
    6. The application uses the required file as needed
    7. The file is sent to the file buffer
    8. The file is sent to the CPU (unless DMA is enabled)
    9. The OS sends the request to the hard disk controller
    10. The controller writes the required file
    As you can see, moving data from the storage unit, possibly to the CPU, then to the file buffer and finally to the application buffer can take a lot of time and resources. With some file systems, it is possible to skip the file buffer. Of course, if DMA is enabled on the hardware side, the CPU is skipped as well.

    NOTE: We’ll assume that the storage media has DMA enabled.

    Direct I/O allows the file buffer to be skipped saving more time. The process is then as follows:


    1. Application X requests a file from the hard disk
    2. The OS sends the request to the hard disk controller
    3. The controller retrieves the required file
    4. The file is sent to the application buffer
    5. The application uses the required file as needed
    6. The OS sends the request to the hard disk controller
    7. The controller writes the required file
    Of course, this is a basic listing of the whole process, but you can get the idea that time is saved with Direct I/O.

    NOTE: Remember that anytime data retrieval can bypass any piece of hardware, not matter how fast it may be, time is saved. Another portion of time lag is the data buses on the motherboard between devices. When data can bypass hardware, the time in the buses is reduced. This can be an important time saver.

    Direct I/O is enabled on individual files or directories as a whole. When a folder has the Direct I/O flag set, any file written within the folder will inherit the flag as well.

    For example, on an enhanced JFS file system, you can use the mount command. A list is shown and if “dio” is listed, then the folder has Direct I/O enabled.

    To enable Direct I/O on a JFS2 drive, use the following command:

    Code:
    mount -o dio
    NOTE: Direct I/O does not work with files which are compressed or encrypted. These files are required to be processed (decompressed and decrypted) before being sent to RAM.

    The FILESYSTEMIO_OPTIONS can be set to “directio” or “setall” to enable Direct I/O by one of the following:

    Code:
    filesystemio_options=directio
     
    filesystemio_options=setall

    Attached Files:

Share This Page