使用 aio_write() 但仍然看到数据通过缓存?
我正在 Linux 2.6.16.46 上使用此代码:
io.aio_fildes = open(name, O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 00300);
io.aio_buf = buffer;
io.aio_nbytes = size;
io.aio_sigevent = sigev;
io.aio_lio_opcode = LIO_WRITE;
aio_write( &io );
这应该使用缓冲区指向的内存进行 IO 操作。尽管如此,我还是看到脏页的数量增加了,就像我正在写入缓存一样。这是为什么?
在构建机器上,open() 中没有 O_DIRECT 支持。但由于我没有使用 write(),这仍然是一个问题吗?
我很确定目标上有直接 IO 支持。
I'm playing with this code on Linux 2.6.16.46:
io.aio_fildes = open(name, O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 00300);
io.aio_buf = buffer;
io.aio_nbytes = size;
io.aio_sigevent = sigev;
io.aio_lio_opcode = LIO_WRITE;
aio_write( &io );
This should use the memory pointed by buffer for the IO operation. Still, I see the number of dirty pages go up as if I was writing to cache. Why is that?
On the build machine, there's no O_DIRECT support in open(). But since I'm not using write(), should that still be a problem?
I'm pretty sure there's direct IO support on the target.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
明白了这一点。直接/缓冲 IO 是一回事,同步/异步是另一回事。要使异步写入避免缓存,即使不使用 write(),仍然需要为 open() 调用提供 O_DIRECT。
一开始可能会出现编译器错误 - 仔细阅读 man 2 open 。
figured this out. Direct/buffered IO is one thing, sync/async is another. To have async writes avoid cache one still needs to give O_DIRECT to the open() call, even if write() is not used.
There will likely be compiler errors at first - read man 2 open carefully.