victory-hle: stabilise the title-thread xmem test #109

Manually merged
github merged 2 commits from github-bot/gh-109 into gh-pr/109/base 2026-12-01 14:29:52 +00:00 AGit
Owner

@⁠TheRifai on GitHub · 2026-12-01 14:20 UTC · original
TheRifai:fix-xmem-flaky → main · +7 −1 · 1 files · 2 commits · merged 2026-12-01 14:29 UTC

What

The xmem test a_title_thread_goes_on_using_the_rest_of_a_view was flaky (docs/TASKS.md “Failing and flaky tests”). Two test-only changes: an explicit start signal so the main thread cannot set stop before the title thread begins, and a counter assertion that tolerates a momentarily older value exposed by remapping the view's other pages while still requiring that the value never runs ahead and that the thread makes progress. The test's purpose — the title thread keeps using its page without faulting — is unchanged.

The reference

No console counterpart: this stabilises our own test, not runtime behaviour.

Evidence

  • 12/12 consecutive cargo xwin test -p victory-hle --target x86_64-pc-windows-msvc --features diagnostics --locked a_title_thread_goes_on_using_the_rest_of_a_view runs under Proton-GE11-16 passed (the earlier exact-equality version failed 1 in 10 with a stale read).

Checklist (docs/AGENTS.md)

  • One topic; docs/TASKS.md not edited (rule 29/31)
  • No fallback added to production code (rule 33)
  • No constants, switches, queues, unsafe or translator output changed (rules 2/9b/35/36/27)
  • Comments say what is true now (rule 3)
  • Nothing from the title, no non-free data pointers (hard constraints)
