Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async I/O (syscalls 245 - 249) #1584

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

Conversation

kmeisthax
Copy link
Contributor

@kmeisthax kmeisthax commented Oct 10, 2021

Linux has an async I/O facility (separate from epoll) that allows sending a small handful of file operations (notably, positioned and/or vectored reads and writes, syncs, and possibly also poll) on an already-open FD into an in-kernel context, and then retrieving all of their results at a later time. It's almost like an early prototype of modern Linux's io_uring, but using syscalls instead of ring buffers.

  • Host-side memory structures for AIO contexts and task tables
  • io_setup impl
  • io_destroy impl
  • io_submit impl
    • FD method for IO submit
    • Fallback io_submit impl
      • IOCB_CMD_PREAD
      • IOCB_CMD_PWRITE
      • IOCB_CMD_FSYNC
      • IOCB_CMD_FDSYNC
      • IOCB_CMD_POLL I don't think this will be possible
      • IOCB_CMD_NOOP
      • IOCB_CMD_PREADV
      • IOCB_CMD_PWRITEV
    • Non-blocking fallback, leveraging O_NONBLOCK and poll/epoll where available Neither will this.
  • io_getevents impl
    • Basic impl
    • min_nr and timeout support
  • io_cancel impl I actually can't figure out how this is supposed to work
  • e2e tests
    • Figure out why the tests expect evt.obj to be sign-extended

@kmeisthax kmeisthax force-pushed the linux_aio branch 8 times, most recently from e401e67 to 97b7657 Compare October 25, 2021 02:45
…an access allocated memory in the guest.

This also slightly changes the AIO context ownership model: while it is still refcounted and retained by any pending requests, any context that does not have a valid task cannot resolve those requests. We flag such orphaned contexts, but allow the context to live until all pending requests have gotten the message and released the context.
I'm assuming `EAGAIN` is the correct error code for running out of events in a context.
This necessitates externally-controlled lock lifetimes, since we need to return pointers into context-owned shared data. This comes with the usual warnings about memory safety.
We don't have a way to actually tell an FD to run an async I/O operation yet, so that's still TODO'd.
@kmeisthax kmeisthax marked this pull request as ready for review November 14, 2021 22:26
@kmeisthax kmeisthax changed the title [DRAFT] Async I/O (syscalls 245 - 249) Async I/O (syscalls 245 - 249) Nov 14, 2021
@kmeisthax kmeisthax force-pushed the linux_aio branch 2 times, most recently from f612141 to 60e6c82 Compare November 14, 2021 22:46
@kmeisthax
Copy link
Contributor Author

I've managed to get this to build again. I'm going to release the draft flag on this PR. It should be sufficient enough to run software that needs async I/O, albeit not with the speed benefits. A good idea for a future PR would be hooking this system up to POSIX AIO (or whatever else iOS supports) to do proper parallel IO on the host filesystem.

I wasn't able to write tests for io_cancel; and all the software I want to run on iSH doesn't use it. If anyone has a compelling use case for I/O cancellation let me know; otherwise I'm going to leave it as ENOSYS.

Copy link
Member

@tbodt tbodt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Did a quick review now, soon I hope to find the time to learn a bit about how AIO works so I can do a real review.

PS: please fix the tests :)

kernel/aio.c Outdated Show resolved Hide resolved
kernel/task.h Outdated Show resolved Hide resolved
fs/aio.c Outdated Show resolved Hide resolved
fs/aio.c Outdated Show resolved Hide resolved
@kmeisthax kmeisthax force-pushed the linux_aio branch 2 times, most recently from cd06108 to 15f09b2 Compare November 21, 2021 19:42
@kmeisthax kmeisthax force-pushed the linux_aio branch 2 times, most recently from 89bf3b1 to db0c0aa Compare November 21, 2021 20:59
@kmeisthax kmeisthax force-pushed the linux_aio branch 4 times, most recently from eafda59 to 709b16e Compare November 21, 2021 21:41
@kmeisthax kmeisthax force-pushed the linux_aio branch 2 times, most recently from 13f779d to 6c09ad5 Compare November 21, 2021 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants