Skip to content

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Nov 10, 2025

Previously, the individual FDs were expected to only call epoll_send_fd_ready_events when something changed. However, they couldn't actually know which changes are relevant to the epoll interests, so instead move the change detection into the epoll core. To ensure we behave consistently with Linux, some events need to force a notification even if there was no change.

Also, fix a bug where when an event got un-available, we'd still keep it in the ready list. (Without the above, that would cause tons of existing tests to fail.) And fix EPOLL_CTL_MOD to make it update the data of events already in the ready list.

Fixes #4374.

@rustbot
Copy link
Collaborator

rustbot commented Nov 10, 2025

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Nov 10, 2025
ecx.epoll_send_fd_ready_events(eventfd)?;
// Linux seems to cause spurious wakeups here, and Tokio seems to rely on that
// (see <https://github.com/rust-lang/miri/issues/4374#issuecomment-3508873493>).
ecx.epoll_send_fd_ready_events(eventfd, /* force_edge */ true)?;
Copy link
Member Author

@RalfJung RalfJung Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Darksonn this is the suspicious part... if I make this false, the Tokio test deadlocks....


// This does not change the status, so we should get no event.
// However, Linux performs a spurious wakeup.
check_epoll_wait::<8>(epfd, &[(expected_event, expected_value)]);
Copy link
Member Author

@RalfJung RalfJung Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... Setting force_edge to false makes it so that we get the empty event list here. Which is what I would expect since the readiness did not change. However, Linux does seem to always emit an epoll event on eventfd writes, even if readiness does not change -- and it looks like Tokio relies on that? At least that is the only explanation I have for the deadlocks I have been seeing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it looks like Tokio does rely on that. Mio has no logic to consume the notification except when the 64-bit counter overflows. I guess this avoids a read syscall, so it makes some sort of sense. See eventfd.rs for details.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks for confirming!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun, Mio also references https://www.illumos.org/issues/16700 -- looks like Illumos was also requested to be bug-for-bug compatible with Linux here.

I wouldn't mind this so much if it was documented, but epoll overall has pretty bad documentation I have to say. :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:D

Copy link
Member Author

@RalfJung RalfJung Nov 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Darksonn FWIW it seems like Linux triggers a wakeup even if you write [0u8; 8] to the eventfd. That way you'd never even have to worry about overflow.

@RalfJung RalfJung force-pushed the epoll-edge branch 2 times, most recently from b66ef3a to 4c670e2 Compare November 10, 2025 11:13
@RalfJung RalfJung enabled auto-merge November 10, 2025 13:26
@RalfJung RalfJung added this pull request to the merge queue Nov 10, 2025
Merged via the queue into rust-lang:master with commit 751fca0 Nov 10, 2025
13 checks passed
@RalfJung RalfJung deleted the epoll-edge branch November 10, 2025 14:25
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label Nov 10, 2025
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.

Miri spurious wake up in epoll?

3 participants