Skip to content

fs: avoid lock acquisition after uring init#7843

Merged
ADD-SP merged 3 commits intotokio-rs:masterfrom
tahmid-23:uring-lock-removal
Jan 9, 2026
Merged

fs: avoid lock acquisition after uring init#7843
ADD-SP merged 3 commits intotokio-rs:masterfrom
tahmid-23:uring-lock-removal

Conversation

@tahmid-23
Copy link
Copy Markdown
Contributor

@tahmid-23 tahmid-23 commented Jan 8, 2026

Motivation

#7815 added a lock acquisition after the uring had been initialized. This negates the point of the atomic state variable. However, we need to mutably initialize the Probe once. This sounds exactly like a use case for OnceCell / OnceLock.

Instead of an atomic indicating the uring state, we use a OnceCell<Option<Probe>> to indicate the uring state: None indicating it being unsupported, and the Probe indicating successful initialization. (This Probe could later be replaced with any other necessary readonly uring state, but this is currently the only necessary type.)

Although we would like to use std's OnceLock, its get_or_try_init method is currently unstable. We cannot implement it ourselves (as previously present), since OnceState::poison is not public and is necessary to implement get_or_try_init. Hence, I added once_cell as a dependency under the io_uring feature. The 1.65 MSRV should be compatible anyway.

@tahmid-23 tahmid-23 closed this Jan 8, 2026
@tahmid-23 tahmid-23 reopened this Jan 8, 2026
@tahmid-23 tahmid-23 marked this pull request as draft January 8, 2026 22:16
@tahmid-23 tahmid-23 marked this pull request as ready for review January 8, 2026 22:44
@ADD-SP ADD-SP added A-tokio Area: The main tokio crate T-io-uring Topic: Linux io_uring M-runtime Module: tokio/runtime labels Jan 8, 2026
@ADD-SP ADD-SP added the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Jan 8, 2026
@tahmid-23 tahmid-23 requested a review from ADD-SP January 8, 2026 23:02
Copy link
Copy Markdown
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

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

Thanks!

@ADD-SP ADD-SP removed the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Jan 8, 2026
@ADD-SP ADD-SP merged commit ff9681b into tokio-rs:master Jan 9, 2026
89 checks passed
Darksonn added a commit that referenced this pull request Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tokio Area: The main tokio crate M-runtime Module: tokio/runtime T-io-uring Topic: Linux io_uring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants