XMem tests: the range-lock read test runs alone against the tests that copy mappings (9 in 10 runs failed) #2439

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

@⁠boraswim on GitHub · 2026-11-29 13:03 UTC · original
boraswim:fix/flaky-tests → main · +19 −0 · 1 files · 2 commits · open

Part of #2420 (item 2).

What it changes

modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it asserts that a read apart from the remapped view is never refused (refused == 0). But map_aliases takes victory_gpu::title_memory_remapping(), which covers all of title memory whatever VICTORY_RANGE_LOCK says (map_aliases_by_page). So any test that copies mappings on another thread of the same test process refuses that read, thousands of times per run (left: 5861, right: 0). That is the lock doing its job, not the range lock failing.

Measured on Windows with cargo test -p victory-hle --lib, repeated:

  • main: the test failed 9 times in 10 (7 in 10 with VICTORY_RANGE_LOCK=1 set beforehand, so it is not the switch being read late).
  • Run as a pair with each of the other 46 xmem tests, only a_scatter_of_many_pages_is_what_one_after_the_other_is makes it fail (3 of 3). That test calls map_aliases with 200 pages.

The change is test-only. The five tests that call map_aliases hold a static WHOLE: RwLock<()> shared, so they still run alongside each other, and the range test holds it alone. This is the same approach #724 took for the watch tests.

How it was tested

  • GPU and profile: none needed, unit tests only (Windows 11, rustc 1.98.1, x86_64-pc-windows-msvc, RTX 4070 SUPER)
  • Before: 9 failures of the test in 10 runs of cargo test -p victory-hle --lib --locked
  • After: 0 failures of the test in 12 runs
  • For shader changes, the wave sizes tested: not a shader change
  • cargo test passed for the crates it touches: yes for this test. victory-hle still has one rarer flake (below).

Still flaky, not touched here (also listed in #2420):

  • xmem::tests::large_default_allocations_honour_write_watch_switch: 1 to 2 failures in 10 runs. After XMemFreeDefault it checks that the reservation's base is MEM_FREE, but a test on another thread can reserve the freed range first, since title memory goes lowest address first (left: 8192 = MEM_RESERVE). Making that check safe needs either a different check or a lock around every allocating test, which is a bigger change than this one.
  • victory-gpu, each 1 to 2 failures in 8 runs: card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end, card_steps::tests::places_written_after_sending_are_learned, uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue, menu::tests::a_change_is_saved_at_once_however_the_game_was_started, watch::many_askers_tests::no_mapping_is_lost_between_askers.

CI's clippy step will stay red on this PR until main's clippy errors are fixed (#2048). Nothing here adds a lint.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2420 (the issue), #724 (same approach for the watch tests). Open PRs touching xmem.rs (#2133, #2263, #2390) change runtime code, not these tests.
**@⁠boraswim** on GitHub · 2026-11-29 13:03 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439) `boraswim:fix/flaky-tests` → `main` · +19 −0 · 1 files · 2 commits · open Part of #2420 (item 2). ## What it changes `modules::xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it` asserts that a read apart from the remapped view is never refused (`refused == 0`). But `map_aliases` takes `victory_gpu::title_memory_remapping()`, which covers all of title memory whatever `VICTORY_RANGE_LOCK` says (`map_aliases_by_page`). So any test that copies mappings on another thread of the same test process refuses that read, thousands of times per run (`left: 5861, right: 0`). That is the lock doing its job, not the range lock failing. Measured on Windows with `cargo test -p victory-hle --lib`, repeated: - main: the test failed 9 times in 10 (7 in 10 with `VICTORY_RANGE_LOCK=1` set beforehand, so it is not the switch being read late). - Run as a pair with each of the other 46 xmem tests, only `a_scatter_of_many_pages_is_what_one_after_the_other_is` makes it fail (3 of 3). That test calls `map_aliases` with 200 pages. The change is test-only. The five tests that call `map_aliases` hold a `static WHOLE: RwLock<()>` shared, so they still run alongside each other, and the range test holds it alone. This is the same approach #724 took for the watch tests. ## How it was tested - GPU and profile: none needed, unit tests only (Windows 11, rustc 1.98.1, x86_64-pc-windows-msvc, RTX 4070 SUPER) - Before: 9 failures of the test in 10 runs of `cargo test -p victory-hle --lib --locked` - After: 0 failures of the test in 12 runs - For shader changes, the wave sizes tested: not a shader change - `cargo test` passed for the crates it touches: yes for this test. `victory-hle` still has one rarer flake (below). Still flaky, not touched here (also listed in #2420): - `xmem::tests::large_default_allocations_honour_write_watch_switch`: 1 to 2 failures in 10 runs. After `XMemFreeDefault` it checks that the reservation's base is `MEM_FREE`, but a test on another thread can reserve the freed range first, since title memory goes lowest address first (`left: 8192` = `MEM_RESERVE`). Making that check safe needs either a different check or a lock around every allocating test, which is a bigger change than this one. - `victory-gpu`, each 1 to 2 failures in 8 runs: `card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end`, `card_steps::tests::places_written_after_sending_are_learned`, `uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue`, `menu::tests::a_change_is_saved_at_once_however_the_game_was_started`, `watch::many_askers_tests::no_mapping_is_lost_between_askers`. CI's clippy step will stay red on this PR until main's clippy errors are fixed (#2048). Nothing here adds a lint. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2420 (the issue), #724 (same approach for the watch tests). Open PRs touching `xmem.rs` (#2133, #2263, #2390) change runtime code, not these tests.
a_read_by_range_waits_only_for_a_remapping_that_meets_it asserts that a
read apart from the remapped view is never refused. map_aliases takes
title_memory_remapping for all of title memory, whatever
VICTORY_RANGE_LOCK says, so any test copying mappings on another thread
of the same test process refused that read thousands of times: the test
failed in 9 of 10 runs of `cargo test -p victory-hle --lib` on Windows
(paired with a_scatter_of_many_pages_is_what_one_after_the_other_is
alone: 3 of 3). The five tests that call map_aliases now hold a test-only
RwLock shared and the range test holds it alone, as the watch tests do
since #724. 0 failures in 12 runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 13:06:12 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-29 13:26 UTC · original · approved these changes

Tested locally merged onto main (829188e9).

  • Merge: Clean 19-line merge in crates/victory-hle/src/modules/xmem.rs.
  • Tests: cargo test -p victory-hle --lib xmem passed twice in a row under default parallel execution (46 passed; 0 failed; 1 ignored each run, including a_read_by_range_waits_only_for_a_remapping_that_meets_it) with 0 warnings in victory-hle.

Clean test synchronization fix eliminating the parallel xmem test flake. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-29 13:26 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#pullrequestreview-6103070461) · **approved these changes** Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean 19-line merge in `crates/victory-hle/src/modules/xmem.rs`. - **Tests**: `cargo test -p victory-hle --lib xmem` passed **twice in a row under default parallel execution** (`46 passed; 0 failed; 1 ignored` each run, including `a_read_by_range_waits_only_for_a_remapping_that_meets_it`) with 0 warnings in `victory-hle`. Clean test synchronization fix eliminating the parallel `xmem` test flake. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
views_in_the_books_alone_are_read_from_their_pages and
a_copy_of_consecutive_pages_shows_them_through_one_view copy one range at
a time (alias_as, map_alias), which goes through remapping_and_views and
locks only its own range; only map_aliases' batched preflight takes the
remap lock for all of title memory. The guard's comment now names that
lock. xmem tests: 0 failures in 10 runs.
Author
Owner

@⁠fainty0 on GitHub · 2026-11-29 14:45 UTC · original · approved these changes

Approve, with non-blocking coverage notes

Root cause. This is real contention on process-wide mapping state, not a failure to exclude an overlapping reader. The 200-page scatter test calls map_aliases (xmem.rs:5059). The aligned batched path takes title_memory_remapping() before PHYSICAL (xmem.rs:2110–2148), which takes MAPPING and publishes ALL in RANGES (watch.rs:3398, 3414, 3598–3622). RangeLock publishes the writer's ranges before draining overlapping readers, so the unrelated reader correctly receives None (rangelock.rs:41–46, 83–121), and the assertion counts that expected refusal as a failure (xmem.rs:4945–4947, 4975).

Review. WHOLE isolates the unrelated batched writers without serialising the range test's own readers and writer (xmem.rs:3770–3781, 4922–4975). All three unit tests that can take the batched preflight are covered (xmem.rs:4372, 5035, 5101). The guards at xmem.rs:4498 and 4636 are conservative, since those cases only use range-aware alias_as / map_alias (xmem.rs:1921–1940). Consider narrowing the guard to the batched cases and describing the lock, not the preflight, as whole-address. Test-only; style fits.

Coverage follow-up. The loop reuses the already-mapped page list (xmem.rs:4932, 4969–4971), and the fast path returns after taking the lock (xmem.rs:1759–1762, 1816–1832), so it need not exercise a real unmap/recommit gap. Alternate the two pages and coordinate worker startup. Pre-existing: the process-wide switch has a first-use race (watch.rs:3418–3444).

Windows Clippy (829188e → 3978372): no new diagnostics (default 5 → 5, all-features 4 → 4; HLE-only 3 → 3). Windows XMem repro not run independently.

**@⁠fainty0** on GitHub · 2026-11-29 14:45 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#pullrequestreview-6103364184) · **approved these changes** ## Approve, with non-blocking coverage notes **Root cause.** This is real contention on process-wide mapping state, not a failure to exclude an overlapping reader. The 200-page scatter test calls `map_aliases` (xmem.rs:5059). The aligned batched path takes `title_memory_remapping()` before `PHYSICAL` (xmem.rs:2110–2148), which takes `MAPPING` and publishes `ALL` in `RANGES` (watch.rs:3398, 3414, 3598–3622). `RangeLock` publishes the writer's ranges before draining overlapping readers, so the unrelated reader correctly receives `None` (rangelock.rs:41–46, 83–121), and the assertion counts that expected refusal as a failure (xmem.rs:4945–4947, 4975). **Review.** `WHOLE` isolates the unrelated batched writers without serialising the range test's own readers and writer (xmem.rs:3770–3781, 4922–4975). All three unit tests that can take the batched preflight are covered (xmem.rs:4372, 5035, 5101). The guards at xmem.rs:4498 and 4636 are conservative, since those cases only use range-aware `alias_as` / `map_alias` (xmem.rs:1921–1940). Consider narrowing the guard to the batched cases and describing the lock, not the preflight, as whole-address. Test-only; style fits. **Coverage follow-up.** The loop reuses the already-mapped page list (xmem.rs:4932, 4969–4971), and the fast path returns after taking the lock (xmem.rs:1759–1762, 1816–1832), so it need not exercise a real unmap/recommit gap. Alternate the two pages and coordinate worker startup. Pre-existing: the process-wide switch has a first-use race (watch.rs:3418–3444). **Windows Clippy (829188e → 3978372):** no new diagnostics (default 5 → 5, all-features 4 → 4; HLE-only 3 → 3). Windows XMem repro not run independently.
Author
Owner

@⁠boraswim on GitHub · 2026-11-29 14:48 UTC · original

Thanks, all checked against the code.

  • Narrowing: right. views_in_the_books_alone_are_read_from_their_pages and a_copy_of_consecutive_pages_shows_them_through_one_view only reach alias_as / map_alias, which go through remapping_and_views and lock their own range. Their guards are gone, and the comment now describes the lock (title_memory_remapping held by map_aliases' batched preflight), not the preflight. xmem tests: 0 failures in 10 parallel runs on Windows.
  • Coverage: agreed that remapping the same page list mostly takes the fast path, so the test proves "never refused" more than "never meets the gap". Alternating two page sets with the same bytes, and a barrier so both readers are running before the first remap, is a separate change from this flake fix, so I'll pick it up as a follow-up rather than widen this PR.
  • The switch's first-use race: noted. This test sets the switch explicitly, so it isn't affected here, but I'll mention it in #2420.
**@⁠boraswim** on GitHub · 2026-11-29 14:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#issuecomment-7257585495) Thanks, all checked against the code. - **Narrowing:** right. `views_in_the_books_alone_are_read_from_their_pages` and `a_copy_of_consecutive_pages_shows_them_through_one_view` only reach `alias_as` / `map_alias`, which go through `remapping_and_views` and lock their own range. Their guards are gone, and the comment now describes the lock (`title_memory_remapping` held by `map_aliases`' batched preflight), not the preflight. xmem tests: 0 failures in 10 parallel runs on Windows. - **Coverage:** agreed that remapping the same page list mostly takes the fast path, so the test proves "never refused" more than "never meets the gap". Alternating two page sets with the same bytes, and a barrier so both readers are running before the first remap, is a separate change from this flake fix, so I'll pick it up as a follow-up rather than widen this PR. - **The switch's first-use race:** noted. This test sets the switch explicitly, so it isn't affected here, but I'll mention it in #2420.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-12-01 00:15 UTC · original

Four fresh Windows check jobs on PRs based on 7d93ee07 hit the exact assertion this addresses. Each reported "a read apart from the remapping had to wait" with a nonzero count:

**@⁠tyr0nsur** on GitHub · 2026-12-01 00:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#issuecomment-7296129276) Four fresh Windows `check` jobs on PRs based on `7d93ee07` hit the exact assertion this addresses. Each reported "a read apart from the remapping had to wait" with a nonzero count: - #3766: [4303](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46541552647/job/142281239634) - #4435: [3588](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46540898234/job/142278969847) - #4589: [4064](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46540897866/job/142278968626) - #4595: [3778](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46540896471/job/142278964313)
Author
Owner

@⁠tyr0nsur on GitHub · 2026-12-01 01:02 UTC · original

I independently reran the XMem test on current main 7d93ee07 and the same tree with #2439 at 3090dbb3 applied. The merge changes only xmem.rs. Windows 11 / Ryzen 7 5800X, Rust 1.98.1, test executables built by cargo test --locked -p victory-hle --lib --no-run, default range-lock environment.

Run Main failures of the range-lock test With #2439
Range-lock test alone (one harness thread) 0/4 0/4
Exact pair with a_scatter_of_many_pages_is_what_one_after_the_other_is (two threads) 12/12 0/12
Full lib suite (default parallelism) 7/8 0/8

Runs alternated the binaries and swapped which one ran first each round. The failed pair runs all hit a read apart from the remapping had to wait with 3,061–4,174 refusals. The five doc, input, and diagnostics PR jobs now hitting this assertion make the same test failure visible in CI.

**@⁠tyr0nsur** on GitHub · 2026-12-01 01:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#issuecomment-7297012687) I independently reran the XMem test on current main `7d93ee07` and the same tree with #2439 at `3090dbb3` applied. The merge changes only `xmem.rs`. Windows 11 / Ryzen 7 5800X, Rust 1.98.1, test executables built by `cargo test --locked -p victory-hle --lib --no-run`, default range-lock environment. | Run | Main failures of the range-lock test | With #2439 | | --- | ---: | ---: | | Range-lock test alone (one harness thread) | 0/4 | 0/4 | | Exact pair with `a_scatter_of_many_pages_is_what_one_after_the_other_is` (two threads) | 12/12 | 0/12 | | Full lib suite (default parallelism) | 7/8 | 0/8 | Runs alternated the binaries and swapped which one ran first each round. The failed pair runs all hit `a read apart from the remapping had to wait` with 3,061–4,174 refusals. The five doc, input, and diagnostics PR jobs now hitting this assertion make the same test failure visible in CI.
Author
Owner

@⁠OGShotz on GitHub · 2026-12-01 13:02 UTC · original

Tested on current main 5fabb46e and the same tree with this PR (3090dbb3) merged. Windows 11, Ryzen 7 3700X, Rust 1.98.1; test executables built with cargo test --locked -p victory-hle --lib --no-run, default range-lock environment, run with the filter modules::xmem::.

  • main: a_read_by_range_waits_only_for_a_remapping_that_meets_it failed in 10 of 10 runs.
  • with this PR: it failed in 2 of 30 runs (1 of 10, then 1 of 20). The full --lib run passed 3 of 3.

So it is a large improvement but not quite all of it on current main. The remaining failure is the same assertion with a much smaller count:

assertion `left == right` failed: a read apart from the remapping had to wait
left: 379

On current main, every test that calls map_aliases already holds WHOLE with this PR applied (batched_copies_that_cannot_be_served_change_nothing, a_scatter_of_many_pages_is_what_one_after_the_other_is, a_batched_copy_with_an_unknown_source_leaves_every_destination_it_showed), so the remaining refusals seem to come from another test that takes the whole-title remap lock some other way. The last test that finished before the failure in the captured run was a_reader_in_place_faults_into_a_lazy_view_while_a_mapping_waits, which may be worth checking.

**@⁠OGShotz** on GitHub · 2026-12-01 13:02 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#issuecomment-7312004942) Tested on current main `5fabb46e` and the same tree with this PR (`3090dbb3`) merged. Windows 11, Ryzen 7 3700X, Rust 1.98.1; test executables built with `cargo test --locked -p victory-hle --lib --no-run`, default range-lock environment, run with the filter `modules::xmem::`. - main: `a_read_by_range_waits_only_for_a_remapping_that_meets_it` failed in 10 of 10 runs. - with this PR: it failed in 2 of 30 runs (1 of 10, then 1 of 20). The full `--lib` run passed 3 of 3. So it is a large improvement but not quite all of it on current main. The remaining failure is the same assertion with a much smaller count: ``` assertion `left == right` failed: a read apart from the remapping had to wait left: 379 ``` On current main, every test that calls `map_aliases` already holds `WHOLE` with this PR applied (`batched_copies_that_cannot_be_served_change_nothing`, `a_scatter_of_many_pages_is_what_one_after_the_other_is`, `a_batched_copy_with_an_unknown_source_leaves_every_destination_it_showed`), so the remaining refusals seem to come from another test that takes the whole-title remap lock some other way. The last test that finished before the failure in the captured run was `a_reader_in_place_faults_into_a_lazy_view_while_a_mapping_waits`, which may be worth checking.
Author
Owner

@⁠Tan7rex on GitHub · 2026-12-01 14:37 UTC · original

Tested on Windows 11 Pro (build 26100), RTX 4090, with this PR's change applied onto current main (5fabb46e; the branch itself is 589 commits behind, and the patch applies cleanly). Test binary built with cargo test --release --locked --no-run -p victory-hle --lib, then run repeatedly; counts are runs in which a_read_by_range_waits_only_for_a_remapping_that_meets_it failed.

How it was run main 5fabb46e main + this PR
whole lib (victory_hle-*.exe, default threads), 100 runs 92 failed 2 failed
modules::xmem:: only, 100 runs 100 failed 25 failed
the test alone, 50 runs not run 0 failed

Every failure with the PR is the same assertion as before (a read apart from the remapping had to wait).

So the PR helps a lot but does not fully fix the test on current main. Paired with each of the other 50 modules::xmem:: tests one at a time (15 runs per pair), it never failed. It fails with about 25 or more of them at once, and bisecting below that lost it. That suggests load or several tests together, not one more test missing the WHOLE guard. I didn't find the cause.

One more thing seen, not proven to be caused by the PR: in the 100 whole-lib runs, large_default_allocations_honour_write_watch_switch failed 2 times with the PR and 0 times on main.

Not tested: the game (the change is test-only).

**@⁠Tan7rex** on GitHub · 2026-12-01 14:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2439#issuecomment-7314551604) Tested on Windows 11 Pro (build 26100), RTX 4090, with this PR's change applied onto current `main` (5fabb46e; the branch itself is 589 commits behind, and the patch applies cleanly). Test binary built with `cargo test --release --locked --no-run -p victory-hle --lib`, then run repeatedly; counts are runs in which `a_read_by_range_waits_only_for_a_remapping_that_meets_it` failed. | How it was run | `main` 5fabb46e | `main` + this PR | |---|---|---| | whole lib (`victory_hle-*.exe`, default threads), 100 runs | 92 failed | 2 failed | | `modules::xmem::` only, 100 runs | 100 failed | 25 failed | | the test alone, 50 runs | not run | 0 failed | Every failure with the PR is the same assertion as before (`a read apart from the remapping had to wait`). So the PR helps a lot but does not fully fix the test on current `main`. Paired with each of the other 50 `modules::xmem::` tests one at a time (15 runs per pair), it never failed. It fails with about 25 or more of them at once, and bisecting below that lost it. That suggests load or several tests together, not one more test missing the `WHOLE` guard. I didn't find the cause. One more thing seen, not proven to be caused by the PR: in the 100 whole-lib runs, `large_default_allocations_honour_write_watch_switch` failed 2 times with the PR and 0 times on `main`. Not tested: the game (the change is test-only).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2439'
git switch 'github-bot/gh-2439'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2439'
git switch 'github-bot/gh-2439'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2439'
git switch 'main'
git merge --squash 'github-bot/gh-2439'
git switch 'main'
git merge --ff-only 'github-bot/gh-2439'
git switch 'main'
git merge 'github-bot/gh-2439'
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/trustno1-coder--VIctory-NVIDIA!2439
No description provided.