xmem: commit physical pages in pieces, and report the real count #561

Open
JoshRob297 wants to merge 1 commit from upstream-pr/561 into main
JoshRob297 commented 2026-11-24 04:56:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by JoshRob297 on 2026-11-24T04:56:26Z.


Addresses #23.

A title that asks for a large block of physical pages fails outright when the host cannot commit all of it at once. The console ABI does not promise one contiguous commitment: the request carries a page count, the title compares what it got, and a host can commit what it allows in pieces and report the real count instead of failing the whole call.

What this changes (crates/victory-hle/src/modules/xmem.rs)

  • The physical-page allocation walks the request in pieces and commits what the host accepts, instead of a single commit that fails as a unit.
  • The count actually committed is what the title receives, so a title that compares the returned count sees the truth rather than a success it cannot use.
  • The startup path names the commit limit when the reservation cannot be satisfied at all, so a machine that cannot hold it says so at the point of failure instead of dying later inside the title.

Verification

cargo +1.98.1 check -p victory-hle --target x86_64-pc-windows-msvc
  Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.90s

That is a type-check against the target this project pins in rust-toolchain.toml, not a run: the change is in the physical-page path and has not been exercised against a title.

What it does not fix

If the title requires the full reservation contiguously — as opposed to asking for a count and comparing — this does not help, and the way to tell is to log the count the title asks for against the count the host can commit. I have not measured that on the failing machine.

Provenance

The measurement this rests on comes from static analysis of the retail executable's allocation call sites (flag word, 64 KiB unit, and one call site that compares the returned page count), not from the source of this project. No game data is included here: no paths, no container names, no hashes.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574935605 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/561). Originally posted by [JoshRob297](https://github.com/JoshRob297) on 2026-11-24T04:56:26Z. --- Addresses #23. A title that asks for a large block of physical pages fails outright when the host cannot commit all of it at once. The console ABI does not promise one contiguous commitment: the request carries a page count, the title compares what it got, and a host can commit what it allows in pieces and report the real count instead of failing the whole call. **What this changes** (`crates/victory-hle/src/modules/xmem.rs`) - The physical-page allocation walks the request in pieces and commits what the host accepts, instead of a single commit that fails as a unit. - The count actually committed is what the title receives, so a title that compares the returned count sees the truth rather than a success it cannot use. - The startup path names the commit limit when the reservation cannot be satisfied at all, so a machine that cannot hold it says so at the point of failure instead of dying later inside the title. **Verification** ``` cargo +1.98.1 check -p victory-hle --target x86_64-pc-windows-msvc Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.90s ``` That is a type-check against the target this project pins in `rust-toolchain.toml`, not a run: the change is in the physical-page path and has not been exercised against a title. **What it does not fix** If the title requires the full reservation contiguously — as opposed to asking for a count and comparing — this does not help, and the way to tell is to log the count the title asks for against the count the host can commit. I have not measured that on the failing machine. **Provenance** The measurement this rests on comes from static analysis of the retail executable's allocation call sites (flag word, 64 KiB unit, and one call site that compares the returned page count), not from the source of this project. No game data is included here: no paths, no container names, no hashes.
catminou4 commented 2026-11-24 13:01:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:44:29Z.

Review: COMMENTED


