fix(hle): coalesce split placeholders when mapping physical pages #1224
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-24T16:32:00Z.
Rebases 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.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T17:54:28Z.
Review: APPROVED
Tested
9fb62942on Windows 11, RTX 5070, MSVC:cargo test -p victory-hlepasses on the head (95 passed).clippy -D warnings(default and all features) are all clean.The change is right:
mapsplits again around[base, base + len)just afterwards, withMEM_PRESERVE_PLACEHOLDER. A merged span bigger than the target is fine.[AllocationBase, base)holds a mapped view, theMEM_COALESCE_PLACEHOLDERScall simply fails, and the old path runs unchanged.map_aliasonly joins a run while the slices stay in one section with consecutive indices (Arc::ptr_eqandindex == first.index + run / PAGE), so each grouped view shows the same pages the per-page views did.Notes:
coalesce_placeholdersnow runs aVirtualQueryExwalk on everymapcall, including single-page maps that never need it. It might be worth calling it only afterMapViewOfFile3has failed once.cargo fmtwill collapse.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T17:59:47Z.
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).
Imported from Marvisak/VIctory. Originally posted by OsiPog on 2026-11-24T18:36:41Z.
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.
Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-24T18:42:22Z.
@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!
Imported from Marvisak/VIctory. Originally posted by OsiPog on 2026-11-24T20:51:20Z.
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.
[PR #1224] HLE: coalesce split placeholders on map and group runs in map_aliasto [PR #1224] fix(hle): coalesce split placeholders when mapping physical pagesImported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:26:41Z.
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
Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-25T01:50:10Z.
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.upstream-sync referenced this pull request2026-11-25 13:02:46 +00:00
Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-25T22:50:38Z.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.