gpu: trim mapped driver shader-cache pages when idle (VICTORY_DRIVER_TRIM) #112

Closed
github-bot wants to merge 1 commit from github-bot/gh-111 into main AGit
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 12:40 UTC · original
SovietBearz0r:minivi-drivercache-trim → main · +457 −2 · 5 files · 1 commits · closed without merging

Return mapped driver shader-cache pages to the OS once pipeline work has settled: VICTORY_DRIVER_TRIM (on; 0 off).

What

New self-contained crates/victory-gpu/src/drivercache.rs: walks the process's mapped files (VirtualQuery + K32GetMappedFileNameW), finds the driver's shader cache (NVIDIA DXCache\*.nvph etc., files >= 16 MiB), unlocks 64 MiB chunks (VirtualUnlock) so resident pages can be dropped, only after >= 5 s without a pipeline load/creation (pipeline::quiet_ms()), with a 30 s empty-walk back-off. Nothing found = safe no-op; hooked into the host's existing sweep next to pipeline::trim_library, and re-armed after pipeline activity.

Verification

  • cargo test -p victory-gpu --lib: 717 passed (5 new: path matcher/filtering/chunking/quiet floor, on temp files); normal and --features diagnostics builds compile.
  • cargo check -p victory, cargo xtask policy, clippy: clean.
  • Needs in-game: confirm the trim line appears after loading settles, free RAM rises, and no hitching from soft-faulting the cache back. Needs a driver that maps its cache (NVIDIA/AMD); on a machine without one it logs once and retries later.
  • Risk: VirtualUnlock on driver-owned cache pages is the documented way to let them go but only unofficially relied on; guarded by committed/mapped re-checks and the idle floor.

Source: Androtim/MiniVI c7d3102b (+499, new drivercache.rs).

**@⁠SovietBearz0r** on GitHub · 2026-12-05 12:40 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/111) `SovietBearz0r:minivi-drivercache-trim` → `main` · +457 −2 · 5 files · 1 commits · closed without merging Return mapped driver shader-cache pages to the OS once pipeline work has settled: `VICTORY_DRIVER_TRIM` (on; `0` off). ## What New self-contained `crates/victory-gpu/src/drivercache.rs`: walks the process's mapped files (`VirtualQuery` + `K32GetMappedFileNameW`), finds the driver's shader cache (NVIDIA `DXCache\*.nvph` etc., files >= 16 MiB), unlocks 64 MiB chunks (`VirtualUnlock`) so resident pages can be dropped, only after >= 5 s without a pipeline load/creation (`pipeline::quiet_ms()`), with a 30 s empty-walk back-off. Nothing found = safe no-op; hooked into the host's existing sweep next to `pipeline::trim_library`, and re-armed after pipeline activity. ## Verification - `cargo test -p victory-gpu --lib`: 717 passed (5 new: path matcher/filtering/chunking/quiet floor, on temp files); normal and `--features diagnostics` builds compile. - `cargo check -p victory`, `cargo xtask policy`, clippy: clean. - **Needs in-game**: confirm the trim line appears after loading settles, free RAM rises, and no hitching from soft-faulting the cache back. Needs a driver that maps its cache (NVIDIA/AMD); on a machine without one it logs once and retries later. - Risk: `VirtualUnlock` on driver-owned cache pages is the documented way to let them go but only unofficially relied on; guarded by committed/mapped re-checks and the idle floor. Source: Androtim/MiniVI `c7d3102b` (+499, new `drivercache.rs`).
Ported from MiniVI c7d3102b (new crates/victory-gpu/src/drivercache.rs,
454 lines; its host.rs/pipeline.rs/pipeline/library.rs hooks).

GPU drivers map multi-gigabyte shader cache files into the process
(NVIDIA's DXCache\*.nvph and the like) and keep gigabytes of their pages
resident after startup/menu compilation goes quiet. A low-priority
background worker now walks the committed MEM_MAPPED regions, keeps those
that are a driver cache file of at least 16 MiB, and VirtualUnlocks them
64 MiB at a time once no pipeline has loaded or been made for 5 s (or
longer under memory pressure, as the pipeline library's own trim waits);
the driver reads an unlocked page back from the file cache on a soft
fault. It is a no-op when nothing is found (with a 30 s cooldown before
another walk) and can be switched off with VICTORY_DRIVER_TRIM=0.

The quiet signal is new: pipeline/library.rs counts pipeline calls under
way and stamps the end of the last one (the library's own trim now
re-arms on creations too); pipeline.rs exposes it. VirtualUnlock is
guarded by a committed/mapped re-check and the regions are re-found if
the mapping moved. Path matching, filtering, chunking and the quiet floor
are pure tests; the scan itself needs a live process with a driver cache
mapped (no GPU work is done).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 12:44:44 +00:00
Author
Owner

@⁠ReTerryDavis on GitHub · 2026-12-05 17:37 UTC · original

Closing this one — VICTORY_DRIVER_TRIM is default-ON, untested in-game, and uses VirtualUnlock on GPU driver-owned shader-cache mappings (the same aggressive working-set trimming class recently reverted in 8746753):

  • TOCTOU race (drivercache.rs:261-300): found() validates committed_mapped once before unlocking, then iterates 64 MiB chunks with 1 ms sleeps without re-verifying the mapping/path. If the driver unmaps its cache and the VA range is reused, VirtualUnlock targets unrelated memory.
  • Calling VirtualUnlock on driver-owned memory can also silently break a driver's own VirtualLock if present, and filename heuristics (*.bin/*.db/*.cache) are brittle across drivers.
**@⁠ReTerryDavis** on GitHub · 2026-12-05 17:37 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/111#issuecomment-7442339924) Closing this one — `VICTORY_DRIVER_TRIM` is **default-ON**, untested in-game, and uses `VirtualUnlock` on GPU driver-owned shader-cache mappings (the same aggressive working-set trimming class recently reverted in `8746753`): - **TOCTOU race (`drivercache.rs:261-300`):** `found()` validates `committed_mapped` once before unlocking, then iterates 64 MiB chunks with 1 ms sleeps without re-verifying the mapping/path. If the driver unmaps its cache and the VA range is reused, `VirtualUnlock` targets unrelated memory. - Calling `VirtualUnlock` on driver-owned memory can also silently break a driver's own `VirtualLock` if present, and filename heuristics (`*.bin`/`*.db`/`*.cache`) are brittle across drivers.
github-bot closed this pull request 2026-12-05 17:43:23 +00:00
Author
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 18:27 UTC · original

Review addressed and resubmitted as #159 (I can't reopen this one: GitHub doesn't let the author reopen a PR closed by the maintainer). The new PR is rebased on current main and its body lists point-by-point what changed; closed this thread is fine, please use the new one.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 18:27 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/111#issuecomment-7443145402) Review addressed and resubmitted as #159 (I can't reopen this one: GitHub doesn't let the author reopen a PR closed by the maintainer). The new PR is rebased on current main and its body lists point-by-point what changed; closed this thread is fine, please use the new one.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.