1

From https://kernel.dk/io_uring.pdf, I noticed submission queue of io_uring requires another indirection of indexing. And the explaination is quite blurry for me.

One important difference is that while the CQ ring is directly indexing the shared array of cqes, the submission side has an indirection array between them. Hence the submission side ring buffer is an index into this array, which in turn contains the index into the sqes. This might initially seem odd and confusing, but there's some reasoning behind it. Some applications may embed request units inside internal data structures, and this allows them the flexibility to do so while retaining the ability to submit multiple sqes in one operation.

And here are the code sample for submission queue

struct io_uring_sqe *sqe;
unsigned tail, index;
tail = sqring→tail;
index = tail & (*sqring→ring_mask);
sqe = &sqring→sqes[index];
/* this call fills in the sqe entries for this IO */
init_io(sqe);
/* fill the sqe index into the SQ ring array */
sqring→array[index] = index; // the completion queue wont need this extra indexing
tail++;
write_barrier();
sqring→tail = tail;
write_barrier();

1 Answers1

1

Please refer to Linux source code: https://github.com/torvalds/linux/blob/f6eb0fed6a3957c0b93e3a00c1ffaad84d4ffc31/include/linux/io_uring_types.h#L220-L222

     * This indirection could e.g. be used to assign fixed
     * io_uring_sqe entries to operations and only submit them to
     * the queue when needed.

So, basically it allows you to reserve an entry in submission queue, and reuse it. Furthermore, It also allows you to decouple the allocation of space for the submission queue entry and the actual submission of the entry.

Dave Butler
  • 1,646
  • 1
  • 12
  • 18