Raw Disk IO

team bbl


Raw Disk I/O

Raw disk I/O is a process that interacts with a disk directly. File I/O, on the other hand, is where a process interacts with a physical device through an intermediary kernel cache. The read() and write() file I/O require the data to be copied to and from user space through kernel buffered regions. Data might exist in two memory locations simultaneously.

Some applications, such as databases, implement their own journaling. Applications that implement their own journaling can avoid duplicate logging (of their own database logs and the journaling file system logs) by performing I/O directly to the raw logical volume and bypassing the file system.

Raw disk I/O is unbuffered, and the data is not cached in a kernel buffer. One area where raw I/O is used to increase performance is in a relational database, such as IBM DB2 and Oracle. The performance can be increased in unbuffered raw I/O because these relational databases have their own I/O buffer for caching.

Setting up Raw I/O on Linux

Before setting up raw I/O on Linux, you need the following:

  • One or more free IDE or SCSI disk partitions.

  • A raw device controller named /dev/rawctl or /dev/raw. If you do not have such a raw device controller, create a symbolic link with the following command:

 # ln s /dev/your_raw_dev_ctrl/.dev/rawctl 

Linux has a pool of raw device nodes that must be bound to a block device before raw I/O can be performed on it. There is raw device controller that acts as the central repository of raw I/O to block device binding information. Binding is performed with a utility named raw.

Example

The following example configures raw I/O on Linux. The example uses raw partition /dev/sda5, which contains no valuable data:

  1. Calculate the number of 4096-byte pages in the partition, rounding down if necessary. For example:

     # fdisk /dev/sda Command (m for help): p      Device boot   Start   End   Blocks   Id   System      /dev/sd1a     1       523   4200997   83   Linux      /dev/sda5     524     1106  4682947   83   Linux Disk /dev/sda: 255 heads, 63 sectors, 1106 cylinders Units = cylinders of 16065 * 512 bytes Command (m for help): q # Table 1. Linux raw I/O calculations.             The number of pages in /dev/sda5 is              num_pages = (((1106-524+1)*16065*512)/4096)             num_pages = 11170736 

  2. Bind an unused raw device node to this partition. This step needs to be done every time the machine is rebooted, and it requires root access. Use raw -a to see which raw device nodes are already in use:

     # raw /dev/raw/raw1 /dev/sda5 /dev/raw/raw1: bound to major 8, minor 5 

  3. Set the appropriate read permissions on the raw device controller and the disk partition. Set the appropriate read and write permissions on the raw device. The raw device is now ready to be used.

    team bbl



    Performance Tuning for Linux Servers
    Performance Tuning for Linux Servers
    ISBN: 0137136285
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net