watch: VICTORY_MAP_LOCK_FINE=1 takes the mapping lock by range (off by default) #304

Open
github-bot wants to merge 3 commits from github-bot/gh-304 into main AGit
Owner

@⁠zocram4cc on GitHub · 2026-11-26 15:19 UTC · original
zocram4cc:feat/map-lock-fine → main · +432 −23 · 8 files · 3 commits · open

What

VICTORY_MAP_LOCK_FINE=1 takes the title-memory mapping lock by address range instead of one RwLock for the whole address space. Off by default; with the switch off the old lock is used unchanged.

Why

The mapping lock serialises every reader and writer of title memory, so writers of unrelated memory made draw-side readers wait for no reason. Range-scoped announcements let disjoint readers proceed while a change is in flight.

Credit: design from Op-lite/victory-scarlett 7c8f019 (scarlett-local, GPL-3.0). Cherry-picked from our perf/v7900-final (commit 631712f is 19dcdaf on v7900/main), original author kept.

Measured

Series S, release build, Proton on Linux, 300 s of world time per run. Two runs per arm; the arms differ only in VICTORY_MAP_LOCK_FINE. Other test switches were the same in both arms.

  • Average frame: on 78.2 / 77.2 ms vs off 88.4 / 78.5 ms.
  • Slowest frame per second: 97 ms on vs 106 ms off.
  • Frames noticeably steadier with the switch on.

Linux/Proton only measured, Windows untested.

Tests

watch::fine_tests: a reader of a disjoint range goes on during a change; an overlapping reader waits; a writer is not starved by a stream of overlapping readers; an unranged reader or writer excludes as the old lock did; with the switch off a ranged change still excludes a read of other memory.

Run under Proton on this head (631712f), one test exe, --test-threads 1:

  • watch::fine_tests (5): VICTORY_MAP_LOCK_FINE unset: 5 pass; VICTORY_MAP_LOCK_FINE=1: 5 pass.
  • watch:: (53 tests, the 5 above included): unset: 50 pass, 3 fail; =1: 50 pass, 3 fail. The same 3 fail in both, and they are the Wine-only failures that also fail on upstream: holes_are_known_until_the_runtime_tells, no_mapping_is_lost_between_askers, what_is_left_alone_is_no_known_hole.

Build

cargo xwin build --profile release -p victory --target x86_64-pc-windows-msvc: passes on this branch.

AI-assisted (Claude Code).

**@⁠zocram4cc** on GitHub · 2026-11-26 15:19 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/304) `zocram4cc:feat/map-lock-fine` → `main` · +432 −23 · 8 files · 3 commits · open ## What `VICTORY_MAP_LOCK_FINE=1` takes the title-memory mapping lock by address range instead of one RwLock for the whole address space. Off by default; with the switch off the old lock is used unchanged. ## Why The mapping lock serialises every reader and writer of title memory, so writers of unrelated memory made draw-side readers wait for no reason. Range-scoped announcements let disjoint readers proceed while a change is in flight. Credit: design from Op-lite/victory-scarlett 7c8f019 (scarlett-local, GPL-3.0). Cherry-picked from our `perf/v7900-final` (commit 631712f is 19dcdaf on `v7900/main`), original author kept. ## Measured Series S, release build, Proton on Linux, 300 s of world time per run. Two runs per arm; the arms differ only in `VICTORY_MAP_LOCK_FINE`. Other test switches were the same in both arms. - Average frame: on 78.2 / 77.2 ms vs off 88.4 / 78.5 ms. - Slowest frame per second: 97 ms on vs 106 ms off. - Frames noticeably steadier with the switch on. Linux/Proton only measured, Windows untested. ## Tests `watch::fine_tests`: a reader of a disjoint range goes on during a change; an overlapping reader waits; a writer is not starved by a stream of overlapping readers; an unranged reader or writer excludes as the old lock did; with the switch off a ranged change still excludes a read of other memory. Run under Proton on this head (631712f), one test exe, `--test-threads 1`: - `watch::fine_tests` (5): `VICTORY_MAP_LOCK_FINE` unset: 5 pass; `VICTORY_MAP_LOCK_FINE=1`: 5 pass. - `watch::` (53 tests, the 5 above included): unset: 50 pass, 3 fail; `=1`: 50 pass, 3 fail. The same 3 fail in both, and they are the Wine-only failures that also fail on upstream: `holes_are_known_until_the_runtime_tells`, `no_mapping_is_lost_between_askers`, `what_is_left_alone_is_no_known_hole`. ## Build `cargo xwin build --profile release -p victory --target x86_64-pc-windows-msvc`: passes on this branch. AI-assisted (Claude Code).
Port of Op-lite/victory-scarlett 7c8f019 (scarlett-local, GPL-3.0), mod fine
and its range-scoped entry points, onto cfdc79e.

