HLE: a persistent view above the title's memory, three-state commits, and a write generation per page #872
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!872
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-872"
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?
@HailLucifer666 on GitHub · 2026-11-25 11:24 UTC · original
HailLucifer666:perf/xmem-high-va-alias-and-dirty-gen→main· +1003 −35 · 1 files · 5 commits · openThree changes to the physical-page path, none of which changes it by default (
VICTORY_XMEM_PERSISTENT_VIEWstill off):The view's address. It used to be wherever
MapViewOfFileput it, which can be inside the range the title itself owns — below 40 bits, the range decision 0001 says title structures must live in. A view there either takes an address the title is about to ask for, or makes our own mapping look like a title address to the title's own pointer arithmetic. It is now reserved withVirtualAlloc2's address requirement from 1 TiB toGetSystemInfo().lpMaximumApplicationAddress(asked, never assumed) and mapped into that reservation withMapViewOfFile3. A view that comes back below the ceiling anyway is released and the caller keeps its temporary view — the host is not trusted to honour the requirement.Commit state, three states per page instead of one bit. The bit recorded "committed" but could not promise anything at the moment it mattered: the DirectStorage workers write these sections concurrently, and a thread that lost the race to
VirtualAlloc(MEM_COMMIT)would store into a page whose commit was still in flight. Pages are nowFREE→COMMITTING(claimed by one thread) →COMMITTED(set only afterVirtualAllocreturned); a loser spins onCOMMITTINGinstead of writing. A bounded spin then gives up to the temporary path, which is always correct, so a thread that died mid-commit cannot hang the title.A write generation per 64 KiB page. Bumped after the bytes are written (release), read with acquire: an unchanged digest is a promise about the bytes, not only about the counter.
physical_generation_digest(pages, offset, len)folds a range into one number — the input phase F needs to stop hashing texture memory it already knows. It has no caller here yet beyond its test, and theallow(dead_code)says so rather than pretending otherwise.Tests (3, all device-free):
persistent_view_maps_above_the_title_memory_ceiling— the view lands at or above 1 TiB, a write through it is in the section's pages, and the rule refuses one page below the ceiling.concurrent_commit_state_never_exposes_an_uncommitted_page— eight threads commit the same four uncommitted pages; all eight succeed and every byte each wrote is still there.dirty_generation_digest_changes_on_write_and_stays_stable_when_clean— a physical write moves the range's digest but not an untouched page's; a second identical write moves it again; a page window's bytes count when the window goes; unknown pages and ranges past the end are refused./keeprobes, each restored byte-identical:a write must showa page window's bytes must showabove_title_memoryalways trueLowestStartingAddressset to nullThat last row is the honest part: this host's allocator is already top-down, so it returns an address above 1 TiB with or without the requirement. The requirement is a belt no test here can reach; the predicate is the pin, and that is the one the probe breaks. Said out loud rather than reported as a passing probe.
Gate on
2853f67e:cargo test -p victory-hle xmem::→ 22 passed;cargo test -p victory-hle→ 108 passed, 0 failed; bothclippy --workspace --all-targetspasses red only onmain's three pre-existing lints;xtask4 passed.Not covered: no run in the game, so whether the high address helps anything in practice is unmeasured.
VICTORY_XMEM_PERSISTENT_VIEWstays off.Review of the commit before this one found five things worth fixing. All of them are about the evidence the change rests on, not about the mapping. THE BUG. Three of them are claims the earlier commit message or comments got wrong. The comment on `View::bytes` said two writers through the section's one mapping write "exactly as they did through separate temporary views". They do not. Through separate virtual views two writes to the same bytes were a data race; through one shared base two live `&mut [u8]` over overlapping bytes is undefined behaviour, and the compiler may assume they do not alias. The precondition -- no two writes in flight cover the same page -- is real, is stated in `dstorage` for the buffer branch only, and is not stated at all for the page branch that calls these helpers. The comment now names it as a precondition rather than calling it unchanged behaviour. The comment on `ensure_committed` promised that a host at its commit limit gets "the same crash report". It gets two: the persistent commit fails and reports, then the caller retries on the temporary path and that commit fails and reports again. The comment says so now instead of claiming otherwise. The `end <= self.size` comparison was described as unobserved and was declared alongside the one surviving mutation, which understated it: it is the only thing keeping `committed_all`'s page arithmetic inside `committed`. It was also invisible to all 16 tests, because both "past the section" rows are refused by the host's own `VirtualAlloc` first. A zero-length range past the end is now asserted refused; that row the host cannot supply, so deleting the comparison turns the test red. WHY NOT HYPOTHETICAL. `persistent_page_windows_share_one_mapping` passed with every write on the temporary path. Its only evidence was `persistent_ptr()` returning the base -- but the test itself calls that, and `View::persistent` calls it before the commit can fail, so the `OnceLock` was populated whether or not the persistent path ever ran. Every byte assertion still held, because the temporary view writes the same pages. A test that cannot see the thing it is named for is worse than no test, and this one would have been quoted as proof that the path works. And with the switch on, nothing said whether it was actually in effect: the map half warns per section, the commit half said nothing, and no run could report "these sections are persistent". That is the exact evidence the switch becoming the default is supposed to rest on. THE FIX. `page_bytes`, the helper the pre-existing tests read bytes through, now asks for `Mapping::Temporary` explicitly, so those tests are the persistent path's negative control whatever the environment says. `persistent_page_windows_share_one_mapping` asserts the pages were committed through the section's mapping after the first window, which only the persistent path does. Confirmed by probe: with `View::persistent` made to return `None`, it now fails with "the window fell back to a temporary view" where it previously passed. `ensure_committed_refuses_ranges_outside_the_section` gains the zero-length row, and the surviving-mutation note now names one mutation because only one remains. A `fallback_noted` on `Section` warns once per section when a commit through the persistent view fails, and `View::persistent` says once, at info, that pages are being written through the persistent view. A run with the switch on can now show which it did. SCOPE. xmem.rs only. The whole-section-vs-chunked decision, the fallback behaviour and the default path are unchanged. Two claims in the previous message are corrected here rather than by rewriting it: "the default path is byte-identical to before" is true of writes, not of allocation -- every section now allocates its page bitset either way, a few KiB per GiB; and "the same crash report" is two reports, as above. Verified: cargo test -p victory-hle xmem:: --locked 16 passed; the two clippy commands clean with and without --all-features; cargo test -p xtask 4 passed; cargo test --workspace --locked 500 passed, 0 failed, 7 ignored. Mutation runs 2026-11-25, all restored: `View::persistent` returning `None` outright fails both persistent tests ("fell back to a temporary view", "not mapped whole"); the `end <= self.size` comparison deleted fails the new zero-length row; the earlier probes (bitset not marked, commit removed) still behave as recorded. Co-Authored-By: DeepSeek V4.1 Flash <[email protected]>@MamaLeVrai on GitHub · 2026-11-25 12:23 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
2853f67intomainf85101bin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails with exactly the errorsmainitself has on this machine (placed_filler_twins,depth_written, a sort; PR #841 fixes them), also with--all-features; this PR adds none.cargo test --workspace --locked: run 1: stopped atindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields(the one that fails onmainitself most runs here (PR #849 and #847 fix its assertion)); run 2: stopped atindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields(the one that fails onmainitself most runs here (PR #849 and #847 fix its assertion)) (mainalone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
2853f67ecdto08aa56ad89@HailLucifer666 on GitHub · 2026-11-26 13:56 UTC · original
Rebased onto the new
#231head (ad67d255); this head is now1e653717(--ontoso only this PR's commit replayed). One import conflict, resolved as the union (GetSystemInfo/SYSTEM_INFOplusGetCurrentProcess/GetCurrentThread), a stray brace removed from theDropmatch, and one new-toolchain lint fixed (let...elseexactly equal to?in the view-size rounding). Verified:cargo checkandclippy -D warningson victory-hle clean;victory-hle xmem::24 passed, 0 failed (the 21 from #231 plus this PR's 3).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.