HLE: map a page scatter in runs, not one page at a time #1264

Open
github-bot wants to merge 9 commits from github-bot/gh-1264 into main AGit
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 16:56 UTC · original
pablogonz12:up/x254 → main · +333 −17 · 3 files · 9 commits · open

What

XMemMapPhysicalPagesScatter called XMemMapPhysicalPages once 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 VirtualQuery about 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-hle xmem:: 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 measured in game yet: no run with this branch against a baseline (the two world runs I have queued are other fixes).

Not tested

  • In game; native Windows.
  • The two-placeholder test passes here with and without the cut: Wine maps that adjacent pair either way, so it pins the intended split rather than reproducing the 487 crash.

Written with an AI assistant.

**@⁠pablogonz12** on GitHub · 2026-11-24 16:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264) `pablogonz12:up/x254` → `main` · +333 −17 · 3 files · 9 commits · open ## What `XMemMapPhysicalPagesScatter` called `XMemMapPhysicalPages` once 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 `VirtualQuery` about 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-hle` `xmem::` 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 measured in game yet: no run with this branch against a baseline (the two world runs I have queued are other fixes). ## Not tested - In game; native Windows. - The two-placeholder test passes here with and without the cut: Wine maps that adjacent pair either way, so it pins the intended split rather than reproducing the 487 crash. Written with an AI assistant.
Idea from ivall/xcl#254: XCL's scatter asked VirtualQuery about every page
whose home it mapped, and the query's cost grew with the run, so n pages
cost O(n^2) (16,384 pages: 29 s there). Scarlight has no per-page query --
a page costs one unmap, one view and one commit, linear in the pages -- so
nothing here is quadratic. Consecutive addresses still paid those three
system calls per 64 KiB page though: XMemMapPhysicalPagesScatter called
XMemMapPhysicalPages once per entry, which defeated the run batching that
call already does.

Now addresses given in consecutive pages 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), and a run that spans two
placeholders -- which cannot be one view -- falls back to the per-page
calls, so every case the old code mapped still maps.

Diagnostics: the copy line now reports page scatters, the pages they name
and the map calls they made, so a run tells whether the title scatters at
all and how much of it batches.
The module is not referenced here and its file lives on another branch; with
--all-features the build stopped on a missing producers.rs.

Written with an AI assistant.
C::Scatter was added once per run, so a call with two runs counted
twice; it is now added once per call, above the loop. C::ScatterMaps
in the per-page fallback sat after the failure check, so a failed
attempt went uncounted; it is now added before the call. The test
comment above the two-address unmap said three.
A run of consecutive addresses was mapped in one XMemMapPhysicalPages call
even when it crossed two reservations; that call unmaps the whole range
first and then fails (the crash on anasssssssss1's machine logged os error
487), leaving pages past the failure unmapped where the old per-page path
left them alone. A run is now cut where its pages stop being consecutive
slices of one section, which is the most one call can map and always sits
inside one placeholder. The new test reserves two placeholders that are
adjacent and maps a page in each through one scatter call.
copystat.rs: both sides added to the enum and the per-frame line, so the
two are kept side by side (COUNTERS 57 -> 64), main's heap slot and
view-wait times stay before the compare, and the scatter counts stay at
the end next to their arguments. xmem.rs merged cleanly.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:35 +00:00
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 17:18 UTC · original

Fixed in 204ec23: the port carried a mod producers; line whose file lives on another branch, so --all-features stopped on the missing producers.rs; that line is gone. Checked with cargo xwin clippy --workspace --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings (clean), the same without --all-features (clean), and victory-hle xmem:: under Wine: 11 passed, 0 failed.

**@⁠pablogonz12** on GitHub · 2026-11-24 17:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7139007920) Fixed in 204ec23: the port carried a `mod producers;` line whose file lives on another branch, so `--all-features` stopped on the missing `producers.rs`; that line is gone. Checked with `cargo xwin clippy --workspace --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings` (clean), the same without `--all-features` (clean), and `victory-hle xmem::` under Wine: 11 passed, 0 failed.
Author
Owner

@⁠anasssssssss1 on GitHub · 2026-11-24 18:07 UTC · original

Tried this on top of r4tedx's integration/testers update 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:

