xmem: keep tiny reservations per page; map_whole only for large runs #93
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!93
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/93/head"
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?
@dutch2005 on GitHub · 2026-11-25 13:51 UTC · original
fix/xmem-whole-threshold→main· +138 −1 · 2 files · 6 commits · closed without mergingWhy
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.
@MamaLeVrai on GitHub · 2026-11-25 14:01 UTC · original
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.
@ySKELLETONX on GitHub · 2026-11-25 14:03 UTC · original
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`.@jmal423 on GitHub · 2026-11-25 14:34 UTC · original
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.@ySKELLETONX on GitHub · 2026-11-25 14:37 UTC · original
@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.
@ySKELLETONX on GitHub · 2026-11-25 15:57 UTC · original
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).@dutch2005 on GitHub · 2026-11-25 15:57 UTC · original
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)@ -1406,0 +1506,4 @@assert_eq!(rest.cast::<u8>().read(), 9);}release_whole(reservation, N * PAGE);assert_eq!(XMemFreePhysicalPages(N, pages.as_ptr()), 1);@gut0to on GitHub · 2026-11-25 14:49 UTC · original
Could 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.
@ -3,0 +4,4 @@# The xmem page pool and the GPU differential tests are global state shared# between tests. Run test binaries with one thread by default, as the hardware# runs already do; `--test-threads` on the command line still wins.[env]@gut0to on GitHub · 2026-11-25 15:31 UTC · original
Could 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.
@gut0to on GitHub · 2026-11-25 14:49 UTC · original · reviewed
AI-assisted review: I checked the cleanup behavior in XMemFreePhysicalPages.
@gut0to on GitHub · 2026-11-25 15:31 UTC · original · reviewed
AI-assisted review: I compared the updated Cargo config with the repository's documented contributor commands.
Pull request closed