Skip to content

Comments

Batch#39

Merged
ming1 merged 8 commits intomainfrom
batch
Oct 7, 2025
Merged

Batch#39
ming1 merged 8 commits intomainfrom
batch

Conversation

@ming1
Copy link
Collaborator

@ming1 ming1 commented Sep 30, 2025

  • export two APIs: uring_poll_io_fn()/ublk_submit_sqe_async(), just make life easier

  • add batch example for showing how to deal with IO batch, which could be used for raid1 to build resync bitmap or journal data

Export uring_poll_io_fn() for targets which need to customer either
poll_fn or read_event() handler.

The coming batch example will use it.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
This commit introduces new async APIs and testing infrastructure:

- Add ublk_submit_sqe_async() for async io_uring SQE submission
- Add __ublk_submit_sqe_async() as internal implementation
- Add ublk_join_io_tasks() test helper for QUEUE_RING polling
- Export init_task_ring_default as pub(crate) for testing
- Add comprehensive tests covering NOP, timeout, concurrent operations, and error handling
- Refactor UblkQueue::ublk_submit_sqe() to use new async infrastructure

The new API enables proper async/await integration for custom io_uring operations
while maintaining compatibility with existing synchronous interfaces.

UblkQueue::ublk_submit_sqe() will be deprecated soon.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
This example demonstrates batch coordination among async tasks within
ublk's smol::LocalExecutor framework. The motivation is to prepare
infrastructure for RAID1 implementation where all writes in a batch
need to:

1. Mark 'need_resync' before any actual writes begin
2. Flush all resync markers to disk
3. Only then proceed with data writes to member disks
4. Clear resync markers after all writes complete

Key features:
- Thread-local context ID communication between run_ops and tasks
- Slab-based BatchCoordinator for efficient resource management
- Two-phase async coordination using smol channels
- Reference counting for automatic cleanup
- Per-queue batch state with comprehensive logging
- Always runs in async mode (no sync mode support)
- Zero overhead when batch coordination is not needed

The approach leverages the existing batching boundary (CQE processing
in ublk_reap_io_events_with_update_queue) and provides clean async
coordination without blocking the executor.

This provides a foundation for RAID1 and other use cases requiring
batch-level synchronization among async tasks in the ublk framework.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Add zero copy feature to examples/batch.rs following the pattern from
examples/null.rs. This enables efficient I/O operations by using
automatic buffer registration via UBLK_F_AUTO_BUF_REG.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Remove batch_id field from BatchCoordinator struct and all related
logging statements. The batch_id was only used for logging purposes
and provided no functional value to the batch coordination logic.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Replace AtomicU32 with Cell<u32> for registered_tasks and completed_tasks
fields in BatchCoordinator since all operations happen in single-threaded
context. This provides better performance and simpler code without atomic
operations overhead.

Changes:
- Replace AtomicU32::new() with Cell::new()
- Replace fetch_add() with get()/set() pattern
- Replace load() with get()
- Remove unused atomic imports

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
…ce bottleneck

Major optimizations implemented:

- **Eliminated phase1_semaphore**: Removed semaphore.acquire().await blocking
- **Real-time write detection**: Direct I/O operation checking in reap_event()
- **Zero-copy tag collection**: Extract tags from CQE user_data without allocation
- **Simplified coordinator lifecycle**: Direct tag transfer from pending to coordinator

- **BatchCoordinator**: Removed completed_tasks counter, stores write tags directly
- **QueueBatchState**: Added pending_write_tags collection from reap_event
- **Task coordination**: Check current IOD operation type instead of cached tags
- **Reusable functions**: is_write_operation() and collect_write_tags_from_cqe()

- Export uring_poll_io_fn() for proper default handler polling
- Both handle_uring_events_default() and handle_uring_events_smol_readable()
  use same write tag collection logic
- Direct tag-based coordination eliminates race conditions
- Only write operations participate in batch coordination

- No semaphore blocking: Tasks proceed immediately without phase1 wait
- Lock-free detection: Atomic operations and RefCell for coordination state
- Precise batching: Only actual write commands trigger coordination overhead
- Scalable design: Performance scales with write volume, not total I/O

Maintains exact RAID1 coordination semantics while providing significant
performance improvements, especially under high I/O loads.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Changes:
- Cargo.toml: Added rand = "0.8" dependency for random delay generation
- examples/batch.rs:
  - Added --io-delay command line option to specify maximum random I/O delay in microseconds
  - Implemented simulate_io_with_delay() function using io_uring timeout operations
  - Integrated delay simulation into the batch I/O task execution path
  - Updated function signatures to pass io_delay_us parameter through the call chain
  - Added random delay logic before I/O operations to simulate realistic workloads

Purpose: Enables testing and benchmarking with simulated I/O delays to
better cover coordinate batch function.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
@ming1 ming1 merged commit 0cd0af8 into main Oct 7, 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