Repository navigation
DirectStorage: workers read a file through a handle each - #2904
0xkn0wh3r3 wants to merge 1 commit into
Conversation
Every worker read a file through the one handle the title's open made. That handle is opened for synchronous reads, and the host does the reads of such a handle one after the other, so the workers queued behind each other on every file. Each worker now reads through a handle of its own, made from the title's with ReOpenFile when it first reads that file (the title's handle if the host makes none). 48 KiB reads at random, 24 threads: 185 MB/s through one handle and 990 MB/s through a handle each, from an archive not in the file cache (the fork's measurement); from the cache on this machine, 4.2 GB/s and 6.6 GB/s (read_bench, ignored, on any file named by VICTORY_BENCH_FILE). VICTORY_DSTORAGE_HANDLES=0 reads through the title's handle alone, as before. From avatarmanz/VIctory-7900XTX fbc1830 (its handles mode; the overlapped and unbuffered modes and the xmem lock changes are left out). Co-authored-by: local <local@localhost>
kotekompotek
left a comment
There was a problem hiding this comment.
Correct — a synchronous handle serializes reads on the host side, so N workers through one handle queue behind each other; a lazy per-worker handle (OnceLock indexed modulo worker count) removes that contention while keeping the title's handle semantics. The =0 escape hatch is there. LGTM.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Verified head 487d01e0 cleanly on origin/main (63bcca43) on Windows 11 x64.
Code Review
- Using
ReOpenFile(..., GENERIC_READ, FILE_SHARE_READ, 0)creates distinct kernelFILE_OBJECTs per worker (unlikeDuplicateHandle), eliminating synchronous-I/O lock serialization across worker threads while keepingseek_readoffsets independent. - Handles open lazily via
OnceLock, fall back cleanly tofirstifReOpenFilefails (or whenVICTORY_DSTORAGE_HANDLES=0), and drop cleanly onInstance<File>release.
Local Verification
cargo test --locked -p victory-hle: 153/153 unit tests passed (1 ignoredread_bench; includesworkers_read_a_file_through_handles_of_their_own), plusfidelityfx(1/1) andno_dll_planting(1/1).cargo clippy --locked -p victory-hle --tests -- -D warnings(default and--features diagnostics) &cargo xtask policy(191 files ok): clean.
Looks clean and ready to merge.
|
Automated triage for the maintainers. Merge candidate (a recommendation to look, not an approval). In Generated by Claude Code |
…rmediate scratch buffers Each worker thread in dstorage::work() processes requests sequentially, but previously constructed a fresh ~10.5 KiB DecompressorOxide and allocated/zero-filled new Vec<u8> buffers for file sources and zlib+BCPack intermediate output on every request. Keep a worker-local WorkerScratch in work() with a boxed miniz_oxide::inflate::core::DecompressorOxide (reset via init() before each stream) plus reusable source and intermediate Vec<u8> buffers (trimmed back after >8 MiB outliers so idle worker RSS stays bounded). Bit-identical inflate status and output verified across valid, short-output, bad-header, bad-Adler32, truncated, and error-recovery cases. Disjoint from Marvisak#2904 and Marvisak#2883; zero new dependencies. Measured (--release bench_dstorage_worker_scratch, median of 3 runs): - 256 KiB x400: 48.03 ms -> 27.61 ms (1.74x, -42.5%) - 32 KiB x2000: 30.21 ms -> 28.79 ms (1.05x, -4.7%) - 4 KiB x8000: 48.24 ms -> 44.41 ms (1.09x, -7.9%) Assisted-by: T3 Code (Antigravity, gemini-4-neon)
Dukestar69
left a comment
There was a problem hiding this comment.
Verified against origin/main (63bcca4):
cargo test -p victory-hle --lib modules::dstorage:: -- --test-threads=1: 17/17 passed (1 ignored bench; includingworkers_read_a_file_through_handles_of_their_own).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Giving each DirectStorage worker its own file handle avoids contention on shared handles while keeping all existing queue/decompression invariants intact.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
…hrough a handle each
|
NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head Tested
Not tested
AI use
|
What
Each DirectStorage worker now reads a file through its own handle instead of the one handle the title's
OpenFilemade. A worker makes its handle withReOpenFilethe first time it reads that file. If the host refuses, it falls back to the title's handle, logs a warning, and carries on. The handles close with the file object.VICTORY_DSTORAGE_HANDLES=0reads through the title's handle alone, as before.Why
The title's handle is opened for synchronous reads, and Windows performs the reads on one such handle one at a time. So the scheduler's workers (one per host core) queued behind each other on every file, however many were free.
Measured with 48 KiB reads at random offsets from 24 threads:
read_bench)Nothing here depends on the GPU vendor.
Where it comes from
From the avatarmanz/VIctory-7900XTX fork, commit
fbc1830. This PR takes only the fork's defaulthandlesmode. Left out: itsoverlappedand unbuffereddirectmodes, and its xmem lock rework from the same commit.#234 also targets this serialization, using overlapped reads on one handle, but it bundles that with xmem mapping changes. This PR is only the handle change.
Tested (Windows 11, RTX 5070 Ti)
cargo test -p victory-hle: 153 passed, 1 ignored (the benchmark). New testworkers_read_a_file_through_handles_of_their_own: six threads read through three handles, and through the title's handle alone, at offsets across a 300,001-byte file and past its end. It checks the bytes and checks that each handle slot a thread used was made.read_bench(ignored):VICTORY_BENCH_FILE=<file> cargo test --release -p victory-hle --lib read_bench -- --ignored --nocapture. The cached-file numbers above come from it.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.Not tested