However, if the process instead uses the asynchronous aio_read() or aio_write() system calls (called aioread() and aiowrite() on some operating systems), then the system call will return immediately once the I/O request has been passed down to the hardware or queued in the operating system, typically before the physical I/O operation has even begun. The execution of the process is not blocked, because it does not need to wait for the results of the system call. Instead, it can continue executing and then receive the results of the I/O operation later, once they are available. This is asynchronous or non-blocking I/O.
Asynchronous I/O enables write intensive processes like Oracle's DBWn to make full use of the I/O bandwidth of the hardware by queuing I/O requests to distinct devices in quick succession so that they can be processed largely in parallel. Asynchronous I/O also allows processes performing compute intensive operations like sorts to pre-fetch data from disk before it is required so that the I/O and computation can occur in parallel.
The performance of asynchronous I/O is heavily dependent on the operating system's implementation of the aio_read() and aio_write() system calls. Kernelized asynchronous I/O is greatly preferable to threaded asynchronous I/O but it is only available for raw devices and Quick I/O files.
异步I/O,就是非阻塞I/O。在我们传统的调用write或者read中,我们往往等待系统调用成功后才会从该函数中返回,如果函数一时间没有返回,那么我们的线程将会阻塞在系统调用这个地方。系统调用结束后,我们通过系统调用函数的返回值来查看这次的调用是否成功还是失败。而通过异步i/o,我们的线程在将I/O请求发送到I/O设备后就会立刻返回,接着下面的执行工作。I/O设备在处理完我们的请求后,会通过其他方式告诉我们处理请求的结果。这就是异步i/o的原理。简单而言,就是让I/O操作和我们的线程执行同时执行。