- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Move inject queue to tokio::runtime::task
#3939
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks great to me, no comments. I asked @hawkw to take a look though as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me --- i commented on some very minor nits, but no blockers!
tokio/src/runtime/queue.rs
Outdated
fn make_fixed_size<T>(buffer: Box<[T]>) -> Box<[T; LOCAL_QUEUE_CAPACITY]> { | ||
assert_eq!(buffer.len(), LOCAL_QUEUE_CAPACITY); | ||
|
||
// SAFETY: We check that the length is correct. | ||
unsafe { Box::from_raw(Box::into_raw(buffer).cast()) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really necessary? is there a reason we can't just replace the Vec::new
with a boxed array literal? if we can't do that, it would be nice to have a comment explaining why, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the alternative:
Box::new([
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
UnsafeCell::new(MaybeUninit::new()),
])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, um. on second thought let's maybe not do that.
|
||
/// Linked-list tail | ||
tail: Option<NonNull<task::Header>>, | ||
buffer: Box<[UnsafeCell<MaybeUninit<task::Notified<T>>>; LOCAL_QUEUE_CAPACITY]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess the other question re https://github.com/tokio-rs/tokio/pull/3939/files#r667212885 is, does this even need to be boxed anymore, if it has a fixed size? should we save another layer of indirection by removing the Box
, or is there a reason for this to live in a separate allocation beyond sizedness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need to, no. If I am to come up with a reason, then some allocators probably dislike allocations that are slightly larger than 1024 bytes. I don't know what effect this has in practice. I am open to removing the box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess another reason is that long fixed size arrays are really awkward to construct for non-copy generic types.
runtime: move inject queue to `tokio::runtime::task` (tokio-rs#3939)
This PR moves the inject queue into the
tokio::runtime::task
module. This is an incremental change towards the goal of isolating the unsafety in the task module and providing a safe API totokio::runtime::task
.The main two changes in this PR are:
src/runtime/queue.rs
tosrc/runtime/task/inject.rs
.Inject::push_batch
to an iterator-based interface.The work-stealing local run queue will continue to have unsafe code despite being outside the task module, but its unsafety is going to be unrelated to the invariants of the
tokio::task
module.It may be easier to read this change one commit at the time. The first commit performs no changes to the code besides moving it around and running rustfmt.