fix(hle): coalesce split placeholders when mapping physical pages #1224

Open
github-bot wants to merge 1 commit from github-bot/gh-1224 into main AGit
Owner

@⁠matheusfrta on GitHub · 2026-11-24 16:32 UTC · original
matheusfrta:patch-1795537915 → main · +193 −17 · 1 files · 1 commits · open

Rebases the placeholder coalescing and run-grouped map_alias changes onto main while keeping shown alias tracking, low_guards, and commit-failure reporting intact. Verified against cargo test -p victory-hle remapping_split_placeholders_and_coalesced_aliases.

**@⁠matheusfrta** on GitHub · 2026-11-24 16:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224) `matheusfrta:patch-1795537915` → `main` · +193 −17 · 1 files · 1 commits · open Rebases the placeholder coalescing and run-grouped `map_alias` changes onto `main` while keeping `shown` alias tracking, `low_guards`, and commit-failure reporting intact. Verified against `cargo test -p victory-hle remapping_split_placeholders_and_coalesced_aliases`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:24:16 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 17:59 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9fb6294: cargo test -p victory-hle passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 17:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7140005643) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 9fb6294: `cargo test -p victory-hle` passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠OsiPog on GitHub · 2026-11-24 18:36 UTC · original

Data point for this change under Wine, from an independent implementation of the same idea (map runs of consecutive pool pages in map_alias as one view, merging the per-page placeholders first with MEM_COALESCE_PLACEHOLDERS; page by page if the merge fails).

Why per-page views hurt under Wine. We profiled wineserver during the multi-minute zero-fps stalls at boot and story load. 91% of its CPU was in is_valid_view_addr (server/mapping.c). Each map_view request scans a linked list of every view the process has mapped. find_mapped_view on unmap is also O(n), and it walks from the head while new views are appended at the tail. With one view per 64 KiB page, n reaches the tens of thousands. Every other server request (waits, events, file I/O) then queues behind those scans. Every stall stack we dumped had a title thread in NtMapViewOfSectionEx. Before the change, single-page XMemMapPhysicalPages calls took 70-470 ms each in MapViewOfFile3, and story load had not finished after 12+ minutes.

Result. Wine-staging 11.21, vkd3d-proton 3.2, RADV, first-boot setup already done. Boot reached the start of the first cutscene in about 4 minutes. Caveat: that run also used a wineserver patched so that is_valid_view_addr skips the overlap scan and find_mapped_view walks from the tail. So it does not isolate this PR's effect. The point is that fewer views helps any stock Wine; the scan cost grows with the view count. The proper server-side fix (a tree of views instead of the list) belongs in Wine, and we are working on it separately.

We haven't run this PR's branch itself. If useful, we can do an A/B run with stock wineserver.

**@⁠OsiPog** on GitHub · 2026-11-24 18:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7140887601) Data point for this change under Wine, from an independent implementation of the same idea (map runs of consecutive pool pages in `map_alias` as one view, merging the per-page placeholders first with `MEM_COALESCE_PLACEHOLDERS`; page by page if the merge fails). **Why per-page views hurt under Wine.** We profiled wineserver during the multi-minute zero-fps stalls at boot and story load. 91% of its CPU was in `is_valid_view_addr` (`server/mapping.c`). Each `map_view` request scans a linked list of every view the process has mapped. `find_mapped_view` on unmap is also O(n), and it walks from the head while new views are appended at the tail. With one view per 64 KiB page, n reaches the tens of thousands. Every other server request (waits, events, file I/O) then queues behind those scans. Every stall stack we dumped had a title thread in `NtMapViewOfSectionEx`. Before the change, single-page `XMemMapPhysicalPages` calls took 70-470 ms each in `MapViewOfFile3`, and story load had not finished after 12+ minutes. **Result.** Wine-staging 11.21, vkd3d-proton 3.2, RADV, first-boot setup already done. Boot reached the start of the first cutscene in about 4 minutes. Caveat: that run also used a wineserver patched so that `is_valid_view_addr` skips the overlap scan and `find_mapped_view` walks from the tail. So it does not isolate this PR's effect. The point is that fewer views helps any stock Wine; the scan cost grows with the view count. The proper server-side fix (a tree of views instead of the list) belongs in Wine, and we are working on it separately. We haven't run this PR's branch itself. If useful, we can do an A/B run with stock wineserver.
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-24 18:42 UTC · original

@⁠OsiPog Thanks for sharing those numbers! That wineserver bottleneck breakdown makes a lot of sense.

An A/B test of this branch on stock wineserver would definitely be interesting and super helpful to see the isolated impact of the PR. If you have the time to run it, I'd really appreciate it!

**@⁠matheusfrta** on GitHub · 2026-11-24 18:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7141034236) @⁠OsiPog Thanks for sharing those numbers! That wineserver bottleneck breakdown makes a lot of sense. An A/B test of this branch on stock wineserver would definitely be interesting and super helpful to see the isolated impact of the PR. If you have the time to run it, I'd really appreciate it!
Author
Owner

@⁠OsiPog on GitHub · 2026-11-24 20:51 UTC · original

