axboe / liburing

Library providing helpers for the Linux kernel io_uring support
MIT License
2.72k stars 393 forks source link

Question: Without SQPOLL, does `io_uring_submit` always submit all SQEs on success? #1071

Closed ZhenbangYou closed 5 months ago

ZhenbangYou commented 5 months ago

The return value of io_uring_submit is the number of successfully submitted SQEs on success. I wonder if this is always equal to the number of SQEs in SQ. Thanks!

axboe commented 5 months ago

Generally, yes. Earlier kernels would abort submission on error, you can setup your ring with IORING_SETUP_SUBMIT_ALL to turn that off on more recent kernels. If that is set, and some request has an error while being submitted, a CQE is posted. Without that setup flag, or on early kernels, io_uring would stop submitting when that happened. This condition can cause io_uring_submit() to return less than what was available to submit, with the remainder still in the queue.

Outside of that, yes it always flushes everything and hence the return value of io_uring_submit() will be identical to the number of requests that were prepared since the last submission.

ZhenbangYou commented 5 months ago

Thanks Jens! These are very helpful!

ZhenbangYou commented 5 months ago

@axboe I have a follow-up question: if some request has an error while being submitted, will io_uring_submit return -errno or the number of successfully submitted SQEs? If it returns the latter, how can I know what error occured (e.g., will that error be shown in a CQE)?

axboe commented 5 months ago

It returns the number of successfully submitted SQEs. For example, if you have 8 queued and number 4 has an error, then it'll return 4 and there will be a CQE posted for the 4th one telling you what error it was. As mentioned earlier, this is how it should just work. Just set IORING_SETUP_SUBMIT_ALL and this is how any submission will work.

ZhenbangYou commented 5 months ago

I see! Thank you so much! Love this clear answer.

ZhenbangYou commented 5 months ago

It's sad that the latest WSL only support Linux 5.15, but IORING_SETUP_SUBMIT_ALL requires 5.18.

axboe commented 5 months ago

People running ancient kernels is the bane of my existence.

ZhenbangYou commented 5 months ago

Haha. I found 6.1 in WSL's repo. Let me try to grab it. Being unable to use useful new features is really annoying.

axboe commented 5 months ago

Just to be clear, this wasn't a jab at you, just systems/distro using ancient stuff to begin with.