WSL 2 的 Windows 文件系统访问速度正在提升
WSL 2 is getting faster Windows file system access

原始链接: https://www.boxofcables.dev/wsl2-per-device-swiotlb-pools-for-virtiofs-and-virtioproxy/

WSL 2 的跨系统工作流文件性能达到了新的里程碑。最近的一次更新(2026 年 5 月合并)为 virtiofs 路径提供了一个长期瓶颈的解决方案:为每个 virtio 设备分配其独立的 DMA (SWIOTLB) 内存池。 此前,WSL 2 依赖单一的全局内存池,导致文件 I/O 与网络流量之间存在资源竞争。通过隔离这些资源,PR #40654 中详述的这项新更改消除了开发人员在 Linux 中构建存储于 Windows 驱动器上的项目时的一大性能障碍。 **核心要点:** * **优化:** 每个 virtio 设备现在可以独立运行,从而降低了 I/O 延迟并减少了资源争用。 * **要求:** 用户必须更新至内核版本 6.18.26.3-1 或更高版本,以及 WSL 2 DeviceHost 1.2.29-0。 * **如何启用:** 确保 `.wslconfig` 文件中已设置 `virtiofs=true`,并为 WSL 分配至少 1 GB 的内存。 虽然默认协议仍为较旧的 Plan 9,但切换至 virtiofs 并配合此项 DMA 更新,显著缩小了原生 Linux 文件访问与 Windows 托管文件系统之间的性能差距,延续了微软在跨系统集成方面的持续改进。

Hacker News 最近的一场讨论凸显了 WSL 2 文件系统性能方面的持续挑战,这对开发者来说仍是一个重大的痛点。许多用户认为,跨操作系统访问文件(特别是通过 `/mnt/c`)速度缓慢,在历史上一直将开发者从 Windows 推向 Linux 或 macOS。 虽然一些用户指出,如果将文件严格保存在 Linux 文件系统中,性能尚可接受,但另一些用户认为这种工作流程在管理大型项目或媒体库时既受限又繁琐。技术型用户指出,性能瓶颈源于连接 Windows 和 Linux 文件系统的开销,其表现类似于缓慢的网络驱动器。 此次讨论也反映出一种趋势:在简化复杂配置任务的 AI 助手的帮助下,越来越多的开发者正转向以 Linux 作为主要桌面环境。尽管一些参与者为 Windows 作为稳定且适合游戏的操作系统进行辩护,但共识是,微软未能尽早优先实现原生速度的文件系统集成是一个重大的失误,这使得许多开发者对 WSL 的现状感到失望。
相关文章

原文

From DrvFs in WSL 1 to Plan 9 to virtiofs, cross-OS file access in WSL 2 has improved with each generation. A new change gives each virtio device its own dedicated DMA pool, removing the last major contention point on the virtiofs path.

WSL 2 is getting faster Windows file system access

If your workflow crosses the Windows/Linux boundary, file I/O performance in WSL 2 has been getting steadily better. A change landed in WSL 2 in May 2026 that removes one of the last remaining bottlenecks on the virtiofs path. To understand why it matters, it helps to follow how cross-OS file access has evolved.

How we got here

WSL 1 (2016) handled Windows drive access through DrvFs, a custom filesystem driver running inside the Windows NT kernel. Because WSL 1 ran Linux processes directly on the Windows kernel through a compatibility layer, file operations on /mnt/c could reach NTFS almost directly. Performance was good for file-heavy workloads.

WSL 2 (May 2019) replaced that model with a full Linux kernel in a lightweight Hyper-V VM. That was the right trade: real Linux kernel calls, proper syscall compatibility, and much better performance for Linux-native workloads. For cross-OS access, the VM boundary meant a different approach was needed. Microsoft built a Plan 9 (9P) file server into the Windows-side WSL service. Your Linux session connects to it over a Hyper-V socket at boot, and file operations on /mnt/c travel through that 9P protocol channel.

9P over a Hyper-V socket works, but it has protocol overhead: each operation is bounded by a message size parameter (msize=65536, 64 KB). File-heavy workloads that hit many small files carry that overhead on every round trip. Microsoft has been iterating on this since WSL 2 launched.

Around 2021, virtiofs arrived as an experimental opt-in. Virtiofs uses the VirtIO transport for shared-memory file access, reducing serialization overhead compared to 9P. You enable it in the [wsl2] section of your .wslconfig with virtiofs=true. It has been working its way through incrementally since then: device reuse improvements in PR #40298, shared mmap support without DAX in PR #40426, and now the DMA layer fix.

The DMA layer

Virtual machines on Hyper-V perform DMA for I/O through bounce buffers: a reserved memory region below the 4 GB DMA boundary that hardware can address directly. The Linux kernel calls this the SWIOTLB pool. Until recently, all virtio devices in a WSL 2 session shared one global pool. A virtiofs mount for /mnt/c, one for /mnt/d, and the virtio network adapter all queued into the same buffer, contending with each other during heavy I/O.

PR #40654, authored by Ben Hillis and merged May 27, 2026, gives each virtio device its own dedicated DMA pool. The kernel allocates a contiguous physical range below 4 GB at boot, publishes its address through sysfs (/sys/bus/vmbus/drivers/hv_pci/swiotlb_base and swiotlb_size), and the WSL service reads those values and injects a per-device swiotlb= option into each virtio device at creation time. No more shared queue between drives and the network adapter.

Note: this requires kernel Microsoft.WSL.Kernel 6.18.26.3-1, shipping with WSL 2 DeviceHost 1.2.29-0. If you are on an older kernel, WSL will tell you: "The running kernel is missing a patch that significantly improves virtio device performance. Update to a more recent WSL kernel to enable this optimization."

What this means in practice

The scenarios that benefit most are the file-heavy cross-OS workflows: working in a project that lives on a Windows drive but builds in Linux. If you keep your code under C:\Users\you\code and run cargo build, npm install, or mvn package from /mnt/c, every file read pays a cross-OS I/O cost. The per-device pool removes one of the remaining contention points on the virtiofs path.

VirtioProxy networking also benefits, since it shares the same DMA infrastructure and gets its own pool too.

To get the most out of this:

  • Set virtiofs=true in the [wsl2] section of your .wslconfig.
  • Update to the latest WSL kernel with wsl.exe --update --pre-release.
  • Keep your WSL 2 session RAM above 1 GB. The SWIOTLB pool needs at least 64 MB of headroom.

Virtiofs remains opt-in for now: the default transport is still Plan 9 over a Hyper-V socket.

The longer arc

WSL filesystem performance across the OS boundary has gotten better with each generation. WSL 1's DrvFs was fast because there was no VM boundary. WSL 2 introduced the VM and the shift to 9P. Virtiofs closed most of the gap. Per-device SWIOTLB pools remove contention at the DMA layer. The gap keeps narrowing.

The default is still Plan 9 over a Hyper-V socket. Virtiofs is still opt-in. The work is ongoing in the open at github.com/microsoft/WSL.

联系我们 contact @ memedata.com