WARN victory_hle::modules::xmem: mapping physical pages failed (not a placeholder?) address=0x121600000 len=1376256 error=Attempt to access invalid address. (os error 487)
WARN victory_hle::modules::xmem: mapping physical pages failed (not a placeholder?) address=0x121e00000 len=2031616 error=Attempt to access invalid address. (os error 487)
WARN victory_hle::modules::xmem: mapping physical pages failed (not a placeholder?) address=0x122000000 len=2949120 error=Attempt to access invalid address. (os error 487)
first-chance exception 0xc0000005 at victory-image+0x11171a8 (read 0x10cd0e3b8: reserved, never committed)

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.

**@⁠anasssssssss1** on GitHub · 2026-11-24 18:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7140198901) Tried this on top of r4tedx's `integration/testers` update 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: ``` WARN victory_hle::modules::xmem: mapping physical pages failed (not a placeholder?) address=0x121600000 len=1376256 error=Attempt to access invalid address. (os error 487) WARN victory_hle::modules::xmem: mapping physical pages failed (not a placeholder?) address=0x121e00000 len=2031616 error=Attempt to access invalid address. (os error 487) WARN victory_hle::modules::xmem: mapping physical pages failed (not a placeholder?) address=0x122000000 len=2949120 error=Attempt to access invalid address. (os error 487) first-chance exception 0xc0000005 at victory-image+0x11171a8 (read 0x10cd0e3b8: reserved, never committed) ``` 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.
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-24 23:28 UTC · original

Both fixed in 81c4ffd3:

  1. the mod producers; line is gone (it came from another branch; stats only re-exports copystat);
  2. C::Scatter is now added once per call, above the run loop, so a call with two runs counts once; C::ScatterMaps in 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 warnings clean (also without --all-features); cargo xwin test -p victory-hle --lib 95 passed, 3 failed (window and loopback tests, no display/network in this Wine prefix — same as on main); cargo xwin test -p victory-gpu --lib 80 passed.

Not tested here: native Windows build, which your run covers. Thanks for the review.

AI-assisted (Claude).

**@⁠pablogonz12** on GitHub · 2026-11-24 23:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7147449089) Both fixed in 81c4ffd3: 1. the `mod producers;` line is gone (it came from another branch; `stats` only re-exports `copystat`); 2. `C::Scatter` is now added once per call, above the run loop, so a call with two runs counts once; `C::ScatterMaps` in 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 warnings` clean (also without `--all-features`); `cargo xwin test -p victory-hle --lib` 95 passed, 3 failed (window and loopback tests, no display/network in this Wine prefix — same as on main); `cargo xwin test -p victory-gpu --lib` 80 passed. Not tested here: native Windows build, which your run covers. Thanks for the review. AI-assisted (Claude).
Author
Owner

@⁠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 main plus the counter and test-comment fixes. The two reports of an in-game crash with this PR are still unexplained.

  • @⁠ruvenesh's run was on 41efca3, which already has the section_run cut. It logged 186 os error 487 warnings and then a 0xc0000005 on 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.
  • The comment in XMemMapPhysicalPagesScatter says 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.
  • The VirtualQuery pre-check you proposed (batch only when the whole run is one reserved placeholder) is not on the branch.
  • There is still no measurement that batching helps.

What would change the verdict: the VirtualQuery pre-check, or a fix for the path that leaves a page uncommitted after a refused batched call. Then a run from a tester with the Scatter/ScatterPages/ScatterMaps counters, 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

**@⁠Marvisak** on GitHub · 2026-11-25 01:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7149448773) · edited 2026-11-26 00:22 UTC <!-- victory-triage v1 head=e9dfb7c691fa2e06cb678ab4fbfeba521d7d4459 verdict=needs-work at=2026-11-26T00:22:00Z --> Automated triage for the maintainers. **Needs work.** The new head is a merge of `main` plus the counter and test-comment fixes. The two reports of an in-game crash with this PR are still unexplained. - @⁠ruvenesh's run was on `41efca3`, which already has the `section_run` cut. It logged 186 `os error 487` warnings and then a `0xc0000005` on 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. - The comment in `XMemMapPhysicalPagesScatter` says 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. - The `VirtualQuery` pre-check you proposed (batch only when the whole run is one reserved placeholder) is not on the branch. - There is still no measurement that batching helps. What would change the verdict: the `VirtualQuery` pre-check, or a fix for the path that leaves a page uncommitted after a refused batched call. Then a run from a tester with the `Scatter`/`ScatterPages`/`ScatterMaps` counters, 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](https://claude.ai/code)_
Author
Owner

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

Addressed in 1433a4a9 (head moved from 81c4ffd3):

  • The crash. The batched call could span two reservations: it unmaps the whole range first, then fails (the 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 one XMemMapPhysicalPages call 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.
  • The test. scatter_cuts_a_run_at_a_second_placeholder reserves 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.
  • Verified with cargo xwin clippy -p victory-hle -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings (clean) and cargo xwin test -p victory-hle --lib: 98 passed, 1 failed (net::only_loopback_is_reachable, ws2_32 lacks WSAConnectByList here, same on main), including both scatter tests.
  • Honest limit: that test passes on Wine with and without the cut (Wine maps the adjacent pair either way), so it pins the intended split rather than reproducing the 487 crash; a native Windows reproducer is still needed.

Still not measured in game.

AI-assisted (Claude).

**@⁠pablogonz12** on GitHub · 2026-11-25 01:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7150028778) Addressed in 1433a4a9 (head moved from 81c4ffd3): - **The crash.** The batched call could span two reservations: it unmaps the whole range first, then fails (the `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 one `XMemMapPhysicalPages` call 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. - **The test.** `scatter_cuts_a_run_at_a_second_placeholder` reserves 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. - Verified with `cargo xwin clippy -p victory-hle -p victory-gpu --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings` (clean) and `cargo xwin test -p victory-hle --lib`: 98 passed, 1 failed (`net::only_loopback_is_reachable`, `ws2_32` lacks `WSAConnectByList` here, same on main), including both scatter tests. - Honest limit: that test passes on Wine with and without the cut (Wine maps the adjacent pair either way), so it pins the intended split rather than reproducing the 487 crash; a native Windows reproducer is still needed. Still not measured in game. AI-assisted (Claude).
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-25 04:31 UTC · original