Test-merge with current main (ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touched lower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039403895 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/561#pullrequestreview-6039403895). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:44:29Z. **Review:** COMMENTED --- Test-merge with current main (`ffe310e`) **conflicts** — needs a rebase. Main moved recently (PR #566 waterfall loops touched `lower.rs`/`resource.rs`/`valu_tests.rs`), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.
jeremygold02 commented 2026-11-24 18:06:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T17:52:59Z.


Verification ran against PR head 3c02d8cf89470f487bab9c3a207da75084aca8b2; the PR was open at refresh.

  • cargo test -j 1 -p victory-hle xmem::tests: 6 passed, 1 failed: modules::xmem::tests::allocated_physical_pages_are_committed.
  • cargo test -j 1 -p victory-hle xmem::tests -- --test-threads=1: the same 6 passed and 1 failed, so the failure reproduces without parallel test interference.

The failure is at xmem.rs:1112: VirtualFree(reserve, 0, MEM_RELEASE) returns 0. The test maps pages into the reservation, then calls XMemFreePhysicalPages, which removes the page-number records but does not unmap the view. XMemMapPhysicalPages with null pages is the unmap path; the test needs to unmap before releasing the reservation.

commits_across_a_piece_boundary and the other five xmem tests pass. The focused tests cover the 64-MiB commit boundary and a 4-page allocation, but do not simulate host commit-limit exhaustion or a short allocation.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139841293 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/561#issuecomment-7139841293). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T17:52:59Z. --- Verification ran against PR head [`3c02d8cf89470f487bab9c3a207da75084aca8b2`](https://github.com/Marvisak/VIctory/commit/3c02d8cf89470f487bab9c3a207da75084aca8b2); the PR was open at refresh. - `cargo test -j 1 -p victory-hle xmem::tests`: 6 passed, 1 failed: `modules::xmem::tests::allocated_physical_pages_are_committed`. - `cargo test -j 1 -p victory-hle xmem::tests -- --test-threads=1`: the same 6 passed and 1 failed, so the failure reproduces without parallel test interference. The failure is at [`xmem.rs:1112`](https://github.com/Marvisak/VIctory/blob/3c02d8cf89470f487bab9c3a207da75084aca8b2/crates/victory-hle/src/modules/xmem.rs#L1112): `VirtualFree(reserve, 0, MEM_RELEASE)` returns 0. The test maps pages into the reservation, then calls `XMemFreePhysicalPages`, which removes the page-number records but does not unmap the view. [`XMemMapPhysicalPages`](https://github.com/Marvisak/VIctory/blob/3c02d8cf89470f487bab9c3a207da75084aca8b2/crates/victory-hle/src/modules/xmem.rs#L607) with null pages is the unmap path; the test needs to unmap before releasing the reservation. `commits_across_a_piece_boundary` and the other five xmem tests pass. The focused tests cover the 64-MiB commit boundary and a 4-page allocation, but do not simulate host commit-limit exhaustion or a short allocation. This verification was AI-assisted.
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:43Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/src/modules/xmem.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148499400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/561#issuecomment-7148499400). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:43Z. --- <!-- victory-triage v1 head=3c02d8cf89470f487bab9c3a207da75084aca8b2 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-hle/src/modules/xmem.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
jeremygold02 commented 2026-11-25 04:06:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:13:14Z.


Triage verdict — Rebase and verify short allocations (3c02d8c)

Evidence

  • The rebase changes the scope of this PR. Merged #51 already records the failing commit request and system commit figures in the crash log, with paging-file guidance.
  • The distinct change in 3c02d8c is charging pages at allocation time and returning a short count.
  • There is a Wine constraint on the rebase too: main uses SEC_COMMIT under Wine to avoid repeated wineserver scans.

Checks and limits

  • On current main 940d32f, cargo test -p victory-hle commit_limit_report_includes_request_and_system_commit passed with synthetic inputs. That verifies the diagnostic text; it does not force a host allocation failure.
  • The earlier cleanup failure is separate from that missing coverage.

Next step

  • I’d rebase around that behavior, retain #51’s crash-log path when resolving the commit conflict, and test a deterministic partial commit before calling it ready. The acceptance case should assert the returned count, which page IDs can still be mapped, and what happens when nothing can be committed.
  • Keep that platform path or provide a Wine comparison before replacing it with SEC_RESERVE and piece commits.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151706503 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/561#issuecomment-7151706503). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:13:14Z. --- **Triage verdict — Rebase and verify short allocations** (`3c02d8c`) **Evidence** - The rebase changes the scope of this PR. Merged #51 already records the failing commit request and system commit figures in the crash log, with paging-file guidance. - The distinct change in `3c02d8c` is charging pages at allocation time and returning a short count. - There is a Wine constraint on the rebase too: [main uses `SEC_COMMIT` under Wine](https://github.com/Marvisak/VIctory/blob/940d32f69b22265690a0b5a15d6ded572ba33baf/crates/victory-hle/src/modules/xmem.rs#L483-L487) to avoid repeated wineserver scans. **Checks and limits** - On current main `940d32f`, `cargo test -p victory-hle commit_limit_report_includes_request_and_system_commit` passed with synthetic inputs. That verifies the diagnostic text; it does not force a host allocation failure. - The [earlier cleanup failure](https://github.com/Marvisak/VIctory/pull/561#issuecomment-7139841293) is separate from that missing coverage. **Next step** - I’d rebase around that behavior, retain #51’s crash-log path when resolving the `commit` conflict, and test a deterministic partial commit before calling it ready. The acceptance case should assert the returned count, which page IDs can still be mapped, and what happens when nothing can be committed. - Keep that platform path or provide a Wine comparison before replacing it with `SEC_RESERVE` and piece commits. This verification was AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/561:upstream-pr/561'
git switch 'upstream-pr/561'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/561'
git switch 'upstream-pr/561'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/561'
git switch 'upstream-pr/561'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/561'
git switch 'main'
git merge --squash 'upstream-pr/561'
git switch 'main'
git merge --ff-only 'upstream-pr/561'
git switch 'main'
git merge 'upstream-pr/561'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!561
No description provided.