Repository navigation
Conversation
On Windows 10 `vmmem` is the memory process of every Hyper-V VM, not only WSL's. A machine can have an orphaned one, created at boot by a process that exited right after it; the first-match lookup picked it and reported WSL2 as running forever at 0 MB, while the real WSL VM went unseen. When looking for `vmmem`, a process now only counts if its parent (the VM worker, vmwp.exe) is still in the same snapshot and was created no later than it, since pids are reused. The snapshot already holds both, so this adds no system call. `vmmemWSL` on Windows 11 is WSL's alone and is unaffected. A second live VM next to WSL2 (Windows Sandbox, a Hyper-V guest) still cannot be told apart without administrator rights: the worker and memory processes cannot be opened and the Host Compute Service is admin-only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows 10 the WSL2 VM's memory process is called
vmmem, and so is the memory process of every other Hyper-V VM.find()returns the first match, and-processcannot help because the names are identical.A common source of a second one is Windows Sandbox. With that optional feature (
Containers-DisposableClientVM) enabled, Windows creates avmmemat boot, even though Sandbox is not running. It holds about 1 GB of committed memory (1 078 MB of private bytes, 0 MB of working set), and its creator exits right after creating it. This is my case: Windows Sandbox is enabled but not in use, and full Hyper-V is off.So on my machine there are two:
vmwp.exe, itself a child ofvmcompute.exeWith the v1.3.0 Windows 10 build,
-logshows this on every poll:That was while the real WSL VM held 7.4 GB. So with Windows Sandbox enabled, the icon stays "on" at 0 % even with WSL shut down, and the WSL VM is never measured.
Fix
A VM's memory process is created by its worker,
vmwp.exe, which lives as long as the VM.When the name being looked for is
vmmem,find()now only takes a process whose parent is in the same session-0 snapshot and was created no later than it. The age check is there because pids are reused.vmmemWSLon Windows 11 belongs to WSL alone, so there the name alone still decides andbehaviour is unchanged.
The walk over the snapshot moved into a small
Entriesiterator. The selection logic is inpick(), so it can be unit-tested on synthetic entries. The new testpick_needs_live_parentcovers four cases:Known limitation
The fix covers the idle Sandbox VM, but not a Sandbox window that is actually open: a second live VM next to WSL2, whether a running Windows Sandbox or a Hyper-V guest, still cannot be told apart without administrator rights.
OpenProcessonvmwp.exe,vmmemandvmcompute.exeis denied to a normal user, and the Host Compute Service, which knows which VM is WSL's, is admin-only. In that case the first match is taken, as before. The limitation is documented in the module docs and in the README.Testing
Tested on Windows 10 22H2 (19045) x64 with WSL 2.7.3.
.\build.ps1 -Win10, then-log:running=true pid=21156 mem=2.90 GBwith CPU readings.The orphan is skipped, and between refreshes only the pid is checked (the snapshot count does not grow).
cargo fmt --checkcargo clippy --locked --release --all-targets -- -D warningscargo test --locked --release: 21 passed, 6 ignored, which are the existing#[ignore]testscargo doc --no-deps --document-private-itemswithRUSTDOCFLAGS=-D warningsNot tested:
vmmemWSL.