All three are addressed on the current head 87e17a602 (the merge of main into up/x254):

  1. mod producers; is gone from crates/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 warnings is clean at this head (checked here, not on Windows).
  2. add(C::Scatter, 1) now sits before the run loop (crates/victory-hle/src/modules/xmem.rs:742), so it counts calls and ScatterMaps counts runs.
  3. The test comment now reads "Two consecutive addresses without pages unmap as one run", which matches the two addresses passed.

Not tested: no game run at this head.

**@⁠pablogonz12** on GitHub · 2026-11-25 04:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7152921884) All three are addressed on the current head `87e17a602` (the merge of `main` into `up/x254`): 1. `mod producers;` is gone from `crates/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 warnings` is clean at this head (checked here, not on Windows). 2. `add(C::Scatter, 1)` now sits before the run loop (`crates/victory-hle/src/modules/xmem.rs:742`), so it counts calls and `ScatterMaps` counts runs. 3. The test comment now reads "Two consecutive addresses without pages unmap as one run", which matches the two addresses passed. Not tested: no game run at this head.
Author
Owner

@⁠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_run is 3 and the direct three-page XMemMapPhysicalPages call 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 warnings clean, 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 main for multi-page maps, but batching scatters creates more such views). #1224 works on the placeholder side of the same area.

AI-assisted (Claude).

**@⁠pablogonz12** on GitHub · 2026-11-25 11:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7161113011) 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_run` is 3 and the direct three-page `XMemMapPhysicalPages` call 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 warnings` clean, 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 `main` for multi-page maps, but batching scatters creates more such views). #1224 works on the placeholder side of the same area. AI-assisted (Claude).
Author
Owner

@⁠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-msvc diagnostics 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:

  • 186 warnings mapping physical pages failed (not a placeholder?) ... os error 487 from about 2 s into the world load. The lengths were mostly 262144 (42 times), 196608 (31) and 131072 (24).
  • About a minute later the title died with 0xc0000005: two reads of a page that was reserved but never committed ("reserved, never committed"), then the usual crash log.

