-
Notifications
You must be signed in to change notification settings - Fork 521
How to reuse io_uring_buf_ring after a failed/incomplete send #1441
-
TLDR:
Question: What is the status of io_uring_buf_ring's head in case io_uring_prep_send_bundle fails? Can I assume that head will be set to 0 in case of error?
Full read:
I am using ring with the following flags IORING_SETUP_SINGLE_ISSUER | IORING_SETUP_DEFER_TASKRUN , a ring will only be used by a single thread.
Use-case:
- Maintain a pre-initialized pool of
io_uring_buf_ringbuffer-rings. I use buf_ring to "serialize"senddata. - When a socket wants to send something, I
Geta buffer-ring from the above pool - Add data(i.e buffers) in the buffer-ring. Buffers are always added to tail, while kernel code updates the head.
- Then do the work i.e
io_uring_prep_send_bundle,io_uring_submitetc. - On successful send I can
Putthe buffer-ring back to the pool for reuse with a differentsend. Because I know thathead == tail? - But what happens if the
sendwas only partial/fails? e.g I wanted to send 4MB data, but after sending 2 MB, the peer sent RST.
In this case if I try to reuse the buffer-ring for some other send i.e add buffers to it(which would always be added at tail), it might send some additional garbage(because when I added these buffers, head != tail).
Questions:
- Is this understanding correct? Feel free to correct me if my understanding about usage is incorrect.
- Technically I can do the following on
sendfailure- tail =
io_uring_buf_ring_head - Put buf-ring back to the pool
- tail =
But that is a system call, is this the best we can do?
Can't the kernel code set head = 0 on failure(I don't know if it already does that or not)? And so we can call io_uring_buf_ring_init(which just sets tail to 0) and we're done?
Reference:
1431 and I don't think the following reply by Jens holds good for my use-case?
If whatever send(s) you have using the ring are not active, then you can manipulate the ring entries as you see fit.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
Please let me know if my usage is incorrect or not natural/idiomatic.
Beta Was this translation helpful? Give feedback.
All reactions
-
FWIW it seems to me that buffer rings are more useful for multishot read/recv than for send. I did some benchmarks and vectorized send seems to have equivalent performance to send_bundle. It is of course much simpler to set up.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1