3

Could someone please explain the differences between posix AIO and freebsd AIO? Seems the functions are the same, aio_read/aio_write.

I understand that linux native AIO is only available in Linux, and uses io_setup/io_submit, etc

vego
  • 889
  • 1
  • 8
  • 20
  • 1
    The FreeBSD man pages for aio_read, aio_write, aio_cancel, etc. all have a STANDARDS section that states something like _The () system call is expected to conform to IEEE Std 1003.1-2001 (“POSIX.1”)._ Why would you think they're different? Also, for Linux, if you need POSIX AIO, then you need to ensure you're using a C library that provides them. Glibc>=v2.1 and musl>=v1.1.7 should be conforming, but currently uClibc, uClibc-ng, dietlibc, or Bionic (Android) don't implement POSIX AIO at all. For those C libraries, use the Linux-specific system calls like io_setup (kernel>=v2.5). – MemReflect Jun 30 '20 at 06:38
  • So, it is thread based AIO? – vego Jun 30 '20 at 06:39
  • 1
    What is meant by thread-based? – arrowd Jun 30 '20 at 16:12
  • @arrowd https://stackoverflow.com/a/8782305/11474744 `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.` – vego Jul 01 '20 at 00:22
  • While linux native AIO is not thread based, it is done in kernel. So I want to know is freebsd the same thread based as posix aio? – vego Jul 01 '20 at 00:24

1 Answers1

1

FreeBSD AIO is also kernel based, which means it doesn't try to emulate asynchronous operations by spawning user-mode thread and running IO operations there.

As the man page says:

the calling thread invokes one system call to request an asynchronous I/O operation.

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • 1
    As a pure piece of additional information, BSD implements async file i/o using an in-kernel thread pool unless the handle is `O_DIRECT`. So whilst better than the situation on Linux, it's not "true universal async" like say io_uring on Linux, or `OVERLAPPED` on Windows, is. Also, POSIX aio scales very poorly to load due to poor design. It's generally a bad choice always, unless you use it via BSD kqueues, where it's actually pretty good. – Niall Douglas Jul 01 '20 at 12:46
  • @NiallDouglas I am curious, you mention that POSIX aio interface is bad *design*. However, when the interface is backed by BSD kqueues then it's actually pretty good. To me that sounds like that the design is just fine, but there is just not that many good implementations of it? I am just really curious as to what in the interface that limits good/scalable implementations. Hope you can share. – safl Mar 27 '21 at 09:26
  • @safl The `kqueue/kevent` mechanism can operate on different types of descriptors. Niall meant that you can pass `aio_sigevent` field as a parameter for `kevent` to get notifications on AIO operations completion. So this is not about "backing up" but "working in conjunction" instead. – arrowd Mar 28 '21 at 12:37