Repository navigation
fix(hle): isolate per-worker DirectStorage file handles and keep 64 KiB xmem views independent - #400
Open
gdemontalivet wants to merge 2 commits into
Conversation
…pendent Track exact-size unmapped placeholder holes and already-committed section pages (VICTORY_MAP_LEAN, on by default), skip unchanged pages individually in XMemMapPhysicalPages and map_alias instead of unmapping sibling pages, and keep each 64 KiB page in its own view unless VICTORY_MAP_RUNS=1 is set so partial remaps never briefly unmap sibling pages under concurrent reads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two concurrency bugs and two
xmemmapping bottlenecks show up when streaming workers saturate DirectStorage and physical-page remapping under Wine on macOS:std::fs::Filehandle per open archive and issueFileExt::seek_readcalls in parallel. Under Wine on macOS, concurrent synchronous reads on the same file handle race on the kernel file object's shared position and return bytes from another worker's offset, causingzlibinflation failures (0x8007000d,E_INVALIDARG).XMemMapPhysicalPagesremaps: On Xbox hardware each 64 KiB page has an independent PTE, whereasXMemMapPhysicalPagespreviously merged consecutive pages into one multi-pageMapViewOfFile3view and calledunmap(base, n * PAGE)across the whole call whenever any single page differed. A later partial remap or unmap of one page inside a multi-page view had toUnmapViewOfFile2the entire host view before remapping its outer halves—briefly unmapping sibling 64 KiB pages that streaming threads were actively reading (0xc0000005).xmemlock contention and redundant placeholder splits/commits: DirectStorage page-destination lookups contended withXMemMapPhysicalPageson a single global mutex, and remapping an unmapped 64 KiB slot re-split its placeholder and re-committed already-committed section pages every time.This series resolves these issues in two commits:
Per-worker DirectStorage file handles and decoupled
xmempage lookups (dstorage.rs,xmem.rs):0..workers, avoiding thread-ID modulo collisions) backed by an independent OS file description opened viaCreateFileWon the recorded path (including mounted virtual drives) orReOpenFile, withVICTORY_DSTORAGE_HANDLES=0opt-out.Mutex<std::fs::File>so non-worker callers or fallback handles never raceseek_readcursors under Wine.xmem's physical-page table (PAGES) and reverse slice-to-address index (SHOWN) into dedicatedRwLocks separate fromPHYSICALso DirectStoragepage_window/write_physicallookups never block behind hostMapViewOfFile3/UnmapViewOfFile2syscalls.Independent 64 KiB views, per-page unchanged skip, and lean placeholder hole reuse (
xmem.rs,docs/macos.md):MapViewOfFile3view by default and skip individual unchanged pages (shows(...)) inXMemMapPhysicalPagesandmap_aliasinstead of unmapping acrossn * PAGE, so remapping one page never unmaps sibling pages being read on other threads.VICTORY_MAP_LEAN(on by default,=0opt-out): track exact-size unmapped placeholder holes (Physical::holes) and already-committed section pages (Section::committed) so remapping a 64 KiB slot replaces its placeholder directly without redundantVirtualFreesplits or commit calls.VICTORY_MAP_RUNS=1(opt-in, default off): optional multi-page run coalescing forXMemMapPhysicalPages,XMemMapPhysicalPagesScatter, andmap_alias, documented indocs/macos.md.Synthetic Benchmarks & Concurrency Tests (CrossOver Preview + Wine on M5 Max)
zlibreads (8 workers):0decompression errors across 8,064+ concurrent high-offset compressed reads; multi-worker cached read throughput rose from11.2 GB/s(1 shared handle) to24.1 GB/s(2.14x).partial_remap_keeps_sibling_pages_mapped_for_concurrent_readers): 1,200 multi-page and single-page remaps of middle page 1 while two reader threads continuously read pages 0 and 2 viaread_volatile—0access violations and exactly1MapViewOfFile3call per changed page.xmempage lookup under concurrent mapping churn:3.17Mpage lookups/s (4.58 us/req) sustained concurrently alongside mapping threads.Live M5 Max Verification (Combined Build on CrossOver Preview + D3DMetal)
CrossOver Preview+ D3DMetal,wave32=true), the runtime reached and sustained the 3D world through+8, +24, +48, +90at1.5–1.8 FPS(549.7–672.1 ms/frameon1,021–1,258 draws/frame,1.275 FPSoverall across+8..+90) with02.48 sallocation stalls,7.2–9.0 ms/frameGUARDSlock hold time (down from4,887 ms/framebefore unlockingGUARDS),149–154 MB/framebuffer copy volume,0DirectStorage decompression or access-violation failures, and38/38over-32 KiB aligned mesh/pixel pairs linked with0host mesh refusals.Verification
victory-hlexmem(21/21) anddstoragesuites passed.cargo xtask policy,git diff --check, andcargo clippy(-- -D warnings, with and without--features diagnostics) passed. All test inputs are synthetic.