Skip to content

unsafe impl Send+Sync for Submitter, SubmissionQueue, CompletionQueue #283

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

problame
Copy link

The IoUring type already has Send + Sync impls.

In tokio-epoll-uring, we use split() and need the Submitter, SubmissionQueue and CompletionQueue to be Send (not sync, though).

This PR adds those unsafe impls, and adds hopefully not too repetitive commentary on why these impls are safe.


Co-authored-by: Conrad Ludgate [email protected]
Cherry picked from commit neondatabase@bbc5a0c

…onQueue`

The `IoUring` type already has `Send` + `Sync` impls.

In [tokio-epoll-uring](https://github.com/neondatabase/tokio-epoll-uring),
we use `split()` and need the `Submitter`, `SubmissionQueue` and
`CompletionQueue` to be `Send` (not sync, though).

This PR adds those `unsafe impl`s, and adds hopefully not too repetitive
commentary on why these impls are safe.

---------

Co-authored-by: Conrad Ludgate <[email protected]>
Cherry picked from commit neondatabase/fork--tokio-rs--io-uring#bbc5a0c5f6cde9051037ec2fcc648cbadb7a80b4
@quininer
Copy link
Member

quininer commented Apr 30, 2024

You seem to have to use unsafe to get &'static mut or use scope thread to make sense. I would recommend submission_shared and completion_shared.

see https://github.com/tokio-rs/io-uring/pull/100/files#diff-3a884378bde161d43e3099c530c5090847e826cb4501d4f7a803144e6bde14d3

@problame
Copy link
Author

problame commented May 3, 2024

Sorry, I'm not following. Who's talking about &'static mut ?

I would recommend submission_shared and completion_shared.

The unsafe impls proposed in this PR allow movement of Submitter, SubmissionQueue, and CompletionQueue, to different threads in consuming code, without any unsafe.

I consider that strictly better than the unsafe fn submission_shared() and unsafe fn completion_shared().

@Nehliin
Copy link

Nehliin commented Nov 9, 2024

This would be useful in my project as well

@DXist
Copy link

DXist commented Apr 30, 2025

I think there is no one size fits all approach. Maybe a solution could be to enable Send via feature.

I'm personally biased towards the ring-per-thread setup recommended by the io_uring author. With non Send IoUring and Submitter interfaces it's possible to provide push_shared method since only one thread is allowed to enqueue io.

I prefer to queue all io operations and submit then in batches. During submission I might do random lookups in large in memory indices and expect frequent cache misses.

To hide cache miss latencies I could issue software prefetch instructions, do yield and interleave application logic using several coroutines.

Each coroutine could accept shared reference to IO driver that holds IoUring instance on Linux platforms. To allow each coroutine to submit new io operations there should be a push-like method that takes shared reference to thread-exclusive Submitter instance.

So for this scenario it's useful to have non-Send IoUring and push functionality via shared reference to a single non-Send Submitter.

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

Successfully merging this pull request may close these issues.

4 participants