A/B follow-up to the data point above: same build (our run-coalescing map_alias change), same first-boot data and settings, only the wineserver differs.

  • Patched wineserver: reached the first chapter card about 4 minutes after launch. Menus held a steady 30 fps.
  • Stock wine-staging 11.21 wineserver: an 8.5-minute stall early in boot, with no frames presented and no log progress. Screen black for the whole run. No chapter card within the 10-minute cap. Single MapViewOfFile3 calls still took 50-517 ms.

So under stock Wine, fewer views from this change are not enough on their own. The view-list scan in wineserver stays the bottleneck, presumably because other mapping paths still create many views. We replaced our byte patch with a source patch that keeps each process's mapped views in a red-black tree instead of a list. In a 40k-view benchmark it also fixes the address queries the byte patch missed (0.07 s vs 1.33 s stock). It is being prepared for Wine upstream. Caveat: these are single runs on a shared, loaded machine.

**@⁠OsiPog** on GitHub · 2026-11-24 20:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7144146454) A/B follow-up to the data point above: same build (our run-coalescing `map_alias` change), same first-boot data and settings, only the wineserver differs. - **Patched wineserver:** reached the first chapter card about 4 minutes after launch. Menus held a steady 30 fps. - **Stock wine-staging 11.21 wineserver:** an 8.5-minute stall early in boot, with no frames presented and no log progress. Screen black for the whole run. No chapter card within the 10-minute cap. Single `MapViewOfFile3` calls still took 50-517 ms. So under stock Wine, fewer views from this change are not enough on their own. The view-list scan in wineserver stays the bottleneck, presumably because other mapping paths still create many views. We replaced our byte patch with a source patch that keeps each process's mapped views in a red-black tree instead of a list. In a 40k-view benchmark it also fixes the address queries the byte patch missed (0.07 s vs 1.33 s stock). It is being prepared for Wine upstream. Caveat: these are single runs on a shared, loaded machine.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:26 UTC · original · edited 2026-11-26 00:21 UTC

Automated triage for the maintainers.

Needs work: needs the maintainer's decision between this PR and #76. Rebased cleanly. The final newline and the test command in the description are fixed. In crates/victory-hle/src/modules/xmem.rs, map_alias now maps each run of consecutive slices of one section as one view (view_run). map merges adjacent reserve regions from the range's BaseAddress with MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS before it splits. remapping_split_placeholders_and_coalesced_aliases covers a split-and-remap, an alias across two sections, and a partial remap from page 1. By reading this is correct: a merge that is refused (a plain reservation, or another allocation) only logs a warning, and map goes on as before.

What is still open:

  • #76 works on the same function. The maintainer has to pick one, or say how they combine.
  • There is no measurement of the benefit on Windows, for example the view count or the time spent in map_alias during a load with and without this PR. @⁠OsiPog's A/B under stock Wine found that fewer views from this approach did not remove the stall on their own, so a Windows number would show whether this is worth carrying.

On your reply: thanks for the rebase that keeps shown, low_guards and the commit-failure reporting. Those are intact in the diff.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7149552539) · edited 2026-11-26 00:21 UTC <!-- victory-triage v1 head=ac39370f881cab4d372fef5b811649659784ab3d verdict=needs-work at=2026-11-26T00:21:53Z --> Automated triage for the maintainers. **Needs work: needs the maintainer's decision between this PR and #76.** Rebased cleanly. The final newline and the test command in the description are fixed. In `crates/victory-hle/src/modules/xmem.rs`, `map_alias` now maps each run of consecutive slices of one section as one view (`view_run`). `map` merges adjacent reserve regions from the range's `BaseAddress` with `MEM_RELEASE | MEM_COALESCE_PLACEHOLDERS` before it splits. `remapping_split_placeholders_and_coalesced_aliases` covers a split-and-remap, an alias across two sections, and a partial remap from page 1. By reading this is correct: a merge that is refused (a plain reservation, or another allocation) only logs a warning, and `map` goes on as before. What is still open: - #76 works on the same function. The maintainer has to pick one, or say how they combine. - There is no measurement of the benefit on Windows, for example the view count or the time spent in `map_alias` during a load with and without this PR. @⁠OsiPog's A/B under stock Wine found that fewer views from this approach did not remove the stall on their own, so a Windows number would show whether this is worth carrying. On your reply: thanks for the rebase that keeps `shown`, `low_guards` and the commit-failure reporting. Those are intact in the diff. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-25 01:50 UTC · original

Updated coalesce_placeholders to start at first.BaseAddress and log a warning if VirtualFree fails. Also cleaned up the formatting (cargo fmt), added a partial-remap case to remapping_split_placeholders_and_coalesced_aliases, and added the test command to the PR description.

**@⁠matheusfrta** on GitHub · 2026-11-25 01:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7150013029) Updated `coalesce_placeholders` to start at `first.BaseAddress` and log a warning if `VirtualFree` fails. Also cleaned up the formatting (`cargo fmt`), added a partial-remap case to `remapping_split_placeholders_and_coalesced_aliases`, and added the test command to the PR description.
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-25 22:50 UTC · original

Rebased onto main and ensured the trailing newline is in place.

**@⁠matheusfrta** on GitHub · 2026-11-25 22:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1224#issuecomment-7176851954) Rebased onto `main` and ensured the trailing newline is in place.
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/1224/head:github-bot/gh-1224'
git switch 'github-bot/gh-1224'

Merge

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