Cut large title-memory allocations into sections of 64 MB #3

Manually merged
github merged 1 commit from github-bot/gh-3 into main 2026-12-04 01:57:18 +00:00 AGit
Owner

@⁠FeelsGoodMan2 on GitHub · 2026-11-30 00:23 UTC · original
FeelsGoodMan2:section-split → main · +168 −35 · 1 files · 1 commits · merged 2026-12-04 01:54 UTC

What this changes

Large allocations of title pages become several sections of 64 MB instead of one section of any size. Only crates/victory-hle/src/modules/xmem.rs changes.

  • VICTORY_SECTION_MB sets the size (default 64; 0: one section per allocation, as before).
  • Allocations up to 256 MB stay one section. The 185 MB 32-bit heap has to be one stretch of one section (arrange).
  • Under Wine an allocation stays one section.
  • The page numbers the title gets stay consecutive. If the host does not give all sections, those already made are closed and the call fails as before.
  • One log line when an allocation is cut.

Why

The title's pool of about 6.1 GB is one section today, and its pages are mapped as single 64 KB views (the source puts them at about 100,000; I have not counted them).

The host keeps the views of a section in one list under one lock. I recorded a CPU and context-switch trace of a sibling fork with the same mapping code. A system thread rebuilding large pages (MiRebuildLargePages -> MiTradePage -> MiTrimSharedPage -> MiTrimSection -> MiViewMayContainPage) goes through the views of a section. The title's thread in copy_page_mappings -> map_aliases -> MapViewOfFile3 / UnmapViewOfFile2 waits for that thread, 1-4 ms per page, one page at a time (VICTORY_MAP_THREADS=1 in play.ps1).

All three gaps over 60 ms in the submit thread (24 s of switch data) are almost all that wait (89-93 %):

Gap Title thread waiting for that system thread Waits
168 ms 157 ms 95
90 ms 80 ms 51
367 ms 342 ms 225
.

Tests

On this branch, Windows 11 build 26300, i5-13600KF, 32 GB RAM, RX 7800 XT:

  • cargo test --workspace --locked --no-fail-fast -- --test-threads=1: 1443 passed, 7 failed, 63 ignored. Failing: warm_bad_fingerprint_override_again_and_help, first_half_values_render_on_hardware_and_warp, a_geometry_program_is_a_geometry_shader, rectangles_are_drawn_whole, the_rectangle_stage_is_a_geometry_shader, repository_passes_policy, documented_switches_are_read. I have not compared them with an untouched main.
  • cargo test -p victory-hle --locked: all passed (the main target 234 passed, 5 ignored).
  • cargo clippy -p victory-hle --lib --tests --no-deps -- -D warnings: clean. The workspace clippy stops on errors in victory-shader and victory-loader, which this branch does not change.

Two new tests: the lengths of the sections (and that 185 MB stay in one), and mapping, aliasing, reading and writing pages across a cut. The second fails with VICTORY_SECTION_MB=0 (4,099 pages in one section) and passes by default.

AI disclosure

Written with an AI coding tool (Claude Code).

🤖 Generated with Claude Code

**@⁠FeelsGoodMan2** on GitHub · 2026-11-30 00:23 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/3) `FeelsGoodMan2:section-split` → `main` · +168 −35 · 1 files · 1 commits · merged 2026-12-04 01:54 UTC ## What this changes Large allocations of title pages become several sections of 64 MB instead of one section of any size. Only `crates/victory-hle/src/modules/xmem.rs` changes. - `VICTORY_SECTION_MB` sets the size (default 64; `0`: one section per allocation, as before). - Allocations up to 256 MB stay one section. The 185 MB 32-bit heap has to be one stretch of one section (`arrange`). - Under Wine an allocation stays one section. - The page numbers the title gets stay consecutive. If the host does not give all sections, those already made are closed and the call fails as before. - One log line when an allocation is cut. ## Why The title's pool of about 6.1 GB is one section today, and its pages are mapped as single 64 KB views (the source puts them at about 100,000; I have not counted them). The host keeps the views of a section in one list under one lock. I recorded a CPU and context-switch trace of a sibling fork with the same mapping code. A system thread rebuilding large pages (`MiRebuildLargePages` -> `MiTradePage` -> `MiTrimSharedPage` -> `MiTrimSection` -> `MiViewMayContainPage`) goes through the views of a section. The title's thread in `copy_page_mappings` -> `map_aliases` -> `MapViewOfFile3` / `UnmapViewOfFile2` waits for that thread, 1-4 ms per page, one page at a time (`VICTORY_MAP_THREADS=1` in `play.ps1`). All three gaps over 60 ms in the submit thread (24 s of switch data) are almost all that wait (89-93 %): | Gap | Title thread waiting for that system thread | Waits | |---:|---:|---:| | 168 ms | 157 ms | 95 | | 90 ms | 80 ms | 51 | | 367 ms | 342 ms | 225 | . ## Tests On this branch, Windows 11 build 26300, i5-13600KF, 32 GB RAM, RX 7800 XT: - `cargo test --workspace --locked --no-fail-fast -- --test-threads=1`: 1443 passed, 7 failed, 63 ignored. Failing: `warm_bad_fingerprint_override_again_and_help`, `first_half_values_render_on_hardware_and_warp`, `a_geometry_program_is_a_geometry_shader`, `rectangles_are_drawn_whole`, `the_rectangle_stage_is_a_geometry_shader`, `repository_passes_policy`, `documented_switches_are_read`. I have not compared them with an untouched `main`. - `cargo test -p victory-hle --locked`: all passed (the main target 234 passed, 5 ignored). - `cargo clippy -p victory-hle --lib --tests --no-deps -- -D warnings`: clean. The workspace clippy stops on errors in `victory-shader` and `victory-loader`, which this branch does not change. Two new tests: the lengths of the sections (and that 185 MB stay in one), and mapping, aliasing, reading and writing pages across a cut. The second fails with `VICTORY_SECTION_MB=0` (4,099 pages in one section) and passes by default. ## AI disclosure Written with an AI coding tool (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A pool of 6.1 GiB was one section with all its views in one list. While the
host rebuilds large pages it goes through that list for each shared page it
moves, and the title's mapping calls wait for it, 1 to 4 ms a page.

