axboe / liburing

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

Question about io_uring_for_each_cqe #867

Closed MBkkt closed 1 year ago

MBkkt commented 1 year ago

Could you explain why do you do load on every iteration?

https://github.com/axboe/liburing/blob/master/src/include/liburing.h#L295

axboe commented 1 year ago

Reloading it should not be necessary.

MBkkt commented 1 year ago

@axboe

But behavior with single load and load on every iteration could be different? Because kernel can produce new cqe while it is iterating. Or I don't understand it right?

axboe commented 1 year ago

That is obviously true, but I would suspect most loops to process CQEs are pretty light (and hence fast) and therefore the likelihood of getting a new entry while looping is pretty small. So while it doesn't hurt to reload the cq tail on every loop, it'd probably be better to avoid it.

MBkkt commented 1 year ago

Thanks.

MBkkt commented 3 weeks ago

This commit fix this inefficiency https://github.com/axboe/liburing/commit/c16017c714b4400feba079c7681baf5186c9c8dc