POSIX AIO和libaio的Linux上的区别? [英] Difference between POSIX AIO and libaio on Linux?

查看:2241
本文介绍了POSIX AIO和libaio的Linux上的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的什么似乎的理解:

POSIX AIO API的原型在< aio.h> 和你librt链接程序( - LRT),而在 libaio的的API < libaio.h> 和你的程序与libaio的(挂-laio )。

POSIX AIO APIs are prototyped in <aio.h> and you link your program with librt(-lrt), while the libaio APIs in <libaio.h> and your program is linked with libaio (-laio).

我想不通:

1.Does内核来处理的不是这些方法的不同?

1.Does the kernel handle the either of these methods differently?

2.Is的 O_DIRECT 标志强制使用其中任何一个?

2.Is the O_DIRECT flag mandatory for using either of them?

这个帖子,libaio的正常工作没有 O_DIRECT使用 libaio的 .Okay时,理解,但:

As mentioned in this post, libaio works fine without O_DIRECT when using libaio.Okay,understood but:

据R.Love的的Linux系统编程的书,Linux支持的 AIO 的(我假设是POSIX AIO)上的常规文件的只有的若与 O_DIRECT 打开。但调用一个小程序,我写的(使用aio.h,与-lrt链接)则aio_write 上没有 O_DIRECT 标志作品不开的问题的文件。

According to R.Love's Linux System Programming book, Linux supports aio (which I assume is POSIX AIO) on regular files only if opened with O_DIRECT.But a small program that I wrote (using aio.h,linked with -lrt) that calls aio_write on a file opened without the O_DIRECT flag works without issues.

推荐答案

在Linux上,这两个AIO实现是根本不同的。

On linux, the two AIO implementations are fundamentally different.

该POSIX AIO是执行正常封闭在多线程I / O,因此给人的错觉的I / O是异步的用户级执行。主要的理由这样做是:

The POSIX AIO is a user-level implementation that performs normal blocking I/O in multiple threads, hence giving the illusion that the I/Os are asynchronous. The main reason to do this is that:


  1. 与任何文件系统
  2. 工作
  3. 它的工作原理(本质上)在任何操作系统上(请记住,GNU的libc的是便携式)

  4. 它的工作原理上启用了缓冲的文件(即没有O_DIRECT标志设置)

的主要缺点是,你的队列深度(即你可以在实践中未完成的操作数)是由您选择了线程的数量,这也意味着一个磁盘上一个缓慢的操作可能会阻塞的操作限制去到不同的磁盘。它也影响它的I / O(或多少)由内核和磁盘调度以及可见。

The main drawback is that your queue depth (i.e. the number of outstanding operations you can have in practice) is limited by the number of threads you choose to have, which also means that a slow operation on one disk may block an operation going to a different disk. It also affects which I/Os (or how many) is seen by the kernel and the disk scheduler as well.

内核AIO(即io_submit()等人)是异步I / O操作,这里的IO请求实际上是在内核排队,排序任何磁盘调度程序你有,presumably内核支持他们中的一些将被转移(在某种程度上最佳次序人们希望),以实际的磁盘异步操作(使用TCQ或NCQ)。这种方法的主要限制是,并非所有的文件系统的工作,以及或所有异步I / O(并可能回落到阻塞语义),文件都必须使用O_DIRECT打开附带一大堆的其他限制I / O请求。如果你没有使用O_DIRECT打开文件,它可能仍然工作,在你得到正确的数据备份,但它可能不是异步完成,但回落至阻塞语义。

The kernel AIO (i.e. io_submit() et.al.) is kernel support for asynchronous I/O operations, where the io requests are actually queued up in the kernel, sorted by whatever disk scheduler you have, presumably some of them are forwarded (in somewhat optimal order one would hope) to the actual disk as asynchronous operations (using TCQ or NCQ). The main restriction with this approach is that not all filesystems work that well or at all with async I/O (and may fall back to blocking semantics), files have to be opened with O_DIRECT which comes with a whole lot of other restrictions on the I/O requests. If you fail to open your files with O_DIRECT, it may still "work", as in you get the right data back, but it probably isn't done asynchronously, but is falling back to blocking semantics.

另外记住,io_submit()可以在某些情况下在磁盘上的实际阻塞。

Also keep in mind that io_submit() can actually block on the disk under certain circumstances.

这篇关于POSIX AIO和libaio的Linux上的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