Direct I/O on Linux

9,032

ext4 doesn't have a dio mount option (I believe AIX and Solaris do) but it does have dioread_lock and dioread_nolock mount options. From the mount(8) manual page:

dioread_lock/dioread_nolock

Controls whether or not ext4 should use the DIO read locking. If the dioread_nolock option is specified ext4 will allocate uninitialized extent before buffer write and convert the extent to initialized after IO completes.

This approach allows ext4 code to avoid using inode mutex, which improves scalability on high speed storages. However this does not work with data journaling and dioread_nolock option will be ignored with kernel warning. Note that dioread_nolock code path is only used for extent-based files. Because of the restrictions this options comprises it is off by default (e.g. dioread_lock).

That said, as others have mentioned, direct I/O is normally enabled by setting the O_DIRECT flag in the open(2) system call - ie, it's controlled by the application, not a mount option. O_DIRECT is supported by ext4, unless you're using the data=journal mount option (see ext4 documentation and this commit).

For InnoDB I know the innodb_flush_method parameter can be used to enable O_DIRECT, but I'm not aware of a similar setting for MyISAM?

Share:
9,032

Related videos on Youtube

BerserkEVA
Author by

BerserkEVA

It's 20+ years since when I started being a developer for a living. Before that development was only endless fun, no matter if day or night. I profoundly love C, C++, Java, Python, PHP and JavaScript. And Unix shell scripting too (Korn, TC, Bash mainly). I'm delighted by: meaningful, well-written code meaningful, well-written and funny comments meaningful, well-written and funny specs Japanese anime and manga mathematics not necessarily in that order. Oh yes, I almost forgot: I am an aged, grumbling and devoted fan of Unix. But I like Linux a lot as well.

Updated on September 18, 2022

Comments

  • BerserkEVA
    BerserkEVA over 1 year

    I'm trying to enable Direct I/O on /opt (/dev/sda6, ext4) on Linux Mint 13. What I'm trying is:

    mount -o dio,rw /dev/sda6 /opt
    

    as root.

    The system responds with:

    mount: wrong fs type, bad option, bad superblock on /dev/hda2
    

    dmesg is reporting:

    EXT4-fs (sda6): Unrecognized mount option "dio" or missing value.
    

    I can't figure out which parameter to set to enable direct I/O (and even if mounting with direct I/O is possible for ext4). Besides this, if ext4 should not support direct I/O, could someone please indicate a filesystem to use on Linux which does?

    • Matthew Ife
      Matthew Ife over 10 years
      Why do you want all disk accesses direct in the first place?
    • BerserkEVA
      BerserkEVA over 10 years
      @MIfe I need it due to the fact that I'm in an embedded environment and my unit is powered by solar panels, so it may suddenly lose power due to the lack of enough solar radiation. If the writings to my database are not completed, it could be end up corrupted. Unfortunately I'm not in the position of having a UPS or similar to handle power failure gracefully.
    • Michael Hampton
      Michael Hampton over 10 years
      If it's an embedded system, why aren't you using a filesystem designed for embedded systems?
    • BerserkEVA
      BerserkEVA over 10 years
      @MichaelHampton : could you suggest one? the ext4 filesystem has been chosen by previous implementors.
    • Matthew Ife
      Matthew Ife over 10 years
      Consider making your database something that is ACID compliant and claims consistency even during power failure. Like SQLite.
    • BerserkEVA
      BerserkEVA over 10 years
      Thanks for your suggestion @MIfe; unfortunately I'm stuck with MySQL (myIsam) right now and switching to SQLite is hardly an option at this late stage.
    • DiverseAndRemote.com
      DiverseAndRemote.com about 9 years
      This would have been really helpful if someone actually answered the question.
    • neverMind9
      neverMind9 over 5 years