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

io_uring_for_each_cqe can overflow the cqe ring with SQPOLL #1139

Open
MarkReedZ opened this issue Apr 23, 2024 · 2 comments
Open

io_uring_for_each_cqe can overflow the cqe ring with SQPOLL #1139

MarkReedZ opened this issue Apr 23, 2024 · 2 comments

Comments

@MarkReedZ
Copy link

A server using for_each_cqe with SQPOLL set will overflow the cqe ring given enough connections / time such that we keep getting new CQEs added onto the end before we complete the loop.

As peek/wait is significantly slower than this loop does anyone have a better method of cq polling in this case? Queue'ing the events and doing a second loop is a 5% slowdown.

    io_uring_for_each_cqe(&uring, head, cqe) {
        handle_read()
        write_response()
    }
    io_uring_cq_advance(&uring, n);

This is the for_each macro. Perhaps saving the tail prior to the loop would be okay?

  for (head = *(ring)->cq.khead;          \
       (cqe = (head != io_uring_smp_load_acquire((ring)->cq.ktail) ? \
    &(ring)->cq.cqes[io_uring_cqe_index(ring, head, (ring)->cq.ring_mask)] : NULL)); \
       head++)  
@MarkReedZ
Copy link
Author

I went with breaking out of the loop after N iterations.

@axboe
Copy link
Owner

axboe commented Apr 24, 2024

I really liked your idea of using a tail assigned at the start of the loop though, I think that's a nice general thing to do and it would solve your issue as well.

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

No branches or pull requests

2 participants