Skip to content

Comments

Misc refactor optimization#36

Merged
ming1 merged 10 commits intomainfrom
misc-refactor-optimization
Sep 21, 2025
Merged

Misc refactor optimization#36
ming1 merged 10 commits intomainfrom
misc-refactor-optimization

Conversation

@ming1
Copy link
Collaborator

@ming1 ming1 commented Sep 21, 2025

  • deprecate uring_op(), uring_op_mut() and get_inflight_nr_io()
  • support UblkFlags::UBLK_DEV_F_NO_IO_STAT
  • optimize: cache dev.dev_info.flags in UblkQueue for performance
  • simplify wait_and_handle_io using flush_and_wake_io_tasks

ming1 and others added 10 commits September 21, 2025 02:53
Align with `cargo fmt`, otherwise it often causes big unnecessary diff.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
- Change flush_and_wake_io_tasks closure type from Fn to FnMut for flexibility
- Implement wait_and_handle_io using flush_and_wake_io_tasks with mutable closure variable to track first CQE
- Remove process_ios and reap_one_event functions (no longer needed)
- Remove individual state update logic from handle_cqe (batch updates are handled by flush_and_wake_io_tasks)
- Remove unused dec_cmd_inflight and update_state methods

This simplifies the code by eliminating duplicate state management and improving code reuse while maintaining backward compatibility.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Split __queue_io_cmd into __queue_io_cmd_no_state and __queue_io_cmd to
improve code organization and reduce state access in the core I/O command
queueing logic.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Target code can more easily track inflight IOs themselves rather than
relying on this library function.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Simplify device_handler_async() implementation by accepting UblkFlags
directly instead of a boolean mlock_fail parameter. This eliminates
conditional flag construction logic and makes the interface cleaner.

Changes:
- Change function signature from device_handler_async(mlock_fail: bool)
  to device_handler_async(dev_flags: UblkFlags)
- Remove conditional flag construction in UblkCtrlBuilder
- Update mlock failure check to use dev_flags.contains()
- Update all callers to pass appropriate UblkFlags combinations

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Create a shared test_helpers module to eliminate code duplication of
async test functions across different test modules. This enables
better code reuse and consistency in async device testing.

Changes:
- Add src/test_helpers.rs with shared async test utilities:
  * io_async_fn() - async I/O function for null device testing
  * q_async_fn() - queue async function for spawning I/O tasks
  * device_handler_async() - complete async device handler
  * ublk_join_tasks() - utility for managing task execution
- Update lib.rs to include test_helpers module with cfg(test)
- Refactor ctrl_async.rs to use shared functions instead of local copies
- Add example usage in io.rs demonstrating cross-module sharing
- All existing tests continue to work unchanged

Benefits:
- Eliminates duplication of complex async test logic
- Provides consistent test patterns across modules
- Enables easy addition of new shared test utilities
- Improves maintainability with single source of truth

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add UblkQueue::need_update_state() helper method to determine when queue
state updates are required. Only update state when UBLK_DEV_F_MLOCK_IO_BUFFER
is set or when zero copy/user copy modes are enabled.

Changes:
- Add always-inline need_update_state() helper method
- Conditionally call inc_cmd_inflight() in __queue_io_cmd()
- Conditionally call mark_stopping() in update_state_batch()

This optimization reduces mutex contention and improves performance
in scenarios where queue state tracking is not necessary.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Cache dev.dev_info.flags as UblkQueue::dev_flags (u64) and use cached value
in UblkQueue methods instead of repeatedly accessing dev.dev_info.flags.

Changes:
- Add dev_flags: u64 field to UblkQueue struct
- Initialize dev_flags in UblkQueue::new()
- Replace self.dev.dev_info.flags with self.dev_flags in queue methods
- Improves performance by eliminating repeated pointer dereferencing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ming1 ming1 merged commit efe6d9b into main Sep 21, 2025
8 checks passed
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.

1 participant