Skip to content

GPU-PV: NVIDIA RM objects created by WSL processes are never released on the host (NVRM non-paged pool leak), traced to the escape/teardown path #42371

Backlog

Description

@sanik9477

Follow-up to #12756, which was auto-closed. This report adds a minimal repro, exact per-call numbers, and guest- and host-side evidence of where the frees are lost.

Windows Version

Microsoft Windows [Version 10.0.26200.8037]

WSL Version

2.7.11.0 (Direct3D 1.611.1-81528511, DXCore 10.0.26100.1-240331-1435.ge-release, WSLg 1.0.73.2)

Are you using WSL 1 or WSL 2?

WSL 2

Kernel Version

6.18.33.2-microsoft-standard-WSL2

Distro Version

Ubuntu 24.04.1 LTS

Other Software

NVIDIA GeForce RTX 5090, Windows driver 617.42 (WDDM 32.0.16.1742). NVML and nvidia-smi come from /usr/lib/wsl/lib.

Repro Steps

  1. On Windows, read the NVRM pool tag: poolmon, or NtQuerySystemInformation(SystemPoolTagInformation), which needs no admin.
  2. In WSL, run nvidia-smi 10 times, or build the program below and run ./nvml_leak_repro 10 handle.
  3. Read NVRM again. Expect +420 after 10x nvidia-smi and +170 after the repro. Then check dmesg | grep 'dxgkio_escape: Ioctl failed: -22'.
// nvml_leak_repro.c - every NVML session in WSL2 leaks NVIDIA RM objects in the Windows host driver.
// Build: gcc -O2 -o nvml_leak_repro nvml_leak_repro.c -ldl
// Run:   ./nvml_leak_repro 10          # 10 x (nvmlInit_v2 + nvmlShutdown)                         -> host NVRM +7 each
//        ./nvml_leak_repro 10 handle   # 10 x (init + nvmlDeviceGetHandleByIndex + shutdown)       -> host NVRM +17 each
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef int (*fn0)(void);
typedef int (*fn_handle)(unsigned int, void **);

int main(int argc, char **argv) {
  int n = argc > 1 ? atoi(argv[1]) : 1;
  int with_handle = argc > 2 && strcmp(argv[2], "handle") == 0;
  void *lib = dlopen("libnvidia-ml.so.1", RTLD_NOW);
  if (!lib) { fprintf(stderr, "dlopen libnvidia-ml.so.1: %s\n", dlerror()); return 1; }
  fn0 init = (fn0)dlsym(lib, "nvmlInit_v2"), shut = (fn0)dlsym(lib, "nvmlShutdown");
  fn_handle get = (fn_handle)dlsym(lib, "nvmlDeviceGetHandleByIndex_v2");
  if (!init || !shut || !get) { fprintf(stderr, "missing NVML symbols\n"); return 1; }
  for (int i = 0; i < n; i++) {
    int r1 = init(), r2 = 0, r3;
    void *dev = NULL;
    if (with_handle) r2 = get(0, &dev);
    r3 = shut();
    if (r1 || r2 || r3) { fprintf(stderr, "cycle %d: init=%d handle=%d shutdown=%d\n", i, r1, r2, r3); return 1; }
  }
  printf("%d NVML cycle(s)%s done; expected host NVRM growth: %d allocations\n", n, with_handle ? " with device handle" : "", n * (with_handle ? 17 : 7));
  return 0;
}

Expected Behavior

When a WSL process exits, all host-side driver state it created is released, as it is for a native Windows process. nvidia-smi.exe on Windows leaks 0.

Actual Behavior

Host NVRM allocations leaked per WSL launch. Each row is 10 launches; every result is an exact integer and repeatable.

