WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Windows->WSL (Plan 9) is ~26x native on metadata and ~73x on reads - consider a Windows-side metadata cache

Open zcsizmadia opened this issue 3 months ago • 4 comments

Scope — not a duplicate of #4197. That issue and most filesystem-performance threads concern /mnt/* (Windows files seen from Linux), which is being worked on. This is the opposite direction: Linux files seen from Windows via \\wsl.localhost / \\wsl$, which Windows-side tooling — editors, git.exe, indexers, build systems — uses constantly.

Problem

Same machine, same 3,000-file tree, warm:

walk (enumerate) read (all bytes)
native, inside WSL 4 ms 39 ms
\\wsl.localhost (Plan 9) 104 ms 2856 ms

The ratios are the interesting part: reads are ~73× native, but the walk is ~26× native while transferring almost no data. The cost tracks the number of filesystem operations, not bytes — every stat, readdir and negative lookup is a round trip across the VM boundary. Windows tools are unusually round-trip heavy (a Windows git status on a WSL repo issues tens of thousands of them), which is why this direction feels worse than raw bandwidth numbers suggest.

Proposed solution

Cache directory metadata on the Windows side of the Plan 9 client, kept coherent by a change-notification channel from the Linux side, so stat / readdir / negative lookups are served locally instead of round-tripping. Most of the gap appears to be recoverable this way without touching bulk read/write throughput.

Alternatives considered

  • Per-tool workarounds — routing commands through wsl.exe (e.g. desktop/desktop#22044). Works, but every tool needs its own fix, and it does nothing for Explorer or an editor's file watcher.
  • Keeping the working copy on NTFS — gives up ext4 performance for the Linux-side workload, which is usually the reason for using WSL2 in the first place.
  • Testing the premise out-of-tree. I implemented the caching approach as a WinFsp filesystem to check whether it actually pays off: https://github.com/zcsizmadia/wsldrive (MIT). The numbers above come from its benchmark harness; with the metadata mirror in place the same walk is 39 ms. I am not proposing that you adopt it — only offering it as evidence that client-side metadata caching recovers most of the per-operation cost, and that the idea may be worth considering in the platform, where it would benefit every tool rather than one at a time.

Additional context

  • Windows 11 10.0.26200, WSL 2.7.8.0, kernel 6.18.33.1-1, Ubuntu (WSL2)
  • The win is per-operation, not per-byte: a single large sequential copy is roughly a wash, so this is not a claim about bulk throughput.
  • Happy to share the benchmark harness or a more detailed profile if that would be useful.

zcsizmadia avatar Aug 29 '26 22:08 zcsizmadia

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use .\collect-wsl-logs.ps1 -LogProfile networking instead, following the instructions in Collect WSL logs for networking issues

Once completed please upload the output files to this GitHub issue.

See Collect WSL logs (recommended method).

If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.

github-actions[bot] avatar Aug 29 '26 22:08 github-actions[bot]

/feature

zcsizmadia avatar Aug 29 '26 22:08 zcsizmadia

Diagnostic information
Found '/feature', adding tag 'feature'

github-actions[bot] avatar Aug 29 '26 22:08 github-actions[bot]

Sharing our own experience with something that might be the same wall, from a different tool: wip wraps wslc build, and staging a build context that lives on the WSL filesystem means walking it over \wsl.localhost/Plan 9 before handing it to wslc.

Back when wip was a Ruby gem running inside the WSL distro, this seemed slow enough to be a real problem — some rough numbers from that era (2,000-file context, /tmp vs /mnt/c). Different process topology and an older WSLC, so I wouldn't treat those numbers as current, but the general shape — cost tracking file count more than bytes — seems to have been at least part of what nudged us toward rewriting as a Windows-side C# Native AOT binary and dealing with the crossing explicitly rather than assuming it'd be fast enough.

What wip does now to work around it, in case the pattern is useful to whoever ends up designing a cache for this:

  • Mirror the WSL-side context into a persistent Windows-local cache once, then on later builds only touch what changed — diffed by a manifest of (relative path → size, mtime) rather than re-reading file contents
  • Build that manifest from one readdir-equivalent per directory (DirectoryInfo.EnumerateFileSystemInfos, which returns size/mtime/attributes inline) instead of a separate stat per file, on the theory that the round trip is the expensive part, not the data itself
  • Copy changed entries atomically (temp name + rename) so an interrupted sync doesn't leave a half-updated cache

This doesn't address the underlying per-operation cost, just tries to avoid paying it more than once per file. A platform-side cache along the lines proposed here could plausibly let us drop this layer entirely, if it pans out.

abechan1 avatar Sep 03 '26 13:09 abechan1