fix(hle): coalesce split placeholders when mapping physical pages #1224
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1224
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1224"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@matheusfrta on GitHub · 2026-11-24 16:32 UTC · original
matheusfrta:patch-1795537915→main· +193 −17 · 1 files · 1 commits · openRebases the placeholder coalescing and run-grouped
map_aliaschanges ontomainwhile keepingshownalias tracking,low_guards, and commit-failure reporting intact. Verified againstcargo test -p victory-hle remapping_split_placeholders_and_coalesced_aliases.@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-hlepasses, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@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_aliasas one view, merging the per-page placeholders first withMEM_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). Eachmap_viewrequest scans a linked list of every view the process has mapped.find_mapped_viewon 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 inNtMapViewOfSectionEx. Before the change, single-pageXMemMapPhysicalPagescalls took 70-470 ms each inMapViewOfFile3, 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_addrskips the overlap scan andfind_mapped_viewwalks 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.
@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!
@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_aliaschange), same first-boot data and settings, only the wineserver differs.MapViewOfFile3calls 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.
@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_aliasnow maps each run of consecutive slices of one section as one view (view_run).mapmerges adjacent reserve regions from the range'sBaseAddresswithMEM_RELEASE | MEM_COALESCE_PLACEHOLDERSbefore it splits.remapping_split_placeholders_and_coalesced_aliasescovers 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, andmapgoes on as before.What is still open:
map_aliasduring 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_guardsand the commit-failure reporting. Those are intact in the diff.CI: passing.
Generated by Claude Code
@matheusfrta on GitHub · 2026-11-25 01:50 UTC · original
Updated
coalesce_placeholdersto start atfirst.BaseAddressand log a warning ifVirtualFreefails. Also cleaned up the formatting (cargo fmt), added a partial-remap case toremapping_split_placeholders_and_coalesced_aliases, and added the test command to the PR description.@matheusfrta on GitHub · 2026-11-25 22:50 UTC · original
Rebased onto
mainand ensured the trailing newline is in place.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.