VICTORY_SECTION_MB sets the size (0: one section, as before). Allocations up
to 256 MB stay whole: the 32-bit heap has to be one stretch of one section.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 14:09:11 +00:00
Author
Owner

@⁠RiceShower0721 on GitHub · 2026-11-30 09:14 UTC · original

just asking if u don't mind is there a way 7000 series apply forced fsr4.1 instead of fsr3?

**@⁠RiceShower0721** on GitHub · 2026-11-30 09:14 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/3#issuecomment-7273941590) just asking if u don't mind is there a way 7000 series apply forced fsr4.1 instead of fsr3?
Author
Owner

@⁠cloph-dsp on GitHub · 2026-12-01 21:00 UTC · original

Verification (independent, AI-assisted: Hy4 flash). Windows, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC, commit-scoped worktree, dedicated CARGO_TARGET_DIR.

Base 30f351de58f5922bde62506d169b1ce16e09886e, head 054bf1e925469ffb9ad49ad8939471d48de76676. git diff --numstat → crates/victory-hle/src/modules/xmem.rs 168/35.

Both test names are new on the base:

git grep -F a_large_allocation_is_cut_into_sections_and_a_small_one_is_not      30f351de -- .
git grep -F pages_of_a_large_pool_lie_in_many_sections_and_map_across_them       30f351de -- .

→ no match, exit 1 for each.

git diff --check "30f351de..054bf1e9" → no output, exit 0.

$env:CARGO_TARGET_DIR='D:\Victory-Contrib\Revictory-Contrib\target-3'
cargo test --locked -p victory-hle --lib -- modules::xmem::tests::a_large_allocation_is_cut_into_sections_and_a_small_one_is_not --exact --test-threads=1 --quiet
cargo test --locked -p victory-hle --lib -- modules::xmem::tests::pages_of_a_large_pool_lie_in_many_sections_and_map_across_them --exact --test-threads=1 --quiet

Result, each: running 1 test, test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 238 filtered out (0.01s and 0.02s).

What they pin, with no device and no title files: the first checks section_lengths(n, one_heap, most) for 5/4/2/1 pages with a 2-page cap — 5 pages split [2, 2, 1], 4 → [2, 2], 2 → [2], 1 → [1] — plus both ways of asking for one section (one_heap, and most = 0), and then that the 32-bit heap's 185 MB allocation still lands in a single section and frees as one call. The second allocates ONE_SECTION + page_count_most() + 3 pages and asserts the page numbers still follow on by FRAMES, that every page's index < section.pages, no section holds more than page_count_most() pages, and that mapping across section boundaries works.

Caveats worth naming: both touch global xmem state, so they only mean anything run alone (--test-threads=1) — a parallel run against other xmem tests allocates into the same page table; and the second test's cross-section mapping arm is what proves the split is usable, while the first only proves the arithmetic of the split.

No game data.

**@⁠cloph-dsp** on GitHub · 2026-12-01 21:00 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/3#issuecomment-7325613441) Verification (independent, AI-assisted: Hy4 flash). Windows, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC, commit-scoped worktree, dedicated `CARGO_TARGET_DIR`. Base `30f351de58f5922bde62506d169b1ce16e09886e`, head `054bf1e925469ffb9ad49ad8939471d48de76676`. `git diff --numstat` → `crates/victory-hle/src/modules/xmem.rs` 168/35. Both test names are new on the base: ``` git grep -F a_large_allocation_is_cut_into_sections_and_a_small_one_is_not 30f351de -- . git grep -F pages_of_a_large_pool_lie_in_many_sections_and_map_across_them 30f351de -- . ``` → no match, exit 1 for each. `git diff --check "30f351de..054bf1e9"` → no output, exit 0. ``` $env:CARGO_TARGET_DIR='D:\Victory-Contrib\Revictory-Contrib\target-3' cargo test --locked -p victory-hle --lib -- modules::xmem::tests::a_large_allocation_is_cut_into_sections_and_a_small_one_is_not --exact --test-threads=1 --quiet cargo test --locked -p victory-hle --lib -- modules::xmem::tests::pages_of_a_large_pool_lie_in_many_sections_and_map_across_them --exact --test-threads=1 --quiet ``` Result, each: `running 1 test`, `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 238 filtered out` (0.01s and 0.02s). What they pin, with no device and no title files: the first checks `section_lengths(n, one_heap, most)` for 5/4/2/1 pages with a 2-page cap — 5 pages split `[2, 2, 1]`, 4 → `[2, 2]`, 2 → `[2]`, 1 → `[1]` — plus both ways of asking for one section (`one_heap`, and `most = 0`), and then that the 32-bit heap's 185 MB allocation still lands in a single section and frees as one call. The second allocates `ONE_SECTION + page_count_most() + 3` pages and asserts the page numbers still follow on by `FRAMES`, that every page's `index < section.pages`, no section holds more than `page_count_most()` pages, and that mapping across section boundaries works. Caveats worth naming: both touch global xmem state, so they only mean anything run alone (`--test-threads=1`) — a parallel run against other xmem tests allocates into the same page table; and the second test's cross-section mapping arm is what proves the split is usable, while the first only proves the arithmetic of the split. No game data.
github manually merged commit 7f2fcea181 into main 2026-12-04 01:57:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.