IDE block i/o & ordering

Helge Hafting (helge.hafting@idb.hist.no)
Mon, 20 Dec 1999 10:23:34 +0100


>Btw. I found an oddity with the IDE block device interface
>(causes problems with DropStuffit in MacOS 9). In a sequence like
>
> write A to sector N
> write B to sector N
> read sector N
>
>then the read might not return the information "B" (but something
>else). I've always assumed that the block device drivers were
>supposed to enforce this consistency but I might be wrong. Everything
>work as it should if an extra "fsync" is inserted after each
>write. This might impact driver performance though.

What is sector N used for? Part of a file opened by several processes?
If two processes open a file, one reading and another writing then
they may execute in parallell (particularly on SMP systems).
If the "reader" reads a sector that the "writer" is busy writing to,
then the reader may end up reading half "old" stuff and half "freshly
written" stuff from that sector.

Not forcing synchronization gives better performance, and it is
consistent with the bigger picture: If the writer writes a million
sectors and the reader reads a million sectors then the reader
may get several old and several new sectors on any os.
Linux merely lets this happen on the byte level too.
This is designed into the page cache, and may happen on
any platform, with any kind of block device.

An application that needs synchronization must handle the issues
itself. fsync may help but not necessarily; the "reader" may read
while the writer is in the middle of writing "B", before the writer
does the fsync. You really need a semaphore.

Helge Hafting

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/