victory-hle(xmem): coalesce contiguous 64 KiB MapViewOfFile3 runs and add lock-free VEH retry around split-and-remap #2425
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2425
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2425"
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?
@faycalbaklouti on GitHub · 2026-11-25 13:14 UTC · original
faycalbaklouti:fix/xmem-coalesce-and-split-veh-retry→main· +793 −29 · 2 files · 2 commits · openTarget upstream:
Marvisak/VIctory(also applicable toBelobug/VIctory-Belobug-AMDandfxceless/victory-fork)Problem
MapViewOfFile3creates one OS VMA per 64 KiB page, rapidly exhaustingvm.max_map_counton Linux/Wine and slowing down large allocations.Solution
map_alias, scatter, and unmap into singleMapViewOfFile3/UnmapViewOfFilecalls.on_split_fault) around the coalesced view split-and-remap window so concurrent accesses to untouched sibling pages cleanly spin/retry until the replacement sub-view is mapped.Verification
git apply --checkonMarvisak/VIctorymain(direct zero-conflict apply).About our fork & censorship-resistant preservation effort:
This fix comes from gta6-vi-port, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries).
rad:z39ofPhQC1siudH9BF3xsmAMmUqxc).onionVP9+Opus viewer:http://kwnoaeecpmxd6eetqfa7fxlymvxnh5du2i6wxr44t4mc7cgch5pw23id.onion/)@Marvisak on GitHub · 2026-11-25 15:32 UTC · original
Automated triage for the maintainers.
Proposed close. This maps runs of contiguous physical pages as one view in
crates/victory-hle/src/modules/xmem.rs(map_alias, scatter,unmap). Becauseunmapmust then split those views, title memory is briefly unmapped while other threads may use it, and the PR adds a first-chance exception handler (on_split_fault) that spins and resumes faults inside that window or a ring of recent splits.maindoes not have.mainmaps one view per page and never unmaps live title memory to remap part of it; the new handler only papers over the window, and it runs ahead of the existing guard handler for every access violation in the process.vm.max_map_countunder Linux/Wine; no problem on Windows is shown.apps/victory/src/private_heap.rswith nomoddeclaration (that file belongs to #2424), and CI is failing.A measured Windows-side reason to coalesce views, and a split that never leaves live memory unmapped, would change this verdict.
This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.
Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 16:56 UTC · original
Both mechanisms hold up to close reading:
Coalescing — run detection requires same-section
Arc+ contiguousindex,chunk_lenstays inside both the source view andlen,map_runfalls back to per-page when a single view can't cover a reservation boundary, andMEM_COALESCE_PLACEHOLDERSis only applied to spans of ≥2 adjacentMEM_RESERVEplaceholder regions (the kernel call itself rejects non-placeholder spans, so a mixed span just stays split → per-page fallback — safe degradation). The test pins the split-then-realise → single-view cycle end to end.Split VEH — window opens before
UnmapViewOfFile2(fault can't slip in front),endwrites HI before LO so a reader'slo < hican't see a stale half-open range, the RECENT_SPLITS ring covers faults arriving microseconds after remap, andVirtualQuery+ prot check beforeCONTINUE_EXECUTIONkeeps genuinely-unmapped addresses propagating. Allocation-free/lock-free as a VEH must be.One robustness note: the spin loop in
on_split_faultis unbounded — if the remapping thread were killed or panicked betweenbegin/end, a faulting thread spins forever (silent deadlock). A bounded spin (say ~10 ms) thenCONTINUE_SEARCHkeeps the retry semantics for real remaps while making a stuck window a crash instead of a hang. Worth adding before this merges.@kotekompotek on GitHub · 2026-11-25 16:59 UTC · original
Read both halves carefully. The coalescing logic is sound — run detection checks
Arc::ptr_eq+ index contiguity,map_rundegrades to per-page on reservation boundaries, and the scatter batching preserves the map/unmap interleaving correctly. A few things need attention before merge:1.
private_heap.rsis dead code. Nothing declaresmod private_heapand no#[global_allocator]installsPrivateHeap— the file compiles to nothing. It's also not mentioned in the PR body. If the intent is the VEH-safe allocator the doc comment describes (which is a real concern foron_split_fault's future growth), wire it in and explain it; otherwise drop the file.2. Unbounded spin in
on_split_fault. A faulting thread spins with no yield while the remapping thread (which holds thephysicalmutex) finishes. On a busy 4-core box a higher-priority faulting thread can livelock the remapper for a quantum at a time — and if the remapper ever dies mid-window, this spins forever. Suggest a bounded spin thenSwitchToThread/YieldProcessorbackoff.3.
coalesce_placeholdersnever checksAllocationBase. It coalesces any run of adjacentMEM_RESERVEregions — including a plainVirtualAllocreservation parked next to our placeholders. TheMEM_COALESCE_PLACEHOLDERScall fails atomically on non-placeholder spans, so today it just silently fails (result ignored → per-page fallback, safe). Still, comparingmbi.AllocationBasewhile extendingspan_endis a one-line tightening that avoids relying on the kernel rejecting mixed spans.4. Sticky ring + masked protect bits.
RECENT_SPLITSentries are never cleared — any address that was ever in a split window stays "recently split" forever (16 slots, overwritten). Combined withprot & 0xffstrippingPAGE_GUARD/modifier bits, a guard-page fault inside a stale range would be swallowed byEXCEPTION_CONTINUE_EXECUTIONbefore the intended handler sees it. Today nothing in the process usesPAGE_GUARD(gpu write-watch usesPAGE_READONLY, which correctly fails the write-prot check), but worth a defensiveProtect & PAGE_GUARD != 0 -> CONTINUE_SEARCHto keep the handler a pure retry mechanism rather than a fault-eater for future protection tricks.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.