aio_read、aio_write 是否被内核缓冲?在 Linux 的情况下,它们是否通过页面缓存?

Are aio_read, aio_write buffered by kernel? In case of Linux, does they go through page cache?

问题如题。 在 Linux 中,传递 O_DIRECT 绕过 buffer 完成的页面缓存。比如数据库系统会用它来管理自己的buffer。

我想知道 aio_write/aio_read 是否默认缓冲?他们当然要排队,但这是否涉及复制数据?如果它们默认被缓冲,可能我们可以只 open 文件而不传递 O_DIRECT,尽管在任何情况下传递 O_DIRECT 都会绕过普通文件的内核页面缓存。

POSIX standards 似乎暗示 aio_read/aio_write 没有被内核缓冲:

Effect of Buffering

If asynchronous I/O is performed on a file that is buffered prior to being actually written to the device, it is possible that asynchronous I/O will offer no performance advantage over normal I/O; the cycles stolen to perform the asynchronous I/O will be taken away from the running process and the I/O will occur at interrupt time. This potential lack of gain in performance in no way obviates the need for asynchronous I/O by realtime applications, which very often will use specialized hardware support, multiple processors, and/or unbuffered, synchronized I/O.

但是,在描述aio_read/aio_write关于缓冲的时候,没有明确的说法。

是的。他们通过内核缓存。 aio_fsync 证明了这一点。