An alternative to the application barrier() call
Posted Sep 13, 2009 17:46 UTC (Sun) by
anton (guest, #25547)
In reply to:
An alternative to the application barrier() call by dlang
Parent article:
POSIX v. reality: A position on O_PONIES
Code that writes a few characters here and a few characters there
usually uses the FILE * based interface, which performs
user-space buffering and then typically performs write() (or somesuch)
calls of 4k or 8k at a time; just strace one of these programs.
That's done to reduce the system call overhead. But even if such
programs perform a write() for each of the application writes, having
barriers between each of them does not kill performance, because a
sequence of such writes can be merged.
Concerning the block device below, if that does not heed the block
device barriers or other block device ordering mechanisms that the
file system requests, then you get no guarantee at all of any
consistency on crash/power failure. It's not just that merged writes
won't work, your style of merge-preventing barriers won't work, either, and
neither will the guarantees that fsync()/fdatasync are supposed to
provide; that's because all of them require that the block device
ordering mechanism(s) that the file system uses actually work, and all
of them will produce inconsistent states if the writes happen in an
order that violates the ordering requests. So, if you want any
consistency guarentees at all, you need an appropriate block device,
and then you can implement mergeable writes just as well as anything
else.
As for an array where a write spans drives, implementing a barrier
or other ordering mechanism on the array level certainly requires
something more involved than just doing barriers on the individual
block devices, but the device has to provide these facilities, or you
can forget about crash consistency on that device (i.e., just don't
use it).
(
Log in to post comments)