refactor(blk): offload virtqueue drain to worker thread#95
Open
agicy wants to merge 1 commit into
Open
Conversation
47fa734 to
10eebf0
Compare
10eebf0 to
f90ae43
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.
Summary
This PR refactors the virtio-blk worker threading model to eliminate the intermediate producer-consumer queue between the main thread and the I/O worker thread.
Before
blkp_reqstructs onto a cross-thread queue (procq).procq's mutex for every single I/O request.After
pthread_cond_signal— it never touches the virtqueue.Performance
Test setup: ramdisk backend, fio + io_uring, 120s runtime, RK3588.
Bug Fixes
While refactoring, several pre-existing issues were fixed:
pthread_joinsovirtio_blk_closedoesn't join an uninitialized thread handle if the worker was never started.written_lenon read error: Whenpreadvfails,written_lenno longer carries-1into the used-ring update (was reporting 0 bytes despite the status byte being written).written_lenforGET_ID: Now reports correct data length via the used ring so the guest sees the full device ID string.close(-1)on open failure: Removed spuriousclose(-1)in the error path whenopen()fails.fstatreturnsst_size = 0(real block devices), fall back toioctl(BLKGETSIZE64).