Skip to content

HLE: overlapped DirectStorage I/O and persistent xmem section views - #234

Open
wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:hle/streaming-io-and-xmem
Open

wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:hle/streaming-io-and-xmem

Conversation

@wbkepler

Copy link
Copy Markdown

Summary

Eliminates DirectStorage kernel file-lock serialization and xmem per-chunk TLB shootdowns during asset streaming:

  • dstorage.rs:
    • Opens archive files with FILE_FLAG_OVERLAPPED (OwnedHandle) and issues concurrent positioned overlapped reads via thread-local manual-reset Win32 events (ReadFile + GetOverlappedResult loop handling partial reads and EOF/Win32 errors).
    • Sets worker threads to THREAD_PRIORITY_BELOW_NORMAL, reuses per-worker Scratch buffers (trimmed above 8 MiB), and replaces unconditional notify_all() wakeups with targeted notify_one() and waiter-aware notifications.
  • xmem.rs:
    • Keeps a persistent host-VA linear mapping (MapViewOfFile3 above 2^40 with MapViewOfFile fallback) and per-page AtomicU64 committed bitmap on each Section (preserving Wine whole-section SEC_COMMIT), eliminating transient MapViewOfFile/UnmapViewOfFile TLB shootdowns in page_window/write_physical.
    • Drops freed sections outside the PHYSICAL lock, coalesces contiguous runs in XMemMapPhysicalPagesScatter and map_alias (with placeholder-boundary fallback), and guards zero-length map/unmap operations.
  • Adds unit tests for concurrent overlapped reads on one handle, scratch reuse/trimming, persistent section commit/drop cleanup across bitmap words, and coalesced scatter/alias + zero-length safety.

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed (victory-hle: 90 passed, 1 ignored)
  • cargo xtask policy — passed (151 files ok)

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…nt xmem section views) into the integration

xmem: the PR's Section (a persistent view and a commit bitmap) keeps the
branch's SECTION_BYTES accounting. map() keeps the branch's
multi-placeholder split and all-or-nothing behaviour; each view now
commits through Section::ensure_committed, which still goes through
commit() and its commit-limit crash report. The PR's warn_on_fail flag
is threaded through. Both sides' tests are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
… from the integration

Build B crashed in the menus about 50 s after launch: the title read an
address that was reserved but not yet committed, before commit on demand
ran. Stack A without Marvisak#234 never did this, so the PR comes out until it is
proven on the RX 7600.

This reverts merge 5cd3c93.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
Reverts the merges of PRs 31, 88, 96, 111, 114, 122, 132, 141, 172, 182,
183, 186, 194, 209, 216, 218, 219, 221, 224, 228, 229, 236, 237, 239, 240
and 247: audio/XMA, saves, XAsync/XTaskQueue, path and PE checks, loader
hardening and a start-up report. None of them is known to change what
the RX 7600 shows or whether the game stays up, and each is one more
thing that can break, as Marvisak#234 did.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@wbkepler

Copy link
Copy Markdown
Author

Found and fixed a regression in this PR (423d3f4).

Coalescing consecutive XMemMapPhysicalPagesScatter / map_alias pages into multi-page views made later single-page remaps unsafe. unmap cannot shrink a view, so remapping one page of a coalesced view unmapped the whole view and then mapped the remainder back. Neighbouring pages were briefly unmapped while other threads read them, which caused access violations on unmapped title memory during world loading (3/3 runs).

Scatter and alias now map one view per page again, as before this PR. The persistent section views, overlapped reads, single-lock scatter and run-coalesced unmaps are unchanged.

Tests: a new regression test checks that remapping one scattered page leaves its neighbours' views in place, and a one-view-per-page test replaces the coalescing test. Workspace clippy, tests and cargo xtask policy pass. A live run now loads into the world (~3k draws/frame, indirect draws > 0) with no exceptions.

wbkepler and others added 2 commits November 24, 2026 21:38
Eliminate DirectStorage kernel file-lock serialization and xmem per-chunk
TLB shootdowns during asset streaming:

- dstorage: open archive files with FILE_FLAG_OVERLAPPED and issue
  concurrent positioned overlapped reads via thread-local manual-reset
  Win32 events, handling partial reads and EOF/errors in a loop.
- dstorage: lower worker thread priority to THREAD_PRIORITY_BELOW_NORMAL,
  reuse per-worker scratch buffers (trimmed above 8 MiB), and replace
  unconditional notify_all() wakeups with targeted notify_one() and
  waiter-aware notifications.
- xmem: keep a persistent host-VA linear mapping (placed above 2^40 when
  possible) and a per-page atomic committed bitmap on each physical
  Section, so page_window and write_physical commit each page at most
  once and never call transient MapViewOfFile/UnmapViewOfFile during
  streaming (preserving Wine's whole-section SEC_COMMIT behavior).
- xmem: coalesce contiguous runs in XMemMapPhysicalPagesScatter and
  map_alias (with placeholder-boundary fallback), guard zero-length
  unmap/map calls, and drop freed sections outside the PHYSICAL lock.
- tests: add unit tests for concurrent overlapped reads, scratch
  reuse/trimming, persistent section commit/drop cleanup across bitmap
  words, and coalesced scatter/alias + zero-length operations.
Coalescing consecutive scatter/alias pages into multi-page views made
later single-page remaps unsafe: `unmap` cannot shrink a view, so
remapping one page of a coalesced view unmapped the whole view and then
mapped the remainder back, leaving neighbouring pages briefly unmapped
while other title threads (and GPU page-mapping copies) were reading
them. This showed up as access violations on unmapped title memory at
varying sites during world loading.

Scatter and alias mappings again get one view per page; runs of scatter
unmaps are still cleared in one pass under a single lock hold, and the
persistent section views and zero-length guards are kept.

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

Copy link
Copy Markdown
Author

Rebased onto current main (ffe310e) as e39fc9c; one small conflict in xmem.rs unmap (kept upstream's zero-length guard and comment with this PR's saturating end). Gate (clippy -D warnings, tests, policy) clean.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

@wbkepler
wbkepler force-pushed the hle/streaming-io-and-xmem branch from 423d3f4 to e39fc9c Compare November 24, 2026 20:39

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-hle/src/modules/dstorage.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

@crashbashash

Copy link
Copy Markdown

Data from Linux/Proton on the persistent-section-view part, in case it helps review. I measured the same idea in a minimal version (one view per section, mapped on first write, unmapped with the section; a page window holds its section), not this PR's code: main 70564ae plus #1849 and #994's Proton commits, RX 6800 XT, GE-Proton11-14, hands-free, 120 s in the world per run, 4 runs before and 3 after.

  • Under Wine every map and unmap is a wineserver request that walks every view of the process (server/mapping.c: is_valid_view_addr, find_mapped_view), and the game keeps 130,000+ views alive in the world. wineserver ran at 75 % of a core, 99.5 % of it in those two walks, about 0.5 ms per request. The per-read DirectStorage views were 27 % of its map/unmap requests.
  • With a view per section there were no per-read views left (25,509 per run before). The game allocates three sections at startup and frees none in the world, so a whole run maps one section view. wineserver map/unmap requests went from 1,432 to 1,176 per second, GPU tile mappings served from 405 to 493 per second (ranges 398–415 and 429–530), game CPU from 80 % to 103 % of a core. Frame time showed no change beyond run-to-run variation.
  • On your revert to one view per page: in the same runs none of 87,955 map_alias pages had a source consecutive with the one before, so coalescing could not have saved views there.

AI-assisted (Claude Code). No game data attached.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants