diff --git a/src/windows/common/helpers.cpp b/src/windows/common/helpers.cpp index f8f3cdaa4..7027a2992 100644 --- a/src/windows/common/helpers.cpp +++ b/src/windows/common/helpers.cpp @@ -39,6 +39,8 @@ using wsl::windows::common::helpers::LaunchWslRelayFlags; constexpr auto c_WslSupportInterfaceKey = L"Software\\Classes\\Interface\\{46f3c96d-ffa3-42f0-b052-52f5e7ecbb08}"; constexpr auto c_WslSupportInterfaceName = L"IWslSupport"; +constexpr ULONG c_MaxStorageHwQueues = 4; + namespace { class ProcessLauncher @@ -762,8 +764,12 @@ try } CATCH_LOG() -void wsl::windows::common::helpers::AppendCommonKernelCommandLine(_Inout_ std::wstring& kernelCmdLine, _In_ int pageReportingOrder, _In_ ULONG64 swiotlbSizeBytes) +void wsl::windows::common::helpers::AppendCommonKernelCommandLine( + _Inout_ std::wstring& kernelCmdLine, _In_ int pageReportingOrder, _In_ ULONG64 swiotlbSizeBytes, _In_ ULONG cpuCount) { + // Set number of processors. + kernelCmdLine += std::format(L" nr_cpus={}", cpuCount); + // Enable timesync workaround to sync on resume from sleep in modern standby. kernelCmdLine += L" hv_utils.timesync_implicit=1"; @@ -778,6 +784,12 @@ void wsl::windows::common::helpers::AppendCommonKernelCommandLine(_Inout_ std::w { kernelCmdLine += std::format(L" swiotlb=force hv_pci_swiotlb={}", swiotlbSizeBytes); } + + // Cap the storage hw queue count. Default is CPU count. + if (cpuCount > c_MaxStorageHwQueues) + { + kernelCmdLine += std::format(L" hv_storvsc.storvsc_max_hw_queues={}", c_MaxStorageHwQueues); + } } UINT64 wsl::windows::common::helpers::ComputeDefaultSwiotlbConfig(_In_ UINT64 memoryBytes) diff --git a/src/windows/common/helpers.hpp b/src/windows/common/helpers.hpp index e83fc1832..2253ace99 100644 --- a/src/windows/common/helpers.hpp +++ b/src/windows/common/helpers.hpp @@ -205,7 +205,7 @@ bool TryAttachConsole(); void RegisterWithDcat(_In_ bool IncludeVersionNumber = true); -void AppendCommonKernelCommandLine(_Inout_ std::wstring& kernelCmdLine, _In_ int pageReportingOrder, _In_ ULONG64 swiotlbSizeBytes); +void AppendCommonKernelCommandLine(_Inout_ std::wstring& kernelCmdLine, _In_ int pageReportingOrder, _In_ ULONG64 swiotlbSizeBytes, _In_ ULONG cpuCount); UINT64 ComputeDefaultSwiotlbConfig(_In_ UINT64 memoryBytes); diff --git a/src/windows/service/exe/HcsVirtualMachine.cpp b/src/windows/service/exe/HcsVirtualMachine.cpp index 17fd76a63..c11a1f78e 100644 --- a/src/windows/service/exe/HcsVirtualMachine.cpp +++ b/src/windows/service/exe/HcsVirtualMachine.cpp @@ -166,8 +166,7 @@ HcsVirtualMachine::HcsVirtualMachine(_In_ const WSLCSessionSettings* Settings) // Initialize kernel command line. std::wstring kernelCmdLine = L"initrd=\\" LXSS_VM_MODE_INITRD_NAME L" " TEXT(WSLC_ROOT_INIT_ENV) L"=1 panic=-1"; - kernelCmdLine += std::format(L" nr_cpus={}", Settings->CpuCount); - helpers::AppendCommonKernelCommandLine(kernelCmdLine, pageReportingOrder, swiotlbSizeBytes); + helpers::AppendCommonKernelCommandLine(kernelCmdLine, pageReportingOrder, swiotlbSizeBytes, Settings->CpuCount); // Setup dmesg collector with optional DmesgOutput handle. // TODO: move dmesg collector to user session process. diff --git a/src/windows/service/exe/WslCoreVm.cpp b/src/windows/service/exe/WslCoreVm.cpp index 7cdcae3cf..9705e9cc2 100644 --- a/src/windows/service/exe/WslCoreVm.cpp +++ b/src/windows/service/exe/WslCoreVm.cpp @@ -1575,11 +1575,8 @@ std::wstring WslCoreVm::GenerateConfigJson() // Initialize kernel command line. std::wstring kernelCmdLine = L"initrd=\\" LXSS_VM_MODE_INITRD_NAME L" " TEXT(WSL_ROOT_INIT_ENV) L"=1 panic=-1"; - // Set number of processors. - kernelCmdLine += std::format(L" nr_cpus={}", m_vmConfig.ProcessorCount); - // Append common kernel parameters shared between WSL2 and WSLC. - helpers::AppendCommonKernelCommandLine(kernelCmdLine, m_pageReportingOrder, m_vmConfig.SwiotlbSizeBytes); + helpers::AppendCommonKernelCommandLine(kernelCmdLine, m_pageReportingOrder, m_vmConfig.SwiotlbSizeBytes, m_vmConfig.ProcessorCount); if (m_vmConfig.EnableVirtio && helpers::IsVirtioSerialConsoleSupported()) {