Date: Sun, 14 Jan 2024 11:23:35 -0700 From: Alan Somers <asomers@freebsd.org> To: =?UTF-8?Q?Vin=C3=ADcius_dos_Santos_Oliveira?= <vini.ipsmaker@gmail.com> Cc: Konstantin Belousov <kostikbel@gmail.com>, freebsd-threads@freebsd.org, Konstantin Belousov <kib@freebsd.org> Subject: Re: aio_read2() and aio_write2() Message-ID: <CAOtMX2iWzPvkzpdp4K5VVkWQicyidT2ibF=_==e_PLaRj6s6WQ@mail.gmail.com> In-Reply-To: <CAK9RveJ9G4Cbq2pPAbfy_nC9dMtQT-b=xO__0=rzWLiyqZNqLw@mail.gmail.com> References: <CAOtMX2haq%2BErvqD2PDYKUGRgdCrk2SDjtoPL-W5jR8q8_4denA@mail.gmail.com> <CAK9RveJLK9uU0twM%2BKznUNnUnsqzwoqidPN8dzNptMQ50Z7r1Q@mail.gmail.com> <CAOtMX2ijQ=KsccMyqH-yAn6SJPR7MD_yy6CF0R2vNrQ-fhUq2Q@mail.gmail.com> <ZaMsUn8xFKrDkJb_@kib.kiev.ua> <CAK9Rve%2BuYpxWyRPwh6gxjRkisU7WPKjXicU9%2BYiqFG-=c3trvg@mail.gmail.com> <CAOtMX2h7vmwKHWUm7aHAfJ0QGPYfaWUmriu%2BxpwA2yK8O2YOoA@mail.gmail.com> <CAK9RveK-sjLxCkKpkSTYkecRQVwT%2BuoOSsaW3xD130Hnwb=cog@mail.gmail.com> <CAOtMX2gbJ6jBSBdyQuwJqPrwDom25=LgrApCBiy5oFuVXL5nQA@mail.gmail.com> <CAK9RveJ9G4Cbq2pPAbfy_nC9dMtQT-b=xO__0=rzWLiyqZNqLw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Jan 14, 2024 at 10:30=E2=80=AFAM Vin=C3=ADcius dos Santos Oliveira <vini.ipsmaker@gmail.com> wrote: > > Em dom., 14 de jan. de 2024 =C3=A0s 14:13, Alan Somers > <asomers@freebsd.org> escreveu: > > The problem is that this flag would be almost impossible to use > > correctly for the intended use cases of POSIX AIO. Your application > > is actually pretty unusual in that it only has one operation in-flight > > at a time. I think it would be better to use the lseek solution > > rather than add a footgun to POSIX AIO. > > There are two things here: Boost.Asio, and applications built on top > of Boost.Asio. I can't speak for other applications built on top of > Boost.Asio. With that in mind, let me proceed. > > There is nothing unusual about my application. I just built an > execution context that implements the green threading model. That's > nothing unusual about that. NodeJS, Python's asyncio, Rust's asyncio, > Golang, luvit, and so on and so on. All these frameworks just mimic > interfaces from the blocking world (e.g. two threads doing a blocking > read() on two different files become two fibers doing a read() within > the same thread). If anything, the whole world is moving to this model > after NodeJS proved its usefulness. So what's unusual about that? I think you're using the term "green threading" too broadly. Golang uses green threads, but Rust does not. The difference is that in Rust with async/await, the task-switching boundaries are explicit (the .await syntax). So Rust uses explicit concurrency, not green threading. I can't speak to the other languages you mention. > > To clarify: I don't have a single in-flight operation at a time. The > same thread dispatches IO requests for different streams (sockets and > files). AIO is not only useful for batching operations (on the same > file). AIO is also useful for a batch of IO operations on different > files. File IO is always =E2=80=9Cready=E2=80=9D and the readiness model = doesn't work > for files. On Linux, I can just use io_uring (proactor/completion > model) for everything (as in it won't prevent me from skipping an > explicit offset). Same with Windows (IOCP). What is special about > FreeBSD here? > > POSIX AIO by itself is useless to me. It's only useful to me with BSD > extensions (SIGEV_KEVENT for kqueue integration). I don't see a reason > why it can't have another small extension that is pretty much > non-invasive. You propose an extension that would essentially create asynchronous (and racy) versions of read, write, readv, and writev . But what about copy_file_range and fspacectl? Or for that matter all the dozens of control-path syscalls like open, stat, chmod, and truncate? This flag that you propose is not a panacea that will eliminate all blocking file operations. There will still be a need for things that block. Rust (via the Tokio library) still uses a thread pool for such things. It even uses the thread pool for the equivalent of read() and write() (but not pread and pwrite). My point is that if you want fully asynchronous file I/O that never blocks you can't achieve that by adding one additional flag to POSIX AIO. That would be a involved project and it needs a serious design effort. Even then, I suspect that the best solution would be to completely eschew the seek pointer. Instead, all operations would either specify the offset (as with pwrite, pread) or operate only at EoF as if O_APPEND were used. -Alan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2iWzPvkzpdp4K5VVkWQicyidT2ibF=_==e_PLaRj6s6WQ>