Controls:

  • The build without this PR (same stack minus #1264, produced by reverting its merge commit cleanly) logged 0 of those warnings and 0 crashes, and ran to 432 s with the world frame captured.
  • The earlier build without any of the six PRs logged 0 of those warnings over a 15+ minute run.

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

**@⁠ruvenesh** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7167408003) Test report on Linux + Proton (GE-Proton11-14), RTX 3060 12 GB, `x86_64-pc-windows-msvc` diagnostics 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:** - 186 warnings `mapping physical pages failed (not a placeholder?) ... os error 487` from about 2 s into the world load. The lengths were mostly 262144 (42 times), 196608 (31) and 131072 (24). - About a minute later the title died with `0xc0000005`: two reads of a page that was reserved but never committed ("reserved, never committed"), then the usual crash log. **Controls:** - The build without this PR (same stack minus #1264, produced by reverting its merge commit cleanly) logged 0 of those warnings and 0 crashes, and ran to 432 s with the world frame captured. - The earlier build without any of the six PRs logged 0 of those warnings over a 15+ minute run. 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).
Author
Owner

@⁠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 when MapViewOfFile3(..., 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)? If ScatterMaps exceeds ScatterPages by roughly the number of warnings, every refused run was retried per page, and XMemMapPhysicalPagesScatter still 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:

  1. Ask the host before trying: VirtualQuery the 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 refused VirtualFree/MapViewOfFile3 pair from the picture completely.
  2. Only if the counters show a failed fallback, look at whether a refused batched 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 19:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7172753659) 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 when `MapViewOfFile3(..., 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`)? If `ScatterMaps` exceeds `ScatterPages` by roughly the number of warnings, every refused run was retried per page, and `XMemMapPhysicalPagesScatter` still 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: 1. Ask the host before trying: `VirtualQuery` the 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 refused `VirtualFree`/`MapViewOfFile3` pair from the picture completely. 2. Only if the counters show a failed fallback, look at whether a refused batched `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.
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-25 23:57 UTC · original

Thanks for the two code points - both are fixed in the current head (e9dfb7c69).

  1. mod producers; is gone: it was dropped in 204ec23c8 ("GPU: drop the producers line the port carried, so --all-features builds"). stats now only re-exports copystat::{C, add}.
  2. C::Scatter counts calls: add(C::Scatter, 1) now sits at the top of XMemMapPhysicalPagesScatter, before the run loop. Per run we add ScatterPages(run) and ScatterMaps(1); each per-page fallback call adds ScatterMaps(1) as well, so the counters tell calls, runs and pages apart. The doc comment matches that.
  3. Nit fixed: the "Three consecutive addresses" test now passes three addresses.

One limit on verification: this machine is Linux, and the cfg(windows) half of victory-gpu does not compile for the host target, so I cannot re-run that --all-features command here. On the non-Windows side the command still fails in crates/victory-loader/src/publish.rs (dead NEXT_STAGING / write_if_changed), with or without this branch; those files are not touched by the PR. The producers error 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 new xmem ones changed.

**@⁠pablogonz12** on GitHub · 2026-11-25 23:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7178246894) Thanks for the two code points - both are fixed in the current head (`e9dfb7c69`). 1. `mod producers;` is gone: it was dropped in `204ec23c8` ("GPU: drop the producers line the port carried, so --all-features builds"). `stats` now only re-exports `copystat::{C, add}`. 2. `C::Scatter` counts calls: `add(C::Scatter, 1)` now sits at the top of `XMemMapPhysicalPagesScatter`, before the run loop. Per run we add `ScatterPages(run)` and `ScatterMaps(1)`; each per-page fallback call adds `ScatterMaps(1)` as well, so the counters tell calls, runs and pages apart. The doc comment matches that. 3. Nit fixed: the "Three consecutive addresses" test now passes three addresses. One limit on verification: this machine is Linux, and the `cfg(windows)` half of `victory-gpu` does not compile for the host target, so I cannot re-run that `--all-features` command here. On the non-Windows side the command still fails in `crates/victory-loader/src/publish.rs` (dead `NEXT_STAGING` / `write_if_changed`), with or without this branch; those files are not touched by the PR. The `producers` error 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 new `xmem` ones changed.
Consecutive slices of one section at consecutive addresses can still cross
two reservations: the pages say nothing about where a placeholder ends, so
a batched call was refused (os error 487) and, worse, the whole range had
already been unmapped. One VirtualQueryEx at the run's first address now
clips the run to the room left in that placeholder; an address that is not
a reserved placeholder (already shown, or the title's own memory) maps page
by page as before.
Author
Owner

@⁠mercuryVM on GitHub · 2026-11-24 17:10 UTC · original · requested changes

Tested 4b8eef97 on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle passes (95 passed). With diagnostics on, though, the build breaks:

cargo clippy -p victory-hle -p victory-gpu --all-targets --all-features
error[E0583]: file not found for module `producers`
  1. crates/victory-gpu/src/lib.rs:30 declares mod producers; (under cfg(all(windows, feature = "diagnostics"))), but the PR doesn't add producers.rs. It looks like a leftover from another branch. Fix: drop the line, or add the file. stats only needs the copystat re-export.

  2. C::Scatter counts runs, not calls (crates/victory-hle/src/modules/xmem.rs, in the run loop). add(C::Scatter, 1) sits inside the while i < n loop, next to add(C::ScatterMaps, 1), so the two counters are always equal. The doc comment says Scatter counts XMemMapPhysicalPagesScatter calls. Fix: move add(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:

  • A run breaks when the address stops being consecutive and also when a page switches between zero and non-zero.
  • A non-zero run passes pages.add(i) with run entries, which stays inside the n the title gave.
  • A failed multi-page run retries page by page, as the old code did.
  • The new test covers mixed zero/non-zero runs and null pages.

AI-assisted (Claude Code).

**@⁠mercuryVM** on GitHub · 2026-11-24 17:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#pullrequestreview-6043907518) · **requested changes** Tested 4b8eef97 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` passes (95 passed). With diagnostics on, though, the build breaks: ``` cargo clippy -p victory-hle -p victory-gpu --all-targets --all-features error[E0583]: file not found for module `producers` ``` 1. **`crates/victory-gpu/src/lib.rs:30` declares `mod producers;`** (under `cfg(all(windows, feature = "diagnostics"))`), but the PR doesn't add `producers.rs`. It looks like a leftover from another branch. Fix: drop the line, or add the file. `stats` only needs the `copystat` re-export. 2. **`C::Scatter` counts runs, not calls** (`crates/victory-hle/src/modules/xmem.rs`, in the run loop). `add(C::Scatter, 1)` sits inside the `while i < n` loop, next to `add(C::ScatterMaps, 1)`, so the two counters are always equal. The doc comment says Scatter counts `XMemMapPhysicalPagesScatter` calls. Fix: move `add(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: - A run breaks when the address stops being consecutive and also when a page switches between zero and non-zero. - A non-zero run passes `pages.add(i)` with `run` entries, which stays inside the `n` the title gave. - A failed multi-page run retries page by page, as the old code did. - The new test covers mixed zero/non-zero runs and null pages. AI-assisted (Claude Code).
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-26 10:30 UTC · original

