hle: track title working-set memory, bound xasync threads, and map XUser devices #687

Open
github-bot wants to merge 2 commits from github-bot/gh-687 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-24 06:54 UTC · original
wbkepler:hle/working-set-and-runtime-fixes → main · +699 −62 · 3 files · 2 commits · open

Summary

  • xmem.rs (XMemGetWorkingSetStatistics):
    • Tracks title-owned memory separately from host allocations (heap via XMemAllocDefault/XMemFreeDefault, non-placeholder committed XMemVirtualAlloc regions via VirtualQueryEx, and physical pages with GPU-optimal breakdown) so host D3D12 mirrors and shader compiler RAM do not trigger premature title asset eviction/OOM.
  • xasync.rs:
    • Replaces per-callback delayed-task OS thread spawning with a single lazily started shared timer thread (BinaryHeap<Reverse<DelayedTask>> + Condvar) and bounds the POOL worker count.
  • xuser.rs (XUserFindUserByLocalId / find_for_device):
    • Maps non-null, non-zero 32-byte APP_LOCAL_DEVICE_ID handles to the offline local user, returning USER_NOT_FOUND for all-zero IDs and E_INVALIDARG for null pointers.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (including 4 new unit tests in xmem/xasync/xuser)
  • cargo xtask policy — passed (151 files ok)
**@⁠wbkepler** on GitHub · 2026-11-24 06:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/687) `wbkepler:hle/working-set-and-runtime-fixes` → `main` · +699 −62 · 3 files · 2 commits · open ## Summary - **`xmem.rs` (`XMemGetWorkingSetStatistics`)**: - Tracks title-owned memory separately from host allocations (heap via `XMemAllocDefault`/`XMemFreeDefault`, non-placeholder committed `XMemVirtualAlloc` regions via `VirtualQueryEx`, and physical pages with GPU-optimal breakdown) so host D3D12 mirrors and shader compiler RAM do not trigger premature title asset eviction/OOM. - **`xasync.rs`**: - Replaces per-callback delayed-task OS thread spawning with a single lazily started shared timer thread (`BinaryHeap<Reverse<DelayedTask>>` + `Condvar`) and bounds the `POOL` worker count. - **`xuser.rs` (`XUserFindUserByLocalId` / `find_for_device`)**: - Maps non-null, non-zero 32-byte `APP_LOCAL_DEVICE_ID` handles to the offline local user, returning `USER_NOT_FOUND` for all-zero IDs and `E_INVALIDARG` for null pointers. ## Verification - `cargo clippy --workspace --all-targets` — passed (zero new warnings) - `cargo clippy -p victory --features diagnostics --all-targets` — passed - `cargo test --workspace` — passed (including 4 new unit tests in `xmem`/`xasync`/`xuser`) - `cargo xtask policy` — passed (151 files ok)
- `xmem`: track title-owned allocations (`XMemAllocDefault`, committed pages
  inside `XMemVirtualAlloc` reservations, and `XMemAllocatePhysicalPages`)
  split across total and GPU-optimal budgets in `XMemGetWorkingSetStatistics`
  instead of reporting host `PagefileUsage` (which includes host GPU mirrors
  and shader compiler memory).
- `xasync`: serve delayed `XTaskQueue` callbacks from one lazily started shared
  timer thread backed by a min-heap + condvar instead of spawning a new OS
  thread per delayed submission, and cap `POOL` worker growth to a bounded
  limit (`(available_parallelism * 2).clamp(8, 64)`).
- `xuser`: return the single signed-in offline local user from
  `XUserFindForDevice` (`find_for_device`) for valid non-zero
  `APP_LOCAL_DEVICE_ID` values, `USER_NOT_FOUND` for all-zero IDs, and
  `E_INVALIDARG` for null pointers.

Adds 4 unit tests covering working-set tracking (and host memory exclusion),
shared-timer deadline ordering, bounded thread-pool burst execution, and
device-to-user lookup.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:13:04 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 09:42 UTC · original

Independent verification of b7d3263d1 merged with main (8e79c80, clean merge) on Windows 11 Pro (26100), Rust 1.98.1 (x86_64-pc-windows-msvc): PASS (with two small edge-case notes below).

Verification

  • cargo xtask policy → asset policy: 153 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings → pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings → pass (0 warnings)
  • cargo test -p victory-hle --locked → 98 passed + 1 integration test (no_dll_planting), 0 failed (all 4 new tests in xmem, xasync, and xuser pass)
  • Full cargo test --workspace --locked passed (frame::tests::waits_end_on_ticks_and_count_frames hit the known CPU-load timing flake once under concurrent compilation and passed in 0.03s on re-run).

Code-review notes

  1. Stale-region address reuse in xmem.rs (XMemVirtualAlloc, already_tracked): if a previously tracked reservation [rbase, rbase + rlen) is freed via VirtualFree and a subsequent XMemVirtualAlloc lands at a sub-address inside [rbase, rbase + rlen) before XMemGetWorkingSetStatistics runs to prune stale entries, already_tracked matches the stale range without checking mbi.AllocationBase == rbase and skips record_virtual_region. When virtual_used() later runs and sees mbi.AllocationBase != rbase, the stale entry is pruned and the new allocation is never tracked. Checking VirtualQueryEx's AllocationBase (or only skipping when base is non-null, i.e., a commit inside an existing reservation) avoids that gap.
  2. Delayed callbacks on terminated queues (xasync.rs, Timer::run): when item.queue.terminated is set before due, Timer::run skips deliver and drops item.task once due expires rather than running it with canceled = true (and retains Arc<Queue> in TIMER.heap until due).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 09:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/687#issuecomment-7127788322) Independent verification of `b7d3263d1` merged with `main` (`8e79c80`, clean merge) on Windows 11 Pro (`26100`), Rust `1.98.1` (`x86_64-pc-windows-msvc`): **PASS** (with two small edge-case notes below). ### Verification - `cargo xtask policy` → `asset policy: 153 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings` → **pass** (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` → **pass** (0 warnings) - `cargo test -p victory-hle --locked` → **98 passed + 1 integration test (`no_dll_planting`), 0 failed** (all 4 new tests in `xmem`, `xasync`, and `xuser` pass) - Full `cargo test --workspace --locked` passed (`frame::tests::waits_end_on_ticks_and_count_frames` hit the known CPU-load timing flake once under concurrent compilation and passed in `0.03s` on re-run). ### Code-review notes 1. **Stale-region address reuse in `xmem.rs` (`XMemVirtualAlloc`, `already_tracked`)**: if a previously tracked reservation `[rbase, rbase + rlen)` is freed via `VirtualFree` and a subsequent `XMemVirtualAlloc` lands at a sub-address inside `[rbase, rbase + rlen)` *before* `XMemGetWorkingSetStatistics` runs to prune stale entries, `already_tracked` matches the stale range without checking `mbi.AllocationBase == rbase` and skips `record_virtual_region`. When `virtual_used()` later runs and sees `mbi.AllocationBase != rbase`, the stale entry is pruned and the new allocation is never tracked. Checking `VirtualQueryEx`'s `AllocationBase` (or only skipping when `base` is non-null, i.e., a commit inside an existing reservation) avoids that gap. 2. **Delayed callbacks on terminated queues (`xasync.rs`, `Timer::run`)**: when `item.queue.terminated` is set before `due`, `Timer::run` skips `deliver` and drops `item.task` once `due` expires rather than running it with `canceled = true` (and retains `Arc<Queue>` in `TIMER.heap` until `due`). AI-assisted; synthetic tests only, no game files.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:34 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/src/modules/xasync.rs, crates/victory-hle/src/modules/xmem.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/687#issuecomment-7148660439) <!-- victory-triage v1 head=73eba29bfaea2def15cb270711389bf80f464247 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-hle/src/modules/xasync.rs`, `crates/victory-hle/src/modules/xmem.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/xasync.rs
  • crates/victory-hle/src/modules/xmem.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/687/head:github-bot/gh-687'
git switch 'github-bot/gh-687'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-687'
git switch 'github-bot/gh-687'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-687'
git switch 'github-bot/gh-687'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-687'
git switch 'main'
git merge --squash 'github-bot/gh-687'
git switch 'main'
git merge --ff-only 'github-bot/gh-687'
git switch 'main'
git merge 'github-bot/gh-687'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!687
No description provided.