WSL command NVRM allocs Bytes -22 dmesg lines
true; open/close /dev/dxg; ENUMADAPTERS2 + CLOSEADAPTER 0 0 0
D3DKMT device create + destroy (raw ioctls) 0 0 0
nvmlInit_v2 + nvmlShutdown 7 1,984 1
nvmlInit_v2, then exit without shutdown, or SIGKILL 7 1,984 0
10 init/shutdown cycles in one process 70 19,840 10
NVML init + nvmlDeviceGetHandleByIndex(0) + shutdown 17 6,112 3
nvidia-smi --query-gpu=uuid,memory.used --format=csv,noheader,nounits 17 6,112 3
nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits 25 8,672 3
nvidia-smi 42 11,664 5
nvidia-smi -q 44 11,712 n/a
CUDA context create + 1 MB alloc/free + destroy (clean or SIGKILL) 2 160 0
Control: nvidia-smi.exe on Windows 0 0 n/a
  • A SIGKILLed process leaks exactly as much as one that exits cleanly.
  • Other users report the leak survives wsl --shutdown. Only a reboot clears it.
  • Impact: a monitoring stack polling nvidia-smi every few seconds reached about 1.5M leaked allocations (about 470 MB of non-paged pool) within days. By then:
    • nvlddmkm DPCs on the GPU-interrupt CPU reached about 10 ms (roughly +7 ms per 1M leaked) and game frames stalled.
    • native nvidia-smi.exe slows in step with the leak: in a same-boot dose test its median call time went from 62.6 ms at 45.6k leaked allocations to 1,039 ms at 1.52M (the --query-gpu=power.draw form: about 46 ms fresh to 141 ms).

Diagnosis

Method, black-box only:

  • an LD_PRELOAD logger on ioctl() for /dev/dxg file descriptors;
  • host pool counters sampled around each call;
  • NVIDIA private escapes decoded with the public RM API structures and class IDs from open-gpu-kernel-modules.

1. Guest: NVML tears down in the wrong order, so its frees never leave the VM.

End of one plain nvidia-smi. Payloads are shortened; fn is the escape function code after the 'NVDA' / 'NV**' header.

seq=79 ESCAPE        ret=0             adapter=40000100  fn=0x0500002a (RM alloc)
seq=80 ESCAPE        ret=0             adapter=40000100  fn=0x0500002b (RM control)
seq=81 DESTROYDEVICE ret=0             device=40000000
seq=82 CLOSEADAPTER  ret=0             adapter=40000100
seq=83 ESCAPE        ret=-1 errno=22   adapter=40000100  fn=0x0500000c (RM free)
seq=84 ESCAPE        ret=-1 errno=22   adapter=40000100  fn=0x0500000c (RM free)
seq=85 ESCAPE        ret=-1 errno=22   adapter=40000100  fn=0x0500000c (RM free)
seq=86 ESCAPE        ret=-1 errno=22   adapter=40000100  fn=0x0500000c (RM free)
seq=87 ESCAPE        ret=-1 errno=22   adapter=40000100  fn=0x0500002b (GPU detach)

One raw line as logged:

IOCTL seq=83 nr=0d ESCAPE ret=-1 errno=22 us=359 adapter=40000100 device=00000000 type=0 flags=00000000 size=64 in=4144564e02000100400000002a2a564e0c000005...
  • Each failed escape logs misc dxg: dxgk: dxgkio_escape: Ioctl failed: -22.
  • dxgkrnl is right to reject them: dxgprocess_adapter_by_handle() no longer finds the closed handle (ioctl.c, 6.18 branch).
  • This -22 is not a host-side failure: dxgvmb_send_escape only ever takes 0 or -EOVERFLOW from the host's packet status.
  • The ordering bug is in NVML, which ships in lxss/lib, but the result is that the frees never cross VMBus.
  • When the detach fails, NVML also skips freeing the RM client.

2. Host: frees that do arrive are rejected.

The shim was set to swallow CLOSEADAPTER (and, in a second run, DESTROYDEVICE too) so the frees reach Windows; the kernel closes both at process exit. In three such runs 94 RM free escapes reached the host and succeeded at the dxg level, but every reply carried NVOS00.status = 0x3d (NV_ERR_INVALID_POINTER). Zero succeeded:

  • CLOSEADAPTER deferred, 10 launches: 40 frees;
  • both deferred, 10 launches: 50 frees, including the 10 client frees NVML only sends once the GPU detach succeeds;
  • one nvidia-smi -q with both deferred: 4 frees.

RM allocs and controls in the same processes succeed.

ESCAPE ret=0 errno=0 size=64 out=4144564e02000100400000002a2a564e0c00000501000000000000000000000000000000000000000000000001000000ff15d0c120005aa560005aa53d000000
(last 4 bytes 3d000000 = NVOS00.status 0x3d)

With deferral the leak drops only from 42 to 39; the 3 is what the now-successful detach releases. So reordering the guest teardown alone cannot fix this.

3. Host: nothing is cleaned up when the guest process exits.