The VirtualQuery pre-check is on the branch now (679b1bb), before the run is used rather than after it is refused.

What it does. One VirtualQueryEx at 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, so run is 1 and the address maps page by page: the same call as main, 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_run only 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, including scatter_cuts_a_run_at_a_second_placeholder, scatter_maps_a_run_over_per_page_placeholders and scatter_maps_runs_of_consecutive_addresses - the batched call is refused there by construction (its placeholders are one page each), the new probe keeps run at 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 186 os error 487 warnings (the batched call should now be attempted only inside one placeholder), and ScatterMaps no larger than ScatterPages. 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.

**@⁠pablogonz12** on GitHub · 2026-11-26 10:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1264#issuecomment-7189459292) The `VirtualQuery` pre-check is on the branch now (`679b1bb`), before the run is used rather than after it is refused. **What it does.** One `VirtualQueryEx` at 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, so `run` is 1 and the address maps page by page: the same call as `main`, 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_run` only 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**, including `scatter_cuts_a_run_at_a_second_placeholder`, `scatter_maps_a_run_over_per_page_placeholders` and `scatter_maps_runs_of_consecutive_addresses` - the batched call is refused there by construction (its placeholders are one page each), the new probe keeps `run` at 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 186 `os error 487` warnings (the batched call should now be attempted only inside one placeholder), and `ScatterMaps` no larger than `ScatterPages`. 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.
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/1264/head:github-bot/gh-1264'
git switch 'github-bot/gh-1264'

Merge

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