Serialization of I/O operations

Hello,

It is important for certain applications to maintain the execution
order of I/O operations, e.g. database servers.
Our concern is related to the execution order of I/O requests issued
by such an application, and, as a result,
which implementations are valid at the storage driver level.

Example: say an application (from within a single thread) issues 3
consecutive overlapped I/O requests: write(A), read, write(B).
Both the writes and the read refer to the same location in the same
file, and access to the file is done using the same handle.
If the requests are performed in the order issued, the read is
guaranteed to return A.
However, if they are handled out of order, it may be possible for the
read to return B, A, or the value that was present
in that location before write(A) (all up to the specific
non-deterministic timing scenario that occurred when the
specific sequence was issued).

Clearly, any application that requires proper I/O operation ordering
has to find a resolution for the above issue:

a. It is possible that the application itself will avoid any possible
contention, i.e. in the above example, detect the reference
to the same location in file of the 3 requests, and delay the issuance
of the read operation until after write(A) returns, and defer the
issuance of write(B) until the read returns.

b. It is also possible that the operating system will take care of
the execution order:

a. The file system could resolve the contentions and synchronize
calls whenever inconsistent results may be returned
due to out of order execution.

b. The file system may rely on the I/O manager to do the work.

c. The entire set of upper layers (application, FS, I/O manager) may
assume that the driver processes the I/O requests in the order
received (by the driver).

d. ?and maybe there are other modules that take care of
synchronization along this stack?

We are implementing a storage device driver, and would like to take
advantage of some performance enhancements
that we can achieve if we execute I/O operations out of order. We want
to know if this is “allowed” and has absolutely no risk of causing any
unexpected behavior on the application level (which may lead to data
corruption, e.g. in database servers).

Alex

P.S
I would like to note that I sent it to both lists – ntfs and ntdev –
as I believe it might have to do with filesystem as well.

Wow… a rare question that can be answered definitively on this forum!

Neither the OS nor any component part of the OS provides any guarantee regarding preserving the order of operating in the storage stack. Full stop. Period.

Consider an application that sends two asynchronous reads to a file system. The first read requires that the file system retrieve meta-data to be able to satisfy it, but the second read can be immediately satisfied with data from cache. You can be SURE that the file system will satisfy the second read, while the first read remains pending. That’s just one example of many… consider scheduling, and what happens when you start to send requests off to worker threads. Not to mention disk drives that can have numerous I/O requests in progress simultaneous, with the whole purpose being to be able to sort these requests and complete them in a priority optimized order.

If an applications needs I/O operations to be serialized, that application needs to send the requests serially: Send one, wait for it to complete, then send the next.

Peter
OSR