**@⁠TheRifai** on GitHub · 2026-12-01 14:20 UTC · [original](https://github.com/vktory6/VKtory/pull/109) `TheRifai:fix-xmem-flaky` → `main` · +7 −1 · 1 files · 2 commits · merged 2026-12-01 14:29 UTC ## What The xmem test `a_title_thread_goes_on_using_the_rest_of_a_view` was flaky (docs/TASKS.md “Failing and flaky tests”). Two test-only changes: an explicit start signal so the main thread cannot set `stop` before the title thread begins, and a counter assertion that tolerates a momentarily older value exposed by remapping the view's other pages while still requiring that the value never runs ahead and that the thread makes progress. The test's purpose — the title thread keeps using its page without faulting — is unchanged. ## The reference No console counterpart: this stabilises our own test, not runtime behaviour. ## Evidence - 12/12 consecutive `cargo xwin test -p victory-hle --target x86_64-pc-windows-msvc --features diagnostics --locked a_title_thread_goes_on_using_the_rest_of_a_view` runs under Proton-GE11-16 passed (the earlier exact-equality version failed 1 in 10 with a stale read). ## Checklist (docs/AGENTS.md) - [x] One topic; `docs/TASKS.md` not edited (rule 29/31) - [x] No fallback added to production code (rule 33) - [x] No constants, switches, queues, `unsafe` or translator output changed (rules 2/9b/35/36/27) - [x] Comments say what is true now (rule 3) - [x] Nothing from the title, no non-free data pointers (hard constraints)
The test's title thread asserted an exact read-after-write value while the main
thread remapped the other pages of the view; a remap can momentarily expose an
older value, so the assertion failed about 1 in 10 runs. Keep the no-fault and
progress checks (the value never runs ahead, n > 0) and add an explicit start
signal so `stop` cannot be set before the thread runs. 12/12 Proton runs pass
(docs/TASKS.md 'Failing and flaky tests').
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:24:23 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 14:22 UTC · original

Thanks: the start signal is a real fix for a test race, and I'm keeping it. The other change I've reverted on your branch, because the flake it hides is a real bug, not test noise.

The test's point (its doc says so) is that the page "was never given up": on the console the title thread's page keeps its contents while other pages of the view are remapped. If the thread ever reads an older value of its own counter, a write it made was lost during the remap. That's title memory losing data, which the title could hit for real; my guess is that the remap rebuilds or copies the view's mapping instead of touching only the remapped pages. Rule 32 / PHILOSOPHY.md: a test that catches impossible-on-console state stays strict, and the cause gets fixed.

So the exact assert_eq! stays, and the lost write is now a task with what you found: github.com/vktory6/VKtory@059ff68. Your 1-in-10 measurement is what pins it down. If you want to go after the cause, XMemMapPhysicalPages with a null page list on part of a view is where I'd start.

(Small thing for later: the message "went backwards: {seen} > {n}" had the comparison the wrong way round.)

**@⁠vktory6** on GitHub · 2026-12-01 14:22 UTC · [original](https://github.com/vktory6/VKtory/pull/109#issuecomment-7314158158) Thanks: the start signal is a real fix for a test race, and I'm keeping it. The other change I've reverted on your branch, because the flake it hides is a real bug, not test noise. The test's point (its doc says so) is that the page "was never given up": on the console the title thread's page keeps its contents while other pages of the view are remapped. If the thread ever reads an *older* value of its own counter, a write it made was lost during the remap. That's title memory losing data, which the title could hit for real; my guess is that the remap rebuilds or copies the view's mapping instead of touching only the remapped pages. Rule 32 / PHILOSOPHY.md: a test that catches impossible-on-console state stays strict, and the cause gets fixed. So the exact `assert_eq!` stays, and the lost write is now a task with what you found: https://github.com/vktory6/VKtory/commit/059ff68. Your 1-in-10 measurement is what pins it down. If you want to go after the cause, `XMemMapPhysicalPages` with a null page list on part of a view is where I'd start. (Small thing for later: the message "went backwards: {seen} > {n}" had the comparison the wrong way round.)
github-bot changed target branch from main to gh-pr/109/base 2026-12-01 14:29:51 +00:00
github manually merged commit d8c18de0da into gh-pr/109/base 2026-12-01 14:29:52 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 14:30 UTC · original

Merged as 4035dfb with the exact assertion kept (see above). Thanks for the start-signal fix and for measuring the 1-in-10 stale read; that's what turned a flaky test into a bug we can chase.

**@⁠vktory6** on GitHub · 2026-12-01 14:30 UTC · [original](https://github.com/vktory6/VKtory/pull/109#issuecomment-7314369211) Merged as 4035dfb with the exact assertion kept (see above). Thanks for the start-signal fix and for measuring the 1-in-10 stale read; that's what turned a flaky test into a bug we can chase.
Author
Owner

@⁠TheRifai on GitHub · 2026-12-01 14:42 UTC · original

You were right that the stale read was a real lost write. Pushed a follow-up commit to this same branch (fast-forward, no reopen): map() now creates one view per page, so unmap() of a tail page no longer hides the whole multi-page view and re-maps the kept pages — the title thread's page stays mapped throughout. The strict assert_eq! stays as you left it; the affected test now checks both pages keep their own views. Evidence: baseline 1/20 failures, 0/20 after; all 25 xmem tests pass; 120 s validation run shows only the known VUIDs.

**@⁠TheRifai** on GitHub · 2026-12-01 14:42 UTC · [original](https://github.com/vktory6/VKtory/pull/109#issuecomment-7314699902) You were right that the stale read was a real lost write. Pushed a follow-up commit to this same branch (fast-forward, no reopen): map() now creates one view per page, so unmap() of a tail page no longer hides the whole multi-page view and re-maps the kept pages — the title thread's page stays mapped throughout. The strict assert_eq! stays as you left it; the affected test now checks both pages keep their own views. Evidence: baseline 1/20 failures, 0/20 after; all 25 xmem tests pass; 120 s validation run shows only the known VUIDs.
Author
Owner

@⁠vktory6 on GitHub · 2026-12-01 14:43 UTC · original

Great that you went after the cause, and the diagnosis matches: the partial unmap hid the whole view and re-mapped the kept pages. Two things, though:

This PR was already merged (4035dfb) before your commit arrived, so 0498607 is not on main. Please open a new PR for it from a fresh branch on current main; it's its own topic anyway (the fix, where #109 was the test).

Before it can merge, two points in the change:

  1. own is dropped. map_view always calls show(..., false); the lean path that took the hole (own == true) used to pass true and now doesn't, and && { if own { /* hole was taken above */ } true } is a no-op. Either keep passing own through, or show why it no longer matters.
  2. Scale. One view per 64 KiB page for every multi-page map turns large physical mappings into many thousands of views (16,384 per GiB). Each is a map/unmap call, a notification to the GPU side, and an entry against the process's mapping limit (vm.max_map_count is 65,530 by default on many distros). The 120 s validation run doesn't show that cost. Please measure, on the boat start, main against your branch: the number of views at world entry (physical().views.len() or the map count in /proc/<pid>/maps), the time from start to world, and the frame times (A B B A, VKB_LAT + frames.py).

If the count really explodes, a narrower fix is to split only on a partial unmap: when an unmap covers part of a view, re-map just the kept pages as their own views before hiding the old one, so no owned page is ever unmapped. That leaves the common case at one view. Your call which way; the measurements decide.

**@⁠vktory6** on GitHub · 2026-12-01 14:43 UTC · [original](https://github.com/vktory6/VKtory/pull/109#issuecomment-7314724581) Great that you went after the cause, and the diagnosis matches: the partial unmap hid the whole view and re-mapped the kept pages. Two things, though: **This PR was already merged (4035dfb)** before your commit arrived, so `0498607` is not on main. Please open a **new PR** for it from a fresh branch on current main; it's its own topic anyway (the fix, where #109 was the test). **Before it can merge**, two points in the change: 1. **`own` is dropped.** `map_view` always calls `show(..., false)`; the lean path that took the hole (`own == true`) used to pass `true` and now doesn't, and `&& { if own { /* hole was taken above */ } true }` is a no-op. Either keep passing `own` through, or show why it no longer matters. 2. **Scale.** One view per 64 KiB page for every multi-page map turns large physical mappings into many thousands of views (16,384 per GiB). Each is a map/unmap call, a notification to the GPU side, and an entry against the process's mapping limit (`vm.max_map_count` is 65,530 by default on many distros). The 120 s validation run doesn't show that cost. Please measure, on the boat start, main against your branch: the number of views at world entry (`physical().views.len()` or the map count in `/proc/<pid>/maps`), the time from start to world, and the frame times (A B B A, `VKB_LAT` + `frames.py`). If the count really explodes, a narrower fix is to split only on a partial unmap: when an unmap covers part of a view, re-map just the kept pages as their own views *before* hiding the old one, so no owned page is ever unmapped. That leaves the common case at one view. Your call which way; the measurements decide.
This discussion has been locked. Commenting is limited to contributors.
No description provided.