Closed tiif closed 1 month ago
@rustbot author
The overall implementation is done. I will add more documentation and update the design docs in the next few days, and there are stuff that can be done to improve the code, but I appreciate an earlier feedback that potentially involves major changes.
@rustbot ready
@rustbot author
:umbrella: The latest upstream changes (presumably #3743) made this pull request unmergeable. Please resolve the merge conflicts.
The PR has been squashed because there is a merge conflict in master and rebase through the 100+ commits is too painful.
The current commit structure is:
I will resolve other comments after refactoring as it might not be applicable after the new changes.
@oli-obk The latest commit contains the changes to add a global epoll events map and eliminate epoll_events
field. ~It is worth mentioning that currently we still need to add an id
field inside the file description because update_readiness
needs to know the identity of file description so it can update the correct set of Vec<EpollEvent>
.~
Edit: We no longer need to manually add an id field to any file description struct.
Let's move that file description commit to its own PR. Even if we don't use the ids yet (so you can just leave out the id field in fdtable and in the wrapper struct), the change seems good on its own
Sure. I am currently trying to find a way to duplicate the change to a new PR. Since the global epoll event map (specifically this commit ) needs the file description id, I don't think it could be entirely removed from this PR.
Since the global epoll event map (specifically this commit ) needs the file description id, I don't think it could be entirely removed from this PR.
yea, epoll and id changes can be kept here. Just remove everything that doesn't make sense in isolation from the other PR and keep just the basic refactoring
my recommendation for doing this is to take this entire PR, duplicate it, git reset --soft HEAD~1
away all the commits and then look at it in your diff viewer and revert all changes that are epoll specific
my recommendation for doing this is to take this entire PR, duplicate it, git reset --soft HEAD~1 away all the commits and then look at it in your diff viewer and revert all changes that are epoll specific
Yup it works wonder! The isolated PR is currently in #3763 .
:umbrella: The latest upstream changes (presumably #3766) made this pull request unmergeable. Please resolve the merge conflicts.
I have renamed FileDescriptor
to FileDescriptionRef
here, but there are still a lot of variables that still being named as file_descriptor
. I will open an issue for this refactor after this landed.
you have some clippy or rustfmt changes to address
:umbrella: The latest upstream changes (presumably #3770) made this pull request unmergeable. Please resolve the merge conflicts.
:umbrella: The latest upstream changes (presumably #3778) made this pull request unmergeable. Please resolve the merge conflicts.
The majority of the change discussed is completed, but I will do a few more passes to catch some minor errors. So to reflect the current status,
@rustbot ready
Weird... ./miri clippy -- -D warnings
works fine locally but failed on CI?
Maybe you need to rebase
https://github.com/rust-lang/miri/pull/3712/commits/80d407e80996284a6bc7fda4c4bf8cb729c49412 is an attempt to pass in FileDescriptionRef
to check_and_update_readiness
, but it ICEs for eventfd test. I haven't fully understood why it happens, but my current guess is it forms a kind of circular reference because we are doing this:
FileDescription::read
calls check_and_update_readiness
check_and_update_readiness
, we borrow_mut
the file description again. I am not sure if it is possible to make it work, but I am going to revert this an try to pass FdId
to read/write
first.
All the comments were addressed, this is ready for another round of review. ^^
https://github.com/rust-lang/miri/pull/3712/commits/4812fa670538bf5c0e53fd7bb0b72e02e424b2ec ensures that notification will be provided if read
emptied the buffer.
Related discussion is in https://rust-lang.zulipchat.com/#narrow/stream/269128-miri/topic/epoll.20notification.20on.20socketpair.20write.20unblock
Do we really want to emulate this behavior? I think epoll totally permits us to wake up these threads even when there is just one byte of space available for writing.
If we do, I think we shouldn't use "empty" as the threshold. More like, if at least 1KiB can be written, or at least half the buffer can be written, or something like that. I wonder what threshold the real implementation uses, but I doubt it is "empty" since that risks starving the readers -- the goal here is presumably to keep a good balance between readers and writers, so "half the buffer" seems like the most naive option to me. This should come with a comment indicating that we do this to avoid waking up threads when they could only write a few bytes.
Do we really want to emulate this behavior? I think epoll totally permits us to wake up these threads even when there is just one byte of space available for writing.
I actually prefer to not emulate this behavior and instead provide epoll notification every time read
is called, because as long as socketpair
reads more than 0 bytes, it will became writable. For this particular behavior, no matter how we approach it, there will always be cases where our emulation differs from the real system, so we might as well just choose one that makes sense. In my opinion, spuriously waking up threads is better than letting the thread blocks due to lack of notification. But I am not sure if I have missed something—let me know if anyone thinks otherwise.
I am completely fine with waking threads up immediately when there's just one byte writeable, even if the real implementation behaves differently for optimization reasons. There should be a comment in the code explaining that.
Not sure if @oli-obk has a preference either way.
I too prefer just notifying whenever anything becomes writable/readable, irrespective of the size.
Okay updated, thanks for helping figure this out!
:pushpin: Commit 5702761073f602033654be6d353215457d645d96 has been approved by oli-obk
It is now in the queue for this repository.
:hourglass: Testing commit 5702761073f602033654be6d353215457d645d96 with merge cd5d255937739cc1bff06ca88b016d9c8b33cd85...
:sunny: Test successful - checks-actions Approved by: oli-obk Pushing cd5d255937739cc1bff06ca88b016d9c8b33cd85 to master...
This PR:
epoll
for #3448 . The design for this PR is documented in https://hackmd.io/@tiif/SJatftrH0 .