Conversation
- Replace immediate initialization with LazyCell::new() for deferred allocation - Add rust-version = "1.80" requirement to Cargo.toml for LazyCell support - Improves performance by deferring expensive IoUring setup until first access Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Replace individual q.q_ring usage with a unified thread-local QUEUE_RING using OnceCell for lazy initialization. This change provides cleaner API access through helper macros and improves thread safety. Key changes: - Add thread-local QUEUE_RING with OnceCell<RefCell<IoUring>> - Create with_queue_ring() and with_queue_ring_mut() for easier external access - Replace all q.q_ring.borrow() and q.q_ring.borrow_mut() calls (20+ instances) - Update both src/io.rs and src/uring_async.rs - Add proper type annotations for compile-time safety - Initialize thread-local ring when queue is created Benefits: - Cleaner, more ergonomic API through helper macros - Thread-local access avoids cross-thread synchronization - Lazy initialization reduces memory overhead - Type-safe access with explicit annotations Three new APIs are added: - with_queue_ring() - with_queue_ring_mut() - init_task_ring() The 1st two are for manipulating the queue's ring, and the 3rd one can be used for customerizing the task ring. Per-task io_uring is the most common usage, so take this way for libublk. - helps to use task ring to handle multiple queues from different devices - helps to support async/.await control command because control ring actually depends on io ring if the two are in same task context - with control command async/.await ready, it will be pretty easier/simpler to run arbitrary queues & tasks & devices combination, one typical example is to create many devices in single process, and let one thread to handle queues with same index from different devices. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
0c73221 to
c2a582b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: replace q.q_ring with thread-local variable and introduce 3 APIs
feat: use LazyCell for thread-local CTRL_URING initialization