After the guest sends DXGK_VMBCOMMAND_DESTROYPROCESS, the host NVRM count doesn't change. The ETW stack in #12756 shows these allocations are made on a System worker thread:
ExpWorkerThread -> dxgkrnl!VmBusProcessPacket -> VmBusExecuteCommandInProcessContext -> DXG_HOST_VIRTUALGPU_VMBUS::VmBusEscape -> DxgkEscape -> DXGADAPTER::DdiEscape -> nvlddmkm
So nothing tied to the guest process's lifetime owns them.

Question for the dxgkrnl side: could host dxgkrnl give the KMD a per-guest-process context for VM escapes, plus a destroy notification when the guest process goes away? The driver could then clean up as it does for native processes.

Host cost per RM object. These sum exactly to every measured leak (17, 25, 42):

RM object Allocs Bytes
NV01_ROOT_CLIENT (0x41) 7 1,984
NV01_DEVICE_0 (0x80) 5 1,392
NV20_SUBDEVICE_0 (0x2080) 5 2,736
NV2081_BINAPI (0x2081) 4 1,152
RM_USER_SHARED_DATA (0xde) 4 1,408
NV04_DISPLAY_COMMON (0x73) 13 1,760
NV20_SUBDEVICE_DIAG (0x208f) 4 1,232

D3DKMT devices, contexts, HW queues and RM controls are all freed correctly. CUDA, which goes through the D3DKMT path, leaks only about 2 x 80 B per process.

Workaround

Avoid short-lived NVML clients in WSL. Use one persistent process that calls nvmlInit once and then polls, or nvidia-smi.exe via interop.

Diagnostic Logs

Full ioctl traces and per-call host pool deltas are available on request.

Activity

  1. github-actions commented on Nov 26, 2026

    @github-actions
    Contributor

    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 wsl-gh-logs@microsoft.com 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'.

  2. sanik9477 commented on Nov 26, 2026

    @sanik9477
    Author

    Correction and more evidence (same PC, same driver and WSL build).

    Correction. For a few minutes the first version of this report said native nvidia-smi.exe took "2.7x as long (168.6 vs 62.7 ms)". That compared two different command forms. Like-for-like:

    • the narrow --query-gpu=power.draw form is 3.6x (168.6 ms on a naturally leaked boot at about 1.45M, vs 46.6 ms fresh);
    • plain nvidia-smi is 16.6x at 1.52M (table below).

    The body is corrected, and so is the count of rejected frees: 94 RM frees reached the host across three deferred runs, and all 94 returned NV_ERR_INVALID_POINTER.

    Dose test: the slowdown follows the leak. On one boot, NVRM was taken from 45.6k to 1.52M leaked allocations with 35,032 WSL nvidia-smi launches in 5 chunks (42.0 each). Native nvidia-smi.exe on Windows was timed at each rest point, in clean idle blocks:

    Leaked NVRM allocations plain nvidia-smi.exe, median (p90) --query-gpu=power.draw form
    45.6k (baseline) 62.6 ms (66.5) 46-47 ms (fresh boot)
    340k 228 ms (250) -
    635k 379 ms (395) 79 ms
    930k 601 ms (668) 109 ms
    1.23M 830 ms (935) 125 ms
    1.52M 1,039 ms (1,142) 141 ms

    At 1.52M:

    • nvlddmkm DPC time on the GPU-interrupt CPU was 19.2 ms/s vs 8.2 ms/s at baseline.
    • The worst frame of a D3D11 frame-time test was 15.9 ms vs 5.6 ms.

    A reboot brought every number back to baseline.

    Also leaked: each NVML session also leaks one 80-byte allocation in the NvLH pool tag. No other NVIDIA or dxgkrnl pool tag moves.

    Rate from a typical poller: one nvidia-smi --query-gpu=power.draw every 2.3 s is about +39k NVRM allocations (13.6 MB) an hour.

    A leak meter from inside WSL: journalctl -k | grep -c 'dxgkio_escape: Ioctl failed: -22' counts 1 line per NVML init/shutdown, 3 per query, and 5 per plain nvidia-smi.

    Gist: https://gist.github.com/sanik9477/f386cf4d398baa51e0d6a2310832c9bc

    • nvml_leak_repro.c: the repro above;
    • nvrm_count.ps1: a no-admin NVRM counter for Windows (NtQuerySystemInformation class 22);
    • dxgtrace.c: the LD_PRELOAD /dev/dxg ioctl logger used for every trace, including the deferred-close modes;
    • evidence.md: the decoded traces, with per-ioctl host deltas and per-condition plateau deltas.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions