xmem: keep tiny reservations per page; map_whole only for large runs #93
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/93"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by dutch2005 on 2026-11-25T13:51:04Z.
Why
Fixes issue #8. On Windows 11 / RDNA2, five
victory-hlexmem tests fail becausemap_wholetakes a tiny reservation (three 64 KiB pages) down the whole-reservation path. Unmapping the middle page then reportsMEM_COMMIT(4096) where the tests expectMEM_RESERVE(8192), and the address of the split placeholders differs.What
map_wholeonly makes a new whole view for reservations above 64 pages. The threshold stays in theknownmatch, so a later small call into a range already shown whole still goes to that view.checked_mul/checked_add.map_aliaswith no pages returns true before the whole-range check (#99, ySKELLETONX); a zero-length alias next to a reservation shown whole is a no-op..cargo/config.tomlsetsRUST_TEST_THREADS=1for the global xmem/GPU state.Review fixes (all on this branch)
os error 487~1 s in): the GPU heap is mapped in several calls, and a later 16-page call was refused after the first call showed the reservation whole. Their fix anda_small_run_into_a_reservation_shown_whole_is_mappedwere taken from fork PR #1 (commit by ySKELLETONX preserved).release_wholenow removes the bookkeeping, unmaps the view and releases the reservation.allocatedoc comment is back onallocate.Testing
On an RX 6700 XT, Windows 11, Rust 1.98.1:
cargo test -p victory-hle --lib xmem -- --test-threads=1— 16 passed, 0 failed.cargo test -p victory-hle --lib— full crate passes.pages.len() <= 64guard; manual mutation confirmed all 16 xmem tests still pass, so the guard is not observable in this test suite. It is retained because the title's multi-call heap mapping needs it, and the startup-crash regression test covers the other side.Independent confirmation: RX 6950 XT (MamaLeVrai) 103 passed, 0 failed, 3/3 runs; RX 7600 XT (ySKELLETONX) fixes #91 and reports 0 failures in 40 parallel runs with the startup fix.
Risk
Tiny reservations no longer make a new in-place whole view; the large GPU heap mappings still do. A title run on the RX 9070 XT with the startup fix would confirm the crash is gone; jmal423 was asked in the review thread.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-25T14:01:18Z.
Tested on the machine of issue #8 and #2 (RX 6950 XT, Windows 11 build 26300, Rust 1.98.1): this PR merged on
main71652a2(head68d437d, no conflict),cargo test --release -p victory-hle --lib, 3 runs.main71652a2The six new tests are in the 103.
victory-shaderis not touched by the PR and still has its 2 failures (see #92). Not run in the game.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T14:03:16Z.
Tested on an RX 7600 XT 16 GB (RDNA3), Windows 11 Pro build 26300, Rust 1.98.1, at
68d437d. It fixes the 5 xmem failures I reported in #91, and the fullvictory-hlecrate passes (103 passed, 1 ignored).One problem: with the default parallel runner,
mapping_no_pages_changes_nothingfails in about 9 of 40 runs ofcargo test -p victory-hle --lib xmem, atassert!(map_alias(at as u64, a as u64, 0)). It never fails with--test-threads=1or with--skip a_large_run_of_pages_is_shown_whole.The cause: the new test leaves a 65-page reservation shown whole. When it lands directly after the other test's 2-page reservation,
map_alias(a + 2 * PAGE, a, 0)is refused becausein_wholeis true for an empty range at the start of a whole range. #99 makesmap_aliaswithlen == 0return true up front. With #99 on top of this PR: 0 failures in 60 parallel runs. You can also take the 4 lines into this PR, whichever you prefer.Small nit: the new test was inserted between
/// \n` pages of one new allocation.andfn allocate, so that doc comment is now attached toa_large_run_of_pages_is_shown_whole`.Imported from Belobug/VIctory-Belobug-AMD. Originally posted by jmal423 on 2026-11-25T14:34:44Z.
Tested this PR on Windows 11 / AMD Radeon RX 9070 XT (on top of
01aadd1+#39, Series X target):The title crashes ~1s after launch with
os error 487(Attempt to access invalid address) insidexmem:Dropping
#93(keeping#39) resolves the startup crash.Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T14:37:56Z.
@jmal423's crash comes from the threshold:
pages.len() <= 64returns beforemap_wholechecks for a whole view that already covers the range. The title maps the GPU heap in several calls. After the first one shows the reservation whole, the 16-page call at0xa10000is refused, goes to the per-page path, and fails with error 487 because the whole view replaced the placeholders there.Fix and regression test (70 of 80 pages mapped whole, then the last 10): dutch2005/VIctory-Belobug-AMD#1, against this PR's branch. The test fails at
0cbedb9with the same null return and passes with the fix.victory-hle: 104 passed. xmem: 0 failures in 40 parallel runs. The threshold now applies only when a run would make a new whole view, so the #8 tests keep the per-page path.@jmal423, if you can run the title with that branch on the 9070 XT, that would confirm it.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T14:49:44Z.
Review: COMMENTED
AI-assisted review: I checked the cleanup behavior in XMemFreePhysicalPages.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T14:49:44Z.
Code review location:
crates/victory-hle/src/modules/xmem.rs; line 1467Could this test unmap the whole view and release reservation before freeing the pages? XMemFreePhysicalPages only removes the page-table entries; it leaves the mapped view in physical.views/physical.whole and the virtual reservation allocated. That leaks xmem state and address space into later tests, especially when the suite runs in parallel. AI-assisted review.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T15:31:04Z.
Review: COMMENTED
AI-assisted review: I compared the updated Cargo config with the repository's documented contributor commands.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-25T15:31:04Z.
Code review location:
.cargo/config.toml; line 4Could this keep the existing xtask alias alongside the test-thread setting? Replacing the [alias] table removes cargo xtask, which the README's policy check and install-hooks instructions rely on. AI-assisted review; I checked the current Cargo config against those README commands.
Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-25T15:57:46Z.
On gut0to's
.cargo/config.tomlcomment: confirmed here. At30132fc,cargo xtask policyfails withno such command: xtask, so the pre-commit hook (cargo xtask policy --staged) refuses every commit. dutch2005/VIctory-Belobug-AMD#2 puts the alias back beside[env]. With this PR's test mutex,victory-hlehad 0 failures in 30 runs at--test-threads=16, so the workspace-wideRUST_TEST_THREADS=1may not be needed (details in that PR).Imported from Belobug/VIctory-Belobug-AMD. Originally posted by dutch2005 on 2026-11-25T15:57:52Z.
Updated
fix/xmem-whole-thresholdfollowing @gut0to and @ySKELLETONX's reviews:XMemMapPhysicalPagescalls inside a reservation already shown whole (f3c7be2, fixing @jmal423's RX 9070 XT startup crash) plusmap_alias(..., 0)early-out.[alias] xtask = "run --quiet --package xtask --"alongside[env] RUST_TEST_THREADS = "1"in.cargo/config.toml(@gut0to).release_whole(unmaps the whole view and releases the reservation before freeing pages, with// SAFETY:comment) and serialized whole-view tests viaWHOLE_TEST.Verification (after final edit)
cargo test -p victory-hle --lib --locked: 104 passed, 0 failed, 1 ignoredcargo xtask policy --staged: 2 files okcargo mutants --in-diff(victory-hle,modules::xmem::tests): 7 caught, 1 documented non-observable missed (xmem.rs:720pages.len() <= 64guard — as noted indocs/mutation-testing.md, unit tests use the shared physical pool unless isolated to a fresh section; kept for title multi-call GPU heap mappings)Pull request closed