Skip to content

Physical page allocations come from sections of up to 2 MiB (VICTORY_SECTION_MB, off by default; #1089) - #1274

Open
CuteBooty wants to merge 2 commits into
fxceless:mainfrom
CuteBooty:sections-2mib
Open

CuteBooty wants to merge 2 commits into
fxceless:mainfrom
CuteBooty:sections-2mib

Conversation

@CuteBooty

Copy link
Copy Markdown

At 46bf5351, each physical-page request creates one Windows section. Fork run 307 measured 45 ms per usual frame and 197 ms per streaming frame in remapping, mostly in the system's own calls; run 308 found no redundant mapping among 103,024 pages. This ports RyanCase94's idea and first patch from #1089: a request is backed by sections of at most 2 MiB, so a remap touches small sections.

Switch. VICTORY_SECTION_MB=2 turns it on. Unset or 0 keeps one section per request, as now. It is off by default here on purpose: with it on, a large request has several section handles, which matters to code that opens a whole allocation as one heap, and it has not been run under Wine. In my own tree it has been on by default for about fifteen runs.

Measured (my tree, not this tip: Ryzen 5 3600, RTX 3070 8 GB, Windows 11, Series S; 5-second log lines):

one section per request sections of up to 2 MiB
texture refresh waiting on the title's remaps, per frame 37 ms on average about 1 ms
worst single wait 816 ms 28 ms and 62 ms (two runs)
samples over 20 ms 68 of 228 1 of 314 and 1 of 331

The lower waits held in every run since. Frame time itself did not get shorter. In play, the half-second freezes while driving were gone.

What changed. xmem.rs: XMemAllocatePhysicalPages and Section::drop (the cap and the cleanup). inplace.rs: title_memory_section, title_memory_section_closed, write_own, census_of track individual sections. One test checks page numbering and a two-byte write across the 2 MiB boundary, with the switch off and on.

State. Ported by hand onto this tip. cargo clippy --workspace --all-targets -- -D warnings is clean, cargo test --workspace passes (617), the asset policy passes. Not yet run in the game on this tip; the numbers above are from my tree (CuteBooty/victory-8gb), where the same change is VICTORY_SECTION_MB, default 2.

Credit: RyanCase94 (#1089) for the idea and the first patch.

🤖 Generated with Claude Code

…SECTION_MB, off by default)

After RyanCase94's idea and first patch in fxceless#1089. With VICTORY_SECTION_MB=2 a request
is backed by sections of at most 2 MiB instead of one section per request, so a
remap touches small sections; 0 or unset keeps one section per request.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@HLVM04

HLVM04 commented Nov 26, 2026

Copy link
Copy Markdown

An in-game data point on NVIDIA for the same idea, though not this PR's port: we applied the original 2 MiB section patch from #1089 alone on our fork-based stack (RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, Windows 11 build 26200, Series S).

  • p90 frame time 105 ms, against about 118 ms before. Median 73 ms.
  • Copy-back 18 ms a frame. No crash or device loss.

Like your 3070 table, the clear change was in the long frames. This is from a few runs, so scene variance is possible, and it was on Windows only.

@Garu667

Garu667 commented Nov 26, 2026

Copy link
Copy Markdown

Data point from an RTX 3080 10 GB (Series X, f6a09d3 + this PR, merged with no conflict), same route twice (boat mission, 30 s standing then ~3 min driving), README set + CARD_SYNC_BATCH=1 CARD_HASH_WIDE=1:

SECTION_MB unset SECTION_MB=2
remapping time (frame log, mean per frame) 42.8 ms 5.0 ms
world fps, median 8.5 8.4
5 s windows whose longest frame > 0.5 s / > 1 s 22 / 10 of 86 18 / 11 of 86
worst frame 3.6 s 3.7 s

So the remapping cost drops about 8x here too, but on this tree and card the long freezes while driving stay: the texture refresh's "waiting for title memory to hold still" reads 0 ms with or without the switch, and VICTORY_FRAME_WHY2 (#1275) shows the submit worker idle through the longest frames, so they come from somewhere else. No device loss, picture unchanged. One run each.

@CuteBooty

Copy link
Copy Markdown
Author

Thank you both for running it, and on the fork's own code, which I had not done.

It is the same shape as on the 3070: the remapping cost drops by a large factor and the frame rate by itself does not move. What went away here were the 0.3-0.8 s stalls while driving, which on my tree were the texture refresh waiting for the title's remaps; on a tree where that wait already reads 0 ms, as in the RTX 3080 run, there is nothing for it to remove, and the long frames there have another cause. I would leave the switch off by default as proposed.

KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
…xceless#1276 on top

What the ten commits bring (two changes of the translator with no
switch, the six-line box, seven switches off by default), and what one
session measured here on build 73df053 with the ten switches of Status
and the usual manoeuvre, its shader cache warm but for 380 programs:
1,794 frames, 6.41 fps, median frame 146 ms, 95th percentile 218; all
28 scripted presses read; the same room with the faults it had; no
error line, no device loss. Before the merge: 6.52 to 6.67 fps, 143 to
147 ms, in five sessions. Private memory peaked at 16.5 GB (17.9 before).

Rows for the skin bake's own textures (fxceless#1264, in with the merge and off
by default; measured here with this tree's port: 185 wrong reads to
none), for the sections of 2 MiB (fxceless#1274) and for the buffer copies let
go with their view heap (fxceless#1276).

Tests on the merged tree: victory-shader 258, victory-gpu 281 with
diagnostics, victory-hle 128, the asset policy passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@KainanP

KainanP commented Nov 26, 2026

Copy link
Copy Markdown

A synthetic reproduction of #1089's stall, without the game. It shows the same effect, and it can be rerun on any machine.

The method is what the title does to its physical pages. A 4 GiB pagefile-backed section (SEC_RESERVE) is mapped one 64 KiB view per page into placeholders, the views are committed, and every page is touched. Then, for 10 s, a random page is remapped at a random address (unmap, MapViewOfFile3 into the placeholder, commit). A second thread meanwhile makes, touches and frees 2 GiB, the kind of memory churn that wakes the large-page rebuild worker. The run alternates one section with 2 MiB sections over 5 rounds in one process.

i7-14650HX, 32 GB, Windows 11 26200, release build, median of 5 rounds, going through VIctory's own XMemAllocatePhysicalPages / XMemMapPhysicalPages:

remaps/s median call p99 call calls of 1 ms or more
one section per request 6,644 16.3 µs 4,093 µs 1,386 (8.6 s of 10 s)
2 MiB sections 50,607 14.4 µs 36.8 µs 28 (1.0 s)
  • Raw Windows calls: a standalone version with no VIctory code gives the same picture. In 15 s, one section had 1,784 calls of 1 ms or more against 45 with 2 MiB sections.
  • What triggers it: a thread that only empties the working set (K32EmptyWorkingSet, no allocations) produces no stall in either mode. The trigger is memory being made and freed elsewhere, which a streaming title does all the time.
  • Without that churn: 2 MiB sections are about 8 % slower per remap (10.0 µs against 9.1 µs median). That is a small fixed price against stalls of up to 30 ms per call.
  • One round of five: the worker did not run in one round, and then both modes measured the same. So a single in-game run can miss the effect, which fits the runs above where only some frames changed.

The same change with the benchmark is up for upstream as Marvisak/VIctory#3177 (on by default there, since main has no in-place heap census), and for AnyXboxX as LooperSalty/AnyXboxX#352 (off by default, like here). For this PR, @CuteBooty: the benchmark is a self-contained #[ignore] test in xmem.rs (physical_remap_bench) and should port as is, if you want the numbers reproducible here.

AI use: Claude Code (Claude Opus 5.5) wrote the benchmark and ran it on my machine. No game files or game data.

…ions

An ignored test, physical_remap_bench, by KainanP (Marvisak/VIctory PR 3177),
adapted to VICTORY_SECTION_MB: a 4 GiB allocation mapped one 64 KiB view per
page, then 10 s of random single-page remaps while another thread makes,
touches and frees 2 GiB, for one section per allocation and for 2 MiB
sections over 3 rounds. The sections are chosen per run through a test-only
override of section_pages, so the switch's value does not matter.

cargo test --release -p victory-hle physical_remap_bench -- --ignored --nocapture

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CuteBooty

Copy link
Copy Markdown
Author

@KainanP thank you for the benchmark. I have ported the test to this branch (99cd7e1b), credited to you with the reference to Marvisak/VIctory PR 3177, adapted to VICTORY_SECTION_MB: it picks one section or 2 MiB sections per run through a test-only override, so the switch's value does not matter. It is #[ignore]d (4 GiB mapped, about 90 s, roughly 6 GiB of memory at the peak):

cargo test --release -p victory-hle physical_remap_bench -- --ignored --nocapture

One change from yours: a drop guard stops the pressure thread, so a failed assertion in the timed loop cannot leave the test hanging.

One run here (Ryzen 5 3600, 32 GB, Windows 11; the machine was not quiet, so read it as shape, not as numbers):

sections remaps/s median p99 calls of 1 ms or more
one 4,410 17.4 us 2,600 us 4,995 (8,960 ms of 10 s)
2 MiB 60,526 13.0 us 24.9 us 40 (726 ms)

Medians of 3 rounds. In one of the three rounds the one-section case was as fast as the 2 MiB one, so the stall comes and goes, as it does in the game.

AI-assisted (Claude Code).

@Proudnoob4

Copy link
Copy Markdown

RTX 4080 / i5-13600K (Win10) 10-minute verification — 66× smaller worst frame stall (7,408 ms -> 112 ms)!

Ported #1274 (VICTORY_SECTION_MB=2) onto our trustno1-coder/VIctory-NVIDIA-based branch (989e5c6, adapting inplace.rs so both Views::sections and Views::whole use BTreeMap and clean up in title_memory_section_gone) and ran both unit tests and a full 10-minute live GTA 6 prologue pass (--console series-s, render_scale=0.6667, RT skipped, warm shader cache):

  • Unit tests: physical_page_numbers_and_writes_continue_across_sections passed with VICTORY_SECTION_MB unset and =2.
  • 10-minute live streaming / stall comparison (same scene, same shader cache, n=104 / 105 settled frames):
    • Pass 15 (VICTORY_SECTION_MB=0): worst frame 7,408.4 ms, 6 frames >55 ms, 0.0 ms steady-state remap wait
    • Pass 16 (VICTORY_SECTION_MB=2): worst frame 112.4 ms (-98.5% / 66× reduction), 2 frames >55 ms (0 in tail-40), 0.0 ms remap wait
  • Visual check (t=140..600s): 0/230 black frames, 60/60 clean consecutive tail burst frames, full 4,582 draws/frame, zero crashes or handle leaks.

(Note: Pass 16 also had #1184 VICTORY_HOIST_CLAMPS=1 enabled in the same run, which shifted steady-state FPS from 32.00 to 30.70 due to list-splitting overhead on top of VICTORY_INDIRECT_BATCH=1; #1274 itself is a clear streaming/stall win and we're keeping VICTORY_SECTION_MB=2 enabled by default in our launcher.)

LooperSalty pushed a commit to LooperSalty/AnyXboxX that referenced this pull request Nov 26, 2026
…, off by default)

XMemAllocatePhysicalPages made one pagefile-backed section per request
(6.1 GiB at once for GTA VI), mapped a 64 KiB view at a time. Windows'
large-page rebuild worker walks every view of a section under its lock for
each page it trades, so the title's map and unmap calls wait behind it
(fxceless/victory-fork#1089). VICTORY_SECTION_MB=2 backs a request with
sections of at most 2 MiB; unset or 0 keeps one section per request.

GPU side: sections and our own views of them (VICTORY_QUIET_BACK) are kept
by handle in maps instead of vectors scanned linearly, a closed section's
own view is unmapped at once (title_memory_section_closed), and the census
groups sections by size.

Synthetic benchmark included (ignored test physical_remap_bench).

Source: fxceless/victory-fork#1274 (CuteBooty), idea and first patch from fxceless/victory-fork#1089 (RyanCase94)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CuteBooty

Copy link
Copy Markdown
Author

Summary of the confirmations so far: the remapping cost drops on every machine that tried it; the stalls go away where the remaps were their cause

@Proudnoob4 thank you for the 10-minute pass and for porting it to a different tree, and thanks again to everyone who ran it. Collected in one place, as reported by each tester (their trees and scenes differ, so the rows do not compare with each other):

Tester Machine Mode Without With VICTORY_SECTION_MB=2
here RTX 3070 8 GB, Ryzen 5 3600 Series S stalls of 0.3-0.8 s while driving gone
HLVM04 RTX 5070 Ti, 9800X3D Series S p90 frame about 118 ms 105 ms
Exopus-0x65f7ad0 RTX 5060 Ti 8 GB, 8700F, 16 GB RAM Series S 32-65 s of remapping in the opening cutscene 2.5 s
Garu667 RTX 3080 10 GB Series X remapping 42.8 ms a frame; long freezes 5.0 ms a frame; freezes unchanged
Proudnoob4 RTX 4080, i5-13600K, Windows 10 Series S worst frame 7,408 ms 112 ms
KainanP i7-14650HX, synthetic test, no game - 1,386 remaps of 1 ms or more in 10 s 28

What I read from it:

  • The remapping cost falls by a large factor everywhere, on Windows 10 and 11, on 8 to 16 GB cards, and in a test without the game.
  • The average frame rate does not move. What changes is the long frames, and only where the remaps caused them: on Garu667's tree the freezes have another cause and stay.
  • Known price: without memory churn elsewhere, 2 MiB sections are about 8 % slower per remap (KainanP: 10.0 against 9.1 µs median).
  • Nobody has reported a change in the picture, a crash or a device loss with it.

Limits, as the testers stated them: mostly one run each; Proudnoob4's pass with the switch also had VICTORY_HOIST_CLAMPS=1 on; the stall comes and goes between runs, so a single run can miss it in either direction.

On the default: I proposed leaving it off. With these reports I would be equally comfortable with it on by default if you prefer that, @fxceless; that is your call. The ignored benchmark on the branch (physical_remap_bench) lets anyone check a machine in about 90 seconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants