Skip to content

Skip orphaned vmmem processes on Windows 10 - #1

Open
LPdsgn wants to merge 1 commit into
ideaconnect:mainfrom
LPdsgn:fix/win10-orphan-vmmem
Open

LPdsgn wants to merge 1 commit into
ideaconnect:mainfrom
LPdsgn:fix/win10-orphan-vmmem

Conversation

@LPdsgn

@LPdsgn LPdsgn commented Sep 29, 2026 •

Copy link
Copy Markdown

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 -process cannot 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 a vmmem at 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:

pid what created parent working set
8056 idle Windows Sandbox VM 19 s after boot, minutes before WSL started exited right after creating it 0 MB
WSL's WSL2 utility VM when WSL starts vmwp.exe, itself a child of vmcompute.exe several GB

With the v1.3.0 Windows 10 build, -log shows this on every poll:

running=true pid=8056 cpu=0.00 mem=0 MB

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.

  • Both facts are already in the snapshot, so there is no extra system call.
  • The pid fast path between refreshes is unchanged.
  • vmmemWSL on Windows 11 belongs to WSL alone, so there the name alone still decides and
    behaviour is unchanged.

The walk over the snapshot moved into a small Entries iterator. The selection logic is in pick(), so it can be unit-tested on synthetic entries. The new test pick_needs_live_parent covers four cases:

  • an orphan;
  • a parent pid reused by a newer process;
  • an orphan followed by a live VM;
  • case folding.

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. OpenProcess on vmwp.exe, vmmem and vmcompute.exe is 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 GB with CPU readings.
    The orphan is skipped, and between refreshes only the pid is checked (the snapshot count does not grow).
  • Every x64 CI step passes locally with the MSVC toolchain (rustc 1.98.1):
    • cargo fmt --check
    • cargo clippy --locked --release --all-targets -- -D warnings
    • both builds, Windows 11 and Windows 10
    • cargo test --locked --release: 21 passed, 6 ignored, which are the existing
      #[ignore] tests
    • cargo doc --no-deps --document-private-items with RUSTDOCFLAGS=-D warnings

Not tested:

  • ARM64: left to CI; the change has no architecture-specific code.
  • Windows 11: there the check is not applied to vmmemWSL.
  • WSL shut down on the affected machine: covered by the unit test, and in the live run the orphan is already skipped.

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.
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.

1 participant