- watch.rs: title_memory_remapping_in(ranges), title_memory_reading_in(at,
  len), title_memory_reading_now_in(at, len). The unranged entry points
  take the whole address space. With the switch off the old RwLock is used
  unchanged; with VICTORY_MAP_LOCK_FINE=1 readers and writers announce their
  ranges under one mutex, writers are one at a time, and a reader waits only
  for an announced writer whose ranges overlap its own. The odd change
  counter and the per-thread change notes are as before.
- xmem.rs: the four runtime writers (XMemMapPhysicalPages, map_alias,
  map_aliases, scatter) announce what their change takes away or maps: their
  64 KiB pages and every view overlapping them whole (affected, affected_ops),
  since unmap takes a view away whole and maps what stays of it again.
- Readers that know their range pass it: draw.rs (vertex read),
  texback::land, texture refresh, land::piece_at, put_beside.
  texback::Target::new stays unranged: its range is only what title_texture
  finds under the read.
- Diagnostics (copystat, diag builds): reader waits on the mapping lock per
  frame, ranged and unranged, count and ms. Log target victory_gpu::copystat.

Tests (watch::fine_tests): a reader of a disjoint range goes on during a
change; an overlapping reader waits; a writer is not starved by a stream of
overlapping readers; an unranged reader or writer excludes as the lock did;
with the switch off a ranged change excludes a read of other memory.

Credit: Op-lite/victory-scarlett 7c8f019 and scarlett-local for the design.

On this tree (upstream c9c932c with renderer ports 6 and 7): applied with no
conflict. Neither port reaches the mapping lock: every caller of
title_memory_reading* and title_memory_remapping* is the same set as on
cfdc79e (listed by grep), the readers in place are all ranged but
texback::Target::new, and port 7's journal parts and port 6's claims are
not readers in place of title memory. The test that needed the switch off
(with_the_switch_off_a_change_excludes_every_read) now follows the switch
(a_change_excludes_a_read_of_other_memory_only_with_the_switch_off), so
watch::fine_tests pass with VICTORY_MAP_LOCK_FINE=1 as well.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:20:41 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-26 16:17 UTC · original

I found some extra work on the default path in 631712f0. Both batched mapping calls build affected_ops while holding the physical mapping mutex, then the whole-address-space lock discards the result. The two single-range callers also walk the view map with the switch off.

I sent a small fix against your PR branch. With the change, the collector runs zero times when the switch is off and once when it’s on. All six mapping-lock tests passed in each mode under Wine 11.22.

**@⁠UwUCammie** on GitHub · 2026-11-26 16:17 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/304#issuecomment-7197445035) I found some extra work on the default path in `631712f0`. Both batched mapping calls build `affected_ops` while holding the physical mapping mutex, then the whole-address-space lock discards the result. The two single-range callers also walk the view map with the switch off. I sent a [small fix against your PR branch](https://github.com/zocram4cc/VIctory-7900XTX/pull/2). With the change, the collector runs zero times when the switch is off and once when it’s on. All six mapping-lock tests passed in each mode under Wine 11.22.
Author
Owner

@⁠zocram4cc on GitHub · 2026-11-26 17:01 UTC · original

Thanks @⁠UwUCammie, merged your fix into this branch (68a7a66). Re-checked under Proton: fine_tests + mapping_tests 7/7 with VICTORY_MAP_LOCK_FINE unset and =1.

**@⁠zocram4cc** on GitHub · 2026-11-26 17:01 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/304#issuecomment-7198396043) Thanks @⁠UwUCammie, merged your fix into this branch (68a7a66). Re-checked under Proton: fine_tests + mapping_tests 7/7 with VICTORY_MAP_LOCK_FINE unset and =1.
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/304/head:github-bot/gh-304'
git switch 'github-bot/gh-304'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-304'
git switch 'github-bot/gh-304'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-304'
git switch 'github-bot/gh-304'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-304'
git switch 'main'
git merge --squash 'github-bot/gh-304'
git switch 'main'
git merge --ff-only 'github-bot/gh-304'
git switch 'main'
git merge 'github-bot/gh-304'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.