HLE: keep one view of a physical-page section instead of a view per write (VICTORY_XMEM_PERSISTENT_VIEW=1) #231
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/231"
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?
Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-24T22:51:37Z.
Problem
write_physicalandpage_windowreach the physical pages throughView::map, which maps a view of the section, commits it withVirtualAlloc(MEM_COMMIT), writes, then unmaps it inDrop for View. Every write pays aMapViewOfFile, a commit and anUnmapViewOfFile, once per run of consecutive pages, however few bytes it touches.page_windowandwrite_physicalhave exactly one production caller: the DirectStorage destination path indstorage.rs, which triespage_windowfirst and falls back towrite_physical. That is the streaming path, called once per in-flight request on every worker, for the whole world load and for every texture streamed while playing. An unmap invalidates that mapping's translations on every processor, so the cost is charged to all cores rather than to the writer alone.Fix
Sectionkeeps one read-write view of its whole range, mapped on first use and unmapped when the section goes (MappedBase, dropped with theSection), plus one bit per 64 KiB page recording which pages are already committed through it.Viewbecomes an enum:Temporaryis the old map/commit/unmap path,Persistentpoints into the section's view and unmaps nothing when it drops.Section::ensure_committedcommits a run in a single call the first time and makes no calls after, reusingcommit()so a host at its commit limit still produces the same crash report.View::temporary, so the worst case is today's behaviour.Mappingis the seam that lets tests force either path, since the switch is read once per process.VICTORY_XMEM_PERSISTENT_VIEW=1, matching the other rollout switches here. It holds a whole-section mapping for the section's life, which is 6.1 GiB of address space for the title's largest allocation, so it should be proven by a live run before it becomes the default. No frame-rate claim is made here — this tree cannot measure that.Verification
cargo test -p victory-hle xmem:: --locked— 16 passed (5 new, all executing:parse_persistent_views_accepts_only_an_explicit_yes,persistent_views_write_and_commit_once,persistent_page_windows_share_one_mapping,temporary_views_never_map_the_section_whole,ensure_committed_refuses_ranges_outside_the_section).cargo clippy --workspace --all-targets --locked -- -D warnings— cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings— cleancargo test -p xtask --locked— 4/4 passedmark_committedmade a no-op fails the twocommitted_allassertions and nothing else; removing thecommitcall makes the persistent write fault withSTATUS_ACCESS_VIOLATION, which proves the commit is load-bearing; forcing thecommitted_allfast path off leaves 16/16 green, so it is documented as the one surviving mutation rather than given a test that could not fail.View::temporaryis the oldView::mapbody), so every pre-existing test is the negative control for the persistent one.Notes for review
XMemMapPhysicalPages, its placeholders, and theunmap()bookkeeping — the persistent view is not inphysical.views, so remapping and unmapping behave exactly as before.write_physicaland thePageWindowfields; this touchesPageWindowonly by changing the type of itsviewfield. Whichever lands second rebases cheaply.Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-24T22:58:52Z.
Review: COMMENTED
P2. Borrow only the requested byte range in a persistent view. On
5faabc4,View::bytes()constructs an exclusive slice over every page in the mapped run.PageWindow::bytes()and the buffered write path then narrow it. Because the persistent view shares one virtual address, independent DirectStorage requests writing disjoint ranges of the same page can still form overlapping mutable references. The workers execute outside the scheduler lock. View · Scheduler · Rust slice safety contractCould the view take a checked offset and length and create the mutable slice only over those bytes? Actual overlapping writes would still need an enforced exclusion rule before using one address for both. The existing DirectStorage fixture submits overlapping destinations through the in-place and buffered paths. This is a source-review finding. Existing fixture
upstream-sync referenced this pull request2026-11-25 00:10:00 +00:00
Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T00:19:57Z.
Thanks — this was right, and the second half of it was the more important half.
View::bytes()formed its slice over the whole run, and onlywrite_physical/PageWindow::bytesnarrowed it afterwards. Through the temporary path that was harmless, because every view has an address of its own. Through the persistent path the section has one address, so narrowing after the fact was too late: two requests writing different bytes of one page each held a slice over the whole page.Both halves are now done, in
8ad1bd62:View::bytes_at(from, len)takes the offset and length and returns exactly those bytes, on either path. Nothing in the module forms a slice over a whole run any more, so writers whose bytes do not touch hold disjoint slices even inside one page.The exclusion rule is enforced, not assumed.
Sectionrecords the byte ranges its live persistent views hold;holdrefuses a claim that touches a live one, andView::persistentreturnsNonewhen refused — so the caller lands on a temporary view, which has an address of its own. Writers whose bytes really do overlap therefore go through two addresses and never through two slices at one base. A view gives its range back when it drops.You were also right that I had nothing to point at. I had written that the title "writes each destination alone" and cited
dstorage, but the page-destination branch states only a size fact — andzlib_into_pages_in_place_and_across_allocationsenqueues two requests with the same destination pages from the same offset, one through the in-place path and one through the buffered path. That is the case the claim rule now handles.What this does not do: it does not make overlapping concurrent writes correct. It makes them fall back to the path that was correct before, so a writer overlapping another still sees whichever write lands last, exactly as it did previously. Making that correct would need an ordering guarantee on the title's side that I cannot verify from here.
Verification (all local; the fork's CI runs sit at
action_requireduntil a maintainer approves them):cargo test -p victory-hle xmem:: --locked— 18 passed, including two new tests:a_view_slice_covers_only_the_bytes_asked_foranda_second_overlapping_persistent_view_falls_back_to_a_temporary_one.-D warningsclean, with and without--all-features;cargo test -p xtask4 passed;cargo test --workspace --lockedgreen.bytes_atreturning the whole run fails withleft: 65536, right: 3; its end check removed makes the past-the-end case read on instead of refusing; skipping the claim makes the second overlapping viewPersistent; never releasing it makes the re-claim fail.One residual I should name rather than leave implied: a leaked
PageWindowwould hold its range for good, so later writes to those bytes would keep taking the temporary path — slower and correct, degrading toward the old behaviour rather than toward unsoundness.Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-25T13:50:28Z.
Your P2 is fixed on
ec89292d, in both halves you asked for.The range.
View::bytes_at(from, len)builds the mutable slice over[from, from + len)and nothing else — a checkedfrom.checked_add(len) <= wholefirst, so a range that does not lie inside the view is a panic with the numbers in it rather than a slice over someone else's pages. Two independent DirectStorage requests writing disjoint ranges of the same page now get disjoint slices even though they lie in one page, which the old whole-run slice could not give them.The exclusion. You were right that disjoint bytes are not enough on their own — the same virtual address shared by two lifetimes still needs a rule.
Section::holdnow refuses a second live persistent view whose bytes touch an existing one, and that request falls back to a temporary copy instead (a_second_overlapping_persistent_view_falls_back_to_a_temporary_one). So actual overlaps are excluded rather than merely being unlikely, and only ranges that never touch share the mapping.Tests:
a_view_slice_covers_only_the_bytes_asked_forpins the range; the fallback test pins the refusal.cargo test -p victory-hle --lib xmem::tests→ 19 passed, 0 failed.Probe: hand back the whole run again (
from_raw_parts_mut(ptr, whole), the old shape) → six tests fail, including the range one and the write path; restored byte-identical.Still true, and worth saying so that it is not read as covered: this is proven against the simulated fixtures only. The DirectStorage workers run outside the scheduler lock, and the only thing that can confirm the ordering in production is the title running a real streaming load with
VICTORY_XMEM_PERSIST=1.Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-26T13:50:21Z.
Rebased onto
maina20809de; head is nowad67d255. Four conflicts inxmem.rs, all the same shape: main added framelog meters and thesplit_lateretry, while this branch renames the section handle and makesViewan enum. Resolution keeps both — main's meters and retry path, the branch'sView::{Temporary, Persistent}andsection.handle— and only a temporary view is unmapped, with that unmap still metered asDiskViewUs. Verified:cargo check/clippy -D warningson victory-hle clean;victory-hle xmem::21 passed, 0 failed.Imported from fxceless/victory-fork. Originally posted by EFriseer on 2026-11-26T14:31:37Z.
Measured on hardware, in case it helps this PR along. I wrote the same change independently before I found this PR: one kept view per section, a commit bit per 64 KiB page, behind a switch that is off by default. So these numbers are for the idea, not for this branch's exact code.
Setup: Ryzen 7 5800X3D (16 threads), RTX 5070 12 GB, 64 GB RAM, game on a PCIe 4.0 NVMe drive. Release build of
a20809dwith the fork's tuned switch set (CARD_WINDOWS_MB=1024, TEXTURE_ROOM_PERCENT=96, HEAP_WORKER, SETTLE_ROOM, PARALLEL_REFRESH, LOOKUP_CACHE and the rest). Free play in the open world and cutscenes of a large retail title. One launch without the change (22 min) and one with it (11 min). The routes differed.No new warnings or errors, and no device loss in either run.
On this 8-core CPU, the per-request map, commit and unmap seemed to compete with the title's own page remapping (map_alias) for the process's address space. The slow requests bunched up exactly where the title streams. That's also where cutscene models stayed low-detail and the frame stalled for 0.5 to 3 s. With the kept view, both mostly went away.
Address space: the kept views reserve the sections' size (6.1 GiB for the largest), and commit charge didn't change visibly.
Imported from fxceless/victory-fork. Originally posted by HailLucifer666 on 2026-11-27T09:38:46Z.
@EFriseer — thank you, these are the most useful hardware numbers on this PR, and I want to be precise about what they are: they measure the idea on your independent build and your route, not this branch's code. That is exactly why I would like to ask for one more run.
Could you run this branch's head,
ad67d255, withVICTORY_XMEM_PERSISTENT_VIEW=1, on the same route and with the same metrics you reported (slowest DirectStorage request, frame-line mean, 5-second stretches over 300 ms, card idle per frame and the two halves of it)? The switch must be1; without it the branch takes the old per-request path and the run is not testing the change.Falsifier up front: if the branch shows no improvement over its own baseline on your machine, then your 276 → 163 ms belongs to the route difference, not to this code — and I will say so rather than quoting it.
If the build has
VICTORY_FRAME_LOG=1andVICTORY_CARD_METER=1(both on by default in diagnostics builds), attaching that log would let the usual frame's make-up be read directly. Please do not setVICTORY_GPU_TIMING— it sends each list separately and changes the frame being measured.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.