Skip to content

Force virtiofs devices to a single virtio queue (vcpus=1)#40758

Open
asherkariv wants to merge 1 commit into
masterfrom
user/askariv/virtiofs_with_vcpus
Open

Force virtiofs devices to a single virtio queue (vcpus=1)#40758
asherkariv wants to merge 1 commit into
masterfrom
user/askariv/virtiofs_with_vcpus

Conversation

@asherkariv

@asherkariv asherkariv commented Jun 9, 2026

Copy link
Copy Markdown

Summary of the Pull Request

Force each virtiofs device to a single virtio queue by adding a vcpus=1 token to the virtiofs device-options string. This bounds the number of concurrent guest-memory apertures a device can request, avoiding the host VID's 512-aperture quota that wsldevicehost otherwise livelocks against when servicing many parallel requests.

The token reuses the existing device-options channel already used to pass the swiotlb information, so no new IPC path or message format is introduced.

Detailed Description of the Pull Request / Additional comments

  • Defines a shared c_vcpusOption ("vcpus=1") constant in GuestDeviceManager.h, with a TODO to revisit once the devicehost supports multiple shares per device.
  • HcsVirtualMachine::AddShare (wslc) and WslCoreVm::AddVirtioFsShare (wsl) append the swiotlb and vcpus tokens via a small appendOption lambda, covering the fixed-drive, dynamic-add, and remount paths.
  • Both tokens are constant for the VM's lifetime, so duplicates collapse to a single entry when VirtioFsShare parses the options into a map.
  • Bumps Microsoft.WSL.DeviceHost to 1.2.32-0.

Note: this supersedes the earlier approach of passing the VM's dynamic vCPU count. A single queue (vcpus=1) is what's needed to keep aperture usage under the host quota.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already.
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: N/A

Validation Steps Performed

Manually validated that virtiofs /mnt/c shares come up with the vcpus=1 option across fixed-drive, dynamic-add, and remount paths, and that wsldevicehost no longer exhausts the host VID aperture quota under parallel load.

Copilot AI review requested due to automatic review settings June 9, 2026 23:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR passes the WSL VM’s vCPU count to wsldevicehost.dll by appending a vcpus=<count> token (semicolon-delimited) to the virtiofs mount/device options string, reusing the existing device-options pathway (already used for swiotlb).

Changes:

  • wsl: Append vcpus={ProcessorCount} to the effective virtiofs mount options in WslCoreVm::AddVirtioFsShare when ProcessorCount != 0.
  • wslc: Cache a vcpus={CpuCount} token in HcsVirtualMachine and append it to the virtiofs device options in AddShare.
  • Introduce a new m_vcpusOption member to carry the token through the wslc path similarly to m_swiotlbOption.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/windows/service/exe/WslCoreVm.cpp Appends vcpus=<count> to virtiofs mount options in the core WSL VM virtiofs share path.
src/windows/service/exe/HcsVirtualMachine.h Adds m_vcpusOption member to store the vCPU-count token for wsldevicehost.
src/windows/service/exe/HcsVirtualMachine.cpp Initializes and appends the cached vcpus=<count> token when creating virtiofs shares.

Comment thread src/windows/service/exe/WslCoreVm.cpp Outdated
Comment thread src/windows/service/exe/HcsVirtualMachine.cpp Outdated
Comment thread src/windows/service/exe/HcsVirtualMachine.cpp Outdated
Comment thread src/windows/service/exe/WslCoreVm.cpp Outdated
Copilot AI review requested due to automatic review settings June 10, 2026 18:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/HcsVirtualMachine.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Add a vcpus=1 token to the virtiofs device-options string so each device
exposes a single virtio queue. This bounds the number of concurrent
guest-memory apertures the device can request, avoiding the host VID's
512-aperture quota that wsldevicehost otherwise livelocks against when
servicing many parallel requests.

- Define a shared c_vcpusOption ("vcpus=1") constant in
  GuestDeviceManager.h, with a TODO to revisit once the devicehost
  supports multiple shares per device.
- HcsVirtualMachine::AddShare and WslCoreVm::AddVirtioFsShare append the
  swiotlb and vcpus tokens via a small appendOption lambda, covering the
  fixed-drive, dynamic-add, and remount paths. Both tokens are constant
  for the VM's lifetime, so duplicates collapse to a single VirtioFsShare
  map entry.
- Bump Microsoft.WSL.DeviceHost to 1.2.32-0.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 13, 2026 13:59
@benhillis benhillis force-pushed the user/askariv/virtiofs_with_vcpus branch from c848fdd to e5f8b82 Compare June 13, 2026 13:59
@benhillis benhillis changed the title User/askariv/virtiofs with vcpus Force virtiofs devices to a single virtio queue (vcpus=1) Jun 13, 2026
@benhillis benhillis marked this pull request as ready for review June 13, 2026 14:00
@benhillis benhillis requested a review from a team as a code owner June 13, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +2189 to +2193
// Append swiotlb and vcpus here to cover the fixed-drive, dynamic add, and remount paths.
// Safe to duplicate: both tokens are constant per VM, and VirtioFsShare collapses repeats into one map entry.
std::wstring effectiveOptions(Options);
if (!m_swiotlbOption.empty())
{
auto appendOption = [&effectiveOptions](const std::wstring& option) {
if (option.empty())
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.

3 participants