0

When doing multiple aio_writes to file is it necessary to wait (e.g. aio_suspend or other) before starting the next one? From the documentation it says that writes are enqueued so does that mean they are written in order? Also, I can track the offset and make sure nothing is ever overwritten (I'm assuming that a failed write could leave a gap in this case).

Coder909
  • 35
  • 9

1 Answers1

0

You've asked two questions:

  • Can I issue new aios before previous aio finishes?
  • If so, are aios finished in-order(i.e. the same as issue order)?

Essentially aio works asynchronously only for O_DIRECT opened files, so I assume it following.

The answer is:

  1. Yes. That's one essential usage of asynchronous I/O
  2. No. You can almost assume nothing on their completion order

aio(different from POSIX aio, see also here) is a linux native support for asynchronous I/O. You submit async I/O to kernel, kernel records it and performs it in background asynchronously. Also, multiple "outstanding" async I/O is permitted and will be maintained by kernel.

As for order, more specifically, write order here, there are many potentials to reorder them inside the kernel.

A typical reorder comes from block layer, which accepts disk write requests from upper filesystem layer and delivers them to lower device driver layer. Within block layer there are many request schedulers, which will schedule the I/O into a "suitable" order. Well, how the "suitable" here is defined depends on the scheduler type. For example, HDD may try to merge more requests and cache a single sector/page waiting for merge potential, which incurs reorder. For more info here is an introduction.

For strong order requirement, you may control it manually by waiting for aios to finish before issuing more.

Kirhhoff
  • 46
  • 2