Page MenuHomeFreeBSD

bhyve/virtio-scsi: Preallocate all I/O requests
Needs ReviewPublic

Authored by rosenfeld_grumpf.hope-2000.org on Oct 30 2025, 7:38 AM.
Tags
None
Referenced Files
F145485227: D53469.id165411.diff
Fri, Feb 20, 10:35 AM
F145441262: D53469.id167542.diff
Thu, Feb 19, 11:00 PM
Unknown Object (File)
Thu, Feb 19, 6:14 AM
Unknown Object (File)
Thu, Feb 19, 6:13 AM
Unknown Object (File)
Sun, Feb 15, 8:37 PM
Unknown Object (File)
Sun, Feb 15, 5:22 PM
Unknown Object (File)
Jan 13 2026, 1:20 AM
Unknown Object (File)
Jan 12 2026, 2:30 PM

Details

Reviewers
jhb
corvink
markj
Group Reviewers
bhyve
Summary

By preallocating all I/O requests on all queues, we can take most
allocations out of the hot I/O code paths and simplify the code
significantly. While here, make sure we check all allocations for
success and make sure to handle failures gracefully.

Additionally, check for I/O request validity as early as possible,
and return illegal requests immediately.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 68264
Build 65147: arc lint + arc unit

Event Timeline

rosenfeld_grumpf.hope-2000.org retitled this revision from bhyve/virtio-scsi: preallocate all I/O requests to bhyve/virtio-scsi: Preallocate all I/O requests.Mon, Feb 9, 4:26 PM

Sync with latest illumos bits after code review.

Use a size_t type where appropriate instead of the abomination that is uint.

This broadly looks ok, I have a few inline comments.

usr.sbin/bhyve/pci_virtio_scsi.c
111

Some comment explaining how these three mutexes are used would be appreciated.

573

Is the vsr_queue field used for anything?

670

Is it really necessary to clear the whole request structure like this?

841

There's no cleanup of the threads in this error path. If you allocate all of the worker structures at once, before the loop, then you don't need to think about cleaning up in this error path (aside from the requests allocated in the loop above, which are easy to deal with).

This revision is now accepted and ready to land.Mon, Feb 16, 9:41 PM
This revision now requires review to proceed.Thu, Feb 19, 6:36 PM
usr.sbin/bhyve/pci_virtio_scsi.c
573

Looks like it isn't used anywhere by the code, but I found it useful during debugging, especially with multiple I/O queue support.

670

I don't know whether it's strictly necessary, but I feel much better knowing there's no stale data left in there before we reuse it, especially not in any of the iovecs.