c++linuxasynchronousio-uring

How does io_uring fulfill asynchronus read/writes?


Recently, I have been trying to incorporate async read/write into an existing feature and came around io_uring. There are a fairly good number of resources available on the internet over liburing and io_uring. But, after reading many of them and being a newbie to kernel handling it is still not clear to me, on which core does kernel run and fulfill sqe requests.

My doubt is let's say my main program is running on the isolated core 0 on my two core machine, once I have added an entry to the sqe ring from this program, then which of the following happens:

  1. Kernel code will run on core 1 parallely
  2. A context switch will happen on core 0 later and then kernel code is executed then.

Solution

  • Adding this so that others don't have to go through two sleepless nights of searching all over the internet.

    Essentially, io_uring spawns a new thread with name iou-wrk-<pid_of_parent> and offloads the task of writing/reading to it. By default the affinity of this thread is same as that of parent process, which works well generally, but can be harmful for use cases where main process must not do a context switch. When this is the case then point 2 from questions is followed. To avoid this and get the behavior as defined in 1 of question, we can set affinity of the worker thread, to a specific core using io_uring_register_iowq_aff() function exposed in liburing or can directly use the io_uring syscalls.

    Relevant links :

    https://man7.org/linux/man-pages/man3/io_uring_register_iowq_aff.3.html

    https://github.com/axboe/liburing/issues/353