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

Open
zocram4cc wants to merge 3 commits from upstream-pr/304 into main
zocram4cc commented 2026-11-26 15:19:25 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by zocram4cc on 2026-11-26T15:19:25Z.


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).

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6629753787 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/304). Originally posted by [zocram4cc](https://github.com/zocram4cc) on 2026-11-26T15:19:25Z. --- ## 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).
UwUCammie commented 2026-11-26 16:17:24 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by UwUCammie on 2026-11-26T16:17:24Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7197445035 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/304#issuecomment-7197445035). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-26T16:17:24Z. --- 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.
zocram4cc commented 2026-11-26 17:01:40 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by zocram4cc on 2026-11-26T17:01:40Z.


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.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7198396043 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/304#issuecomment-7198396043). Originally posted by [zocram4cc](https://github.com/zocram4cc) on 2026-11-26T17:01:40Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/304:upstream-pr/304'
git switch 'upstream-pr/304'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/304'
git switch 'upstream-pr/304'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/304'
git switch 'upstream-pr/304'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/304'
git switch 'main'
git merge --squash 'upstream-pr/304'
git switch 'main'
git merge --ff-only 'upstream-pr/304'
git switch 'main'
git merge 'upstream-pr/304'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
avatarmanz/VIctory-7900XTX!304
No description provided.