HLE: map a page scatter in runs, not one page at a time #1264
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!1264
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1264"
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?
@pablogonz12 on GitHub · 2026-11-24 16:56 UTC · original
pablogonz12:up/x254→main· +333 −17 · 3 files · 9 commits · openWhat
XMemMapPhysicalPagesScattercalledXMemMapPhysicalPagesonce per entry, so the run batching that call already does never happened for the scatter. Consecutive addresses now ride one call: one unmap of the run, one view per section run, one commit per run. A zero page ends the run it is in (it unmaps only its own address). A run is cut where its pages stop being consecutive slices of one section (section_run), which is the most one call can map and always sits inside one placeholder, so a batched call never crosses two reservations; a call that still fails for another reason falls back to the per-page calls.Diagnostics: the copy line now reports page scatters, the pages they name and the map calls they made, so a run says whether the title scatters at all and how much of it batches.
Why
The console scatters a lot on load and on streaming. Idea from ivall/xcl#254 (XCL's scatter asked
VirtualQueryabout every page, so n pages cost O(n^2)); Victory has no per-page query, but it still paid three system calls per 64 KiB page where one call per run does.How tested
cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean.victory-hlexmem::tests under Wine: 11 passed, 0 failed, including the scatter tests (runs, a zero page breaking a run, and two adjacent reservations, each ending as its own placeholder, mapped from one scatter call).Not tested
Written with an AI assistant.
@pablogonz12 on GitHub · 2026-11-24 17:18 UTC · original
Fixed in
204ec23: the port carried amod producers;line whose file lives on another branch, so--all-featuresstopped on the missingproducers.rs; that line is gone. Checked withcargo xwin clippy --workspace --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings(clean), the same without--all-features(clean), andvictory-hle xmem::under Wine: 11 passed, 0 failed.@anasssssssss1 on GitHub · 2026-11-24 18:07 UTC · original
Tried this on top of r4tedx's
integration/testersupdate 9 (94e0ea5) on an RTX 4050 Laptop (6 GB), Windows 11 26300, diag build,--console series-s, with three other changes merged (#1010, #1277, #1265, and a small local console-flow change in the shader translator). The title crashed about 2 minutes after launch, during loading, before the world:Backing out only this PR's changes (same tree, same cache, same settings) boots past that point. So on this tree a scatter run seems to reach a range that is not a placeholder. That could be a page already mapped by an earlier run, or the run crossing a reservation boundary. The title then reads memory that was never committed.
Not checked: this PR alone on
ffe310e. That combination may be fine, and the interaction may be with the testers tree's own xmem changes. One run.No game data attached.
@pablogonz12 on GitHub · 2026-11-24 23:28 UTC · original
Both fixed in
81c4ffd3:mod producers;line is gone (it came from another branch;statsonly re-exportscopystat);C::Scatteris now added once per call, above the run loop, so a call with two runs counts once;C::ScatterMapsin the per-page fallback is added before the call, so a failed attempt counts too. The test comment above the two-address unmap now says two.Re-checked after merging
origin/main:cargo xwin clippy -p victory-hle -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warningsclean (also without--all-features);cargo xwin test -p victory-hle --lib95 passed, 3 failed (window and loopback tests, no display/network in this Wine prefix — same as on main);cargo xwin test -p victory-gpu --lib80 passed.Not tested here: native Windows build, which your run covers. Thanks for the review.
AI-assisted (Claude).
@Marvisak on GitHub · 2026-11-25 01:20 UTC · original · edited 2026-11-26 00:22 UTC
Automated triage for the maintainers.
Needs work. The new head is a merge of
mainplus the counter and test-comment fixes. The two reports of an in-game crash with this PR are still unexplained.41efca3, which already has thesection_runcut. It logged 186os error 487warnings and then a0xc0000005on a reserved, never-committed page. The same stack with only this PR reverted had neither. So the cut did not remove the failure, and an earlier report from @anasssssssss1 matches it.XMemMapPhysicalPagesScattersays consecutive slices of one section "always sit inside one placeholder". Placeholders are laid out by virtual address, though, and the physical pages say nothing about them. A run of consecutive section slices at consecutive addresses can still cross two reservations, which is the case the cut was meant to stop.VirtualQuerypre-check you proposed (batch only when the whole run is one reserved placeholder) is not on the branch.What would change the verdict: the
VirtualQuerypre-check, or a fix for the path that leaves a page uncommitted after a refused batched call. Then a run from a tester with theScatter/ScatterPages/ScatterMapscounters, showing no crash and no 487 warnings, ideally with a before/after time for the load.On your reply: thanks for fixing the counters and the stray
mod producers;. Those are correct now. But the open item from the last verdict was the crash, and this head does not address it.CI: passing.
Generated by Claude Code
@pablogonz12 on GitHub · 2026-11-25 01:50 UTC · original
Addressed in
1433a4a9(head moved from81c4ffd3):os error 487), so pages past the failure lost their mapping where the old per-page path left them alone. A run is now cut at the first page that is not a consecutive slice of the same section (section_run, xmem.rs:698), which is the most oneXMemMapPhysicalPagescall maps and always sits inside one placeholder. A batched call can then no longer cross a placeholder boundary; the per-page fallback stays for a genuine failure.scatter_cuts_a_run_at_a_second_placeholderreserves two adjacent placeholders (VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)), takes a physical page from each of two allocations and maps both through one scatter call, then unmaps them.cargo xwin clippy -p victory-hle -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings(clean) andcargo xwin test -p victory-hle --lib: 98 passed, 1 failed (net::only_loopback_is_reachable,ws2_32lacksWSAConnectByListhere, same on main), including both scatter tests.Still not measured in game.
AI-assisted (Claude).
@pablogonz12 on GitHub · 2026-11-25 04:31 UTC · original
All three are addressed on the current head
87e17a602(the merge ofmainintoup/x254):mod producers;is gone fromcrates/victory-gpu/src/lib.rs;cargo xwin clippy -p victory-hle -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warningsis clean at this head (checked here, not on Windows).add(C::Scatter, 1)now sits before the run loop (crates/victory-hle/src/modules/xmem.rs:742), so it counts calls andScatterMapscounts runs.Not tested: no game run at this head.
@pablogonz12 on GitHub · 2026-11-25 11:29 UTC · original
Added the test the triage asked for,
scatter_maps_a_run_over_per_page_placeholders(test only): three consecutive slices of one section are mapped one page at a time, then again through one scatter call over the same addresses. It records the views (offset, length, slice) after the per-page mapping and asserts they are identical after the scatter, that each address reads its own page, and that unmapping the middle page leaves the other two.Under Wine (GE-Proton11-14) the case is real, not accepted silently: with a temporary probe,
section_runis 3 and the direct three-pageXMemMapPhysicalPagescall over that range returns null, so the per-page fallback runs and leaves the same three views as the per-page path.victory-hle xmem::: 13 passed, 0 failed;cargo xwin clippy --workspace --all-targets -- -D warningsclean, with and without--all-features.Still open, so you can weigh it: no native Windows run; no measurement that the batching helps; such a range costs one refused call (and its warning) on top of the per-page calls; and unmapping part of a batched view briefly unmaps the whole view before mapping the rest back (that path exists on
mainfor multi-page maps, but batching scatters creates more such views). #1224 works on the placeholder side of the same area.AI-assisted (Claude).
@ruvenesh on GitHub · 2026-11-25 15:53 UTC · original
Test report on Linux + Proton (GE-Proton11-14), RTX 3060 12 GB,
x86_64-pc-windows-msvcdiagnostics builds: with this PR the title crashed in the world load once; the same build without this PR did not. One run each way, so this is a single reproduction, not a confirmed pair.Setup: a local stack of
main(940d32f) plus about 70 open PRs (a "mega" build), plus a second build that adds this PR and five others (#2309, #2441, #2453, #2415, #2474). Same prefix settings, same scripted menu presses, capped runs.What happened with this PR's build:
mapping physical pages failed (not a placeholder?) ... os error 487from about 2 s into the world load. The lengths were mostly 262144 (42 times), 196608 (31) and 131072 (24).0xc0000005: two reads of a page that was reserved but never committed ("reserved, never committed"), then the usual crash log.Controls:
I did not read this PR's diff closely, so I can't say where it goes wrong. My guess, flagged as a guess: a batched run that fails with 487 leaves some pages mapped but not committed (an earlier head of this PR hit the same os error on adjacent reservations, per the thread), and the title then reads them. I did not see the scatter counters this PR adds in the lines I checked.
This was this PR's head at the time of the run (
41efca3). Happy to rerun on a newer head. No game data attached. AI-assisted (Claude Code).@pablogonz12 on GitHub · 2026-11-25 19:46 UTC · original
Thanks — that is a useful report, and the warnings plus that crash point at one place. What I can say from the code, and what I cannot test here (I have no Windows host and no world run):
The 186 warnings are this PR's batched attempt being refused, by design.
map()logs that line whenMapViewOfFile3(..., MEM_REPLACE_PLACEHOLDER)does not give back the address it asked for. In this PR the scatter call first tries the whole run of consecutive pages as one view — your lengths (262144, 196608, 131072 = 4, 3, 2 pages of 64 KiB) are exactly those runs — and when the run crosses two placeholders the call is refused and the same range is then mapped a page at a time. So one refused run costs one warning. Before this PR every page was its own call, so the same situation never produced a warning; the count says "64-page-aligned runs get refused", not "pages were lost".What matters for the crash is whether the per-page fallback then succeeded. If it did, the reads that faulted are not these pages. Could you check, on the failing build, the diagnostics counters this PR adds (
Scatter,ScatterPages,ScatterMaps)? IfScatterMapsexceedsScatterPagesby roughly the number of warnings, every refused run was retried per page, andXMemMapPhysicalPagesScatterstill returned 1. If it returned 0 for some call, then a range really was left unmapped and the title read it.Also useful: whether the warnings' addresses are inside the tiled heap's placeholder or in a pool region, i.e. whether the refused runs are "crosses two placeholders" (what I expect) or "the address is not a placeholder at all" (which would mean the batched call is reaching memory this code does not own).
Two things I would like to do, in this order, unless you tell me the counters point elsewhere:
VirtualQuerythe run and only batch when all of it lies in one reserved placeholder (one region,MEM_RESERVE), so a run that cannot be one view is never attempted and never warns. That removes the refusedVirtualFree/MapViewOfFile3pair from the picture completely.VirtualFree(MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)can leave part of the range freed when the range crosses placeholders — that is the one way I see this code leaving a page uncommitted.Both are changes I would rather make with your machine in the loop than guess at: nothing on my side runs Windows, and my only automated view of this code is unit tests on a placeholder laid out as three separate pages (which is why the batched call is expected to be refused there). A rerun on a newer head after (1) is exactly what I would want — same build plus this PR and nothing else, three runs, if you can spare them.
Not tested in a game run here; no Windows host.
@pablogonz12 on GitHub · 2026-11-25 23:57 UTC · original
Thanks for the two code points - both are fixed in the current head (
e9dfb7c69).mod producers;is gone: it was dropped in204ec23c8("GPU: drop the producers line the port carried, so --all-features builds").statsnow only re-exportscopystat::{C, add}.C::Scattercounts calls:add(C::Scatter, 1)now sits at the top ofXMemMapPhysicalPagesScatter, before the run loop. Per run we addScatterPages(run)andScatterMaps(1); each per-page fallback call addsScatterMaps(1)as well, so the counters tell calls, runs and pages apart. The doc comment matches that.One limit on verification: this machine is Linux, and the
cfg(windows)half ofvictory-gpudoes not compile for the host target, so I cannot re-run that--all-featurescommand here. On the non-Windows side the command still fails incrates/victory-loader/src/publish.rs(deadNEXT_STAGING/write_if_changed), with or without this branch; those files are not touched by the PR. Theproducerserror was the only one the PR added, and it is gone. The Windows clippy job in CI is green on this head. No test other than the two newxmemones changed.@mercuryVM on GitHub · 2026-11-24 17:10 UTC · original · requested changes
Tested
4b8eef97on Windows 11, RTX 5070, MSVC:cargo test -p victory-hlepasses (95 passed). With diagnostics on, though, the build breaks:crates/victory-gpu/src/lib.rs:30declaresmod producers;(undercfg(all(windows, feature = "diagnostics"))), but the PR doesn't addproducers.rs. It looks like a leftover from another branch. Fix: drop the line, or add the file.statsonly needs thecopystatre-export.C::Scattercounts runs, not calls (crates/victory-hle/src/modules/xmem.rs, in the run loop).add(C::Scatter, 1)sits inside thewhile i < nloop, next toadd(C::ScatterMaps, 1), so the two counters are always equal. The doc comment says Scatter countsXMemMapPhysicalPagesScattercalls. Fix: moveadd(C::Scatter, 1)above the loop.Nit: the test comment "Three consecutive addresses without pages unmap as one run" sits above a call that passes two addresses.
The batching itself looks right to me:
pages.add(i)withrunentries, which stays inside thenthe title gave.AI-assisted (Claude Code).
@pablogonz12 on GitHub · 2026-11-26 10:30 UTC · original
The
VirtualQuerypre-check is on the branch now (679b1bb), before the run is used rather than after it is refused.What it does. One
VirtualQueryExat the run's first address gives the end of the region it lies in (xmem.rs:752,placeholder_room). When that region is a reserved placeholder, the run is clipped to the room left in it (/ PAGE), and only then cut at the next section boundary as before. When the probe does not report a reserved placeholder - an address that already shows pages, or the title's own memory - the room is 0, sorunis 1 and the address maps page by page: the same call asmain, unchanged.So a run of consecutive section slices that crosses two reservations is now never attempted as one view: the batched call sees only addresses inside one placeholder, which is the case the 487s were coming from.
Why the cut alone was not enough. You are right that the physical pages say nothing about the placeholders:
section_runonly says "these are consecutive slices of one section", and the address layout is the title's. The cut was a guess about that layout; the probe asks the host instead.Tested.
cargo xwin test -p victory-hle --lib(x86_64-pc-windows-msvc, under Wine on Linux): 17 xmem tests pass, 0 failed, includingscatter_cuts_a_run_at_a_second_placeholder,scatter_maps_a_run_over_per_page_placeholdersandscatter_maps_runs_of_consecutive_addresses- the batched call is refused there by construction (its placeholders are one page each), the new probe keepsrunat 1, and the views after the fallback are unchanged.cargo xwin clippy -p victory-hle -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings: clean.What I still cannot say. No measurement that batching helps, and no game run: I have no Windows host and no run of the title. What I would want from @ruvenesh or @anasssssssss1 is the same build plus this PR at
679b1bb, three runs: expect 0 of the 186os error 487warnings (the batched call should now be attempted only inside one placeholder), andScatterMapsno larger thanScatterPages. If a 487 still appears with this head, the run passed the probe and the refusal is something else, and the counters will say which.Written with an AI assistant.
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.