c++ - O_DIRECT 与 AIO_RAW

标签 c++ file asynchronous posix device

使用 POSIX 异步 I/O 时,使用 O_DIRECTAIO_RAW 有什么区别吗?或者我应该/我可以同时使用两者吗?我们正在开发 NoSQL 数据库服务器,并正在寻找使异步 I/O 在 POSIX 系统上更高效的方法。

open(2) :

O_DIRECT Try to minimize cache effects of the I/O to and from this file. In general this will degrade performance, but it is useful in special situations, such as when applications do their own caching. File I/O is done directly to/from user space buffers.

aiocb(5) :

You may set the AIO_RAW flag bit in the aio_flags structure member when the asynchronous I/O is being done to a raw device partition. When the AIO_RAW flag bit is set, asynchronous I/O might possibly be more efficient.

最佳答案

提问者从未具体说明他们支持哪些操作系统(一个链接指向 Linux 手册页,另一个链接指向 SCO 手册页),因此很难在没有推测的情况下回答这个问题。

在撰写本文时,Linux 不支持 AIO_RAW,因为 glibc 的 struct aiocb 没有 aio_flags 成员(https://www.gnu.org/software/libc/manual/html_node/Asynchronous-I_002fO.html ) 并且内核 AIO(不是 POSIX)不支持 AIO_RAW 值。所以:

are there any differences between using O_DIRECT and AIO_RAW? Or should I/can I use both?

是的,因为并非所有支持 POSIX AIO 的操作系统(例如 Linux)都允许您设置 AIO_RAW,而且肯定会有您不能同时使用两者的情况。此外,在某些操作系统(例如 Linux)上,O_DIRECT 可以用于文件系统内部和设备上的文件,而 AIO_RAW 仅适用于“原始设备”。从 dt 源代码来看,AIO_RAW 似乎只在 HP-UX 和 SCO Unix 上受支持,因此它在其他操作系统上的使用可能有限。

关于c++ - O_DIRECT 与 AIO_RAW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15998294/

相关文章:

c++ - 公共(public)成员未初始化

C++ 在构造函数中初始化函数指针

c++ - 程序总是产生相同的值(value)?

java - Android Loader 是否在单独的线程中执行其工作?

multithreading - Action Script 3.0中的异步

c++ - 取代ezXML

Python在具有特定扩展名的目录中获取最新文件

c++ - Assimp Faces 都有索引 (0,1,2)

multithreading - 顺序执行和同步执行有什么区别?

c++ - 链接器 LNK2005 错误